Skip to content
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

WIP: use promises for actor environments #4741

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/mo_interpreter/interpret.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type lib_env = V.value V.Env.t
type lab_env = V.value V.cont V.Env.t
type ret_env = V.value V.cont option
type throw_env = V.value V.cont option
type actor_env = V.value V.Env.t ref (* indexed by actor ids *)
type actor_env = V.def V.Env.t ref (* indexed by actor ids *)

(* The actor heap.
NB: A cut-down ManagementCanister with id "" is added later, to enjoy access to logging facilities.
Expand Down Expand Up @@ -70,6 +70,8 @@ let env_of_scope flags ae scope =

let context env = V.Blob env.self

let defined f d = f (Lib.Promise.value d)

(* Error handling *)

exception Trap of Source.region * string
Expand All @@ -87,7 +89,7 @@ let lookup_actor env at aid id =
match V.Env.find_opt aid !(env.actor_env) with
| None -> trap at "Unknown actor \"%s\"" aid
| Some actor_value ->
let fs = V.as_obj actor_value in
let fs = defined V.as_obj actor_value in
match V.Env.find_opt id fs with
| None -> trap at "Actor \"%s\" has no method \"%s\"" aid id
| Some field_value -> field_value
Expand Down Expand Up @@ -907,7 +909,7 @@ and interpret_obj env obj_sort self_id dec_fields (k : V.value V.cont) =
let env'' = adjoin_vals { env' with self } ve_in in
interpret_dec_fields env'' dec_fields ve_ex
(fun obj ->
(env.actor_env := V.Env.add self obj !(env.actor_env);
(env.actor_env := V.Env.add self (Lib.Promise.make_fulfilled obj) !(env.actor_env);
k self'))
| _ ->
let ve_ex, ve_in = declare_dec_fields dec_fields V.Env.empty V.Env.empty in
Expand Down Expand Up @@ -1039,15 +1041,14 @@ let ensure_management_canister env =
V.Env.add
(* ManagementCanister with raw_rand (only) *)
""
(V.Obj
(V.Env.singleton "raw_rand"
(V.async_func (T.Write) 0 1
(fun c v k ->
async env
Source.no_region
(fun k' r ->
k' (V.Blob (V.Blob.rand32 ())))
k))))
V.(Obj
(Env.singleton "raw_rand"
(async_func T.Write 0 1
(fun c v k ->
async env
Source.no_region
(fun k' r -> k' (Blob (Blob.rand32 ())))
k))) |> Lib.Promise.make_fulfilled)
!(env.actor_env)

let interpret_prog flags scope p : (V.value * scope) option =
Expand Down
Loading