Skip to content

ripple: count writes to pure globals as load-time effects - #344104

Merged
Alexandru Dima (alexdima) merged 2 commits into
mainfrom
ripple/pure-global-writes
Oct 25, 2026
Merged

Alexandru Dima (alexdima) merged 2 commits into
mainfrom
ripple/pure-global-writes

Conversation

@alexdima

@alexdima Alexandru Dima (alexdima) commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #342907.

What

ripple's analyzer treats globals such as console, Error, Object and Array (PURE_GLOBALS) as local in escapes(), 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 = f or Object.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_nodes in engine.rs) and selected none of the tests that load it, although those tests then run with a different Error, console or Array.

main has one such module: src/vs/base/test/common/virtualScheduling/virtualTimeApi.ts sets Error.stackTraceLimit = 50 when it loads.

Assignments, updates and Object mutators (Object.assign, Object.defineProperty, Object.freeze, ...) now escape when their target is a global or a member of one, pure or not (write_escapes in analyze.rs):

  • Calling methods of pure globals stays pure.
  • Changing what their methods return stays local: Object.assign(Object.create(proto), props) is common in tests.
  • delete already counted as an effect.
  • Assigning a bare global (Promise = MyPromise) now counts too; it was ignored like an assignment to a local variable.
  • Changing a global through an alias (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() in engine.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_it and removing_a_method_selects_the_tests_that_called_it cover removing an export, or a method, that an unchanged module still uses. They are in this pull request because every change to build/ripple runs every unit test on macOS and Windows, so one pull request uses fewer VM minutes than two.

Validation

  • Regression test: cargo test --release --locked loading_a_module_that_writes_to_built_in_globals with main'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_effects covers the analyzer, including the calls and local writes that must stay pure.
  • Base-side traversal tests (8a2bba2): both pass. With dependent_tests(base, bg, &base_seeds, &mut sel.decl) temporarily removed from select(), cargo test --release --locked fails 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 the stats, 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>.jsonl with both binaries: all 708 commits are identical on sha, declTestFiles and runAll. The summary stays at 9.0% mean, 1.9% median, 24.1% p90 and 14.5% selecting nothing. virtualTimeApi.ts re-exports globalTimeApi.ts, which already has effects, so in this history its own effect never changed a selection.
  • The new effect on the real tree: two throwaway commits, in which processor.ts first loads ./virtualClock.js and ./globalTimeApi.js, then also ./virtualTimeApi.js. ripple affected --config build/ripple/vscode.jsonc --base <first> --head <second>: main selects 0 test files, this branch 303 (every test that loads processor.ts at runtime).
  • Recall on the saved CI failures (the 75 pull request runs with failing Linux unit test jobs, re-scored with ripple affected): 47 of 79 failing test files selected, the same as with main'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.

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]>
Copilot AI balanced review requested due to automatic review settings October 25, 2026 07:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 Object mutations 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]>
@alexdima
Alexandru Dima (alexdima) merged commit e4bf7dc into main Oct 25, 2026
60 checks passed
@alexdima
Alexandru Dima (alexdima) deleted the ripple/pure-global-writes branch October 25, 2026 09:32
@vs-code-engineering vs-code-engineering Bot added this to the 1.144.0 milestone Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants