Compare commits

...

88 Commits

Author SHA1 Message Date
agra
74607c4dbc Merge branch 'wt-stdlib-base'
Some checks failed
Build / build-linux (push) Has been cancelled
Build / build-windows (push) Has been cancelled
2026-06-09 23:07:21 +03:00
agra
2d68beb053 refactor(R3): migrate headTypeGate + bareVisibleStructDecl to single walk
headTypeGate and bareVisibleStructDecl were using the same
moduleTypeAuthor + flatTypeAuthorCount pattern that selectNominalLeaf
used before R2. Migrated both to a single collectVisibleAuthors call
with inline type-specific resolution, matching the R2 pattern.

Deleted now-unused helpers: moduleTypeAuthor, FlatTypeAuthor,
moduleTypeAuthorTid, FlatTypeAuthorCount, flatTypeAuthorCount.
Net: -76 lines.

541/541 regression tests pass. 426/426 unit tests pass.
2026-06-09 22:37:18 +03:00
agra
3b4df4ab8d refactor(R2): selectNominalLeaf uses single collectVisibleAuthors walk
Replaces the 3 separate author-collection calls inside selectNominalLeaf
(moduleTypeAuthor + ownConstDeclIsPendingAlias + flatTypeAuthorCount +
forwardAliasOrUndeclared) with a single collectVisibleAuthors call plus
inline type-specific resolution. The flat walk now handles:
- own named type: resolved or forward (slot not yet interned)
- own const_decl: resolved alias or pending (own wins over flat)
- flat named types: ambiguous / resolved / forward
- flat const_decl pending aliases: pending (for forward aliases in imports)

Deletes 3 now-unused helpers: forwardAliasOrUndeclared, constAuthor,
ownConstDeclIsPendingAlias. Net: -17 lines.

541/541 regression tests pass. Issue 0107 repro still outputs 300.
2026-06-09 22:31:12 +03:00
agra
010e644897 fix(R1): own const_decl pending alias wins over flat imports (issue 0107)
When a module declares `A :: B; B :: u64;` and both a flat import and a
namespaced import export `B :: u8`, the flat import's B was discovered by
flatTypeAuthorCount before the own B :: u64 was processed — binding A to
u8 and silently truncating values.

Fix: ownConstDeclIsPendingAlias guard added to selectNominalLeaf between
the own-alias check and the flat-import walk. If the querying module has
an own const_decl for the name that is not yet in type_aliases_by_source,
return .pending so the forward-alias fixpoint resolves it correctly.

Regression: examples/0830-modules-flat-ns-same-name-forward-alias.sx
(x : A = 300 prints 300, not 44). 541/541 tests pass.
2026-06-09 22:16:47 +03:00
agra
5ed54a08ee refactor(R0): delete ResolvedProgram pre-pass; add resolveBare/resolveQualified
Removes the S2.x pre-pass and its 10 NodeRefTable maps — 1934 net lines
deleted. The Resolver gains two lazy functions: resolveBare(name, from,
domain) and resolveQualified(target, name), each returning ResolvedAuthors
(verdict + author set). verdictOver and authoredAsDomainAnywhere move from
ResolvePass to Resolver as private methods. All domain-predicate helpers
(eligibleKind, structDeclOf, fnDeclOf, etc.) are promoted to pub.

Test file trimmed from 1352 to 396 lines; old pre-pass population tests
replaced by focused resolveBare / resolveQualified verdict tests.

540/540 regression tests pass. Zero behavior change.
2026-06-09 21:55:53 +03:00
agra
ccae961dc4 Merge branch 'flow/stdlib/S2.2' into wt-stdlib-base 2026-06-09 16:07:37 +03:00
agra
2ae0ab1cff additive: compute resolver type-demanded verdicts 2026-06-09 15:55:33 +03:00
agra
a8d57521ac feat(stdlib/S2.2): selection verdicts in the resolver [additive]
Move the author-SELECTION SEMANTICS (the verdicts) into the resolver. Every
`.authors` ResolvedRef now carries the verdict the resolver COMPUTES above the
collector — own-wins / single-flat-visible / ≥2-ambiguous / not-visible /
type-vs-value domain-filtered — evaluated over the DOMAIN-ELIGIBLE subset of the
collected author set (`eligibleKind`). This folds the per-kind selection the old
lower-side selectors carried (selectNominalLeaf / flatTypeAuthorCount /
selectModuleConst / selectPlainCallableAuthor / selectGenericStructHead /
headTypeGate / headFnLeak) into ONE uniform computation, closing the
protocol / error-set / foreign per-kind surfaces (E6c/d/e) as resolver behavior.

Template/pack grammar stays carried as `.template` / `.pack` refs — NO
`sig_registration_mode`.

ADDITIVE / PARALLEL / UNCONSUMED: lowering still reads the old selectors, so the
verdict changes no generated byte. No file outside resolver.zig reads
ResolvedRef, so byte-identity is structural. ResolvedRef.authors is wrapped into
{ set, verdict } (the RAW set is preserved; the verdict filters).

Resolver unit tests prove the verdicts on real Phase A facts: the five bare-type
outcomes incl. the type-vs-value filter, and the resolver-target classes the old
selectors get WRONG — 0811 error-set / 0821 protocol-head / 0829 generic-struct
all → ambiguous (two flat authors, none own) and → own-wins (own author present).
The resolver-target corpus stays xfail in run_examples (unconsumed until S3.9);
verdicts asserted via the harness, not by flipping goldens.

