Skip to content

refactor(pir): record only that an eval is checked, derive what catches it - #179

Merged
thiremani merged 2 commits into
masterfrom
pir-eval-checked
Nov 26, 2026
Merged

thiremani merged 2 commits into
masterfrom
pir-eval-checked

Conversation

@thiremani

@thiremani thiremani commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Eval.OnOOB and Check.OnOOB held one enum for two facts: whether the
expression holds a bounds-checked access, and what resolves a failed one — a
fallback after the node's side of a first, or a skipped outcome. The second
is the node's place in the plan, so the builder had to know where a node would
sit before it could build it. The node now records the first fact alone, and
the renderer derives the second from the position it is already walking.

Closes #177. Nothing runs or prints differently.

What changed

  • Node. Eval.Checked and Check.Checked replace OnOOB. pir.OOBScope,
    MaySkip and pir.Fallible are gone. MayFail is the one predicate on
    Outcome (Eval: its bit; Check and Last: true; First: its last
    side's), and Supplier embeds Outcome.
  • Renderer. writeNodes and writeSelection take the enclosing resolver
    and pass it to outcomeLine. A side of a first that a fallback follows
    prints [on-oob=fallback]; every other node takes what resolves the node
    around it, so a last's sides fail as the last does and a gate's region
    as the statement does.
  • Validator. validateScope and both its messages go, and validateEval,
    validateCheck and validateLast lose fallbackFollows.
    validateAccesses keeps its rule against the bit. The rule that a side a
    fallback follows must be able to fail stays, with its index test inline.
  • Builder and lowerer. buildSide, buildLast, buildCheck and
    buildEval lose fallbackFollows. The lowerer pushes a bounds guard from
    Checked, in lowerCheck and lowerEval alike, and reads MayFail where
    it called pir.Fallible.

Where it differs from the issue

  • planOOBScope is renamed planChecked, since it now returns a bool.
  • Two validateAccesses messages are reworded to name the bit: "holds a
    checked access and is not marked checked" and "is marked checked and holds
    no checked access". The "unknown out-of-bounds scope" message is gone, a
    bool having no unknown value.
  • failure(), which produces the [on-fallback] / [on-skip] tag on a
    release, keeps its own lookup over a plan's firsts. The issue does not
    list it and its logic is unchanged. It will need to recurse once a first
    can sit inside a last (Step 6 slice 5).
  • Five prose passages of docs/Pluto IR Plan.md (Steps 5 and 6) said the node
    records the scope or the validator checks it, and now say what is true. No
    plan text in the docs changes.

Review round

  • The doc sentence on a first's skip policy now says it follows the last
    side where the statement has no gate: x = n > 0 arr[9] || -1 carries
    [on-skip=keep] or [on-skip=zero] though its fallback always yields.
  • firstLastsPlan renders expanded, which pins drop %t2 [on-fallback]
    beside drop %t4 [on-skip] inside pir.
  • lowerEval reads ev.Checked, as lowerCheck reads ch.Checked.

Dead or moved, not just deleted

  • MaySkip was dead as a separate predicate. It differed from MayFail
    only on an eval a fallback follows. A copy of master patched so that
    Eval.MaySkip panics when asked of such an eval passes the pir and
    compiler tests and plans all 16 fixture directories with no panic and
    master's plan text.
  • validateScope has nothing left to check. The node no longer stores
    what resolves a failure, so no stored tag can disagree with its position.
  • fallbackFollows moved into the renderer. 35 mutants, each run alone,
    are all killed:
Mutant Caught by
A last's sides treated as caught by the next side (2) TestRenderLast
A first's last side falls back; a side takes the enclosing resolver; first does not catch; first or eval ignores the resolver (5) TestRenderFirst, TestPlanGoldenFallbacks, TestPlanGoldenFirstConditions
A nested last ignores the enclosing resolver; a check ignores it (3) TestRenderFirst, TestPlanGoldenFirstConditions
A gate's region falls back TestRenderGate
The region starts at fallback; tag on unchecked nodes; words swapped (3) most render and golden tests
Release tag always skip TestRenderFirst, TestPlanGoldenFallbacks
Release tag does not look through a nested last TestRenderFirst, TestPlanGoldenFirstConditions
planChecked always false or true; an eval's skip policy ignores the bit (3) TestCFGAnalysis (validator ICE)
A first's skip policy ignores its last side TestPlanGoldenFallbacks
Check guard inverted or dropped (2) TestPlanGoldenGates
Eval guard inverted or dropped (2) TestCFGAnalysis
Every side given a yield flag compiler tests crash in CreateStore
Validator accepts a wrong bit (2), skips a check side, or changes the must-fail rule (2) TestValidate*Rejects, TestValidateAccepts
MayFail wrong on an eval, a first, a last or a check (6) TestElaborate, TestValidate*, TestRender*, goldens

Tests

  • Eight validator cases for the removed rule are deleted.
  • CheckUnvalidated breaks the checked bit instead of the scope, and
    CheckSideNotChecked is added, so a check side of a first is still shown
    to be validated.
  • One render case is added to TestRenderFirst (firstLastsPlan, a last in
    each side of a first), in the expanded view. The three nested-last
    mutants and the release tag through a nested last were first caught only
    by the compiler package's goldens; with it, pir pins both itself.
  • No golden in compiler/pir_test.go, emit_pir_test.go or the docs is
    edited.

Verification

Check Result
gofmt -l . empty
go vet ./... exit 0
go test -count=1 -race ./... all packages ok
python3 test.py --leak-check 91 passed, 0 failed
-emit-pir=expanded over all 16 fixture directories, against master byte-identical, 39,287 lines
__text of all 89 executables, against master identical, with PLUTO_TARGET_CPU portable and native

The master side was built from c85d326, and each build ran under its own
PTCACHE.

🤖 Generated with Claude Code

thiremani and others added 2 commits November 26, 2026 12:37
…es it

Eval.OnOOB and Check.OnOOB held one enum for two facts: whether the
expression holds a bounds-checked access, and what resolves a failed
one, a fallback after the node's side of a first or a skipped outcome.
The second is the node's place in the plan, so the builder had to know
where a node would sit before it could build it, and validateScope
existed to check that it had been told correctly.

The node now holds the first fact alone, as Checked. The renderer works
the [on-oob=...] tag out from the position it is already walking: a side
of a first that a fallback follows prints fallback, and every other node
takes what resolves the node around it, so a last's sides fail as the
last does. Nothing else read the second fact. The lowerer branches to a
fallback from the side's index and pushes a bounds guard from the bit.

- pir.OOBScope, MaySkip and pir.Fallible are gone. MayFail is the one
  predicate on Outcome, and Supplier embeds Outcome. MaySkip differed
  from MayFail only on an eval a fallback follows, and it was never
  asked of one: a mapping takes a value's outcome, and a first answers
  through its last side.
- buildSide, buildLast, buildCheck and buildEval lose fallbackFollows,
  and planOOBScope becomes the predicate planChecked.
- validateEval, validateCheck and validateLast lose it too, and
  validateScope goes with both its messages. validateAccesses holds the
  bit to the expression, and its two messages now name the bit.
- The release tag of a failed side ([on-fallback], [on-skip]) keeps its
  own lookup over a plan's firsts. It will need to recurse once a first
  can sit inside a last.

Nothing runs or prints differently. The expanded plan text of every
fixture is byte-identical, as is the __text of all 89 executables, and
no golden plan in the tests or the docs changes. The tests of the
removed rule are deleted, and one render case pins the tag through a
last nested in each side of a first.

Closes #177.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…hrough a last

Three points from the reviews of the checked-bit change. Nothing runs or
prints differently.

- lowerEval pushes its bounds guard from ev.Checked, as lowerCheck does
  from ch.Checked. Eval.MayFail returns the same bit, so this only names
  the question the guard asks: does the expression hold a checked access.
- The render case with a last in each side of a first now asserts the
  expanded view. It pins `drop %t2 [on-fallback]` beside
  `drop %t4 [on-skip]`, so the pir package itself catches a release tag
  that stops looking through a nested last. Only a compiler golden
  caught that before.
- The plan document said a first's mapping takes its skip policy from
  the last side. That holds only where the statement has no gate:
  `x = n > 0 arr[9] || -1` carries a policy though its fallback always
  yields. The sentence now says so.

Refs #177.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@thiremani
thiremani merged commit 56278f3 into master Nov 26, 2026
2 checks passed
@thiremani
thiremani deleted the pir-eval-checked branch November 26, 2026 09:57
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.

PIR: an eval says it can fail, the plan's shape says what catches it

1 participant