Repository navigation
Releases
v0.8.0
v0.8.0 — v1/v2 split + v0.8.x roadmap
Date: 2026-04-30
Spec: notes/Spec/1500/1575_gocopy_v08x_full_cpython_port.md
Template: notes/Spec/1500/1576_v2_per_port_spec_template.md
v0.8.0 is the preparatory cut for the v0.8.x port cycle. No behaviour
change — cmd/gocopy still drives the v1 (formerly compiler/)
pipeline end-to-end. The release sets up the repo layout and the CI
posture that the next six phase releases (v0.8.1–v0.8.6) build on.
Why the major bump
v0.7.x grew the visitor pipeline shape-by-shape behind 11 validate*
allowlist gates, with a legacy classifier as fallback for unsupported
shapes. That worked to keep the oracle green during construction but
produced two compilers in one repo: the v0.7 visitor (partial, gated)
and the v0.6 classifier (full, ad-hoc). Patching v1 in place would
carry the architectural baggage forward forever.
v0.8.x takes the opposite approach: freeze v1/ and write v2/ from
scratch as a structural mirror of CPython 3.14 Python/*.c. Each
v2/<pkg>/ ports exactly one upstream .c file, with the same
function names (Go-idiomatic), same control flow, same
SOURCE: Python/<file>.c:<line> cites. Per-port specs gate each
phase release.
Repo restructure
git mv compiler v1— every existingcompiler/package now
lives atv1/<same-name>/. 79.gofiles moved.- All in-tree
github.com/tamnd/gocopy/compiler/...imports
rewritten togithub.com/tamnd/gocopy/v1/.... cmd/gocopy/main.goupdated in lockstep — still wires v1's
Compile. No behaviour change.v1/parser_boundary_test.goallow-list strings updated from
compiler/...tov1/....
v2/ skeleton
One Go package per CPython Python/*.c file. No internal/
subfolders — every package is importable so per-port specs and
tests can target each translation unit directly.
| v2/ package | Mirrors |
|---|---|
v2/preprocess/ |
Python/ast_preprocess.c |
v2/future/ |
Python/future.c |
v2/symtable/ |
Python/symtable.c |
v2/codegen/ |
Python/codegen.c |
v2/instrseq/ |
Python/instruction_sequence.c |
v2/flowgraph/ |
Python/flowgraph.c |
v2/assemble/ |
Python/assemble.c |
v2/compile/ |
Python/compile.c |
v2/ast/ |
parser AST alias surface (parity with v1/ast/) |
v2/lower/ |
parser→ast translation (parity with v1/lower/) |
v2/dump/ |
(no upstream) stage-dump + diff tooling vs CPython |
Each package has only a doc.go for now, citing the upstream source
file and the per-port spec slot. Implementation lands in v0.8.1+.
CI: oracle warn-only during v0.8.x
The cpython oracle diff job in .github/workflows/ci.yml is
expected to be partially red until v2/ reaches byte parity (target:
v0.8.6). The oracle step now:
- runs
tests/run.shfor visibility - emits the
N/M fixtures byte-identicalsummary into
$GITHUB_STEP_SUMMARY - emits a
::warning::annotation referencing spec 1575 - always exits 0 (warn-only mode)
Strict mode returns in v0.8.6 once oracle hits 441/441.
v0.8.x roadmap (spec 1575)
Six phases mapped to six phase releases:
| Release | Phase | CPython source | Oracle target |
|---|---|---|---|
| v0.8.0 | prep | (repo restructure) | 343/441 |
| v0.8.1 | 1 | (tooling — no upstream) | 343/441 |
| v0.8.2 | 2 | future.c + ast_preprocess.c |
~345/441 |
| v0.8.3 | 3 | symtable.c |
~345/441 |
| v0.8.4 | 4 | instruction_sequence.c + codegen.c |
~410/441 |
| v0.8.5 | 5 | flowgraph.c + assemble.c |
~435/441 |
| v0.8.6 | 6 | compile.c + delete v1/ |
441/441 |
Per-port specs land alongside each release's PRs under
~/notes/Spec/1500/15xx_v2_<pkg>_port.md, following the template
introduced as spec 1576.
Added
v2/directory tree (11 packages, onedoc.goper package).notes/Spec/1500/1575_gocopy_v08x_full_cpython_port.md—
full v0.8.x roadmap (this spec).notes/Spec/1500/1576_v2_per_port_spec_template.md—
template for per-port specs that gate phase release PRs.
Changed
.github/workflows/ci.yml— oracle step switched to warn-only
for v0.8.x cycle. Step summary captures the byte-identical count;
workflow warning annotation references spec 1575.cmd/gocopy/main.go— import pathcompiler→v1.v1/parser_boundary_test.go(wascompiler/parser_boundary_test.go)
— allow-list updated for the v1/ tree.- 79
.gofiles moved fromcompiler/tov1/(verbatim).
Tests
go vet ./...: clean.go build ./...: clean (v1 + v2 stubs both build).go test ./...: green (v1 unit tests pass post-rename;
v2 packages have no tests yet).tests/run.sh: 343/441 (unchanged from v0.7.11.3 baseline —
the rename is mechanical only).
Out of scope (deferred to v0.8.1+)
- Any change to compiler behaviour. v0.8.0 is purely the cut.
- Stage-dump tooling,
--dump-stage=*CLI flags,
tests/scripts/{cpython,gocopy}_dump.py,
tests/scripts/diff_stages.py— all v0.8.1. v2/preprocess/andv2/future/implementation — v0.8.2.- All other v2/ packages — v0.8.3 through v0.8.6.
- Deletion of
v1/— v0.8.6, after oracle hits 441/441.
v0.7.10.9
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_TRUEinstead).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 thevisitFuncExprdispatcher and newvisitFuncBoolOpExpr
that 1:1 portsPython/codegen.c::codegen_boolop. Allocates the
end label, walksValues[: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—astExprColand
astExprEndColnow recognise*ast.BoolOp(start col from the
BoolOp'sP.Col; end col from the last value's end).compiler/codegen/visit_funcbody_stmt.go—
validateFuncBodyAssignRHSaccepts*ast.BoolOpwith
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'soptimize_basic_blockthread-jumps the inner
conditional past the outer'sCOPY/TO_BOOL/JUMP/NOT_TAKENto
land directly on the outer'sPOP_TOP
(Python/flowgraph.c:2348-2361,JUMP_IF_FALSE → JUMP_IF_TRUE
inverse rule). Reproducing that requires emitting pseudo
JUMP_IF_FALSE/TRUEfirst, running thread-jump, then expanding
viaconvert_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.
v0.7.10.12
v0.7.10.12 — while + for + nested-def + nonlocal in funcbody
Date: 2026-04-30
Spec: notes/Spec/1500/1570_gocopy_v07112_while_for_nested.md
Roadmap: notes/Spec/1500/1558_gocopy_v0710x_release_roadmap.md
v0.7.10.12 closes the funcbody surface gap left by v0.7.10.11
by promoting the four remaining stmt shapes spec 1558 §v0.7.10.12
bundled: while, for, nested def (with implicit closure
when the inner captures), and nonlocal (cell/free-var closure
pipeline). All four were previously rejected by visitFuncBodyDef
and fell through to the legacy visitFunctionDef path.
- while —
while name: target = const→
LOAD test + TO_BOOL + POP_JUMP_IF_FALSE → exit, body emits
NOT_TAKEN + body-Assign + JUMP_BACKWARD → top, exit emits
LOAD_CONST None + RETURN_VALUE - for —
for tgt in iter: bodyTgt = const→
LOAD iter + GET_ITER + FOR_ITER → exit, body emits
STORE tgt + body-Assign + JUMP_BACKWARD → top, exit emits
END_FOR + POP_ITER + LOAD_CONST None + RETURN_VALUE - nested def — zero-arg inner
defwhose body is either
[Return(rhs)]or[Nonlocal(...), Assign(t = rhs)].
Closure cluster: optional cell-tuple build + LOAD_CONST
innerCode + MAKE_FUNCTION + optional SET_FUNCTION_ATTRIBUTE 8- STORE for inner name.
- nonlocal —
nonlocal x; x = ...inside an inner def
promotesxto a cell on the outer scope and a free on the
inner. The inner emits LOAD_DEREF / STORE_DEREF; the outer
emits MAKE_CELL prologue + LOAD_FAST (push cell to closure
tuple) instead of LOAD_FAST_BORROW.
Symtable: LocalsPlus slot ordering — locals before cells
compiler/symtable/scope.go::LocalsPlusNames previously walked
OrderedNames once and appended each name to its slot group in
source-definition order. CPython's compute_localsplus_info
(Python/compile.c) instead emits all plain locals first,
then all non-param cells, irrespective of source order. The
test fixture is fixture 048 (outer: x = 1; def inner: nonlocal x; x = 2; return inner): x (cell, defined line 2) appeared
before inner (local, defined line 3), so the old walk produced
LocalsPlusNames [x, inner] while CPython produces
[inner, x]. Fixed by walking OrderedNames twice — first
emitting plain SymLocal && !SymCell names, then emitting all
SymCell names — both walks preserve source order within each
group.
resolveNameOp: SymCell|SymFree wins over SymLocal
compiler/codegen/scope_ops.go::resolveNameOp previously fell
into the SymParam | SymLocal arm before the
SymCell | SymFree arm, so a nonlocal x; x = 2 binding (which
has both SymLocal from the assign and SymFree from the
nonlocal directive) wrongly dispatched to STORE_FAST. CPython's
compiler_nameop (Python/codegen.c) classifies CELL/FREE
ahead of LOCAL — the deref must run against the parent's cell,
not a fresh fast slot. Fixed by reordering: cell/free check
first, param/local check second, global/builtin check third.
Closure tuple build uses LOAD_FAST, not LOAD_DEREF
compiler_make_closure (Python/codegen.c) bypasses
compiler_nameop when building the closure tuple operand: it
loads the cell object itself (not the cell's value), so for
a cell-in-current-scope it emits LOAD_FAST against the
LocalsPlus slot, not LOAD_DEREF. (LOAD_FAST then promotes to
LOAD_FAST_BORROW via optimize_load_fast.) For a free-in-
current-scope (i.e., a captured name passed through to a
nested scope), it emits LOAD_DEREF. emitFuncBodyInnerDef
mirrors this: it inspects outer.Scope.Symbols[free].Flags
and picks LOAD_FAST or LOAD_DEREF directly, not via
emitNameLoad (which would always pick LOAD_DEREF for cells).
Inner def Loc spans through body end
CPython's LOC(s) for a FunctionDef stmt is the full def-block
span — from def keyword (line, col) through the end of the
last body statement (endLine, endCol). gocopy's gopapy AST
doesn't carry end_lineno/end_col_offset on FunctionDef, so
innerDefBodyEnd recovers the span from the last body
statement's RHS via astExprEndCol. The MAKE_FUNCTION /
SET_FUNCTION_ATTRIBUTE / STORE cluster in the outer scope all
carry this span; the linetable encoder emits a LONG entry for
the multi-line case.
visitFuncBodyDef MAKE_CELL + COPY_FREE_VARS prologue
The visitor now walks childScope.Cells and emits MAKE_CELL N
(at NO_LOCATION) for each cell, then if len(childScope.Frees) > 0 emits COPY_FREE_VARS N (also NO_LOCATION) — both before
RESUME 0 at firstlineno. Mirrors CPython's
compiler_function_body setup phase.
Added
tests/fixtures/funcbody/048_stmt_nonlocal.py—
def outer: x = 1; def inner: nonlocal x; x = 2; return inner.
Pins MAKE_CELL on outer slot 0 (x), STORE_DEREF in inner,
LOAD_FAST + BUILD_TUPLE 1 + MAKE_FUNCTION +
SET_FUNCTION_ATTRIBUTE 8 closure cluster, and the
LocalsPlusNames[inner, x]slot ordering.tests/fixtures/funcbody/049_stmt_while.py—
def f: x = 0; while x: x = 0. Pins three-block while CFG
(top + body + exit), TO_BOOL + POP_JUMP_IF_FALSE, NOT_TAKEN
head on body, JUMP_BACKWARD → top, implicit
LOAD_CONST None + RETURN_VALUE on exit.tests/fixtures/funcbody/050_stmt_for.py—
def f(xs): for x in xs: y = 1. Pins entry GET_ITER, top
FOR_ITER → exit, body STORE_FAST tgt + body-Assign +
JUMP_BACKWARD → top, exit END_FOR + POP_ITER + LOAD_CONST
None + RETURN_VALUE.tests/fixtures/funcbody/051_stmt_nested_def.py—
def outer: def inner: return 1; return inner. Pins the
no-closure inner-def path: outer has no cells/frees, inner
is plain (no COPY_FREE_VARS), MAKE_FUNCTION cluster carries
no SET_FUNCTION_ATTRIBUTE 8.
Changed
compiler/symtable/scope.go::LocalsPlusNames— split the
OrderedNameswalk into two passes (plain locals first,
then cells), so non-param cells emit after plain locals
regardless of source order.compiler/codegen/scope_ops.go::resolveNameOp— reorder
arms so SymCell|SymFree checks before SymParam|SymLocal.compiler/codegen/visit_funcbody_stmt.go— extend the
last-stmt classifier with*ast.Whileand*ast.For;
extend the non-last-stmt classifier with*ast.FunctionDef
(validated viavalidateFuncBodyInnerDef). Add MAKE_CELL
and COPY_FREE_VARS prologue emit before RESUME. Wire
last-stmt dispatch toemitFuncBodyWhile/
emitFuncBodyForand non-last dispatch to
emitFuncBodyInnerDef.compiler/codegen/visit_funcbody_loop.go— new file:
validateFuncBodyWhile,validateFuncBodyFor,
emitFuncBodyWhile,emitFuncBodyFor. Both emitters
return the body's last source line/col so the outer
FunctionDef Loc spans through the loop body end (not just
the while/for header).compiler/codegen/visit_funcbody_innerdef.go— new file:
validateFuncBodyInnerDef,emitFuncBodyInnerDef,
innerDefBodyEnd. Inner consts get a None plant if
nothing else is added during body emit. Closure tuple
build uses LOAD_FAST for cells / LOAD_DEREF for frees.CHANGELOG.md— v0.7.10.12 entry added.
Tests
- Oracle (
bash tests/run.sh): 287/287 fixtures byte-identical
(was 283/283). - Visitor parity (
go test ./compiler/ -run TestVisitorParity):
byte-identical=247 not-implemented=40 mismatched=0 errored=0
(was 243/40/0/0). - All existing tests stay green.
Out of scope (deferred)
- break / continue inside while/for — needs the
label-stack pipelinecompiler_visit_stmt_break/
compiler_visit_stmt_continueandwith_loopsblock-
scope tracking. Rolls into v0.7.10.13. - non-empty while-else / for-else — needs the orelse
visit + label binding after the loop's exit. - multi-stmt while/for body — only single-Assign body
accepted; multi-stmt requires a generic body-visit loop. - non-Name while test / non-Name for iter — Constant /
Compare / Call tests defer to richer codegen_jump_if and
codegen_visit_expr support. - Tuple for-target —
for x, y in itemsneeds UNPACK_*
instructions and lvalue tuple handling. - Inner def with arguments — only zero-arg inner defs
accepted. - Inner def with its own cells (3-deep capture) — when
inner is itself an outer for a grandchild scope. Defers
to a later cycle. - Inner def with decorators / annotations / type params —
same gate-outs as outer-def support already had.
v0.7.10.11
v0.7.10.11 — raise + assert + global + AnnAssign in funcbody
Date: 2026-04-30
Spec: notes/Spec/1500/1569_gocopy_v07111_raise.md
Roadmap: notes/Spec/1500/1558_gocopy_v0710x_release_roadmap.md
v0.7.10.11 opens visitFuncBodyDef to four of the five stmt
shapes spec 1558 §v0.7.10.11 bundled: raise, assert,
global, and AnnAssign. nonlocal defers to v0.7.10.12
because it needs the cell/free-var closure pipeline (cellvar
mark on outer scope, STORE_DEREF/LOAD_DEREF on inner).
- raise — bare /
raise X/raise X from Y - global —
global x; x = 1→ STORE_GLOBAL,
co_varnames=() - AnnAssign —
x: int = 5emits as Assign;
x: int(no value) emits no instructions per PEP 526
function-scope rules - assert —
assert Xandassert X, "msg"→
TO_BOOL + POP_JUMP_IF_TRUE + LOAD_COMMON_CONSTANT 0 +
(optional msg load + CALL 0) + RAISE_VARARGS 1 +
implicit LOAD_CONST None + RETURN_VALUE
CFG terminator fix
compiler/flowgraph/cfg.go::isTerminator was missing
RAISE_VARARGS. CPython 3.14 Python/flowgraph.c classifies it
under IS_SCOPE_EXIT_OPCODE, so a basic block that ends with
RAISE_VARARGS must not get a fall-through edge. Without this,
assert X produced co_stacksize=2 instead of CPython's 1
because Block 1 (which ends in RAISE_VARARGS) propagated
depth=1 into the end block via a spurious fall-through, and the
end block's LOAD_CONST None then peaked at 2.
isScopeExit in optimize_load_fast.go extended in lockstep
to keep the two predicates aligned.
Symtable: global wins over local
compiler/symtable/build.go::analyze now strips SymLocal from
any name that also has SymGlobal set. This mirrors
CPython's symtable.c::analyze_block rule "global wins over
local": for global x; x = 1, visitTarget had unconditionally
added SymLocal for the assignment target, leaving x in
co_varnames. Stripping SymLocal when SymGlobal is set
forces the analyze pass to keep x in co_names (and out of
co_varnames) — the shape CPython emits.
*ast.Assert was also added to visitStmt (was rejected as
unsupported); it visits Test and Msg into the current scope.
Stack size minimum
Bare raise emits only RESUME 0 and RAISE_VARARGS 0,
both zero-effect, so StackDepth reports 0. CPython's
Objects/codeobject.c::_PyCode_Validate (lines 517-519)
unconditionally bumps every code object's stacksize to ≥ 1
before serialization:
if (con->stacksize == 0) {
con->stacksize = 1;
}Ported 1:1 in compiler/assemble/assemble.go after the
StackDepth(cfg) call. Fixture 040 (bare raise) is the
trigger; without this bump it would ship co_stacksize=0
while CPython's reference .pyc carries co_stacksize=1.
Assert codegen
Mirrors CPython's codegen_assert (Python/codegen.c:2932):
test block: visit Test + TO_BOOL + POP_JUMP_IF_TRUE → end
raise block: NOT_TAKEN + LOAD_COMMON_CONSTANT 0 [+ Msg load + CALL 0] + RAISE_VARARGS 1
end block: LOAD_CONST None + RETURN_VALUE
All raise-block instructions emit at LOC(test) per
flowgraph.c::propagate_line_numbers (NO_LOCATION inherits
prev_location). LOAD_COMMON_CONSTANT 0 is the 3.14
replacement for 3.13's LOAD_ASSERTION_ERROR — oparg 0 is
CONSTANT_ASSERTIONERROR.
Added opcodes
bytecode.RAISE_VARARGS = 104— HasArg, ArgRaw,
OpTerminator, StackVar (oparg-dependent pop).bytecode.LOAD_COMMON_CONSTANT = 81— HasArg, ArgRaw,
StackEff +1.
Added
tests/fixtures/funcbody/040_stmt_raise_bare.py—
def f():\n raise. Pins RESUME + RAISE_VARARGS 0,
co_consts=[None], single linetable entry, and the
stacksize=1 bump.tests/fixtures/funcbody/041_stmt_raise_with_value.py—
def f():\n raise ValueError. LOAD_GLOBAL +
RAISE_VARARGS 1,co_names=('ValueError',).tests/fixtures/funcbody/042_stmt_raise_from.py—
def f():\n raise ValueError from KeyError. LOAD_GLOBAL × 2- RAISE_VARARGS 2.
tests/fixtures/funcbody/043_stmt_global.py—
def f(): global x; x = 1; return x. STORE_GLOBAL +
LOAD_GLOBAL,co_names=('x',),co_varnames=().tests/fixtures/funcbody/044_stmt_annassign_value.py—
def f(): x: int = 5; return x. Annotation dropped;
LOAD_SMALL_INT 5 + STORE_FAST 0 + LOAD_FAST 0 + RETURN_VALUE.tests/fixtures/funcbody/045_stmt_annassign_no_value.py—
def f(): x: int; return 1. Emits no instructions for
x: int;co_varnames=().tests/fixtures/funcbody/046_stmt_assert.py—
def f(): assert x. Three-block CFG with
LOAD_COMMON_CONSTANT and the implicit RETURN_NONE epilogue,
co_stacksize=1.tests/fixtures/funcbody/047_stmt_assert_msg.py—
def f(): assert x, "msg". Adds LOAD_CONST 'msg' + CALL 0,
co_stacksize=2.
Changed
bytecode/opcode.go— add RAISE_VARARGS, LOAD_COMMON_CONSTANT.bytecode/opmeta.go— register both opcodes.compiler/assemble/assemble.go— port
_PyCode_Validateminimum-stacksize-1 bump.compiler/flowgraph/cfg.go— extendisTerminatorwith
RAISE_VARARGS so a raise-ending block has no fall-through.compiler/flowgraph/optimize_load_fast.go— extend
isScopeExitwith RAISE_VARARGS to match
CPython'sIS_SCOPE_EXIT_OPCODE.compiler/symtable/build.go— accept*ast.Assert;
stripSymLocalfrom globals inanalyzeso
global x; x = 1excludesxfromco_varnames.compiler/codegen/visit_funcbody_stmt.go— extend the
last-stmt classifier with*ast.Raiseand*ast.Assert;
extend the non-last-stmt classifier with*ast.AnnAssign,
*ast.Global,*ast.Nonlocal. Add validators
(validateFuncBodyRaise,validateFuncBodyAssert,
validateFuncBodyAnnAssign,validateFuncBodyGlobalNonlocal)
and emitters (emitFuncBodyRaise,emitFuncBodyAssert,
emitFuncBodyAnnAssign). Global / Nonlocal are no-ops at
emit time.emitFuncBodyAssignnow routes through
emitNameStoresoglobal x; x = 1resolves to
STORE_GLOBAL.CHANGELOG.md— v0.7.10.11 entry added.
Tests
- Oracle (
bash tests/run.sh): 283/283 fixtures byte-identical
(was 275/275). - Visitor parity (
go test ./compiler/ -run TestVisitorParity):
byte-identical=243 not-implemented=40 mismatched=0 errored=0
(was 235/40/0/0). - All existing tests stay green.
Out of scope (deferred)
- nonlocal — needs cell/free-var closure pipeline
(cellvar mark on outer + STORE_DEREF/LOAD_DEREF on inner).
Rolls into v0.7.10.12 alongside while/for/nested-def. - Mid-body raise / assert — needs
eliminate_unreachable_codeflowgraph pass to drop the
trailing implicit RETURN_NONE. Stays on the legacy
visitFunctionDefpath. - raise of richer expression —
raise Exception("msg"),
raise mod.Err. Same gate-out — only bare-Name accepted. - assert of richer expression —
assert x == 1,
assert all(...). Only bare-Name Test accepted. - AnnAssign with non-Name annotation or value —
x: List[int] = ...and friends. Only Name-annotated,
Name-or-Constant-valued AnnAssigns accepted.
v0.7.10.10
v0.7.10.10 — Name decorators via codegen_decorators + codegen_apply_decorators
Date: 2026-04-30
Spec: notes/Spec/1500/1568_gocopy_v07110_decorators.md
Roadmap: notes/Spec/1500/1558_gocopy_v0710x_release_roadmap.md
v0.7.10.10 opens visitFuncBodyDef to bare-Name decorators —
@d, @d1\n@d2\n chains, and any compositional combination
with the existing default / kwonly / posonly / *args /
**kwargs surface. Decorator expressions richer than a single
Name (Attribute @module.dec, Call @dec(arg)) gate out and
fall through to the legacy visitClosureDef /
visitFunctionDef path.
The emit mirrors Python/codegen.c::codegen_function's
decorator brackets:
LOAD_NAME d (decoLoc) ← codegen_decorators
... default tuple, kwdefault dict (existing)
LOAD_CONST funcCode (outerLoc) ← codegen_function_body
MAKE_FUNCTION (outerLoc)
SET_FUNCTION_ATTRIBUTE 2 / 1 (existing)
CALL 0 (decoLoc) ← codegen_apply_decorators
STORE_NAME g (outerLoc) ← codegen_nameop Store
For N decorators, pushes are in source order
(d1, d2, ..., dN); CALL 0 emits are in reverse source
order (dN, dN-1, ..., d1), each carrying its own decorator's
loc — matches CPython's positions table exactly.
Spec 1558 §v0.7.10.10 originally bundled annotations and the
three-visitor collapse with decorators. Annotations in 3.14
require a deferred-eval scope (PEP 649,
codegen_setup_annotations_scope opens a separate code unit
gated by MAKE_FUNCTION_ANNOTATE) — substantial pipeline work
that splits off into a follow-up release. The visitor collapse
is similarly its own refactor.
Inner-code metadata change
co_firstlineno of the inner function code now equals
decorators[0].P.Line when decorators are present (matching
Python/codegen.c::codegen_function line 1421-1423). RESUME's
loc inside the inner code uses firstlineno, not the def line.
Linetable deltas inside the inner code key off the decorator
line, exactly as CPython's.
Added
tests/fixtures/funcbody/034_decorator_single.py—
@d\ndef g(): return 1. Pins single decorator: LOAD_NAME +
funcCode-MAKE_FUNCTION + CALL 0 + STORE_NAME, with inner
co_firstlinenoset to decorator's line.tests/fixtures/funcbody/035_decorator_chain.py—
@d1\n@d2\ndef g(): return 1. Pins decorator chain: two
pushes in source order, two CALL 0 in reverse, distinct loc
per CALL.
Changed
compiler/codegen/visit_funcbody_stmt.go— early gate now
accepts non-emptyDecoratorListprovided every entry is a
bare*ast.Name(col ≤ 255, name 1..15 chars, line ≥ 1).
Returns annotation and TypeParams stay gated. Inner unit's
firstlinenousesdecorators[0].P.Linewhen decorated;
resumeLocfollows. Two new emit blocks bracket the existing
defaults / kwdefaults / MAKE_FUNCTION / SET_* sequence:
decorator pushes (forward order) before defaults, and
CALL 0× N (reverse order) afterSET_FUNCTION_ATTRIBUTE
but beforeSTORE_NAME. Both blocks use a per-decorator
decoLoc(n)helper that spans(line, col, col+len(id)).CHANGELOG.md— v0.7.10.10 entry added.
Tests
- Oracle (
bash tests/run.sh): 275/275 fixtures byte-identical
(was 273/273). - Visitor parity (
go test ./compiler/ -run TestVisitorParity):
byte-identical=235 not-implemented=40 mismatched=0 errored=0
(was 233/40/0/0). - All existing tests stay green.
Out of scope (deferred)
- Annotations (param + return). PEP 649 deferred-eval scope
required — landing in a follow-up release. - Visitor collapse —
visitFuncBodyDef/
visitClosureDef/visitFunctionDefwill fold into a single
codegenFunctiononce annotations land. - Attribute decorators (
@module.dec). Need
visitFuncExpr-style decorator expression visit, not just
LOAD_NAME. - Call decorators (
@dec(arg), e.g.
@dataclass(slots=True)). Same as Attribute, plus argument
visit + CALL N rather than CALL 0.
v0.7.10.8
v0.7.10.8 — positional + kw-only defaults via codegen_default_arguments
Date: 2026-04-30
Spec: notes/Spec/1500/1566_gocopy_v07108_defaults.md
Roadmap: notes/Spec/1500/1558_gocopy_v0710x_release_roadmap.md
v0.7.10.8 opens visitFuncBodyDef to function signatures that
supply default values:
- positional defaults (
def f(a, b=1),def f(a, b="x"),
def f(a, b=DEFAULT)) - keyword-only defaults (
def f(*, b=1))
Defaults are restricted to *ast.Constant (any constantValue-
friendly payload) or *ast.Name (1..15 chars, col ≤ 255). Wider
expression shapes still gate out. Parameter annotations stay gated
at v0.7.10.10.
To match CPython byte-for-byte, this release also ports the
fold_tuple_of_constants flowgraph pass: a LOAD_CONST/LOAD_SMALL_INT
chain followed by BUILD_TUPLE n collapses into a single
LOAD_CONST (c1, ..., cn). Without this pass the visitor's
LOAD_CONST 0 + LOAD_CONST 1 + BUILD_TUPLE 2 for default tuples
would not match CPython's LOAD_CONST 3 ((1, 2)) shape.
The pass also runs at module scope (runVisitorShadow in
compiler/visitor.go), since the defaults emit happens in the
parent module unit, not inside popChildUnit.
Added
tests/fixtures/funcbody/021_default_const_int.py—
def f(a, b=1): return b. Pins int default + folded(1,)tuple.tests/fixtures/funcbody/022_default_const_str.py—
def f(a, b="x"): return b. Pins str default + folded('x',).tests/fixtures/funcbody/023_default_name.py—
def f(a, b=DEFAULT): return b. Pins LOAD_NAME default — fold
refuses (LOAD_NAME isn't const-loading).tests/fixtures/funcbody/024_default_kwonly.py—
def f(*, b=1): return b. Pins kwonly default + BUILD_MAP +
SET_FUNCTION_ATTRIBUTE 2.compiler/flowgraph/fold_tuple_of_constants.go— 1:1 port of
Python/flowgraph.c:1436fold_tuple_of_constants+
:1293get_const_value+ :1350get_const_loading_instrs+
:1412instr_make_load_const. Walks each block, collapses
matching BUILD_TUPLE chains, returns the (extended) consts pool.compiler/flowgraph/fold_tuple_of_constants_test.go— 8
unit tests (LOAD_CONST chain, LOAD_SMALL_INT chain, single
element, mixed-loader refuse, too-few-loaders, no-BUILD_TUPLE,
nil seq, two BUILD_TUPLEs in one block).
Changed
compiler/codegen/visit_funcbody_stmt.go— gates loosened to
accept Defaults and non-nil KwOnlyDef. Validation extended over
default values (Constant | Name only). Defaults emit pattern:
positional values →BUILD_TUPLE K, then kwonly key/value pairs
→BUILD_MAP K, thenLOAD_CONST funcCode + MAKE_FUNCTION + SET_FUNCTION_ATTRIBUTE 2 (kwdefaults) + SET_FUNCTION_ATTRIBUTE 1 (defaults) + STORE_NAME. Default value loaders use the value's
AST span; the BUILD_TUPLE / BUILD_MAP / MAKE_FUNCTION / SET_*
instructions all shareouterLocso they collapse into one
linetable entry per CPython.compiler/codegen/scope.go::popChildUnit—FoldTupleOfConstants
inserted betweenOptimizeLoadConstandRemoveUnusedConsts.compiler/visitor.go::runVisitorShadow— same three-pass
pipeline now runs at module scope so the defaults emit folds
identically to a child function unit.compiler/visitor_parity_test.go— pipeline aligned with
production:OptimizeLoadConst + FoldTupleOfConstants + RemoveUnusedConstsrun beforeoptimize.Run.CHANGELOG.md— v0.7.10.8 entry added.
Tests
- Oracle (
bash tests/run.sh): 269/269 fixtures byte-identical
(was 265/265). - Visitor parity (
go test ./compiler/ -run TestVisitorParity):
byte-identical=229 not-implemented=40 mismatched=0 errored=0
(was 224/41/0/0). - 8 new flowgraph unit tests for
FoldTupleOfConstantspass. - All existing tests stay green.
Out of scope (deferred)
- Defaults richer than
Constant | Name(e.g.,
def f(a, b=g())) — defer. - Defaults at function scope (closures with default args) — defer.
- Parameter annotations — v0.7.10.10.
- Type params — same release as annotations.
v0.7.10.7
v0.7.10.7 — extended args (PosOnly / KwOnly / *args / **kwargs) in funcbody
Date: 2026-04-30
Spec: notes/Spec/1500/1565_gocopy_v07107_extended_args.md
Roadmap: notes/Spec/1500/1558_gocopy_v0710x_release_roadmap.md
v0.7.10.7 opens visitFuncBodyDef to function signatures that use
positional-only, keyword-only, *args, and **kwargs parameters.
The visitor still gates out defaults and parameter annotations
(those land at v0.7.10.8 / v0.7.10.10). Body emit shape is
unchanged — the work is purely in the function unit's metadata
(co_argcount, co_posonlyargcount, co_kwonlyargcount,
co_flags, co_varnames, co_localspluskinds).
Bringing fixture 020 (def f(a, b, /, c, d, *args, e, f, **kwargs))
online surfaced two latent symtable bugs that no shipped fixture
exercised before:
bindArgsappended params in the AST source order
(PosOnly + Args + Vararg + KwOnly + Kwarg). CPython's
co_varnamesputs KwOnly BEFORE Vararg/Kwarg. Reordered to
match.LocalsPlusKindsreturnedLocalsKindArg(FastLocal | FastArg
= 0x26) for every param. CPython differentiates by arg kind:
posonly = 0x22, regular = 0x26, kwonly = 0x24,
*args= 0x2a,**kwargs= 0x2c. The fix derives the
arg-kind bits from each param's slot position inParams,
using thePosOnlyCount/ArgCount/KwOnlyCount/
HasVararg/HasKwargalready on Scope.
Added
tests/fixtures/funcbody/016_args_vararg.py—
def f(*args): return args. PinsCO_VARARGS,ArgCount=0,
single-slot LocalsPlusNames.tests/fixtures/funcbody/017_args_kwarg.py—
def f(**kwargs): return kwargs. PinsCO_VARKEYWORDS.tests/fixtures/funcbody/018_args_posonly.py—
def f(a, /, b): return a. PinsPosOnlyArgCount=1,
ArgCount=2.tests/fixtures/funcbody/019_args_kwonly.py—
def f(a, *, b): return b. PinsKwOnlyArgCount=1,
ArgCount=1.tests/fixtures/funcbody/020_args_full.py—
def f(a, b, /, c, d, *args, e, f, **kwargs): return args. Pins
the full extended layout. Exercises both the bindArgs reorder and
the LocalsPlusKinds per-position kind bits.
Changed
compiler/codegen/visit_funcbody_stmt.go— gates loosened to
accept PosOnly / KwOnly / Vararg / Kwarg. Defaults and non-nil
KwOnlyDef still reject. Validation extended over all named-param
slots (name length 1..15, col ≤ 255, no annotation). Slot-count
cap remains 15.assemble.Optionspopulated:
ArgCount = PosOnly + Args,PosOnlyArgCount,KwOnlyArgCount,
flags includeCO_VARARGS/CO_VARKEYWORDSwhen present.compiler/symtable/build.go::bindArgs— append order corrected
toPosOnly + Args + KwOnly + Vararg + Kwarg.compiler/symtable/scope.go::LocalsPlusKinds— per-position
arg-kind derivation. Backwards-compatible: every pre-v0.7.10.7
fixture used regular positional args only, which still map to
LocalsKindArg(0x26).CHANGELOG.md— v0.7.10.7 entry added.
Tests
- Oracle (
bash tests/run.sh): 265/265 fixtures byte-identical
(was 260/260). - Visitor parity (
go test ./compiler/ -run TestVisitorParity):
byte-identical=224 not-implemented=41 mismatched=0 errored=0
(was 219/41/0/0; the 5 new fixtures all land in the byte-identical
bucket). - All existing tests stay green.
Out of scope (deferred)
- Defaults / KwOnlyDef — v0.7.10.8 (needs
codegen_default_arguments). - Parameter annotations — v0.7.10.10 (decorators+annotations bundle).
- Type params — same release as annotations.
v0.7.10.6
v0.7.10.6 — optimize_load_const + remove_unused_consts 1:1 port
Date: 2026-04-30
Spec: notes/Spec/1500/1564_gocopy_v07106_optimize_load_const.md
Roadmap: notes/Spec/1500/1558_gocopy_v0710x_release_roadmap.md
v0.7.10.6 lifts the visitor's "first-int quirk" out of
compiler/codegen/visit_func_stmt.go and into two CPython-faithful
flowgraph passes ported 1:1 from
Python/flowgraph.c:
flowgraph.OptimizeLoadConstrewrites everyLOAD_CONSTwhose
pool entry is an int in[0, 255]intoLOAD_SMALL_INTwith
the value embedded in the oparg.
MIRRORS:Python/flowgraph.c:2168 basicblock_optimize_load_const:1408 maybe_instr_make_load_smallint.
flowgraph.RemoveUnusedConstscondenses the const pool to
indices that survivingLOAD_CONSTinstructions still
reference, always preserving slot 0 (CPython treats it as the
implicit docstring slot).
MIRRORS:Python/flowgraph.c:3174 remove_unused_consts.
The visitor now mirrors codegen_addop_load_const: every constant
load is addConst(v) + emit LOAD_CONST idx, and the optimizer
earns its keep post-emit. Net byte output is unchanged.
Reduced scope (vs spec 1558's original "v0.7.10.6")
Spec 1558 originally bundled seven flowgraph functions plus the
compiler/optimize/ → compiler/flowgraph/ package move into
this release. The full bundle is multi-day work and would block
fixture-coverage releases. v0.7.10.6 ships the two passes
sufficient to delete the first-int hack; the rest follow:
fold_const_unaryop+fold_const_binop: v0.7.10.7 / .8.- Named-expression / walrus: later, when its fixtures arrive.
compiler/optimize/→compiler/flowgraph/package move: pre-
funeral cleanup at v0.7.10.14.
Added
compiler/flowgraph/optimize_load_const.go(52 LOC) —
OptimizeLoadConst(seq, consts)walks every block, rewriting
LOAD_CONST idx→LOAD_SMALL_INT vwhenconsts[idx]is an
int in[0, 255]. The const-pool entry is left in place; the
follow-upRemoveUnusedConstspass condenses unreferenced slots
except slot 0.compiler/flowgraph/remove_unused_consts.go(90 LOC) —
RemoveUnusedConsts(seq, consts) []anybuilds anindex_map,
marks every used index, always reserves slot 0, condenses the
pool, and remaps every survivingLOAD_CONSToparg to its new
index. Returns the original slice when no entries dropped.compiler/flowgraph/optimize_load_const_test.go(9 cases) —
covers int 0 / int 255 / int 256 / negative int / None / string
pool entries; non-LOAD_CONSTopcodes left untouched; nil seq;
oparg outside pool.compiler/flowgraph/remove_unused_consts_test.go(8 cases) —
covers all-used / slot-0-always-kept / drop-middle / drop-
trailing / remap-all-surviving / empty pool / nil seq /
cross-block.
Changed
compiler/codegen/visit_func_stmt.go—visitFuncConstantExpr
now calls the newemitFuncBodyConstLoad(always
LOAD_CONST + addConst). The old
emitFuncBodyConstLoadFirstIntwas deleted.compiler/codegen/scope.go::popChildUnit— runs
flowgraph.OptimizeLoadConstandflowgraph.RemoveUnusedConsts
beforeoptimize.Run, so downstream passes
(InsertSuperinstructions,OptimizeLoadFast,resolveJumps)
see the canonical opcode shape.CHANGELOG.md— v0.7.10.6 entry added.
Tests
- Oracle (
bash tests/run.sh): 260/260 fixtures byte-identical. - Visitor parity (
go test ./compiler/ -run TestVisitorParity):
byte-identical=219 not-implemented=41 mismatched=0 errored=0
(unchanged from v0.7.10.5). - New flowgraph unit tests: 17 added, all green.
Out of scope (deferred)
010_expr_const_negative.py(def f(): return -3) — still
blocked onfold_const_unaryop. Lands when that pass ships.- Compare-chain shape (
a < b < c) — needs both visitor and
classifier work. Release TBD. - Module-level (top-level) const-pool optimization — only
function bodies and closures go throughpopChildUnit. The
module-level path keeps its current shape until the func_body.go
funeral (v0.7.10.14) makes the visitor the only top-level path.
v0.7.10.5
v0.7.10.5 — funcbody fixtures: small-int return + is None + Compare with const
Date: 2026-04-30
Spec: notes/Spec/1500/1563_gocopy_v07105_load_small_int_isnone.md
Roadmap: notes/Spec/1500/1558_gocopy_v0710x_release_roadmap.md
v0.7.10.5 is a fixture-only release. It adds 6 named regression
fixtures under tests/fixtures/funcbody/ for shapes the
post-v0.7.10.4 pipeline already supports but did not have a
dedicated fixture for: small-int returns, is None /
is not None returns, and single-op Compares with mixed
operand kinds. No source change in compiler/.
Added
tests/fixtures/funcbody/009_expr_const_small_int.py—
def f(): return 7. Pins LOAD_SMALL_INT 7 + RETURN_VALUE in
the trivial zero-arg const-return shape.tests/fixtures/funcbody/011_expr_cmp_is_none.py—
def f(x): return x is None. Pins
LOAD_FAST_BORROW x + LOAD_CONST None + IS_OP 0 + RETURN_VALUE.tests/fixtures/funcbody/012_expr_cmp_is_not_none.py—
def f(x): return x is not None. Pins IS_OP 1.tests/fixtures/funcbody/013_expr_cmp_eq_small_int.py—
def f(x): return x == 0. Pins
LOAD_FAST_BORROW x + LOAD_SMALL_INT 0 + COMPARE_OP eq + RETURN_VALUE.tests/fixtures/funcbody/014_expr_cmp_lt_small_int.py—
def f(x): return x < 5. Pins COMPARE_OP lt with a small-int
RHS.tests/fixtures/funcbody/015_expr_cmp_eq_str.py—
def f(x): return x == "foo". Pins COMPARE_OP eq with a str
constant RHS (forces the const pool to grow past the
small-int slot 0).
Changed
CHANGELOG.md— v0.7.10.5 entry added.
Tests
- Oracle (
bash tests/run.sh): 260/260 fixtures byte-identical
(was 254/254; +6). - Visitor parity (
go test ./compiler/ -run TestVisitorParity):
byte-identical=219 not-implemented=41 mismatched=0 errored=0(was 213/41/0/0; +6 fixtures, all routed through
visitFuncBodyDef→visitFuncCompareExpr/
visitFuncConstantExpr). - No new unit tests: every new fixture exercises an existing
code path; the parity counter is the regression net.
Out of scope (deferred)
fold_const_unaryopport — v0.7.10.6. Fixture
010_expr_const_negative.py(def f(): return -3) is
reserved but not shipped: CPython folds it to
consts=(3, -3) + LOAD_CONST 1, gocopy currently emits
LOAD_SMALL_INT 3 + UNARY_NEGATIVE. The port lands in
v0.7.10.6.basicblock_optimize_load_const+remove_unused_consts
port — v0.7.10.6. Together these will replace the visitor's
emitFuncBodyConstLoadFirstIntfirst-int hack with the
flowgraph machinery CPython uses to produce the same byte
output. (Spec 1558's "delete the quirk" note was overstated
— the behavior is correct CPython output, not a quirk; the
port deletes the visitor-side shortcut, not the behavior.)- Compare-chain shape (
a < b < cand longer) — release TBD.
Both the visitor and the classifier currently reject
multi-op Compares; supporting them needs the chained-CMP
bytecode shape (COPY 1 + TO_BOOL + POP_JUMP_IF_FALSE+
fall-through merge with SWAP/POP) on both paths. Not part
of any currently-scheduled v0.7.10.x release.
v0.7.10.4
v0.7.10.4 — optimize_load_fast 1:1 port
Date: 2026-04-30
Spec: notes/Spec/1500/1562_gocopy_v07104_optimize_load_fast.md
Roadmap: notes/Spec/1500/1558_gocopy_v0710x_release_roadmap.md
v0.7.10.4 ports CPython 3.14
Python/flowgraph.c::optimize_load_fast into the gocopy
flowgraph package as the second flowgraph pass. The visitor
stops emitting LOAD_FAST_BORROW directly; the new pass
performs the strength reduction from the per-block lifetime
analysis CPython uses.
Added
compiler/flowgraph/optimize_load_fast.go—OptimizeLoadFast(mirrors Python/flowgraph.c:2776
optimize_load_fast).killLocal(mirrors Python/flowgraph.c:2707kill_local).storeLocal(mirrors Python/flowgraph.c:2718
store_local).loadFastPushBlock(mirrors Python/flowgraph.c:2728
load_fast_push_block) — implemented inline as the
pushBlockclosure insideOptimizeLoadFast.numPoppedPushed— narrow port of the
_PyOpcode_num_popped/_PyOpcode_num_pushedpair for
the opcodes the visitor currently emits at this pipeline
stage.
compiler/flowgraph/optimize_load_fast_test.go— 7 unit
tests covering: trivial RETURN_VALUE promotion, the
STORED_AS_LOCAL stays-LOAD_FAST guard, BINARY_OP both
borrow, pre-fused LFLF → LFLBLFLB, REF_UNCONSUMED stays
LOAD_FAST, the SUPPORT_KILLED interaction with STORE_FAST,
and the nil-seq edge case.
Changed
-
compiler/optimize/optimize.go::Run— pipeline now runs
flowgraph.OptimizeLoadFast(seq)between
flowgraph.InsertSuperinstructions(seq)and
resolveJumps(seq), approximating CPython's
_PyCfg_OptimizedCfgToInstructionSequenceordering
(Python/flowgraph.c:4062 — runs immediately before
_PyCfg_ToInstructionSequence). -
compiler/codegen/scope_ops.go— bothemitNameLoadand
emitNameLoadCallswitch theirnameOpFastarms from
LOAD_FAST_BORROWto plainLOAD_FAST. The promotion is
now owned byoptimize_load_fast. -
compiler/codegen/visit_funcbody_stmt.go::emitFuncBodyAugAssign
— the LOAD_FAST_BORROW for the AugAssign target becomes
LOAD_FAST. Header comment rewritten to drop the
pre-classifier story and point at
optimize_load_fastas the owner of the borrow
promotion. -
compiler/codegen/visit_funcbody_stmt.go::emitFuncBodyTernaryReturn
— the visitor now emits a CPython-shaped IfExp CFG: the
true branch ends withJUMP_FORWARD → endLabel, the false
branch falls through to a labelled end-merge block whose
sole instruction isRETURN_VALUE. The previous shape
duplicatedRETURN_VALUEinto both branches and
pre-classified the false-branch Name as plain LOAD_FAST.
The new shape letsoptimize_load_fastderive the same
outcome from the CFG: the JUMP_FORWARD predecessor is
inlined (true branch becomes scope-exit-terminated, LF
promoted to LFB), the fall-through predecessor leaves its
load with REF_UNCONSUMED set and stays LF. -
compiler/codegen/visit_functiondef_stmt.go— the
hand-codedLOAD_FAST_BORROW 0at the trivial
def f(arg): return argbody becomesLOAD_FAST 0. The
optimizer promotes it back. Header doc-comment updated. -
compiler/codegen/visit_closuredef_stmt.go— both
hand-codedLOAD_FAST_BORROWinstructions (cell-tuple
build at outer block, inner-function return) become
LOAD_FAST. The optimizer promotes both back. Header
doc-comment updated. -
compiler/optimize/inline_small_exit_blocks.go::inlineSmallExitBlocks
— narrowed to inline a candidate merge tail into
JUMP_FORWARDpredecessors only. Fall-through
predecessors are no longer inlined, and the merge block
survives whenever a fall-through predecessor remains.
This matches CPython's
basicblock_inline_small_or_no_lineno_blocks, which only
acts on blocks ending with an unconditional jump. The old
fall-through inlining over-consumed refs within the
falling-through predecessor and would have caused the new
optimize_load_fastto incorrectly promote aLOAD_FAST
that CPython leaves unpromoted (visible in the IfExp
ternary fixtures 185 / 186).
Removed
-
compiler/flowgraph/insert_superinstructions.go::makeSuperInstruction
— the v0.7.10.3 deviation case
LOAD_FAST_BORROW + LOAD_FAST_BORROW → LFLBLFLBis gone.
With the visitor no longer emittingLOAD_FAST_BORROW,
the pass is a strict 1:1 port of CPython's three pairs:
LF+LF,SF+LF,SF+SF. Header comment rewritten. -
compiler/flowgraph/insert_superinstructions_test.go—
TestInsertSuperinstructions_LfbPairBridgerenamed to
TestInsertSuperinstructions_LfbPairNotFusedand rewritten
to assert thatLOAD_FAST_BORROWpairs are NOT fused at
this stage.
Tests
- 254/254 fixtures byte-identical (
bash tests/run.sh). TestVisitorParity:
byte-identical=213 not-implemented=41 mismatched=0 errored=0 skipped=0 (total=254).
Unchanged from v0.7.10.3 — refactor of where the borrow
promotion runs, not a coverage change.TestOptimizeLoadFast_{TrivialReturn,StoredAsLocal, BinopBothBorrow,LFLF_Pair,RefUnconsumed,KilledByStore, NilSeq}— 7 new unit tests, all PASS.go build / go vet / go test ./...clean.
Out of scope — moves to v0.7.10.5+
LOAD_SMALL_INTquirk removal lands v0.7.10.5.optimize_cfgsub-passes (basicblock-level peephole,
remove_redundant_nops,eliminate_unreachable_code)
land v0.7.10.6.- Wider argument-shape coverage (kw-only, vararg, kwarg,
pos-only) lands v0.7.10.7.