go: types.sx scaffold — synth/check skeleton + 12 tests; Phase 3 starts [shapes-static-types-bidirectional]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s

First slice of Phase 3 (bidirectional type checker).

lib/go/types.sx defines:
  * go-ctx-empty / go-ctx-extend / go-ctx-lookup — context as a value.
  * go-ctx-extend-field — consumes the (:field NAMES TYPE) shape from
    the parser, binding every name to the shared type. This is the
    cross-deliverable validation of the :field binding-group
    observation made during Phase 2 func decls: parser produces it,
    type checker consumes it, same shape end-to-end.
  * go-predeclared — true / false / nil baked in. Full list expanded
    on demand.
  * go-synth — currently handles variable lookup; literals / calls /
    binops follow in subsequent iterations.
  * go-check — v0 defers to synth + structural type equality. Untyped-
    constant flow and assignment-compatibility relations land later.
  * Type errors carry first-class tags (:unbound, :mismatch,
    :unsupported-synth) so consumers and tooling can dispatch.

Conformance.sh wired with new types suite. Scoreboard cleanup: drop
the "pending" types row since the suite is now real.

types 12/12, total 317/317. Phase 3 underway.

Sister-plan static-types-bidirectional diary updated with the
synth/check shape: judgment skeleton, error tag structure, and the
proposal that `check` should accept a `subtype?` predicate parameter
so each consumer (Go untyped-constants, TS variance, Rust lifetimes)
plugs in its own variance discipline without rewriting the judgment.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-27 20:41:02 +00:00
parent 2404a593bd
commit 6c3b7d1cf9
7 changed files with 307 additions and 24 deletions

View File

@@ -214,22 +214,28 @@ Progress-log line → push `origin/loops/go`.
deferred to a follow-up; it doesn't gate Phase 3.
### Phase 3 — Bidirectional type checker, MVP (`lib/go/types.sx`) ⬜
- **Independent implementation.** Do NOT use lib/guest/static-types-
bidirectional/ — that kit doesn't exist yet and depends on this work
for its design. See `plans/lib-guest-static-types-bidirectional.md`.
- Synth + check judgments. Context as a value (per-block scope).
- Coverage MVP: declared-type variables, function signatures (params +
returns), call type-checking, simple composite types (slice, map, chan
element), interface satisfaction (structural match against method sets),
short variable declaration `:=` (synth from RHS).
- **Untyped constants.** `42` has type `untyped int` until contextualised;
this is the canonical pitfall (see Gotchas below).
- Defer: generics (Phase 7), full conversion rules.
- Tests: positive (type-correct programs check) + negative (mismatched
types fail with informative errors carrying AST paths).
- **Acceptance:** types/ suite at 60+ tests. Chisel note `shapes-static-
types-bidirectional` — append a paragraph to the sister plan's design
diary describing what synth/check shape emerged.
- [x] Scaffold: `go-synth` / `go-check` skeletons; context-as-value
(`go-ctx-empty` / `-extend` / `-lookup` / `-extend-field`);
predeclared `true`/`false`/`nil`; structural type equality.
- [ ] Literal kinds in AST (parser change: `(:literal KIND VALUE)`)
+ literal synth (`:ty-untyped-int`/`-float`/`-string`/`-rune`).
- [ ] Binary-op synth with untyped-constant flow (canonical pitfall:
`var x float64 = 42 / 7` must compute as untyped int / int = 6,
then convert to float64).
- [ ] Var/const declaration checking (`var x T = expr`, `var x = expr`,
`const Pi = 3.14`).
- [ ] Function declaration: extend ctx with params via `:field` group,
check body, verify return-list types match signature.
- [ ] Call type-checking (synth callee, check args against param types,
synth result).
- [ ] Composite type element checking (slice / map / chan).
- [ ] Interface satisfaction (structural match against method sets).
- [ ] Short variable declaration `:=` (synth RHS into LHS bindings).
- Defer: generics (Phase 7), full conversion rules, type assertions,
type switches.
- **Acceptance:** types/ suite at 60+ tests. Current: 12/12. Chisel note
`shapes-static-types-bidirectional` — sister-plan design diary is the
cross-language record.
### Phase 4 — Tree-walk evaluator (`lib/go/eval.sx`) ⬜
- AST-walking interpreter over CEK. Each Go statement maps to one step
@@ -528,6 +534,16 @@ Minimal repro: see `lib/go/lex.sx#gl-oct-digit?` and `#gl-match-op`.
_Newest first. Append one dated entry per commit._
- 2026-05-27 — **Phase 3 scaffold.** First `lib/go/types.sx` cut: context
as an association list (`go-ctx-empty` + `-extend` + `-lookup`), a
load-bearing `go-ctx-extend-field` that consumes the `:field` binding-
group shape (validating the Phase 2 cross-deliverable observation),
predeclared `true`/`false`/`nil`, `go-synth` for identifier lookup,
`go-check` deferring to synth + structural equality. types suite
12/12, total 317/317. Literal kinds (untyped int/float/string/rune)
+ binop synth + var-decl checking next. `[shapes-static-types-
bidirectional]` — sister-plan diary updated with the synth/check
Go-side surface as it emerges.
- 2026-05-27 — **Phase 2 complete.** End-to-end multi-form file parsing.
`go-parse` now returns single forms for backward compat (~169 tests
unchanged) or `(list :file FORMS)` for multi-form input. Tests cover

View File

@@ -282,6 +282,36 @@ The kits compose; design accordingly.
_Newest first. Append one dated entry per milestone landed._
- 2026-05-27 — From Go-on-SX Phase 3 scaffold (`lib/go/types.sx` first
cut): the **independent synth/check shape** has landed. Two judgments,
both consuming a context-as-value:
```
(go-synth CTX EXPR) → TYPE-NODE | (:type-error TAG ...)
(go-check CTX EXPR EXPECTED) → :ok | (:type-error TAG ...)
```
Context is an association list of `(NAME TYPE)` bindings; the
load-bearing extension primitive is `go-ctx-extend-field` which takes
a `(:field NAMES TYPE)` binding-group node and binds every NAME to
TYPE. This validates the earlier cross-deliverable observation: the
parser produces `:field` once, the type checker consumes it once,
same shape across struct fields / func params / var-decls.
**Design insight for the kit**: the synth/check pair is the canonical
judgment skeleton. `check` deferring to `synth + structural-equality`
is the v0 default that every consumer overrides for subtype-ish
relationships. The kit's `check` should accept a `subtype?` predicate
parameter so Go (untyped-constant flow), TS (variance), and Rust
(lifetime subtyping) each plug in their own variance discipline
without rewriting the whole judgment. The kit's `synth` stays uniform.
Error shape `(:type-error TAG ...)` with first-class tags
(`:unbound`, `:mismatch`, `:unsupported-synth`) gives consumers and
IDE tooling structured errors to dispatch on. Untyped-constant flow
and binop-synth — the canonical Go pitfall (`var x float64 = 42 / 7`)
— arrive next. Source: Go-on-SX commit landing `lib/go/types.sx`.
- 2026-05-27 — From Go-on-SX Phase 2 (func decls landing): parser-side
observation that's load-bearing for any bidirectional checker. Go's
parser ended up with a single shape — `(list :field NAMES TYPE)` —