Guidance for AI coding agents working in this repository. Every rule below traces to a file in the repo.
Reference Go implementation of Cadence, Flow's resource-oriented smart contract language (module github.com/onflow/cadence). The repo ships the lexer, parser, semantic checker, tree-walking interpreter, a bytecode compiler+VM (bbq/), runtime, stdlib, CLI tools, and the @onflow/cadence-parser npm package. License: Apache 2.0.
Use go 1.24.0 locally (per go.mod); .github/workflows/ci.yml pins go-version: '1.25' for the commands-and-tools job.
make build— builds CLI binaries (cmd/parse/parse,cmd/parse/parse.wasm,cmd/check/check,cmd/main/main) plusbuild-tools(analysis, get-contracts, compatibility-check).make test— runstest-with-compiler+test-with-tracing, thengo test -tags compare_subtyping $(TEST_PKGS).TEST_PKGSexcludes/cmd,/analysis,/tools(Makefile line 91).make test-with-compiler—go test ./interpreter/... ./runtime/... -compile=true(routes the suite through thebbqVM).make test-with-tracing— same packages with-tags cadence_tracing.make test-with-coverage—-race -coverprofile=coverage.txt -covermode=atomic; post-processescoverage.txtviasedto drop zero-line entries.make smoke-test—go test -count=5 ./interpreter/... -runSmokeTests=true -validateAtree=false.make ci/make ci-with-tracing— workflow targets invoked by.github/workflows/ci.yml.make test-tools—test-analysis test-compatibility-check test-subtype-gen.make bench/make bench-common—go test -bench=. -benchmem -shuffle=on -benchtime=$(BENCH_TIME).BENCH_REPSandBENCH_TIMEare overridable; install benchstat viamake install-benchstat.make lint— buildstools/golangci-lint/golangci-lintplus the custom linter.soplugins, then runs with--timeout=5m -v ./....make fix-lintadds--fix.make generate— installsstringer@v0.32.0, thengo generate -v ./.... Required after touching any file with a//go:generatedirective.make check-headers— runs./check-headers.sh(fails on.gofiles missing the Apache 2.0 header or aCode generatedmarker).make check-tidy— runsgenerate, thengo mod tidy, thengit diff --exit-code.make validate-error-doc-links—go run ./cmd/errors validate-doc-links.make release bump=patch|minor|major— drivesbump-version.sh, updatingversion.goandnpm-packages/cadence-parser/package.json.
Concurrent-checker smoke test (from docs/development.md): go test -race -v ./sema/... -cadence.checkConcurrently=10 — runs each sema test 10 times concurrently and asserts error equality.
Compiler/runtime is a pipeline of Go packages at the repo root:
ast/— AST node types; many files pair with*_string.gogenerated viastringer.parser/,old_parser/— current parser and the pre-1.0 parser retained for contract-upgrade compatibility checks.sema/— semantic analyzer / type checker. Contains generators undersema/gen/andsema/type_check_gen/.interpreter/— tree-walking interpreter; includes generated tables (subtype_check.gen.go,type_check_gen/).bbq/— bytecode pipeline:bbq/compiler,bbq/vm,bbq/opcode,bbq/constant,bbq/leb128,bbq/commons,bbq/test_utils. Activated in tests by the-compile=trueflag.runtime/— embedding API:environment.go, CCF/JSON value conversion, storage. Contract-update validation tests live here (contract_update_validation_test.go); the implementation isstdlib/contract_update_validation.go.stdlib/— built-in contracts/functions (crypto, RLP understdlib/rlp/, test framework, PublicKey,contract_update_validation.go);stdlib/contracts/holds embedded Cadence source.common/,errors/,encoding/ccf,encoding/json,values/,format/,pretty/,fixedpoint/,integer/,activations/— supporting packages.cmd/— CLI entrypoints:parse,check,main(REPL/executor),execute,info,lex,json-cdc,minifier,decode-slab,decode-state-values,errors. Usage examples indocs/development.md.tools/— Go tooling plus custom linters (maprange,unkeyed,constructorcheck), agolangci-lintwrapper,analysis,ast-explorer,compare-parsing,compatibility-check,get-contracts,go-apply-expr-diff,pretty,storage-explorer,subtype-gen,staged-contracts-report-printer,update,accounts-script.compat/— Python contract-compatibility suite (pyproject.toml,main.py,requirements.txt); driven by.github/workflows/compat.yaml.fuzz/andfuzz.go— go-fuzz entry point that callsparser.ParseProgramthen constructs asemachecker.npm-packages/cadence-parser—@onflow/cadence-parserv1.10.2;npm run buildcompilescmd/parseto WASM (GOARCH=wasm GOOS=js).test_utils/— shared fixtures (common_utils,sema_utils,runtime_utils,interpreter_utils,contracts). Dot-imports are whitelisted only for these paths.
- License header required. Every
.gofile must contain the Apache 2.0 header or aCode generated (from|by)marker.check-headers.shgreps for it and fails CI otherwise. - Run
make generateafter touching any//go:generatesource. CI runsmake check-tidy, which regenerates and fails on anygit diff. Stringer is pinned tov0.32.0in the Makefile; do not upgrade casually. - Test build tags:
compare_subtyping(enabled bymake test),cadence_tracing(enabled bymake test-with-tracing). Do not add new tags without wiring them into the Makefile targets. -compile=truetest flag runs the suite through thebbqVM. Keep it onmake test-with-compilerandmake test-with-compiler-and-tracing.- No
for-rangeover Go maps. The custommaprangelinter (tools/maprange/maprange.so, loaded via.golangci.yml) reports them.forbidigoadditionally blocksmaps.Keys/maps.Values. Sort keys explicitly for deterministic iteration. - Unkeyed composite literals forbidden outside
_test.go(customunkeyedlinter). - Host function values must carry a static type.
semgrep.yamlrulehost-function-value-without-typeerrors onNewHostFunctionValue($G, nil, $F)andNewUnmeteredHostFunctionValue(nil, $F). CI runssemgrep ci --config semgrep.yaml. - Dot-imports are permitted only for the four
test_utils/*packages andbbq/test_utils(.golangci.ymlstaticcheck.dot-import-whitelist). - goimports local prefix is
github.com/onflow/cadence(.golangci.ymlformatters). Internal imports go in their own import group. - Concurrent sema testing: add
-cadence.checkConcurrently=10when modifyingsema/to surface non-determinism (docs/development.md). - Commit messages: present tense, imperative mood, ≤72-char subject (
CONTRIBUTING.md§Git Commit Messages). Maintainer branches use<github-username>/<issue-number>-<short-title>. - Version bumps:
make release bump=patch|minor|major.bump-version.shrewritesversion.goconst Versionandnpm-packages/cadence-parser/package.json— they must stay in sync. old_parser/is intentionally retained for pre-1.0 contract upgrade compatibility; do not delete.- CODEOWNERS: all files require review from the owners listed in
CODEOWNERS.
- Generated Go sources (105 files, counted via
grep -rl '// Code generated' . --include='*.go'):*_string.go(stringer),interpreter/subtype_check.gen.go,version.go, and any file starting with// Code generated. Regenerate viamake generate. version.go— rewritten bybump-version.sh; edit throughmake release.go.sum— managed bygo mod tidy(enforced bymake check-tidy).- Build artifacts listed in
.gitignore:cmd/parse/parse,cmd/parse/parse.wasm,cmd/check/check,cmd/main/main,tools/golangci-lint/golangci-lint,tools/*/*.so,coverage.txt.