Skip to content

Sema: rewrite semantic analysis of function calls #22414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 10, 2025
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
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const assert = std.debug.assert;
const DevEnv = @import("src/dev.zig").Env;

const zig_version: std.SemanticVersion = .{ .major = 0, .minor = 14, .patch = 0 };
const stack_size = 32 * 1024 * 1024;
const stack_size = 46 * 1024 * 1024;

pub fn build(b: *std.Build) !void {
const only_c = b.option(bool, "only-c", "Translate the Zig compiler to C code, with only the C backend enabled") orelse false;
Expand Down
1 change: 1 addition & 0 deletions lib/compiler/aro_translate_c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ pub fn translate(
context.pattern_list.deinit(gpa);
}

@setEvalBranchQuota(2000);
inline for (@typeInfo(std.zig.c_builtins).@"struct".decls) |decl| {
const builtin_fn = try ZigTag.pub_var_simple.create(arena, .{
.name = decl.name,
Expand Down
1 change: 1 addition & 0 deletions lib/std/math/log_int.zig
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub fn log_int(comptime T: type, base: T, x: T) Log2Int(T) {
}

test "log_int" {
@setEvalBranchQuota(2000);
// Test all unsigned integers with 2, 3, ..., 64 bits.
// We cannot test 0 or 1 bits since base must be > 1.
inline for (2..64 + 1) |bits| {
Expand Down
1 change: 1 addition & 0 deletions lib/std/os/windows.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,7 @@ fn mountmgrIsVolumeName(name: []const u16) bool {
}

test mountmgrIsVolumeName {
@setEvalBranchQuota(2000);
const L = std.unicode.utf8ToUtf16LeStringLiteral;
try std.testing.expect(mountmgrIsVolumeName(L("\\\\?\\Volume{383da0b0-717f-41b6-8c36-00500992b58d}")));
try std.testing.expect(mountmgrIsVolumeName(L("\\??\\Volume{383da0b0-717f-41b6-8c36-00500992b58d}")));
Expand Down
6 changes: 4 additions & 2 deletions lib/std/zig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,8 @@ pub const SimpleComptimeReason = enum(u32) {
array_mul_factor,
slice_cat_operand,
comptime_call_target,
inline_call_target,
generic_call_target,
wasm_memory_index,
work_group_dim_index,

Expand Down Expand Up @@ -791,7 +793,6 @@ pub const SimpleComptimeReason = enum(u32) {
struct_field_default_value,
enum_field_tag_value,
slice_single_item_ptr_bounds,
comptime_param_arg,
stored_to_comptime_field,
stored_to_comptime_var,
casted_to_comptime_enum,
Expand Down Expand Up @@ -828,6 +829,8 @@ pub const SimpleComptimeReason = enum(u32) {
.array_mul_factor => "array multiplication factor must be comptime-known",
.slice_cat_operand => "slice being concatenated must be comptime-known",
.comptime_call_target => "function being called at comptime must be comptime-known",
.inline_call_target => "function being called inline must be comptime-known",
.generic_call_target => "generic function being called must be comptime-known",
.wasm_memory_index => "wasm memory index must be comptime-known",
.work_group_dim_index => "work group dimension index must be comptime-known",

Expand Down Expand Up @@ -865,7 +868,6 @@ pub const SimpleComptimeReason = enum(u32) {
.struct_field_default_value => "struct field default value must be comptime-known",
.enum_field_tag_value => "enum field tag value must be comptime-known",
.slice_single_item_ptr_bounds => "slice of single-item pointer must have comptime-known bounds",
.comptime_param_arg => "argument to comptime parameter must be comptime-known",
.stored_to_comptime_field => "value stored to a comptime field must be comptime-known",
.stored_to_comptime_var => "value stored to a comptime variable must be comptime-known",
.casted_to_comptime_enum => "value casted to enum with 'comptime_int' tag type must be comptime-known",
Expand Down
3 changes: 0 additions & 3 deletions lib/std/zig/AstGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10209,9 +10209,6 @@ fn callExpr(

const callee = try calleeExpr(gz, scope, ri.rl, call.ast.fn_expr);
const modifier: std.builtin.CallModifier = blk: {
if (gz.is_comptime) {
break :blk .compile_time;
}
if (call.async_token != null) {
break :blk .async_kw;
}
Expand Down
11 changes: 9 additions & 2 deletions lib/std/zig/Zir.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4735,6 +4735,7 @@ pub const FnInfo = struct {
body: []const Inst.Index,
ret_ty_ref: Zir.Inst.Ref,
total_params_len: u32,
inferred_error_set: bool,
};

pub fn getParamBody(zir: Zir, fn_inst: Inst.Index) []const Zir.Inst.Index {
Expand Down Expand Up @@ -4774,8 +4775,9 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
body: []const Inst.Index,
ret_ty_ref: Inst.Ref,
ret_ty_body: []const Inst.Index,
ies: bool,
} = switch (tags[@intFromEnum(fn_inst)]) {
.func, .func_inferred => blk: {
.func, .func_inferred => |tag| blk: {
const inst_data = datas[@intFromEnum(fn_inst)].pl_node;
const extra = zir.extraData(Inst.Func, inst_data.payload_index);

Expand Down Expand Up @@ -4805,14 +4807,15 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
.ret_ty_ref = ret_ty_ref,
.ret_ty_body = ret_ty_body,
.body = body,
.ies = tag == .func_inferred,
};
},
.func_fancy => blk: {
const inst_data = datas[@intFromEnum(fn_inst)].pl_node;
const extra = zir.extraData(Inst.FuncFancy, inst_data.payload_index);

var extra_index: usize = extra.end;
var ret_ty_ref: Inst.Ref = .void_type;
var ret_ty_ref: Inst.Ref = .none;
var ret_ty_body: []const Inst.Index = &.{};

if (extra.data.bits.has_cc_body) {
Expand All @@ -4828,6 +4831,8 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
} else if (extra.data.bits.has_ret_ty_ref) {
ret_ty_ref = @enumFromInt(zir.extra[extra_index]);
extra_index += 1;
} else {
ret_ty_ref = .void_type;
}

extra_index += @intFromBool(extra.data.bits.has_any_noalias);
Expand All @@ -4839,6 +4844,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
.ret_ty_ref = ret_ty_ref,
.ret_ty_body = ret_ty_body,
.body = body,
.ies = extra.data.bits.is_inferred_error,
};
},
else => unreachable,
Expand All @@ -4860,6 +4866,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
.ret_ty_ref = info.ret_ty_ref,
.body = info.body,
.total_params_len = total_params_len,
.inferred_error_set = info.ies,
};
}

Expand Down
Loading