mirror of
https://github.com/roc-lang/roc.git
synced 2025-12-23 08:48:03 +00:00
Simplify some error handling
This commit is contained in:
parent
254c66726c
commit
afe0fc98aa
2 changed files with 11 additions and 22 deletions
|
|
@ -677,23 +677,16 @@ pub fn getExpr(store: *const NodeStore, expr: CIR.Expr.Idx) CIR.Expr {
|
|||
|
||||
/// Replaces an existing expression with an e_num expression in-place.
|
||||
/// This is used for constant folding during compile-time evaluation.
|
||||
/// IMPORTANT: This modifies the expression node in-place and should only be called
|
||||
/// after type-checking is complete, since it doesn't update type variables.
|
||||
/// Note: This modifies only the CIR node and should only be called after type-checking
|
||||
/// is complete. Type information is stored separately and remains unchanged.
|
||||
pub fn replaceExprWithNum(store: *NodeStore, expr_idx: CIR.Expr.Idx, value: CIR.IntValue, num_kind: CIR.NumKind) !void {
|
||||
const node_idx: Node.Idx = @enumFromInt(@intFromEnum(expr_idx));
|
||||
|
||||
// Store i128 value in extra_data
|
||||
const extra_data_start = store.extra_data.len();
|
||||
|
||||
// Store the IntLiteralValue as i128 (16 bytes = 4 u32s)
|
||||
const value_as_i128: i128 = @bitCast(value.bytes);
|
||||
const value_as_u32s: [4]u32 = @bitCast(value_as_i128);
|
||||
for (value_as_u32s) |word| {
|
||||
_ = try store.extra_data.append(store.gpa, word);
|
||||
}
|
||||
_ = try store.extra_data.appendSlice(store.gpa, &value_as_u32s);
|
||||
|
||||
// Update the node to be an expr_num
|
||||
// Access the node through the safe multi list set method
|
||||
store.nodes.set(node_idx, .{
|
||||
.tag = .expr_num,
|
||||
.data_1 = @intFromEnum(num_kind),
|
||||
|
|
|
|||
|
|
@ -233,9 +233,13 @@ pub const ComptimeEvaluator = struct {
|
|||
else => false,
|
||||
};
|
||||
|
||||
// Skip e_runtime_error (compile error already reported)
|
||||
if (expr == .e_runtime_error) {
|
||||
return EvalResult.success;
|
||||
return EvalResult{
|
||||
.crash = .{
|
||||
.message = "Runtime error in expression",
|
||||
.region = region,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// Reset halted flag at the start of each def - crashes only halt within a single def
|
||||
|
|
@ -265,18 +269,10 @@ pub const ComptimeEvaluator = struct {
|
|||
},
|
||||
};
|
||||
}
|
||||
if (self.crash.crashMessage()) |msg| {
|
||||
return EvalResult{
|
||||
.crash = .{
|
||||
.message = msg,
|
||||
.region = region,
|
||||
},
|
||||
};
|
||||
}
|
||||
// If we got error.Crash but no message was recorded, still return crash with a default message
|
||||
const msg = self.crash.crashMessage() orelse unreachable;
|
||||
return EvalResult{
|
||||
.crash = .{
|
||||
.message = "Crash occurred but no message was recorded",
|
||||
.message = msg,
|
||||
.region = region,
|
||||
},
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue