Skip to content

feat(pir): plan an || as a gate and as a side of an && - #180

Open
thiremani wants to merge 8 commits into
masterfrom
pir-gate-first
Open

thiremani wants to merge 8 commits into
masterfrom
pir-gate-first

Conversation

@thiremani

@thiremani thiremani commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

PIR Step 6, fifth slice: an || plans as a statement's gate and as a side of
an &&. x = a > 9 || b > 0 7 and x = (a > 9 || b > 0) && 7 reach a plan
(matrix rows 15, 19). A side of a last takes its kind from the side itself,
as a side of a first does, so the two nest in each other to any depth.

Plan text, as decided

assign t
    source
        t = n > 0 && (sarr[9] > "a" || sarr[8] > "b") || h

    execute
        %t0 =
            first Str
                last Str
                    %t1 = check I64 n > 0
                next
                    first Str
                        %t2 = check owned Str sarr[9] > "a" [on-oob=fallback]
                    fallback
                        %t3 = check owned Str sarr[8] > "b" [on-oob=fallback]
            fallback
                %t4 = eval borrowed Str h

    commit
        t = %t0 [move %t2] [move %t3] [copy %t4]
        drop %t2 [on-fallback]
        drop %t3 [on-fallback]
        drop t [old]

A gate takes a first's own outcome, as it takes a last's:

assign x
    source
        x = sarr[9] > "a" || MkStr(b) > "a" 7

    execute
        %t0 =
            first Str
                %t1 = check owned Str sarr[9] > "a" [on-oob=fallback]
            fallback
                %t2 = check owned Str MkStr(b) > "a"
        gate %t0
            %t3 = eval I64 7

    commit
        x = %t3 [on-skip=keep]
        drop %t1
        drop %t2

Four decisions, each chosen from options shown with a statement and its plan
text:

  1. A first that is a side of a last binds no outcome, as a last in a
    first binds none. A selection binds an outcome only where a mapping or a
    gate names it. Transfers name the checks and evals that supply the value,
    so nothing could reference a nested selection's name.
  2. A selection that is only tested prints the solver's type of its ||,
    as a gate's last already prints its final side's. For an || that is the
    one type its sides share. This leans on a solver rule: a gate's || sides
    must match in type, though a gate takes no value.
  3. A failed access goes to the nearest fallback at any depth, and skips
    the outcome where there is none. Above, no fallback follows %t3 inside
    its own first, and the outer one resolves it. A release carries the same
    word.
  4. A node no mapping takes from is only tested, whatever its kind. An eval
    can be one, as in y = (arr[9] || b > 0) && 7. What it built is released
    once it ran, with no word after the drop.

What changed

  • Router and builder (compiler/pir.go): planTestedEligible admits a
    gate's condition or a side before the final one of a last as a check or a
    first. One buildSide serves both selections.
  • Lowerer: lowerTested runs a node for its bit alone and releases what
    it built. lowerSelection, lowerSupplying and lowerStaged run a first
    or a last a mapping takes and stage each node that can supply the value.
    A node inside a last also keeps the bit that says it ran. lowerFirst,
    lowerFirstSide and lowerLast are replaced by these.
  • pir: Suppliers (exported, replaces supplier) lists every node that
    can supply a value. tests() returns evals as well as checks. failure()
    walks the resolver the renderer uses, and now enters a last. The renderer
    needed no other change for nesting.
  • Validator: a gate's condition is a check, a last or a first, and it
    must be able to fail. A first that is a side of a last is held to a
    first's own rules, binds no outcome, and fits the last's type where it
    is the final side.

One merged rule removed

A gate's last no longer has to end in a check, and its test case
ConditionEndsInEval is gone. The fourth slice's text assumed a gate's
condition holds only comparisons. It can hold values: x = arr[9] || b > 0 5
and x = b > 9 || arr[1] > 0 && k 5 both compile on master. A last that
is only tested may therefore end in an eval, under decision 4.

Evidence

  • Reach: 19 more assignments plan over the fixtures as they stood before
    this slice, each as one plan, all in tests/cond: 9 whose gate holds an
    || and 10 with an || as a side of an && (6 in cond/logical_ops, 13
    in cond/value_cond_expr).
  • Machine code: 88 of the 89 fixture executables have an identical
    __text. cond/value_cond_expr differs. The 6 statements that newly plan
    in cond/logical_ops compile to the same code as before.
  • Nothing else moves: a build whose router admits no || as a tested node
    or as a last's final side produces all 89 __text sections and every
    plan's text identical to 56278f3. Both sides were built under their own
    PTCACHE.
  • Mutants, one at a time in a scratch copy: 31 run, 31 caught. Three
    lowerer mutants survived the fixtures as they stood, which is why two
    fixture cases and one unit-test row were added: a tested eval that never
    yields (TestedValueYields), a last side that yields only by its first
    node (NestedFirstSecondYields), and a missing "ran" bit for a first
    inside a last (TestPlanLastReleasesFinalSideWhereItRan/FinalFirstSide).
  • Differential fuzz against master's legacy lowering, 9 seeds: about 920
    newly planned nested statements, no output difference and no leak. It
    generates one-slot integer and heap-string trees of && and || up to
    three deep, with printing calls and out-of-bounds reads, and says nothing
    about other shapes.
  • Gate: gofmt -l . empty, go vet ./..., go test -count=1 -race ./...
    and python3 test.py --leak-check 91/91 under its own PTCACHE.

