Repository navigation
Conversation
A new cleanup pass, fold-pure-calls, statically evaluates a call to a small pure function whose arguments are all literals, replaces the call with the result and drops the helper once nothing references it. The safe lane only folds a helper that is called directly; the unsafe lane also folds one that is passed around as a value.
|
Preview: https://6d8607b7.untwist-d8y.pages.dev Branch link: https://feat-fold-pure-calls.untwist-d8y.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a cleanup pass, fold-pure-calls, that evaluates calls like
dec(2)to small pure helpers such aslet dec = (a) => ["hello", "log"][a]when every argument is a literal, and removes the helper once nothing uses it. Nothing from the input is run: the body is checked and evaluated over a small pure subset (literals, parameters, operators on primitives, ternaries, templates, and own-element reads of literal arrays, objects, strings and never-written constants).Calls that could run before a let/const they depend on, helpers that are written, impure or read free names, out-of-range reads and arrays that escape are all left alone, in both lanes. The safe lane also requires the helper to be called only directly; the unsafe lane folds a helper passed around as a value. The rules are written up in docs/known-divergences/deobfuscate.md, and fixtures/pure-calls covers both the folded shapes and the near misses against node.
This also touches web/src/settings/passes.json, since the pass table test keeps it in sync.