Skip to content

Compiler dependency analysis#95

Merged
nomeata merged 17 commits intomasterfrom
compiler-dep-anal
Dec 7, 2018
Merged

Compiler dependency analysis#95
nomeata merged 17 commits intomasterfrom
compiler-dep-anal

Conversation

@nomeata
Copy link
Contributor

@nomeata nomeata commented Dec 1, 2018

Building on the extended usage analysis in #84, the compiler is now smarter about what needs to be put on the heap and what not. Main perks:

  • mutually recursive closed functions (like odd and even in mutrec.as) are now just static functions with direct calls
  • much less heap allocations, local variables are put in WebAssembly locals unless they are captured and mutable

I am not actively asking for a review of this, just parking it here until #84 has been reviewed and merged.

Turns out this is super simple once we have the annotated information
from `freeVars.ml`, and does not even have to distinguish the various
forms for declaration.

This fixes #74.

All tests go through, so it does not seem to be overly restrictive. It
could certainly need more tests and some eyeballs if it is actually
sound.
this is of course conservative, but good enough for the code that we
have.
When compiling a (recursive) block, we need to do a dependency analysis, to
find out which names need to be heap-allocated, which local-allocated and which
are simply static functions. The rules are:
- functions are static, unless they capture something that is not a static function
- everything that is captured before it is defined needs to be heap-allocated,
  unless it is a static function
- everything that is mutable and captures needs to be heap-allocated

Immutable things are always pointers or unboxed scalars, and can be put into
closures as such.
so beef up freevars.ml to distinguish this.
@nomeata nomeata self-assigned this Dec 1, 2018
@nomeata nomeata mentioned this pull request Dec 1, 2018
@nomeata nomeata merged commit 2480c81 into master Dec 7, 2018
@nomeata nomeata deleted the compiler-dep-anal branch December 7, 2018 10:56
dfinity-bot added a commit that referenced this pull request Oct 28, 2020
## Changelog for candid:
Branch: 
Commits: [dfinity/candid@a1dcbad4...3e3ad95a](dfinity/candid@a1dcbad...3e3ad95)

* [`119703ba`](dfinity/candid@119703b) [Spec] Relax LEB128 decoding ([dfinity/candid⁠#79](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/79))
* [`10f08432`](dfinity/candid@10f0843) Update prim.test.did
* [`b2524816`](dfinity/candid@b252481) parser for test suite ([dfinity/candid⁠#78](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/78))
* [`71bf6e76`](dfinity/candid@71bf6e7) release 0.5.2 ([dfinity/candid⁠#80](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/80))
* [`b9f387e3`](dfinity/candid@b9f387e) test suite for JS ([dfinity/candid⁠#81](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/81))
* [`9e5dc775`](dfinity/candid@9e5dc77) Release ([dfinity/candid⁠#82](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/82))
* [`1df9d2d7`](dfinity/candid@1df9d2d) more candid test data ([dfinity/candid⁠#83](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/83))
* [`9e4156d9`](dfinity/candid@9e4156d) fix newtype ([dfinity/candid⁠#85](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/85))
* [`6880a430`](dfinity/candid@6880a43) display for types ([dfinity/candid⁠#86](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/86))
* [`04b1b068`](dfinity/candid@04b1b06) release ([dfinity/candid⁠#87](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/87))
* [`117c6436`](dfinity/candid@117c643) Refactor Lexer ([dfinity/candid⁠#89](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/89))
* [`0a5789f9`](dfinity/candid@0a5789f) fix value pretty printer ([dfinity/candid⁠#92](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/92))
* [`9f35a5aa`](dfinity/candid@9f35a5a) refactor error ([dfinity/candid⁠#94](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/94))
* [`2e742927`](dfinity/candid@2e74292) Parse annvals in textual format ([dfinity/candid⁠#93](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/93))
* [`0a144c79`](dfinity/candid@0a144c7) use principal from ic-types ([dfinity/candid⁠#84](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/84))
* [`01412b14`](dfinity/candid@01412b1) release ([dfinity/candid⁠#95](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/95))
* [`f540df54`](dfinity/candid@f540df5) release ([dfinity/candid⁠#98](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/98))
* [`798675d8`](dfinity/candid@798675d) Add generic functions to encode/decode around a tuple ([dfinity/candid⁠#99](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/99))
* [`0d26e568`](dfinity/candid@0d26e56) release ([dfinity/candid⁠#100](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/100))
* [`191b6f1f`](dfinity/candid@191b6f1) Reset record_nesting_depth after each value ([dfinity/candid⁠#101](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/101))
* [`8e7be65d`](dfinity/candid@8e7be65) fix record ([dfinity/candid⁠#103](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/103))
* [`159533b2`](dfinity/candid@159533b) Update construct.test.did
* [`a6ea0991`](dfinity/candid@a6ea099) add service initialization parameters ([dfinity/candid⁠#88](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/88))
* [`3a1f56fa`](dfinity/candid@3a1f56f) refactor: sort dependencies and add traits for error types ([dfinity/candid⁠#105](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/105))
* [`89df78ee`](dfinity/candid@89df78e) support service constructor ([dfinity/candid⁠#106](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/106))
* [`738d5ed4`](dfinity/candid@738d5ed) fix for actor class codegen ([dfinity/candid⁠#107](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/107))
* [`97ba7a0f`](dfinity/candid@97ba7a0) export init args in js ([dfinity/candid⁠#108](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/108))
* [`d4e00adc`](dfinity/candid@d4e00ad) fix js init export ([dfinity/candid⁠#109](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/109))
* [`c1662abe`](dfinity/candid@c1662ab) [spec] Reverse subtyping ([dfinity/candid⁠#110](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/110))
* [`713595be`](dfinity/candid@713595b) The “reverse variant extension rule” is redundand ([dfinity/candid⁠#113](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/113))
* [`79d49a01`](dfinity/candid@79d49a0) Spec: Opt decoding also from non-opt values ([dfinity/candid⁠#114](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/114))
* [`2cfc0ecf`](dfinity/candid@2cfc0ec) improve pretty printing for values ([dfinity/candid⁠#116](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/116))
* [`8fafe345`](dfinity/candid@8fafe34) Un-rename Soundness document ([dfinity/candid⁠#115](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/115))
* [`8e6fc502`](dfinity/candid@8e6fc50) Bump spec version ([dfinity/candid⁠#112](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/112))
* [`7cedebcb`](dfinity/candid@7cedebc) fix clippy ([dfinity/candid⁠#117](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/117))
* [`a732a639`](dfinity/candid@a732a63) Candid UI Canister ([dfinity/candid⁠#111](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/111))
* [`d97b271c`](dfinity/candid@d97b271) disable pretty printing for large vectors ([dfinity/candid⁠#118](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/118))
* [`aceb7f92`](dfinity/candid@aceb7f9) derive candid type for functions ([dfinity/candid⁠#119](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/119))
* [`c3dc0ad7`](dfinity/candid@c3dc0ad) rename derived code for CDK ([dfinity/candid⁠#120](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/120))
* [`d1f8de7d`](dfinity/candid@d1f8de7) release ([dfinity/candid⁠#121](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/121))
* [`3e3ad95a`](dfinity/candid@3e3ad95) remove multi-line string in test suites ([dfinity/candid⁠#125](http://r.duckduckgo.com/l/?uddg=https://github.com/dfinity/candid/issues/125))
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