Skip to content

Commit bc846c3

Browse files
authored
Merge pull request #22414 from mlugg/better-analyze-call
Sema: rewrite semantic analysis of function calls
2 parents 80a9f0b + 6a837e6 commit bc846c3

37 files changed

+798
-1177
lines changed

build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const assert = std.debug.assert;
1111
const DevEnv = @import("src/dev.zig").Env;
1212

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

1616
pub fn build(b: *std.Build) !void {
1717
const only_c = b.option(bool, "only-c", "Translate the Zig compiler to C code, with only the C backend enabled") orelse false;

lib/compiler/aro_translate_c.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ pub fn translate(
168168
context.pattern_list.deinit(gpa);
169169
}
170170

171+
@setEvalBranchQuota(2000);
171172
inline for (@typeInfo(std.zig.c_builtins).@"struct".decls) |decl| {
172173
const builtin_fn = try ZigTag.pub_var_simple.create(arena, .{
173174
.name = decl.name,

lib/std/math/log_int.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub fn log_int(comptime T: type, base: T, x: T) Log2Int(T) {
6161
}
6262

6363
test "log_int" {
64+
@setEvalBranchQuota(2000);
6465
// Test all unsigned integers with 2, 3, ..., 64 bits.
6566
// We cannot test 0 or 1 bits since base must be > 1.
6667
inline for (2..64 + 1) |bits| {

lib/std/os/windows.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,7 @@ fn mountmgrIsVolumeName(name: []const u16) bool {
14681468
}
14691469

14701470
test mountmgrIsVolumeName {
1471+
@setEvalBranchQuota(2000);
14711472
const L = std.unicode.utf8ToUtf16LeStringLiteral;
14721473
try std.testing.expect(mountmgrIsVolumeName(L("\\\\?\\Volume{383da0b0-717f-41b6-8c36-00500992b58d}")));
14731474
try std.testing.expect(mountmgrIsVolumeName(L("\\??\\Volume{383da0b0-717f-41b6-8c36-00500992b58d}")));

lib/std/zig.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,8 @@ pub const SimpleComptimeReason = enum(u32) {
749749
array_mul_factor,
750750
slice_cat_operand,
751751
comptime_call_target,
752+
inline_call_target,
753+
generic_call_target,
752754
wasm_memory_index,
753755
work_group_dim_index,
754756

@@ -791,7 +793,6 @@ pub const SimpleComptimeReason = enum(u32) {
791793
struct_field_default_value,
792794
enum_field_tag_value,
793795
slice_single_item_ptr_bounds,
794-
comptime_param_arg,
795796
stored_to_comptime_field,
796797
stored_to_comptime_var,
797798
casted_to_comptime_enum,
@@ -828,6 +829,8 @@ pub const SimpleComptimeReason = enum(u32) {
828829
.array_mul_factor => "array multiplication factor must be comptime-known",
829830
.slice_cat_operand => "slice being concatenated must be comptime-known",
830831
.comptime_call_target => "function being called at comptime must be comptime-known",
832+
.inline_call_target => "function being called inline must be comptime-known",
833+
.generic_call_target => "generic function being called must be comptime-known",
831834
.wasm_memory_index => "wasm memory index must be comptime-known",
832835
.work_group_dim_index => "work group dimension index must be comptime-known",
833836

@@ -865,7 +868,6 @@ pub const SimpleComptimeReason = enum(u32) {
865868
.struct_field_default_value => "struct field default value must be comptime-known",
866869
.enum_field_tag_value => "enum field tag value must be comptime-known",
867870
.slice_single_item_ptr_bounds => "slice of single-item pointer must have comptime-known bounds",
868-
.comptime_param_arg => "argument to comptime parameter must be comptime-known",
869871
.stored_to_comptime_field => "value stored to a comptime field must be comptime-known",
870872
.stored_to_comptime_var => "value stored to a comptime variable must be comptime-known",
871873
.casted_to_comptime_enum => "value casted to enum with 'comptime_int' tag type must be comptime-known",

lib/std/zig/AstGen.zig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10209,9 +10209,6 @@ fn callExpr(
1020910209

1021010210
const callee = try calleeExpr(gz, scope, ri.rl, call.ast.fn_expr);
1021110211
const modifier: std.builtin.CallModifier = blk: {
10212-
if (gz.is_comptime) {
10213-
break :blk .compile_time;
10214-
}
1021510212
if (call.async_token != null) {
1021610213
break :blk .async_kw;
1021710214
}

lib/std/zig/Zir.zig

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4735,6 +4735,7 @@ pub const FnInfo = struct {
47354735
body: []const Inst.Index,
47364736
ret_ty_ref: Zir.Inst.Ref,
47374737
total_params_len: u32,
4738+
inferred_error_set: bool,
47384739
};
47394740

47404741
pub fn getParamBody(zir: Zir, fn_inst: Inst.Index) []const Zir.Inst.Index {
@@ -4774,8 +4775,9 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
47744775
body: []const Inst.Index,
47754776
ret_ty_ref: Inst.Ref,
47764777
ret_ty_body: []const Inst.Index,
4778+
ies: bool,
47774779
} = switch (tags[@intFromEnum(fn_inst)]) {
4778-
.func, .func_inferred => blk: {
4780+
.func, .func_inferred => |tag| blk: {
47794781
const inst_data = datas[@intFromEnum(fn_inst)].pl_node;
47804782
const extra = zir.extraData(Inst.Func, inst_data.payload_index);
47814783

@@ -4805,14 +4807,15 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
48054807
.ret_ty_ref = ret_ty_ref,
48064808
.ret_ty_body = ret_ty_body,
48074809
.body = body,
4810+
.ies = tag == .func_inferred,
48084811
};
48094812
},
48104813
.func_fancy => blk: {
48114814
const inst_data = datas[@intFromEnum(fn_inst)].pl_node;
48124815
const extra = zir.extraData(Inst.FuncFancy, inst_data.payload_index);
48134816

48144817
var extra_index: usize = extra.end;
4815-
var ret_ty_ref: Inst.Ref = .void_type;
4818+
var ret_ty_ref: Inst.Ref = .none;
48164819
var ret_ty_body: []const Inst.Index = &.{};
48174820

48184821
if (extra.data.bits.has_cc_body) {
@@ -4828,6 +4831,8 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
48284831
} else if (extra.data.bits.has_ret_ty_ref) {
48294832
ret_ty_ref = @enumFromInt(zir.extra[extra_index]);
48304833
extra_index += 1;
4834+
} else {
4835+
ret_ty_ref = .void_type;
48314836
}
48324837

48334838
extra_index += @intFromBool(extra.data.bits.has_any_noalias);
@@ -4839,6 +4844,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
48394844
.ret_ty_ref = ret_ty_ref,
48404845
.ret_ty_body = ret_ty_body,
48414846
.body = body,
4847+
.ies = extra.data.bits.is_inferred_error,
48424848
};
48434849
},
48444850
else => unreachable,
@@ -4860,6 +4866,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
48604866
.ret_ty_ref = info.ret_ty_ref,
48614867
.body = info.body,
48624868
.total_params_len = total_params_len,
4869+
.inferred_error_set = info.ies,
48634870
};
48644871
}
48654872

0 commit comments

Comments
 (0)