Skip to content

v0.7.10.9

Choose a tag to compare

@github-actions github-actions released this 30 Apr 02:50
· 5 commits to main since this release
v0.7.10.9
cbf8c28

v0.7.10.9 — and / or predicates via codegen_boolop

Date: 2026-04-30
Spec: notes/Spec/1500/1567_gocopy_v07109_boolop.md
Roadmap: notes/Spec/1500/1558_gocopy_v0710x_release_roadmap.md

v0.7.10.9 opens visitFuncBodyDef to and / or predicate
expressions on the assign / return / If-test / Compare RHS surface.
Operands stay restricted to the shapes validateFuncBodyAssignRHS
already accepts — Name, Constant, BinOp, UnaryOp, Compare, Call,
Attribute, Subscript, Tuple. Same-op chains (a and b and c,
a or b or c or d) parse as a single multi-value BoolOp and emit
straight from the dispatcher. Nested mixed-op BoolOp (e.g.
a and b or c parsed as (a and b) or c) requires CPython's
pseudo-op pipeline + optimize_basic_block thread-jump and is
deferred.

The emit mirrors Python/codegen.c::codegen_boolop with
convert_pseudo_conditional_jumps + normalize_jumps already
applied: per non-final operand we emit <operand> then
COPY 1, TO_BOOL 0, POP_JUMP_IF_FALSE/TRUE → end, NOT_TAKEN,
POP_TOP. The final operand falls through; the merge block is
bound to the end label. The COPY/TO_BOOL/JUMP/NOT_TAKEN/POP_TOP
five-instruction group all share the BoolOp's outer span
(first-operand start col → last-operand end col on the BoolOp
line), matching CPython's co_positions shape exactly.

Added

  • tests/fixtures/funcbody/030_expr_bool_and.py —
    def f(a, b): return a and b. Pins the basic And pattern.
  • tests/fixtures/funcbody/031_expr_bool_or.py —
    def f(a, b): return a or b. Pins the Or pattern (same shape,
    POP_JUMP_IF_TRUE instead).
  • tests/fixtures/funcbody/032_expr_bool_chain.py —
    def f(a, b, c): return a and b and c. Pins the 3-operand And
    chain — two (COPY, TO_BOOL, JUMP, NOT_TAKEN, POP_TOP) groups,
    third operand falls through.
  • tests/fixtures/funcbody/033_expr_bool_or_chain.py —
    def f(a, b, c, d): return a or b or c or d. Pins the 4-operand
    Or chain.

Changed

  • compiler/codegen/visit_func_stmt.go — added a *ast.BoolOp
    arm to the visitFuncExpr dispatcher and new visitFuncBoolOpExpr
    that 1:1 ports Python/codegen.c::codegen_boolop. Allocates the
    end label, walks Values[:n-1] emitting the COPY/TO_BOOL/JUMP/
    NOT_TAKEN/POP_TOP group per operand, falls through on the last,
    binds the merge block.
  • compiler/codegen/source_scan.go — astExprCol and
    astExprEndCol now recognise *ast.BoolOp (start col from the
    BoolOp's P.Col; end col from the last value's end).
  • compiler/codegen/visit_funcbody_stmt.go —
    validateFuncBodyAssignRHS accepts *ast.BoolOp with
    Op ∈ {And, Or}, len(Values) ≥ 2, all values themselves
    validated, and no nested BoolOp (a value that is itself a
    BoolOp gates out, since byte-identical emit for that requires
    the pseudo-op + thread-jump pipeline).
  • CHANGELOG.md — v0.7.10.9 entry added.

Tests

  • Oracle (bash tests/run.sh): 273/273 fixtures byte-identical
    (was 269/269).
  • Visitor parity (go test ./compiler/ -run TestVisitorParity):
    byte-identical=233 not-implemented=40 mismatched=0 errored=0
    (was 229/40/0/0).
  • All existing tests stay green.

Out of scope (deferred)

  • Nested BoolOp (a and b or c, (a or b) and c, etc.).
    CPython's optimize_basic_block thread-jumps the inner
    conditional past the outer's COPY/TO_BOOL/JUMP/NOT_TAKEN to
    land directly on the outer's POP_TOP
    (Python/flowgraph.c:2348-2361, JUMP_IF_FALSE → JUMP_IF_TRUE
    inverse rule). Reproducing that requires emitting pseudo
    JUMP_IF_FALSE/TRUE first, running thread-jump, then expanding
    via convert_pseudo_conditional_jumps. Defer to a release that
    introduces the pseudo-op stage.
  • Constant-fold short-circuits (True and X, False or Y) —
    requires the same pseudo-op stage.
  • BoolOp at module scope — the existing classifier path covers
    the 2-Name shape; defer broader support to v0.7.10.14 cleanup.