Skip to content

fix(codegen): non-Number fields no longer pay for region Number proofs (#11680 matrix regressions) - #11795

Merged
proggeramlug merged 2 commits into
mainfrom
fix-matrix-any-str-regressions
Oct 3, 2026
Merged

proggeramlug merged 2 commits into
mainfrom
fix-matrix-any-str-regressions

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes most of the matrix regressions that #11680 caused on any- and str-typed fields.

Root cause. The region planner asked for a Number lane on every + or compare operand, and on receivers such as o.a in o.a.length. The runtime refused that lane on non-double fields, so the region word retired and every iteration ran the generic path. An admitted region also switched off the proven-shape routes for reads and method dispatch across the whole loop.

Fix. A Number request on a non-double field is published with a value-test bit, and the guard checks the value. Reads beneath a property access, call or new no longer request a Number lane. A region's proven-shape authority now covers stores only.

Matrix

Cells slower than pre-#11680 Rows above 1.25 (excluding addkey)
main 85 22
this PR 18 17

Examples, shown as pre-#11680 / main / this PR:

  • read1 any param: 33 / 71 / 12
  • read4_stmt any modconst: 85 / 132 / 28
  • read1 str param: 64 / 92 / 64

The Number-field wins from #11680 are kept: 258 cells are faster than pre-#11680.

tsc and Zod: tsc −0.11%, Zod +0.01%; full collections and RSS are equal, and output matches node.

Verification

  • runtime 4823/0; codegen 2432/0; region_any_str_reads 4/0.
  • Gap filters field/class/region/numeric/read all pass.
  • census --gate: OK. fmt and file size pass.
  • Sabotage (value test forced true) turns a unit test red and makes the gap test differ from node.
  • Two region-report tests gained one store in their shared fixture, because reads no longer record the denial. No assertion was weakened.

Still open

Summary by CodeRabbit

  • Performance
    • Loop-based numeric reads can now be optimized when fields have dynamic or string-capable values, with runtime checks ensuring values are numbers.
    • String .length reads avoid unnecessary numeric checks, and calls on receivers with a proven class can remain direct.
    • Reported instructions per iteration decreased from 71 to 11, 92 to 64, and 90 to 61 in the covered scenarios.

Fixes the #11680 matrix regressions for any/str fields:
- a Number read (R) on a non-identity lane (Any, deprecated F64) is published
  with REGION_LOOP_WORD_VALUE_TEST (bit 63); the guard tests the R slots
  values on the object (a static word decides it at compile time);
- a read beneath a property access, element access, call or new is not a
  Number operand (o.a.length no longer requests R);
- an admitted region Ptr<Shape> authority covers its receivers stores only;
  reads and method dispatch keep their proven routes;
- re-check: a learned word with the bit fails the loop-invariant fast
  compare and continues in G, so F64 words pay nothing extra.
@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ce48aeda-3726-4b2b-b060-38e0d0fdacac
📥 Commits

Reviewing files that changed from the base of the PR and between af8eca2 and c708f31.

📒 Files selected for processing (1)
  • changelog.d/11795-matrix-any-str-regressions.md
💤 Files with no reviewable changes (1)
  • changelog.d/11795-matrix-any-str-regressions.md

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

Loop-region Number reads can now use eligible non-F64 lanes when guards check the slot values. Receiver selection, guard generation, and store-proof access were updated. New runtime and compiler tests cover any and string-valued fields, nested reads, and calls on proven receivers.

Changes

Loop-region Number reads

Layer / File(s) Summary
Pack Number-read lanes into region words
crates/perry-runtime/src/object/shapes.rs, crates/perry-runtime/src/object/*tests.rs
Region packing accepts eligible non-identity lanes for Number reads and marks words that require value checks. Runtime tests cover eligible lanes, refusals, and slot changes.
Select receivers and preserve store checks
crates/perry-codegen/src/stmt/region_loop/plan.rs, crates/perry-codegen/src/expr/mod.rs, crates/perry-codegen/src/expr/member_update.rs, crates/perry-codegen/src/expr/property_set.rs, crates/perry-codegen/src/stmt/ptr_shape_region_report_tests.rs, crates/perry-codegen/src/expr/region_loop_tests.rs
Number-read discovery stops at nested property reads and selected expression forms. Proven receiver shapes remain available to region reads, while store paths use a separate proof accessor.
Emit and validate guard value checks
crates/perry-codegen/src/stmt/region_loop/{guard.rs,mod.rs,numeric_expression.rs}, crates/perry/tests/region_any_str_reads.rs, test-files/test_gap_region_any_lane_number_read.ts, test-files/test_gap_region_method_call_receiver.ts, changelog.d/11795-matrix-any-str-regressions.md
Static and learned guards check selected R slots when the word requests value tests, and failed checks route to the generic path. Tests cover any and string reads, numeric reads, and method calls on proven receivers.

Priority: ➖ Normal

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

Change: Bug fix

Merge Risk: ⚪ Minimal · up to c708f

No actionable issue is established for this change; it is mergeable after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to af8ec

The change admits more values to optimized execution while retaining value validation and stricter write restrictions. No introduced security weakness was established in the reviewed paths. Incomplete compatibility and deployment coverage keeps the assessment above minimal risk.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The inspected security-sensitive scope is object interpretation and raw numeric execution within programs using these optimized loops. A proof error could affect the executing process; the supplied evidence does not establish tenant, service, credential or environment-level exposure.

Trust Boundaries and Controls

  • observed — Program-supplied receiver values cross into trusted slot interpretation only after object-pointer and matching-shape checks. Flagged lanes additionally require canonical Number validation before raw-double execution. Direct method dispatch retains exact-class and method-eligibility prerequisites rather than treating region admission as unrestricted call authority.

Resilience and Maintainability Implications

  • observed — The write paths retain runtime setter fallbacks for unsafe values and representation downgrades, together with existing write-barrier handling. Separating receiver facts from store facts preserves this ownership boundary despite broader reuse of read proofs.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 72.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 50 functions across 15 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the codegen fix for region Number proofs on non-Number fields. It is specific and related to the main change.
Description check ✅ Passed The description explains the problem and fix, reports performance results, lists verification, and identifies open issues. It does not use every template heading or explicitly complete the checklist, …
Full details: Docstring Coverage

Explanation

Docstring coverage is 72.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 50 functions across 15 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@proggeramlug proggeramlug added the run-extended-tests Opt PR into compile-smoke/parity/doc-tests/drizzle-mysql-smoke label Oct 3, 2026
@proggeramlug
proggeramlug merged commit 9ec5c75 into main Oct 3, 2026
24 of 45 checks passed
@proggeramlug
proggeramlug deleted the fix-matrix-any-str-regressions branch October 3, 2026 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-extended-tests Opt PR into compile-smoke/parity/doc-tests/drizzle-mysql-smoke

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant