-
Notifications
You must be signed in to change notification settings - Fork 98
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
feat: allow access to Self
and its public methods from actor
initialisers
#4719
base: master
Are you sure you want to change the base?
Changes from all commits
66fae26
e5e84ee
84de9b2
49d7f1e
b5ae4a8
e2e0255
bfbb6b9
f2c047a
3a51fa8
cfe59f0
8933498
d558928
b3e5917
c776e5e
60f4efc
3490b61
66b0ecc
c4f8c15
bb3e9a1
9a2efc7
c14f3b1
53d5f84
af3fb01
744e3ee
635ec3c
63c5779
88c4b40
d14834a
c7ffd49
d9d5b2b
a8946e7
3afe689
69290a6
b1cd79c
d2e0f1c
431900a
0ae91a8
f605a45
879fc73
df56bd9
a0e613b
88023fc
76d3d1a
54bb508
6ce2ceb
83cca50
58a5aae
0e09b59
9da4dde
a883087
b4f1410
21e1429
bead5c9
2eb4457
7e74d0c
d566c65
454621f
9b3897e
e6b4993
afbb127
548c832
414f14d
4459be7
aa0e7d5
6abf618
fd53c84
de19de5
b6d40bd
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 |
---|---|---|
|
@@ -84,55 +84,55 @@ let rec exp msgs e : f = match e.it with | |
(* Or anything that is occurring in a call (as this may call a closure): *) | ||
| CallE (e1, ts, e2) -> eagerify (exps msgs [e1; e2]) | ||
(* And break, return, throw can be thought of as calling a continuation: *) | ||
| BreakE (i, e) -> eagerify (exp msgs 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. no changed semantics in this function, just cleanups |
||
| RetE e -> eagerify (exp msgs e) | ||
| BreakE (_, e) | ||
| RetE e | ||
| ThrowE e -> eagerify (exp msgs e) | ||
(* Uses are delayed by function expressions *) | ||
| FuncE (_, sp, tp, p, t, _, e) -> | ||
delayify ((exp msgs e /// pat msgs p) /// shared_pat msgs sp) | ||
delayify ((exp msgs e /// pat msgs p) /// shared_pat msgs sp) | ||
| ObjBlockE (s, (self_id_opt, _), dfs) -> | ||
group msgs ~extern:self_id_opt (dec_fields msgs dfs) | ||
(* The rest remaining cases just collect the uses of subexpressions: *) | ||
| LitE _ | ActorUrlE _ | ||
| LitE _ | ||
| PrimE _ | ImportE _ -> M.empty | ||
| UnE (_, uo, e) -> exp msgs e | ||
| BinE (_, e1, bo, e2)-> exps msgs [e1; e2] | ||
| RelE (_, e1, ro, e2)-> exps msgs [e1; e2] | ||
| ShowE (_, e) -> exp msgs e | ||
| ToCandidE es -> exps msgs es | ||
| FromCandidE e -> exp msgs e | ||
| TupE es -> exps msgs es | ||
| ProjE (e, i) -> exp msgs e | ||
| ObjBlockE (s, _, dfs) -> | ||
(* For actors, this may be too permissive; to be revised when we work on actors again *) | ||
group msgs (dec_fields msgs dfs) | ||
| ObjE (bases, efs) -> exps msgs bases ++ exp_fields msgs efs | ||
| DotE (e, i) -> exp msgs e | ||
| AssignE (e1, e2) -> exps msgs [e1; e2] | ||
| ArrayE (m, es) -> exps msgs es | ||
| IdxE (e1, e2) -> exps msgs [e1; e2] | ||
| TupE es | ||
| ArrayE (_, es) | ||
| ToCandidE es -> exps msgs es | ||
| BlockE ds -> group msgs (decs msgs ds) | ||
| NotE e -> exp msgs e | ||
| AndE (e1, e2) -> exps msgs [e1; e2] | ||
| OrE (e1, e2) -> exps msgs [e1; e2] | ||
| ImpliesE (e1, e2) -> exps msgs [e1; e2] | ||
| OldE e -> exp msgs e | ||
| IfE (e1, e2, e3) -> exps msgs [e1; e2; e3] | ||
| SwitchE (e, cs) -> exp msgs e ++ cases msgs cs | ||
| SwitchE (e, cs) | ||
| TryE (e, cs, None) -> exp msgs e ++ cases msgs cs | ||
| TryE (e, cs, Some f)-> exps msgs [e; f] ++ cases msgs cs | ||
| WhileE (e1, e2) -> exps msgs [e1; e2] | ||
| LoopE (e1, None) -> exp msgs e1 | ||
| LoopE (e1, Some e2) -> exps msgs [e1; e2] | ||
| LoopE (e1, Some e2) | ||
| WhileE (e1, e2) | ||
| AssignE (e1, e2) | ||
| IdxE (e1, e2) | ||
| BinE (_, e1, _, e2) | ||
| RelE (_, e1, _, e2) | ||
| AndE (e1, e2) | ||
| OrE (e1, e2) | ||
| ImpliesE (e1, e2) -> exps msgs [e1; e2] | ||
| ForE (p, e1, e2) -> exp msgs e1 ++ (exp msgs e2 /// pat msgs p) | ||
| LabelE (i, t, e) -> exp msgs e | ||
| DebugE e -> exp msgs e | ||
| AsyncE (_, _, e) -> exp msgs e | ||
| AwaitE (_, e) -> exp msgs e | ||
| AssertE (_, e) -> exp msgs e | ||
| AnnotE (e, t) -> exp msgs e | ||
| OptE e -> exp msgs e | ||
| DoOptE e -> exp msgs e | ||
| BangE e -> exp msgs e | ||
| TagE (_, e) -> exp msgs e | ||
| UnE (_, _, e) | ||
| ShowE (_, e) | ||
| FromCandidE e | ||
| DotE (e, _) | ||
| ProjE (e, _) | ||
| NotE e | ||
| OldE e | ||
| LabelE (_, _, e) | ||
| DebugE e | ||
| AsyncE (_, _, e) | ||
| AwaitE (_, e) | ||
| AssertE (_, e) | ||
| AnnotE (e, _) | ||
| OptE e | ||
| DoOptE e | ||
| BangE e | ||
| TagE (_, e) | ||
| ActorUrlE e | ||
ggreif marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| IgnoreE e -> exp msgs e | ||
|
||
and exps msgs es : f = unions (exp msgs) es | ||
|
@@ -178,12 +178,15 @@ and dec msgs d = match d.it with | |
| VarD (i, e) -> (M.empty, S.singleton i.it) +++ exp msgs e | ||
| TypD (i, tp, t) -> (M.empty, S.empty) | ||
| ClassD (csp, i, tp, p, t, s, i', dfs) -> | ||
let extern = if s.it = Type.Actor then Some i' else None in | ||
(M.empty, S.singleton i.it) +++ delayify ( | ||
group msgs (dec_fields msgs dfs @ class_self d.at i') /// pat msgs p /// shared_pat msgs csp | ||
group msgs ~extern (dec_fields msgs dfs @ class_self d.at i' s.it) /// pat msgs p /// shared_pat msgs csp | ||
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. Instead of adding the ~extern optional parameter, why not just add (class_self ... ) to beginning or end of the decs argument, depending on whether this is an 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. (and then rename class_self to obj_self...) 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. Well, that would break
right? See also the discussion in #1104. 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. Ok, I had a go - you are right about the shadowing but that's possible to account for #4736 |
||
) | ||
|
||
(* The class self binding is treated as defined at the very end of the group *) | ||
and class_self at i : group = [(at, S.singleton i.it, S.empty, S.empty)] | ||
and class_self at i : Type.obj_sort -> group = function | ||
| Type.Actor -> [] | ||
| _ -> [(at, S.singleton i.it, S.empty, S.empty)] | ||
|
||
and decs msgs decs : group = | ||
(* Annotate the declarations with the analysis results *) | ||
|
@@ -192,9 +195,13 @@ and decs msgs decs : group = | |
(d.at, defs, eager_vars f, delayed_vars f) | ||
) decs | ||
|
||
and group msgs (grp : group) : f = | ||
and group msgs ?(extern=None) (grp : group) : f = | ||
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. this is the meat |
||
(* Create a map from declared variable to their definition point *) | ||
let defWhen = M.disjoint_unions (List.mapi (fun i (_, defs, _, _) -> map_of_set i defs) grp) in | ||
(* Insert the externally defined binding in front if present, non-shadowing *) | ||
let defWhen = match extern with | ||
| Some b when M.find_opt b.it defWhen |> Option.is_none -> M.add b.it (-1) defWhen | ||
| _ -> defWhen in | ||
Comment on lines
+201
to
+204
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. You might not need this if you just extend the decs appropriately, |
||
(* Calculate the relation R *) | ||
let r = NameRel.unions (List.map (fun (_, defs, _, delayed) -> NameRel.cross defs delayed) grp) in | ||
(* Check for errors *) | ||
|
@@ -242,4 +249,3 @@ let check_lib lib = | |
ignore (group msgs (decs msgs (imp_ds @ ds))); | ||
Some () | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure you need this? If the actor's self_id is bound in the value environment, there should be no need to special case this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am pretty sure I need it (not that I like it!), but I'll double-check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using
env.self
by guessing is a bit sick, I agree... (but it made my boat to float)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When doing
when false && not...
I getin both
incomplete-self-reference.run-ir
andincomplete-self-reference.run-low
.Trying to fix this now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand yet,
.run-ir
traces asbut here is the IR-dump: