@@ -1868,12 +1868,14 @@ def lower_heap_values(cx, vs, ts, out_param):
18681868 tuple_value = {str (i): v for i,v in enumerate (vs)}
18691869 if out_param is None :
18701870 ptr = cx.opts.realloc(0 , 0 , alignment(tuple_type), elem_size(tuple_type))
1871+ flat_vals = [ptr]
18711872 else :
18721873 ptr = out_param.next(' i32' )
1874+ flat_vals = []
18731875 trap_if(ptr != align_to(ptr, alignment(tuple_type)))
18741876 trap_if(ptr + elem_size(tuple_type) > len (cx.opts.memory))
18751877 store(cx, tuple_value, tuple_type, ptr)
1876- return [ptr]
1878+ return flat_vals
18771879```
18781880The ` may_leave ` flag is guarded by ` canon_lower ` below to prevent a component
18791881from calling out of the component while in the middle of lowering, ensuring
@@ -2207,43 +2209,61 @@ component instance defining a resource can access its representation.
22072209
22082210For a canonical definition:
22092211``` wasm
2210- (canon task.start (core func $f))
2212+ (canon task.start $ft (core func $f))
22112213```
22122214validation specifies:
2213- * ` $f ` is given type ` (func (param i32)) `
2215+ * ` $f ` is given type ` $ft ` , which validation requires to be a (core) function type
22142216
22152217Calling ` $f ` invokes the following function which extracts the arguments from the
22162218caller and lowers them into the current instance:
22172219``` python
2218- async def canon_task_start (task , i ):
2220+ async def canon_task_start (task , core_ft , flat_args ):
2221+ assert (len (core_ft.params) == len (flat_args))
22192222 trap_if(task.opts.sync)
2223+ trap_if(core_ft != flatten_functype(CanonicalOptions(), FuncType([], task.ft.params), ' lower' ))
22202224 task.start()
2221- lower_async_values(task, task.start_thunk(), task.ft.param_types(), CoreValueIter([i]))
2222- return []
2225+ args = task.start_thunk()
2226+ flat_results = lower_sync_values(task, MAX_FLAT_RESULTS , args, task.ft.param_types(), CoreValueIter(flat_args))
2227+ assert (len (core_ft.results) == len (flat_results))
2228+ return flat_results
22232229```
2224- The call to the ` Task.start ` (defined above) ensures that ` canon task.start ` is
2225- called exactly once, before ` canon task.return ` , before an async call finishes.
2230+ An expected implementation of ` task.start ` would generate a core wasm function
2231+ for each lowering of an ` async ` -lifted export that performs the fused copy of
2232+ the arguments into the caller, storing the index of this function in the ` Task `
2233+ structure and using ` call_indirect ` to perform the function-type-equality check
2234+ required here. The call to ` Task.start ` (defined above) ensures that `canon
2235+ task.start` is called exactly once, before ` canon task.return`, before an async
2236+ call finishes.
22262237
22272238### 🔀 ` canon task.return `
22282239
22292240For a canonical definition:
22302241``` wasm
2231- (canon task.return (core func $f))
2242+ (canon task.return $ft (core func $f))
22322243```
22332244validation specifies:
2234- * ` $f ` is given type ` (func (param i32)) `
2245+ * ` $f ` is given type ` $ft ` , which validation requires to be a (core) function type
22352246
22362247Calling ` $f ` invokes the following function which lifts the results from the
22372248current instance and passes them to the caller:
22382249``` python
2239- async def canon_task_return (task , i ):
2250+ async def canon_task_return (task , core_ft , flat_args ):
2251+ assert (len (core_ft.params) == len (flat_args))
22402252 trap_if(task.opts.sync)
2253+ trap_if(core_ft != flatten_functype(CanonicalOptions(), FuncType(task.ft.results, []), ' lower' ))
22412254 task.return_()
2242- task.return_thunk(lift_async_values(task, CoreValueIter([i]), task.ft.result_types()))
2255+ results = lift_sync_values(task, MAX_FLAT_PARAMS , CoreValueIter(flat_args), task.ft.result_types())
2256+ task.return_thunk(results)
2257+ assert (len (core_ft.results) == 0 )
22432258 return []
22442259```
2245- The call to ` Task.return_ ` (defined above) ensures that ` canon task.return ` is
2246- called exactly once, after ` canon task.start ` , before an async call finishes.
2260+ An expected implementation of ` task.return ` would generate a core wasm function
2261+ for each lowering of an ` async ` -lifted export that performs the fused copy of
2262+ the results into the caller, storing the index of this function in the ` Task `
2263+ structure and using ` call_indirect ` to perform the function-type-equality check
2264+ required here. The call to ` Task.return_ ` (defined above) ensures that `canon
2265+ task.return` is called exactly once, after ` canon task.start`, before an async
2266+ call finishes.
22472267
22482268### 🔀 ` canon task.wait `
22492269
0 commit comments