Skip to content

Commit 548d1b8

Browse files
cristianocclaude
andcommitted
Build make_key through the constructors
make_key was the last thing in lambda.ml constructing terms raw. It could, owning the type, and the argument for letting it was that folding would change the key: it substitutes alias bindings as it canonicalizes, substitution can put a constant where a variable was, and the constructors would then fold what the raw rebuild left alone. That is true of the mechanism and false of the outcome. Routing every construction through the constructors leaves generated JavaScript unchanged across the runtime, Belt and the 626 test modules, so the keys still make the same sharing decisions. The argument was worth checking rather than asserting. It is safe to fold here now for a second reason: since the preceding commit, no key reaches generated code. They are compared - in same_actions, up_ok_action and the action store - and nothing else. What remains of L-constructors in make_key is pattern matching. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W8g8qwBARAcvW9MyuKQq8H
1 parent f10b062 commit 548d1b8

1 file changed

Lines changed: 17 additions & 22 deletions

File tree

compiler/ml/lambda.ml

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,13 +1278,9 @@ let make_key e =
12781278
| Lvar id -> ( try Ident.find_same id env with Not_found -> e)
12791279
| Lglobal_module _ | Lconst _ -> e
12801280
| Lapply ap ->
1281-
Lapply
1282-
{
1283-
ap with
1284-
ap_func = tr_rec env ap.ap_func;
1285-
ap_args = tr_recs env ap.ap_args;
1286-
ap_info = {ap.ap_info with ap_loc = Location.none};
1287-
}
1281+
apply ~ap_transformed_jsx:ap.ap_transformed_jsx (tr_rec env ap.ap_func)
1282+
(tr_recs env ap.ap_args)
1283+
{ap.ap_info with ap_loc = Location.none}
12881284
| Llet (Alias, x, ex, e) ->
12891285
(* Ignore aliases -> substitute *)
12901286
let ex = tr_rec env ex in
@@ -1295,25 +1291,24 @@ let make_key e =
12951291
(* Because of side effects, keep other lets with normalized names *)
12961292
let ex = tr_rec env ex in
12971293
let y = make_key x in
1298-
Llet (str, y, ex, tr_rec (Ident.add x (Lvar y) env) e)
1294+
let_ str y ex (tr_rec (Ident.add x (var y) env) e)
12991295
| Lprim {primitive = p; args = es; loc = _} ->
1300-
Lprim {primitive = p; args = tr_recs env es; loc = Location.none}
1301-
| Lswitch (e, sw) -> Lswitch (tr_rec env e, tr_sw env sw)
1296+
prim ~primitive:p ~args:(tr_recs env es) Location.none
1297+
| Lswitch (e, sw) -> switch (tr_rec env e) (tr_sw env sw)
13021298
| Lstringswitch (e, sw, d) ->
1303-
Lstringswitch
1304-
( tr_rec env e,
1305-
List.map (fun (s, e) -> (s, tr_rec env e)) sw,
1306-
tr_opt env d )
1307-
| Lstaticraise (i, es) -> Lstaticraise (i, tr_recs env es)
1299+
stringswitch (tr_rec env e)
1300+
(List.map (fun (s, e) -> (s, tr_rec env e)) sw)
1301+
(tr_opt env d)
1302+
| Lstaticraise (i, es) -> staticraise i (tr_recs env es)
13081303
| Lstaticcatch (e1, xs, e2) ->
1309-
Lstaticcatch (tr_rec env e1, xs, tr_rec env e2)
1310-
| Ltrywith (e1, x, e2) -> Ltrywith (tr_rec env e1, x, tr_rec env e2)
1304+
staticcatch (tr_rec env e1) xs (tr_rec env e2)
1305+
| Ltrywith (e1, x, e2) -> try_ (tr_rec env e1) x (tr_rec env e2)
13111306
| Lifthenelse (cond, ifso, ifnot) ->
1312-
Lifthenelse (tr_rec env cond, tr_rec env ifso, tr_rec env ifnot)
1313-
| Lsequence (e1, e2) -> Lsequence (tr_rec env e1, tr_rec env e2)
1314-
| Lbreak -> Lbreak
1315-
| Lcontinue -> Lcontinue
1316-
| Lassign (x, e) -> Lassign (x, tr_rec env e)
1307+
if_ (tr_rec env cond) (tr_rec env ifso) (tr_rec env ifnot)
1308+
| Lsequence (e1, e2) -> seq (tr_rec env e1) (tr_rec env e2)
1309+
| Lbreak -> break
1310+
| Lcontinue -> continue
1311+
| Lassign (x, e) -> assign x (tr_rec env e)
13171312
| Lletrec _ | Lfunction _ | Lfor _ | Lfor_of _ | Lfor_await_of _ | Lwhile _
13181313
->
13191314
raise_notrace Not_simple

0 commit comments

Comments
 (0)