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

optimisation: annotations to track (reads from) mutable declarations and adapt Ir.VarE #4637

Merged
merged 21 commits into from
Aug 2, 2024

Conversation

ggreif
Copy link
Contributor

@ggreif ggreif commented Jul 27, 2024

By making reads from mutable variables distinguishable, we restore the referential transparency of VarE (Const, id). This was the reason why #4611 failed (and had to be reverted in #4623).

This opens up a bunch of optimisation possibilities

  • VarE path compression
  • dead LetD elimination
  • BlockE/NewObjE simplification
  • nested BlockE merging (given the defs are disjoint and outer uses don't reference inner ones; use freevars.ml)
  • etc.

In the long run this may allow us to extend the IR effect system with {Load, Store} effects, and thus pave the way for transactional memory.

We now have a note on Syntax.VarE's identifier, being immutable by default. When performing type checking, this field can change to signify a mutable variable source after looking up the identifier in the environment. Then desugaring uses mutability info to create either IR.VarE (Const, _) (for immutable) or a`IR.VarE (Var, _) (for mutable). The IR type checker then asserts that the right kind of access is used.

The Wasm output should be unchanged.

NOTE: with this PR git revert 13d9d5748700662d30d54d6ccfcf2787deac482e can be done and it passes. So it seems to work 😀

@ggreif ggreif self-assigned this Jul 27, 2024
to preserve inference result
also tighten `VarE` subtyping
and make `varE` a bit smarter
Copy link

github-actions bot commented Jul 27, 2024

Comparing from b569bf9 to 31cf9cc:
The produced WebAssembly code seems to be completely unchanged.

@ggreif ggreif changed the title WIP: first draft of annotations and new MutReadPrim primitive optimisation: annotations to track mutable definitions and a new MutReadPrim primitive Jul 27, 2024
this is now an `idm` because it carries a sourcing mutability note

I am also asserting that the two mechanisms are equivalent,
so that in the next commit I can remove the annotation on `exp`.
@ggreif ggreif marked this pull request as ready for review July 29, 2024 11:18
src/mo_def/syntax.ml Outdated Show resolved Hide resolved
@ggreif ggreif changed the title optimisation: annotations to track mutable definitions and a new MutReadPrim primitive optimisation: annotations to track (reads from) mutable definitions and a new MutReadPrim primitive Jul 29, 2024
@ggreif ggreif changed the title optimisation: annotations to track (reads from) mutable definitions and a new MutReadPrim primitive optimisation: annotations to track (reads from) mutable declarations and a new MutReadPrim primitive Jul 30, 2024
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.

See comments - happy to discuss on zoom

in the next commit try removing the Prim

this is a review suggestiion
src/ir_passes/tailcall.ml Outdated Show resolved Hide resolved
@ggreif ggreif changed the title optimisation: annotations to track (reads from) mutable declarations and a new MutReadPrim primitive optimisation: annotations to track (reads from) mutable declarations and adapt Ir.VarE Aug 1, 2024
@ggreif ggreif requested review from crusso and dfx-json August 1, 2024 16:47
src/ir_def/check_ir.ml Outdated Show resolved Hide resolved
src/ir_def/check_ir.ml Show resolved Hide resolved
src/ir_def/construct.ml Outdated Show resolved Hide resolved
src/ir_passes/await.ml Show resolved Hide resolved
src/lowering/desugar.ml Outdated Show resolved Hide resolved
src/mo_def/syntax.ml Outdated Show resolved Hide resolved
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 (see minor suggestions)

ggreif and others added 4 commits August 2, 2024 17:53
@ggreif ggreif added the automerge-squash When ready, merge (using squash) label Aug 2, 2024
@mergify mergify bot merged commit 5ac33ad into master Aug 2, 2024
10 checks passed
@mergify mergify bot removed the automerge-squash When ready, merge (using squash) label Aug 2, 2024
@mergify mergify bot deleted the gabor/mut-VarE branch August 2, 2024 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants