Repository navigation
v0.6.25
v0.6.25 — codegen module-level: funcdef (band C start)
Date: 2026-04-29
Spec: notes/Spec/1500/1535_gocopy_v0625_codegen_funcdef.md
Roadmap: notes/Spec/1500/1523_gocopy_v06x_part2_roadmap.md (band C)
CPython parity: Python/codegen.c (3.14.0): module-level
compiler_function lowering of a FunctionDef whose body is
return arg for a single positional argument.
The v0.6.25 release opens band C of the v0.6.x part 2
roadmap. It teaches the codegen package the modFuncDef shape:
- A single top-level
def f(arg): return argdefinition where
f and arg are 1..15-char ASCII identifiers, the body is a
singlereturn <argName>statement, and there are no
decorators, annotations, type-params, defaults, or variadic
parameters.
This is the first codegen path that emits a nested code
object. The inner function CodeObject and the outer module
wrapper are both hand-built mirroring the classifier's
compileFuncDef byte-for-byte using the existing
bytecode.FuncReturnArg* and bytecode.FuncDefModule*
helpers — no IR/assembler routing for the inner code object
yet (deferred until a later band-C release once the
assembler grows nested-code-object support).
Notable byte-equality details, all mirroring the classifier's
compileFuncDef byte-for-byte:
- Inner function (
f):RESUME 0/LOAD_FAST_BORROW 0
/RETURN_VALUE 0. ArgCount=1, StackSize=1, Flags=0x3
(CO_OPTIMIZED|CO_NEWLOCALS), LocalsPlusNames=[argName],
LocalsPlusKinds=[LocalsKindArg=0x26], Name=QualName=
funcName (no<module>.prefix at module scope),
FirstLineNo=defLine. - Outer module:
RESUME 0/LOAD_CONST 0(the inner
code object) /MAKE_FUNCTION 0/STORE_NAME 0
(funcName) /LOAD_CONST 1(None) /RETURN_VALUE 0.
StackSize=1, FirstLineNo=defLine, co_consts=[funcCode,
nil], co_names=[funcName]. - Inner line table: emitted via
bytecode.FuncReturnArgLineTable— three entries: SHORT0
for RESUME at synthetic firstlineno, FirstLine entry for
LOAD_FAST_BORROW at body line, SHORT0 for RETURN_VALUE at
the return-keyword column. - Outer line table: emitted via
bytecode.FuncDefModuleLineTable— a 5-byte prologue plus
a single LONG entry covering the 5-cu run from
LOAD_CONST/MAKE_FUNCTION/STORE_NAME/LOAD_CONST/RETURN_VALUE
at columns [0, argEnd) on lines defLine..bodyEndLine.
The 246/246 oracle stays byte-identical. The parallel-output
gate (TestCodegenParity) automatically lights up fixture
136 funcdef_simple.py.
Added
compiler/codegen/visit_funcdef.go—funcDefModuletype
plusclassifyFuncDefModule+buildFuncDefModule. Mirrors
compiler/compiler.go::compileFuncDefand
compiler/classify_ast.go::extractFuncDefbyte-for-byte.
Single-statement only so the parity gate stays byte-equal
with the classifier.
Changed
-
compiler/codegen/codegen.go—Buildrecognizes
modFuncDef after modFor, ahead of the ErrUnsupported
fallback. Doc comment updated to record band C opening
and the first nested-code-object shape. -
compiler/codegen_parity_test.go—compileViaClassifier
picks up the modFuncDef classifier path so the parity gate
validates the new codegen-owned fixture against the
classifier reference.
Tests
- 246/246 fixtures byte-identical (
tests/run.sh). compiler/codegen/codegen_test.goadds:
TestBuildFuncDefSimple,
TestBuildFuncDefDifferentNames,
TestBuildFuncDefMismatchedReturnFallsThrough,
TestBuildFuncDefMultipleArgsFallsThrough,
TestBuildFuncDefDecoratorFallsThrough.compiler/codegen_parity_test.goautomatically validates
fixture 136 via the new arm.
Out of scope
- Closures (band C, v0.6.26).
- General function bodies — assigns + return (band C,
v0.6.27). - Decorators, annotations, defaults, vararg/kwarg.
- Multiple positional or kw-only arguments.
- Multi-statement bodies, return of an expression other
than the single arg-Name. - Routing the inner code object through
assemble.Assemble. - Optimizer passes, classifier funeral, perf — bands C and D.