Gate: zig build && zig build test (430) && tests/run_examples.sh (540 byte-identical),
all exit 0; tests/resolver-target 18 xfail unchanged.
2026-06-09 15:29:17 +03:00
agra
42acf93401 Merge branch 'flow/stdlib/S2.1c' into wt-stdlib-base 2026-06-09 15:01:41 +03:00
agra
3b1415a287 fix(stdlib/S2.1c): preseed top-level UFCS aliases [additive] 2026-06-09 14:50:51 +03:00
agra
59681e0a09 feat(stdlib/S2.1c): foreign-class + struct-const + UFCS — final 3 domains on the owning pass [additive]
On the S2.1a owning traversal, populate the last three ResolvedProgram side
tables, closing planspec S2.1's full-population acceptance (all ten domains):

  - foreign_class_refs: a bare reference whose collected author is a
    foreign_class_decl is routed here (its own domain) instead of the bare
    type/value/callable table.
  - struct_const_refs: a Type.CONST field access whose base resolves to a
    struct author carrying that const member (mirrors lowering's struct_const_map).
  - ufcs_refs: a ufcs_alias decl (alias -> target author) plus its UFCS-rewrite
    call sites (alias(args), incl. pipe-desugared), via a global traversal-ordered
    alias map mirroring lowering's flat ufcs_alias_map.

Still PARALLEL / UNCONSUMED / RAW: lowering reads the OLD selectors, no consumer
cut over, ResolvedRef stays raw. Byte-identical vs baseline (540 examples).

Population proof extended: a new resolver.test fixture exercises all ten domains
at once and asserts each side table non-empty + node-keyed for the three new ones.
2026-06-09 14:32:27 +03:00
agra
2301b60bb4 Merge branch 'flow/stdlib/S2.1b' into wt-stdlib-base 2026-06-09 14:11:56 +03:00
agra
1f10036a1a fix(stdlib/S2.1b): namespace-qualified parameterized heads [additive] 2026-06-09 14:01:23 +03:00
agra
6b41d113f2 feat(stdlib/S2.1b): namespace-qualified + 3 head domains on the owning pass [additive]
On the S2.1a exhaustive traversal, populate four more ResolvedProgram side
tables, still RAW / PARALLEL / UNCONSUMED:

- namespace-qualified references: an `alias.member` field_access whose base
  alias is a NamespaceEdges[ambient_source] target resolves via
  collectNamespaceAuthors into namespace_refs, keyed by the access node.
- the three HEAD domains at parameterized_type_expr heads, binned by the
  resolved author's decl kind: a struct with type params -> generic_struct_heads,
  a fn/const-wrapped fn with type params -> type_fn_heads, a protocol ->
  protocol_heads. RAW: the whole author set is recorded with no winner picked;
  a name authored as >1 head kind lands a distinct entry in every matching table.

Lowering still reads the old selectors and resolved_program has no consumer, so
generated output is byte-identical. ResolvedRef stays RAW (selection is S2.2);
generics stay symbolic. S2.1c (foreign-class / struct-const / UFCS) owns the
remaining three tables.

Extends the population proof: a resolver unit test asserting all four tables are
non-empty + node-keyed with the expected RAW authors.

Gate (all exit 0): zig build; zig build test (All 427 mod + exe + LSP sweep 574);
tests/run_examples.sh (540 passed, byte-identical); tests/resolver-target
(18 xfail, 0 leaked); m3te ios-sim via the main sx binary.
2026-06-09 13:38:59 +03:00
agra
51ab730b74 Merge branch 'flow/stdlib/S2.1a' into wt-stdlib-base 2026-06-09 13:17:36 +03:00
agra
1fb65e9e75 additive: complete resolver traversal gaps 2026-06-09 13:05:23 +03:00
agra
b46ad8b7a7 feat(stdlib/S2.1a): resolver.zig owning pass + ResolvedProgram scaffold + 3 bare-name domains [additive]
Turn src/ir/resolver.zig from a raw author-collection facade into the OWNING
resolution pass: one exhaustive recursive AST walk (exhaustive switch over
ast.Node.Data with NO else arm, so a new node kind is a compile error here
rather than a silently unvisited subtree) populating a ResolvedProgram.

- ResolvedProgram: all 10 node-keyed side tables declared as
  AutoHashMap(*const ast.Node, ResolvedRef) + symbolic TemplateParamId/
  PackParamId registries. ResolvedRef is the S2.1 RAW form — collected author
  identity (AuthorSet, own ∪ flat), NO verdict (own-wins/ambiguity is S2.2).
- Populate the 3 bare-name domains (type / value-const / callable heads) via
  collectVisibleAuthors(.user_bare_flat); record $T / ..$Ts / $pack[i] as
  SYMBOLIC template/pack refs, never TypeIds. The 7 head/qualified/foreign
  domains stay declared-but-empty (S2.1b/c own them).
- Slot via Compilation.resolveProgram() after the program_index facts are
  wired and before lowerRoot; ResolvedProgram owned on Compilation, borrowed
  *ResolvedProgram lent to ProgramIndex (lowerToIR signature unchanged).
- Population proof unit test over real Phase A facts: the 3 tables are
  non-empty, keyed by node identity, and carry symbolic template/pack refs.

ADDITIVE / PARALLEL / UNCONSUMED: lowering still reads the OLD selectors, so
single-author output is byte-identical. Gate green: zig build; zig build test
(425/425, LSP smoke 574 files no crash); run_examples (540 passed, 0 failed,
byte-identical incl. FFI 12xx-14xx + 1615 ios-sim); resolver-target (18 xfail
unchanged).
2026-06-09 12:29:27 +03:00
agra
b29037b257 Merge branch 'flow/stdlib/S1' into wt-stdlib-base 2026-06-09 11:50:06 +03:00
agra
cd7510067f refactor(stdlib/S1.2): delete module_fns; dissolve legacy_direct_any [additive]
Delete module_fns as a separate function-author fact source. Its authors
already live in the module_decls raw facts, so lowerRetainedSameNameAuthors now
reads function authors straight out of module_decls (filtered to *FnDecl via
fnDeclOfRaw) — the same path → name → RawDeclRef store, fn-filtered. Remove
imports.ModuleFns / FnIndex / indexModuleFns / buildModuleFns / fnDeclOf, the
Compilation.module_fns field + its build + wiring, and ProgramIndex.module_fns.

Remove VisibilityMode.legacy_direct_any (the quarantined own-scope-plus-full-
import_graph mode): no production caller passed it, so the collectVisibleAuthors
and isVisible switch arms that handled it are dead and go too, collapsing
VisEdgeSet to the single flat-import walk. No semantic fallback is introduced;
import_graph stays the transitive-visibility source for findVisibleImpls.

Additive: the old maps stay active and lowering still consumes them — no
lowering consumer is cut over to the DeclTable (that is S3), and no resolution
behavior changes. Tests that drove the removed symbols are rerouted through
module_decls / the flat-edge walk.

Gate over the baseline-green corpus: zig build, zig build test (424/424),
bash tests/run_examples.sh (540 passed) — all exit 0; single-author output
byte-identical; multi-author 0722–0740 stdout/exit unchanged.
2026-06-09 11:36:04 +03:00
agra
8058be2538 feat(stdlib/S1.1): DeclId for every declaration — additive DeclTable [additive]
Build a DeclTable in parallel with the import facts: every RawDeclRef
(source / imported / namespaced / C-imported) gets a stable DeclId carrying
source path, display name, AST node identity, span, and DeclKind. Namespace
targets record their members' DeclIds (NamespaceTarget.member_ids). A generic
struct's template is keyed by DeclId in a parallel struct_template_by_decl
store, written alongside the live name-keyed struct_template_map.

A Debug-only round-trip cross-check (RawDeclRef -> DeclId -> AST node ptr)
asserts the table identifies the same node across the corpus, run from
buildDeclTable and pinned by a unit test.

Additive (S0.1 class: mirror): the old maps stay active and lowering still
consumes them; nothing reads the DeclTable / struct_template_by_decl for
selection yet (the S4 cutover does). Generated IR + output bytes are unchanged
by construction.

Gate over the baseline-green corpus: zig build, zig build test (424/424),
bash tests/run_examples.sh (540 passed) — all exit 0; single-author output
byte-identical (37 .ir snapshots unchanged).
2026-06-09 11:25:04 +03:00
agra
864a14e42b Merge branch 'flow/stdlib/S0' into wt-stdlib-base 2026-06-09 11:00:22 +03:00
agra
ca8bc85120 docs(fork-c/S0): correct two doc-accuracy lines (base-equivalence wording + grounded FFI count)
attempt-2 review fixes (docs-only; contract mechanics confirmed sound):
- README + S0.2 grep-clean: 'S0 HEAD == base' / 'S0 == base' were inaccurate
  (HEAD carries the docs/examples/tests diff). Reword to: production/compiler
  behavior is base-equivalent — zero src/ changes, single-author output
  byte-identical to base by construction — HEAD is a distinct commit, not base.
- S0.3 ledger: drop the stale '116-class corpus' FFI wording for the grounded
  live count (96 entry trees / 95 active markers), matching the S0.1 count note.

No partition / manifest / examples / harness change. Gate green:
zig build + zig build test (LSP sweep 574, no crash) + run_examples (540/0);
m3te ios-sim build via main binary exit 0.
2026-06-09 10:47:42 +03:00
agra
1ce3a4e9e0 docs(fork-c/S0): setup contract — byte-baseline + commit-discipline, E6b disposition + two-corpus partition, A–E6 reuse/delete ledger
S0 of the ratified Fork C plan (zero-legacy name-resolution redesign, S0→S6).
Pure setup/documentation: NO production code change, NO behavior change.
Single-author output byte-identical to wt-stdlib-base by construction.

Deliverables under docs/fork-c/ (docs/, not current/, because current/ is
gitignored and the contract must be committed):

S0.1 — byte-baseline + commit-discipline: the committed examples/expected/*
snapshots are the single-author byte-identity reference; the zero-diff repro is
`zig build && zig build test && bash tests/run_examples.sh`. Resolver-target set
explicitly excluded + listed. Commit-classification rule: mirror | consumer-cutover | deletion.

S0.2 — E6b disposition + two-corpus partition: transitional E6b src NOT merged
(grep-clean: no resolveRegistrationSigTypeInSource / sig_registration_mode /
e6br_gate.test.zig on baseline). Harvested 0811–0829 trees + goldens (never the
src), empirically partitioned by running each through the base compiler vs the
E6b target:
  - baseline-green (mirror-equivalence): 0795–0798 (merged) + 0823, 0828 — given
    examples/expected/ markers, locked into the S0 baseline.
  - resolver-target (known-wrong old behavior): 0811–0822, 0824–0827, 0829 + the
    re-filed E6BR-5 nested-pattern regression — a listed xfail harness under
    tests/resolver-target/ (manifest + TARGET goldens, NO active marker), flips
    active+green at S3.9. 0811/0829 noted as old-selector-wrong on the E6b-unmerged
    base; E6BR-5 subsumed by the whole-AST resolver, NOT an E6b attempt-6.

S0.3 — A–E6 reuse/delete ledger: every load-bearing A–E6 artifact mapped REUSED
(Fork C home) or DELETED/TRANSITIONAL (S3/S6 phase); E6c/d/e dropped, F/H/I/K
absorbed/superseded.

Gate over the baseline-green corpus: zig build + zig build test (LSP corpus sweep
574 files, no crash) + bash tests/run_examples.sh (540 passed, 0 failed) all exit 0.
2026-06-09 10:29:23 +03:00
agra
1f755284d9 Merge branch 'flow/stdlib/E6a' into wt-stdlib-base 2026-06-09 00:05:21 +03:00
agra
b9a67d1042 fix(stdlib/E6a): adopt forward struct stub for recursive enum/union (E6A-1)
attempt-1's per-decl enum/union register path panicked on any valid
self- or mutually-referential top-level enum/union: a `*Name` field in
the body is resolved through the stateless `type_resolver.resolveNamed`,
which has no kind context and forward-stubs an as-yet-unregistered name
as a STRUCT. `internNamedTypeDecl` then `findByName`-adopted that struct
stub and called `updatePreservingKey`, whose kind-stability assert tripped
on struct -> enum/union (types.zig:446). The corpus had no recursive
enum/union, so the gate missed it.

Fix: when the slot `findByName` returns is a wrong-kind forward struct
placeholder (empty-fields struct) for an enum/union/tagged_union
registration, re-key it in place (`replaceKeyedInfo`) under the same
TypeId instead of `updatePreservingKey`. This mirrors how a self-ref
struct adopts its own (same-kind) forward stub; the new helper
`adoptsForwardStructStub` gates the re-key precisely to that case, so a
struct adopting a struct stub and every non-recursive enum/union stay on
the byte-identical `updatePreservingKey`/fresh-intern path.

Regression 0799 (single-author): self-ref union linked cells
(`next: *Node`), self-ref enum/tagged-union (`branch: *Tree`), and a
mutual-ref pair (A holds *B, B holds *A); builds and walks each recursive
link. Fail-before: panic at registerUnionDecl on eed2f99. Pass-after:
exit 0, "union=7 enum=42 mutual=99".

Gate: zig build && zig build test && run_examples.sh all exit 0
(538 passed, 0 failed; 0795-0798 + 0752-0794 + FFI byte-identical);
m3te ios-sim build via the main binary exit 0.
2026-06-08 23:55:46 +03:00
agra
eed2f99f76 feat(stdlib/E6a): per-decl nominal identity for enum + union decls
Give top-level ENUM and UNION decls per-decl nominal identity so two
same-name flat enums/unions intern DISTINCT nominal TypeIds instead of
collapsing to one global last-wins entry. Establishes the reusable
non-struct register path the later E6 kind-steps (E6b error-set, E6c
protocol, E6d foreign-class) extend.

Registration side (was: stateless `type_bridge.resolveInlineEnum/Union`
`findByName` last-wins short-circuit, no Lowering access):
- Split the type_bridge inline builders into a body-BUILDER
  (`buildEnumInfo` / `buildUnionInfo`) + the existing thin interner
  wrappers (field-type positions keep the legacy single-slot path).
- Add `Lowering.registerEnumDecl` / `registerUnionDecl` mirroring
  `registerStructDecl`: build the TypeInfo, intern via
  `internNamedTypeDecl(decl_key, name_id, info, nominal_id)` under the
  per-decl nominal identity (reserved slot id, else `shadowNominalId`).
- Reroute all six enum/union registration dispatch sites (scanDecls
  const-wrapped + top-level, lowerDecls/comptime, block-local, local
  const) to the new path.

Shared infra generalized ONCE:
- Pass-0b genuine-shadow pre-pass now reserves struct/enum/union shadow
  slots of the MATCHING kind, grouped by (kind, name), via a kind-generic
  `topLevelTypeDecl` / `reserveShadowSlot`. A forward/self/mutual ref to a
  shadow name binds to the reserved nominal TypeId.
- `namedRefTid` consults `type_decl_tids` for `.enum_decl`/`.union_decl`
  before the global `findByName`.

No new per-kind resolution path: selectNominalLeaf / headTypeGate /
flatTypeAuthorCount already gate every kind. Single-author /
phantom-double-spelling names keep nominal_id 0 (byte-identical corpus).

Regressions 0795-0798 (enum + union: ambiguity over every bare-type form,
and own-wins with distinct nominal TypeIds), fail-before/pass-after:
0795/0797 exit 0 -> exit 1 with the loud "type is ambiguous" diagnostic;
0796 silently printed `own=.east` -> correct `own=.north`; 0798 hard
`field 'm' not found` error -> correct `own=5 dep=9`.

Gate: zig build && zig build test (423/423) && run_examples.sh (537/537)
all exit 0; m3te ios-sim build via the main binary exit 0.
2026-06-08 23:18:29 +03:00
agra
e5db824477 Merge branch 'flow/stdlib/E5' into wt-stdlib-base 2026-06-08 22:19:36 +03:00
agra
919c7bd855 fix(stdlib/E5): source-aware value-const TYPE inference (F4)
Value-const SELECTION was source-aware for emission/folding (F2/R1/F1), but
expression TYPE inference still read the global last-wins `module_const_map`,
so an inferred return type / coercion on a same-name const borrowed another
module's const TYPE (mixed-type same-name consts were never exercised by the
attempt-1 same-typed goldens).

- expr_typer.zig: the `.identifier` const path now selects via the source-aware
  `selectModuleConst` (own-wins / one-flat-visible) instead of the global
  `module_const_map`. The global map still gates "is this a const name?"; an
  unpartitioned registration-only author emits its global type, and an ambiguous
  bare reference yields `.unresolved` (the emission path diagnoses loudly).
- lower.zig: expose `selectModuleConst` so the type-inference path shares the one
  author selector emission/folding already use.

Audited every `module_const_map` read: emission (4102) and global-init copy
(1447) were already source-aware (attempt-1); the binds-a-value predicate (6400)
is a boolean, not a type read; the in-`selectModuleConst` read (13842) is the
unwired fallback. No sibling inference site leaks.

examples: 0793 mixed-type own-wins inference (A's `K:s32` yields `1`, not the
global `f64`'s `1.000000`); 0794 mixed-type bare → loud ambiguous (exit 1), the
inference change does not mask the ambiguity. Prior E5 surfaces (0786-0792), the
0105 set (0752-0758), E1-E4 type surfaces (0763-0785) and FFI byte-identical;
533 markers green.
2026-06-08 22:07:12 +03:00
agra
189774712f test(stdlib/E5): pin 0786-0792 value-const same-name golden markers
Track the 21 examples/expected/078x golden markers (exit/stdout/stderr for
0786-0792) generated alongside 5df4ac6. The E5 source change and example
sources were committed there; these regression markers were generated on disk
(the example gate passes against them) but left untracked, leaving the tree
dirty and the new regressions unpinned in git. No source or golden content
changes — markers verified byte-for-byte against the current binary via
run_examples.sh (531 passed, 0 failed).

- 0786 own-wins (a=1 b=2)
- 0787 bare same-name two-flat-visible -> loud ambiguous (exit 1)
- 0788 expr-chain value+dimension coherent (a_len=2 a_val=2 b_len=11 b_val=11)
- 0789 imported expr-const nested leaves pinned to author source (val=2 len=2)
- 0790 cross-module same-name cycle-guard, no false cycle (m=3 len=3)
- 0791 multi-level cross-module chain (big=102 bk=11)
- 0792 struct-field registration-time dimension (a_sz=2 b_sz=7)
2026-06-08 21:40:33 +03:00
agra
5df4ac61a7 fix(stdlib/E5): source-aware same-name VALUE consts (own-wins / ambiguous / cross-module expr-chains)
Re-land the value-const analog of the E1-E4 type work, reconciled onto the
current source-keyed resolver and hardened. A same-name VALUE const declared in
multiple flat-imported modules is now resolved per declaring source, not the
global last-wins `module_const_map`.

- imports.zig: `isPerSourceDecl` retains every non-function `const_decl`
  per-source (value consts + type aliases), so each same-name author reaches
  registration as a distinct author of its own module. Functions and var_decls
  keep first-wins.
- lower.zig:
  * `selectModuleConst` over `module_consts_by_source` — own-wins; exactly one
    flat-visible resolves; >=2 flat-visible bare -> loud ambiguous (consistent
    with the 0755 type / 0724 fn / 0782 generic ambiguities). Rewires every
    consumer: `comptimeIntNamed`, the runtime-id read, the global-init read,
    and the float-name path (`lookupFloatName` / `nameIsFloatTyped`).
  * `SourceConstCtx` + `foldSourceConstInt`/`Float` + `sourceConstIsFloatTyped`
    fold a selected const's RHS with nested same-name leaves re-selected in
    their own author source, so VALUE and array-DIMENSION results are coherent.
  * `pinConstAuthorSource` pins each fold level to the SELECTED const's author
    (F1), including multi-level cross-module chains.
  * cycle guard keyed on (name, author-source), not name alone (F3), so
    same-name nested consts across modules do not trip a false cycle.
  * `emitModuleConst` takes the author source and pins while folding/lowering.
  Registration-time struct/inline-type field dimensions route through the now
  source-aware stateful reader; the type-alias dimension path resolves each
  alias against its own author's consts.
- program_index.zig: expose `isFloatConstType` / `isCountableConstType` for the
  source-aware folds.

examples: 0786 own-wins, 0787 ambiguous (exit 1), 0788 expr-chain value+dim
coherent, 0789 leaf-author-pin, 0790 cross-module cycle-guard (F3), 0791
multi-level cross-module chain, 0792 struct-field registration-time dim.
Single-author corpus byte-identical (524 prior markers green); 531 total.
2026-06-08 21:29:31 +03:00
agra
37c3b1e1f4 Merge branch 'flow/stdlib/E4' into wt-stdlib-base 2026-06-08 20:50:24 +03:00
agra
6406d0fb1f fix(stdlib/E4): collapse generic-struct author matrix into four choke-points
The generic-struct author-selection matrix {bare,qualified} × {site} × {layout,
body} drifted per-site across 12 attempts because method bodies were resolved by
bare template name in `fn_ast_map["Box.method"]`, independent of which author
produced the instance's layout. Collapse it into four choke-points so
layout-author ≡ body-author by construction:

  CP-1 `selectGenericStructHead` — the single layout-head selector every generic
       struct head site funnels through (alias-RHS .call/.parameterized, array-
       literal, static head, resolveTypeCall/ParameterizedWithBindings). Emits the
       visibility / missing-member diagnostics inline; returns a control-flow-only
       union. No head site reads `struct_template_map` for selection directly.
  CP-2 author stamp — non-optional `decl: *StructDecl` on `StructTemplate` (set at
       the sole producer `buildGenericStructTemplate`) + `struct_instance_author`
       written at `instantiateGenericStruct` from the SAME `tmpl` that builds the
       layout; re-stamped on the dedup fast-path so an instance is never returned
       without an author.
  CP-3 alias metadata copy — mirror template/bindings/author from the mangled
       instance onto the alias display name, so an `ABox`-typed receiver is a
       first-class dispatch instance (Counter-2).
  CP-4 `genericInstanceMethod` / `ensureGenericInstanceMethodLowered` — the single
       body reader: inline methods select via the stamped author (`structMethodFn`,
       source-pin follows for free); impl-block methods fall back to the template-
       keyed `fn_ast_map` entry. Routes the four bespoke body sites (static head,
       instance dispatch, param typing, protocol thunk) + the new qualified static
       head (`a.Box(s64).make(7)`, finding #2).

A debug assert locks `struct_instance_author` / `struct_instance_template` keyset
coincidence so a future third writer that forgets the author trips a test.

Goldens 0777/0778/0780 (bare instance method — ptr/by-value/param-typed, finding
#1), 0779/0785 (qualified static head + missing member, finding #2), 0783 (alias
instance dispatch, Counter-2), 0782 (ambiguity containment). 0414/0415/0543 and
the FFI suites stay green.
2026-06-08 20:34:53 +03:00
agra
7ba64d5756 fix(stdlib/E4): bare generic static-method head selects the visible author (type + method)
The static-method-call head `Box(s64).make(7)` was the last uncovered bare-
generic-head instantiation site: it gated visibility with `headTypeLeak` but
then instantiated the global last-wins `struct_template_map` entry and ran the
name-keyed `Box.make` from `fn_ast_map`, so a NON-visible 2-flat-hop same-name
template (and its method) won. `size_of(Box(s64))` picked the visible `b.Box`
(8) while `Box(s64).make(7)` returned a `c.Box`-shaped (16) value.

Route the static-method head through the single bare-VISIBLE author for BOTH
the instantiated type layout AND the method body: split the existing visible-
author selection into `bareVisibleStructDecl` (returns the StructDecl + source;
single selection point, `bareVisibleStructTemplate` now delegates to it — no
drift) and source-pin the method body via the author's own `sd.methods`
(`structMethodFn`) instead of the last-wins `fn_ast_map`. Ambiguity (>1 visible
author) is already diagnosed by the pre-existing `headTypeLeak` gate.

Exhaustive bare-head instantiation-site audit (all callers reaching
`instantiateGenericStruct` / `struct_template_map` for a bare head): .call alias,
.parameterized_type_expr alias, resolveType .call, resolveTypeCallWithBindings,
resolveParameterizedWithBindings — all already route through the visible-author
selection; the static-method head was the only remaining one and is now covered.

Regression 0776: bare generic static-method head with a 2-hop same-name template
asserts the visible author's layout (xtype=8, x reachable); fail-before xtype=16.
2026-06-08 19:06:13 +03:00
agra
246883073c fix(stdlib/E4): bare generic head selects visible author; qualified missing-member diagnoses
E4 non-transitive type rule had two generic-head author-selection holes:

#1 A BARE generic struct head / alias with a single bare-VISIBLE author still
   instantiated a NON-visible 2-flat-hop same-name template, because the
   `.unregistered` gate arm fell through to the global last-wins
   `struct_template_map` winner. Add `bareVisibleStructTemplate`: after the
   visibility gate passes, select the source-keyed template authored by the
   single bare-visible author (own-wins, else the one 1-hop flat author) and
   instantiate THAT instead of the global map's last-wins entry. Null (→ the
   global map, byte-identical) when the visible author IS the canonical one
   (the common single-author case) or the picture isn't a clean single author.
   Applied at every bare generic-struct head/alias site (annotation `.call` /
   `.parameterized_type_expr`, alias-registration `.call` /
   `.parameterized_type_expr`, array-literal head).

#2 A QUALIFIED head `a.Box(..)` whose namespace `a` authors no member `Box`
   silently fell back to the bare global template, instantiating an unrelated
   module's `Box`. Add `qualifiedMemberMissing`: a qualified head whose known
   namespace lacks the member now emits "namespace 'a' has no member 'Box'" and
   poisons with `.unresolved`; a qualified head NEVER reaches the bare global map.

Regressions: 0774 (bare head + bare alias, 2-hop same-name → size=8 alias=8,
fail-before 16 16); 0775 (qualified missing member → diagnostic + exit 1,
fail-before size=16 exit 0).
2026-06-08 18:39:53 +03:00
agra
8c59acbd25 fix(stdlib/E4): qualified generic alias head a.Box(..) selects the namespace author
The const-decl alias-registration path treated a qualified generic head
(`ABox :: a.Box(s64)`) only as a gate exemption, then read the bare last-wins
`struct_template_map` — so `ABox` and `BBox` both instantiated whichever
same-name template won globally (both size 16). attempt-9 routed the annotation
head sites through `qualifiedStructTemplate`; this applies the same selection to
the two alias-registration branches (.call and .parameterized_type_expr) before
the bare fallback, and extracts the shared instantiate-and-register logic into
`registerGenericStructAlias`.

ABox :: a.Box(s64) now resolves to a's template (size 8); BBox :: b.Box(s64) to
b's (size 16). Regression 0773 pins it (fail-before alias a=16 b=16, after a=8
b=16).
2026-06-08 17:56:29 +03:00
agra
eb7636d0f3 fix(stdlib/E4): qualified generic head ns.Box(..) selects the namespace author
A qualified generic type head `ns.Box(args)` was stripped to its bare name and
read from the last-wins `struct_template_map`, so the namespace qualifier never
selected the template author: `a.Box(s64)` and `b.Box(s64)` (two namespaces each
authoring a same-name `Box($T)` with different layouts) both instantiated the
global same-name template. The documented ambiguity escape hatch ("qualify it as
ns.Box") silently produced the wrong layout.

Select the template via the namespace edge (importer -> alias -> NamespaceTarget)
instead of the bare map, at both the .call and parameterized-type-expr head
sites. Two same-name templates instantiated with the same args would also collide
on the mangled name `Box__s64`, so tag the non-canonical author's mangled name
with its source (the canonical bare-map author keeps the untagged name -> no
churn for single-author generics).

Extract `buildGenericStructTemplate` so the bare registration and the new
namespace-qualified selection share one template builder.

Regression: examples/0772 — two namespaces each authoring Box($T) with different
layouts; ns_a.Box(s64) and ns_b.Box(s64) resolve to their own module's template
(sizes 8 and 16). Fail-before on 566de96 (a=16 b=16), pass-after (a=8 b=16).
2026-06-08 17:19:41 +03:00
agra
566de96821 fix(stdlib/E4): type-fn head gate selects the TYPE-FUNCTION author (ordinary fn must not vouch)
attempt-7 made the type-fn head gate kind-aware (a non-function no longer
vouches), but it still accepted ANY function author: a directly-visible
ORDINARY function (`Make :: () -> s32`, zero `$`-params) authorized a hidden
2-flat-hop type-function head (`Make :: ($T) -> Type`), so `size_of(Make(s64))`
silently instantiated the 2-hop type-fn and printed `size=8` at exit 0.

Narrow the author view from "any fn_decl" to "a TYPE-FUNCTION" via a new
`typeFnAuthor` predicate (`fnDeclOfRaw` + `type_params.len > 0`), the same
discriminator every instantiation site uses to recognize a type-fn head. Both
`flatFnAuthorVisible` and `flatFnAuthorAmbiguous` now count only type-fn
authors, so a same-name ordinary function — which cannot be the type head being
instantiated — does not vouch for a 2-hop type-fn head.

Regression 0771: main -> b (`Make :: () -> s32` ordinary fn + flat-imports c)
-> c (`Make :: ($T) -> Type`); `size_of(Make(s64))` -> "type 'Make' is not
visible", exit 1 (fail-before on 94c3cd7: size=8 exit 0). 0770 (non-fn vouch),
0769 (type-fn ambiguity), 0768/0767/0766-0763, 0208/0210 (valid type-fn heads),
0544/0706/0105 and FFI all green & byte-identical.
2026-06-08 16:43:01 +03:00
agra
94c3cd7507 fix(stdlib/E4): kind-aware type-fn head gate (non-fn must not vouch)
The type-fn head visibility check (`headFnLeak`) used the module-scope
NAME predicate `isNameVisible`, so a same-name 1-hop NON-function (a value
const `Make :: 123`) reported the name "visible" and let the global
`fn_ast_map` type-fn — whose real author is 2 flat hops away — silently
instantiate. `size_of(Make(s64))` printed 8 at exit 0 instead of a
visibility diagnostic.

Decide visibility from the ELIGIBLE FUNCTION authors directly reachable
from the use site (`flatFnAuthorVisible`, mirroring `flatFnAuthorAmbiguous`'s
fn-only author view): visible iff the own author or a 1-hop flat-import
author is a `fn_decl`. A non-function does not vouch. Guarded to fall open
when the import facts aren't wired (comptime / directory imports), mirroring
`headTypeGate`. Own / scope-local / 1-hop / directly-imported type-fn heads
still resolve; 0769 ambiguity unchanged.

Regression: examples/0770-modules-type-fn-head-non-transitive (main → b
[`Make :: 123` + flat-imports c] → c [`Make :: ($T) -> Type`]); the bare
`Make(s64)` head emits "type 'Make' is not visible", exit 1.
2026-06-08 16:03:23 +03:00
agra
cb9ef381b5 fix(stdlib/E4): own-wins at non-leaf bare-type sites + type-fn head ambiguity
attempt-6: address Adi's two in-scope findings (#3 deferred to E6).

#1 E4-own-author-type-arg (silent-wrong): the bare-TYPE gate returned
`.proceed` for the querying source's OWN author, so the non-leaf sites
(reflection / type-arg / array-literal / type-value / match arm) dropped it
and re-resolved a same-name flat import via global `findByName`. headTypeGate
now resolves the own author to ITS per-source TypeId (mirroring
selectNominalLeaf's own-wins, 0754); the type-as-value and type-match sites,
which only consumed the poison bit and re-resolved globally, now route through
the gate and use the `.resolved` author. size_of(Widget) with an own + imported
Widget now yields main's own size, not the import's.

#2 E4-type-fn-head-ambiguity (silent-wrong): headFnLeak only checked
isNameVisible, so two flat same-name type-returning functions both reported
"visible" and one was silently instantiated. It now diagnoses >=2 distinct
direct flat type-fn authors (no own author) as ambiguous before the
isNameVisible short-circuit, consistent with the parameterized struct /
protocol heads and the leaf (0755/0767). Own / single / diamond-collapse
type-fn heads still resolve.

Regressions: 0768 (own-wins at every non-leaf bare-type site, fail-before
reflection=16 -> pass-after 8) and 0769 (two flat Make type-fns -> ambiguity
diagnostic exit 1). README: own-wins + type-fn-head ambiguity at every bare-type
site.
2026-06-08 15:22:10 +03:00
agra
382f78f49b fix(stdlib/E4): carry full author outcome through the bare-TYPE gate (ambiguity at every site)
attempt-4 gated every bare-type-reference site for VISIBILITY via a boolean
leak-check that only caught not-visible and DROPPED the ambiguous outcome, so two
DIRECT flat same-name type authors (the 0755/0105 ambiguity case) fell through to
a global findByName / struct_template_map pick at the non-leaf sites.

Unified author-outcome fix (one path, every site consumes it):

- flatTypeAuthorCount: ≥2 distinct flat authors that do NOT all collapse onto one
  shared TypeId are now `.ambiguous` even when none carries a concrete TypeId yet —
  two same-name GENERIC TEMPLATES (template name registered in no findByName slot)
  are a genuine collision, exactly like two registered structs. Identical-target
  authors (diamond import / two aliases onto the same target) still collapse to
  `.one`, so all valid cases stay byte-identical.

- headTypeGate: the complete source-aware author outcome (.proceed / .resolved /
  .ambiguous / .not_visible) for an unqualified bare TYPE head, emitting the loud
  ambiguity diagnostic (consistent with the leaf / 0755) or the not-visible
  diagnostic. headTypeLeak is now its poison-vs-proceed projection, so every head /
  instantiation / alias-decl / match site poisons on ambiguity with the right
  message. Reflection / type-arg and array/vector-literal identifier heads consume
  `.resolved` to use the source-keyed TypeId, never a global findByName pick.

Regression examples/0767: size_of(Thing) / Nums.[1,2] / Box(s64) / t:Type=Thing /
case Thing: with two direct flat same-name authors each emit the ambiguity
diagnostic, exit 1 (fail-before on bb8f7dc: exit 0 / cascade). 0763/0764/0765/0766
/0755/0706/0544/0105 + FFI byte-identical. README: bare-type ambiguity is enforced
at every reference site.
2026-06-08 14:15:34 +03:00
agra
bb8f7dc5ec fix(stdlib/E4): route reflection/literal/value/match bare-type sites through the non-transitive gate
attempt-3 closed the leaf + parameterized-head leaks but several more
sites still resolved an UNQUALIFIED type name via the global
type_alias_map / findByName / type_bridge.resolveAstType without the
single-hop visibility gate, so a 2-flat-hop bare type leaked through:

  - resolveTypeArg (reflection / size_of / align_of / type_name / type_eq):
    identifier + type_expr leaves now gate via headTypeLeak; the wrapped /
    structural forms (*T, [N]T, []T, ?T, fn-ptr, tuple) route through the
    already-gated resolveTypeWithBindings so each inner leaf recurses the
    source-aware resolveNominalLeaf.
  - resolveTupleLiteralTypeArg: each element leaf is resolved through the
    source-aware resolver before the delegated build, so (COnly, s64) is
    gated.
  - resolveArrayLiteralType (T.[...] typed array/vector-literal head):
    identifier + type_expr leaves gate via headTypeLeak.
  - type-as-value lowerExpr identifier (x: Type = COnly, x == COnly).
  - type-category match arm (case COnly:).

Qualified ns.X / 1-hop / source-pinned library-internal references stay
exempt (the gate falls through for reachable / unauthored names, and
returns the existing "unresolved type" diagnostic for genuinely-undeclared
names). README notes the type gate holds wherever a bare type name is
named. New regressions 0765 (2-hop reject) / 0766 (1-hop pass).
2026-06-08 13:18:51 +03:00
agra
4f99fb0d85 fix(stdlib/E4): gate unqualified parameterized type heads non-transitively
attempt-3: extend the E4 single-hop bare-TYPE gate to parameterized type
HEADS (the constructor-head analog of the bare-leaf gate). Before this, the
head lookup hit the global struct_template_map / protocol_ast_map /
fn_ast_map *before* any source-aware visibility check, so a 2-flat-hop
imported generic struct/protocol/type-fn remained bare-visible (e.g.
`Box(s64)` when main imports only b.sx and b.sx imports c.sx).

- headTypeLeak: generic-struct / parameterized-protocol heads use the same
  type-author single-hop model as the bare-leaf gate (moduleTypeAuthor +
  flatTypeAuthorCount + localTypeInSource + nameAuthoredAsTypeAnywhere).
- headFnLeak: type-returning-function heads use single-hop function
  visibility (isNameVisible), exempting scope-local mangled type-fns.
- Gated at every unqualified head site: resolveParameterizedWithBindings,
  resolveTypeCallWithBindings, the scanDecls alias-decl dispatch (poisoning
  the alias with .unresolved on leak), resolveArrayLiteralType, and the
  generic-static-method call path. Namespaced (`ns.Box(..)`) heads are an
  explicit qualified reach and stay exempt. Source-pinned instantiation
  (E3/E4) is preserved, so library-internal heads still resolve where they
  are visible.

Regression: examples/0764-modules-import-generic-head-non-transitive
(2-hop `Box(s64)` -> "type 'Box' is not visible", exit 1; direct #import
resolves). Fails-before on a250964 (printed 3), passes-after.

README: note the non-transitive rule covers parameterized type heads.

Gate: zig build 0, zig build test 0 (LSP 522, 423/423), run_examples
505/0, FFI 12xx/13xx/14xx green, 0706/0763/0544/0105 green & byte-identical,
m3te ios-sim build+launch exit 0.
2026-06-08 12:37:00 +03:00
agra
a250964ced fix(stdlib/E4): source-pin pack-fn fixed-prefix param types to the defining module
E4's pack-fn source-pin was incomplete: an imported pack function's
fixed-prefix (non-pack) parameter types were resolved in the CALLER's
module, so a param whose type is bare-visible only in the pack fn's own
module was wrongly rejected with "type 'X' is not visible" — even though
the equivalent plain fn (typed via the source-pinned call-arg path) ran
fine.

Two sites in the pack-mono path re-resolved the fixed-prefix param type
in the caller's context:
  - lowerPackFnCall: the call-site arg-typing pass (to contextually type
    the arg from its param) — fires first.
  - monomorphizePackFn: the body parameter binding, after the caller
    source was restored from the signature build.

Both now resolve via resolveParamTypeInSource(fd.body.source_file, &p),
pinning to the pack fn's defining module — matching the already-pinned
signature build, the body lowering, and the cross-module call-arg typing
sites. The call-site arg itself is still lowered AFTER, in the caller's
context (issue 0106).

Regression: examples/0544-packs-imported-pack-fn-fixed-param-source-pin
(main -> lib -> dep; `Needs` two flat hops away, never named in main).
Fails pre-fix with "type 'Needs' is not visible"; passes after. A control
plain fn in the same lib already ran, isolating the pack-mono path.
2026-06-08 11:52:23 +03:00
agra
9d5143aee6 fix(stdlib/E4): source-pin sx-defined objc-class IMP trampolines + finish non-transitive bare-TYPE gate
Final E4 piece: the IMP trampolines emitted for an sx-defined #objc_class
resolved their method-signature types (e.g. -> BOOL) at whatever lowering
site triggered emission, not the class's defining module — so under the
single-hop bare-TYPE gate a 2-flat-hop objc type (BOOL via uikit->objc)
leaked as 'not visible' when m3te's main triggered emission.

- ast.ForeignClassDecl gains source_file (stamped by resolveImports, like
  ProtocolDecl/StructTemplate); stampFnBodySource stamps the decl + each
  bodied method body.
- emitObjcDefinedClassImps pins current_source_file to fcd.source_file for
  the whole per-class emission (alloc/dealloc/method/property IMPs).
- Removes the BOOLLEAF debug probe.

Completes E4: bare-TYPE visibility is single-hop non-transitive across all
member kinds; every instantiation kind (generic struct/fn, pack fn, param
protocol, type fn, objc-block, objc-class IMP) is source-pinned to its
defining module. Full gate green; m3te ios-sim builds + launches (exit 0).
2026-06-08 11:22:05 +03:00
agra
33a6f5c650 wip(E4): partial source-pin + non-transitive flip [stdlib E4 attempt-1 WIP checkpoint]
Incomplete WIP from a worker killed at the 55-min wall (large blast radius:
core source-pin + ~8 example migrations + ~10 library module migrations).
Committed so the resumed session continues on a clean tree. May not build.
2026-06-08 11:12:08 +03:00
agra
4d539eeacd Merge branch 'flow/stdlib/E3' into wt-stdlib-base 2026-06-08 10:14:27 +03:00
agra
3816bfff47 fix(diag): source-key local_type_names so a caller block-local can't leak into an imported template field [stdlib E3 attempt-5]
A block-local type is visible only within the source that declares it. The
global `local_type_names` set was source-insensitive, so an imported generic
template's field (resolved in the template's source context, attempt-4) could
bind a type the CALLER declared block-local — silently compiling an undeclared
imported field instead of diagnosing it.

Key `local_type_names` by declaring source. The bare-TYPE gate now resolves a
local only when the query originates in the local's own source (R2 preserved);
a same-name block-local of a DIFFERENT source routes to the undeclared path so
the leak surfaces (`unknown type '...'`, exit 1) instead of escaping via the
`registered` catch-all that would otherwise resolve the globally-registered
cross-source local.

Regression: examples/0762 — imported `Bad :: struct($T) { x: T; y: LocalOnly; }`
with `LocalOnly` declared only in the caller `main` now errors in lib.sx
(fail-before on 8162170 printed `1 9` exit 0).
2026-06-08 10:02:33 +03:00
agra
81621703ca fix(diag): imported generic struct field with bad type → diagnostic, not .unresolved/silent stub [stdlib E3 attempt-4]
attempt-3 closed the MAIN-file value-param-as-type quadrant (0172) in the
UnknownTypeChecker, but the checker only walks main-file decls — an IMPORTED
generic struct's field with a bad type name was never checked. Worse, the
generic-struct INSTANTIATION resolved its field type nodes in the (possibly
cross-module) instantiation site's source context, not the template's module.
So for `Bad :: struct($N: u32) { x: N; }` declared in an imported module and
used as `Bad(3)` from main, the field `x: N` resolved against the main file:
the value-param-as-type leaf poisoned it with `.unresolved` and PANICKED at
LLVM emission, and the genuinely-undeclared sibling (`y: Missing` in a generic
import, distinct from the non-generic 0759 case) silently fabricated a 0-field
stub.

Root cause + uniform fix: capture the declaring module on each StructTemplate
and resolve its field type nodes in THAT source context during
instantiateGenericStruct. The source-aware nominal leaf then classifies main vs
imported by the TEMPLATE's file, so both failure modes are diagnosed at the
right authority for every quadrant — main + imported, undeclared name + value
param used as a type:
- imported `.undeclared` field → the existing leaf emits "unknown type 'X'"
  (now reached because `from` is the template's module, not main).
- imported value-param-as-type → the `is_generic` leaf, when the name is bound
  as a comptime VALUE (`comptime_value_bindings`), emits the tailored
  "'N' is a value parameter, not a type" hint (gated to non-main; the
  UnknownTypeChecker owns the main-file case). Caught in every type position
  (`x: N`, `*N`, `[3]N`, `?N`). A genuinely-unbound type param (`$R`) stays a
  silent `.unresolved`.

No `.unresolved` reaches LLVM for these cases (hasErrors halts after lowering);
the emit_llvm `.unresolved` @panic tripwire stays as the last-resort sentinel.
Valid value-param VALUE positions (`[N]u8` dim, `Vector(N,T)` lane) and
`$T:Type`/`$T:Protocol` type-param fields still resolve.

Regressions:
- 0760-modules-imported-generic-value-param-as-field-type (panic-before / clean
  diagnostic-after).
- 0761-modules-imported-generic-undeclared-field (silent-compile-before / clean
  diagnostic-after).
0171/0172/0759 stay green; main-file quadrants emit exactly one error.

Gate: zig build; zig build test (423/423 + LSP corpus sweep); run_examples 501
passed / 0 failed (prior 499 byte-identical); m3te ios-sim build exit 0.
2026-06-08 09:37:52 +03:00
agra
a0390a63ab fix(diag): generic VALUE param ($N: u32) used as a field/annotation type → diagnostic (no .unresolved LLVM panic) [stdlib E3 attempt-3]
The generic-struct field checker (attempt-2) accepted ALL struct type
params as valid type-name leaves, including VALUE params. The parser
marks any reference to a struct's own param `is_generic` (so `x: T`
resolves without `$`), and it marks a value param `$N: u32` the same
way — so `Bad :: struct($N: u32) { x: N; }` instantiated `Bad(3)` slipped
past the unknown-type walk, resolved the field's type leaf to the
`.unresolved` sentinel, and panicked at LLVM emission instead of
diagnosing.

Distinguish TYPE params (`$T: Type`, `$T: SomeProtocol`, the `..$Ts`
pack) from VALUE params (`$N: u32`) using the binder's own classification
rule (lower.zig). A value param named in a type position now gets the
tailored "'N' is a value parameter, not a type" hint, exit 1, before
codegen. Two dispatch paths covered: the `is_generic` struct-field path
(reportIfValueParamInTypePosition) and the non-generic annotation path
(reportIfUnknownType in-scope filter). A value param in a VALUE position
(array dim `[N]u8`, `Vector` lane) still resolves.

Regression: 0172-types-value-param-as-field-type (panic-before / clean
diagnostic-after). 0171 and 0759 stay green; 499 markers, prior
byte-identical.
2026-06-08 09:02:54 +03:00
agra
a4906975bd fix(diag): undeclared type in a main-file generic struct field → diagnostic (no silent stub) [stdlib E3 attempt-2]
Closes the main-file carveout left by attempt-1 (4072689): a genuinely-
undeclared type used as a field type inside a MAIN-file GENERIC struct still
fell through the type leaf's empty-struct stub and silently compiled —
`Box :: struct($T: Type) { good: T; bad: MissingType; }` with `b : Box(s64)`
exited 0 and printed a value instead of reporting `unknown type 'MissingType'`.

Root cause: `UnknownTypeChecker` is the main-file diagnostic authority (the
type leaf defers to it for `.undeclared` names there), but
`checkStructFieldTypes` SKIPPED every generic struct outright ("its fields
reference `$T`, resolved at instantiation"), so the undeclared name was never
examined. The sibling `walkBodyTypes` `.struct_decl` arm skipped body-local
generic structs the same way.

Fix (semantic_diagnostics.zig, checker only — no leaf change):
- `checkStructFieldTypes`: stop skipping generic structs; walk the field
  types with the struct's OWN type params (`$T`, `$N`, `..$Ts`) passed as the
  in-scope set. A param name resolves; any OTHER bare name that is neither
  declared nor a generic param is reported. Value-param positions (a `Vector`
  lane count, a `$N: u32` arg) are still skipped inside
  `checkTypeNodeForUnknown` / `isValueParamPosition`.
- `walkBodyTypes` `.struct_decl`: same close for body-local structs — the
  local struct's own type params join the enclosing scope's in-scope params
  (so it can name both the outer fn's `$T` and its own), any other bare field
  type is still flagged.

The `..$Ts` pack field `(..$Ts)` parses to a `spread_expr` inside the tuple,
which hits `checkTypeNodeForUnknown`'s `else` arm — never walked — so the pack
examples (0538-0543, 0414) stay green. The checker walks only MAIN-file decls,
so library generic structs (List, Map) are untouched.

Regression: examples/0171-types-undeclared-type-in-generic-struct-field — the
reviewer's exact shape; `unknown type 'MissingType'` at the field, exit 1.
Fail-before on 4072689 (prints 7, exit 0), pass-after.

Gate: zig build; zig build test (423/423 + LSP corpus sweep 514); run_examples
498 passed / 0 failed (prior 497 byte-identical); m3te ios-sim build exit 0.
2026-06-08 08:36:45 +03:00
agra
4072689afe fix(lower): genuinely-undeclared type → diagnostic + .unresolved (no silent stub) [stdlib E3]
Phase E3: remove the silent empty-struct fall-throughs in type resolution for
genuinely-undeclared names, replacing them with a real "unknown type" diagnostic
+ the dedicated `.unresolved` sentinel (already present, with the sizeOf @panic
tripwire) — the REJECTED-PATTERN this project bans.

Split `TypeHeadResolution.undeclared` into `.forward` (a real author not interned
yet — self/forward/mutual/foreign reference, adopted on registration via
internNamedTypeDecl) vs `.undeclared` (NO author anywhere). `resolveNominalLeaf`:
- `.pending` / `.forward` keep the empty-struct stub the type adopts on register.
- `.undeclared` in a NON-main (imported/library) module — which the
  UnknownTypeChecker trusts and never walks — emits "unknown type 'X'" + poisons
  with `.unresolved`. In the MAIN file the checker owns the diagnostic (and a
  valid unbound generic leaf legitimately lands here), so the leaf keeps the
  legacy stub and does not double-report.

Also convert the `parameterized_type_expr` constructor-head fallback
(resolveParameterizedWithBindings): an unresolvable base now emits + returns
`.unresolved` (mirroring the `.call`-node sibling) instead of a 0-field stub
that mis-sizes `b.field` / `b.len`. Threads the reference span through both
callers.

Triage of the other empty-struct sites (all load-bearing on the green suite or
unable to distinguish forward from undeclared — KEPT): resolveNamed's legacy
namer (forward/generic/Self/foreign-opaque: R/Self/Object/Array), the
foreign-class struct + JNI Self placeholders, the shadow-slot reservation, the
type_bridge stateless pack/generic namer, and the struct-literal inference
fallback (front-run by the leaf; 0 suite hits).

Regression: examples/0759-modules-undeclared-type-in-import — an undeclared type
in an imported module now errors (exit 1) instead of silently compiling (the
pre-fix code printed `thing.x = 42`, exit 0).

Gate: zig build; zig build test (423/423 + LSP corpus sweep); run_examples 497
passed / 0 failed (prior 496 byte-identical); m3te ios-sim build exit 0.
2026-06-08 08:10:42 +03:00
agra
27acfb8229 Merge branch 'flow/stdlib/E2' into wt-stdlib-base 2026-06-08 07:38:40 +03:00
agra
f8efa25416 revert(stdlib): narrow E2 to the 0105 type/alias close; defer value consts to E5 [stdlib E2 attempt-6]
Scope-narrowing revert of the value-const same-name sub-area (attempts 3-5),
per PO/Agra ruling. The 0105 type/alias close (per-source nominal struct
identity, source-keyed type aliases, F1 self/mutual refs, anon-struct
regression) is kept intact; cross-module same-name VALUE consts move to step E5.

- imports.zig: narrow `isPerSourceDecl` so a `const_decl` is retained
  per-source ONLY when its RHS introduces a TYPE (alias / inline type decl).
  VALUE consts (literal / value-expression RHS) and functions keep the pre-E2
  first-wins name-merge. Restores value-const reads to exactly the
  wt-stdlib-base (pre-E2) first-wins behavior.
- lower.zig / program_index.zig: restored to the pre-value-const state
  (66d10c0) — removes selectModuleConst / SourceConstCtx / pinConstAuthorSource
  / SelectedConst and the rewired comptimeIntNamed / float / runtime /
  global-init const reads; value-const reads return to the global path.
- examples: drop 0759-0762 (value-const own-wins / ambiguous / expr-chain-dim
  / leaf-author-pin) — they move to E5.

Kept green: 0752-0758 (same-name structs distinct + own-wins + ambiguous + self
/mutual ref), 0756 (alias per-source), 0170 (anon-struct field distinct).

Gate: zig build + zig build test (423/423, LSP sweep 513 no-crash) +
run_examples (496/0, prior markers byte-identical) + m3te ios-sim build exit 0.
2026-06-08 07:28:31 +03:00
agra
4666fb1941 fix(lower): pin nested-leaf source to the SELECTED const's author — close F1 R1 [stdlib E2 attempt-5]
A same-name expression const read from another module folded its nested
leaves (`M` inside `K :: M + 1`) from the CALLER's source, not the source
that authored the selected const. A unique imported `K` became ambiguous
when the reading module also flat-imported a different same-name `M`.

`selectModuleConst` now returns the author SOURCE alongside the const info
(`SelectedConst`), and the fold/lower of a selected const's RHS pins
`current_source_file` to that author for the duration (`pinConstAuthorSource`)
— so `K :: M + 1` defined in `a.sx` always folds `M` against `a.sx`,
coherently whether `K` is read as a runtime value or used as an array
dimension. Each recursion level pins to its own selected author's source.

Single-author programs pin to the source they were already in → byte-
identical (499 prior examples unchanged). Genuine ambiguity at the read
site (0760) is still caught before any pin.

Regression: examples/0762-modules-same-name-const-leaf-author-pin
(`a.sx M::1; K::M+1`, `b.sx M::10`, main flat-imports both, reads K as
value AND `[K]u8` dimension → val=2 len=2). Fail-before on 8518b66
(`'M' is ambiguous` / "array dimension must be a compile-time integer
constant"), pass-after.
2026-06-08 07:02:59 +03:00
agra
8518b66cec fix(lower): propagate source-aware const selection into expression-chain folds — close F2 R1 [stdlib E2 attempt-4]
attempt-3 made the value-const READ source-aware (own-wins / ambiguous) but
the dimension/count fold of a SELECTED const's RHS still recursed through the
global last-wins `module_const_map`, so a nested same-name leaf came from the
wrong module. Reviewer R1: a.sx `M::1; K::M+1`, b.sx `M::10; K::M+1`, with both
`[K]u8` (a_len) and `return K` (a_val) — pre-fix `a_len=11 a_val=2`, an
INCOHERENCE for the same const `K` (a_val read A's chain; a_len read B's `M`).

`comptimeIntNamed` delegated to `moduleConstIntWith(global_map, ...)`, whose
leaf ctx (`ModuleConstCtx`) resolved nested names through the global map. The
value path (`emitModuleConst` -> `foldCountI64(ci.value, self)`) folds through
`self`, so its leaves bounce back to the source-aware `comptimeIntNamed` — which
is why a_val was already correct.

- New `SourceConstCtx` (lower.zig): the leaf-resolution twin of `ModuleConstCtx`,
  but every nested const leaf re-selects its OWN source author via
  `selectModuleConst` (own-wins / ambiguous), never the global last-wins map.
  `ConstFoldFrame` cycle-guards a const whose RHS references another const.
- `comptimeIntNamed` / `lookupFloatName` / `nameIsFloatTyped` now fold the
  selected `ci`'s RHS through `SourceConstCtx` (via `foldSourceConstInt` /
  `foldSourceConstFloat` / `sourceConstIsFloatTyped`). This makes the dimension
  and value reads of a shadowed expression-chain const coherent.
- Drop the now-unused `moduleConst{Int,Float,IsFloatTyped}With` wrappers from
  program_index.zig; expose `isCountableConstType` / `isFloatConstType`.

Single-author -> byte-identical (the selected `ci` IS the global one and every
nested leaf has one author). The stateless `type_bridge` registration-time const
reader still folds leaves through the global map, but realistic dim sites (struct
fields, array aliases — probed) resolve via the stateful path and stay coherent
under import-order swaps; no reachable wrong-dimension found (tracked follow-up,
byte-identical single-author).

Regression: examples/0761-modules-same-name-const-expr-chain-dim — a_len=2
a_val=2, b_len=11 b_val=11. Fail-before on 72f06a1 (`a_len=11`), pass-after.

Gate: zig build + zig build test (423/423, LSP sweep 515 clean) + run_examples
(499/0, 498 prior byte-identical + 0761) + m3te ios-sim build exit 0.
2026-06-08 01:06:44 +03:00
agra
72f06a109b fix(lower): source-aware value-const resolution (own-wins / ambiguous) — close F2 [stdlib E2 attempt-3]
E2 retained per-source const declarations but left the const READ path on the
global last-wins `module_const_map`, so a module's OWN reference to a same-name
const bound the LAST global author (F2: a.sx `K::1`, b.sx `K::2`, main flat-imports
both → both read B's K). Complete the const analog of the type (`selectNominalLeaf`)
and callable (`selectPlainCallableAuthor`) source-aware models.

- `selectModuleConst`: own-wins; exactly one flat-visible author → it; ≥2 distinct
  flat-visible → `.ambiguous` (loud diagnostic, consistent with 0755/0724); none
  → `.none`. Reads the SELECTED author's per-source value (`module_consts_by_source`)
  and folds its RHS over the global leaf map, so a const-EXPRESSION chain
  (`N :: M + 1`, M flat-imported) still resolves M.
- Rewire `comptimeIntNamed` / `lookupFloatName` / `nameIsFloatTyped`, the runtime
  identifier path, and the global-init-from-const path through it; drop the now
  subsumed `moduleConstBareInvisible` gate.
- program_index: `moduleConst{Int,Float,IsFloatTyped}With` fold a selected `ci`.

Examples: 0759 (own-wins value const, a=1 b=2) + 0760 (two-flat-visible →
ambiguous). Single-author byte-identical (run_examples 498/0, 496 prior unchanged;
zig build test 423/423; corpus sweep 515 no-crash; m3te ios-sim exit 0).
2026-06-08 00:32:07 +03:00
agra
66d10c00bb fix(lower): reserve genuine same-name struct shadows before fields — close F1 [stdlib E2 attempt-2]
A self / forward / mutual reference inside a same-name struct shadow bound to
the FIRST same-name author (another module's struct) instead of its own nominal
TypeId: registerStructDecl resolved a shadow's field types BEFORE registering its
decl key in type_decl_tids, so namedRefTid fell through to the name-only
findByName first-author fallback (F1).

Fix: a genuine same-name struct shadow (≥2 DISTINCT struct decls author the name
in the scanned decl set) reserves ALL its authors' distinct nominal slots up-front
in scanDecls — the first at id 0, the rest at fresh nonzero ids — BEFORE any field
resolves. Every self / forward / mutual ref to the shadow name then resolves via
type_decl_tids to its OWN nominal TypeId.

Gating on the scanned decls, not nameHasMultipleTypeAuthors (the raw import facts
over-count a single file reached via two un-normalized import spellings, e.g.
math/matrix44), keeps single-real-decl names on the legacy id-0 post-field path —
byte-identical (494 prior markers unchanged, single-author old==new).

internNamedTypeDecl now takes the precomputed nominal_id; no-drift + single
graph-walk invariants untouched; generics / enum / union / error-set stay legacy.

Regressions: 0757 (self-ref *Box → reads B's own field), 0758 (forward + mutual
*Node/*Box between two shadows). Fail-before on d98ad5c
("field 'y'/'m' not found"), pass-after.
2026-06-07 23:51:46 +03:00
agra
d98ad5c14f feat(stdlib): per-decl nominal identity + same-name shadows — close 0105 [stdlib E2]
Make same-name top-level types in different sources DISTINCT nominal types
instead of collapsing last-wins in the type table (issue 0105).

Registration:
- internNamedTypeDecl assigns a per-decl nominal_id and populates
  type_decl_tids. The first author of a name keeps nominal_id 0 (byte-identical
  to pre-E2); a genuine cross-module shadow (>=2 distinct normalized-path
  authors per the import facts) gets a fresh id -> a distinct TypeId.
- mergeFlat/addOwnDecl stop first-wins-dropping per-source decls (named types +
  non-fn const_decls) so every same-name author reaches registration; functions
  and var_decls (incl. #foreign extern globals) keep first-wins.

Resolution (selectNominalLeaf):
- own-author wins; else flatTypeAuthorCount over the transitive flat closure:
  >=2 distinct -> .ambiguous (loud diagnostic + poison); exactly one -> resolved;
  a flat author not yet findByName-registered -> .undeclared stub (not a leak).
- struct-literal type names route through the same source-aware leaf.
- lazyLowerFunction pins the function's own source before resolving its return
  type, so a shadowed signature type resolves in its module, not the caller's.

Codegen:
- mangleTypeName appends __n<id> for nonzero nominal_id so same-name shadows get
  distinct monomorph symbols (struct_to_string__Box vs __Box__n1).

Library hygiene:
- rename trace.sx's compiler-contracted Frame -> TraceFrame (+ the two compiler
  findByName sites) so it never collides with a UI/geometry Frame; the layout is
  structural (getFrameStructType / SxFrame), name-independent.

Examples: 0752-0756 pin the five 0105 cases (distinct fields / same fields /
own-wins / ambiguous / alias per-source); 0170 pins the folded anon-struct-field
regression.
2026-06-07 22:57:28 +03:00
agra
4b2a067991 wip(E2): partial nominal-identity/shadow work [stdlib E2 attempt-1 WIP checkpoint]
Incomplete WIP from a worker killed at the 30-min wall; committed as a
checkpoint so the resumed session continues on a clean tree. May not build.
2026-06-07 22:17:07 +03:00
agra
a8c7404a2f Merge branch 'flow/stdlib/E1.5' into wt-stdlib-base 2026-06-07 21:24:33 +03:00
agra
d2eb4c2af4 fix(lower): source-aware initial scan registration for identifier-RHS aliases [stdlib E1.5 attempt-2]
E1.5 attempt-1 made the forward-alias FIXPOINT source-aware but left the
EARLIER path — the `scanDecls` identifier-RHS alias branch — resolving the
RHS through the GLOBAL `type_alias_map` / global `findByName` (last-wins
across modules). When a namespaced import is scanned BEFORE a forward alias
`A :: B; B :: u64;`, dep's same-name `B :: u8` already sits in the global map,
so the early scan bound `A` to dep's `u8` and the per-source fixpoint guard
(`aliasResolvedInSource`) then skipped `A` — re-opening 0105 one layer down
(reviewer R1).

Cut the scan registration over to `selectNominalLeaf(rhs, src, is_raw)`,
resolving `B` AS SEEN FROM the alias's OWN source. Only the `.resolved`
outcome is written via the unified `putTypeAlias`; `.pending` / `.undeclared`
/ `.not_visible` leave `A` UNWRITTEN so the source-aware fixpoint re-tries it
once the local `B` registers. No raw `type_alias_map.put` / global `findByName`
selection reintroduced (E1 no-drift invariant). resolver.zig untouched
(single graph-walk invariant).

Also thread the backtick raw flag (`identifier.is_raw`) into BOTH the scan
registration and the fixpoint `selectNominalLeaf` calls, so a raw-RHS alias
(`` RawAlias :: `s2 ``) resolves to the nominal `` `s2 `` author, not the
builtin `s2` spelling (fixes 0154 under the new scan path; closes the same
latent hardcode in the fixpoint).

Regression: examples/0751-modules-forward-alias-ns-before — the reviewer's
exact ordering (ns import with `B :: u8` BEFORE `A :: B; B :: u64;`). Fails
on 2d34993 (`forward A` = 44, dep's u8) and passes after (= 300, local u64).
0750 + 0132/0133 + the full suite stay byte-identical (488/0).
2026-06-07 21:12:33 +03:00
agra
2d34993586 feat(lower): source-aware forward-alias fixpoint [stdlib E1.5]
resolveForwardIdentifierAliases now resolves a forward alias A :: B against
B AS SEEN FROM A's own source via selectNominalLeaf (E1's source-keyed
nominal leaf over type_aliases_by_source / moduleTypeAuthor), never the
global type_alias_map / global findByName. The already-resolved guard is
per-source (aliasResolvedInSource). .pending routes back into the fixpoint;
.undeclared / .not_visible leave A unwritten (no global last-wins leak).

This is the sequencing pin before E2: a global fixpoint binds A to a
same-name B authored by a different module (e.g. a namespaced import that
pollutes the global alias map last-wins), re-opening 0105 one layer down
once shadows register. Writes stay on the unified putTypeAlias helper (E1
no-drift invariant); the single graph-walk in resolver.zig is untouched.

Regression: examples/0750-modules-forward-alias-source-aware — a forward
alias A :: B with main's own B :: u64 and a namespaced same-name B :: u8;
A must bind main's u64 (300), not the global last-wins u8 (44).
2026-06-07 20:43:01 +03:00
agra
4a10c9a291 Merge branch 'flow/stdlib/E1' into wt-stdlib-base 2026-06-07 19:42:07 +03:00
agra
78ef2ea3d8 fix(lower): single unified writer for the three decl-fact maps; close param-alias leak [stdlib E1 attempt-5]
Route EVERY write of type_alias_map / module_const_map / global_names (and
their *_by_source analogues) through one helper per map
(putTypeAlias/putModuleConst/putGlobal/dropModuleConst). The global put and the
by-source put are now inseparable, so no write-site can mirror one side and
miss the other — the dual-write drift that leaked ns-only aliases past the
source-aware bare-TYPE gate. Grep-clean: no raw .put/.remove to the three maps
outside the helpers (mirrors the no-raw-TypeTable.update discipline).

The generic-struct instantiation alias sites (Secret :: Box(s32), both the
.call and .parameterized_type_expr branches) previously registered only a named
struct in the TypeTable and never reached type_aliases_by_source, so
moduleTypeAuthor missed them and a bare ns-only use leaked (exit 42, no
diagnostic). Routing those writes through the unified putTypeAlias lands the
alias in the per-source cache and the leak closes BY CONSTRUCTION — a flat use
still resolves to the same TypeId findByName would, a ns-only use is rejected.

Regression 0749 (ns-only Secret :: Box(s32) bare -> "type 'Secret' is not
visible"): fail-before on daf4bbc exit 42 no diagnostic, pass-after exit 1.
Single-author resolution byte-identical (486 passed / 0 failed). resolver.zig
single graph-walk untouched; generic/param-protocol/Vector/type-fn stay legacy.
2026-06-07 19:31:13 +03:00
agra
daf4bbc862 fix(resolver): treat type aliases as bare-TYPE authors in both gate directions [stdlib E1 attempt-4]
R4: a type alias is a `const_decl`, not a named-type decl, so the bare-TYPE
visibility gate ignored aliases — a namespaced-only alias leaked bare (silent
empty-struct stub, no diagnostic) and a flat-visible alias was poisoned by an
invisible same-name named type. Unify both type-author kinds (named type AND
alias) behind one per-module predicate `moduleTypeAuthor`, returning the author
KIND so resolution is decoupled from `findByName` timing (a forward/self
reference like `next: *ArenaChunk`, unregistered mid-registration, is still
recognised as an author and falls to the legacy stub instead of a false
"not visible"). The leak detector `nameAuthoredAsTypeAnywhere` now also scans
`type_aliases_by_source`. Single source of truth across named types, top-level
aliases, and parameterized/type-fn aliases — leak side and false-rejection side.

Behavior-preserving for single-author names (full suite byte-identical, paths
normalized). Generic / parameterized-protocol / Vector / type-function heads
stay legacy (0210). Block-local `Name :: <type>` remains a value const under the
reserved-name duality (pre-existing; the gate handles it safely, no leak).

Regressions: 0747 (ns-only alias bare -> not visible), 0748 (flat-visible alias
not poisoned by ns-only same-name struct). Both fail-before on 4bd57c8 /
pass-after here.
2026-06-07 18:41:01 +03:00
agra
4bd57c857e fix(resolver): type-author-aware + local-safe bare-TYPE gate; R3 model escalated [stdlib E1 attempt-3]
R1 (type-author-aware gate): the bare-TYPE visibility gate now requires a
flat-import-reachable TYPE author (struct/enum/union/error-set/protocol/foreign
class). A same-name flat VALUE/FUNCTION no longer makes a namespaced-only TYPE
bare-visible — the name-only `m.names.contains` check (attempt-2) is replaced by
`moduleAuthorsType` (kind-checked via `RawDeclRef`). Regression 0745.

R2 (no local false-positive): a block-local type clobbers the global type-table
entry for its name (`registerStructDecl`'s findByName-orelse-intern +
updatePreservingKey), so it IS the resolved type — never a namespaced-only leak.
A new `local_type_names` set, populated at both block-local type-decl paths,
exempts such names from the gate. Regression 0746.

readme.md: drop the false "transitively" claim — flat-import bare visibility for
functions and constants is NON-transitive (0706).

R3 (foundational model consistency) is ESCALATED, not resolved here — see the
attempt-3 worker report. Ground truth: making the TYPE gate single-hop (to match
the value/function model) breaks ~19 tests, ~13 of them library-INTERNAL generic
refs (e.g. `List.append`'s `alloc: Allocator`, lowered in the caller's source
context). That needs source-pinning generic instantiation to the template's
defining module — a separate architectural piece beyond E1's leaf-cut scope, and
proven risky (a `monomorphizeFunction` pin broke 4 FFI objc-block tests and did
not even take, since template method bodies lack a reliable `source_file`). The
TYPE gate therefore stays on the (type-author-aware) transitive flat closure for
E1; the non-transitive reconciliation is a routed follow-up.
2026-06-07 17:51:09 +03:00
agra
7188481761 feat(resolver): complete source-aware nominal-TYPE leaf — bare ns-only types not visible [stdlib E1 attempt-2]
Completes the F1 deliverable the reviewer flagged: the bare TYPE leaf still
returned the global `findByName` match BEFORE any visibility check, so a type
declared only behind a namespaced import leaked bare. Now the registered-type
branch of `selectNominalLeaf` is gated on bare-flat visibility (the type analog
of Phase B's value/function tightening): a bare reference to a namespaced-only
import's TYPE errors ("type 'X' is not visible; #import the module that declares
it") and poisons to `.unresolved` — never the leaked global match, never a
silent empty-struct stub.

Visibility gate is the TRANSITIVE flat-import closure (`typeBareVisible`), not
the single-hop `collectVisibleAuthors`/`isNameVisible`: a flat import is
transitive for resolution, so a type two flat hops away (`CAllocator`, via
`main → std.sx → allocators.sx`) stays bare-visible while a namespaced-only type
(reached solely over a namespace edge) does not. The gate applies ONLY to a
TOP-LEVEL author (`module_decls`) — a LOCAL type / generic-param / fabricated
empty-struct stub is findByName-registered but authored in no module, so it
resolves ungated and byte-identically (its own diagnostics still fire). The
compiler-synthesized default-Context emission falls open (`CAllocator` is
infrastructure, independent of the program's import style). The closure walk
lives in lower.zig, so resolver.zig keeps its single graph-walk.

A namespaced callee's declared return type now resolves in the callee's own
module context (`resolveTypeInSource` over `qualified_fn_source`) — a `Value`
returned by `json.parse` is visible inside `json.sx`, not at the call site
(issue-0100-F1 source-pin analog).

Migrates 0719 (flat-imports `cli` for its types, keeps `cli` namespaced for the
same-name `cli.parse`). Adds 0743 (bare ns-only struct → not visible) and 0744
(bare ns-only enum → not visible) regressions. 0742 (ns-only const) + 0210
(generics stay legacy) unchanged. readme updated.

Gate: zig build / zig build test (LSP sweep, no crash) / run_examples 481/0;
m3te ios-sim exit 0; 0743/0744 fail-before on 7cd12b0 (compiled, no diagnostic)
/ pass-after (clean "not visible").
2026-06-07 16:49:15 +03:00
agra
7cd12b0ed5 feat(resolver): source-aware nominal leaf (Lowering-side) + ns-const tightening [stdlib E1]
Route the Lowering-side bare type leaf through the source-keyed caches (E0):
nominal author via collectVisibleAuthors(.user_bare_flat) + alias via
type_aliases_by_source, instead of the global findByName first-match. The
binding-free resolveAstType path + registration sites stay on the global
compat readers (move later). Single-author resolution byte-identical (no
shadows yet). Folded req #1: a namespaced-only import's const is no longer
bare-visible in array-dim/comptime-scalar position. Adds regression 0742
(ns-only bare const) and 0210 (generics/Vector/type-fn stay legacy).

Salvaged from a worker killed at the wall before commit; manager verified
the gate at ground truth (zig build test exit 0; run_examples 479/0 with
0210+0742 ok, prior 477 byte-identical; m3te ios-sim exit 0; folded fix
confirmed fail-before on master 7ffc0c1 exit 0 / pass-after exit 1).
2026-06-07 15:24:43 +03:00
agra
a5d6c940dd Merge branch 'flow/stdlib/E0' into wt-stdlib-base 2026-06-07 14:30:15 +03:00
agra
662142c388 feat(resolver): source-keyed alias/const/global caches, write-side only [stdlib E0]
Phase E0 of the unified resolver (R5 §#4): add the source-partitioned
analogues of the global `type_alias_map` / `module_const_map` /
`global_names`, keyed `source path -> name -> X`, and POPULATE them from
the existing scan. Purely additive and behavior-preserving — the global
maps remain the ONLY readers; the read-side cutover to
`selectedAuthor.source` is E1.

ProgramIndex:
- type_aliases_by_source / module_consts_by_source / globals_by_source
  (StringHashMap of inner StringHashMap), owned + freed on deinit.
- put{TypeAlias,ModuleConst,Global}BySource + removeModuleConstBySource
  helpers; retain `module.alloc` to lazily create inner per-source maps.

lower.zig scan: every global `type_alias_map`/`module_const_map`/
`global_names` write (and each module_const_map.remove) now mirrors into
its by-source analogue, keyed by the registering decl's source
(decl.source_file / current_source_file), the analogue of module_fns.

Tests:
- program_index.test.zig: same alias/const/global name under two sources
  lands two distinct entries (not last-wins); compat globals stay
  single-keyed; removeModuleConstBySource scoped to its source.
- lower.test.zig: end-to-end two-source namespace fixture — the scan
  populates the by-source caches per declaring source while the global
  maps stay single-keyed by name.

Gate: zig build + zig build test (423, incl. 2 new) + run_examples
(477, byte-identical) + m3te ios-sim build, all exit 0.
2026-06-07 14:17:08 +03:00
agra
c839c60233 Merge branch 'flow/stdlib/D' into wt-stdlib-base 2026-06-07 13:39:29 +03:00
agra
09666cb90e feat(types): nominal identity + key-safe TypeTable mutation, ban raw update [stdlib D]
Phase D of the unified resolver: make the TypeTable safe to key by nominal
identity before same-name type shadows land (Phase E). Behavior-preserving —
nominal_id=0 means structural (today's keying, byte-identical); single-author
names intern to the same TypeId as before.

types.zig:
- StructInfo/EnumInfo/UnionInfo/TaggedUnionInfo/ErrorSetInfo gain
  `nominal_id: u32 = 0`. hash/eql fold it into the nominal arms ONLY, and only
  when nonzero, so legacy (structural) interning hashes/compares byte-identically.
- internNominal(info, nominal_id): stamps the id into the nominal arm then
  interns; nonzero id on a non-nominal info trips an assert.
- updatePreservingKey(id, info): field-fill that asserts the intern key is
  unchanged (replaces the forward-decl stub→full pattern).
- replaceKeyedInfo(id, info): the one legitimate re-key (anon rename
  __anon → Parent.field); removes the stale key and installs the new one.
- findUniqueByName: quarantined findByName that asserts ≤1 match.
- type_decl_tids: decl-node → TypeId identity map (the fn_decl_fids analogue),
  consumed by the resolver in Phase E.

Ban raw TypeTable.update outside types.zig (the acceptance bar): every caller
in lower.zig / type_bridge.zig / protocols.zig is reclassified — forward-decl
field fills route through updatePreservingKey, qualifyAnonType's rename through
replaceKeyedInfo. The raw `update` method is removed. Inline named type-decl
registration ("current winners") routes through internNominal(info, 0).

Tests (types.test.zig): forward-decl field fill (stable key), anon rename
(re-key), generic struct instantiation, type-returning function, parameterized
protocol value struct, same display-name → distinct nominal ids, plus an
old==new assertion (internNominal(.,0) byte-identical to legacy intern),
findUniqueByName, and the type_decl_tids identity map.

Gate: zig build (0), zig build test (421/421), run_examples (477, byte-identical),
m3te ios-sim build via worktree binary (0). No shadows registered; stubs intact.
2026-06-07 13:27:10 +03:00
agra
7ffc0c112f Merge branch 'wt-stdlib-base' 2026-06-07 12:57:52 +03:00
agra
e4d58b2abb Merge branch 'flow/stdlib/C' into wt-stdlib-base 2026-06-07 12:55:05 +03:00
agra
82fc71ccbe fix(lower): route early pack/comptime dispatch through SelectedFunc [stdlib C attempt-3]
lowerCall's early pack/comptime/generic dispatch keyed off the first-wins
winner (`fn_ast_map.get(early_name)`) BEFORE the main dispatch consumes the
selected same-name author. Under a genuine flat same-name collision where the
caller's own author is a plain free fn but the first-wins winner is a comptime
pack `(..$args)` (or comptime-param / generic), the early path invoked the
WINNER — so `CallResolver.plan` (which selects the own plain author) and
lowering disagreed about which function a bare call names.

Confirms reviewer finding C-review-1. The earlier manager ground-truth got
`show_b=2` because it used a slice variadic `(..xs: []s64)` — NOT a pack fn
(`isPackParam` false), so it never hit the early dispatch. The reviewer used a
comptime pack `(..$args)` (`isPackFn` true), which does. Both observations are
correct for their respective shapes; the bug is real for the comptime-pack
winner.

Fix: the early dispatch reads the SAME author the selector chose
(`sel_author.decl`) when a collision rerouted the call, else the winner
(common path, byte-identical). The selector only ever returns a plain free fn
(`isPlainFreeFn` excludes type-params / comptime / pack), so a selected author
falls through to the main dispatch that binds it via `SelectedFunc`.

Regression: examples/0741-modules-flat-same-name-bare-pack-winner — a.sx
(imported first) authors `f` as a comptime pack (first-wins winner); b.sx
authors its own plain `f`; b's bare `f()` must return 2 (own author), not 1
(the pack). Fails on 2dd6c3c (b: f() = 1), passes after.

Gate: zig build + zig build test (412/412) + run_examples (477/0) +
m3te ios-sim exit 0.
2026-06-07 12:40:00 +03:00
agra
2dd6c3c13b fix(resolver): share plan SelectedFunc across consumers + route UFCS through selector [stdlib C attempt-2]
Address Phase C review (C-1, C-2): make CallResolver.plan's SelectedFunc the
single shared call author consumed by the lower-call sites instead of each
re-resolving; route free-fn value-receiver UFCS through the selector in plan so
plan typing and lowering pick the same author under a flat same-name collision.
Adds regression 0740-modules-flat-same-name-ufcs-typing.

Salvaged from a worker killed at the wall during its final gate step; manager
verified the gate at ground truth (zig build test exit 0; run_examples 476/0 with
0722-0735 + 0740 ok; m3te ios-sim exit 0).
2026-06-07 12:05:12 +03:00
agra
9568f7689f feat(resolver): route plain bare-call author through Phase B collector via SelectedFunc [stdlib C]
Phase C of the unified resolver (R5 §C, §#3). Re-base the plain bare-name
call author onto the Phase B collector behind one shared SelectedFunc, so
every call-path consumer reads ONE author and they can no longer disagree
(fix-0102 F2). Behavior-preserving: 0722-0735 byte-identical, run_examples
stays at 475.

- SelectedFunc {decl, source, materialized?} replaces ResolvedAuthor in
  BareCallee.func; CallPlan.Target gains a `selected` arm (calls.zig).
- selectPlainCallableAuthor: resolveBareCallee's body verbatim over
  resolver.collectVisibleAuthors (.user_bare_flat) — the ONE graph-walk.
  fnDeclOfRaw mirrors imports.fnDeclOf so the collector's all-domain authors
  reproduce module_fns' fn-only view; every byte of the negative space is
  preserved (own==winner → .none; non-plain-free → .none; filter-before-count;
  ≥2 distinct → .ambiguous). No eager materialization.
- selectedFuncId materializes the FuncId on demand (shadow-only), caching into
  materialized — null until a site needs it (0102d: a shadow taken as a value
  never lowers the winner).
- Six consumers route through the one selector: lowerCall variadic packing,
  free-fn UFCS, fn-value, closure(fn), resolveCallParamTypes, and
  expandCallDefaults (decl-only, no materialization). plan() produces the
  SelectedFunc as `.selected`. Generic/comptime/foreign/builtin stay legacy.
- lower.test.zig: wire module_decls; selectPlainCallableAuthor verdicts
  (own-winner → .none; ≥2 flat → .ambiguous; own-shadow → decl+source, fid
  round-trips, materialized null).

Gate: zig build + zig build test (412 ok) + run_examples (475, byte-identical)
+ m3te ios-sim build exit 0.
2026-06-07 11:02:08 +03:00
agra
f2de1a9710 Merge branch 'flow/stdlib/B' into wt-stdlib-base 2026-06-07 10:27:42 +03:00
agra
fc112200c7 docs(readme): stop quoting per-kind ns-import diagnostics (mid-migration) [stdlib B attempt-8]
The namespaced-only bare-visibility behavior is non-uniform and partial during
the resolver migration: runtime const/fn use errors, comptime/array-dim const
positions still compile, const-aliases report 'unresolved', and bare types still
resolve. Rewrite the note to state the durable rule (a namespaced import binds
only its alias; reach members as m.name; bare-name visibility joins over flat
imports only) and that bare references to ns-only members are being phased out
and do not yet resolve uniformly across name kinds. No specific diagnostic
string, no completeness/uniformity claim. Doc-only; no code path touched.
2026-06-07 10:04:40 +03:00
agra
aa2b79683b docs(readme): scope ns-only bare-visibility claim to values/functions [stdlib B attempt-7]
Phase B tightened bare VALUE/FUNCTION visibility through a namespaced-only
import (isNameVisible/isCImportVisible -> 'not visible'). Bare TYPE names
from such an import still resolve today; type-name visibility tightens in a
later resolver phase. Correct the README so it no longer claims all bare
names from a namespaced import error.
2026-06-07 09:51:57 +03:00
agra
0369cb001f fix(lower): stamp caller source on variadic comptime pack args [stdlib B attempt-6]
lowerComptimeCall stamped the caller's source onto fixed comptime `$`-params
so their substituted bare names resolve in the caller's visibility context,
but the variadic comptime pack branch (`..$args`) recorded the pack-arg slice
without stamping. Those nodes are later re-lowered via packArgNodeAt under the
defining-module pin, so a caller-owned helper in a formatted-arg position
(`std.print("{}", caller_fn())`) was checked against the metaprogram's module
and rejected as "not visible". Stamp every pack-arg node with the caller source,
mirroring the fixed-param treatment — completing Problem 1 for pack args.

Regression: examples/0739-modules-comptime-pack-arg-caller-context.sx
(two caller-owned s64 helpers in std.print pack positions; fail-before both
"not visible", pass-after prints "42 7"). No exemption flag, no silent default.
2026-06-07 09:31:17 +03:00
agra
8875a28641 fix(lower): resolve substituted caller comptime $-args in caller context [stdlib B attempt-5]
attempt-3 pinned current_source_file to the metaprogram's defining module
across the whole body lowering (lowerComptimeCall / monomorphizePackFn). That
pin also covered caller-provided comptime $-arg nodes spliced into the body by
substituteComptimeNodes — but those are CALLER-authored and must resolve in the
caller's visibility context, not the callee's. Result: a caller-owned helper
passed to an imported metaprogram errored "'<name>' is not visible".

Fix: stamp each comptime $-arg node with the caller's source_file at the cpn
build site (stampCallerSource, in lowerComptimeCall + monomorphizePackFn);
lowerExpr switches current_source_file to a node's source_file when present, so
the substituted subtree resolves against the caller while the surrounding callee
code keeps the defining-module pin. No exemption / fall-open.

Regression: examples/0738-modules-comptime-arg-caller-context.sx — a caller-owned
helper passed as a comptime-ONLY $-arg through a namespaced import. Fail-before
(attempt-3 binary): "'caller_name' is not visible". Pass-after: prints
"hello world", exit 0. Comptime-only, so it does not exercise issue 0107.

0106 RESOLVED banner extended (point 3: body=defining context, substituted
$-args=caller context). run_examples 473 -> 474; zig build test 412/412.
2026-06-07 09:07:27 +03:00
agra
b62223edaf fix(lower): pin defining-module context for pack/comptime metaprograms; drop #insert exemption [stdlib B attempt-3]
ROOT FIX for issue 0106's library-metaprogram half — no exemption.

attempt-2 masked the 0106 fallout with an `in_insert_expansion` flag that
made the visibility adapters fall open during ANY `#insert` expansion,
including a USER's `#insert <expr>` — so a bare reach into a namespaced-only
import from user `#insert` code wrongly compiled (Adi's blocker). The flag
was the wrong shape. This removes it and fixes the real cause.

Root cause: a metaprogram's body (`std.print` / `std.format` / `log.*`,
whose `#insert build_format(fmt)` + `#insert "out(result);"` reference
std-internal bare names) was lowered under the CALL SITE's
`current_source_file`, so those names were policed against the consumer's
imports. Normal functions get this right via `lowerFunctionBodyInto`, which
pins `func.source_file`; the two monomorphizers don't:
  - `monomorphizePackFn`   — bare `print(...)` / `format(...)` (pack path).
  - `lowerComptimeCall`    — namespaced `std.print` / `log.warn` (reached via
                             the field-access `hasComptimeParams` branch).

Fix: both paths now save/set/restore `current_source_file` to the body's
DEFINING module around the BODY lowering only (call-site args stay in the
caller's context). The defining path is stamped onto each function body node
by `resolveImports` (`stampFnBodySource`), mirroring `Function.source_file`.
So library internals resolve in std.sx/log.sx naturally, while a USER's
`#insert <expr>` is still checked in the user's context.

- Exemption GONE: `in_insert_expansion` flag + both adapter fall-open checks
  deleted; `isNameVisible`/`isCImportVisible` are byte-identical adapters.
- New pinned regression: examples/0737-modules-insert-bare-not-visible.sx
  (+ a.sx) — a USER `#insert secret()` into a namespaced-only import errors
  ('secret' is not visible). fail-before exit 0 on the attempt-2 binary /
  pass-after exit 1.
- face #1 (0736) still errors; face #2 (0015/0700/0718/1030) pass again WITH
  NO exemption — the metaprogram body resolves in its own module.
- run_examples 472 -> 473; zig build test 412/412; m3te ios-sim build exit 0.
- issues/0106 RESOLVED banner updated (root cause + no-exemption fix).
2026-06-07 06:09:28 +03:00
agra
6f2bf84293 fix(lower): #insert-expansion visibility exemption + close 0106 [stdlib B attempt-2]
Folds the coupled 0106 fix into Phase B. attempt-1 tightened the bare-name
visibility adapters (isNameVisible/isCImportVisible) to the flat_import_graph
edge set via the unified isVisible(.user_bare_flat/.c_import_bare) predicate;
that surfaced issue 0106 — std.print / log.* expand `#insert build_format(fmt)`
(comptime call) and `#insert "out(result);"` (inserted stmt) in the CONSUMER's
current_source_file, so their library-internal bare names were policed against
the consumer's imports and errored (run_examples 471 -> 467).

Fix: a precise, named exemption. Lowering.in_insert_expansion is set across
lowerInsertExprValue (the comptime eval + the parsed-back statements); the two
visibility adapters fall open while it is set — mirroring the existing
UFCS-alias / mangled-local "compiler indirection" exemptions. NOT a blanket
skip: scoped to #insert-expanded code, ordinary bare references stay policed.
Library-internal call bodies (build_format's concat/substr) already resolve in
the defining module — lowerFunctionBodyInto pins their current_source_file.

The flat tightening stays: a bare reference to a namespaced-only import's
internal name now correctly errors ('<name>' is not visible). This is the
Agra-ratified user-visible semantics change.

- face #1 pinned: examples/0736-modules-namespaced-only-bare-not-visible.sx
  (+ a.sx) — exit 1 + stderr; fail-before (import_graph compiled it, exit 0) /
  pass-after (flat set errors, exit 1).
- face #2 restored: examples 0015 / 0700 / 0718 / 1030 pass again.
- run_examples 471 -> 472 (the new regression).
- issues/0106 marked RESOLVED; readme.md documents namespaced-only visibility.

Collectors + unified predicate from attempt-1 (resolver.zig) unchanged; nothing
routes resolution AUTHOR-SELECTION through them yet (that is Phase C).
2026-06-07 05:17:23 +03:00
agra
7158337c73 wip(resolver): collectors + unified predicate + tightened adapters [stdlib B, BLOCKED on 0106]
Collectors (resolver.zig: collectVisibleAuthors/collectNamespaceAuthors + AuthorSet
+ VisibilityMode, 4 unit tests) + unified visibility predicate + isNameVisible/
isCImportVisible adapters routed to flat modes. Tightening surfaces issue 0106
(stdlib comptime expansion relies on the over-permissive import_graph join), so
run_examples is 467/471 here. attempt-2 folds in the coupled comptime-context fix.
2026-06-07 04:52:56 +03:00
agra
35457cb614 Merge branch 'flow/stdlib/A' into wt-stdlib-base 2026-06-07 00:06:52 +03:00
agra
5f06b6504f fix(imports): diagnose namespace-alias dup + propagate buildImportFacts errors [stdlib A attempt-2]
Two defects from the Phase A attempt-1 review.

F1 — duplicate-name diagnostic missed NAMESPACE ALIASES (silent first-win).
`addNamespace` unconditionally put the alias into scope/own_decls, so a
same-module collision between an authored decl and a `dup :: #import "…"`
alias compiled clean in the fn-then-alias order (the scalar
ModuleRawDeclIndex silently first-won). Now `addNamespace` returns a bool
and refuses a same-module duplicate (mirroring addOwnDecl); the call site
surfaces it via the new `reportDuplicateName` (the import_decl node has no
declName, so the alias name is passed explicitly). The C-import namespace
site gets the same guard. Both orders now emit "duplicate top-level
declaration 'X'" and exit nonzero (alias-then-fn was already caught by
addOwnDecl seeing the alias in scope).

F2 — buildImportFacts errors were swallowed by `else |_| {}` in core.zig
(REJECTED-PATTERN catch-all leaving the borrowed store silently empty).
`resolveImports` returns !void, so the call is now a plain `try` and a
build failure propagates instead of producing a stale/empty store.

Tests: extend the dup-name regression with fn-vs-namespace-alias
collisions in both orders. No resolution behavior change (no lower.zig
edits; run_examples 471 byte-identical); m3te ios-sim builds via the
worktree binary.
2026-06-06 23:54:51 +03:00
agra
b5ec121645 feat(imports): buildImportFacts raw-fact store (ModuleRawDeclIndex + NamespaceEdges) [stdlib A]
Phase A of the unified resolver (R5 locked design). Additive infrastructure
with NO behavior change — builds the import-side raw-fact store; nothing
consumes it yet.

- imports.zig: add RawDeclRef / RawAuthor / ModuleRawDeclIndex / ModuleDecls /
  NamespaceTarget / NamespaceEdges, plus buildImportFacts (mirrors
  buildModuleFns) producing a scalar per-module name→RawDeclRef index + the
  namespace edges. Callable without IR lowering (LSP reuses it later).
- ast.zig: NamespaceDecl gains target_module_path, captured at resolution time
  (the resolved_path otherwise lost on the node) so the namespace edge records
  the alias target.
- imports.zig: same-module duplicate top-level name is now DIAGNOSED
  ("duplicate top-level declaration 'X'") where addOwnDecl would silently drop
  the second author — replaces the discarded `_ =` at the three call sites.
- program_index.zig: borrowed views module_decls / namespace_edges (like
  module_fns); deinit does not free them.
- core.zig: build the facts alongside buildModuleFns and point the borrowed
  views at them.
- imports.test.zig: index unit tests (flat / directory / namespaced file /
  namespaced directory / C-import namespace / same-name fn / same-name struct /
  value-vs-type same spelling / raw const_decl) + the duplicate-name diagnostic
  regression (fails pre-fix, passes after).

Gate (worktree): zig build, zig build test (incl. LSP corpus sweep), and
run_examples (471, byte-identical) all green; m3te ios-sim build exits 0.
2026-06-06 23:34:32 +03:00
531 changed files with 9654 additions and 696 deletions

60
docs/fork-c/README.md Normal file
View File

@@ -0,0 +1,60 @@
# Fork C — setup contract (S0)
Zero-legacy name-resolution redesign (S0→S6), replacing E6cK. This directory is the
**committed S0 contract** the remaining 26 steps (S1→S6) execute against. It is pure
setup/documentation — **S0 introduces no production code change and no behavior
change**; single-author output is byte-identical to `wt-stdlib-base` by construction.
**Authority:** `runs/stdlib/design/fork-c-deepdive/reconciled.md` (§5 by-construction
audit, §6 staged roadmap + deletion lists, §8 fold-in) and
`runs/stdlib/design/fork-c-plan/planspec-r3.json` (the S0.1/S0.2/S0.3 intent +
acceptance, Adi-confirmed — they govern).
## Doc-area decision
Deliverables live under **`docs/fork-c/`**, NOT `current/fork-c/`. Reason: `current/`
is **gitignored** in this repo (`.gitignore``current/`), so a new `current/fork-c/`
tree would not be committed; the S0 contract must be committed. `docs/` is tracked.
## Baseline
- **Base:** `wt-stdlib-base @ 1f755284d98c6e8ebba953045c06e35d8cbe6278` (AE6a merged).
- **E6b:** `flow/stdlib/E6b @ af737b0` — PAUSED, **unmerged**, all transitional, destined
for S3/S6 deletion. Its semantics goldens are harvested; its src is never merged.
- **This branch:** `flow/stdlib/S0` (branched from the base). **Production/compiler
behavior is base-equivalent** — zero `src/` changes, single-author output
byte-identical to base by construction — but S0 HEAD is a distinct commit carrying
the docs/examples/tests diff (it does **not** equal base).
## Contents
| file | sub-step | what |
|---|---|---|
| `S0.1-byte-baseline-and-commit-discipline.md` | S0.1 | the byte-identity reference + the zero-diff reproduction command + resolver-target exclusion + the `mirror \| consumer-cutover \| deletion` commit-classification discipline |
| `S0.2-e6b-disposition-and-two-corpus-partition.md` | S0.2 | E6b src not merged (grep-clean) + the harvested corpus partitioned baseline-green vs resolver-target + 0811/0829 placement + the E6BR-5 re-file + the mirror/flip statement |
| `S0.3-reuse-delete-ledger.md` | S0.3 | every load-bearing AE6 artifact mapped REUSED (Fork C home) or DELETED/TRANSITIONAL (S3/S6 phase); E6c/d/e dropped, F/H/I/K absorbed/superseded |
| `../../tests/resolver-target/` | S0.2 | the listed resolver-target harness: `manifest.md` (18 cases), `expected/` TARGET goldens, the E6BR-5 reproducer under `cases/`, and `run_resolver_target.sh` (xfail runner — NOT part of the gate) |
## The two-corpus law (the one thing the next 26 steps must never conflate)
1. **BASELINE-GREEN / mirror-equivalence corpus** — tests where the old selector is
already correct today (AE6a merged + the 6 harvested baseline-green cases + FFI
12xx14xx + the LSP smoke). Stays **green and single-author byte-identical at every
step S0→S6**, and is the S2 assert-only Debug mirror's **only** oracle.
2. **RESOLVER-TARGET corpus** — harvested goldens that encode **known-wrong old
behavior** (silent resolve / under-diagnose / wrong author / own-wins-fails) + the
E6BR-5 regression. Held **inactive/xfail** (listed, never silently dropped) from S0
through S3.8, then **flips to active + green at S3.9** against its TARGET output —
never against the old selectors (a wrong oracle for it on the E6b-unmerged base).
## Gate (this branch)
```sh
export PATH="$HOME/.zvm/bin:$PATH"
zig build && zig build test && bash tests/run_examples.sh # exit 0 over the baseline-green corpus
```
Since S0 changes no production code, single-author output is byte-identical by
construction. The resolver-target xfail diagnostic
(`bash tests/resolver-target/run_resolver_target.sh`) is separate and not part of the
gate.

View File

@@ -0,0 +1,102 @@
# S0.1 — Byte-baseline (baseline-green only) + commit-classification discipline
Authority: `runs/stdlib/design/fork-c-plan/planspec-r3.json` (S0.1) +
`runs/stdlib/design/fork-c-deepdive/reconciled.md` (§6 green-lock). Base:
`wt-stdlib-base @ 1f755284d98c6e8ebba953045c06e35d8cbe6278` (AE6a merged). This is
documentation only — no production code change, no behavior change.
## 1. The byte-identity reference
The single-author byte-identity reference that **every later Fork C commit is checked
against** is the committed `examples/expected/*` snapshot set on the baseline commit
above. We do **not** copy every file into this doc; the snapshots ARE the reference,
and the reproduction is a documented zero-diff command (§2). Single-author byte
identity is held structurally by `nominal_id == 0 ≡ structural intern`
(`src/ir/types.zig` `internNominal`), which S1S2 keep additive and S3 preserves
through ordinal-0 materialization.
The baseline-green corpus that the reference covers:
| segment | what | how it is exercised | count @ S0 |
|---|---|---|---|
| baseline-green examples | every `examples/<name>.sx` with an active `examples/expected/<name>.exit` marker (incl. the 6 harvested baseline-green cases `07950798`, `0823`, `0828`) | `bash tests/run_examples.sh` | **540** active markers |
| FFI corpus | `examples/12xx14xx` (96 entry trees; 95 with active markers; ~418 files incl. module/`.c`/`.h`/`.m` companions) | same runner (markers) | 95 active markers |
| LSP completion/hover smoke | LSP unit tests under `zig build test``analyzeDocument` flat/namespaced import + the `lsp corpus sweep: every examples/*.sx analyzes without panicking` sweep + definition/references/inlayHint | `zig build test` | — |
> Count note: `reconciled.md §1` cites "116 files in `examples/12xx14xx`". The live
> tree has **96 entry `.sx` trees** (95 with active markers); the "116" is a stale
> historical figure. What is load-bearing is the invariant — *all FFI 12xx14xx
> examples stay byte-stable* — which `run_examples.sh` enforces via their markers,
> not the exact historical count.
## 2. The zero-diff reproduction method
`tests/run_examples.sh` runs `sx run <entry>` for every `<name>.sx` that has an
`expected/<name>.exit` marker, normalizes stdout/stderr identically for expected and
actual (address hashing → `0xADDR`; absolute `…/examples|issues/` paths → repo-relative),
and diffs exit + stdout + stderr (+ optional `.ir`). A **zero-diff** run is the
byte-identity check:
```sh
export PATH="$HOME/.zvm/bin:$PATH"
zig build # build the compiler under test
zig build test # unit tests incl. the LSP completion/hover smoke + corpus sweep
bash tests/run_examples.sh # must print "<N> passed, 0 failed, 0 skipped*, 0 timed out"
```
Any later commit whose single-author output drifts shows up as a `FAIL` with a printed
diff. `tests/run_examples.sh --update` regenerates the snapshots — it must **only** be
run intentionally when a commit's classification (§3) authorizes an output change, and
the diff reviewed. (* `skipped` counts `.exit` markers whose `.sx` is absent; it is 0
on a clean tree.)
## 3. Resolver-target EXCLUSION (recorded, not silently absent)
The **resolver-target set** is **excluded from both** the byte-baseline AND the active
`run_examples.sh` set, because it encodes known-wrong old behavior (silent resolve /
exit 0 / under-diagnosis / wrong author) — a stale old-selector verdict must never
enter the baseline as if it were correct. The exclusion is explicit and **listed**, not
absent:
- the 17 harvested `08xx` resolver-target cases (`0811, 0812, 0813, 0814, 0815, 0816,
0817, 0818, 0819, 0820, 0821, 0822, 0824, 0825, 0826, 0827, 0829`) + the re-filed
**E6BR-5** regression;
- enumerated in `tests/resolver-target/manifest.md`, with TARGET goldens in
`tests/resolver-target/expected/`, held inactive (no `examples/expected/` marker) and
asserted currently-failing by `tests/resolver-target/run_resolver_target.sh`;
- full disposition in `S0.2-e6b-disposition-and-two-corpus-partition.md`.
They flip to active + green at **S3.9** and only then join the baseline.
## 4. Commit-classification discipline
Every future Fork C migration commit (S1→S6) is tagged with exactly one of three
classes, stated in the commit subject/body so a reviewer knows what byte-effect to
expect:
| tag | meaning | expected byte-effect on the baseline-green corpus |
|---|---|---|
| **`mirror`** | builds new facts / a new resolver path **in parallel**, while lowering still consumes the old path (S1S2; the assert-only Debug mirror) | **zero** — single-author output byte-identical; provably zero byte-risk |
| **`consumer-cutover`** | switches a consumer from the old path to the resolved facts (S3 materializer / calls / consts / protocol-registration / `#using`; S5 LSP) | **zero on baseline-green** — byte-identical by ordinal-0 materialization + payload-preserving facts; the only commits that may change resolver-target (the S3.9 flip is a cutover) |
| **`deletion`** | removes a now-dead artifact (old name selectors, `*_by_source` mirrors, `type_bridge`, `findByName`, the grep gate, the S2 mirror) | **zero** — the deleted code had no live readers after its cutover; a surviving reader fails to compile |
Rules:
- A commit is exactly one class; a cutover that also deletes its now-dead source is
still a `consumer-cutover` if the delete is the same atomic cutover (e.g. S3.10
removes the last old selector **and** the S2 mirror in the cutover commit).
- `mirror` and `deletion` commits MUST be byte-zero on baseline-green; if a `mirror`
commit changes a byte, it was not actually parallel — stop.
- Only `consumer-cutover` may legitimately change output, and only the **resolver-target**
corpus (never baseline-green) — that is the S3.9 flip.
## 5. Acceptance (S0.1) — self-check
- ✅ Byte-baseline of all baseline-green examples + FFI 12xx14xx + LSP smoke captured
and reproducible via the documented zero-diff command (§1§2); the reference is the
committed `examples/expected/*` at the baseline commit, re-checked by a zero-`FAIL`
`run_examples.sh`.
- ✅ Resolver-target set explicitly excluded from the byte-baseline AND the active
`run_examples.sh` set, and recorded/listed (§3) — not silently absent.
- ✅ The `mirror | consumer-cutover | deletion` classification rule is written (§4).
- ✅ `zig build && zig build test && bash tests/run_examples.sh` green over the
baseline-green corpus; no behavior change (S0 adds no production code).

View File

@@ -0,0 +1,143 @@
# S0.2 — E6b disposition, the two-corpus partition, and the E6BR-5 re-file
Authority: `runs/stdlib/design/fork-c-plan/planspec-r3.json` (S0.2) +
`runs/stdlib/design/fork-c-deepdive/reconciled.md` (§3 one-resolver-two-timings, §6
roadmap, §8 fold-in). Base: `wt-stdlib-base @ 1f75528` (AE6a merged). E6b:
`flow/stdlib/E6b @ af737b0` (PAUSED, unmerged). This is documentation only — no
production code change.
## 1. E6b transitional src is NOT merged
The transitional E6b source on `flow/stdlib/E6b @ af737b0` is **not** brought onto the
Fork C baseline. All of it is destined for **S3/S6 deletion** under Fork C:
- the **route-all engine** + the type-reference **choke-point**
(`resolveRegistrationSigTypeInSource` / `sig_registration_mode`) — `lower.zig`,
`protocols.zig`;
- the executable **grep gate** `src/ir/e6br_gate.test.zig` (+ its `ir.zig` import);
- the supporting `calls` / `lower` / `protocols` / `type_bridge` / `type_resolver` /
`types` changes.
Grounded reasons it is transitional, not load-bearing: the whole-AST resolver walks
**every** reference position, so it closes the protocol/param-impl signature surface
the choke-point policed (reconciled §3/§4 T4); and the grep gate is unnecessary once
the leaf it polices no longer exists (reconciled §5). AE6a stays merged purely as
**proof-of-semantics + per-decl nominal infra** (`internNominal` / `nominal_id==0`
byte-identity rule / `RawDeclRef` facts → the `DeclId` seed) — see
`S0.3-reuse-delete-ledger.md`.
**Grep-clean (verified on this branch — `src/` is base-equivalent, zero src changes):**
| check | base / S0 | E6b |
|---|---|---|
| `resolveRegistrationSigTypeInSource` in `src/` | **absent** | present (`lower.zig`) |
| `sig_registration_mode` in `src/` | **absent** | present (`lower.zig`, `protocols.zig`) |
| `src/ir/e6br_gate.test.zig` | **absent** | present |
| `walkConcreteSigArgs` in `src/ir/lower.zig` | **absent** | present (the E6BR-5 site) |
Because S0 introduces **no production code change**, these remain absent on the Fork C
baseline by construction.
## 2. Harvested resolver-acceptance corpus + the two-corpus partition
Harvested by copying the example **trees + their expected goldens ONLY** (never the
transitional src):
- `examples/08110829` (19 trees) from `flow/stdlib/E6b @ af737b0` — error-set /
protocol / param-impl / route-all same-name ambiguity & own-wins surfaces;
- `examples/07950798` (already merged on the base) — the enum/union ambiguous/own-wins
pair.
The corpus is **partitioned by empirically running each harvested case through the
current base compiler and comparing its output to the E6b TARGET golden** (the exact
method: build, then `sx run examples/<name>.sx`, normalize with the
`run_examples.sh` rules, diff against the E6b golden):
### (a) BASELINE-GREEN — the mirror-equivalence corpus
Harvested cases whose **old selector is already CORRECT on `wt-stdlib-base` today**
(actual == E6b target, byte-for-byte). They get standard
`examples/expected/<name>.{exit,stdout,stderr}` markers, are run by
`tests/run_examples.sh`, and are **locked into the S0 baseline**. This set is the S2
assert-only Debug mirror's **ONLY** oracle.
| case | exit | proof it is already-correct on base |
|---|---|---|
| `0795-modules-same-name-enum-ambiguous` | 1 | already merged + green (E6a) |
| `0796-modules-same-name-enum-own-wins` | 0 | already merged + green |
| `0797-modules-same-name-union-ambiguous` | 1 | already merged + green |
| `0798-modules-same-name-union-own-wins` | 0 | already merged + green |
| `0823-route-all-own-wins-subform-wrappers` | 0 | base output == E6b target (`opt=1 arr=2 sl=3 dep=99`) |
| `0828-protocols-param-impl-arg-wrapped-own-wins` | 0 | base output == E6b target (`tag=7 dep=9`) |
### (b) RESOLVER-TARGET — known-wrong old behavior
Harvested cases (and the re-filed E6BR-5) where the **old selector is wrong on the
E6b-unmerged base** (silently resolves last-wins / under-diagnoses / picks the wrong
author / fails own-author resolution). They are held in a **documented, listed,
separate harness** at `tests/resolver-target/` with **NO active `examples/expected/`
marker** (so `run_examples.sh` does not run them), but **WITH** their TARGET output
recorded and an **enumerated manifest** (`tests/resolver-target/manifest.md`, 18
cases). The sibling xfail runner `run_resolver_target.sh` runs each and asserts it
currently FAILS — so the set is **never silently dropped**. It flips to active + green
at **S3.9**.
The 17 harvested `08xx` resolver-target cases: `0811, 0812, 0813, 0814, 0815, 0816,
0817, 0818, 0819, 0820, 0821, 0822, 0824, 0825, 0826, 0827, 0829`. Per-case class,
base-now behavior, and target are in the manifest.
**0811 and 0829 placement (required one-liners):**
- **0811 → resolver-target.** *Old selector is wrong here on the E6b-unmerged base:*
the five bare error-set forms (`size_of` / annotation / type-as-value / match-arm /
`!IoErr` channel) each silently resolved one global last-wins `IoErr` via the
`type_bridge.resolveInlineErrorSet` `findByName` short-circuit and the program exited
0; the target is five loud "type 'IoErr' is ambiguous" diagnostics + exit 1.
- **0829 → resolver-target.** *Old selector is wrong here on the E6b-unmerged base:*
the concrete `*Box` prefix of the mixed pack-closure source fell to the no-author
`type_bridge.resolveTemplateSignatureType` wrapper (global last-wins) and registered
silently (exit 0); the target is a loud `Box` ambiguity + exit 1.
## 3. E6BR-5 re-filed into resolver-target
**E6BR-5** (the open nested-pattern ambiguity hole that paused E6b) is re-filed into
the resolver-target set as a regression — **explicitly NOT an E6b attempt-6.**
- *What it is:* `walkConcreteSigArgs` (E6b `lower.zig:14686`) **skips** any direct arg
that has an unbound part instead of **recursing** into it, so a nested concrete leaf
(`*Box` inside `Closure(Closure(*Box, ..$inner) -> $IR, ..$args) -> $R`) is never
ambiguity-checked; the impl compiled rc=0. On `wt-stdlib-base` (E6BR-4 unmerged) both
the direct and nested concrete leaf silently resolve via the pre-E6BR-4 no-author
wrapper path, so the reproducer exits 0 with no diagnostic.
- *Subsumption (one line):* the whole-AST resolver walks **every** reference position —
including nested parameterized-pattern leaves — so the nested `Box` is
ambiguity-checked by construction and the "skip a nested arg" hole cannot exist.
- *Form:* an authored reproducer lives at
`tests/resolver-target/cases/e6br5-nested-pack-source-ambiguous.sx` (self-contained;
verified to exit 0 silently on the base — the fail-before). Its target is a **spec**
(exit 1 + `Box` ambiguous), with exact bytes produced by the resolver at S3.9
(`expected/e6br5-…target.md`).
## 4. The mirror / flip statement (locked)
- **S2's mirror asserts `resolver == old-selector` over the BASELINE-GREEN corpus
ONLY.** It never asserts new == old over the resolver-target corpus (the old selector
is a wrong oracle there), and it never selects for lowering (assert-only, Debug-only,
deleted in the S3.10 commit that completes the cutover).
- **S3.9 flips the resolver-target corpus to active + green**, validated against each
case's TARGET output (not against the old selectors). After the flip, the goldens
move from `tests/resolver-target/expected/` to `examples/expected/`, the harness goes
empty, and these cases stay green through S6.
## 5. Acceptance (S0.2) — self-check
- ✅ Written disposition: E6b transitional src not merged (§1, grep-clean table).
- ✅ Harvested corpus recorded + partitioned: baseline-green (markers, locked,
mirror-equivalence) vs resolver-target (enumerated manifest, separate listed harness,
no active marker, TARGET goldens present, currently xfail, never dropped) — §2.
- ✅ 0811 and 0829 each in resolver-target with the "old selector is wrong on the
E6b-unmerged base" one-liner — §2.
- ✅ E6BR-5 re-filed into resolver-target with the subsumption one-liner, NOT an E6b
attempt-6 — §3.
- ✅ Mirror/flip statement recorded — §4.
- ✅ No transitional E6b src on the Fork C baseline (grep-clean) — §1.

View File

@@ -0,0 +1,72 @@
# S0.3 — AE6 reuse / delete ledger
Authority: `runs/stdlib/design/fork-c-deepdive/reconciled.md` (§6 roadmap + per-phase
deletion lists, §8 fold-in) + `runs/stdlib/design/migration.md` ("what happens to
already-merged AE6 work") + `planspec-r3.json` (S0.3). Base: `wt-stdlib-base @
1f75528`. Symbol/file refs are grounded against the base tree. This is documentation
only — no code change.
This ledger is the contract the later phases execute against: every load-bearing AE6
artifact is mapped to **REUSED** (with its Fork C home) or **DELETED/TRANSITIONAL**
(with the S3/S6 phase that removes it). AE6a stays merged; the transitional E6b src
is never merged (see `S0.2-…`).
## A. REUSED — AE6 work that becomes Fork C infrastructure
| AE6 artifact (base location) | Fork C home | phase |
|---|---|---|
| **Phase A import facts**`RawDeclRef` / `RawAuthor` / `ModuleDecls` / `NamespaceEdges` (`src/imports.zig`), built in `resolveImports` (`core.zig`) | **seed `DeclId` construction**`DeclTable` keys every `RawDeclRef` into a stable `DeclId` (source + name + AST ptr + `DeclKind`); namespace members get ids | S1 |
| **Phase B visibility**`collectVisibleAuthors` / `collectNamespaceAuthors` (`src/ir/resolver.zig`), "the one graph iterator" over `flat_import_graph`/`namespace_edges` | **resolver internals** — become the resolver's visibility walk, with own-wins / single-flat-visible / ≥2-ambiguous **verdicts above them**, producing `ResolvedRef` | S2 |
| **Phase C callable selection** | **`ResolvedRef.function` / `.type_function`** keyed by `DeclId` | S2 (select) → S3 (consume) |
| **Phase D nominal identity**`internNominal` / `updatePreservingKey` + the **`nominal_id == 0 ≡ structural intern` ordinal-0 byte-identity rule** (`src/ir/types.zig`, `lower.zig`) | **reused inside materialization**`materializeType(ResolvedTypeNode)` interns in old scan order with ordinal 0 for non-colliding decls ⇒ byte-identical single-author output | S3 (+ green-lock every phase) |
| **E-series selection rules** — own-wins / not-visible / ambiguity / direct-flat (the E1E6a behaviors) | **resolver behavior + regression tests** (the baseline-green corpus is the mirror oracle) | S2 behavior; regressions locked S0 |
| **CP rule** — body-author == layout-author | **keyed by `InstantiationId{template_decl, resolved_args}`** in the fact store | S4 |
| **E6BR routed-signature cases** (the E6BR-1…4 behavioral cells) | **resolver-signature regressions** — the resolver walks every signature reference position; cases live in the resolver-target corpus, flip at S3.9 | S3.9 |
| **FFI `foreign_class_map` consumers + FFI corpus (96 entry trees / 95 active markers)** | parallel `DeclId`s land at S1 (map still the consumer); foreign classes keyed by `DeclId` at S4; runtime names stay **payload strings on facts** | S1 → S4 |
## B. DELETED / TRANSITIONAL — removed in S3/S6
| artifact (base location) | why it goes | removal phase |
|---|---|---|
| **Stateless `type_bridge` leaves**`resolveAstType` / `resolveTypeName` / `resolveInline{Enum,Union,Struct,ErrorSet}` / `resolveParameterizedType` / `resolveErrorType` (`src/ir/type_bridge.zig`); the whole `type_bridge.zig` (E6b renamed the entry leaf `resolveAstTypeNoAuthorSelection`) | no-author `findByName` leaves — replaced by `materializeType(ResolvedTypeNode)` which cannot take a name | selectors S3; file S6 |
| **`TypeResolver.resolveName` / `resolveNamed`** (`src/ir/type_resolver.zig`) (E6b: `resolveNamedGlobalNoAuthorSelection`) | name→global resolution; superseded by the resolver | S3 (name-selection) / S6 (`resolveName*`) |
| **Old name selectors**`selectNominalLeaf`, `resolveNominalLeaf`, `moduleTypeAuthor`, `namedRefTid`, `flatTypeAuthorCount`, `nameAuthoredAsTypeAnywhere`, `selectModuleConst` (+ const-source pins), `selectGenericStructHead`, `headTypeGate`, `headFnLeak`, `flatFnAuthor*`, the name-selection in `resolveTypeCallWithBindings`/`resolveParameterizedWithBindings` (`src/ir/lower.zig`) | the duality leak — replaced by `ResolvedRef`/`ResolvedTypeNode` consumed in lowering | S3 |
| **`*_by_source` mirrors + source pins** (`src/ir/program_index.zig`) + their writers + the `lower.zig` unified writers | dual-write mirrors of the global maps — superseded by the `DeclId`-keyed fact store | S4 |
| **`type_decl_tids`** (`src/ir/types.zig`, `lower.zig`) | name→TypeId mirror — superseded by `DeclId` facts | S4/S6 |
| **`ShadowTypeDecl` / shadow-slot reservation helpers** (`src/ir/lower.zig`) + lower-side nominal selectors | shadow reservation is a name-keyed pre-pass artifact — subsumed by `DeclId` pre-pass | S3/S4 |
| **`TypeTable.findByName` / `findUniqueByName`** (`src/ir/types.zig`) | the global name table — deleted **last** (after the ~15 category-(b) stdlib lookups are re-homed to resolved-once `DeclId`s, per the §6 critical ordering constraint) | S6 |
| **the type-reference choke-point + route-all engine** (`resolveRegistrationSigTypeInSource` / `sig_registration_mode`) | **transitional E6b src — never merged**; destined for deletion under Fork C | S3/S6 (already off-baseline) |
| **the grep gate `e6br_gate.test.zig`** (+ its `ir.zig` import) | **transitional E6b src — never merged**; unnecessary once the leaf it polices is gone | S6 (already off-baseline) |
| **the S2→S3 assert-only Debug mirror** | a test oracle, not a code path — must be deleted in the **same S3.10 commit** that removes the last old selector | S3.10 |
## C. Dropped / absorbed / superseded plan items
- **E6c / E6d / E6e** (protocol / foreign / type-fn per-kind identity): **DROPPED as
steps.** They become resolver behavior + regression tests — a whole-AST resolver
walks every reference position (annotation, `size_of`, dispatch head, `Self`,
vtable), closing the protocol surface the per-kind patch structurally could not
(reconciled §4 T4).
- **F** (namespace resolver + 0104): **ABSORBED** into S2 as resolver internals
(`namespace_edges``ResolvedRef.namespace` / member).
- **H** (constructor heads): **ABSORBED** into S3 `materializeType` over resolved
generic/protocol/type-fn heads.
- **I** (protocol + foreign selection, loud-on-≥2): **ABSORBED** into S2 selection + S4
`DeclId` facts.
- **K** (delete dead readers): **SUPERSEDED** by the S4 `DeclId`-keyed fact store + the
S6 deletions — "just delete the maps" is upgraded to "replace with `DeclId` facts."
- **the per-kind taxonomy**: **REIFIED** as the `ResolvedRef` union itself; the
exhaustive `switch` is the live taxonomy check (the grep gate is gone because the leaf
it policed no longer exists).
## D. Acceptance (S0.3) — self-check
- ✅ Every load-bearing AE6 artifact mapped to REUSED (with Fork C home) or
DELETED/TRANSITIONAL (with the S3/S6 phase that removes it) — tables A & B; covers
Phase A import facts → `DeclId` seed; B `collectVisibleAuthors` → resolver internals;
C callable selection → `ResolvedRef.function/type_function`; D `internNominal` +
ordinal-0 byte-identity → materialization; E-series rules → resolver behavior +
regressions; CP → `InstantiationId`; the stateless `type_bridge`/`type_resolver`
leaves, `*_by_source` mirrors + source pins, `type_decl_tids`/shadow helpers +
lower-side selectors, the choke-point + route-all + grep gate → S3/S6 deletion.
- ✅ States E6c/d/e dropped and F/H/I/K absorbed/superseded — table C.
- ✅ No code change.

View File

@@ -1,4 +1,5 @@
#import "modules/std.sx";
#import "modules/allocators.sx"; // `Allocator` is non-transitive: name it, import it.
#import "modules/math/math.sx";
#import "modules/compiler.sx";
#import "modules/test.sx";

View File

@@ -0,0 +1,20 @@
// Two top-level structs each carry an inline anonymous-struct field named
// `inner`, but of DIFFERENT shapes. Each `inner` must resolve to its OWN
// anonymous type (`A.inner` has `x`; `B.inner` has `y, z`) — they must not
// cross-bind on the shared field spelling.
//
// Regression (folded from the Phase-D `replaceKeyedInfo` re-key, which made the
// per-parent anon rename key-safe): on master 7ffc0c1 the two anon types
// cross-bound and `b.inner.y` failed with "field 'y' not found on type
// 'B.inner'". Pins fail-before / pass-after.
#import "modules/std.sx";
A :: struct { inner: struct { x: s64; }; }
B :: struct { inner: struct { y: s64; z: s64; }; }
main :: () -> s32 {
a := A.{ inner = .{ x = 1 } };
b := B.{ inner = .{ y = 2, z = 3 } };
print("{} {} {}\n", a.inner.x, b.inner.y, b.inner.z);
0
}

View File

@@ -0,0 +1,29 @@
// A genuinely-undeclared type name used as a field type inside a MAIN-file
// GENERIC struct must emit a clean "unknown type" diagnostic, not silently
// compile.
//
// The `UnknownTypeChecker` used to SKIP generic structs entirely ("their field
// types reference the struct's own `$T`, resolved at instantiation"). That skip
// was too broad: a field type like `bad: MissingType` — which is NOT a type
// param and names no declared type — fell through the type leaf's empty-struct
// stub and the struct silently compiled, mis-sizing every downstream load.
//
// The checker now walks generic-struct fields with the struct's own type params
// (`$T`) in scope: `good: T` resolves (it IS a param) while `bad: MissingType`
// is reported. A value-param position (a `Vector` lane count, a `$N: u32` arg)
// is still skipped, so a valid generic struct keeps compiling unchanged.
//
// Expected: `error: unknown type 'MissingType'` pointing at the field; exit 1.
// Regression (stdlib E3).
#import "modules/std.sx";
Box :: struct($T: Type) {
good: T;
bad: MissingType;
}
main :: () -> s32 {
b : Box(s64) = .{ good = 7, bad = 0 };
print("{}\n", b.good);
return 0;
}

View File

@@ -0,0 +1,29 @@
// A generic struct's VALUE param (`$N: u32`) is a compile-time integer, not a
// type. Naming it in a TYPE position — here a field type `x: N` — must emit a
// clean diagnostic, NOT silently compile.
//
// The parser marks any reference to a struct's own type param `is_generic`
// (so `x: T` for a real `$T: Type` resolves without a `$`). That marking is
// the same for a value param, so the unknown-type walk used to skip `x: N`
// entirely; the field's type leaf then resolved to the `.unresolved` sentinel
// and PANICKED at LLVM emission ("unresolved type reached LLVM emission").
//
// The checker now distinguishes TYPE params (`$T: Type`, `$T: SomeProtocol`,
// the `..$Ts` pack) from VALUE params (`$N: u32`) using the binder's own rule:
// a value param named in a type position gets the tailored hint. A value param
// in a VALUE position (a `[N]u8` array dimension, a `Vector` lane count) still
// works (see 0147 / 0201).
//
// Expected: `error: 'N' is a value parameter, not a type`; exit 1.
// Regression (stdlib E3).
#import "modules/std.sx";
Bad :: struct($N: u32) {
x: N;
}
main :: () -> s32 {
b : Bad(3) = .{ x = 1 };
print("{}\n", b.x);
return 0;
}

View File

@@ -0,0 +1,31 @@
// Resolver E1 lock: the bare-type-leaf cutover to the source-aware
// `selectNominalLeaf` must NOT touch the NON-leaf type heads. A generic-struct
// instantiation (`Box(s32)`), a `Vector(N, T)` builtin, and a type-returning
// function (`Make(3, s64)`) are all resolved by `resolveTypeWithBindings`
// ABOVE the bare-name leaf switch (`resolveParameterizedWithBindings` /
// `resolveTypeCallWithBindings` / the `Vector` builtin path), so they stay on
// the legacy resolution and never reach `selectNominalLeaf`. Parameterized
// protocols share the same `resolveParameterizedWithBindings` pre-leaf path
// (covered by 0204/0206). This example pins that all three still resolve
// identically after the cutover.
#import "modules/std.sx";
Box :: struct($T: Type) {
value: T;
}
Make :: ($K: u32, $T: Type) -> Type { return [K]T; }
N :: 3;
main :: () {
b : Box(s32) = .{ value = 42 };
print("box: {}\n", b.value);
v : Vector(4, f32) = .[1, 2, 3, 4];
print("vec: {} {}\n", v.x, v.w);
a : Make(N, s64) = ---;
a[0] = 10; a[2] = 30;
print("typefn: len={} a0={} a2={}\n", a.len, a[0], a[2]);
}

View File

@@ -13,6 +13,9 @@
// both impl modules.
#import "modules/std.sx";
// `Wrap` is declared in the shared types module; bare-import visibility is
// non-transitive, so naming it here means importing it here (not via impl-a/b).
#import "./0411-protocols-impl-duplicate-types.sx";
#import "./0411-protocols-impl-duplicate-impl-a.sx";
#import "./0411-protocols-impl-duplicate-impl-b.sx";

View File

@@ -0,0 +1,22 @@
// Regression (stdlib E4): an imported pack function whose fixed-prefix param
// type is visible only in its defining module must resolve during pack
// monomorphization. `lib.sx` imports `dep.sx` (which defines `Needs`) and
// exposes `make() -> Needs` plus `use_pack(n: Needs, ..$args)`. `main` imports
// ONLY `lib.sx`, so `Needs` is two flat hops away and not bare-visible here —
// main never names it.
//
// Before the fix, `monomorphizePackFn` restored the caller's source before
// re-binding the fixed-prefix params, so `n: Needs` was resolved in main's
// context and rejected with "type 'Needs' is not visible" — even though the
// control plain fn `use_plain(n: Needs)` (typed via the source-pinned call-arg
// path) ran fine. The fixed-prefix param is now resolved under the pack fn's own
// source (`fd.body.source_file`), matching the rest of the pack signature/body.
#import "modules/std.sx";
#import "0544-packs-imported-pack-fn-fixed-param-source-pin/lib.sx";
main :: () -> s32 {
x := make();
print("plain {}\n", use_plain(x));
print("pack {}\n", use_pack(x, 1, 2));
return 0;
}

View File

@@ -0,0 +1,3 @@
// `Needs` lives two flat-import hops away from `main` (main -> lib -> dep), so
// it is NOT bare-visible at the call site under non-transitive visibility.
Needs :: struct { v: s64; }

View File

@@ -0,0 +1,16 @@
// `lib.sx` imports `dep.sx`, so `Needs` is bare-visible HERE. A module that
// imports only `lib.sx` cannot see `Needs` (non-transitive). The pack fn's
// fixed-prefix param `n: Needs` must therefore resolve in this module's
// context, not the caller's.
#import "modules/std.sx";
#import "dep.sx";
make :: () -> Needs => Needs.{ v = 7 };
// Control: a plain (non-pack) fn with the same fixed param already resolves in
// its defining module — the cross-module call-arg typing path is source-pinned.
use_plain :: (n: Needs) -> s64 => n.v;
// Pack fn: the fixed-prefix param `n: Needs` is bound during pack
// monomorphization. Its type must resolve under this module's source.
use_pack :: (n: Needs, ..$args) -> s64 => n.v + args[0];

View File

@@ -9,6 +9,9 @@
// registration tripped: `duplicate impl 'Into' for source 's64'`. Now the flat
// decl list also dedups by node identity, so this builds and prints 7.
#import "modules/std.sx";
// `Wrapped` lives in the shared `common.sx`; bare-import visibility is
// non-transitive, so naming it here means importing it here (not via mid_a/b).
#import "0709-modules-issue-0056/common.sx";
#import "0709-modules-issue-0056/mid_a.sx";
#import "0709-modules-issue-0056/mid_b.sx";

View File

@@ -18,6 +18,7 @@
// and freed in one `deinit`; the writer path allocates nothing.
#import "modules/std.sx";
#import "modules/allocators.sx"; // `Allocator` is non-transitive: name it, import it.
#import "modules/std/json.sx";
#import "modules/fs.sx";

View File

@@ -20,6 +20,7 @@
// `JsonParseError` variant on the error channel, never a bogus value.
#import "modules/std.sx";
#import "modules/allocators.sx"; // `Allocator` is non-transitive: name it, import it.
#import "modules/std/json.sx";
// Canonical document: no insignificant whitespace, escapes in the writer's

View File

@@ -23,6 +23,7 @@
// and decoded strings go through `alloc`, and the writer allocates nothing.
#import "modules/std.sx";
#import "modules/allocators.sx"; // `Allocator` is non-transitive: name it, import it.
#import "modules/std/json.sx";
// The writer's EXACT output for the PART A document (insertion order,

View File

@@ -12,6 +12,15 @@
// independent identities.
#import "modules/std.sx";
#import "modules/allocators.sx"; // `Allocator` is non-transitive: name it, import it.
// `cli` is imported BOTH flat (so its types — `FlagSpec` / `Command` / `Diag` —
// are bare-visible) AND namespaced (so the same-name `cli.parse` stays a
// distinct qualified identity from `json.parse`). Post-E1 a bare reference to a
// namespaced-ONLY type is a "not visible" error, so the flat import is what makes
// the bare type names below resolve; `json` stays namespaced-only (its `Value`
// reaches `main` only as `json.parse`'s return type, resolved in `json.sx`'s own
// context).
#import "modules/std/cli.sx";
cli :: #import "modules/std/cli.sx";
json :: #import "modules/std/json.sx";

View File

@@ -0,0 +1,12 @@
// Bare-name visibility under a NAMESPACED-only import (regression, issue 0106).
// `a.sx` is imported only as `m :: #import` — its top-level `secret` is reachable
// ONLY as `m.secret`. A BARE `secret()` must error: bare-name visibility joins
// over the FLAT import edges (`flat_import_graph`), and a namespaced alias is not
// a flat edge. (Before the fix, `isNameVisible` walked `import_graph`, which also
// records namespaced edges, so the bare call silently resolved.)
m :: #import "0736-modules-namespaced-only-bare-not-visible/a.sx";
main :: () -> s32 {
x := secret();
0
}

View File

@@ -0,0 +1 @@
secret :: () -> s64 { 7 }

View File

@@ -0,0 +1,15 @@
// A bare name inside a USER `#insert <expr>` is visibility-checked in the
// USER's module, not skipped (regression, issue 0106). `a.sx` is imported only
// as `m :: #import` — its top-level `secret` is reachable ONLY as `m.secret`.
// A BARE `secret()` driving a `#insert` must error just like any other bare
// reference into a namespaced-only import: `#insert` expansion does NOT exempt
// user-typed code from visibility. (Library metaprograms like `std.print` keep
// working because their bodies lower in their OWN module's context — see
// `monomorphizePackFn` / `lowerComptimeCall` pinning `current_source_file` to
// the body's defining module — not because `#insert` is exempt.)
m :: #import "0737-modules-insert-bare-not-visible/a.sx";
main :: () -> s32 {
#insert secret();
0
}

View File

@@ -0,0 +1 @@
secret :: () -> string { "leaked := 1;" }

View File

@@ -0,0 +1,24 @@
// A caller-owned helper passed as a comptime-ONLY `$`-arg to a NAMESPACED
// imported metaprogram resolves in the CALLER's visibility context — not the
// metaprogram's defining module (regression, issue 0106 follow-up).
//
// `emit` is reachable only as `m.emit`; the comptime arg `caller_name()` is
// authored HERE in the caller. When `emit` splices that arg into its `#insert`
// body and lowers it, the bare name `caller_name` must stay visible in the
// caller's context. Before the fix, the body's defining-module pin also covered
// the substituted caller arg, so `caller_name` was wrongly checked against
// `emit.sx` and rejected as "not visible". The metaprogram's OWN code still
// resolves in `emit.sx` (where `concat`/`print` are flat-imported), so this
// stays compatible with the 0106 defining-context pin.
//
// Comptime-ONLY: `caller_name()` is evaluated at compile time and its value is
// embedded as a literal in the generated `print(...)` statement — it is never
// materialized at runtime (so this does NOT exercise issue 0107).
m :: #import "0738-modules-comptime-arg-caller-context/emit.sx";
caller_name :: () -> string { return "world"; }
main :: () -> s32 {
m.emit(caller_name());
return 0;
}

View File

@@ -0,0 +1,9 @@
// Library metaprogram: builds a `print(...)` statement at compile time from the
// comptime `$who` value. `concat`/`print` are flat-imported here and resolve in
// THIS module's context (the 0106 defining-module pin). The substituted caller
// `$`-arg, by contrast, resolves in the CALLER's context.
#import "modules/std.sx";
emit :: ($who: string) {
#insert concat(concat("print(\"hello ", who), "\\n\");");
}

View File

@@ -0,0 +1,25 @@
// Caller-owned helpers passed as VARIADIC comptime-pack args (`..$args`) to a
// NAMESPACED imported metaprogram resolve in the CALLER's visibility context —
// not the metaprogram's defining module (regression, issue 0106 follow-up).
//
// `std.print :: ($fmt: string, ..$args)` is authored in `std.sx`; the pack args
// `caller_num()` / `caller_two()` are authored HERE in the caller. The body's
// typed `args[i]` substitution (via packArgNodeAt) lowers each pack arg under
// the metaprogram's defining-module pin, so without stamping the pack-arg nodes
// with the caller's source, the bare names `caller_num` / `caller_two` were
// wrongly checked against `std.sx` and rejected as "not visible". The fixed
// comptime param (`$fmt`) already got this treatment; this extends it to every
// node in the variadic pack. The metaprogram's OWN code (build_format / out)
// still resolves in `std.sx`, so the defining-context pin stays intact.
//
// Two pack positions lock that EVERY pack arg is stamped, not just the first.
// s64 values only — accepted by print at runtime today (no 0107/0108 coupling).
std :: #import "modules/std.sx";
caller_num :: () -> s64 { return 42; }
caller_two :: () -> s64 { return 7; }
main :: () -> s32 {
std.print("{} {}\n", caller_num(), caller_two());
return 0;
}

View File

@@ -0,0 +1,17 @@
// Regression (issue 0102, Phase C): value-receiver free-function UFCS under a
// flat same-name collision must be TYPED as the author lowering dispatches.
// a.sx (imported first → first-wins winner) authors `tag -> string`; b.sx
// authors its OWN `tag -> s64`. In b.sx, `v.tag()` dispatches b.tag (s64), but
// before the fix the call PLAN typed it as a.tag (string, first-wins) — so the
// pack-fn `print` boxed the raw s64 110 as a string pointer and dereferenced
// 0x6e → segfault. `CallResolver.plan` now selects the SAME author the lowering
// call-path binds, so plan-typing and dispatch can't disagree (fix-0102 F2).
#import "modules/std.sx";
#import "0740-modules-flat-same-name-ufcs-typing/a.sx";
#import "0740-modules-flat-same-name-ufcs-typing/b.sx";
main :: () -> s32 {
show_a(); // a-side: own == winner → string, byte-for-byte unchanged
show_b(); // b-side: shadow author → s64, typed + dispatched as b.tag
0
}

View File

@@ -0,0 +1,6 @@
#import "modules/std.sx";
// a.sx authors `tag` returning a string; imported first → first-wins winner.
// `show_a`'s `v.tag()` is the caller's OWN author (own == winner → existing UFCS
// path, byte-for-byte unchanged): typed AND dispatched as a.tag (string).
tag :: (x: s64) -> string { return "a-string"; }
show_a :: () { v : s64 = 10; print("a: v.tag() = {}\n", v.tag()); }

View File

@@ -0,0 +1,7 @@
#import "modules/std.sx";
// b.sx authors its OWN `tag` returning s64. `show_b`'s `v.tag()` must be both
// dispatched AND typed as b.tag (s64 = 110), not the first-wins winner from a.sx
// (string). `print` types each arg from the call plan, so a mistype here boxes
// the s64 as a string pointer → segfault before the fix.
tag :: (x: s64) -> s64 { return x + 100; }
show_b :: () { v : s64 = 10; print("b: v.tag() = {}\n", v.tag()); }

View File

@@ -0,0 +1,18 @@
// Regression (issue 0102, Phase C): a BARE call whose own author is a plain free
// fn must DISPATCH to that author, not the first-wins winner — even when the
// winner is a comptime PACK (`..$args`) of the same name. a.sx (imported first)
// authors `f` as a pack → first-wins winner; b.sx authors its OWN plain `f`. In
// b.sx, `f()` must reach b.f (returns 2). Before the fix, lowerCall's early
// pack/comptime/generic dispatch keyed off the first-wins winner (a's pack) and
// invoked it (returns 1) BEFORE consuming the selected author — so plan-selected
// author and lowered+dispatched author disagreed. The early dispatch now reads
// the SAME `SelectedFunc` the main dispatch binds (fix-0102 F2).
#import "modules/std.sx";
#import "0741-modules-flat-same-name-bare-pack-winner/a.sx";
#import "0741-modules-flat-same-name-bare-pack-winner/b.sx";
main :: () -> s32 {
show_a(); // a-side: own == winner (the pack) → returns 1, byte-for-byte unchanged
show_b(); // b-side: selected own plain author → returns 2, not the pack winner
0
}

View File

@@ -0,0 +1,6 @@
#import "modules/std.sx";
// a.sx authors `f` as a comptime pack; imported first → first-wins winner.
// `show_a`'s bare `f()` is the caller's OWN author (own == winner → existing
// pack path, byte-for-byte unchanged): dispatched as a.f (the pack → 1).
f :: (..$args) -> s64 { return 1; }
show_a :: () { print("a: f() = {}\n", f()); }

View File

@@ -0,0 +1,6 @@
#import "modules/std.sx";
// b.sx authors its OWN plain `f`. `show_b`'s bare `f()` must dispatch b.f (2),
// not the first-wins pack winner from a.sx (1). The selector picks b.f; the
// early pack/comptime dispatch must NOT hijack it with the winner.
f :: () -> s64 { return 2; }
show_b :: () { print("b: f() = {}\n", f()); }

View File

@@ -0,0 +1,15 @@
// Bare module-const visibility under a NAMESPACED-only import — the const
// sibling of 0736 (folded req #1 of the source-aware resolver, Phase E1).
// `dep.sx` is imported only as `dep :: #import`, so its top-level `DEP_LEN`
// is reachable ONLY as `dep.DEP_LEN`. A BARE `DEP_LEN` in a comptime
// array-dimension position must NOT resolve: bare module-const visibility
// joins over the FLAT import edges (`flat_import_graph`), and a namespaced
// alias is not a flat edge. Before the fix the bare const leaked through the
// global `module_const_map` first-match (and its float-fold fallback) straight
// into the `[VAL]s32` dimension, so the array silently got length 3.
dep :: #import "0742-modules-namespaced-only-bare-const-not-visible/dep.sx";
main :: () -> s32 {
arr : [DEP_LEN]s32 = ---;
0
}

View File

@@ -0,0 +1 @@
DEP_LEN :: 3;

View File

@@ -0,0 +1,16 @@
// Bare TYPE visibility under a NAMESPACED-only import — the struct sibling of
// 0736 (bare call) and 0742 (bare const), and the core of the source-aware
// nominal leaf (Phase E1). `dep.sx` is imported only as `dep :: #import`, so its
// top-level `Secret` struct is reachable ONLY as `dep.Secret`. A BARE `Secret`
// in a type position must NOT resolve: bare-TYPE visibility joins over the FLAT
// import edges (`flat_import_graph`, transitively), and a namespaced alias is not
// a flat edge. Before the fix the bare type leaked through the global
// `findByName` first-match (the leaf returned it ahead of the visibility check),
// so `s.x` compiled and ran. The qualified form `dep.Secret` stays the supported
// spelling (its member resolution lands fully in Phase F).
dep :: #import "0743-modules-namespaced-only-bare-type-not-visible/dep.sx";
main :: () -> s32 {
s : Secret = .{ x = 5, y = 6 };
s.x
}

View File

@@ -0,0 +1,4 @@
Secret :: struct {
x: s32;
y: s32;
}

View File

@@ -0,0 +1,13 @@
// Bare TYPE visibility under a NAMESPACED-only import — the ENUM sibling of 0743
// (struct), covering the second registered nominal kind for the source-aware
// nominal leaf (Phase E1). `dep.sx` is imported only as `dep :: #import`, so its
// top-level `Color` enum is reachable ONLY as `dep.Color`. A BARE `Color` in a
// type position must NOT resolve — bare-TYPE visibility joins over the FLAT
// import edges, and a namespaced alias is not a flat edge. Before the fix the
// bare enum leaked through the global `findByName` first-match.
dep :: #import "0744-modules-namespaced-only-bare-enum-not-visible/dep.sx";
main :: () -> s32 {
c : Color = .green;
if c == .green { 0 } else { 9 }
}

View File

@@ -0,0 +1,5 @@
Color :: enum {
red;
green;
blue;
}

View File

@@ -0,0 +1,15 @@
// Type-author-aware bare-TYPE visibility gate (Phase E1, R1). `flatval.sx` is
// flat-imported and authors a VALUE/FUNCTION `Secret`; `nstype.sx` is namespaced
// (`nst :: #import`) and authors a TYPE `Secret`. A bare `Secret` in a type
// position must NOT resolve: the only flat-visible `Secret` author is a FUNCTION,
// and a same-name flat value does NOT make the namespaced-only TYPE bare-visible.
// The leak this closes: a name-only gate would see the flat function and let the
// global `findByName` first-match return the namespaced-only struct. The type is
// reachable only as `nst.Secret`.
#import "0745-modules-flat-value-shadows-ns-only-type/flatval.sx";
nst :: #import "0745-modules-flat-value-shadows-ns-only-type/nstype.sx";
main :: () -> s32 {
s : Secret = .{ x = 5, y = 6 };
s.x
}

View File

@@ -0,0 +1,2 @@
// A flat-visible VALUE/FUNCTION named `Secret` (not a type).
Secret :: () -> s32 { 0 }

View File

@@ -0,0 +1,4 @@
Secret :: struct {
x: s32;
y: s32;
}

View File

@@ -0,0 +1,13 @@
// A block-LOCAL type resolves even when a namespaced-only import authors a
// top-level type of the same name (Phase E1, R2). `dep.sx` is namespaced
// (`dep :: #import`) and authors a top-level `Secret`; `main` declares its OWN
// block-local `Secret`. The local must resolve to ITS fields (a legitimately-
// scoped local is never a namespaced-only leak), not be rejected by the bare-TYPE
// visibility gate just because the namespaced import shares the name.
dep :: #import "0746-modules-local-type-shadows-ns-only-type/dep.sx";
main :: () -> s32 {
Secret :: struct { z: s32; }
s : Secret = .{ z = 7 };
s.z
}

View File

@@ -0,0 +1,4 @@
Secret :: struct {
x: s32;
y: s32;
}

View File

@@ -0,0 +1,16 @@
// Bare TYPE-ALIAS visibility under a NAMESPACED-only import — the alias sibling
// of 0743 (bare named type) and 0742 (bare const). A type ALIAS is a `const_decl`
// whose value resolved to a type, so it never registers a `findByName` named-type
// entry; the source-aware leaf must still treat it as a TYPE author (R4). `dep.sx`
// is imported only as `dep :: #import`, so its top-level `Secret :: s32` alias is
// reachable ONLY as `dep.Secret`. A BARE `Secret` in a type position must NOT
// resolve: bare-TYPE visibility joins over the FLAT import edges, and a namespaced
// alias is not a flat edge. Before the fix the ns-only alias was NOT a recognised
// type author, so the bare reference fell to the legacy empty-struct stub with NO
// diagnostic (the value silently came out 0). Regression (issue R4).
dep :: #import "0747-modules-namespaced-only-bare-alias-not-visible/dep.sx";
main :: () -> s32 {
x : Secret = 7;
x
}

View File

@@ -0,0 +1 @@
Secret :: s32;

View File

@@ -0,0 +1,18 @@
// A flat-visible (here own-module) type ALIAS must resolve even when a
// namespaced-only import authors a same-name NAMED type — the alias↔named-type
// analog of 0745/0746 (R4, FALSE-REJECTION direction). `dep.sx` is namespaced
// (`ns :: #import`) and authors a top-level `Secret` STRUCT; `main` authors its
// OWN top-level alias `Secret :: s32`. A bare `Secret` must resolve to MAIN's
// alias (`s32`), NOT be poisoned by the invisible same-name struct: the alias is
// the only flat-visible TYPE author. Before the fix the leaf saw the global
// `findByName` struct and, finding no NAMED-type author in `main` (an alias is a
// `const_decl`, not a named type), wrongly rejected the bare reference as "not
// visible". Regression (issue R4).
ns :: #import "0748-modules-flat-alias-shadows-ns-only-type/dep.sx";
Secret :: s32;
main :: () -> s32 {
x : Secret = 42;
x
}

View File

@@ -0,0 +1,4 @@
Secret :: struct {
x: s32;
y: s32;
}

View File

@@ -0,0 +1,17 @@
// Bare PARAMETERIZED-struct alias visibility under a NAMESPACED-only import —
// the generic-struct sibling of 0747 (plain alias) and 0743 (named type). A
// generic-struct instantiation alias (`Secret :: Box(s32)`) registers ONLY a
// named struct type in the TypeTable; its raw import fact stays `.const_decl`,
// so before the fix it was NOT recognised as a type author and a BARE `Secret`
// leaked to the registered struct with NO diagnostic (the value silently came
// out 42). The unified declaration-fact writer routes the instantiation alias
// through `type_aliases_by_source`, so the bare-TYPE gate treats it like any
// other alias: `dep.sx` is imported only as `dep :: #import`, so bare `Secret`
// is reachable ONLY as `dep.Secret` and must NOT resolve. Regression
// (attempt-5 R4-parameterized-alias-leak).
dep :: #import "0749-modules-namespaced-only-bare-param-alias-not-visible/dep.sx";
main :: () -> s32 {
s : Secret = .{ value = 42 };
s.value
}

View File

@@ -0,0 +1,5 @@
Box :: struct($T: Type) {
value: T;
}
Secret :: Box(s32);

View File

@@ -0,0 +1,31 @@
// Source-aware forward-alias fixpoint (R5 §4, E1.5). A forward identifier alias
// `A :: B` must resolve its target `B` AS SEEN FROM ITS OWN SOURCE, not via the
// global `type_alias_map` (which is last-wins across every module).
//
// `main` authors a forward alias `A :: B` and its own `B :: u64`. The namespaced
// import `ns :: #import ".../dep.sx"` ALSO authors a top-level `B :: u8`; being
// scanned after main's `B`, dep's alias is what the GLOBAL `type_alias_map["B"]`
// ends up holding (last-wins). A global forward-alias fixpoint therefore bound
// `A` to dep's `u8` — re-opening 0105 one layer down. The source-aware fixpoint
// resolves `A`'s target against MAIN's source, binding the local `B :: u64`.
//
// Observable: a runtime 300 coerced into an `A`-typed slot round-trips as 300
// when `A` is `u64` (correct) and truncates to 44 when `A` is wrongly `u8`.
// The direct reference `b : B` already resolves source-aware via E1's nominal
// leaf, so it pins the same `u64` for contrast. Regression (stdlib E1.5).
#import "modules/std.sx";
A :: B;
B :: u64;
ns :: #import "0750-modules-forward-alias-source-aware/dep.sx";
main :: () -> s32 {
n : s64 = 300;
a : A = xx n;
b : B = xx n;
print("forward A (u64=300): {}\n", cast(s64) a);
print("direct B (u64=300): {}\n", cast(s64) b);
print("ns.width(): {}\n", ns.width());
return 0;
}

View File

@@ -0,0 +1,10 @@
// Namespaced helper module. It authors a top-level type alias `B` whose
// spelling collides with the importer's own `B`. Because the import is
// NAMESPACED (`ns :: #import`), `dep.B` is NOT flat-visible to the importer —
// but its alias write still lands in the global `type_alias_map` (last-wins),
// which is exactly what the source-aware forward-alias fixpoint must ignore.
B :: u8;
width :: () -> s32 {
return 8;
}

View File

@@ -0,0 +1,36 @@
// Source-aware forward-alias fixpoint — the INITIAL scan registration (E1.5).
// Sibling of 0750, but the namespaced import is placed BEFORE the forward alias:
//
// ns :: #import ".../dep.sx"; // authors a same-name `B :: u8`
// A :: B; // forward alias
// B :: u64; // its LOCAL target, declared later
//
// Because `ns` is scanned first, dep's `B :: u8` is already in the global
// `type_alias_map` when `A :: B` is scanned. The pre-E1.5-attempt-2 `scanDecls`
// identifier-RHS branch resolved the RHS through that GLOBAL map and bound `A` to
// dep's `u8` right there; the per-source fixpoint guard then saw `A` already
// resolved and skipped it, so the source-aware leaf never corrected it (`A` came
// out `u8`, truncating 300 -> 44). The source-aware scan registration resolves
// `B` AS SEEN FROM main's source: dep's `B` is namespaced-only (not bare-visible)
// and main's `B` is not registered yet, so `A` is left UNWRITTEN and the fixpoint
// binds it to the local `B :: u64` once that registers.
//
// Observable: a runtime 300 coerced into an `A`-typed slot round-trips as 300
// when `A` is `u64` (correct) and truncates to 44 when `A` is wrongly `u8`.
// Regression (stdlib E1.5).
#import "modules/std.sx";
ns :: #import "0751-modules-forward-alias-ns-before/dep.sx";
A :: B;
B :: u64;
main :: () -> s32 {
n : s64 = 300;
a : A = xx n;
b : B = xx n;
print("forward A (u64=300): {}\n", cast(s64) a);
print("direct B (u64=300): {}\n", cast(s64) b);
print("ns.width(): {}\n", ns.width());
return 0;
}

View File

@@ -0,0 +1,11 @@
// Namespaced helper module. It authors a top-level type alias `B` whose spelling
// collides with the importer's own `B`. Because the import is NAMESPACED
// (`ns :: #import`), `dep.B` is NOT flat-visible to the importer — but its alias
// write still lands in the global `type_alias_map`, which the source-aware
// forward-alias scan registration must ignore even when this module is scanned
// (and so populates the global map) BEFORE the importer's own `A :: B`.
B :: u8;
width :: () -> s32 {
return 8;
}

View File

@@ -0,0 +1,14 @@
// issue 0105 case 1 — same-name struct, DIFFERENT fields. Two flat-imported
// modules each declare a top-level `Box` with a different field set. Each
// module's function builds and returns ITS OWN `Box`; `main` (which authors no
// `Box`) prints both. Each value resolves against its declaring module's type,
// so the formatter shows A's `{x}` and B's `{p, q}` — proving the two `Box`
// types are distinct nominal identities, not a single last-wins collapse.
#import "modules/std.sx";
#import "0752-modules-same-name-struct-distinct-fields/a.sx";
#import "0752-modules-same-name-struct-distinct-fields/b.sx";
main :: () -> s32 {
print("a={} b={}\n", a_box(), b_box());
0
}

View File

@@ -0,0 +1,3 @@
// Module A authors its OWN `Box` (one `s64` field `x`).
Box :: struct { x: s64; }
a_box :: () -> Box { return Box.{ x = 7 }; }

View File

@@ -0,0 +1,5 @@
// Module B authors a DIFFERENT `Box` (two fields `p`, `q`) — a same-name shadow
// of A's `Box`. Pre-0105 the two collapsed last-wins in the type table, so one
// module's field set vanished; now each `Box` is a distinct nominal type.
Box :: struct { p: s64; q: s64; }
b_box :: () -> Box { return Box.{ p = 3, q = 4 }; }

View File

@@ -0,0 +1,15 @@
// issue 0105 case 2 — same-name struct, SAME fields. Two flat-imported modules
// each declare `Pair { x, y }` with identical shape. They are STILL distinct
// nominal identities (each holds its own per-source TypeId / nominal id), not
// folded into one — both register, both monomorphize their own formatter, and
// each module's value prints correctly. (The nominal-distinctness mechanism is
// pinned at the unit level in `types.test.zig`; this example pins that two
// identically-shaped same-name structs coexist without collapse or crash.)
#import "modules/std.sx";
#import "0753-modules-same-name-struct-same-fields/a.sx";
#import "0753-modules-same-name-struct-same-fields/b.sx";
main :: () -> s32 {
print("a={} b={}\n", a_pair(), b_pair());
0
}

View File

@@ -0,0 +1,3 @@
// Module A authors `Pair { x, y }`.
Pair :: struct { x: s64; y: s64; }
a_pair :: () -> Pair { return Pair.{ x = 1, y = 2 }; }

View File

@@ -0,0 +1,5 @@
// Module B authors `Pair { x, y }` with the SAME field shape as A's. The two
// still get distinct nominal identities (not collapsed): each keeps its own
// TypeId / per-source author, so both register and format independently.
Pair :: struct { x: s64; y: s64; }
b_pair :: () -> Pair { return Pair.{ x = 5, y = 6 }; }

View File

@@ -0,0 +1,15 @@
// issue 0105 case 3 — own-wins-over-flat. `main` flat-imports `dep.sx` (which
// authors `Widget { a }`) AND authors its OWN `Widget { m }`. A bare `Widget`
// reference in `main` resolves to `main`'s OWN author, not the flat-imported one
// (the querying source's author wins outright — no ambiguity), so `Widget.{ m }`
// builds `main`'s type while `dep_widget()` returns `dep`'s distinct `Widget`.
#import "modules/std.sx";
#import "0754-modules-same-name-struct-own-wins/dep.sx";
Widget :: struct { m: s64; }
main :: () -> s32 {
w := Widget.{ m = 5 };
print("own={} dep={}\n", w, dep_widget());
0
}

View File

@@ -0,0 +1,5 @@
// A flat-imported module authors its OWN `Widget { a }`. The importing file
// (`main`) ALSO authors a `Widget` — its own author must win there (0105 case 3),
// while this module's `Widget` stays a distinct type used by `dep_widget`.
Widget :: struct { a: s64; }
dep_widget :: () -> Widget { return Widget.{ a = 9 }; }

View File

@@ -0,0 +1,13 @@
// issue 0105 case 4 — two-flat-visible → AMBIGUOUS. `main` flat-imports two
// modules that each author a same-name `Thing`, and authors none itself. A bare
// `Thing` reference can't be disambiguated, so the compiler emits a LOUD
// diagnostic ("ambiguous … qualify the reference or remove the duplicate
// import") and poisons the result — never a silent first-/last-wins pick.
#import "modules/std.sx";
#import "0755-modules-same-name-struct-ambiguous/a.sx";
#import "0755-modules-same-name-struct-ambiguous/b.sx";
main :: () -> s32 {
t : Thing = .{ a = 1 };
0
}

View File

@@ -0,0 +1,2 @@
// One of two flat-imported authors of a same-name `Thing`.
Thing :: struct { a: s64; }

View File

@@ -0,0 +1,3 @@
// The second flat-imported author of a same-name `Thing`. With both visible and
// no own author in `main`, a bare `Thing` reference is genuinely ambiguous.
Thing :: struct { b: s64; }

View File

@@ -0,0 +1,13 @@
// issue 0105 case 5 — same-name type ALIAS, per-source visibility. Two
// flat-imported modules each alias `Id` to a DIFFERENT type (A: `s32`, B:
// `f64`). Each module's bare `Id` resolves against its OWN source alias, so A's
// `x : Id` is a 32-bit integer (prints 100) and B's `x : Id` is a float (prints
// 2.5) — proving aliases are source-keyed, never folded last-wins.
#import "modules/std.sx";
#import "0756-modules-same-name-alias-per-source/a.sx";
#import "0756-modules-same-name-alias-per-source/b.sx";
main :: () -> s32 {
print("a={} b={}\n", a_val(), b_val());
0
}

View File

@@ -0,0 +1,4 @@
// Module A aliases `Id` to `s32`. A bare `Id` in this module resolves to A's
// alias regardless of B's same-name alias (per-source alias visibility).
Id :: s32;
a_val :: () -> s64 { x : Id = 100; y : s64 = xx x; return y; }

View File

@@ -0,0 +1,5 @@
// Module B aliases the SAME name `Id` to a DIFFERENT type `f64`. A bare `Id` in
// this module resolves to B's `f64` alias, not A's `s32` — each module's alias
// is keyed to its own source, so the two never collide last-wins.
Id :: f64;
b_val :: () -> f64 { x : Id = 2; return x + 0.5; }

View File

@@ -0,0 +1,16 @@
// issue 0105 / F1 regression — a SELF-REFERENCE inside a same-name struct shadow.
// Two flat-imported modules each declare a top-level `Box`; module B's `Box` has
// a field `next: *Box` referencing its own name. The shadow must resolve that
// self-ref to ITS OWN nominal identity, not the first same-name author (A's
// `Box`), so `head.next.*.y` reads B's `y` (= 42). Proves the reserve-before-
// fields ordering: a shadow author's decl key is recorded before its fields are
// resolved, so a self / forward ref binds via `type_decl_tids`, never the global
// findByName first-author fallback.
#import "modules/std.sx";
#import "0757-modules-same-name-struct-self-ref/a.sx";
#import "0757-modules-same-name-struct-self-ref/b.sx";
main :: () -> s32 {
print("a={} b={}\n", a_box(), b_chain());
0
}

View File

@@ -0,0 +1,3 @@
// Module A authors its OWN `Box` (one field `x`) — the FIRST same-name author.
Box :: struct { x: s64; }
a_box :: () -> Box { return Box.{ x = 7 }; }

View File

@@ -0,0 +1,12 @@
// Module B authors a same-name `Box` shadow whose field SELF-REFERENCES its own
// name (`next: *Box`). Pre-fix the self-ref resolved to A's `Box` (registered
// first under the bare name), so `next.*.y` failed with "field 'y' not found on
// type 'Box'". The shadow's slot is now reserved BEFORE its fields resolve, so
// `*Box` binds to B's OWN nominal TypeId and the deref sees B's `y`.
Box :: struct { y: s64; next: *Box; }
b_chain :: () -> s64 {
tail := Box.{ y = 42, next = null };
head := Box.{ y = 1, next = @tail };
// Walk the self-referential link; reads B's own `y`, not A's `x`.
return head.next.*.y;
}

View File

@@ -0,0 +1,15 @@
// issue 0105 / F1 regression — FORWARD + MUTUAL refs between same-name struct
// shadows. Two flat-imported modules each declare `Box` and `Node`; module B's
// `Box` forward-refs B's `Node` (declared later) and B's `Node` back-refs B's
// `Box`. Every cross-reference must bind to B's OWN nominal identities, proving
// the up-front genuine-shadow reservation: ALL of a genuine shadow's authors are
// reserved in `type_decl_tids` before any field resolves, so a forward / mutual
// ref never falls back to the global findByName first-author (A's `Node`).
#import "modules/std.sx";
#import "0758-modules-same-name-struct-mutual-ref/a.sx";
#import "0758-modules-same-name-struct-mutual-ref/b.sx";
main :: () -> s32 {
print("b={}\n", b_test());
0
}

View File

@@ -0,0 +1,3 @@
// Module A authors its OWN `Box` and `Node` (the FIRST same-name authors).
Box :: struct { x: s64; }
Node :: struct { n: s64; }

View File

@@ -0,0 +1,13 @@
// Module B authors same-name `Box` and `Node` shadows that reference EACH OTHER.
// B's `Box` has a FORWARD ref to B's `Node` (declared after it), and B's `Node`
// back-refs B's `Box`. Both forward and mutual refs must resolve to B's OWN
// nominal TypeIds, not the first same-name authors in A.
Box :: struct { y: s64; peer: *Node; }
Node :: struct { m: s64; owner: *Box; }
b_test :: () -> s64 {
nd := Node.{ m = 99, owner = null };
bx := Box.{ y = 7, peer = @nd };
// Reads B's Node.m (99); pre-fix the forward ref bound to A's Node (which has
// field `n`, not `m`) → "field 'm' not found on type 'Node'".
return bx.peer.*.m;
}

View File

@@ -0,0 +1,22 @@
// A genuinely-undeclared type name used in an IMPORTED (non-main) module must
// emit a clean "unknown type" diagnostic, not silently compile.
//
// The `UnknownTypeChecker` only walks MAIN-file decls — imported / library
// modules are trusted and never checked. So an undeclared type name in an
// imported module used to fall through the type leaf's empty-struct stub and
// silently fabricate a 0-field struct: `make_thing()` below compiled and ran
// (printing `thing.x = 42`) even though `lib.sx` references the non-existent
// type `Coordnate`. The source-aware nominal leaf now poisons a genuinely-
// undeclared name with the `.unresolved` sentinel and emits the diagnostic at
// the reference, so the typo surfaces instead of mis-sizing `Thing` downstream.
//
// Expected: `error: unknown type 'Coordnate'` pointing into lib.sx; exit 1.
// Regression (stdlib E3).
#import "modules/std.sx";
#import "0759-modules-undeclared-type-in-import/lib.sx";
main :: () -> s32 {
print("thing.x = {}\n", make_thing());
return 0;
}

View File

@@ -0,0 +1,14 @@
// Flat-imported helper. `Coordnate` is a typo — no such type is declared
// anywhere. Because this module is imported (not the main file), the
// `UnknownTypeChecker` trusts it and never walks it, so the type leaf is the
// sole guard against the silently-fabricated empty-struct stub.
Thing :: struct {
x: s32;
y: Coordnate;
}
make_thing :: () -> s32 {
t : Thing = ---;
t.x = 42;
return t.x;
}

View File

@@ -0,0 +1,18 @@
// A generic struct's VALUE param (`$N: u32`) named in a TYPE position must emit
// a clean diagnostic even when the struct is declared in an IMPORTED module —
// not just the main file (examples/0172 covers the main-file case). Before the
// fix the imported template's field `x: N` resolved to the `.unresolved`
// sentinel and PANICKED at LLVM emission ("unresolved type reached LLVM
// emission"); the field type leaf now diagnoses the imported value-param misuse
// at the reference, the same way the main-file `UnknownTypeChecker` does.
//
// Expected: `error: 'N' is a value parameter, not a type` pointing into lib.sx;
// exit 1. Regression (stdlib E3).
#import "modules/std.sx";
#import "0760-modules-imported-generic-value-param-as-field-type/lib.sx";
main :: () -> s32 {
b : Bad(3) = .{ x = 1 };
print("{}\n", b.x);
return 0;
}

View File

@@ -0,0 +1,10 @@
// Flat-imported generic struct whose VALUE param `$N: u32` is named in a TYPE
// position (`x: N`). Because this module is imported (not the main file), the
// `UnknownTypeChecker` trusts it and never walks it — so the field type leaf is
// the sole guard. `instantiateGenericStruct` resolves the template's field nodes
// in THIS source context, so the leaf classifies the value-param misuse as
// imported and emits the tailored hint instead of poisoning the field with the
// `.unresolved` sentinel (which panicked at LLVM emission before the fix).
Bad :: struct($N: u32) {
x: N;
}

View File

@@ -0,0 +1,19 @@
// A genuinely-undeclared type in an IMPORTED GENERIC struct field must emit
// "unknown type" even when the struct is instantiated from the main file —
// 0759 only covered a non-generic imported struct instantiated in-module.
// Before the fix the generic template's fields resolved in the main-file
// instantiation context, so the leaf trusted them as main-file decls and
// silently stubbed `Missing` (the program compiled and printed `b.x`). The
// template's fields now resolve in the template's own source context, so the
// undeclared name surfaces.
//
// Expected: `error: unknown type 'Missing'` pointing into lib.sx; exit 1.
// Regression (stdlib E3).
#import "modules/std.sx";
#import "0761-modules-imported-generic-undeclared-field/lib.sx";
main :: () -> s32 {
b : Bad(s32) = .{ x = 1, y = 2 };
print("{}\n", b.x);
return 0;
}

View File

@@ -0,0 +1,12 @@
// Flat-imported generic struct with a genuinely-undeclared field type
// (`y: Missing`). 0759 covers a NON-generic imported struct; a generic one is
// instantiated cross-module, so before the fix its field nodes were resolved in
// the (main-file) instantiation context — the source-aware leaf saw "main",
// trusted it to the `UnknownTypeChecker` (which never walks imports), and
// silently fabricated a 0-field stub. `instantiateGenericStruct` now resolves
// the template's fields in THIS module's source context, so the undeclared name
// surfaces at the reference.
Bad :: struct($T: Type) {
x: T;
y: Missing;
}

View File

@@ -0,0 +1,25 @@
// An IMPORTED generic template's field that names a type the CALLER declared
// only as a BLOCK-LOCAL must NOT bind that caller-local type — a block-local is
// visible only within its OWN source. `lib.sx` defines
// `Bad :: struct($T) { x: T; y: LocalOnly; }`; `main` declares `LocalOnly` only
// inside its own body before instantiating `Bad(s32)`. The imported template's
// module cannot see a caller block-local, so `y: LocalOnly` is undeclared in the
// lib file.
//
// Before the fix the global `local_type_names` set was source-insensitive: the
// template's field resolution (run in the template's source context, E3
// attempt-4) consulted it, found the caller's `LocalOnly`, and silently compiled
// (printed a value, exit 0). `local_type_names` is now keyed by declaring source,
// so a cross-source block-local no longer leaks into another source's resolution.
//
// Expected: `error: unknown type 'LocalOnly'` pointing into lib.sx; exit 1.
// Regression (stdlib E3 attempt-5).
#import "modules/std.sx";
#import "0762-modules-imported-generic-caller-local-field-leak/lib.sx";
main :: () -> s32 {
LocalOnly :: struct { v: s32; }
b : Bad(s32) = .{ x = 1, y = .{ v = 9 } };
print("{} {}\n", b.x, b.y.v);
return 0;
}

View File

@@ -0,0 +1,9 @@
// Flat-imported generic struct whose field `y: LocalOnly` names a type that is
// declared only as a BLOCK-LOCAL in the CALLER (`main`). The template's fields
// resolve in THIS module's source context (E3 attempt-4), and a block-local type
// is visible only within its own source, so `LocalOnly` is genuinely undeclared
// here — the source-aware leaf surfaces it instead of binding the caller's local.
Bad :: struct($T: Type) {
x: T;
y: LocalOnly;
}

View File

@@ -0,0 +1,20 @@
// `#import` is non-transitive for TYPES, exactly like values/functions (0706):
// when A imports B and B imports C, A must NOT see C's top-level TYPE names.
// This file imports `b.sx` (which in turn imports `c.sx`) and then references
// C's type `COnly` directly — the compiler rejects it with a
// "type ... is not visible; #import the module that declares it" diagnostic.
//
// `b.sx` ↔ `c.sx` together still compile: `b_make`'s return type `COnly`
// resolves because b.sx directly imports c.sx.
//
// Regression (Phase E4): before the bare-TYPE gate went single-hop this
// 2-flat-hop type was wrongly visible (the interim transitive closure).
#import "modules/std.sx";
#import "0763-modules-import-type-non-transitive/b.sx";
main :: () -> s32 {
x : COnly = .{ v = 5 };
print("{}\n", x.v);
0
}

View File

@@ -0,0 +1,7 @@
#import "c.sx";
// b.sx directly imports c.sx, so it CAN name `COnly` — proving the type is
// only one flat hop away here, two hops away from a file that imports b.sx.
b_make :: () -> COnly {
.{ v = 99 }
}

View File

@@ -0,0 +1 @@
COnly :: struct { v: s64 = 0; }

View File

@@ -0,0 +1,24 @@
// `#import` is non-transitive for a PARAMETERIZED TYPE HEAD (a generic-struct
// constructor like `Box(s64)`), exactly like a bare leaf type (0763) and like
// values/functions (0706): when A imports B and B imports C, A must NOT see C's
// top-level generic type `Box`. This file imports `b.sx` (which imports `c.sx`)
// and instantiates C's generic `Box(s64)` directly — the compiler rejects the
// head with a "type ... is not visible; #import the module that declares it"
// diagnostic, BEFORE instantiating the template.
//
// `b.sx` ↔ `c.sx` together still compile: `b_make`'s `Box(s64)` resolves because
// b.sx directly imports c.sx (the head is one flat hop away there, two from a
// file that imports b.sx).
//
// Regression (Phase E4): before the bare-head gate went single-hop this 2-flat-
// hop generic head was wrongly visible — the head lookup hit the global
// `struct_template_map` before any source-aware visibility check.
#import "modules/std.sx";
#import "0764-modules-import-generic-head-non-transitive/b.sx";
main :: () -> s32 {
x : Box(s64) = .{ v = 3 };
print("{}\n", x.v);
0
}

View File

@@ -0,0 +1,8 @@
#import "c.sx";
// b.sx directly imports c.sx, so it CAN instantiate `Box(s64)` — proving the
// generic head is only one flat hop away here, two hops from a file that
// imports b.sx.
b_make :: () -> Box(s64) {
.{ v = 99 }
}

View File

@@ -0,0 +1 @@
Box :: struct($T: Type) { v: T; }

View File

@@ -0,0 +1,27 @@
// `#import` is non-transitive for a type named in a REFLECTION / type-arg slot
// (`size_of(T)`, `size_of(*T)`) and in a TYPED ARRAY-LITERAL annotation
// (`T.[...]`), exactly like a bare leaf annotation (0763), a parameterized head
// (0764), and values/functions (0706): when A imports B and B imports C, A must
// NOT see C's top-level types here either. This file imports `b.sx` (which
// imports `c.sx`) and references C's `Nums` / `COnly` in those positions — each
// is rejected with a "type ... is not visible; #import the module that declares
// it" diagnostic, BEFORE the global type table can resolve it.
//
// `b.sx` ↔ `c.sx` together still compile: `b_sizes` / `b_arr` resolve `Nums` /
// `COnly` because b.sx directly imports c.sx (one flat hop there, two from a
// file that imports b.sx).
//
// Regression (Phase E4): before the bare-TYPE gate reached the reflection
// type-arg and array-literal leaf sites, these 2-flat-hop references leaked
// through the global `type_alias_map` / `findByName` / `type_bridge` lookup.
#import "modules/std.sx";
#import "0765-modules-import-reflection-type-non-transitive/b.sx";
main :: () -> s32 {
print("{}\n", size_of(Nums));
print("{}\n", size_of(*COnly));
xs := Nums.[1, 2];
print("{} {}\n", xs[0], xs[1]);
0
}

View File

@@ -0,0 +1,13 @@
#import "c.sx";
// b.sx directly imports c.sx, so it CAN name these types in reflection /
// type-arg / array-literal positions — the type is one flat hop away here,
// two from a file that imports b.sx.
b_sizes :: () -> s64 {
size_of(Nums) + size_of(*COnly)
}
b_arr :: () -> s64 {
xs := Nums.[1, 2];
xs[0] + xs[1]
}

View File

@@ -0,0 +1,3 @@
Nums :: [2]s64;
COnly :: struct { v: s64 = 0; }

View File

@@ -0,0 +1,16 @@
// The pass side of 0765: a DIRECTLY imported module's types are bare-visible in
// reflection / type-arg slots (`size_of(Nums)`, `size_of(*COnly)`) and in a
// typed array-literal annotation (`Nums.[...]`) — single-hop visibility, so a
// 1-flat-hop type resolves exactly as before the E4 gate. Confirms the gate
// only rejects the 2-hop case (0765), never a directly-imported reference.
#import "modules/std.sx";
#import "0766-modules-reflection-type-direct-ok/c.sx";
main :: () -> s32 {
print("{}\n", size_of(Nums));
print("{}\n", size_of(*COnly));
xs := Nums.[1, 2];
print("{} {}\n", xs[0], xs[1]);
0
}

View File

@@ -0,0 +1,3 @@
Nums :: [2]s64;
COnly :: struct { v: s64 = 0; }

View File

@@ -0,0 +1,39 @@
// Bare-TYPE references are NON-transitive AND ambiguity-checked at every site,
// not just the nominal leaf annotation (0755). `main` flat-imports two modules
// that each author a same-name `Thing` / `Box` / `Nums` and authors none itself,
// so EACH of the following bare forms is a genuine collision the source cannot
// disambiguate — and each must emit the LOUD "type ... is ambiguous" diagnostic
// (consistent with the leaf, 0755) and poison the result, NEVER silently pick a
// global `findByName` / `struct_template_map` author:
//
// - reflection / type-arg slot `size_of(Thing)`
// - typed array/vector-literal `Nums.[1, 2]`
// - parameterized generic head `Box(s64)`
// - type-as-value `t : Type = Thing`
// - type-category match arm `case Thing:`
//
// Regression (Phase E4 attempt-5): before the bare-type gate carried the full
// source-aware author outcome, these non-leaf sites used a boolean leak-check
// that dropped the AMBIGUOUS outcome — two direct flat same-name authors fell
// through to a global pick (exit 0 / cascade) instead of the loud diagnostic.
#import "modules/std.sx";
#import "0767-modules-ambiguous-bare-type-forms/a.sx";
#import "0767-modules-ambiguous-bare-type-forms/b.sx";
describe :: ($T: Type) -> s32 {
r := if T == {
case Thing: 1;
else: 0;
}
r
}
main :: () -> s32 {
sz := size_of(Thing);
xs := Nums.[1, 2];
x : Box(s64) = .{ v = 3 };
t : Type = Thing;
d := describe(s64);
0
}

View File

@@ -0,0 +1,6 @@
// One of two flat-imported authors of same-name types `Thing` / `Box` / `Nums`.
// With both modules flat-visible from a file that authors none itself, every
// bare reference to these names is genuinely ambiguous.
Thing :: struct { a: s64; }
Box :: struct($T: Type) { v: T; }
Nums :: [2]s64;

View File

@@ -0,0 +1,7 @@
// The second flat-imported author of same-name `Thing` / `Box` / `Nums`. The
// distinct shapes (`Thing` a separate nominal identity, `Box` a separate generic
// template, `Nums` aliased to a different element width) make each bare
// reference a real collision the importing source cannot disambiguate.
Thing :: struct { a: s64; }
Box :: struct($T: Type) { v: T; }
Nums :: [2]s32;

View File

@@ -0,0 +1,44 @@
// Own-wins (0754 / issue 0105 case 3) holds at EVERY non-leaf bare-type site,
// not just the nominal leaf annotation. `main` flat-imports `dep.sx` (which
// authors a same-name `Widget { a, b }` = 16 bytes and `Nums :: [2]s32` = 8
// bytes) AND authors its OWN `Widget { a }` = 8 bytes and `Nums :: [2]s64` = 16
// bytes. Each bare reference below must resolve to MAIN's own author — the gate's
// source-keyed `.resolved` author — NOT whichever same-name flat import a global
// `findByName` / `struct_template_map` pick would return:
//
// - reflection / type-arg slot `size_of(Widget)` → 8 (own)
// - typed array-literal head `Nums.[…]` / size_of → 16 (own [2]s64)
// - type-as-value `t : Type = Widget`
// - type-category match arm `case Widget:` → own identity
//
// Regression (Phase E4 attempt-6, finding #1): before the bare-type gate carried
// the OWN author's source-keyed TypeId into the non-leaf sites, an own author
// produced `.proceed` and these sites fell through to a global `findByName` — so
// `size_of(Widget)` printed the IMPORTED type's 16 and `case Widget:` matched the
// imported nominal identity (describe → 222). `dep_sizes` proves dep's distinct
// types still resolve to THEIR own 16 + 8 = 24 inside dep.
#import "modules/std.sx";
#import "0768-modules-own-wins-nonleaf-bare-type/dep.sx";
Widget :: struct { a: s64; }
Nums :: [2]s64;
describe :: ($T: Type) -> s32 {
r := if T == {
case Widget: 111;
else: 222;
}
r
}
main :: () -> s32 {
print("reflection={}\n", size_of(Widget));
xs := Nums.[1, 2];
print("array={}\n", size_of(Nums));
t : Type = Widget;
print("typeval_eq={}\n", t == Widget);
print("match={}\n", describe(Widget));
print("dep={}\n", dep_sizes());
0
}

View File

@@ -0,0 +1,8 @@
// A flat-imported module authors its OWN `Widget { a, b }` (16 bytes) and
// `Nums :: [2]s32` (8 bytes). The importing file (`main`) ALSO authors a
// same-name `Widget { a }` (8 bytes) and `Nums :: [2]s64` (16 bytes) — its own
// authors must win at EVERY bare-type site there (own-wins, 0754), while this
// module's distinct types stay live via `dep_sizes`.
Widget :: struct { a: s64; b: s64; }
Nums :: [2]s32;
dep_sizes :: () -> s64 { return size_of(Widget) + size_of(Nums); }

View File

@@ -0,0 +1,21 @@
// A type-returning FUNCTION head (`Make(s64)` where `Make :: ($T) -> Type`) is
// NON-transitive AND ambiguity-checked, exactly like the parameterized generic-
// struct / protocol heads (0767) and the nominal leaf (0755). `main` flat-imports
// two modules that each author a same-name `Make` type-fn with a different body
// and authors none itself, so the bare `Make(s64)` head is a genuine collision —
// it must emit the LOUD "type 'Make' is ambiguous" diagnostic and poison, NEVER
// silently instantiate whichever single author `fn_ast_map` happens to hold.
//
// Regression (Phase E4 attempt-6, finding #2): before `headFnLeak` did bare-call
// ambiguity selection it only checked `isNameVisible` (both authors ARE visible),
// so two flat `Make` type-fns silently instantiated one author — `size_of(Make(s64))`
// printed 16 (a.sx's two-field body) at exit 0 instead of the ambiguity diagnostic.
#import "modules/std.sx";
#import "0769-modules-ambiguous-type-fn-head/a.sx";
#import "0769-modules-ambiguous-type-fn-head/b.sx";
main :: () -> s32 {
print("size={}\n", size_of(Make(s64)));
0
}

View File

@@ -0,0 +1,7 @@
// One of two flat-imported authors of a same-name type-returning function
// `Make :: ($T) -> Type`. Its body returns a two-field struct; b.sx's returns a
// one-field struct, so a bare `Make(s64)` head is a genuine collision the
// importing source cannot disambiguate.
Make :: ($T: Type) -> Type {
return struct { x: T; y: T; };
}

View File

@@ -0,0 +1,5 @@
// The second flat-imported author of same-name type-fn `Make`. Its distinct
// one-field body makes a bare `Make(s64)` head ambiguous against a.sx's.
Make :: ($T: Type) -> Type {
return struct { x: T; };
}

View File

@@ -0,0 +1,23 @@
// A type-returning FUNCTION head (`Make(s64)` where `Make :: ($T) -> Type`) is
// NON-transitive even when a DIRECT flat import authors the same name as a
// NON-function. `main` flat-imports `b.sx`; `b.sx` declares `Make :: 123` (a
// value const, not a type-fn) AND flat-imports `c.sx`, whose `Make` IS the
// type-returning function. The only TYPE-FN author of `Make` is two flat hops
// away (main → b → c), so the bare `Make(s64)` head must emit the
// "type 'Make' is not visible" diagnostic and poison — the visible 1-hop
// `Make :: 123` const must NOT vouch for it.
//
// Regression (Phase E4 attempt-7, finding E4-type-fn-head-hidden-by-visible-
// nonfn): before `headFnLeak` decided visibility from the ELIGIBLE FUNCTION
// authors it used the module-scope NAME predicate (`isNameVisible`), which the
// visible non-fn `Make :: 123` satisfied — so the global `fn_ast_map` type-fn
// silently instantiated and `size_of(Make(s64))` printed 8 at exit 0 instead of
// the visibility diagnostic.
#import "modules/std.sx";
#import "0770-modules-type-fn-head-non-transitive/b.sx";
main :: () -> s32 {
print("size={}\n", size_of(Make(s64)));
0
}

Some files were not shown because too many files have changed in this diff Show More