Repository navigation
v0.6.13
v0.6.13 — codegen module-level: unary assignment
Date: 2026-04-29
Spec: notes/Spec/1500/1522_gocopy_v0613_codegen_unary_assign.md
CPython parity: Python/codegen.c (3.14.0): module-level
compiler_visit_expr1 for the UnaryOp node, driven by a
top-level Assign.
The v0.6.13 release teaches the codegen package the next
module-level shape after the v0.6.12 binop-assign: a single
<target> = <op> <operand> statement where target and operand
are both Names of 1..15 ASCII chars and <op> is one of
USub, Invert, or Not.
For USub and Invert the bytecode is RESUME, LOAD_NAME,
UNARY_NEGATIVE | UNARY_INVERT, STORE_NAME, LOAD_CONST None,
RETURN_VALUE. For Not the bytecode is RESUME, LOAD_NAME,
TO_BOOL (with 3 cache words), UNARY_NOT, STORE_NAME, LOAD_CONST
None, RETURN_VALUE. co_consts = [None]; co_names = [operand,
target]; co.StackSize = 1.
This is the first codegen path to drive the TO_BOOL + UNARY_NOT
inline-cache path — three cache words (six zero bytes) appended
by the IR encoder based on bytecode.CacheSize[TO_BOOL], and a
shared Loc that run-merges the TO_BOOL + cache + UNARY_NOT span
into a single 5-unit linetable entry.
The 246/246 oracle stays byte-identical. The parallel-output
gate (TestCodegenParity) automatically lights up fixtures
101-103 (3 unary fixtures spanning every UnaryOp operator the
classifier supports).
Note on roadmap deviation
Spec 1508 originally allocated v0.6.13 to driver consolidation,
perf, and the classifier funeral. With codegen still owning only
the assign-family shapes (basic, multi, chained, aug, binop)
plus empty/no-ops/docstring, the classifier still owns ~30
shapes (cmp, bool, ternary, collection, subscript, attr, call,
if/else, while, for, funcdef, closuredef, genexpr, funcbody,
imports, …). Retiring it now would lose fixture coverage.
modUnaryAssign is the next natural codegen step after binop:
same single-line single-statement Name-only family, three
operators, exercises the TO_BOOL + UNARY_NOT inline-cache path
on the codegen surface for the first time. After v0.6.13 codegen
owns every Name-only single-line BinOp / UnaryOp shape that
exists in the classifier.
Driver consolidation, perf, and classifier funeral slide to
later sub-releases once codegen has absorbed enough of the
remaining classifier shapes to retire the reference path
without losing fixtures.
Added
compiler/codegen/visit_unary_assign.go—unaryAssignModule
type,unaryKindCGenum (Neg / Invert / Not), and
classifyUnaryAssignModule+buildUnaryAssignModule. The
classifier accepts only single-statement modules so the parity
gate stays byte-equal with the classifier's
compileUnaryAssign(which has no slot for trailing no-ops).
Changed
-
compiler/codegen/codegen.go—Buildrecognizes the
modUnaryAssign shape after modBinOpAssign, ahead of the
ErrUnsupported fallback. -
compiler/codegen_parity_test.go—compileViaClassifier
picks up the modUnaryAssign classifier path so the parity
gate validates the new codegen-owned fixtures against the
classifier reference. -
compiler/codegen/codegen_test.go— removed the obsolete
TestBuildBinOpAssignUnaryFallsThrough(the shape it
asserted now goes through codegen).
Tests
- 246/246 fixtures byte-identical (
tests/run.sh). compiler/codegen/codegen_test.goadds:
TestBuildUnaryAssignNeg,
TestBuildUnaryAssignInvert,
TestBuildUnaryAssignNot,
TestBuildUnaryAssignNotMultiCharNames,
TestBuildUnaryAssignWithTailFallsThrough.compiler/codegen_parity_test.goautomatically validates
fixtures 101-103 via the new arm.
Out of scope
- modUnaryAssign with a non-name operand (
x = -1) — that's
already handled by the v0.6.9 basic-assign / constant-fold
path. - modUnaryAssign with tail no-ops — classifier accepts but the
v0.0.16 helpers have no slot for them; codegen rejects to
stay byte-equal. - modCmpAssign, modBoolOp, modTernary — later sub-releases.
- Driver consolidation, classifier funeral, perf — later
releases once codegen surface is wide enough. - Function definitions, classes, comprehensions, try/except —
later. - Optimizer passes — later.