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).
This commit is contained in:
agra
2026-06-09 11:25:04 +03:00
parent 864a14e42b
commit 8058be2538
5 changed files with 348 additions and 1 deletions

View File

@@ -15487,6 +15487,17 @@ pub const Lowering = struct {
const tmpl = self.buildGenericStructTemplate(sd, source_file) orelse return;
self.program_index.struct_template_map.put(tmpl.name, tmpl) catch {};
// S1.1 (additive): key the template by DeclId in parallel. Nothing
// reads this for selection yet; `struct_template_map` stays the live
// consumer. A template whose decl is not in the table (comptime /
// block-local registration with facts unwired) keeps only the
// name-keyed entry.
if (self.program_index.decl_table) |dt| {
if (dt.declIdForStructDecl(sd)) |id| {
self.program_index.struct_template_by_decl.put(id, tmpl) catch {};
}
}
// Register methods under "TemplateName.method" in fn_ast_map
for (sd.methods) |method_node| {
if (method_node.data == .fn_decl) {