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

feat: allow access to Self and its public methods from actor initialisers #4719

Merged
merged 74 commits into from
Oct 17, 2024

Conversation

ggreif
Copy link
Contributor

@ggreif ggreif commented Sep 30, 2024

This PR accomplishes following improvements:

  • allow actor Self { ... Self ... } in the actor initialiser (similarly for actor class)
  • ditto for accessing all public methods Self.method from the actor initialiser
  • accessing these from under lambdas without making the respective methods undefined when using them

The latter should allow setting up timers: addTimer(b, period, Self.method) from actor initialiser.

Also fixes the hole in definedness analysis (#4731).


NOTES:

  • calling Self.method from actor initialiser is prohibited by the capability checker
  • accessing Self.method from actor initialiser is currently allowed when method is not defined yet, and results in a descriptor (pair)
  • comparison (in terms of shared) of the internal methods with external methods is trapping in the interpreter, but should work in the deployed actor.

There is an idea inside to fix these problems.


TODO:

Copy link

github-actions bot commented Oct 2, 2024

Comparing from d8e8726 to dfee0b2:
In terms of gas, no changes are observed in 5 tests.
In terms of size, no changes are observed in 5 tests.

let env' = adjoin_vals { env with self = self } ve_in in
interpret_dec_fields env' dec_fields ve_ex
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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Crazy idea: At the moment, the actor environment maps actor ids to Objects containing a map from field names to values.
Suppose we changed that, so an actor environment just contains a map from field names to promises (i.e. ve_ex).
Then we can update the actor map before we interpret the body. As the promises in ve_ex get defined, so do the ones accessible from the self-reference, a bit like your previous 'increments' but automatic.
I think that might let us implement the equality on mixtures of symbolic and function references (provided we also give the equality operator) access to the environment.

Best attempted in a separate PR I think. Might be a dead-end with too many pervasive changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On first look this might work, the callback could simply define the method as interpret_obj is iterating over the decs.

Comment on lines +241 to +242
| Func _, Tup [Blob _; Text _]
| Tup [Blob _; Text _], Func _ -> assert false; (* mixed, cannot determine equality *)
Copy link
Contributor

Choose a reason for hiding this comment

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

If equality had access to the actor env then we could probably do better here and maybe even get it right (see above)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but I wouldn't hold my breath.

@crusso crusso mentioned this pull request Oct 16, 2024
ggreif and others added 6 commits October 16, 2024 09:48
* fix for ir_interpreter

* typos

* refactor

* Update src/ir_interpreter/interpret_ir.ml

* Update src/lowering/desugar.ml

* update output

* revert changes since real bug was elsewhere in lowering

* update test output

* delete unused declared_defined_id

* missing test file
* fix for ir_interpreter

* typos

* refactor

* Update src/ir_interpreter/interpret_ir.ml

* Update src/lowering/desugar.ml

* update output

* revert changes since real bug was elsewhere in lowering

* update test output

* deal with self

* refactor

* delete unused declared_defined_id

* delete unused declared_defined_id

* missing test file

---------

Co-authored-by: Gabor Greif <[email protected]>
@ggreif ggreif requested a review from crusso October 17, 2024 17:40
caller(Self.method);
caller(method);
debugPrint (debug_show(principalOfActor Self));
debugPrint "So far so good!";
Copy link
Contributor

Choose a reason for hiding this comment

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

Strange, this one doesn't generate a a type error about trailing
debugPrint, but pass-class-self does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, very bizarre.

Copy link
Contributor

@crusso crusso left a comment

Choose a reason for hiding this comment

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

LGTM. Can you open an issue to improve function equality in the interpreters in future?

@crusso
Copy link
Contributor

crusso commented Oct 17, 2024

Users should appreciate this...

@ggreif
Copy link
Contributor Author

ggreif commented Oct 17, 2024

LGTM. Can you open an issue to improve function equality in the interpreters in future?

Yeah, already did: #4732.

@ggreif ggreif added the automerge-squash When ready, merge (using squash) label Oct 17, 2024
@mergify mergify bot merged commit 0a0eb38 into master Oct 17, 2024
10 checks passed
@mergify mergify bot deleted the gabor/pass-self branch October 17, 2024 21:21
@mergify mergify bot removed the automerge-squash When ready, merge (using squash) label Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: actor self reference oddity
2 participants