Fix remaining violations

This commit is contained in:
Richard Feldman 2025-12-04 07:51:24 -05:00
parent 36d68c9774
commit ece0001c49
No known key found for this signature in database
3 changed files with 31 additions and 32 deletions

View file

@ -752,7 +752,7 @@ pub const TupleAccessor = struct {
}
/// Set an element by copying from a source StackValue
pub fn setElement(self: TupleAccessor, index: usize, source: StackValue, ops: *RocOps) !void {
pub fn setElement(self: TupleAccessor, index: usize, source: StackValue) !void {
const dest_element = try self.getElement(index);
try source.copyToPtr(self.layout_cache, dest_element.ptr.?);
}
@ -1030,7 +1030,7 @@ pub const RecordAccessor = struct {
}
/// Set a field by copying from a source StackValue
pub fn setFieldByIndex(self: RecordAccessor, index: usize, source: StackValue, ops: *RocOps) !void {
pub fn setFieldByIndex(self: RecordAccessor, index: usize, source: StackValue) !void {
const dest_field = try self.getFieldByIndex(index);
try source.copyToPtr(self.layout_cache, dest_field.ptr.?);
}

View file

@ -1016,7 +1016,7 @@ pub const ComptimeEvaluator = struct {
// Build the Numeral record
// Ownership of before_list and after_list is transferred to this record
const num_literal_record = try self.buildNumeralRecord(is_neg_value, before_list, after_list, roc_ops);
const num_literal_record = try self.buildNumeralRecord(is_neg_value, before_list, after_list);
defer num_literal_record.decref(&self.interpreter.runtime_layout_store, roc_ops);
// Evaluate the from_numeral function to get a closure
@ -1231,7 +1231,6 @@ pub const ComptimeEvaluator = struct {
is_negative: eval_mod.StackValue,
digits_before_pt: eval_mod.StackValue,
digits_after_pt: eval_mod.StackValue,
roc_ops: *RocOps,
) !eval_mod.StackValue {
// Use precomputed idents from self.env for field names
const field_layouts = [_]layout_mod.Layout{
@ -1253,13 +1252,13 @@ pub const ComptimeEvaluator = struct {
// Use self.env for field lookups since the record was built with self.env's idents
const is_neg_idx = accessor.findFieldIndex(self.env.idents.is_negative) orelse return error.OutOfMemory;
try accessor.setFieldByIndex(is_neg_idx, is_negative, roc_ops);
try accessor.setFieldByIndex(is_neg_idx, is_negative);
const before_pt_idx = accessor.findFieldIndex(self.env.idents.digits_before_pt) orelse return error.OutOfMemory;
try accessor.setFieldByIndex(before_pt_idx, digits_before_pt, roc_ops);
try accessor.setFieldByIndex(before_pt_idx, digits_before_pt);
const after_pt_idx = accessor.findFieldIndex(self.env.idents.digits_after_pt) orelse return error.OutOfMemory;
try accessor.setFieldByIndex(after_pt_idx, digits_after_pt, roc_ops);
try accessor.setFieldByIndex(after_pt_idx, digits_after_pt);
return dest;
}

View file

@ -769,7 +769,7 @@ pub const Interpreter = struct {
return StackValue{ .layout = .{ .tag = .zst, .data = undefined }, .ptr = ptr, .is_initialized = true };
}
pub fn pushCopy(self: *Interpreter, src: StackValue, roc_ops: *RocOps) !StackValue {
pub fn pushCopy(self: *Interpreter, src: StackValue) !StackValue {
const size: u32 = if (src.layout.tag == .closure) src.getTotalSize(&self.runtime_layout_store) else self.runtime_layout_store.layoutSize(src.layout);
const target_usize = self.runtime_layout_store.targetUsize();
var alignment = src.layout.alignment(target_usize);
@ -872,8 +872,8 @@ pub const Interpreter = struct {
};
// Copy elements for comparison (compare_fn will consume them)
const arg0 = try self.pushCopy(elem1_value, roc_ops); // element being inserted
const arg1 = try self.pushCopy(elem0_value, roc_ops); // element to compare against
const arg0 = try self.pushCopy(elem1_value); // element being inserted
const arg1 = try self.pushCopy(elem0_value); // element to compare against
// Push continuation to handle comparison result
try work_stack.push(.{ .apply_continuation = .{ .sort_compare_result = .{
@ -2133,7 +2133,7 @@ pub const Interpreter = struct {
};
// Copy to new location and increment refcount
var result = try self.pushCopy(elem_value, roc_ops);
var result = try self.pushCopy(elem_value);
result.rt_var = elem_rt_var; // Ensure rt_var is preserved after copy
return result;
},
@ -2195,14 +2195,14 @@ pub const Interpreter = struct {
if (list_a.len() == 0) {
list_a_arg.decref(&self.runtime_layout_store, roc_ops);
// list_b ownership is transferred to the result (pushCopy increfs)
const result = try self.pushCopy(list_b_arg, roc_ops);
const result = try self.pushCopy(list_b_arg);
list_b_arg.decref(&self.runtime_layout_store, roc_ops);
return result;
}
if (list_b.len() == 0) {
list_b_arg.decref(&self.runtime_layout_store, roc_ops);
// list_a ownership is transferred to the result (pushCopy increfs)
const result = try self.pushCopy(list_a_arg, roc_ops);
const result = try self.pushCopy(list_a_arg);
list_a_arg.decref(&self.runtime_layout_store, roc_ops);
return result;
}
@ -6297,7 +6297,7 @@ pub const Interpreter = struct {
}
// Copy the value to pass to the method
const copied_value = self.pushCopy(value, roc_ops) catch return null;
const copied_value = self.pushCopy(value) catch return null;
// Bind the parameter
self.bindings.append(.{
@ -6462,7 +6462,7 @@ pub const Interpreter = struct {
switch (pat) {
.assign => |_| {
// Bind entire value to this pattern
const copied = try self.pushCopy(value, roc_ops);
const copied = try self.pushCopy(value);
try out_binds.append(.{ .pattern_idx = pattern_idx, .value = copied, .expr_idx = expr_idx, .source_env = self.env });
return true;
},
@ -6473,7 +6473,7 @@ pub const Interpreter = struct {
return false;
}
const alias_value = try self.pushCopy(value, roc_ops);
const alias_value = try self.pushCopy(value);
try out_binds.append(.{ .pattern_idx = pattern_idx, .value = alias_value, .expr_idx = expr_idx, .source_env = self.env });
return true;
},
@ -10631,7 +10631,7 @@ pub const Interpreter = struct {
self.triggerCrash("e_closure: capture field not found in record", false, roc_ops);
return error.Crash;
};
try accessor.setFieldByIndex(idx_opt, cap_val, roc_ops);
try accessor.setFieldByIndex(idx_opt, cap_val);
}
}
return value;
@ -10764,7 +10764,7 @@ pub const Interpreter = struct {
}
}
}
const copy_result = try self.pushCopy(b.value, roc_ops);
const copy_result = try self.pushCopy(b.value);
return copy_result;
}
}
@ -10794,7 +10794,7 @@ pub const Interpreter = struct {
var accessor = try rec_val.asRecord(&self.runtime_layout_store);
if (accessor.findFieldIndex(var_ident)) |fidx| {
const field_val = try accessor.getFieldByIndex(fidx);
return try self.pushCopy(field_val, roc_ops);
return try self.pushCopy(field_val);
}
}
}
@ -10817,7 +10817,7 @@ pub const Interpreter = struct {
});
// Return a copy to give the caller ownership while the binding retains ownership too.
// This is consistent with the pushCopy call above for already-bound values.
return try self.pushCopy(result, roc_ops);
return try self.pushCopy(result);
}
}
@ -11424,7 +11424,7 @@ pub const Interpreter = struct {
// Set all elements
for (0..total_count) |idx| {
try accessor.setElement(idx, values[idx], roc_ops);
try accessor.setElement(idx, values[idx]);
}
// Decref temporary values after they've been copied into the tuple
@ -11646,7 +11646,7 @@ pub const Interpreter = struct {
const info = base_accessor.field_layouts.get(idx);
const dest_field_idx = accessor.findFieldIndex(info.name) orelse return error.TypeMismatch;
const base_field_value = try base_accessor.getFieldByIndex(idx);
try accessor.setFieldByIndex(dest_field_idx, base_field_value, roc_ops);
try accessor.setFieldByIndex(dest_field_idx, base_field_value);
}
}
@ -11668,7 +11668,7 @@ pub const Interpreter = struct {
}
}
try accessor.setFieldByIndex(dest_field_idx, val, roc_ops);
try accessor.setFieldByIndex(dest_field_idx, val);
}
// Decref base value and field values after they've been copied
@ -11797,7 +11797,7 @@ pub const Interpreter = struct {
var tuple_dest = StackValue{ .layout = tuple_layout, .ptr = payload_ptr, .is_initialized = true };
var tup_acc = try tuple_dest.asTuple(&self.runtime_layout_store);
for (values, 0..) |val, idx| {
try tup_acc.setElement(idx, val, roc_ops);
try tup_acc.setElement(idx, val);
}
}
}
@ -11872,7 +11872,7 @@ pub const Interpreter = struct {
var tuple_dest = StackValue{ .layout = tuple_layout, .ptr = payload_ptr, .is_initialized = true };
var tup_acc = try tuple_dest.asTuple(&self.runtime_layout_store);
for (values, 0..) |val, idx| {
try tup_acc.setElement(idx, val, roc_ops);
try tup_acc.setElement(idx, val);
}
}
}
@ -11967,7 +11967,7 @@ pub const Interpreter = struct {
var tuple_dest = StackValue{ .layout = tuple_layout, .ptr = payload_ptr, .is_initialized = true };
var tup_acc = try tuple_dest.asTuple(&self.runtime_layout_store);
for (values, 0..) |val, idx| {
try tup_acc.setElement(idx, val, roc_ops);
try tup_acc.setElement(idx, val);
}
}
@ -11985,7 +11985,7 @@ pub const Interpreter = struct {
// Scrutinee is on value stack - get it but keep it there for potential later use
const scrutinee_temp = value_stack.pop() orelse return error.Crash;
// Make a copy to protect from corruption
const scrutinee = try self.pushCopy(scrutinee_temp, roc_ops);
const scrutinee = try self.pushCopy(scrutinee_temp);
scrutinee_temp.decref(&self.runtime_layout_store, roc_ops);
// Try branches starting from current_branch
@ -13133,7 +13133,7 @@ pub const Interpreter = struct {
var accessor = try receiver_value.asRecord(&self.runtime_layout_store);
const field_idx = accessor.findFieldIndex(da.field_name) orelse return error.TypeMismatch;
const field_value = try accessor.getFieldByIndex(field_idx);
const result = try self.pushCopy(field_value, roc_ops);
const result = try self.pushCopy(field_value);
try value_stack.push(result);
return true;
}
@ -14027,8 +14027,8 @@ pub const Interpreter = struct {
};
// Copy elements for comparison
const arg0 = try self.pushCopy(elem_current_value, roc_ops);
const arg1 = try self.pushCopy(elem_inner_value, roc_ops);
const arg0 = try self.pushCopy(elem_current_value);
const arg1 = try self.pushCopy(elem_inner_value);
// Push continuation for next comparison
// After swap, the element we're inserting is now at sc.inner_index
@ -14108,8 +14108,8 @@ pub const Interpreter = struct {
};
// Copy elements for comparison
const arg0 = try self.pushCopy(elem_outer_value, roc_ops);
const arg1 = try self.pushCopy(elem_prev_value, roc_ops);
const arg0 = try self.pushCopy(elem_outer_value);
const arg1 = try self.pushCopy(elem_prev_value);
// Push continuation for next comparison
try work_stack.push(.{ .apply_continuation = .{ .sort_compare_result = .{