Make Lambda-to-Lam conversion structural - #8604
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9762eed607
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Pattern matching introduces Alias lets as O(1) renames of a pattern ident onto the scrutinee. Convert used to substitute those while translating; do the same rewrite as a Lam pass immediately after conversion instead, so convert stays a translation. Exported aliases are kept for coercion. Later lets_dce is unchanged. JS from runtime, Belt, tests/tests, belt_tests, and commonjs_tests matched the convert-time pass (1079 files). Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
The Lam primitive was compiled to f.apply(null, args) but never constructed. Drop it together with the JS IR constructor and the stale Lifused/translclass comments left in convert. Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
%revapply/%apply were leftover |>/@@ encodings; ReScript -> is rewritten before typing. __LOC__ and friends still compile, but as constants in translcore rather than a Lambda primitive. Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
Pack JS catch values in translcore so convert only translates Ltrywith. Drop raise_kind/reraise tracking (JS throw is one operation) and emit RE_EXN_ID string equality from matching instead of Pextension_slot_eq. Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
Exception packing, Promise.catch, and JsExn.anyToExnInternal now apply Primitive_exceptions.internalToException instead of a dedicated primitive. Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
Emit nested let/letrec from transl_let and eval_rec_bindings via Lambda_scc.bind_rec. Convert Lletrec is identity. JS compile only sorts functions before values for dummy/updateDummy init. Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
Remove the dense int-switch-to-add peephole and the switcher-offset let rewrite. Rewrite the one test that relied on the former to an or-pattern plus add. Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
Drop exit_map and the catch-of-raise peephole. Matching still emits catch body with (i) (exit j); Lam_pass_exits inlines the size-1 handler. Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
Lambda.mk_prim expands Peliminated so those payloads never appear as Lprim nodes. Convert maps the constructor 1-1. Lam matches assert false because the node cannot occur. Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
Replace Lambda Const_base and Const_immstring with direct int, char, string, float, and bigint constructors, and use int32-backed Const_int consistently in Lambda and Lam. Represent Lam assert-false separately from ordinary integer zero. Remove the unreachable typedtree Const_int32 and Const_int64 variants and bump the CMT magic number for the serialized type change. Treat ReScript strings as immutable when normalizing match actions, with snapshots covering early string-action sharing and the separate untagged-discriminator merge boundary. Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
Give Lambda Const_string the same structured payload used by Lam, and move processed-delimiter decoding into External_arg_spec so Lambda producers can store the final delimiter directly. Remove the inline-constant delimiter round-trip, cover every processed delimiter encoding, and consolidate the branch changelog into review-facing entries. Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
9762eed to
262cd0b
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #8604 +/- ##
==========================================
+ Coverage 76.33% 76.44% +0.11%
==========================================
Files 476 478 +2
Lines 63253 63163 -90
==========================================
+ Hits 48284 48286 +2
+ Misses 14969 14877 -92
🚀 New features to boost your workflow:
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
| *) | ||
|
|
||
| (* Semantic SCC already ran in [Lambda_scc.bind_rec]. JS still wants | ||
| functions before values so dummy / updateDummy init is well-ordered. *) |
There was a problem hiding this comment.
what is dummy / updateDummy init?
There was a problem hiding this comment.
it refers to the code below -- can clean up the comment
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-8604 |
cknitt
left a comment
There was a problem hiding this comment.
In a large project, I got three output changes. Two were improvements (unnecessary local vars removed/inlined).
One regarding two branches in a switch statement with identical body was a bit unexpected (introducing an exit variable that was not needed before), but I think that particular case can be investigated separately later.
Summary
Lam_sccThis PR is based on #8598 so the refreshed compiler documentation describes the contracts used by this cleanup. It is intentionally not registered as a GitHub stack.
Generated output audit
Every generated JavaScript change was reviewed:
internalToExceptionimplementation through the normal runtime binding after removal ofPwrap_exnConst_stringdelimiter change itself produces no generated JavaScript changesTests
make test