refactor(ir): extract ExprTyper for non-call expression typing (A3.1)
Move the structural / non-call arms of Lowering.inferExprType into a new src/ir/expr_typer.zig (ExprTyper): literals, unary/binary ops, try/catch, if, block, field access, identifier/type-name, struct/tuple literals, index/slice/deref, null-coalesce, caller_location, and the no-value statement shapes. ExprTyper is a *Lowering facade (Principle 5, same as PackResolver) — expression typing reads live lexical-scope / pack / target-type state and ~14 resolver helpers, so it borrows *Lowering rather than re-threading every field; the plan's TypeResolver/ProgramIndex/ResolveEnv ideal is the later-phase target as that state lifts into an explicit context (documented in the module doc). Lowering.inferExprType is now a 2-arm dispatcher: `.call => inferCallType(c)` (call result typing stays in Lowering until A3.2), else delegates to ExprTyper.inferType. The call arm body moved verbatim into the new Lowering.inferCallType (the by-value `|c|` capture became a `*const ast.Call` param; the lone `&c` -> `c`). 14 Lowering helper methods consumed by the facade were widened to pub (orIsFailableChain, orChainSuccessType, errorChannelOf, failableSuccessType, isObjcClassPointer, lookupObjcPropertyOnPointer, lookupObjcDefinedStateFieldOnPointer, getElementType, optionalOfFlattened, getStructFields, isKnownTypeName, comptimeIndexOf, packArgNodeAt, resolveType) plus Scope.lookup — the same pub-for-facade step PackResolver took. Fields need no change (Zig fields are always cross-file accessible). expr_typer.test.zig adds focused unit tests (literal shapes, comparison vs arithmetic, unary not/negate, deref of non-pointer) for the scope-free structural arms. Barrel-wired in ir.zig. Behavior-preserving. Gate: zig build, zig build test (incl. new ExprTyper tests), bash tests/run_examples.sh -> 356/0. lower.zig ~18774 -> 18598.
This commit is contained in:
@@ -7,6 +7,7 @@ pub const lower = @import("lower.zig");
|
||||
pub const program_index = @import("program_index.zig");
|
||||
pub const type_resolver = @import("type_resolver.zig");
|
||||
pub const packs = @import("packs.zig");
|
||||
pub const expr_typer = @import("expr_typer.zig");
|
||||
pub const semantic_diagnostics = @import("semantic_diagnostics.zig");
|
||||
|
||||
pub const TypeId = types.TypeId;
|
||||
@@ -38,6 +39,7 @@ pub const ProgramIndex = program_index.ProgramIndex;
|
||||
pub const TypeResolver = type_resolver.TypeResolver;
|
||||
pub const ResolveEnv = type_resolver.ResolveEnv;
|
||||
pub const PackResolver = packs.PackResolver;
|
||||
pub const ExprTyper = expr_typer.ExprTyper;
|
||||
|
||||
pub const compiler_hooks = @import("compiler_hooks.zig");
|
||||
pub const emit_llvm = @import("emit_llvm.zig");
|
||||
@@ -59,6 +61,7 @@ pub const lower_tests = @import("lower.test.zig");
|
||||
pub const program_index_tests = @import("program_index.test.zig");
|
||||
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 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