Skip to content

Commit a02d2b5

Browse files
committed
don't automatically take pointer when passing by non-copying value
this commit does not have all tests passing
1 parent 66f5f77 commit a02d2b5

File tree

10 files changed

+248
-271
lines changed

10 files changed

+248
-271
lines changed

src/ir.cpp

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10463,13 +10463,6 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ
1046310463
zig_unreachable();
1046410464
}
1046510465

10466-
static IrInstruction *ir_implicit_byval_const_ref_cast(IrAnalyze *ira, IrInstruction *inst) {
10467-
if (type_is_copyable(ira->codegen, inst->value.type))
10468-
return inst;
10469-
TypeTableEntry *const_ref_type = get_pointer_to_type(ira->codegen, inst->value.type, true);
10470-
return ir_implicit_cast(ira, inst, const_ref_type);
10471-
}
10472-
1047310466
static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr) {
1047410467
TypeTableEntry *type_entry = ptr->value.type;
1047510468
if (type_is_invalid(type_entry)) {
@@ -12283,7 +12276,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1228312276
IrInstruction *casted_arg;
1228412277
if (is_var_args) {
1228512278
arg_part_of_generic_id = true;
12286-
casted_arg = ir_implicit_byval_const_ref_cast(ira, arg);
12279+
casted_arg = arg;
1228712280
} else {
1228812281
if (param_decl_node->data.param_decl.var_token == nullptr) {
1228912282
AstNode *param_type_node = param_decl_node->data.param_decl.type;
@@ -12296,7 +12289,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1229612289
return false;
1229712290
} else {
1229812291
arg_part_of_generic_id = true;
12299-
casted_arg = ir_implicit_byval_const_ref_cast(ira, arg);
12292+
casted_arg = arg;
1230012293
}
1230112294
}
1230212295

@@ -12515,9 +12508,18 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1251512508

1251612509
size_t next_proto_i = 0;
1251712510
if (first_arg_ptr) {
12518-
IrInstruction *first_arg;
1251912511
assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);
12520-
if (handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) {
12512+
12513+
bool first_arg_known_bare = false;
12514+
if (fn_type_id->next_param_index >= 1) {
12515+
TypeTableEntry *param_type = fn_type_id->param_info[next_proto_i].type;
12516+
if (type_is_invalid(param_type))
12517+
return ira->codegen->builtin_types.entry_invalid;
12518+
first_arg_known_bare = param_type->id != TypeTableEntryIdPointer;
12519+
}
12520+
12521+
IrInstruction *first_arg;
12522+
if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) {
1252112523
first_arg = first_arg_ptr;
1252212524
} else {
1252312525
first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);
@@ -12667,9 +12669,18 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1266712669
size_t next_proto_i = 0;
1266812670

1266912671
if (first_arg_ptr) {
12670-
IrInstruction *first_arg;
1267112672
assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);
12672-
if (handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) {
12673+
12674+
bool first_arg_known_bare = false;
12675+
if (fn_type_id->next_param_index >= 1) {
12676+
TypeTableEntry *param_type = fn_type_id->param_info[next_proto_i].type;
12677+
if (type_is_invalid(param_type))
12678+
return ira->codegen->builtin_types.entry_invalid;
12679+
first_arg_known_bare = param_type->id != TypeTableEntryIdPointer;
12680+
}
12681+
12682+
IrInstruction *first_arg;
12683+
if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) {
1267312684
first_arg = first_arg_ptr;
1267412685
} else {
1267512686
first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);
@@ -12802,10 +12813,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1280212813
return ira->codegen->builtin_types.entry_invalid;
1280312814
}
1280412815
if (inst_fn_type_id.async_allocator_type == nullptr) {
12805-
IrInstruction *casted_inst = ir_implicit_byval_const_ref_cast(ira, uncasted_async_allocator_inst);
12806-
if (type_is_invalid(casted_inst->value.type))
12807-
return ira->codegen->builtin_types.entry_invalid;
12808-
inst_fn_type_id.async_allocator_type = casted_inst->value.type;
12816+
inst_fn_type_id.async_allocator_type = uncasted_async_allocator_inst->value.type;
1280912817
}
1281012818
async_allocator_inst = ir_implicit_cast(ira, uncasted_async_allocator_inst, inst_fn_type_id.async_allocator_type);
1281112819
if (type_is_invalid(async_allocator_inst->value.type))
@@ -12866,20 +12874,23 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1286612874
IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count);
1286712875
size_t next_arg_index = 0;
1286812876
if (first_arg_ptr) {
12869-
IrInstruction *first_arg;
1287012877
assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);
12871-
if (handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) {
12878+
12879+
TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type;
12880+
if (type_is_invalid(param_type))
12881+
return ira->codegen->builtin_types.entry_invalid;
12882+
12883+
IrInstruction *first_arg;
12884+
if (param_type->id == TypeTableEntryIdPointer &&
12885+
handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type))
12886+
{
1287212887
first_arg = first_arg_ptr;
1287312888
} else {
1287412889
first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);
1287512890
if (type_is_invalid(first_arg->value.type))
1287612891
return ira->codegen->builtin_types.entry_invalid;
1287712892
}
1287812893

