Repository navigation
ripple: count writes to pure globals as load-time effects - #344104
Merged
Merged
Conversation
Changing a pure global or one of its members at load time, such as `Error.stackTraceLimit = 0`, `console.log = f` or `Object.defineProperty(Array.prototype, ...)`, changes what every module that uses it does. ripple took it as having no effect outside the module, because `escapes()` treats pure globals as local so that calling their methods stays pure. A module that started loading such a module selected none of the tests that load it. Assignments, updates and `Object` mutators now escape when their target is a global or a member of one, pure or not. Calls of their methods stay pure, and changing what their methods return (`Object.create(proto)`) stays local. Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No actionable findings remain; the focused change preserves call behavior and includes regressions for effect detection and test selection.
No open issues 🎉
What changed in this PR
This PR improves ripple’s test selection by recognizing writes to built-in globals as load-time effects, so tests loading newly imported modules with those writes are selected.
Changes:
- Detects global assignments, updates, and
Objectmutations while preserving existing pure-call behavior. - Adds regression coverage for effect detection and importer test selection.
- Documents the behavior and the remaining limitation around mutations through aliases.
| File | Description |
|---|---|
build/ripple/src/engine.rs |
Adds regression coverage for selecting tests that load global-mutating modules. |
build/ripple/src/analyze.rs |
Separates write-effect detection from call purity and adds analyzer tests. |
build/ripple/README.md |
Explains global write effects and alias-analysis limits. |
Review effort: Balanced
No test covered the base-side traversal of `select()`, which finds the tests that depended on removed code: every test passed without it. Removing an export, or a method, that an unchanged module still uses breaks the tests that load that module without changing them. Both new tests select nothing (`left: []`) without that traversal. From finding 1 of #344101 (comment) Co-authored-by: Copilot <[email protected]>
Alexandru Dima (alexdima)
marked this pull request as ready for review
October 25, 2026 09:21
Alexandru Dima (alexdima)
enabled auto-merge (squash)
October 25, 2026 09:21
Ladislau Szomoru (lszomoru)
approved these changes
Oct 25, 2026
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.
Follow-up to #342907.
What
ripple's analyzer treats globals such as
console,Error,ObjectandArray(PURE_GLOBALS) as local inescapes(), so that calling their methods (console.log(x),Object.keys(x)) is not a load-time effect. The same check also decided writes, so changing them at load time was not an effect either:Error.stackTraceLimit = 0,console.log = f,Error.stackTraceLimit++,Array.prototype.last = forObject.defineProperty(Error, ...), directly or in a function called at load time. Such a module had no global load-time effects, so a module that started loading it did not change its effect sequence (effect_sequence/changed_nodesinengine.rs) and selected none of the tests that load it, although those tests then run with a differentError,consoleorArray.mainhas one such module:src/vs/base/test/common/virtualScheduling/virtualTimeApi.tssetsError.stackTraceLimit = 50when it loads.Assignments, updates and
Objectmutators (Object.assign,Object.defineProperty,Object.freeze, ...) now escape when their target is a global or a member of one, pure or not (write_escapesinanalyze.rs):Object.assign(Object.create(proto), props)is common in tests.deletealready counted as an effect.Promise = MyPromise) now counts too; it was ignored like an assignment to a local variable.const proto = Array.prototype; proto.last = f) is still not seen, like module state changed through an alias. The README now lists it with that limit.A second commit, 8a2bba2, adds two regression tests for an unrelated gap: no test covered the base-side traversal of
select()inengine.rs(dependent_tests(base, bg, &base_seeds, &mut sel.decl)), which finds the tests that depended on removed code (finding 1 of #344101).removing_an_export_selects_the_tests_that_used_itandremoving_a_method_selects_the_tests_that_called_itcover removing an export, or a method, that an unchanged module still uses. They are in this pull request because every change tobuild/rippleruns every unit test on macOS and Windows, so one pull request uses fewer VM minutes than two.Validation
cargo test --release --locked loading_a_module_that_writes_to_built_in_globalswithmain's analyzer failed: none of the six write forms selected the test (left: ([], [], [], [], [], [], [])). It passes with the fix.writes_to_built_in_globals_are_global_effectscovers the analyzer, including the calls and local writes that must stay pure.dependent_tests(base, bg, &base_seeds, &mut sel.decl)temporarily removed fromselect(),cargo test --release --lockedfails exactly these two (left: [],right: ["src/app/test/g.test.ts"]) and passes the other 70; the call is restored. The commit only adds test code: the release binary is byte-identical to the one that thestats, replay and recall results below were measured with.cd build/ripple && cargo +nightly-2026-04-14 fmt && cargo test --release --locked && cargo build --release --locked: no formatting changes, 72 tests passed (70 with the first commit alone), release build succeeded.ripple stats --config build/ripple/vscode.jsonc --rev a383e086268,main's binary and this branch's: modules with global load-time effects 4,732 → 4,733 (virtualTimeApi.ts). Modules that load one (9,340 of 10,817) and pinned declarations (3,957) are unchanged.ripple replay --config build/ripple/vscode.jsonc --since "2026-10-13 00:00" --until 75e6bc29961240c00800a33718fda8f4611e3541 --out <file>.jsonlwith both binaries: all 708 commits are identical onsha,declTestFilesandrunAll. The summary stays at 9.0% mean, 1.9% median, 24.1% p90 and 14.5% selecting nothing.virtualTimeApi.tsre-exportsglobalTimeApi.ts, which already has effects, so in this history its own effect never changed a selection.processor.tsfirst loads./virtualClock.jsand./globalTimeApi.js, then also./virtualTimeApi.js.ripple affected --config build/ripple/vscode.jsonc --base <first> --head <second>:mainselects 0 test files, this branch 303 (every test that loadsprocessor.tsat runtime).ripple affected): 47 of 79 failing test files selected, the same as withmain's binary. Nothing that was selected before is missed.node --experimental-strip-types build/hygiene.ts build/ripple/src/analyze.rs build/ripple/src/engine.rs build/ripple/README.md: passed.ripple plan --config build/ripple/vscode.jsonc --base HEAD^1 --head HEAD --out-dir <dir>: exit 0. It runs every unit test, as for any change to ripple.