Harden Nat-narrowing guard data structures + pin #757 deferral#761
Conversation
#759, #760) Post-#756-review hardening follow-ups, kept deliberately minimal. #759 — Nat guard data-structure hardening: - Single-sourced the checker->verifier side-table span key via a new ast.span_key(), replacing the hand-rolled (line, column, end_line, end_column) tuple at three sites (checker/expressions, checker/calls, verifier). The read and write halves of the #747 side-table now share one key constructor, so the format cannot drift between them. - Added ConstructorLayout.__post_init__ asserting nat_fields is empty or length-aligned with field_offsets, so a drifted built-in literal (e.g. MdHeading) fails loudly at construction rather than as a mis-indexed guard. - Dropped the third listed item (mirror expected= into _check_ability_op_call): it is inert (the verifier does not obligate ability-op narrowings) AND not a one-line mirror (ability type-params are inferred FROM the arg types, so the expected type is unknown until after synth). Not worth the restructure. #760 — pinned the generic-instantiated-ctor-field runtime deferral with a codegen test: Some(0 - 5) building Option<Nat> compiles and runs without trapping today (the field erases to i64; no per-field mono metadata, #757). When #757 lands and emits the guard, the test flips to a trap and becomes the regression anchor, symmetric with the #754 effect-op pin. No behaviour change. Verifier (200) + checker (521) suites green (the span-key refactor preserves the side-table read/write paths); conformance 90, examples 35 (the __post_init__ assertion holds on every real layout). Closes #759 Closes #760 Co-Authored-By: Claude <[email protected]>
|
Warning Review limit reached
More reviews will be available in 16 minutes and 9 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughIntroduces Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Suggested labels
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #761 +/- ##
==========================================
- Coverage 91.63% 91.63% -0.01%
==========================================
Files 70 70
Lines 25459 25463 +4
Branches 321 321
==========================================
+ Hits 23329 23332 +3
- Misses 2122 2123 +1
Partials 8 8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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 `@vera/codegen/api.py`:
- Around line 48-59: The __post_init__ method uses an assert statement to
validate that nat_fields length matches field_offsets length. Replace the assert
with an explicit if condition that raises ValueError instead. Check if
nat_fields exists and its length does not equal field_offsets length, then raise
a ValueError with the same error message that is currently in the assert
statement. This ensures the validation always executes even when Python is run
with optimization flags like -O or -OO.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: ea88ec57-bfef-4ca8-baa9-1e27be553296
📒 Files selected for processing (10)
CHANGELOG.mdKNOWN_ISSUES.mdROADMAP.mdTESTING.mdtests/test_codegen.pyvera/ast.pyvera/checker/calls.pyvera/checker/expressions.pyvera/codegen/api.pyvera/verifier.py
💤 Files with no reviewable changes (1)
- KNOWN_ISSUES.md
…(CR #761) The __post_init__ guard used assert, which python -O/-OO strips — defeating the #759 'fail loudly at construction' intent — and was the sole failure of the CI 'ruff check --select S vera/' gate (S101). Converted to an explicit if ... raise ValueError, matching this file's existing validation style. The 35 existing vera/ asserts are '# noqa: S101' type-narrowing hints (fine to strip); this one is load-bearing validation, so it must always run. Co-Authored-By: Claude <[email protected]>
Summary
Two small post-#756-review hardening follow-ups — closing the two low-value trackers that review spun off, rather than letting them age in the backlog.
#759 —
@Natguard data-structure hardening(line, column, end_line, end_column)tuple built at three sites (checker/expressions.py,checker/calls.py,verifier._span_key). Extractedast.span_key()so the write (checker) and read (verifier) halves share one constructor and can't drift apart.nat_fieldsinvariant.ConstructorLayout.nat_fieldsruns parallel tofield_offsets; user constructors build both in one loop, but the built-inMdHeadinglayout hand-authors them as separate literals. Added a__post_init__assertion (nat_fields == () or len(nat_fields) == len(field_offsets)) so a drifted literal fails loudly at construction instead of as a silently mis-indexed runtime guard.@Natnarrowing guard data structures (single-source span keys, enforce parallel-tuple invariants) #759 item as inert. The issue also listed "mirrorexpected=into_check_ability_op_call". On inspection it's (a) inert — the verifier doesn't obligate ability-op narrowings at all (lookup_effect_opdoesn't search abilities) — and (b) not the one-line mirror it looked like: ability type-params are inferred from the argument types, so the expected type isn't known until after synth (a two-pass restructure). Not worth it; descoped, noted on the issue.#760 — pin the #757 runtime deferral
The generic-instantiated constructor field is the one #747 narrowing site with no runtime guard (it erases to i64; constructor layouts carry no per-field
@Natmono metadata). Added a codegen test assertingSome(0 - 5)building anOption<Nat>compiles and runs without trapping today. When #757 lands and emits the guard, the test flips to a trap — the regression anchor, symmetric with how #754 is pinned. The verifier still obligates the narrowing statically (E503), so verified programs are unaffected.Validation
No behaviour change. Verifier (200) + checker (521) suites green — the span-key refactor preserves the side-table read/write paths; conformance 90 + examples 35 confirm the
__post_init__assertion holds on every real layout. mypy + ruff clean.Closes #759
Closes #760
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Tests
Chores
Documentation