Skip to content

fix(runtime): fence the dense subclass seqlock; specialize imported this-methods and proven Symbols - #8737

Merged
proggeramlug merged 1 commit into
mainfrom
merge/b28
Aug 24, 2026
Merged

fix(runtime): fence the dense subclass seqlock; specialize imported this-methods and proven Symbols#8737
proggeramlug merged 1 commit into
mainfrom
merge/b28

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Lands #8735, #8729 and #8731.

#8735 — fence the dense subclass seqlock

A real data race, and the reasoning checks out. cached_dense_layout read two payload fields Relaxed, then rechecked the sequence counter with an Acquire load — but an acquire load only constrains operations that follow it, so on weakly-ordered hardware the preceding payload reads could sink past the recheck. A reader racing a colliding publisher could combine one field from the old layout with one from the new and return a wrong element value rather than faulting, which is the worst failure shape.

The fix is a standalone fence(Acquire) between the payload reads and the recheck — the canonical seqlock-reader form, and precisely the ordering an acquire load cannot provide:

// … relaxed payload loads …
std::sync::atomic::fence(Ordering::Acquire);
// … sequence recheck …

#8729 — compare proven Symbols by identity

Lowers strict equality against a proven Symbol to raw NaN-boxed identity, while keeping loose equality, reassigned locals, and erased TypeScript annotation claims on the semantic runtime helpers. That last exclusion is the important one: a declared type is not a proof.

#8731 — specialize imported methods capturing this (fixes #8693)

Publishes producer-authoritative proven-this method capabilities through imports, aliases and re-exports, emitting guarded direct imported clone calls with generic dispatch fallbacks retained.

Validation (on the merged result)

  • All 30 lint-job checkers pass
  • perry-runtime --lib (RUST_TEST_THREADS=1): 2669 passed, 0 failed
  • perry-codegen --lib: 1222 passed, 0 failed (+8)
  • perry-codegen --tests (all integration suites): 0 failures
  • Squashed tree verified identical to the validated tree

A changelog.d/ fragment was added for #8735, which had neither one nor a skip-changelog label.

No version bump.

Summary by CodeRabbit

  • Performance

    • Improved optimization of imported class methods that safely capture this, while preserving correct fallback behavior.
    • Optimized strict equality checks for proven Symbol() and Symbol.for() values.
    • Improved field initialization for eligible class properties.
  • Bug Fixes

    • Fixed class prototype updates, deletions, overrides, and method dispatch after mutation.
    • Strengthened dense-array subclass layout handling on weakly ordered hardware.
  • Tests

    • Added regression coverage for cross-module methods, Symbol identity, prototype changes, garbage collection, and related edge cases.

…his-methods and proven Symbols

Lands #8735, #8729 and #8731.

#8735 fixes a real data race in the dense-array subclass layout cache.
`cached_dense_layout` read two payload fields `Relaxed` and then rechecked
the sequence counter with an `Acquire` LOAD -- but an acquire load only
constrains what follows it, so on weakly ordered hardware the preceding
payload reads could sink past the recheck. A reader racing a colliding
publisher could then combine one field from the old layout with one from
the new and return a WRONG ELEMENT rather than faulting. A standalone
`fence(Acquire)` now sits between the payload reads and the recheck, which
is the canonical seqlock-reader form.

#8729 lowers strict equality against a proven Symbol to raw NaN-boxed
identity, keeping loose equality, reassigned locals and erased TypeScript
annotation claims on the semantic runtime helpers.

#8731 (fixes #8693) publishes producer-authoritative proven-`this` method
capabilities through imports, aliases and re-exports, emitting guarded
direct imported clone calls while retaining generic dispatch fallbacks.

A changelog fragment was added for #8735, which had neither one nor a
skip-changelog label.

No version bump.
@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0a4dd8fa-d93e-448a-b307-2196c11c2aff

📥 Commits

Reviewing files that changed from the base of the PR and between 0749bd3 and 5eba4d7.

