Skip to content

gopy file map

One-line per CPython source file, with the target Go package path and a short purpose note. Canonical lookup table for porters.

1602. File map: cpython/Python/* to gopy/*

The mapping is one-to-many: a CPython file may split across several Go files (or vice-versa). Where multiple C files collapse into one Go package, the package’s doc.go lists the source files it derives from.

Conventions:

  • All Go packages live at the module root (gopy/<pkg>). We do not use Go’s internal/ directory convention. See 1601 for rationale.
  • Files named like dynload_*.c and emscripten_*.c are platform glue we do not port. Go’s runtime handles the equivalents. They are listed here for completeness with a -- Go target.
  • Generated headers (generated_cases.c.h, executor_cases.c.h, optimizer_cases.c.h, opcode_targets.h) are regenerated from the CPython DSL via our own Go-emitting code generator. See 1621.

Compiler pipeline

C fileGo targetPurpose
Python/asdl.cast/asdl.goASDL sequence helpers (asdl_seq_*)
Python/Python-ast.cast/nodes_gen.go (generated)Generated AST node constructors
Python/ast.cast/validate.go_PyAST_Validate
Python/ast_preprocess.cast/preprocess.goConstant fold, PEP 765 control-flow checks
Python/ast_unparse.cast/unparse.goAST → source (annotations)
Python/symtable.csymtable/Two-pass symbol table builder
Python/future.cfuture/future.go__future__ extraction
Python/compile.ccompile/compiler.goPipeline orchestration
Python/codegen.ccompile/codegen.go plus codegen_*.go panelAST → instruction sequence (split per stmt/expr family)
Python/instruction_sequence.ccompile/instrseq.goLabeled instruction sequence
Python/flowgraph.ccompile/flowgraph.go, flowgraph_passes.go, flowgraph_stackdepth.goCFG build + optimization panel + stackdepth
Python/assemble.ccompile/assemble.go, assemble_locations.go, assemble_exceptions.go, assemble_varint.goBytecode + PEP 626 line table + PEP 657 exception table
Lib/dis.pycompile/dis.goDisassembler used by the v05test gate
(none)compile/code.goCode value type, mirrors PyCodeObject
(generator output)compile/opcodes_gen.goOpcode constants and metadata (generated)

Bytecode interpreter & frame

C fileGo targetPurpose
Python/ceval.cvm/eval.goEval loop entry & unwind
Python/ceval_gil.cvm/gil.goGIL acquire/release, eval breaker
Python/ceval_macros.hvm/dispatch.goDispatch helpers
Python/bytecodes.c(input to generator)Source-of-truth ISA
Python/generated_cases.c.hvm/opcodes_gen.go (generated)Tier-1 dispatch handlers
Python/opcode_targets.hvm/opcode_targets_gen.go (generated)Computed-goto table replaced by switch
Python/frame.cvm/frame.goPyFrameObject
Python/stackrefs.cvm/stackref.goTagged stack references

Specializer / optimizer / JIT / instrumentation

C fileGo targetPurpose
Python/specialize.cspecialize/PEP 659 adaptive specialization
Python/optimizer.coptimizer/optimizer.goTrace projection, executor build
Python/optimizer_analysis.coptimizer/analysis.goType/global watcher, dataflow
Python/optimizer_bytecodes.c(input to generator)Tier-2 abstract-interp DSL
Python/optimizer_symbols.coptimizer/symbols.goSymbol lattice
Python/optimizer_cases.c.hoptimizer/cases_gen.go (generated)Abstract interp cases
Python/executor_cases.c.hoptimizer/executor_gen.go (generated)Tier-2 interpreter cases
Python/jit.cjit/stub.go (deferred)Copy-and-patch JIT, deferred
Python/instrumentation.cmonitor/instrumentation.goPEP 669 monitoring
Python/legacy_tracing.cmonitor/legacy.gosys.settrace / sys.setprofile
Python/intrinsics.cintrinsics/intrinsics.goINTRINSIC_1 / INTRINSIC_2

State, lifecycle, init, run

C fileGo targetPurpose
Python/pystate.cstate/Runtime / Interpreter / Thread
Python/pylifecycle.clifecycle/lifecycle.goInitialize / Finalize phases
Python/initconfig.cinitconfig/config.goPyConfig
Python/preconfig.cinitconfig/preconfig.goPyPreConfig
Python/interpconfig.cinitconfig/interpconfig.goPer-interpreter config
Python/pathconfig.cpathconfig/pathconfig.gosys.path, prefix, exec_prefix
Python/bootstrap_hash.chash/secret.goPYTHONHASHSEED bootstrap
Python/pythonrun.cpythonrun/REPL, file/string eval
Python/frozen.cimp/frozen.goFrozen module table
Python/frozenmain.ccmd/gopy-frozen/Embedded entry point
Python/import.cimp/import.goimportlib bootstrap, sys.modules
Python/importdl.cimp/importdl_stub.go (deferred)Native .so/.pyd loading, deferred
Python/marshal.cmarshal/marshal.go.pyc wire format
Python/crossinterp.ccrossinterp/XIData, sub-interpreter handoff

Errors, modules, codecs

C fileGo targetPurpose
Python/errors.cerrors/errors.goPyErr_* exception protocol
Python/traceback.ctraceback/traceback.goTraceback objects, formatting
Python/suggestions.cerrors/suggest.go“Did you mean…?” hints
Python/bltinmodule.cbuiltin/__builtins__
Python/sysmodule.csysmod/sys
Python/_warnings.cwarnings/warnings.gowarnings
Python/_contextvars.ccontextvar/contextvars_module.go_contextvars C module
Python/codecs.ccodecs/codecs.goCodec registry, error handlers
Python/modsupport.cmodsupport/modsupport.goPy_BuildValue, module init helpers
Python/structmember.cstructmember/structmember.gotp_members descriptors
Python/getargs.cgetargs/getargs.goPyArg_Parse* parsers

Memory, GC, concurrency

C fileGo targetPurpose
Python/gc.cgc/collector.goGenerational cycle collector (GIL)
Python/gc_gil.cgc/gil.goGIL-build helpers
Python/gc_free_threading.cgc/freethreading.gonogil cycle collector
Python/brc.cgc/brc.goBiased reference counting
Python/qsbr.cgc/qsbr.goQuiescent-state-based reclamation
Python/uniqueid.cgc/uniqueid.goPer-thread refcount index pool
Python/index_pool.cgc/indexpool.goFree index allocator
Python/object_stack.cgc/objstack.goGC mark stack
Python/pyarena.carena/arena.goBump arena (compiler scratch)
Python/thread.cpythread/thread.goThread create/join
Python/lock.cpysync/lock.goPyMutex, _PyOnceFlag
Python/parking_lot.cpysync/parkinglot.goWebKit-style park/unpark
Python/critical_section.cpysync/criticalsection.goPer-object critical sections (nogil)

Note on pysync: we use the package name pysync (not sync) to avoid shadowing Go’s standard library sync package inside the gopy module, since these CPython primitives have semantics distinct from sync.Mutex / sync.Cond.

Strings, numbers, hashing, time, hamt, context

C fileGo targetPurpose
Python/formatter_unicode.cformat/format.go__format__ mini-language
Python/pystrtod.cpystrconv/strtod.gostrtod wrapper (calls dtoa)
Python/dtoa.cpystrconv/dtoa.goDavid Gay shortest-roundtrip dtoa
Python/pystrhex.cpystrconv/hex.gobytes-to-hex helpers
Python/pystrcmp.cpystrconv/cmp.golocale-independent strcmp
Python/mystrtoul.cpystrconv/strtoul.goint parsing
Python/mysnprintf.c(drop, use fmt.Sprintf)n/a in Go
Python/pyhash.chash/hash.goSipHash-1-3, FNV, x86_aes
Python/pyctype.cpystrconv/ctype.goASCII isalpha/isdigit (locale-independent)
Python/pymath.cpymath/pymath.gomath primitives, NaN/Inf
Python/pyfpe.cpymath/fpe.gofloat-point exception handling
Python/hamt.chamt/hamt.goHash array mapped trie (contextvars)
Python/hashtable.chashtable/hashtable.goInternal hash table for caches
Python/context.ccontextvar/context.goPEP 567 contextvars
Python/pytime.cpytime/pytime.gomonotonic, perf_counter, FromSeconds
Python/Python-tokenize.ctokenize/tokenize.gotokenizer C-API hooks
Grammar/Tokens plus Include/internal/pycore_token.h plus Lib/token.pytokenize/types_gen.go (generated by tools/tokens_go), tokenize/types.goToken kind constants and Type.String
Python/getopt.cgetopt/getopt.goargv parsing for python.exe
Python/tracemalloc.ctracemalloc/tracemalloc.goallocation tracing
Python/remote_debugging.cremotedebug/remotedebug.go (deferred)remote debug hooks

Note on pystrconv: same reasoning as pysync. Avoids colliding with Go’s standard library strconv. pystrconv holds the Python-specific string/number routines (dtoa, locale-independent strcmp, mystrtoul). Go’s strconv is used for plain Go conversions.

Misc / drop list

C fileGo target / dispositionNote
Python/getversion.cbuild/version.goHard-coded version string
Python/getplatform.cbuild/platform.goruntime.GOOS/runtime.GOARCH based
Python/getcompiler.cbuild/compiler.go“gopy 0.x using go1.X” string
Python/getcopyright.cbuild/copyright.gostatic copyright string
Python/getopt.cgetopt/Already listed above
Python/dynload_shlib.c--Drop. Go does not load .so extensions
Python/dynload_win.c--Drop
Python/dynload_hpux.c--Drop
Python/dynload_stub.c--Drop
Python/dup2.c--Use Go’s os package
Python/dynamic_annotations.c--TSAN annotations; drop
Python/perf_jit_trampoline.c--perf-jit trampoline; drop
Python/perf_trampoline.c--perf trampoline; drop
Python/asm_trampoline.S--asm; drop
Python/emscripten_*.c--Emscripten platform; drop
Python/fileutils.cfileutils/Path helpers (only the bits not in os/filepath)
Python/condvar.h--Use sync.Cond
Python/config_common.h--autoconf glue
Python/thread_pthread.h--Use Go runtime
Python/thread_pthread_stubs.h--Drop
Python/thread_nt.h--Use Go runtime
Python/crossinterp_*.hcrossinterp/types.goXIData type registry
Python/remote_debug.hremotedebug/header
Python/stdlib_module_names.himp/stdlib_names_gen.goGenerated list of stdlib module names

Go top-level layout

gopy/
├── go.mod                        # module tamnd/gopy
├── cmd/
│   ├── gopy/                     # main interpreter entry (mirror of python.c)
│   └── gopy-frozen/              # embedded-only entry (mirror of frozenmain.c)
├── arena/
├── ast/
├── build/                        # version/platform/compiler/copyright strings
├── builtin/                      # __builtins__ module
├── codecs/
├── compile/                      # codegen, flowgraph, assemble, instrseq
├── contextvar/
├── crossinterp/
├── errors/
├── fileutils/
├── format/
├── future/
├── gc/
├── getargs/
├── getopt/
├── hamt/
├── hash/
├── hashtable/
├── imp/                          # import + frozen + stdlib_names; see 1612
├── initconfig/
├── intrinsics/
├── jit/                          # stub
├── lifecycle/
├── marshal/
├── modsupport/
├── monitor/
├── object/                       # NB: cpython/Objects/* lives in a separate spec series
├── opcode/                       # opcode constants + metadata
├── optimizer/
├── pathconfig/
├── pymath/
├── pystrconv/                    # Python-specific str/number conversion
├── pysync/                       # Python-specific sync primitives
├── pythonrun/
├── pythread/
├── pytime/
├── remotedebug/                  # stub
├── specialize/
├── state/
├── structmember/
├── symtable/
├── sysmod/
├── tokenize/
├── traceback/
├── tracemalloc/
├── vm/
├── warnings/
└── compat/                       # cross-runtime golden tests
    ├── bytecode/
    ├── marshal/
    └── hash/

On flat layout vs internal/

Go’s internal/ directory convention restricts imports to packages within the same module subtree. We deliberately do not use it for gopy, for three reasons:

  1. Embedders: third-party Go programs that embed gopy as a Python runtime (think python -c style execution from Go code) need to import vm, state, lifecycle, compile etc. directly. Burying them under internal/ would block that.
  2. Stdlib re-implementations: the Go-native ports of CPython’s Modules/* and Lib/* live in companion modules (tamnd/gopy-stdlib, etc.). Those need to import from this module’s runtime packages.
  3. Tooling and tests: compat/ and external golden-test harnesses import the same packages the runtime uses. internal/ would force awkward indirections.

Discoverability is preserved by the package name itself. There is no ambiguity that compile, vm, gc, frame etc. belong to the gopy runtime.