1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//! Wasm-gc backend-link view — the resolved-HIR slice the rest of
//! this backend reads.
//!
//! ## Why this exists as a named view, not a transitional hack
//!
//! The pipeline (`parse → tco → typecheck → resolve → CodegenContext`)
//! is module-aware: `CodegenContext.resolved_fn_defs` holds the
//! entry's fns and `resolved_module_fn_defs` holds each dep's fns
//! separately, both keyed against the pre-flatten `SymbolTable`.
//! That structure is correct for backends that emit per-module
//! artifacts (Rust → one Rust crate per Aver module, VM → per-
//! module bytecode, Lean → namespaces, Dafny → modules).
//!
//! The wasm-gc backend emits a single .wasm file by design — that's
//! a *linking* decision, not a semantic one. The pipeline shouldn't
//! know about it. So this backend runs its own legal link stage:
//! [`flatten_multimodule`] (in `crate::codegen::wasm_gc::flatten`)
//! merges dep fns into the entry's items with module-prefixed names
//! (`Fractal.render` → `Fractal_render`), then this view runs a
//! fresh resolver pass against the flattened items.
//!
//! Calling this a "link" stage names what it actually is: the
//! backend collapses N modules into 1 emit unit, and identity
//! lookups in the post-link world use [`WasmGcLinkedView`] as the
//! canonical resolver substrate. Mirrors how a native linker has
//! its own symbol view distinct from the per-translation-unit views
//! the compiler produced.
//!
//! ## Invariant
//!
//! - **Input:** post-typecheck, post-resolve, post-flatten items
//! slice. Every reachable `FnDef` has been monomorphised and
//! prefixed.
//! - **Output:** [`WasmGcLinkedView`] holding the flattened-scope
//! [`SymbolTable`] plus one [`ResolvedFnDef`] per source `FnDef`,
//! indexable by stable [`FnId`].
//!
//! ## Why FnId lookup, not bare name
//!
//! Pre-PR-9.3a the codegen `CodegenContext::resolve_fn_def` flat-
//! searched resolved tables by `rfd.name == fd.name`. Post-flatten
//! that happens to work in wasm-gc because every name is prefixed.
//! [`fn_def_by_id`] keys by `FnId` instead so the pattern doesn't
//! depend on flatten's name-uniqueness side effect — the link stage
//! still rewrites names, but the identity layer stays robust.
//!
//! [`flatten_multimodule`]: super::flatten::flatten_multimodule
//! [`SymbolTable`]: crate::ir::SymbolTable
//! [`ResolvedFnDef`]: crate::ir::hir::ResolvedFnDef
//! [`FnId`]: crate::ir::FnId
use HashMap;
use crate;
use crateFnId;
use crateSymbolTable;
use crate;
use WasmGcError;
/// Resolved-HIR view of the wasm-gc backend's post-link compile
/// unit. See module doc for the invariant.
pub