Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Air.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1528,11 +1528,13 @@ pub fn refToInterned(ref: Inst.Ref) ?InternPool.Index {
}

pub fn internedToRef(ip_index: InternPool.Index) Inst.Ref {
assert(@intFromEnum(ip_index) >> 31 == 0);
return switch (ip_index) {
.var_args_param_type => .var_args_param_type,
.none => .none,
else => @enumFromInt(@as(u31, @intCast(@intFromEnum(ip_index)))),
else => {
assert(@intFromEnum(ip_index) >> 31 == 0);
return @enumFromInt(@as(u31, @intCast(@intFromEnum(ip_index))));
},
};
}

Expand Down
52 changes: 35 additions & 17 deletions src/AstGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1509,9 +1509,11 @@ fn arrayInitExpr(
const tag: Zir.Inst.Tag = if (types.array != .none) .array_init else .array_init_anon;
return arrayInitExprInner(gz, scope, node, array_init.ast.elements, types.array, types.elem, tag);
},
.ty, .coerced_ty => {
const tag: Zir.Inst.Tag = if (types.array != .none) .array_init else .array_init_anon;
const result = try arrayInitExprInner(gz, scope, node, array_init.ast.elements, types.array, types.elem, tag);
.ty, .coerced_ty => |ty_inst| {
const arr_ty = if (types.array != .none) types.array else blk: {
break :blk try gz.addUnNode(.opt_eu_base_ty, ty_inst, node);
};
const result = try arrayInitExprInner(gz, scope, node, array_init.ast.elements, arr_ty, types.elem, .array_init);
return rvalue(gz, ri, result, node);
},
.ptr => |ptr_res| {
Expand Down Expand Up @@ -1748,7 +1750,9 @@ fn structInitExpr(
},
.ty, .coerced_ty => |ty_inst| {
if (struct_init.ast.type_expr == 0) {
const result = try structInitExprRlNone(gz, scope, node, struct_init, ty_inst, .struct_init_anon);
const struct_ty_inst = try gz.addUnNode(.opt_eu_base_ty, ty_inst, node);
_ = try gz.addUnNode(.validate_struct_init_ty, struct_ty_inst, node);
const result = try structInitExprRlTy(gz, scope, node, struct_init, struct_ty_inst, .struct_init);
return rvalue(gz, ri, result, node);
}
const inner_ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr);
Expand Down Expand Up @@ -2565,6 +2569,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
.array_type_sentinel,
.elem_type_index,
.elem_type,
.vector_elem_type,
.vector_type,
.indexable_ptr_len,
.anyframe_type,
Expand Down Expand Up @@ -2743,6 +2748,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
.for_len,
.@"try",
.try_ptr,
.opt_eu_base_ty,
=> break :b false,

.extended => switch (gz.astgen.instructions.items(.data)[inst].extended.opcode) {
Expand Down Expand Up @@ -8314,7 +8320,10 @@ fn builtinCall(
local_val.used = ident_token;
_ = try gz.addPlNode(.export_value, node, Zir.Inst.ExportValue{
.operand = local_val.inst,
.options = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .export_options_type } }, params[1]),
// TODO: the result location here should be `.{ .coerced_ty = .export_options_type }`, but
// that currently hits assertions in Sema due to type resolution issues.
// See #16603
.options = try comptimeExpr(gz, scope, .{ .rl = .none }, params[1]),
});
return rvalue(gz, ri, .void_value, node);
}
Expand All @@ -8329,7 +8338,10 @@ fn builtinCall(
const loaded = try gz.addUnNode(.load, local_ptr.ptr, node);
_ = try gz.addPlNode(.export_value, node, Zir.Inst.ExportValue{
.operand = loaded,
.options = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .export_options_type } }, params[1]),
// TODO: the result location here should be `.{ .coerced_ty = .export_options_type }`, but
// that currently hits assertions in Sema due to type resolution issues.
// See #16603
.options = try comptimeExpr(gz, scope, .{ .rl = .none }, params[1]),
});
return rvalue(gz, ri, .void_value, node);
}
Expand Down Expand Up @@ -8363,7 +8375,10 @@ fn builtinCall(
},
else => return astgen.failNode(params[0], "symbol to export must identify a declaration", .{}),
}
const options = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .export_options_type } }, params[1]);
// TODO: the result location here should be `.{ .coerced_ty = .export_options_type }`, but
// that currently hits assertions in Sema due to type resolution issues.
// See #16603
const options = try comptimeExpr(gz, scope, .{ .rl = .none }, params[1]);
_ = try gz.addPlNode(.@"export", node, Zir.Inst.Export{
.namespace = namespace,
.decl_name = decl_name,
Expand All @@ -8373,7 +8388,10 @@ fn builtinCall(
},
.@"extern" => {
const type_inst = try typeExpr(gz, scope, params[0]);
const options = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .extern_options_type } }, params[1]);
// TODO: the result location here should be `.{ .coerced_ty = .extern_options_type }`, but
// that currently hits assertions in Sema due to type resolution issues.
// See #16603
const options = try comptimeExpr(gz, scope, .{ .rl = .none }, params[1]);
const result = try gz.addExtendedPayload(.builtin_extern, Zir.Inst.BinNode{
.node = gz.nodeIndexToRelative(node),
.lhs = type_inst,
Expand Down Expand Up @@ -8477,7 +8495,10 @@ fn builtinCall(
// zig fmt: on

.Type => {
const operand = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .type_info_type } }, params[0]);
// TODO: the result location here should be `.{ .coerced_ty = .type_info_type }`, but
// that currently hits assertions in Sema due to type resolution issues.
// See #16603
const operand = try expr(gz, scope, .{ .rl = .none }, params[0]);

const gpa = gz.astgen.gpa;

Expand Down Expand Up @@ -8604,13 +8625,7 @@ fn builtinCall(

.splat => {
const result_type = try ri.rl.resultType(gz, node, "@splat");
const elem_type = try gz.add(.{
.tag = .elem_type_index,
.data = .{ .bin = .{
.lhs = result_type,
.rhs = @as(Zir.Inst.Ref, @enumFromInt(0)),
} },
});
const elem_type = try gz.addUnNode(.vector_elem_type, result_type, node);
const scalar = try expr(gz, scope, .{ .rl = .{ .ty = elem_type } }, params[0]);
const result = try gz.addPlNode(.splat, node, Zir.Inst.Bin{
.lhs = result_type,
Expand Down Expand Up @@ -8755,7 +8770,10 @@ fn builtinCall(
},
.prefetch => {
const ptr = try expr(gz, scope, .{ .rl = .none }, params[0]);
const options = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .prefetch_options_type } }, params[1]);
// TODO: the result location here should be `.{ .coerced_ty = .preftech_options_type }`, but
// that currently hits assertions in Sema due to type resolution issues.
// See #16603
const options = try comptimeExpr(gz, scope, .{ .rl = .none }, params[1]);
_ = try gz.addExtendedPayload(.prefetch, Zir.Inst.BinNode{
.node = gz.nodeIndexToRelative(node),
.lhs = ptr,
Expand Down
29 changes: 0 additions & 29 deletions src/Module.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5938,35 +5938,6 @@ pub fn paramSrc(
unreachable;
}

pub fn argSrc(
mod: *Module,
call_node_offset: i32,
decl: *Decl,
start_arg_i: usize,
bound_arg_src: ?LazySrcLoc,
) LazySrcLoc {
@setCold(true);
const gpa = mod.gpa;
if (start_arg_i == 0 and bound_arg_src != null) return bound_arg_src.?;
const arg_i = start_arg_i - @intFromBool(bound_arg_src != null);
const tree = decl.getFileScope(mod).getTree(gpa) catch |err| {
// In this case we emit a warning + a less precise source location.
log.warn("unable to load {s}: {s}", .{
decl.getFileScope(mod).sub_file_path, @errorName(err),
});
return LazySrcLoc.nodeOffset(0);
};
const node = decl.relativeToNodeIndex(call_node_offset);
var args: [1]Ast.Node.Index = undefined;
const call_full = tree.fullCall(&args, node) orelse {
assert(tree.nodes.items(.tag)[node] == .builtin_call);
const call_args_node = tree.extra_data[tree.nodes.items(.data)[node].rhs - 1];
const call_args_offset = decl.nodeIndexToRelative(call_args_node);
return mod.initSrc(call_args_offset, decl, arg_i);
};
return LazySrcLoc.nodeOffset(decl.nodeIndexToRelative(call_full.ast.params[arg_i]));
}

pub fn initSrc(
mod: *Module,
init_node_offset: i32,
Expand Down
Loading