fix(codegen): tag-guard String methods on Any receivers - #7866
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughString method lowering now checks runtime String tags before using String builtins. Other ChangesAny String method dispatch
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant PropertyGetLowering
participant StringMethodLowering
participant NativeMethodDispatcher
Caller->>PropertyGetLowering: invoke String-named method
PropertyGetLowering->>PropertyGetLowering: evaluate receiver and inspect runtime tags
PropertyGetLowering->>StringMethodLowering: lower proven String receiver
PropertyGetLowering->>NativeMethodDispatcher: dispatch unproven or non-String receiver
NativeMethodDispatcher-->>Caller: return method result
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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: 2
🤖 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-codegen/src/lower_call/property_get.rs`:
- Around line 51-57: The tag-based String lowering guard in the property-get
lowering logic must also validate call arity. For known String method names,
bypass this guard when args.len() falls outside the selected method’s accepted
arity, allowing the generic dispatcher to handle non-string receivers while
preserving String lowering for valid arities; update the condition surrounding
lower_string_method_from_proven_box and reuse the existing method-arity matching
logic.
In `@test-files/test_gap_7673_any_string_method_collision.ts`:
- Around line 1-53: Run the gap test with Node v26.5.1, matching the version
pinned by .node-version, rather than the current Node v24.15.0 environment.
🪄 Autofix
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: be0ca6c3-2e30-4162-880a-c091cedc9bf1
📒 Files selected for processing (7)
changelog.d/7866-any-string-method-dispatch.mdcrates/perry-codegen/src/lower_call/console_promise.rscrates/perry-codegen/src/lower_call/property_get.rscrates/perry-codegen/src/lower_call/property_get/helpers.rscrates/perry-codegen/src/lower_string_method.rscrates/perry-codegen/tests/argless_builtin_extra_args.rstest-files/test_gap_7673_any_string_method_collision.ts
💤 Files with no reviewable changes (1)
- crates/perry-codegen/src/lower_call/property_get/helpers.rs
631c921 to
85c46f6
Compare
Summary
z.string().trim()Reproduction
The regression program covers a schema-like object whose
trim,split, andminmethods return the object, plus 18 String methods on an opaqueanystring. The fixed binary matches Node byte-for-byte across all 22 output rows.Performance
Measured on the locked M1 mini with both compilers linked against the same unchanged baseline runtime. The benchmark runs 30,000,000
charCodeAtcalls on a string hidden behindJSON.parse(process.argv[2]); 30 alternating runs after two warmups per binary:User-time deltas were -29.2% and -0.1%, respectively. The improvement comes from proving the runtime tag once and skipping the old per-call coercion.
Tests
cargo test -p perry-codegen --lib(889 passed)cargo test -p perry-codegen --test argless_builtin_extra_args(3 passed)python3 scripts/check_test_registration.pybash scripts/check_file_size.shCloses #7673
Summary by CodeRabbit
Bug Fixes
anyvalues.Tests