Skip to content

experiment: stable functions #5143

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

Draft
wants to merge 5 commits into
base: luc/stable-functions
Choose a base branch
from

Conversation

crusso
Copy link
Contributor

@crusso crusso commented May 15, 2025

additional tests

  • stable-class-bug.mo: demonstrates unsoundness of promoting generic stable functions to generic local functions.
  • stable-box-bug.mo: a simplified counter-example.

@crusso crusso requested a review from luc-blaeser May 15, 2025 10:38
@crusso crusso changed the base branch from master to luc/stable-functions May 15, 2025 10:39
Copy link

github-actions bot commented May 15, 2025

Comparing from bb2ae15 to 8a00c4a:
The produced WebAssembly code seems to be completely unchanged.

@crusso
Copy link
Contributor Author

crusso commented May 22, 2025

I added a renaming pass to ir_passes that renames all bound variables apart from @-prefixed ones that the code generator relies on (1c212ed).

As I expected, this appears to break eop, presumably because the free variable annotations on stable closures are not safe for renaming/alpha conversion. Broken, but probably fixable with some work:

I think the stable closure environment need to be represented as an explicit record, with fixed field names but alpha convertible values for each field. The closure body then has to rebind its free variables by pattern matching on the record of fixed field names. Or the moral equivalent of that.

The eop test that fail are

[nix-shell:~/motoko/test/run-drun]$ EXTRA_MOC_ARGS=--enhanced-orthogonal-persistence make
...
Some tests failed:
for-await.mo gc-random-test-force-gc.mo gc-random-test-no-force-gc.mo nested-generic-classes.mo nested-stable-functions.mo stable-box-bug.mo stable-captures-stable.mo stable-class-bug.mo stable-class.mo generic-stable-function.drun incompatible-stable-closure.drun life.drun life-mut.drun migrate-stable-function.drun reachable-stable-functions.drun

I'm pretty sure the tests all succeed when run without eop...checking now...

Yep:

[nix-shell:~/motoko/test/run-drun]$ make
../run.sh -d *.mo *.drun
WARNING: Could not run ic-ref-run, will skip running some tests
....
variant-upgrades:
All tests passed.

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.

1 participant