Repository navigation
refactor(pir): record only that an eval is checked, derive what catches it - #179
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Eval.OnOOBandCheck.OnOOBheld one enum for two facts: whether theexpression 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 secondis 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
Eval.CheckedandCheck.CheckedreplaceOnOOB.pir.OOBScope,MaySkipandpir.Fallibleare gone.MayFailis the one predicate onOutcome(Eval: its bit;CheckandLast: true;First: its lastside's), and
SupplierembedsOutcome.writeNodesandwriteSelectiontake the enclosing resolverand pass it to
outcomeLine. A side of afirstthat afallbackfollowsprints
[on-oob=fallback]; every other node takes what resolves the nodearound it, so a
last's sides fail as thelastdoes and a gate's regionas the statement does.
validateScopeand both its messages go, andvalidateEval,validateCheckandvalidateLastlosefallbackFollows.validateAccesseskeeps its rule against the bit. The rule that a side afallbackfollows must be able to fail stays, with its index test inline.buildSide,buildLast,buildCheckandbuildEvallosefallbackFollows. The lowerer pushes a bounds guard fromChecked, inlowerCheckandlowerEvalalike, and readsMayFailwhereit called
pir.Fallible.Where it differs from the issue
planOOBScopeis renamedplanChecked, since it now returns a bool.validateAccessesmessages are reworded to name the bit: "holds achecked 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 arelease, keeps its own lookup over a plan's
firsts. The issue does notlist it and its logic is unchanged. It will need to recurse once a
firstcan sit inside a
last(Step 6 slice 5).docs/Pluto IR Plan.md(Steps 5 and 6) said the noderecords the scope or the validator checks it, and now say what is true. No
plan text in the docs changes.
Review round
first's skip policy now says it follows the lastside where the statement has no gate:
x = n > 0 arr[9] || -1carries[on-skip=keep]or[on-skip=zero]though its fallback always yields.firstLastsPlanrenders expanded, which pinsdrop %t2 [on-fallback]beside
drop %t4 [on-skip]insidepir.lowerEvalreadsev.Checked, aslowerCheckreadsch.Checked.Dead or moved, not just deleted
MaySkipwas dead as a separate predicate. It differed fromMayFailonly on an eval a fallback follows. A copy of
masterpatched so thatEval.MaySkippanics when asked of such an eval passes thepirandcompilertests and plans all 16 fixture directories with no panic andmaster's plan text.validateScopehas nothing left to check. The node no longer storeswhat resolves a failure, so no stored tag can disagree with its position.
fallbackFollowsmoved into the renderer. 35 mutants, each run alone,are all killed:
last's sides treated as caught by the next side (2)TestRenderLastfirst's last side falls back; a side takes the enclosing resolver;firstdoes not catch;firstor eval ignores the resolver (5)TestRenderFirst,TestPlanGoldenFallbacks,TestPlanGoldenFirstConditionslastignores the enclosing resolver; a check ignores it (3)TestRenderFirst,TestPlanGoldenFirstConditionsTestRenderGateskipTestRenderFirst,TestPlanGoldenFallbackslastTestRenderFirst,TestPlanGoldenFirstConditionsplanCheckedalways false or true; an eval's skip policy ignores the bit (3)TestCFGAnalysis(validator ICE)first's skip policy ignores its last sideTestPlanGoldenFallbacksTestPlanGoldenGatesTestCFGAnalysisCreateStoreTestValidate*Rejects,TestValidateAcceptsMayFailwrong on an eval, a first, a last or a check (6)TestElaborate,TestValidate*,TestRender*, goldensTests
CheckUnvalidatedbreaks the checked bit instead of the scope, andCheckSideNotCheckedis added, so a check side of afirstis still shownto be validated.
TestRenderFirst(firstLastsPlan, alastineach side of a
first), in the expanded view. The three nested-lastmutants and the release tag through a nested
lastwere first caught onlyby the compiler package's goldens; with it,
pirpins both itself.compiler/pir_test.go,emit_pir_test.goor the docs isedited.
Verification
gofmt -l .go vet ./...go test -count=1 -race ./...python3 test.py --leak-check-emit-pir=expandedover all 16 fixture directories, againstmaster__textof all 89 executables, againstmasterPLUTO_TARGET_CPUportable and nativeThe
masterside was built fromc85d326, and each build ran under its ownPTCACHE.🤖 Generated with Claude Code