fix(thread): make static dispatch IDs worker-safe#6842
Conversation
📝 WalkthroughWalkthroughAOT 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. ChangesStatic dispatch descriptor flow
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
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (18)
changelog.d/6784-diagnostics-worker-dispatch.mdcrates/perry-codegen/src/codegen/string_pool.rscrates/perry-codegen/src/expr/call_spread.rscrates/perry-codegen/src/expr/property_get/helpers.rscrates/perry-codegen/src/expr/property_set.rscrates/perry-codegen/src/lower_call/console_promise.rscrates/perry-codegen/src/lower_call/method_override.rscrates/perry-codegen/src/lower_call/property_get/dynamic_dispatch.rscrates/perry-codegen/src/lower_call/scalar_method.rscrates/perry-codegen/src/nanbox.rscrates/perry-codegen/src/strings.rscrates/perry-codegen/tests/native_proof_regressions.rscrates/perry-runtime/src/object/field_get_set/ic_miss.rscrates/perry-runtime/src/object/native_call_method.rscrates/perry-runtime/src/object/native_module.rscrates/perry-runtime/src/string/intern.rscrates/perry-runtime/src/string/mod.rscrates/perry-runtime/src/string/tests.rs
Closes #6784
Summary
*_by_idlowering, avoiding broad binary/RSS growthStatic 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-runtimecargo test -p perry-codegencargo test -p perry-runtime --lib string::tests(39 passed)cargo test -p perry-runtime --lib -- --test-threads=1(1,465 passed, 3 ignored)diagnostics_channelparity suite (69 passed, 0 failed; baseline 67/69)worker-main-publishparity (pass)worker-subscriber-policyparity (pass)cargo fmt --all -- --checkgit diff --checkSummary by CodeRabbit