Make mutable scratch buffers a part of the Renderer#1050
Merged
Conversation
He-Pin
approved these changes
Jun 25, 2026
He-Pin
reviewed
Jun 25, 2026
stephenamar-db
added a commit
that referenced
this pull request
Jun 25, 2026
When independent Interpreters run concurrently (e.g. a Bazel bundle worker fanning evaluation across a thread pool) they share the process-wide default `std` module and, via the parse cache, the StaticOptimizer-folded AST. Two pieces of shared mutable state raced: 1. The default `std` module is a singleton built with `static = false`, so the first `std.foo` lookup (which StaticOptimizer triggers while folding) called `putCache`, mutating the inline cache (ck1/cv1) and lazily allocating the `valueCache` HashMap. Concurrent first access could return the wrong builtin or corrupt the map. Add `Val.Obj.mkWithConstCache`, which pre-fills the value cache for every constant field at construction; `StdLibModule.module` now uses it, making lookups read-only. Context-dependent members (thisFile/pi) carry `cached = false` and never write either, so the instance is immutable after construction. 2. `Expr.ObjBody.MemberList._cachedAllKeyNames` / `_cachedVisibleKeyNames` are shared across interpreters via the parse cache but were non-volatile; an unsafe publication could expose a half-filled array. Make both `@volatile`, matching the existing `_cachedSortedOrder` / `_noSelfRef` pattern. Adds regression tests to ParallelManifestRaceTests: a deterministic guard that the std value cache is pre-filled at construction, plus concurrent stress tests for std first-access and shared-MemberList materialization. Also fixes the test file to use java.lang.AssertionError (utest._ shadows it). This builds on #1050 (renderer scratch buffers) and the static-object sorted-key cache fix, which together cover the data races in #1047 that are reachable under the supported concurrency model (independent interpreters). Co-authored-by: Isaac
stephenamar-db
added a commit
that referenced
this pull request
Jun 25, 2026
When independent Interpreters run concurrently (e.g. a Bazel bundle worker fanning evaluation across a thread pool) they share the process-wide default `std` module and, via the parse cache, the StaticOptimizer-folded AST. Two pieces of shared mutable state raced: 1. The default `std` module is a singleton built with `static = false`, so the first `std.foo` lookup (which StaticOptimizer triggers while folding) called `putCache`, mutating the inline cache (ck1/cv1) and lazily allocating the `valueCache` HashMap. Concurrent first access could return the wrong builtin or corrupt the map. Add `Val.Obj.mkWithConstCache`, which pre-fills the value cache for every constant field at construction; `StdLibModule.module` now uses it, making lookups read-only. Context-dependent members (thisFile/pi) carry `cached = false` and never write either, so the instance is immutable after construction. 2. `Expr.ObjBody.MemberList._cachedAllKeyNames` / `_cachedVisibleKeyNames` are shared across interpreters via the parse cache but were non-volatile; an unsafe publication could expose a half-filled array. Make both `@volatile`, matching the existing `_cachedSortedOrder` / `_noSelfRef` pattern. Adds regression tests to ParallelManifestRaceTests: a deterministic guard that the std value cache is pre-filled at construction, plus concurrent stress tests for std first-access and shared-MemberList materialization. Also fixes the test file to use java.lang.AssertionError (utest._ shadows it). This builds on #1050 (renderer scratch buffers) and the static-object sorted-key cache fix, which together cover the data races in #1047 that are reachable under the supported concurrency model (independent interpreters). Co-authored-by: Isaac
stephenamar-db
added a commit
that referenced
this pull request
Jun 25, 2026
…) (#1052) When independent Interpreters run concurrently (e.g. a Bazel bundle worker fanning evaluation across a thread pool) they share the process-wide default `std` module and, via the parse cache, the StaticOptimizer-folded AST. Two pieces of shared mutable state raced: 1. The default `std` module is a singleton built with `static = false`, so the first `std.foo` lookup (which StaticOptimizer triggers while folding) called `putCache`, mutating the inline cache (ck1/cv1) and lazily allocating the `valueCache` HashMap. Concurrent first access could return the wrong builtin or corrupt the map. Add `Val.Obj.mkWithConstCache`, which pre-fills the value cache for every constant field at construction; `StdLibModule.module` now uses it, making lookups read-only. Context-dependent members (thisFile/pi) carry `cached = false` and never write either, so the instance is immutable after construction. 2. `Expr.ObjBody.MemberList._cachedAllKeyNames` / `_cachedVisibleKeyNames` are shared across interpreters via the parse cache but were non-volatile; an unsafe publication could expose a half-filled array. Make both `@volatile`, matching the existing `_cachedSortedOrder` / `_noSelfRef` pattern. Adds regression tests to ParallelManifestRaceTests: a deterministic guard that the std value cache is pre-filled at construction, plus concurrent stress tests for std first-access and shared-MemberList materialization. Also fixes the test file to use java.lang.AssertionError (utest._ shadows it). This builds on #1050 (renderer scratch buffers) and the static-object sorted-key cache fix, which together cover the data races in #1047 that are reachable under the supported concurrency model (independent interpreters).
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.
No description provided.