fix(swc): key optimizer env cache by configured values - #12166
fix(swc): key optimizer env cache by configured values#12166David Murdoch (davidmurdoch) wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 25d8a40 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Merging this PR will not alter performance
Comparing Footnotes
|
Description:
GlobalPassOption::buildstores parsedjsc.transform.optimizer.globals.envsmaps in a process-wide cache, but the cache key is currently built fromglobals.vars. Two compilations with the samevarsand different explicitenvsmaps therefore collide, causing the later compilation to reuse stale environment replacements from the earlier one.Build the cache key from the configured environment map instead, and sort its entries so equivalent maps produce the same key regardless of iteration order.
This was discovered while investigating the cached-span source-map issue fixed by #12129, but it is a separate cache-key bug.
The regression test compiles the same source twice in one process with different explicit environment values. Before the fix, the second compilation incorrectly emits the first value.
Tests:
cargo fmt --all -- --checkcargo clippy -p swc --all-targets -- -D warningscargo test -p swc --libcargo test -p swc --test simplecargo test -p swc --test simple --features react-compilercargo test -p swc --test rust_apicargo test -p swc --test source_map define_source_map_is_stable_across_compilations -- --exactRelated issue (if exists):
Follow-up to #12129.