📒 Files selected for processing (42)
  • benchmarks/compiler_output/workloads.toml
  • changelog.d/8693-imported-this-specialization.md
  • changelog.d/8729-symbol-identity-equality.md
  • changelog.d/8735-dense-subclass-seqlock-fence.md
  • crates/perry-codegen/src/codegen/helpers.rs
  • crates/perry-codegen/src/codegen/method.rs
  • crates/perry-codegen/src/codegen/method_registry.rs
  • crates/perry-codegen/src/codegen/mod.rs
  • crates/perry-codegen/src/codegen/module_globals_emit.rs
  • crates/perry-codegen/src/codegen/opts.rs
  • crates/perry-codegen/src/collectors/mod.rs
  • crates/perry-codegen/src/collectors/proven_this.rs
  • crates/perry-codegen/src/collectors/repsel_benefit.rs
  • crates/perry-codegen/src/collectors/repsel_benefit/tests.rs
  • crates/perry-codegen/src/expr/compare.rs
  • crates/perry-codegen/src/expr/compare_tests.rs
  • crates/perry-codegen/src/lib.rs
  • crates/perry-codegen/src/lower_call/field_init.rs
  • crates/perry-codegen/src/lower_call/field_init/tests.rs
  • crates/perry-codegen/src/lower_call/method_override.rs
  • crates/perry-codegen/src/lower_call/typed_shape_bake_tests.rs
  • crates/perry-codegen/src/type_analysis/refine.rs
  • crates/perry-runtime/src/array/subclass.rs
  • crates/perry-runtime/src/object/class_registry.rs
  • crates/perry-runtime/src/object/class_registry/prototype_methods.rs
  • crates/perry-runtime/src/object/delete_rest.rs
  • crates/perry-runtime/src/object/field_set_by_name.rs
  • crates/perry-runtime/src/object/native_call_method.rs
  • crates/perry-runtime/src/object/native_call_method/handle_methods.rs
  • crates/perry-runtime/src/object/object_ops/define_property.rs
  • crates/perry-runtime/src/proxy.rs
  • crates/perry/src/commands/compile/object_cache.rs
  • crates/perry/src/commands/compile/object_cache/object_cache_tests.rs
  • crates/perry/src/commands/compile/run_pipeline.rs
  • crates/perry/tests/issue_8693_imported_this_specialization.rs
  • scripts/local_binding_type_allowlist.json
  • test-files/fixtures/issue_8693_imported_this/barrel.js
  • test-files/fixtures/issue_8693_imported_this/main.js
  • test-files/fixtures/issue_8693_imported_this/package.json
  • test-files/fixtures/issue_8693_imported_this/registry.js
  • test-files/fixtures/issue_8693_imported_this/semantics.js
  • test-files/test_symbol_identity_equality.ts

📝 Walkthrough

Walkthrough

The PR adds imported this method specialization with producer-published capabilities, guarded direct calls, fallback dispatch, and prototype invalidation handling. It also adds Symbol identity optimization, a dense-layout Acquire fence, regression fixtures, benchmarks, and integration tests.

Changes

Imported method specialization

Layer / File(s) Summary
Capability analysis and routing
crates/perry-codegen/src/collectors/*, crates/perry-codegen/src/codegen/mod.rs, crates/perry-codegen/src/codegen/opts.rs, crates/perry-codegen/src/lib.rs
Codegen collects eligible proven-this methods, evaluates tower profitability, and publishes imported capability metadata.
Cross-module capability propagation
crates/perry/src/commands/compile/run_pipeline.rs, crates/perry/src/commands/compile/object_cache.rs, crates/perry/src/commands/compile/object_cache/object_cache_tests.rs, benchmarks/compiler_output/workloads.toml
The compile pipeline propagates capability lists through imports, aliases, and class closures. Cache keys include both lists.
Clone emission and direct-call metadata
crates/perry-codegen/src/codegen/helpers.rs, crates/perry-codegen/src/codegen/method.rs, crates/perry-codegen/src/codegen/method_registry.rs, crates/perry-codegen/src/lower_call/method_override.rs
Pshape clones receive linkage and inline policies. Imported declarations and guarded direct-call lowering metadata are emitted.
Captured-this field initialization
crates/perry-codegen/src/lower_call/field_init.rs, crates/perry-codegen/src/lower_call/field_init/tests.rs
Eligible arrow field initializers use predeclared by-name storage instead of dynamic class-field addition.
Prototype mutation and dispatch invalidation
crates/perry-runtime/src/object/*, crates/perry-runtime/src/proxy.rs
Prototype writes, deletes, recreation, and method resolution update registry state, fast guards, and typed feedback.
Imported specialization validation
crates/perry/tests/issue_8693_imported_this_specialization.rs, test-files/fixtures/issue_8693_imported_this/*, changelog.d/8693-imported-this-specialization.md
Fixtures and tests cover imports, aliases, mutation fallbacks, method semantics, LLVM output, lowering records, and moving GC.

Symbol identity equality

Layer / File(s) Summary
Symbol provenance and refinement
crates/perry-codegen/src/type_analysis/refine.rs, crates/perry-codegen/src/codegen/module_globals_emit.rs
Symbol() and Symbol.for() initializers produce proven Symbol runtime types.
Strict Symbol comparison
crates/perry-codegen/src/expr/compare.rs, crates/perry-codegen/src/expr/compare_tests.rs, test-files/test_symbol_identity_equality.ts, scripts/local_binding_type_allowlist.json, changelog.d/8729-symbol-identity-equality.md
Proven Symbol operands use raw-bit strict comparison. Loose equality and invalidated provenance retain runtime comparison paths.

Runtime memory ordering

Layer / File(s) Summary
Dense-layout seqlock reader
crates/perry-runtime/src/array/subclass.rs, changelog.d/8735-dense-subclass-seqlock-fence.md
The dense-layout reader adds an Acquire fence before sequence validation.

Estimated code review effort: 5 (Critical) | ~90 minutes

Suggested reviewers: thehypnoo

Sequence Diagram(s)

sequenceDiagram
  participant ImportedModule
  participant CompilePipeline
  participant Codegen
  participant Runtime
  ImportedModule->>CompilePipeline: publish proven-this method capabilities
  CompilePipeline->>Codegen: attach capabilities to ImportedClass
  Codegen->>Runtime: emit guarded pshape direct call
  Runtime->>Codegen: use generic dispatch fallback when guards fail
Loading
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch merge/b28

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

perf(codegen): specialize imported class methods that capture this

1 participant