-
Notifications
You must be signed in to change notification settings - Fork 116
feat: introduce await?
to short-circuit fulfilled async
futures
#5215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 17 commits
cb2d3a9
dabcb73
2c22f59
5e49632
2c9b66e
29a5626
5464929
cead471
45dc3fa
c342af0
a053eb8
57c340e
7701980
b8c54a8
891ae89
421bba0
f4432e2
8491185
19f48fc
e4c35ca
8123e9f
b9a64cd
923099c
eda49f2
1f4bb4d
0274330
633b1c0
cdbc376
7dd2f45
09ce9d7
32f6f2b
fcca72a
824eb80
c43a13e
ac3ca6e
7b7e7dc
7adf9b4
a7dd642
aa4e687
b0334e6
21b28b4
307681d
85378ab
0bae09f
982e6e9
7f5b78c
93367d6
582f570
05593e2
33e65e0
a23a938
ecab9f4
087c2c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,8 +162,9 @@ let asyncE s typ_bind e typ1 = | |
eff = T.(if s = Fut then Await else Triv) } | ||
} | ||
|
||
let awaitE s e = | ||
let awaitE e = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dead argument
ggreif marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let (s, _ , typ) = T.as_async (T.normalize (typ e)) in | ||
let s = match s with T.Cmp -> AwaitCmp | T.Fut -> AwaitFut false in | ||
{ it = PrimE (AwaitPrim s, [e]); | ||
at = no_region; | ||
note = Note.{ def with typ; eff = T.Await } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -253,7 +253,9 @@ and exp' at note = function | |
| T.Async (_, t, _) -> t | ||
| _ -> assert false) in | ||
(blockE ds { at; note; it }).it | ||
| S.AwaitE (s, e) -> I.PrimE (I.AwaitPrim s, [exp e]) | ||
| S.AwaitE (T.Cmp, e) when T.is_fut e.note.S.note_typ -> I.PrimE I.(AwaitPrim (AwaitFut true), [exp e]) | ||
| S.AwaitE (T.Cmp, e) -> I.PrimE I.(AwaitPrim AwaitCmp, [exp e]) | ||
| S.AwaitE (T.Fut, e) -> I.PrimE I.(AwaitPrim (AwaitFut false), [exp e]) | ||
| S.AssertE (Runtime, e) -> I.PrimE (I.AssertPrim, [exp e]) | ||
| S.AssertE (_, e) -> (unitE ()).it | ||
| S.AnnotE (e, _) -> assert false | ||
|
@@ -454,7 +456,7 @@ and call_system_func_opt name es obj_typ = | |
(primE (Ir.OtherPrim "trap") | ||
[textE "canister_inspect_message explicitly refused message"])) | ||
| "lowmemory" -> | ||
awaitE T.Cmp | ||
awaitE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused argument elided |
||
(callE (varE (var id.it note)) [T.scope_bound] (unitE())) | ||
| name -> | ||
let inst = match name with | ||
|
@@ -1193,7 +1195,7 @@ let import_compiled_class (lib : S.comp_unit) wasm : import_declaration = | |
(asyncE T.Fut | ||
(typ_arg c' T.Scope T.scope_bound) | ||
(letE principal | ||
(awaitE T.Cmp | ||
(awaitE | ||
(callE (varE install_actor_helper) cs' | ||
(tupE [ | ||
install_arg; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -364,10 +364,6 @@ func @new_async<T <: Any>() : (@Async<T>, @Cont<T>, @Cont<Error>, @CleanCont) { | |
|
||
var cleanup : @BailCont = @cleanup; | ||
ggreif marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func clean() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See the lambda in line 399. This reduces the closure size a bit. |
||
cleanup(); | ||
}; | ||
|
||
func enqueue(k : @Cont<T>, r : @Cont<Error>, b : @BailCont) : { | ||
#suspend; | ||
#schedule : () -> (); | ||
|
@@ -391,16 +387,16 @@ func @new_async<T <: Any>() : (@Async<T>, @Cont<T>, @Cont<Error>, @CleanCont) { | |
}; | ||
#suspend | ||
}; | ||
case (? (#ok (r, t))) { | ||
#schedule (func () { @refund := r; k(t) }); | ||
case (?#ok (r, t)) { | ||
#schedule (func() { @refund := r; k(t) }) | ||
}; | ||
case (? (#error e)) { | ||
#schedule (func () { r(e) }); | ||
case (?#error e) { | ||
#schedule (func _ = r(e)) | ||
}; | ||
}; | ||
}; | ||
|
||
(enqueue, fulfill, fail, clean) | ||
(enqueue, fulfill, fail, func() = cleanup()) | ||
}; | ||
|
||
// Subset of IC management canister interface required for our use | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
actor A { | ||
public func foo() : async Int { 42 }; | ||
public func go() : async Int { await* A.foo() } | ||
ggreif marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
A.go() //OR-CALL ingress go 0x4449444C0000 |
Uh oh!
There was an error while loading. Please reload this page.