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:
@@ -9,6 +9,7 @@ pub const type_resolver = @import("type_resolver.zig");
|
||||
pub const packs = @import("packs.zig");
|
||||
pub const expr_typer = @import("expr_typer.zig");
|
||||
pub const calls = @import("calls.zig");
|
||||
pub const generics = @import("generics.zig");
|
||||
pub const semantic_diagnostics = @import("semantic_diagnostics.zig");
|
||||
|
||||
pub const TypeId = types.TypeId;
|
||||
@@ -43,6 +44,7 @@ pub const PackResolver = packs.PackResolver;
|
||||
pub const ExprTyper = expr_typer.ExprTyper;
|
||||
pub const CallResolver = calls.CallResolver;
|
||||
pub const CallPlan = calls.CallPlan;
|
||||
pub const GenericResolver = generics.GenericResolver;
|
||||
|
||||
pub const compiler_hooks = @import("compiler_hooks.zig");
|
||||
pub const emit_llvm = @import("emit_llvm.zig");
|
||||
@@ -66,6 +68,7 @@ pub const type_resolver_tests = @import("type_resolver.test.zig");
|
||||
pub const packs_tests = @import("packs.test.zig");
|
||||
pub const expr_typer_tests = @import("expr_typer.test.zig");
|
||||
pub const calls_tests = @import("calls.test.zig");
|
||||
pub const generics_tests = @import("generics.test.zig");
|
||||
pub const type_bridge_tests = @import("type_bridge.test.zig");
|
||||
pub const emit_llvm_tests = @import("emit_llvm.test.zig");
|
||||
pub const jni_descriptor_tests = @import("jni_descriptor.test.zig");
|
||||
|
||||
Reference in New Issue
Block a user