@@ -257,12 +257,9 @@ options that affect how an overall function is lifted/lowered:
257257@dataclass
258258class CanonicalOptions (LiftLowerOptions ):
259259 post_return: Optional[Callable] = None
260- sync : bool = True # = !canonopt.async
260+ async_ : bool = False
261261 callback: Optional[Callable] = None
262262```
263- (Note that the ` async ` ` canonopt ` is inverted to ` sync ` here for the practical
264- reason that ` async ` is a keyword and most branches below want to start with the
265- ` sync = True ` case.)
266263
267264
268265### Runtime State
@@ -407,13 +404,13 @@ the `rt` field of `ResourceHandle` (above) and thus resource type equality is
407404class ResourceType (Type ):
408405 impl: ComponentInstance
409406 dtor: Optional[Callable]
410- dtor_sync : bool
407+ dtor_async : bool
411408 dtor_callback: Optional[Callable]
412409
413- def __init__ (self , impl , dtor = None , dtor_sync = True , dtor_callback = None ):
410+ def __init__ (self , impl , dtor = None , dtor_async = False , dtor_callback = None ):
414411 self .impl = impl
415412 self .dtor = dtor
416- self .dtor_sync = dtor_sync
413+ self .dtor_async = dtor_async
417414 self .dtor_callback = dtor_callback
418415```
419416
@@ -865,7 +862,7 @@ synchronously or with `async callback`. This predicate is used by the other
865862` exclusive ` lock.
866863``` python
867864 def needs_exclusive (self ):
868- return self .opts.sync or self .opts.callback
865+ return not self .opts.async_ or self .opts.callback
869866
870867```
871868
@@ -2642,7 +2639,7 @@ MAX_FLAT_RESULTS = 1
26422639def flatten_functype (opts , ft , context ):
26432640 flat_params = flatten_types(ft.param_types())
26442641 flat_results = flatten_types(ft.result_type())
2645- if opts.sync :
2642+ if not opts.async_ :
26462643 if len (flat_params) > MAX_FLAT_PARAMS :
26472644 flat_params = [' i32' ]
26482645 if len (flat_results) > MAX_FLAT_RESULTS :
@@ -3176,7 +3173,7 @@ function can free any associated allocations. Since `Task.enter` acquired the
31763173synchronous functions cannot overlap execution; attempts by callers to make
31773174overlapping calls will result in backpressure in ` Task.enter ` .
31783175``` python
3179- if opts.sync :
3176+ if not opts.async_ :
31803177 flat_results = call_and_trap_on_throw(callee, thread, flat_args)
31813178 assert (types_match_values(flat_ft.results, flat_results))
31823179 result = lift_flat_values(cx, MAX_FLAT_RESULTS , CoreValueIter(flat_results), ft.result_type())
@@ -3363,7 +3360,7 @@ above).
33633360 assert (types_match_values(flat_ft.params, flat_args))
33643361 flat_args = CoreValueIter(flat_args)
33653362
3366- if opts.sync :
3363+ if not opts.async_ :
33673364 max_flat_params = MAX_FLAT_PARAMS
33683365 max_flat_results = MAX_FLAT_RESULTS
33693366 else :
@@ -3416,7 +3413,7 @@ synchronous then (since `post-return` is prevented from blocking via
34163413value and thus the implementation can avoid the creation of any ` Thread ` and
34173414use a plain synchronous function call instead, as expected.
34183415``` python
3419- if opts.sync :
3416+ if not opts.async_ :
34203417 if not subtask.resolved():
34213418 thread.suspend_until(subtask.resolved)
34223419 assert (types_match_values(flat_ft.results, flat_results))
@@ -3504,23 +3501,23 @@ Calling `$f` invokes the following function, which removes the handle from the
35043501current component instance's table and, if the handle was owning, calls the
35053502resource's destructor.
35063503``` python
3507- def canon_resource_drop (rt , sync , thread , i ):
3504+ def canon_resource_drop (rt , async_ , thread , i ):
35083505 trap_if(not thread.task.inst.may_leave)
35093506 inst = thread.task.inst
35103507 h = inst.table.remove(i)
35113508 trap_if(not isinstance (h, ResourceHandle))
35123509 trap_if(h.rt is not rt)
35133510 trap_if(h.num_lends != 0 )
3514- flat_results = [] if sync else [0 ]
3511+ flat_results = [] if not async_ else [0 ]
35153512 if h.own:
35163513 assert (h.borrow_scope is None )
35173514 if inst is rt.impl:
35183515 if rt.dtor:
35193516 rt.dtor(h.rep)
35203517 else :
35213518 if rt.dtor:
3522- caller_opts = CanonicalOptions(sync = sync )
3523- callee_opts = CanonicalOptions(sync = rt.dtor_sync , callback = rt.dtor_callback)
3519+ caller_opts = CanonicalOptions(async_ = async_ )
3520+ callee_opts = CanonicalOptions(async_ = rt.dtor_async , callback = rt.dtor_callback)
35243521 ft = FuncType([U32Type()],[])
35253522 callee = partial(canon_lift, callee_opts, rt.impl, ft, rt.dtor)
35263523 flat_results = canon_lower(caller_opts, ft, callee, thread, [h.rep])
@@ -3684,15 +3681,15 @@ wasm state and passes them to the [current task]'s caller via `Task.return_`:
36843681def canon_task_return (thread , result_type , opts : LiftOptions, flat_args ):
36853682 task = thread.task
36863683 trap_if(not task.inst.may_leave)
3687- trap_if(task.opts.sync )
3684+ trap_if(not task.opts.async_ )
36883685 trap_if(result_type != task.ft.result)
36893686 trap_if(not LiftOptions.equal(opts, task.opts))
36903687 cx = LiftLowerContext(opts, task.inst, task)
36913688 result = lift_flat_values(cx, MAX_FLAT_PARAMS , CoreValueIter(flat_args), task.ft.result_type())
36923689 task.return_(result)
36933690 return []
36943691```
3695- The ` trap_if(task.opts.sync ) ` prevents ` task.return ` from being called by
3692+ The ` trap_if(not task.opts.async_ ) ` prevents ` task.return ` from being called by
36963693synchronously-lifted functions (which return their value by returning from the
36973694lifted core function).
36983695
@@ -3731,11 +3728,11 @@ request made by a supertask and claiming that all `borrow` handles lent to the
37313728def canon_task_cancel (thread ):
37323729 task = thread.task
37333730 trap_if(not task.inst.may_leave)
3734- trap_if(task.opts.sync )
3731+ trap_if(not task.opts.async_ )
37353732 task.cancel()
37363733 return []
37373734```
3738- The ` trap_if(task.opts.sync ) ` prevents ` task.cancel ` from being called by
3735+ The ` trap_if(not task.opts.async_ ) ` prevents ` task.cancel ` from being called by
37393736synchronously-lifted functions (which must always return a value by returning
37403737from the lifted core function).
37413738
@@ -3922,7 +3919,7 @@ the event payload of a future `SUBTASK` event.
39223919``` python
39233920BLOCKED = 0x ffff_ffff
39243921
3925- def canon_subtask_cancel (sync , thread , i ):
3922+ def canon_subtask_cancel (async_ , thread , i ):
39263923 trap_if(not thread.task.inst.may_leave)
39273924 subtask = thread.task.inst.table.get(i)
39283925 trap_if(not isinstance (subtask, Subtask))
@@ -3934,7 +3931,7 @@ def canon_subtask_cancel(sync, thread, i):
39343931 subtask.cancellation_requested = True
39353932 subtask.callee.request_cancellation()
39363933 if not subtask.resolved():
3937- if sync :
3934+ if not async_ :
39383935 thread.suspend_until(subtask.resolved)
39393936 else :
39403937 return [BLOCKED ]
@@ -4105,7 +4102,7 @@ be returned. Otherwise, asynchronous calls deliver the event if it was produced
41054102synchronously and return ` BLOCKED ` if not:
41064103``` python
41074104 if not e.has_pending_event():
4108- if opts.sync :
4105+ if not opts.async_ :
41094106 e.state = CopyState.SYNC_COPYING
41104107 thread.suspend_until(e.has_pending_event)
41114108 else :
@@ -4187,11 +4184,11 @@ of elements copied is not packed in the high 28 bits; they're always zero.
41874184 e.copy(thread.task.inst, buffer, on_copy_done)
41884185```
41894186
4190- The end of ` future_copy ` is the exact same as ` stream_copy ` : waiting if ` sync `
4191- and returning either the progress made or ` BLOCKED ` .
4187+ The end of ` future_copy ` is the exact same as ` stream_copy ` : waiting if called
4188+ synchronously and returning either the progress made or ` BLOCKED ` .
41924189``` python
41934190 if not e.has_pending_event():
4194- if opts.sync :
4191+ if not opts.async_ :
41954192 e.state = CopyState.SYNC_COPYING
41964193 thread.suspend_until(e.has_pending_event)
41974194 else :
@@ -4220,19 +4217,19 @@ validation specifies:
42204217The implementation of these four built-ins all funnel down to a single
42214218parameterized ` cancel_copy ` function:
42224219``` python
4223- def canon_stream_cancel_read (stream_t , sync , thread , i ):
4224- return cancel_copy(ReadableStreamEnd, EventCode.STREAM_READ , stream_t, sync , thread, i)
4220+ def canon_stream_cancel_read (stream_t , async_ , thread , i ):
4221+ return cancel_copy(ReadableStreamEnd, EventCode.STREAM_READ , stream_t, async_ , thread, i)
42254222
4226- def canon_stream_cancel_write (stream_t , sync , thread , i ):
4227- return cancel_copy(WritableStreamEnd, EventCode.STREAM_WRITE , stream_t, sync , thread, i)
4223+ def canon_stream_cancel_write (stream_t , async_ , thread , i ):
4224+ return cancel_copy(WritableStreamEnd, EventCode.STREAM_WRITE , stream_t, async_ , thread, i)
42284225
4229- def canon_future_cancel_read (future_t , sync , thread , i ):
4230- return cancel_copy(ReadableFutureEnd, EventCode.FUTURE_READ , future_t, sync , thread, i)
4226+ def canon_future_cancel_read (future_t , async_ , thread , i ):
4227+ return cancel_copy(ReadableFutureEnd, EventCode.FUTURE_READ , future_t, async_ , thread, i)
42314228
4232- def canon_future_cancel_write (future_t , sync , thread , i ):
4233- return cancel_copy(WritableFutureEnd, EventCode.FUTURE_WRITE , future_t, sync , thread, i)
4229+ def canon_future_cancel_write (future_t , async_ , thread , i ):
4230+ return cancel_copy(WritableFutureEnd, EventCode.FUTURE_WRITE , future_t, async_ , thread, i)
42344231
4235- def cancel_copy (EndT , event_code , stream_or_future_t , sync , thread , i ):
4232+ def cancel_copy (EndT , event_code , stream_or_future_t , async_ , thread , i ):
42364233 trap_if(not thread.task.inst.may_leave)
42374234 e = thread.task.inst.table.get(i)
42384235 trap_if(not isinstance (e, EndT))
@@ -4241,7 +4238,7 @@ def cancel_copy(EndT, event_code, stream_or_future_t, sync, thread, i):
42414238 if not e.has_pending_event():
42424239 e.shared.cancel()
42434240 if not e.has_pending_event():
4244- if sync :
4241+ if not async_ :
42454242 thread.suspend_until(e.has_pending_event)
42464243 else :
42474244 return [BLOCKED ]
0 commit comments