diff --git a/src/backend/llvm/ops.zig b/src/backend/llvm/ops.zig index 1c5fc7cf..46947e77 100644 --- a/src/backend/llvm/ops.zig +++ b/src/backend/llvm/ops.zig @@ -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)));