P5.7 Step C2a: fold inline comptime calls on the VM (ops.zig)
The emitCall inline comptime-call fold (zero-arg comptime callee -> constant) was the last backend use of the legacy Interpreter. Route it through comptime_vm.tryEval; a bail falls through to the normal call path. Drop the interp_mod/Interpreter imports from ops.zig. 500/500 unit + 706/0 corpus.
This commit is contained in:
@@ -4,10 +4,9 @@ const c = llvm.c;
|
||||
const emit = @import("../../ir/emit_llvm.zig");
|
||||
const ir_inst = @import("../../ir/inst.zig");
|
||||
const ir_types = @import("../../ir/types.zig");
|
||||
const interp_mod = @import("../../ir/interp.zig");
|
||||
const comptime_vm = @import("../../ir/comptime_vm.zig");
|
||||
|
||||
const LLVMEmitter = emit.LLVMEmitter;
|
||||
const Interpreter = interp_mod.Interpreter;
|
||||
const Inst = ir_inst.Inst;
|
||||
const BinOp = ir_inst.BinOp;
|
||||
const UnaryOp = ir_inst.UnaryOp;
|
||||
@@ -1138,11 +1137,10 @@ pub const Ops = struct {
|
||||
}
|
||||
|
||||
if (callee_func.is_comptime and call_op.args.len == 0) {
|
||||
var interp_inst = Interpreter.init(self.e.ir_mod, self.e.alloc);
|
||||
interp_inst.build_config = &self.e.build_config;
|
||||
if (self.e.import_sources) |sm| interp_inst.setSourceMap(sm);
|
||||
defer interp_inst.deinit();
|
||||
if (interp_inst.call(call_op.callee, &.{})) |result| {
|
||||
// Inline comptime-call fold: evaluate the zero-arg comptime callee on
|
||||
// the VM (the sole evaluator) and splat its scalar/string result as a
|
||||
// constant. A bail (null) falls through to the normal call path.
|
||||
if (comptime_vm.tryEval(self.e.alloc, self.e.ir_mod, call_op.callee, &self.e.build_config, self.e.import_sources)) |result| {
|
||||
if (result.asInt()) |v| {
|
||||
self.e.mapRef(c.LLVMConstInt(self.e.toLLVMType(instruction.ty), @bitCast(v), 0));
|
||||
return;
|
||||
@@ -1156,7 +1154,7 @@ pub const Ops = struct {
|
||||
self.e.mapRef(self.e.emitStringConstant(result.string));
|
||||
return;
|
||||
}
|
||||
} else |_| {}
|
||||
}
|
||||
}
|
||||
const callee = self.e.func_map.get(call_op.callee.index()) orelse {
|
||||
self.e.mapRef(c.LLVMGetUndef(self.e.toLLVMType(instruction.ty)));
|
||||
|
||||
Reference in New Issue
Block a user