authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-20 14:03:55-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-20 14:03:55-07:00
log328ec15d9cae0373c1f973699c392db5b63ab886
tree2c81e060907538a5668ffe03b54a114b56e2fe03
parent6dc45e7d3186f81b1329c71b6380ff3ddd5dec41

Revert "make distinct error limit configurable"

This reverts commit 78855bd21866b515018259a2194e036e4b3120df. This commit did not replace uses of `Type.err_int` of which there are currently 60 uses. Re-opens #786

5 files changed, 28 insertions(+), 81 deletions(-)

src/Compilation.zig-23
......@@ -739,7 +739,6 @@ pub const InitOptions = struct {
739739 pdb_source_path: ?[]const u8 = null,
740740 /// (Windows) PDB output path
741741 pdb_out_path: ?[]const u8 = null,
742 error_limit: ?Module.ErrorInt = null,
743742};
744743
745744fn addModuleTableToCacheHash(
......@@ -1433,7 +1432,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
14331432 .local_zir_cache = local_zir_cache,
14341433 .emit_h = emit_h,
14351434 .tmp_hack_arena = std.heap.ArenaAllocator.init(gpa),
1436 .error_limit = options.error_limit orelse (std.math.maxInt(u16) - 1),
14371435 };
14381436 try module.init();
14391437
......@@ -2488,7 +2486,6 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
24882486 man.hash.add(comp.bin_file.options.skip_linker_dependencies);
24892487 man.hash.add(comp.bin_file.options.parent_compilation_link_libc);
24902488 man.hash.add(mod.emit_h != null);
2491 man.hash.add(mod.error_limit);
24922489 }
24932490
24942491 try man.addOptionalFile(comp.bin_file.options.linker_script);
......@@ -2869,10 +2866,6 @@ pub fn totalErrorCount(self: *Compilation) u32 {
28692866 }
28702867 }
28712868 }
2872
2873 if (module.global_error_set.entries.len - 1 > module.error_limit) {
2874 total += 1;
2875 }
28762869 }
28772870
28782871 // The "no entry point found" error only counts if there are no semantic analysis errors.
......@@ -3023,22 +3016,6 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle {
30233016 for (module.failed_exports.values()) |value| {
30243017 try addModuleErrorMsg(module, &bundle, value.*);
30253018 }
3026
3027 const actual_error_count = module.global_error_set.entries.len - 1;
3028 if (actual_error_count > module.error_limit) {
3029 try bundle.addRootErrorMessage(.{
3030 .msg = try bundle.printString("module used more errors than possible: used {d}, max {d}", .{
3031 actual_error_count, module.error_limit,
3032 }),
3033 .notes_len = 1,
3034 });
3035 const notes_start = try bundle.reserveNotes(1);
3036 bundle.extra.items[notes_start] = @intFromEnum(try bundle.addErrorMessage(.{
3037 .msg = try bundle.printString("use '--error-limit {d}' to increase limit", .{
3038 actual_error_count,
3039 }),
3040 }));
3041 }
30423019 }
30433020
30443021 if (bundle.root_list.items.len == 0) {
src/Module.zig-8
......@@ -137,9 +137,6 @@ deletion_set: std.AutoArrayHashMapUnmanaged(Decl.Index, void) = .{},
137137/// Key is the error name, index is the error tag value. Index 0 has a length-0 string.
138138global_error_set: GlobalErrorSet = .{},
139139
140/// Maximum amount of distinct error values, set by --error-limit
141error_limit: ErrorInt,
142
143140/// Incrementing integer used to compare against the corresponding Decl
144141/// field to determine whether a Decl's status applies to an ongoing update, or a
145142/// previous analysis.
......@@ -5023,11 +5020,6 @@ pub fn getErrorValueFromSlice(
50235020 return getErrorValue(mod, interned_name);
50245021}
50255022
5026pub fn errorSetBits(mod: *Module) u16 {
5027 if (mod.error_limit == 0) return 0;
5028 return std.math.log2_int_ceil(ErrorInt, mod.error_limit + 1); // +1 for no error
5029}
5030
50315023pub fn createAnonymousDecl(mod: *Module, block: *Sema.Block, typed_value: TypedValue) !Decl.Index {
50325024 const src_decl = mod.declPtr(block.src_decl);
50335025 return mod.createAnonymousDeclFromDecl(src_decl, block.namespace, block.wip_capture_scope, typed_value);
src/main.zig-9
......@@ -421,7 +421,6 @@ const usage_build_generic =
421421 \\ --deps [dep],[dep],... Set dependency names for the root package
422422 \\ dep: [[import=]name]
423423 \\ --main-mod-path Set the directory of the root module
424 \\ --error-limit [num] Set the maximum amount of distinct error values
425424 \\ -fPIC Force-enable Position Independent Code
426425 \\ -fno-PIC Force-disable Position Independent Code
427426 \\ -fPIE Force-enable Position Independent Executable
......@@ -912,8 +911,6 @@ fn buildOutputType(
912911 var error_tracing: ?bool = null;
913912 var pdb_out_path: ?[]const u8 = null;
914913 var dwarf_format: ?std.dwarf.Format = null;
915 var error_limit: ?Module.ErrorInt = null;
916
917914 // e.g. -m3dnow or -mno-outline-atomics. They correspond to std.Target llvm cpu feature names.
918915 // This array is populated by zig cc frontend and then has to be converted to zig-style
919916 // CPU features.
......@@ -1043,11 +1040,6 @@ fn buildOutputType(
10431040 root_deps_str = args_iter.nextOrFatal();
10441041 } else if (mem.eql(u8, arg, "--main-mod-path")) {
10451042 main_mod_path = args_iter.nextOrFatal();
1046 } else if (mem.eql(u8, arg, "--error-limit")) {
1047 const next_arg = args_iter.nextOrFatal();
1048 error_limit = std.fmt.parseUnsigned(Module.ErrorInt, next_arg, 0) catch |err| {
1049 fatal("unable to parse error limit '{s}': {s}", .{ next_arg, @errorName(err) });
1050 };
10511043 } else if (mem.eql(u8, arg, "-cflags")) {
10521044 extra_cflags.shrinkRetainingCapacity(0);
10531045 while (true) {
......@@ -3554,7 +3546,6 @@ fn buildOutputType(
35543546 .reference_trace = reference_trace,
35553547 .error_tracing = error_tracing,
35563548 .pdb_out_path = pdb_out_path,
3557 .error_limit = error_limit,
35583549 }) catch |err| switch (err) {
35593550 error.LibCUnavailable => {
35603551 const target = target_info.target;
src/type.zig+20-26
......@@ -905,11 +905,8 @@ pub const Type = struct {
905905 .opt_type => return abiAlignmentAdvancedOptional(ty, mod, strat),
906906 .error_union_type => |info| return abiAlignmentAdvancedErrorUnion(ty, mod, strat, info.payload_type.toType()),
907907
908 .error_set_type, .inferred_error_set_type => {
909 const bits = mod.errorSetBits();
910 if (bits == 0) return AbiAlignmentAdvanced{ .scalar = .@"1" };
911 return .{ .scalar = intAbiAlignment(bits, target) };
912 },
908 // TODO revisit this when we have the concept of the error tag type
909 .error_set_type, .inferred_error_set_type => return .{ .scalar = .@"2" },
913910
914911 // represents machine code; not a pointer
915912 .func_type => |func_type| return .{
......@@ -970,11 +967,10 @@ pub const Type = struct {
970967 else => return .{ .scalar = .@"16" },
971968 },
972969
973 .anyerror, .adhoc_inferred_error_set => {
974 const bits = mod.errorSetBits();
975 if (bits == 0) return AbiAlignmentAdvanced{ .scalar = .@"1" };
976 return .{ .scalar = intAbiAlignment(bits, target) };
977 },
970 // TODO revisit this when we have the concept of the error tag type
971 .anyerror,
972 .adhoc_inferred_error_set,
973 => return .{ .scalar = .@"2" },
978974
979975 .void,
980976 .type,
......@@ -1288,11 +1284,8 @@ pub const Type = struct {
12881284
12891285 .opt_type => return ty.abiSizeAdvancedOptional(mod, strat),
12901286
1291 .error_set_type, .inferred_error_set_type => {
1292 const bits = mod.errorSetBits();
1293 if (bits == 0) return AbiSizeAdvanced{ .scalar = 0 };
1294 return AbiSizeAdvanced{ .scalar = intAbiSize(bits, target) };
1295 },
1287 // TODO revisit this when we have the concept of the error tag type
1288 .error_set_type, .inferred_error_set_type => return AbiSizeAdvanced{ .scalar = 2 },
12961289
12971290 .error_union_type => |error_union_type| {
12981291 const payload_ty = error_union_type.payload_type.toType();
......@@ -1386,11 +1379,10 @@ pub const Type = struct {
13861379 .enum_literal,
13871380 => return AbiSizeAdvanced{ .scalar = 0 },
13881381
1389 .anyerror, .adhoc_inferred_error_set => {
1390 const bits = mod.errorSetBits();
1391 if (bits == 0) return AbiSizeAdvanced{ .scalar = 0 };
1392 return AbiSizeAdvanced{ .scalar = intAbiSize(bits, target) };
1393 },
1382 // TODO revisit this when we have the concept of the error tag type
1383 .anyerror,
1384 .adhoc_inferred_error_set,
1385 => return AbiSizeAdvanced{ .scalar = 2 },
13941386
13951387 .prefetch_options => unreachable, // missing call to resolveTypeFields
13961388 .export_options => unreachable, // missing call to resolveTypeFields
......@@ -1584,7 +1576,8 @@ pub const Type = struct {
15841576 return (try abiSizeAdvanced(ty, mod, strat)).scalar * 8;
15851577 },
15861578
1587 .error_set_type, .inferred_error_set_type => return mod.errorSetBits(),
1579 // TODO revisit this when we have the concept of the error tag type
1580 .error_set_type, .inferred_error_set_type => return 16,
15881581
15891582 .error_union_type => {
15901583 // Optionals and error unions are not packed so their bitsize
......@@ -1617,9 +1610,10 @@ pub const Type = struct {
16171610 .bool => return 1,
16181611 .void => return 0,
16191612
1613 // TODO revisit this when we have the concept of the error tag type
16201614 .anyerror,
16211615 .adhoc_inferred_error_set,
1622 => return mod.errorSetBits(),
1616 => return 16,
16231617
16241618 .anyopaque => unreachable,
16251619 .type => unreachable,
......@@ -2178,7 +2172,8 @@ pub const Type = struct {
21782172
21792173 while (true) switch (ty.toIntern()) {
21802174 .anyerror_type, .adhoc_inferred_error_set_type => {
2181 return .{ .signedness = .unsigned, .bits = mod.errorSetBits() };
2175 // TODO revisit this when error sets support custom int types
2176 return .{ .signedness = .unsigned, .bits = 16 };
21822177 },
21832178 .usize_type => return .{ .signedness = .unsigned, .bits = target.ptrBitWidth() },
21842179 .isize_type => return .{ .signedness = .signed, .bits = target.ptrBitWidth() },
......@@ -2197,9 +2192,8 @@ pub const Type = struct {
21972192 .enum_type => |enum_type| ty = enum_type.tag_ty.toType(),
21982193 .vector_type => |vector_type| ty = vector_type.child.toType(),
21992194
2200 .error_set_type, .inferred_error_set_type => {
2201 return .{ .signedness = .unsigned, .bits = mod.errorSetBits() };
2202 },
2195 // TODO revisit this when error sets support custom int types
2196 .error_set_type, .inferred_error_set_type => return .{ .signedness = .unsigned, .bits = 16 },
22032197
22042198 .anon_struct_type => unreachable,
22052199
src/value.zig+8-15
......@@ -701,20 +701,15 @@ pub const Value = struct {
701701 }
702702 },
703703 .ErrorSet => {
704 const bits = mod.errorSetBits();
705 const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8);
706
704 // TODO revisit this when we have the concept of the error tag type
705 const Int = u16;
707706 const name = switch (ip.indexToKey(val.toIntern())) {
708707 .err => |err| err.name,
709708 .error_union => |error_union| error_union.val.err_name,
710709 else => unreachable,
711710 };
712 var bigint_buffer: BigIntSpace = undefined;
713 const bigint = BigIntMutable.init(
714 &bigint_buffer.limbs,
715 mod.global_error_set.getIndex(name).?,
716 ).toConst();
717 bigint.writeTwosComplement(buffer[0..byte_count], endian);
711 const int = @as(Module.ErrorInt, @intCast(mod.global_error_set.getIndex(name).?));
712 std.mem.writeInt(Int, buffer[0..@sizeOf(Int)], @as(Int, @intCast(int)), endian);
718713 },
719714 .Union => switch (ty.containerLayout(mod)) {
720715 .Auto => return error.IllDefinedMemoryLayout, // Sema is supposed to have emitted a compile error already
......@@ -992,12 +987,10 @@ pub const Value = struct {
992987 }
993988 },
994989 .ErrorSet => {
995 const bits = mod.errorSetBits();
996 const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8);
997 const int = std.mem.readVarInt(u64, buffer[0..byte_count], endian);
998 const index = (int << @as(u6, @intCast(64 - bits))) >> @as(u6, @intCast(64 - bits));
999 const name = mod.global_error_set.keys()[@intCast(index)];
1000
990 // TODO revisit this when we have the concept of the error tag type
991 const Int = u16;
992 const int = std.mem.readInt(Int, buffer[0..@sizeOf(Int)], endian);
993 const name = mod.global_error_set.keys()[@as(usize, @intCast(int))];
1001994 return (try mod.intern(.{ .err = .{
1002995 .ty = ty.toIntern(),
1003996 .name = name,