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

Backend refactor: Move ActorScript name environment further down #430

Merged
merged 5 commits into from
May 21, 2019

Conversation

nomeata
Copy link
Collaborator

@nomeata nomeata commented May 17, 2019

compile.ml is mostly split into two parts:

  • the back-end leaning parts: Heap objects, functions on them etc.
  • the frontend-leaning parts: Traversing the AST, keeping track of the
    variable bindings etc.

But so far we had one environment for both aspects (e.g. storing names
for WebAssembly locals; keeping track of where AS variables are stored).
This has bothered me for a long time, and I finally pulled the band-aid:

  • E.t no longer has local_vars_env. In fact, E.t is only concerned
    with the bookkeeping needed to prodcue Wasm.

    Also env : E.t now only changes when going into a new Wasm function,
    no longer with every ActorScript scope. For some local go function,
    it no longer needs to be passed around.

  • There is a new environment ASEnv.t which only contains the
    ActorScript name and label environment. It is defined much futher
    down, and passed around separately by compile_exp etc.

    Only the ae : ASEnv.t changes when entering a scope, so only this
    needs to be threaded through patterns or declarations etc.

This also unbreaks the unholy nested type recursion through varloc. I
expect that I can simply the deferred_loc story now that this is
distangeled.

In theory we should be able to do open IR before the second part, but
we are not quite there yet.

Bitwise identical Wasm output with this change, according to
./compare-wat.

`compile.ml` is mostly split into two parts:
 * the back-end leaning parts: Heap objects, functions on them etc.
 * the frontend-leaning parts: Traversing the AST, keeping track of the
    variable bindings etc.

But so far we had one environment for both aspects (e.g. storing names
for WebAssembly locals; keeping track of where AS variables are stored).
This has bothered me for a long time, and I finally pulled the band-aid:

* `E.t` no longer has `local_vars_env`. In fact, `E.t` is only concerned
  with the bookkeeping needed to prodcue Wasm.

  Also `env : E.t` now only changes when going into a new _Wasm function_,
  no longer with every ActorScript scope. For some local `go` function,
  it no longer needs to be passed around.

* There is a new environment `ASEnv.t` which only contains the
  ActorScript name and label environment. It is defined much futher
  down, and passed around separately by `compile_exp` etc.

  Only the `ae : ASEnv.t` changes when entering a scope, so only this
  needs to be threaded through patterns or declartions etc.

This also unbreaks the unholy nested type recursion through `varloc`. I
expect that I can simply the `deferred_loc` story now that this is
distangeled.

In theory we should be able to do `open IR` before the second part, but
we are not quite there yet.

Bitwise identical Wasm output with this change, according to
`./compare-wat`.
@nomeata nomeata requested a review from ggreif May 17, 2019 12:38
@nomeata
Copy link
Collaborator Author

nomeata commented May 21, 2019

Gabor, can I have a review? This is a refactoring, so rather tedious to keep in a feature branch.

Copy link
Contributor

@ggreif ggreif left a comment

Choose a reason for hiding this comment

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

Looks reasonable, let's see how it affects in-flight PRs and branches.

src/compile.ml Outdated Show resolved Hide resolved
src/compile.ml Outdated Show resolved Hide resolved
src/compile.ml Outdated Show resolved Hide resolved
nomeata and others added 2 commits May 21, 2019 10:46
Co-Authored-By: Gabor Greif <[email protected]>
Co-Authored-By: Gabor Greif <[email protected]>
@nomeata nomeata added the automerge-squash When ready, merge (using squash) label May 21, 2019
@mergify mergify bot merged commit 1e4b624 into master May 21, 2019
@mergify mergify bot deleted the joachim/asenv branch May 21, 2019 08:53
@mergify mergify bot removed the automerge-squash When ready, merge (using squash) label May 21, 2019
nomeata added a commit that referenced this pull request May 27, 2019
this is possible since #430.

This refactor also opens the door for storing fixed-width numbers and
references in Wasm locals directly.

No change to the generated wasm code.
nomeata added a commit that referenced this pull request May 28, 2019
this is possible since #430.

This refactor also opens the door for storing fixed-width numbers and
references in Wasm locals directly.

No change to the generated wasm code.
dfinity-bot added a commit that referenced this pull request May 24, 2023
## Changelog for candid:
Branch: master
Commits: [dfinity/candid@f7166f47...9301221a](dfinity/candid@f7166f4...9301221)

* [`51c00478`](dfinity/candid@51c0047) spec: support composite query ([dfinity/candid⁠#420](https://togithub.com/dfinity/candid/issues/420))
* [`74869398`](dfinity/candid@7486939) fix recursion test ([dfinity/candid⁠#425](https://togithub.com/dfinity/candid/issues/425))
* [`eb31f888`](dfinity/candid@eb31f88) Use Arc<Type> with `arc_type` feature ([dfinity/candid⁠#407](https://togithub.com/dfinity/candid/issues/407))
* [`b9d6cbff`](dfinity/candid@b9d6cbf) support custom candid path for export_service ([dfinity/candid⁠#421](https://togithub.com/dfinity/candid/issues/421))
* [`fa29c70d`](dfinity/candid@fa29c70) Add config options for Rust binding ([dfinity/candid⁠#422](https://togithub.com/dfinity/candid/issues/422))
* [`f31396d8`](dfinity/candid@f31396d) Bump webpack from 5.24.4 to 5.76.0 in /tools/ui ([dfinity/candid⁠#413](https://togithub.com/dfinity/candid/issues/413))
* [`9301221a`](dfinity/candid@9301221) release ([dfinity/candid⁠#430](https://togithub.com/dfinity/candid/issues/430))
mergify bot pushed a commit that referenced this pull request May 24, 2023
## Changelog for candid:
Branch: master
Commits: [dfinity/candid@f7166f47...9301221a](dfinity/candid@f7166f4...9301221)

* [`51c00478`](dfinity/candid@51c0047) spec: support composite query ([dfinity/candid⁠#420](https://togithub.com/dfinity/candid/issues/420))
* [`74869398`](dfinity/candid@7486939) fix recursion test ([dfinity/candid⁠#425](https://togithub.com/dfinity/candid/issues/425))
* [`eb31f888`](dfinity/candid@eb31f88) Use Arc<Type> with `arc_type` feature ([dfinity/candid⁠#407](https://togithub.com/dfinity/candid/issues/407))
* [`b9d6cbff`](dfinity/candid@b9d6cbf) support custom candid path for export_service ([dfinity/candid⁠#421](https://togithub.com/dfinity/candid/issues/421))
* [`fa29c70d`](dfinity/candid@fa29c70) Add config options for Rust binding ([dfinity/candid⁠#422](https://togithub.com/dfinity/candid/issues/422))
* [`f31396d8`](dfinity/candid@f31396d) Bump webpack from 5.24.4 to 5.76.0 in /tools/ui ([dfinity/candid⁠#413](https://togithub.com/dfinity/candid/issues/413))
* [`9301221a`](dfinity/candid@9301221) release ([dfinity/candid⁠#430](https://togithub.com/dfinity/candid/issues/430))
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.

2 participants