Tests

  • compiler: TestPlanGoldenNestedSelections (eight goldens: a gate over an
    ||, one with an && side, an || before a last's final side as a value
    and under a gate, tested releases in a gate, an || as a last's final
    side with both release tags, a first in a last in a first, and a
    tested eval); fg and fl now plan in TestPlanRouterRejections, and
    fh and fk pin what stays legacy.
  • pir: TestValidateNestedFirstRejects, TestRenderNestedFirst, five
    TestElaborate cases and one TestValidateAccepts case.
  • cond/logical_ops: TestedValueYields and NestedFirstSecondYields.
    master prints the same lines for both.

Staying legacy

A gate that is a bare range or array-selection driver, alone or as a side of
an ||; a comparison with an || or an && for an operand, as in
(a > 9 || 4) > 3 && 7; a side of several slots; and an || or an && under
an operator, in a cell, in a call argument or in a print.

Docs

docs/Pluto IR Plan.md gains "Fifth slice landed" and updates §4, §12 and the
first and fourth slices' "Staying legacy" lists. Rows 15 and 19 of
docs/Pluto PIR Capability Matrix.md no longer say an || gate stays legacy.

Review round

Seven commits after 61b21f0: one per finding from two rounds of review, and
one from the author's own reading.

  • 5a7c598 validator. A first before a last's final side must be able
    to fail. A hand-built (sarr[9] || t) && 7 passed Validate, and so did a
    gate over (sarr[9] || t) && u, which can never reject. Last.MayFail
    answers true for every last, which was sound only while every side before
    the final one was a check. No source statement builds such a plan, since the
    solver requires each such operand to be able to fail.
  • 1536019 release guard. The mutant claim above was too wide for one
    rule: the mutant I ran dropped the "ran" bit of both sides of a final ||,
    and FinalFirstSide caught it through the first side alone. A mutant
    dropping only the second side's bit survived every test and fixture.
    TestPlanLastReleasesEachSideOfFinalFirstWhereItRan now checks that the
    second side's own bit guards the load and the release of its own memory.
    The lowering was already correct and is unchanged.
  • 2d456d1 router. planSideEligible mirrors buildSide, and
    planTestedEligible is left to tested positions, as its comment said. The
    plan text and the __text of all 89 executables are identical before and
    after.
  • 92d72a8 docs. Matrix row 7b no longer lists fg and fl or an ||
    gate as legacy, and plan §12 says a last whose final side is a first
    takes more than one transfer.
  • 202938c builder. A gate's || is a case of its own in
    buildCondition, and any other single condition is an internal compiler
    error that names it. The router admits only a comparison or an || there,
    so nothing plans differently.
  • 197f2a8 test. The release-guard test compared two strings.Index
    positions without asserting that either exists, so it passed with the
    second side's store false removed. It asserts both first now.
  • 301bc42 docs. A last takes one transfer for each eval or check
    that can supply its value, which can be more than its final first has
    sides. Row 7b's skip-policy rule is scoped to a first that is the whole
    value of a statement without a gate.

One suggestion was not taken: adding the three other new fixtures to
TestValidateAccepts. TestElaborate already runs Validate on all four
unmutated.

Seven more mutants, one at a time, each caught: three release-guard mutants,
the new validator rule, and three of the simplified router. The full gate was
re-run after the first four review commits: gofmt -l . empty,
go vet ./..., go test -count=1 -race ./..., and
python3 test.py --leak-check 91/91 under its own PTCACHE. The last three
commits change one builder branch no statement reaches, a test and the docs;
for those, gofmt, go vet ./... and go test -count=1 -race ./... were
re-run.

🤖 Generated with Claude Code

thiremani and others added 8 commits November 26, 2026 16:22
PIR Step 6, fifth slice. `x = a > 9 || b > 0 7` and
`x = (a > 9 || b > 0) && 7` reach a plan (matrix rows 15, 19). A side of
a last takes its kind from the side itself, as a side of a first does,
so an || there is a first, and the two nest in each other to any depth.

- A first or a last binds an outcome only where a mapping or a gate
  names it. A first that is a side of a last binds none, as a last in a
  first binds none, and a gate takes a first's own outcome.
- A node no mapping takes from is only tested, whatever its kind: every
  node of a gate's condition, and every node of a side before the final
  one of a last. What it built is released once it ran. An eval can be
  one, as in `(arr[9] || b > 0) && 7`.
- A last supplies its value from its final side, so where that side is
  a first each of the first's sides can supply it. pir.Suppliers lists
  them, and a mapping names a transfer for each.
