Skip to content

fix(thread): make static dispatch IDs worker-safe#6842

Merged
proggeramlug merged 1 commit into
PerryTS:mainfrom
proggeramlug:fix/6784-parity
Jul 26, 2026
Merged

fix(thread): make static dispatch IDs worker-safe#6842
proggeramlug merged 1 commit into
PerryTS:mainfrom
proggeramlug:fix/6784-parity

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Closes #6784

Summary

  • replace GC-backed static property/method IDs with immutable AOT descriptors in read-only data
  • resolve descriptors directly for byte-based dispatch and lazily materialize heap keys in each worker’s existing intern table
  • preserve legacy raw/boxed heap and short-string ID forms, including WTF-8 property names
  • emit descriptors only for strings actually used by *_by_id lowering, avoiding broad binary/RSS growth

Static StringPool handles are allocated in the main thread’s GC arena. Worker closures previously embedded those pointers, so worker-side method dispatch rejected them as foreign-arena strings and silently produced undefined. The descriptor carries length, encoding flags, precomputed FNV-1a hash, and a pointer to immutable string bytes; each runtime thread owns any heap materialization it needs.

Validation

  • cargo check -p perry-codegen -p perry-runtime
  • cargo test -p perry-codegen
  • cargo test -p perry-runtime --lib string::tests (39 passed)
  • cargo test -p perry-runtime --lib -- --test-threads=1 (1,465 passed, 3 ignored)
  • full diagnostics_channel parity suite (69 passed, 0 failed; baseline 67/69)
  • cache-free worker-main-publish parity (pass)
  • cache-free worker-subscriber-policy parity (pass)
  • cargo fmt --all -- --check
  • git diff --check

Summary by CodeRabbit

  • Bug Fixes
    • Fixed AOT property and method dispatch across worker threads.
    • Enabled diagnostic channel publishing and subscriber ownership checks to work reliably from workers.
    • Improved compatibility for static method calls, property access, and class method binding.
    • Preserved correct handling of UTF-8 and WTF-8 property and method names.
  • Tests
    • Added regression coverage for static dispatch descriptors, worker-safe resolution, caching, and special-character handling.

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

AOT property and method dispatch IDs now reference immutable static descriptors instead of heap string handles. Runtime decoding materializes descriptor bytes through per-thread interning, while codegen callsites and regression tests use the new tagged representation.

Changes

Static dispatch descriptor flow

Layer / File(s) Summary
Descriptor contract and emission
crates/perry-codegen/src/strings.rs, crates/perry-codegen/src/nanbox.rs, crates/perry-codegen/src/codegen/string_pool.rs
String pooling stores dispatch metadata and hashes, emits opt-in immutable descriptors, and produces tagged descriptor IDs.
By-id callsite migration
crates/perry-codegen/src/expr/..., crates/perry-codegen/src/lower_call/...
Property access, method binding, spread calls, guarded calls, and fallback dispatch paths now use static descriptor IDs.
Runtime decoding and materialization
crates/perry-runtime/src/string/*, crates/perry-runtime/src/object/..., changelog.d/6784-diagnostics-worker-dispatch.md
Runtime decoding recognizes static descriptors, interns their bytes per thread, and routes field and class-method operations through materialized keys.
Regression validation
crates/perry-codegen/tests/native_proof_regressions.rs, crates/perry-runtime/src/string/tests.rs
Tests verify immutable descriptor IR, tagged IDs, descriptor decoding, caching, and WTF-8 handling.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Codegen
  participant RuntimeResolver
  participant ThreadInternTable
  participant ByIdOperation
  Codegen->>RuntimeResolver: pass tagged static descriptor ID
  RuntimeResolver->>ThreadInternTable: materialize descriptor bytes
  ThreadInternTable-->>RuntimeResolver: return per-thread StringHeader
  RuntimeResolver->>ByIdOperation: dispatch using resolved key
Loading

Suggested reviewers: thehypnoo

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: making static dispatch IDs worker-safe.
Description check ✅ Passed The description covers the summary and validation well, but it omits explicit template sections like Changes and a separate Related issue block.
Linked Issues check ✅ Passed The changes address the linked worker dispatch failures in #6784 by replacing GC-backed IDs with worker-safe descriptors and materialization.
Out of Scope Changes check ✅ Passed The file changes stay focused on worker-safe static dispatch IDs, runtime materialization, codegen, and matching tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/perry-runtime/src/string/mod.rs`:
- Around line 204-225: Update the STATIC_DISPATCH_TAG branch in the
string-reference resolver to validate the decoded descriptor address with the
same established address-space sanity checks used by the heap-pointer fallback,
including is_valid_string_ptr and appropriate arena classification before
dereferencing. Return None for invalid or unknown addresses, while preserving
the existing null, alignment, and valid StaticDispatchString handling.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 84581b10-88b1-42f9-abea-d1807d5cb013

📥 Commits

Reviewing files that changed from the base of the PR and between 21a3d00 and fd6339d.

📒 Files selected for processing (18)
  • changelog.d/6784-diagnostics-worker-dispatch.md
  • crates/perry-codegen/src/codegen/string_pool.rs
  • crates/perry-codegen/src/expr/call_spread.rs
  • crates/perry-codegen/src/expr/property_get/helpers.rs
  • crates/perry-codegen/src/expr/property_set.rs
  • crates/perry-codegen/src/lower_call/console_promise.rs
  • crates/perry-codegen/src/lower_call/method_override.rs
  • crates/perry-codegen/src/lower_call/property_get/dynamic_dispatch.rs
  • crates/perry-codegen/src/lower_call/scalar_method.rs
  • crates/perry-codegen/src/nanbox.rs
  • crates/perry-codegen/src/strings.rs
  • crates/perry-codegen/tests/native_proof_regressions.rs
  • crates/perry-runtime/src/object/field_get_set/ic_miss.rs
  • crates/perry-runtime/src/object/native_call_method.rs
  • crates/perry-runtime/src/object/native_module.rs
  • crates/perry-runtime/src/string/intern.rs
  • crates/perry-runtime/src/string/mod.rs
  • crates/perry-runtime/src/string/tests.rs

Comment thread crates/perry-runtime/src/string/mod.rs
@proggeramlug
proggeramlug merged commit 497f64e into PerryTS:main Jul 26, 2026
30 of 31 checks passed
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.

[parity] node:diagnostics_channel — 2 failing node-suite tests (2026-07-22 baseline)

1 participant