12879-
TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type;
12880-
if (type_is_invalid(param_type))
12881-
return ira->codegen->builtin_types.entry_invalid;
12882-
1288312894
IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type);
1288412895
if (type_is_invalid(casted_arg->value.type))
1288512896
return ira->codegen->builtin_types.entry_invalid;

std/array_list.zig

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,36 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
2929
};
3030
}
3131

32-
pub fn deinit(self: *const Self) void {
32+
pub fn deinit(self: Self) void {
3333
self.allocator.free(self.items);
3434
}
3535

36-
pub fn toSlice(self: *const Self) []align(A) T {
36+
pub fn toSlice(self: Self) []align(A) T {
3737
return self.items[0..self.len];
3838
}
3939

40-
pub fn toSliceConst(self: *const Self) []align(A) const T {
40+
pub fn toSliceConst(self: Self) []align(A) const T {
4141
return self.items[0..self.len];
4242
}
4343

44-
pub fn at(self: *const Self, n: usize) T {
44+
pub fn at(self: Self, n: usize) T {
4545
return self.toSliceConst()[n];
4646
}
4747

4848
/// Sets the value at index `i`, or returns `error.OutOfBounds` if
4949
/// the index is not in range.
50-
pub fn setOrError(self: *const Self, i: usize, item: *const T) !void {
50+
pub fn setOrError(self: Self, i: usize, item: T) !void {
5151
if (i >= self.len) return error.OutOfBounds;
52-
self.items[i] = item.*;
52+
self.items[i] = item;
5353
}
5454

5555
/// Sets the value at index `i`, asserting that the value is in range.
56-
pub fn set(self: *const Self, i: usize, item: *const T) void {
56+
pub fn set(self: *Self, i: usize, item: T) void {
5757
assert(i < self.len);
58-
self.items[i] = item.*;
58+
self.items[i] = item;
5959
}
6060

61-
pub fn count(self: *const Self) usize {
61+
pub fn count(self: Self) usize {
6262
return self.len;
6363
}
6464

@@ -81,12 +81,12 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
8181
return result;
8282
}
8383

84-
pub fn insert(self: *Self, n: usize, item: *const T) !void {
84+
pub fn insert(self: *Self, n: usize, item: T) !void {
8585
try self.ensureCapacity(self.len + 1);
8686
self.len += 1;
8787

8888
mem.copy(T, self.items[n + 1 .. self.len], self.items[n .. self.len - 1]);
89-
self.items[n] = item.*;
89+
self.items[n] = item;
9090
}
9191

9292
pub fn insertSlice(self: *Self, n: usize, items: []align(A) const T) !void {
@@ -97,9 +97,9 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
9797
mem.copy(T, self.items[n .. n + items.len], items);
9898
}
9999

100-
pub fn append(self: *Self, item: *const T) !void {
100+
pub fn append(self: *Self, item: T) !void {
101101
const new_item_ptr = try self.addOne();
102-
new_item_ptr.* = item.*;
102+
new_item_ptr.* = item;
103103
}
104104

105105
pub fn appendSlice(self: *Self, items: []align(A) const T) !void {

std/build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pub const Builder = struct {
234234
defer wanted_steps.deinit();
235235

236236
if (step_names.len == 0) {
237-
try wanted_steps.append(&self.default_step);
237+
try wanted_steps.append(self.default_step);
238238
} else {
239239
for (step_names) |step_name| {
240240
const s = try self.getTopLevelStepByName(step_name);

std/fmt/index.zig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,6 @@ pub fn formatType(
162162
},
163163
builtin.TypeInfo.Pointer.Size.Many => {
164164
if (ptr_info.child == u8) {
165-
//This is a bit of a hack, but it made more sense to
166-
// do this check here than have formatText do it
167165
if (fmt[0] == 's') {
168166
const len = std.cstr.len(value);
169167
return formatText(value[0..len], fmt, context, Errors, output);
@@ -176,6 +174,12 @@ pub fn formatType(
176174
return output(context, casted_value);
177175
},
178176
},
177+
builtin.TypeId.Array => |info| {
178+
if (info.child == u8) {
179+
return formatText(value, fmt, context, Errors, output);
180+
}
181+
return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(&value));
182+
},
179183
else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"),
180184
}
181185
}

std/json.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ pub const Parser = struct {
13261326
},
13271327
// Array Parent -> [ ..., <array>, value ]
13281328
Value.Array => |*array| {
1329-
try array.append(value);
1329+
try array.append(value.*);
13301330
p.state = State.ArrayValue;
13311331
},
13321332
else => {

0 commit comments

Comments
 (0)