- A failed access goes to the nearest fallback that follows a side
  holding it, however deep, and skips the outcome where there is none.
  The release tag of a failed node follows the same walk, which now
  enters a last.

The lowerer has two paths. lowerTested runs a node for its bit alone
and releases what it built. lowerSelection runs a first or a last a
mapping takes and stages each node that can supply the value; one
inside a last also keeps the bit that says it ran, since the sides
before it may have stopped the last. lowerFirst, lowerFirstSide and
lowerLast are replaced by these.

One merged validator rule is removed: a gate's last no longer has to
end in a check. A last that is only tested may end in an eval, and a
gate can hold one today (`x = b > 9 || arr[1] > 0 && k 5`). In its
place a gate's condition must be able to fail.

Over the fixtures as they stood, 19 more assignments plan, all in
tests/cond. The __text of 88 of the 89 executables is unchanged;
cond/value_cond_expr differs. With the router admitting no || as a
tested node or as a last's final side, all 89 and every plan's text
match 56278f3.

Staying legacy: a gate that is a bare range or array-selection driver,
a comparison with an || or an && for an operand, a side of several
slots, and an || or an && under an operator, in a cell, in a call
argument or in a print.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A side before the final one of a last is only tested, and the next
after it runs where it yielded. Until the fifth slice every such side
was a check, so Last.MayFail could answer true for every last. A first
may sit there now, and the validator did not ask whether it can fail.
A hand-built `(sarr[9] || t) && 7` passed, and so did a gate over
`(sarr[9] || t) && u`, which can never reject, though the rule beside
it says a gate's condition must be able to fail.

validateLast now rejects a first before the final side that cannot
fail, as validateFirstSide rejects a side a fallback follows that
cannot. Every valid last can therefore fail again, which the gate rule
and maySkip rely on. No source statement builds such a plan: the solver
requires every operand of an && before the last one to be able to
fail.

The comments on Last.MayFail and maySkip said a last fails through its
checks. A last may hold none, so they now name the side before its
final one.

Found in review of #180.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
An || that ends an && runs its second side only where the first one
failed, so that side has a bit and memory of its own. The FinalFirstSide
row of TestPlanLastReleasesFinalSideWhereItRan checked only the first
side's bit. With the second side's bit removed, the generated code
released that side's memory where the && had stopped before the ||,
when nothing was staged there, and every unit test and fixture still
passed: the read is of undefined memory, so no run fails reliably.

TestPlanLastReleasesEachSideOfFinalFirstWhereItRan reads the second
side's bit and memory from the block the fallback admits, and checks
that the bit is cleared before the sides part and that the load and the
release of that memory sit only in the block a branch on that bit
admits. The lowering itself is unchanged; it emitted both guards.

Found in review of #180.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
planTestedEligible is documented as the rule for a node that is only
tested, but planLastEligible also called it on a last's final side,
which supplies the value. planSideEligible now mirrors buildSide: a side
yields one slot and takes its kind from itself, an && as a last, an ||
as a first, a comparison as a check and any other expression as an
eval. planFirstEligible and the final side of planLastEligible both ask
it, and planTestedEligible is left to the sides before the final one
and to a gate's conditions.

Nothing plans differently. Over every fixture the plan text and the
__text of all 89 executables are identical before and after.

Found in review of #180.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Row 7b of the capability matrix still listed `fg` and `fl` among the
statements that do not plan, and said an || as a statement's gate stays
on legacy lowering. Both plan since the fifth slice, and the row now
names `fh` and `fk` as what the router test keeps legacy.

Plan §12 said a mapping takes a last's value by one transfer. That
holds where the final side is an eval or a check. Where it is a first,
each of its sides can supply the value, and the mapping names a
transfer for each.

Found in review of #180.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
buildCondition built a first for any single gate condition that was no
comparison. The router admits only a comparison or an || there, so the
default was never wrong, but it rested on that. Had a later slice
admitted another condition without a case here, the builder would have
made a first of one side, and the validator would have stopped it with
"has 1 sides and needs a fallback", a message about the wrong thing.

An || is now a case of its own, and any other condition is an internal
compiler error that names the condition. Nothing plans differently.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
TestPlanLastReleasesEachSideOfFinalFirstWhereItRan compared the position
of the store that clears the second side's bit with the position of the
block where the sides part. strings.Index gives -1 for a store that is
not there, and -1 is less than any position, so the test passed with
that store removed. It now asserts that both positions exist first, as
the test before it does.

Found in review of #180.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… skip rule

Plan §12 and the fifth slice's passage said a last whose final side is
a first takes a transfer for each side of that first. A side may be a
last that itself ends in a first, so a first of two sides can give
three transfers. The count is one for each eval or check that can
supply the value, and both places now say so, as does the format rule
for a mapping's transfers.

Matrix row 7b said a mapping carries a skip policy only where the side
no fallback follows can fail. That holds where the first is the whole
value of a statement without a gate. Under a gate or as a side of an &&
the mapping always carries one: `x = n > 0 && (n > 1 || 8)` keeps x
where n > 0 fails, though 8 always yields.

Found in review of #180.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

1 participant