Skip to content

Commit b680e41

Browse files
committed
Merge remote-tracking branch 'origin/main' into omit-inline-debug-effects
# Conflicts: # src/eval/compile_time_finalization.zig # src/postcheck/lambda_mono/lower.zig
2 parents e942aa1 + 34d8a6e commit b680e41

50 files changed

Lines changed: 1525 additions & 241 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/backend/dev/LirCodeGen.zig

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5428,7 +5428,8 @@ pub fn LirCodeGen(comptime target: RocTarget) type {
54285428
try locals.put(localKey(expect_stmt.condition), expect_stmt.condition);
54295429
try stack.append(sa, expect_stmt.next);
54305430
},
5431-
.runtime_error => {},
5431+
.comptime_branch_taken => |marker| try stack.append(sa, marker.next),
5432+
.runtime_error, .comptime_exhaustiveness_failed => {},
54325433
.incref => |inc| {
54335434
try locals.put(localKey(inc.value), inc.value);
54345435
try stack.append(sa, inc.next);
@@ -5549,7 +5550,8 @@ pub fn LirCodeGen(comptime target: RocTarget) type {
55495550
try locals.put(localKey(expect_stmt.condition), expect_stmt.condition);
55505551
try stack.append(sa, expect_stmt.next);
55515552
},
5552-
.runtime_error => {},
5553+
.comptime_branch_taken => |marker| try stack.append(sa, marker.next),
5554+
.runtime_error, .comptime_exhaustiveness_failed => {},
55535555
.incref => |inc| {
55545556
try locals.put(localKey(inc.value), inc.value);
55555557
try stack.append(sa, inc.next);
@@ -14048,6 +14050,15 @@ pub fn LirCodeGen(comptime target: RocTarget) type {
1404814050
try self.emitTrap();
1404914051
},
1405014052

14053+
.comptime_exhaustiveness_failed => {
14054+
try self.emitRocCrash("compile-time exhaustiveness failure reached runtime code");
14055+
try self.emitTrap();
14056+
},
14057+
14058+
.comptime_branch_taken => |marker| {
14059+
try work.append(wa, .{ .node = marker.next });
14060+
},
14061+
1405114062
.join => |j| {
1405214063
const jp_key = @intFromEnum(j.id);
1405314064
try self.setupJoinPointParams(j.id, j.params);

src/backend/llvm/Builder.zig

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6111,7 +6111,7 @@ pub const WipFunction = struct {
61116111
args: []const Value,
61126112
name: []const u8,
61136113
) Allocator.Error!Value {
6114-
return self.callInner(kind, call_conv, function_attributes, ty, callee, args, name, false);
6114+
return self.callInner(kind, call_conv, function_attributes, ty, callee, args, name, false, false);
61156115
}
61166116

61176117
fn callInner(
@@ -6124,6 +6124,7 @@ pub const WipFunction = struct {
61246124
args: []const Value,
61256125
name: []const u8,
61266126
has_op_bundle_cold: bool,
6127+
force_debug_location: bool,
61276128
) Allocator.Error!Value {
61286129
const ret_ty = ty.functionReturn(self.builder);
61296130
assert(ty.isFunction(self.builder));
@@ -6132,31 +6133,35 @@ pub const WipFunction = struct {
61326133
for (params, args[0..params.len]) |param, arg_val| assert(param == arg_val.typeOfWip(self));
61336134

61346135
try self.ensureUnusedExtraCapacity(1, Instruction.Call, args.len);
6135-
const instruction = try self.addInst(switch (ret_ty) {
6136-
.void => null,
6137-
else => name,
6138-
}, .{
6139-
.tag = switch (kind) {
6140-
.normal => .call,
6141-
.fast => .@"call fast",
6142-
.musttail => .@"musttail call",
6143-
.musttail_fast => .@"musttail call fast",
6144-
.notail => .@"notail call",
6145-
.notail_fast => .@"notail call fast",
6146-
.tail => .@"tail call",
6147-
.tail_fast => .@"tail call fast",
6148-
},
6149-
.data = self.addExtraAssumeCapacity(Instruction.Call{
6150-
.info = .{
6151-
.call_conv = call_conv,
6152-
.has_op_bundle_cold = has_op_bundle_cold,
6136+
const instruction = try self.addInstInner(
6137+
switch (ret_ty) {
6138+
.void => null,
6139+
else => name,
6140+
},
6141+
.{
6142+
.tag = switch (kind) {
6143+
.normal => .call,
6144+
.fast => .@"call fast",
6145+
.musttail => .@"musttail call",
6146+
.musttail_fast => .@"musttail call fast",
6147+
.notail => .@"notail call",
6148+
.notail_fast => .@"notail call fast",
6149+
.tail => .@"tail call",
6150+
.tail_fast => .@"tail call fast",
61536151
},
6154-
.attributes = function_attributes,
6155-
.ty = ty,
6156-
.callee = callee,
6157-
.args_len = @intCast(args.len),
6158-
}),
6159-
});
6152+
.data = self.addExtraAssumeCapacity(Instruction.Call{
6153+
.info = .{
6154+
.call_conv = call_conv,
6155+
.has_op_bundle_cold = has_op_bundle_cold,
6156+
},
6157+
.attributes = function_attributes,
6158+
.ty = ty,
6159+
.callee = callee,
6160+
.args_len = @intCast(args.len),
6161+
}),
6162+
},
6163+
force_debug_location,
6164+
);
61606165
self.extra.appendSliceAssumeCapacity(@ptrCast(args));
61616166
return instruction.toValue();
61626167
}
@@ -6185,14 +6190,19 @@ pub const WipFunction = struct {
61856190
name: []const u8,
61866191
) Allocator.Error!Value {
61876192
const intrinsic = try self.builder.getIntrinsic(id, overload);
6188-
return self.call(
6193+
return self.callInner(
61896194
fast.toCallKind(),
61906195
CallConv.default,
61916196
function_attributes,
61926197
intrinsic.typeOf(self.builder),
61936198
intrinsic.toValue(self.builder),
61946199
args,
61956200
name,
6201+
false,
6202+
switch (id) {
6203+
.@"dbg.declare", .@"dbg.value" => self.debug_location != .no_location,
6204+
else => false,
6205+
},
61966206
);
61976207
}
61986208

@@ -6207,6 +6217,7 @@ pub const WipFunction = struct {
62076217
&.{try self.builder.intValue(.i1, 1)},
62086218
"",
62096219
true,
6220+
false,
62106221
);
62116222
}
62126223

@@ -6990,6 +7001,15 @@ pub const WipFunction = struct {
69907001
self: *WipFunction,
69917002
name: ?[]const u8,
69927003
instruction: Instruction,
7004+
) Allocator.Error!Instruction.Index {
7005+
return self.addInstInner(name, instruction, false);
7006+
}
7007+
7008+
fn addInstInner(
7009+
self: *WipFunction,
7010+
name: ?[]const u8,
7011+
instruction: Instruction,
7012+
force_debug_location: bool,
69937013
) Allocator.Error!Instruction.Index {
69947014
const block_instructions = &self.cursor.block.ptr(self).instructions;
69957015
try self.instructions.ensureUnusedCapacity(self.builder.gpa, 1);
@@ -7007,7 +7027,8 @@ pub const WipFunction = struct {
70077027
self.instructions.appendAssumeCapacity(instruction);
70087028
if (!self.strip) {
70097029
self.names.appendAssumeCapacity(final_name);
7010-
if (block_instructions.items.len == 0 or
7030+
if (force_debug_location or
7031+
block_instructions.items.len == 0 or
70117032
!std.meta.eql(self.debug_location, self.prev_debug_location))
70127033
{
70137034
self.debug_locations.putAssumeCapacity(index, self.debug_location);

src/backend/llvm/MonoLlvmCodeGen.zig

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ pub const MonoLlvmCodeGen = struct {
171171
/// one subprogram per proc, and per-statement line locations from the
172172
/// LIR store's source-location tables.
173173
emit_debug_info: bool = false,
174+
/// Emit local variable declarations for source-level debugger inspection.
175+
emit_local_debug_info: bool = false,
174176
/// Build-only default-platform Linux executables link a small runtime
175177
/// object that owns process startup diagnostics and signal handling.
176178
enable_default_platform_runtime: bool = false,
@@ -997,14 +999,12 @@ pub const MonoLlvmCodeGen = struct {
997999
const file = try self.debugFileFor(builder, self.current_debug_file);
9981000
const empty_expr = builder.debugExpression(&.{}) catch return error.OutOfMemory;
9991001
const previous_debug_location = wip.debug_location;
1000-
if (self.enable_default_platform_diagnostics) {
1001-
wip.debug_location = .{ .location = .{
1002-
.line = proc_line,
1003-
.column = if (proc_line == 0) 0 else 1,
1004-
.scope = scope.toOptional(),
1005-
.inlined_at = .none,
1006-
} };
1007-
}
1002+
wip.debug_location = .{ .location = .{
1003+
.line = proc_line,
1004+
.column = if (proc_line == 0) 0 else 1,
1005+
.scope = scope.toOptional(),
1006+
.inlined_at = .none,
1007+
} };
10081008
defer wip.debug_location = previous_debug_location;
10091009

10101010
for (self.store.getLocalSpan(proc.frame_locals)) |local_id| {
@@ -1189,7 +1189,9 @@ pub const MonoLlvmCodeGen = struct {
11891189
defer self.allocator.free(self.local_slots);
11901190
try self.allocLocalSlots();
11911191
try self.unpackProcArgs(proc);
1192-
if (!builder.strip) try self.declareFrameLocals(proc, self.store.procLoc(proc_id).line);
1192+
if (!builder.strip and self.emit_local_debug_info) {
1193+
try self.declareFrameLocals(proc, self.store.procLoc(proc_id).line);
1194+
}
11931195

11941196
if (proc.hosted) |hosted| {
11951197
try self.emitHostedProcBody(hosted, proc);
@@ -1390,7 +1392,7 @@ pub const MonoLlvmCodeGen = struct {
13901392
arg_layouts: []const layout.Idx,
13911393
ret_layout: layout.Idx,
13921394
) Error!void {
1393-
if (self.enable_default_platform_runtime and
1395+
if (self.enable_default_platform_hosted_calls and
13941396
self.host_call_mode == .extern_symbols and
13951397
self.target.os.tag == .linux and
13961398
std.mem.eql(u8, symbol_name, "_start"))
@@ -1800,6 +1802,12 @@ pub const MonoLlvmCodeGen = struct {
18001802
.runtime_error => {
18011803
try self.emitCrashBytes("hit a runtime error");
18021804
},
1805+
.comptime_exhaustiveness_failed => {
1806+
try self.emitCrashBytes("compile-time exhaustiveness failure reached runtime code");
1807+
},
1808+
.comptime_branch_taken => |marker| {
1809+
try work.append(wa, .{ .node = marker.next });
1810+
},
18031811
.incref => |inc| {
18041812
try self.emitRcForLocal(.incref, inc.value, inc.count, inc.atomicity);
18051813
try work.append(wa, .{ .node = inc.next });

src/backend/wasm/WasmCodeGen.zig

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3123,7 +3123,8 @@ fn collectProcLocals(
31233123
try recordProcLocal(locals, expect_stmt.condition);
31243124
try work.append(wa, expect_stmt.next);
31253125
},
3126-
.runtime_error => {},
3126+
.comptime_branch_taken => |marker| try work.append(wa, marker.next),
3127+
.runtime_error, .comptime_exhaustiveness_failed => {},
31273128
.switch_stmt => |switch_stmt| {
31283129
try recordProcLocal(locals, switch_stmt.cond);
31293130
for (self.store.getCFSwitchBranches(switch_stmt.branches)) |branch| {
@@ -7284,6 +7285,13 @@ fn generateCFStmtNode(self: *Self, work: *std.ArrayList(StmtWork), wa: Allocator
72847285
try self.emitRocStaticStringCall(wasm_roc_ops_crashed_offset, msg);
72857286
self.currentCode().append(self.allocator, Op.@"unreachable") catch return error.OutOfMemory;
72867287
},
7288+
.comptime_exhaustiveness_failed => {
7289+
try self.emitRocStaticStringCall(wasm_roc_ops_crashed_offset, "compile-time exhaustiveness failure reached runtime code");
7290+
self.currentCode().append(self.allocator, Op.@"unreachable") catch return error.OutOfMemory;
7291+
},
7292+
.comptime_branch_taken => |marker| {
7293+
try work.append(wa, .{ .node = .{ .stmt_id = marker.next, .stop = stop } });
7294+
},
72877295
.crash => |crash| {
72887296
const msg_bytes = self.store.getString(crash.msg);
72897297
try self.emitRocStaticStringCall(wasm_roc_ops_crashed_offset, msg_bytes);

src/canonicalize/Can.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10129,6 +10129,7 @@ fn runExprKernel(
1012910129
const if_expr_idx = try self.env.addExpr(Expr{ .e_if = .{
1013010130
.branches = branches_span,
1013110131
.final_else = final_else,
10132+
.warn_unused_branches = false,
1013210133
} }, state.region);
1013310134

1013410135
const if_free_vars = self.scratch_free_vars.spanFrom(state.free_vars_start);
@@ -10802,6 +10803,7 @@ fn runExprKernel(
1080210803
.e_if = .{
1080310804
.branches = branches_span,
1080410805
.final_else = can_else.idx,
10806+
.warn_unused_branches = true,
1080510807
},
1080610808
}, state.region);
1080710809

@@ -10868,6 +10870,7 @@ fn runExprKernel(
1086810870
.e_if = .{
1086910871
.branches = branches_span,
1087010872
.final_else = empty_record_idx,
10873+
.warn_unused_branches = true,
1087110874
},
1087210875
}, state.region);
1087310876

src/canonicalize/Expression.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ pub const Expr = union(enum) {
201201
e_if: struct {
202202
branches: IfBranch.Span,
203203
final_else: Expr.Idx,
204+
warn_unused_branches: bool,
204205
},
205206
/// This is *only* for calling functions, not for tag application.
206207
/// The Tag variant contains any applied values inside it.

src/canonicalize/Node.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ pub const Payload = extern union {
575575
};
576576

577577
pub const ExprIfThenElse = extern struct {
578-
branches_else_idx: u32, // Index into span_with_node_data: (branches.start, branches.len, final_else)
578+
branches_else_idx: u32, // Index into if_data
579579
_padding: [8]u8 = .{ 0, 0, 0, 0, 0, 0, 0, 0 },
580580
};
581581

0 commit comments

Comments
 (0)