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

experiment: simpler version of claudio/self-pass #4735

Merged
merged 12 commits into from
Oct 17, 2024
13 changes: 6 additions & 7 deletions src/ir_interpreter/interpret_ir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,7 @@ and interpret_exp_mut env exp (k : V.value V.cont) =
| None -> trap exp.at "accessing identifier before its definition"
)
| LitE lit ->
k (interpret_lit env lit)
| PrimE (ActorDotPrim n, [{ it = VarE (_, actor); _ }]) when not(Lib.Promise.is_fulfilled (find actor env.vals)) ->
(* actor not defined yet, just pair them up *)
k V.(Tup [Blob (env.self); Text n])
k (interpret_lit env lit)
| PrimE (p, es) ->
interpret_exps env es [] (fun vs ->
match p, vs with
Expand Down Expand Up @@ -587,13 +584,13 @@ and interpret_exp_mut env exp (k : V.value V.cont) =

and interpret_actor env ds fs k =
let self = V.fresh_id () in
let env0 = {env with self} in
let self' = V.Blob self in
let ve = declare_decs ds V.Env.empty in
let env' = adjoin_vals env0 ve in
let env' = adjoin_vals { env with self } ve in
interpret_decs env' ds (fun _ ->
let obj = interpret_fields env' fs in
env.actor_env := V.Env.add self obj !(env.actor_env);
k (V.Blob self)
k self'
)

and interpret_lexp env lexp (k : (V.value ref) V.cont) =
Expand Down Expand Up @@ -691,6 +688,8 @@ and declare_pats pats ve : val_env =
let ve' = declare_pat pat in
declare_pats pats' (V.Env.adjoin ve ve')

and declare_defined_id id v =
V.Env.singleton id (Lib.Promise.make_fulfilled v)

and define_id env id v =
Lib.Promise.fulfill (find id env.vals) v
Expand Down
7 changes: 4 additions & 3 deletions src/lowering/desugar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ and exp' at note = function
(breakE "!" (nullE()))
(* case ? v : *)
(varP v) (varE v) ty).it
| S.ObjBlockE (s, _t, dfs) ->
obj_block at s None dfs note.Note.typ
| S.ObjBlockE (s, (self_id_opt,_), dfs) ->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the bug, which was failing to introduce a the self declaration for some cases.

obj_block at s self_id_opt dfs note.Note.typ
| S.ObjE (bs, efs) ->
obj note.Note.typ efs bs
| S.TagE (c, e) -> (tagE c.it (exp e)).it
Expand Down Expand Up @@ -562,7 +562,8 @@ and build_actor at ts self_id es obj_typ =
[expD (assignE state (nullE()))]
in
let ds' = match self_id with
| Some n -> with_self n.it obj_typ ds
| Some n ->
with_self n.it obj_typ ds
| None -> ds in
let meta =
I.{ candid = candid;
Expand Down
6 changes: 4 additions & 2 deletions src/mo_interpreter/interpret.ml
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,9 @@ and declare_pat_fields pfs ve : val_env =
let ve' = declare_pat pf.it.pat in
declare_pat_fields pfs' (V.Env.adjoin ve ve')

and declare_defined_id id v =
V.Env.singleton id.it (Lib.Promise.make_fulfilled v)

and define_id env id v =
define_id' env id.it v

Expand Down Expand Up @@ -898,9 +901,8 @@ and interpret_obj env obj_sort self_id dec_fields (k : V.value V.cont) =
let self' = V.Blob self in
(* Define self_id eagerly *)
let env' = match self_id with
| Some id -> adjoin_vals env (declare_id id)
| Some id -> adjoin_vals env (declare_defined_id id self')
| None -> env in
Option.iter (fun id -> define_id env' id self') self_id;
let ve_ex, ve_in = declare_dec_fields dec_fields V.Env.empty V.Env.empty in
let env'' = adjoin_vals { env' with self } ve_in in
interpret_dec_fields env'' dec_fields ve_ex
Expand Down
3 changes: 1 addition & 2 deletions test/run-drun/pass-class-self.mo
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ actor class C() = Self {
ignore principalOfActor Self;
caller(Self.method);
caller(method);
//debugPrint (debug_show(principalOfActor Self));
//debugPrint "So far so good!";
ignore debugPrint (debug_show(principalOfActor Self));
}
Loading