Semantic Diff

#9394 Return unchanged JS IR nodes from the mapper and the JS passes

1 commit

643e9c03dbf69629e7d42ce5652a50b828982210..pr-9394

3d212378c · cknitt + Claude · Nov 23, 2026, 06:25 UTC

Return unchanged JS IR nodes from the mapper and the JS passes

The JS IR mapper Js_record_map rebuilt every node, list and option even when nothing in it changed, and five JS passes run on it, so each pass copied a module's whole JS program although it rewrites little. The mapper now returns a node as it is when all its parts come back physically unchanged, like Lambda_traverse.shallow_map_sharing on the Lambda side; the passes' own overrides (statement lists in flatten, tailcall_inline and record_rest, switches and try in external_shadow) and a string switch in remove_alias do the same. Every function is still called in the same order on the same values.

The JS IR has no mutable fields of its own, and the mutable state reachable from it (identifier usage stats, function environments) was already shared by reference before, so no pass sees a difference. JS output and diagnostics are byte-identical on 77 benchmark files, and total allocation drops by 3.2%.