Skip to content

Commit 114b153

Browse files
committed
Extend number of flat parameters in async lower from 1 to 4
1 parent deb0b0a commit 114b153

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

design/mvp/canonical-abi/definitions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,7 @@ def lower_async_value(ReadableEndT, cx, v, t):
15221522

15231523
MAX_FLAT_PARAMS = 16
15241524
MAX_FLAT_RESULTS = 1
1525+
MAX_FLAT_ASYNC_PARAMS = 4
15251526

15261527
def flatten_functype(opts, ft, context):
15271528
flat_params = flatten_types(ft.param_types())
@@ -1545,7 +1546,7 @@ def flatten_functype(opts, ft, context):
15451546
else:
15461547
flat_results = []
15471548
case 'lower':
1548-
if len(flat_params) > 1:
1549+
if len(flat_params) > MAX_FLAT_ASYNC_PARAMS:
15491550
flat_params = ['i32']
15501551
if len(flat_results) > 0:
15511552
flat_params += ['i32']
@@ -1932,7 +1933,7 @@ def on_resolve(results):
19321933

19331934
def on_start():
19341935
on_progress()
1935-
return lift_flat_values(cx, 1, flat_args, ft.param_types())
1936+
return lift_flat_values(cx, MAX_FLAT_ASYNC_PARAMS, flat_args, ft.param_types())
19361937

19371938
def on_resolve(results):
19381939
on_progress()

design/mvp/canonical-abi/run_tests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,6 +2231,25 @@ async def core_func(task, args):
22312231

22322232
await canon_lift(sync_opts, inst, ft, core_func, None, lambda:[], lambda _:(), host_on_block)
22332233

2234+
async def test_async_abi():
2235+
heap = Heap(1000)
2236+
opts = mk_opts(heap.memory, 'utf8', heap.realloc)
2237+
inst = ComponentInstance()
2238+
caller = Task(opts, inst, FuncType([],[]), None, None, None)
2239+
2240+
ft1 = FuncType([F32Type(), F64Type(), U32Type(), S64Type()],[])
2241+
async def f1(task, on_start, on_resolve, on_block):
2242+
args = on_start()
2243+
assert(len(args) == 4)
2244+
assert(args[0] == 1.1)
2245+
assert(args[1] == 2.2)
2246+
assert(args[2] == 3)
2247+
assert(args[3] == 4)
2248+
on_resolve([])
2249+
[] = await canon_lower(opts, ft1, f1, caller, [1.1, 2.2, 3, 4])
2250+
2251+
TODO
2252+
22342253
async def run_async_tests():
22352254
await test_roundtrips()
22362255
await test_handles()
@@ -2250,6 +2269,7 @@ async def run_async_tests():
22502269
await test_futures()
22512270
await test_cancel_subtask()
22522271
await test_self_empty()
2272+
await test_async_abi()
22532273

22542274
asyncio.run(run_async_tests())
22552275

0 commit comments

Comments
 (0)