refactor(ir): extract GenericResolver (generics.zig) for substitution + mono keys (A4.1 step 2)
Generic substitution and monomorphization-key construction now live in one module, src/ir/generics.zig, behind a *Lowering facade (GenericResolver), mirroring CallResolver / ExprTyper. Moved verbatim: - mangleTypeName + mangleParamList (the mono-key fragment builder), - mangleGenericName (generic mono key), appendComptimeValueMangle (comptime-value fragment), - buildTypeBindings (call-site type-param inference), inferGenericReturnType (generic return resolution). inferGenericReturnType now uses a scoped TypeBindingScope (enter/exit with defer) instead of a manual type_bindings save/restore — the PLAN-ARCH A4.1 "scoped substitution env" shape; a generics.test.zig assertion confirms the prior bindings are restored (the issue-0048/0050 leak class, for this field). Lowering keeps a thin pub mangleTypeName wrapper delegating to genericResolver().mangleTypeName, because ~30 cross-cutting callers (impl-map keys, conversion keys, shape keys) reach it well beyond generics. mangleParamList (sole caller was mangleTypeName) moved fully. The other 4 originals are deleted (no fallback); their 6 call sites now go through self.genericResolver() (calls.zig via self.l.genericResolver()). matchTypeParam / extractTypeParam / isTypeParamDecl widened to pub (the moved substitution logic calls them); genericResolver() accessor added. The 2 mangleTypeName / inferGenericReturnType unit tests moved from lower.test.zig to generics.test.zig (driving GenericResolver directly) and wired into the barrel. monomorphizeFunction / monomorphizePackFn intentionally stay in lower.zig (they save/restore three fields across nested mono and call emission helpers) — a heavier scoped-env adoption deferred to an optional sub-step 3. zig build, zig build test, and tests/run_examples.sh (357/0) all green — no .ir snapshot churn, confirming the move preserved mono-key/substitution output.
This commit is contained in:
@@ -153,7 +153,7 @@ pub const CallResolver = struct {
|
||||
if (fd.type_params.len > 0) {
|
||||
return .{
|
||||
.kind = .generic_fn,
|
||||
.return_type = self.l.inferGenericReturnType(fd, c),
|
||||
.return_type = self.l.genericResolver().inferGenericReturnType(fd, c),
|
||||
.target = .{ .named = name },
|
||||
.expands_defaults = defaultsFor(fd, c.args.len),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user