P5.7 Step C2b: drop the Interpreter materialization context from emit_llvm

valueToLLVMConst / serializeAggregateValue took a *const Interpreter only to
resolve .heap_ptr data fields via interp.heapSlice — but the VM's regToValue
never produces .heap_ptr (it's interp-internal). Drop the param, remove the
dead interp_inst in emitGlobals, and drop the .heap_ptr fat-pointer data arm
(falls through to the loud bail). Remove the now-unused Interpreter alias.

500/500 unit + 706/0 corpus.
This commit is contained in:
agra
2026-06-19 19:52:44 +03:00
parent cd8608c10c
commit 103a156b26

View File

@@ -30,7 +30,6 @@ const Global = ir_inst.Global;
const ir_module = @import("module.zig"); const ir_module = @import("module.zig");
const Module = ir_module.Module; const Module = ir_module.Module;
const interp_mod = @import("interp.zig"); const interp_mod = @import("interp.zig");
const Interpreter = interp_mod.Interpreter;
const Value = interp_mod.Value; const Value = interp_mod.Value;
const comptime_vm = @import("comptime_vm.zig"); const comptime_vm = @import("comptime_vm.zig");
const build_opts = @import("build_opts"); const build_opts = @import("build_opts");
@@ -933,12 +932,7 @@ pub const LLVMEmitter = struct {
if (global.comptime_func) |func_id| { if (global.comptime_func) |func_id| {
// The comptime VM is the SOLE evaluator (P5.7) — no legacy // The comptime VM is the SOLE evaluator (P5.7) — no legacy
// fallback. A bail is ALWAYS a build-gating error naming the // fallback. A bail is ALWAYS a build-gating error naming the
// reason. `interp_inst` is a fresh helper context that // reason; its result Value is materialized by `valueToLLVMConst`.
// `valueToLLVMConst` uses to materialize the VM's result Value
// (strings / aggregates) — it does NOT evaluate anything.
var interp_inst = Interpreter.init(self.ir_mod, self.alloc);
interp_inst.build_config = &self.build_config;
if (self.import_sources) |sm| interp_inst.setSourceMap(sm);
sx_trace_clear(); sx_trace_clear();
const result = comptime_vm.tryEval(self.alloc, self.ir_mod, func_id, &self.build_config, self.import_sources) orelse { const result = comptime_vm.tryEval(self.alloc, self.ir_mod, func_id, &self.build_config, self.import_sources) orelse {
// Surface the bail loudly instead of silently filling the // Surface the bail loudly instead of silently filling the
@@ -966,7 +960,7 @@ pub const LLVMEmitter = struct {
continue; continue;
} }
} }
const init_val = self.valueToLLVMConst(init_value, global.ty, &interp_inst, self.ir_mod.types.getString(global.name)); const init_val = self.valueToLLVMConst(init_value, global.ty, self.ir_mod.types.getString(global.name));
c.LLVMSetInitializer(llvm_global, init_val); c.LLVMSetInitializer(llvm_global, init_val);
} else if (global.init_val) |iv| { } else if (global.init_val) |iv| {
const init_val = switch (iv) { const init_val = switch (iv) {
@@ -1091,7 +1085,6 @@ pub const LLVMEmitter = struct {
self: *LLVMEmitter, self: *LLVMEmitter,
val: Value, val: Value,
ty: TypeId, ty: TypeId,
interp: *const Interpreter,
global_name: []const u8, global_name: []const u8,
) c.LLVMValueRef { ) c.LLVMValueRef {
const llvm_ty = self.toLLVMType(ty); const llvm_ty = self.toLLVMType(ty);
@@ -1132,7 +1125,7 @@ pub const LLVMEmitter = struct {
break :blk self.failGlobalInit(llvm_ty); break :blk self.failGlobalInit(llvm_ty);
}, },
.string => |s| self.emitConstStringGlobal(s), .string => |s| self.emitConstStringGlobal(s),
.aggregate => |fields| self.serializeAggregateValue(fields, ty, interp, global_name), .aggregate => |fields| self.serializeAggregateValue(fields, ty, global_name),
// The remaining Value variants cannot become static binary // The remaining Value variants cannot become static binary
// constants outside of a fat-pointer aggregate. Bail loudly. // constants outside of a fat-pointer aggregate. Bail loudly.
// (`heap_ptr` / `byte_ptr` / `int → ptr` are handled inside // (`heap_ptr` / `byte_ptr` / `int → ptr` are handled inside
@@ -1164,7 +1157,6 @@ pub const LLVMEmitter = struct {
self: *LLVMEmitter, self: *LLVMEmitter,
fields: []const Value, fields: []const Value,
ty: TypeId, ty: TypeId,
interp: *const Interpreter,
global_name: []const u8, global_name: []const u8,
) c.LLVMValueRef { ) c.LLVMValueRef {
const llvm_ty = self.toLLVMType(ty); const llvm_ty = self.toLLVMType(ty);
@@ -1185,10 +1177,6 @@ pub const LLVMEmitter = struct {
const len: usize = @intCast(len_i); const len: usize = @intCast(len_i);
const bytes_opt: ?[]const u8 = switch (data) { const bytes_opt: ?[]const u8 = switch (data) {
.heap_ptr => |hp| blk: {
const mem = interp.heapSlice(hp) orelse break :blk null;
break :blk if (len <= mem.len) mem[0..len] else null;
},
.byte_ptr => |addr| readHostBytes(addr, len), .byte_ptr => |addr| readHostBytes(addr, len),
.int => |v| blk: { .int => |v| blk: {
if (v == 0 and len == 0) break :blk &.{}; // empty slice if (v == 0 and len == 0) break :blk &.{}; // empty slice
@@ -1225,7 +1213,7 @@ pub const LLVMEmitter = struct {
var field_vals = std.ArrayList(c.LLVMValueRef).empty; var field_vals = std.ArrayList(c.LLVMValueRef).empty;
defer field_vals.deinit(self.alloc); defer field_vals.deinit(self.alloc);
for (ir_fields, fields) |ir_field, fv| { for (ir_fields, fields) |ir_field, fv| {
field_vals.append(self.alloc, self.valueToLLVMConst(fv, ir_field.ty, interp, global_name)) catch unreachable; field_vals.append(self.alloc, self.valueToLLVMConst(fv, ir_field.ty, global_name)) catch unreachable;
} }
return c.LLVMConstNamedStruct(llvm_ty, field_vals.items.ptr, @intCast(field_vals.items.len)); return c.LLVMConstNamedStruct(llvm_ty, field_vals.items.ptr, @intCast(field_vals.items.len));
} }
@@ -1235,7 +1223,7 @@ pub const LLVMEmitter = struct {
var elem_vals = std.ArrayList(c.LLVMValueRef).empty; var elem_vals = std.ArrayList(c.LLVMValueRef).empty;
defer elem_vals.deinit(self.alloc); defer elem_vals.deinit(self.alloc);
for (fields) |fv| { for (fields) |fv| {
elem_vals.append(self.alloc, self.valueToLLVMConst(fv, elem_ty, interp, global_name)) catch unreachable; elem_vals.append(self.alloc, self.valueToLLVMConst(fv, elem_ty, global_name)) catch unreachable;
} }
return c.LLVMConstArray2(llvm_elem_ty, elem_vals.items.ptr, @intCast(elem_vals.items.len)); return c.LLVMConstArray2(llvm_elem_ty, elem_vals.items.ptr, @intCast(elem_vals.items.len));
} }