| author | |
| committer | |
| log | 6f08e172299320a3b243998878b38b0b3f43d8d5 |
| tree | 22ca949d513aa57651081ce831875e322666eb2a |
| parent | 0183b44bb10751c46bd520e673726a66c027b477 |
This should avoid the random pointer invalidation crashes.
Closes #189549 files changed, 70 insertions(+), 61 deletions(-)
src/Sema.zig+13-10| ... | @@ -12619,8 +12619,9 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12619,8 +12619,9 @@ fn analyzeSwitchRuntimeBlock( |
| 12619 | operand_ty.fmt(mod), | 12619 | operand_ty.fmt(mod), |
| 12620 | }); | 12620 | }); |
| 12621 | } | 12621 | } |
| 12622 | for (0..operand_ty.errorSetNames(mod).len) |i| { | 12622 | const error_names = operand_ty.errorSetNames(mod); |
| 12623 | const error_name = operand_ty.errorSetNames(mod)[i]; | 12623 | for (0..error_names.len) |name_index| { |
| 12624 | const error_name = error_names.get(ip)[name_index]; | ||
| 12624 | if (seen_errors.contains(error_name)) continue; | 12625 | if (seen_errors.contains(error_name)) continue; |
| 12625 | cases_len += 1; | 12626 | cases_len += 1; |
| 12626 | 12627 | ||
| ... | @@ -22362,8 +22363,9 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData | ... | @@ -22362,8 +22363,9 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData |
| 22362 | if (!operand_ty.isAnyError(mod) and operand_ty.errorSetIsEmpty(mod)) break :disjoint true; | 22363 | if (!operand_ty.isAnyError(mod) and operand_ty.errorSetIsEmpty(mod)) break :disjoint true; |
| 22363 | if (dest_ty.isAnyError(mod)) break :disjoint false; | 22364 | if (dest_ty.isAnyError(mod)) break :disjoint false; |
| 22364 | if (operand_ty.isAnyError(mod)) break :disjoint false; | 22365 | if (operand_ty.isAnyError(mod)) break :disjoint false; |
| 22365 | for (dest_ty.errorSetNames(mod)) |dest_err_name| { | 22366 | const dest_err_names = dest_ty.errorSetNames(mod); |
| 22366 | if (Type.errorSetHasFieldIp(ip, operand_ty.toIntern(), dest_err_name)) | 22367 | for (0..dest_err_names.len) |dest_err_index| { |
| 22368 | if (Type.errorSetHasFieldIp(ip, operand_ty.toIntern(), dest_err_names.get(ip)[dest_err_index])) | ||
| 22367 | break :disjoint false; | 22369 | break :disjoint false; |
| 22368 | } | 22370 | } |
| 22369 | 22371 | ||
| ... | @@ -22375,8 +22377,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData | ... | @@ -22375,8 +22377,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData |
| 22375 | 22377 | ||
| 22376 | _ = try sema.resolveInferredErrorSetTy(block, src, dest_ty.toIntern()); | 22378 | _ = try sema.resolveInferredErrorSetTy(block, src, dest_ty.toIntern()); |
| 22377 | _ = try sema.resolveInferredErrorSetTy(block, operand_src, operand_ty.toIntern()); | 22379 | _ = try sema.resolveInferredErrorSetTy(block, operand_src, operand_ty.toIntern()); |
| 22378 | for (dest_ty.errorSetNames(mod)) |dest_err_name| { | 22380 | for (0..dest_err_names.len) |dest_err_index| { |
| 22379 | if (Type.errorSetHasFieldIp(ip, operand_ty.toIntern(), dest_err_name)) | 22381 | if (Type.errorSetHasFieldIp(ip, operand_ty.toIntern(), dest_err_names.get(ip)[dest_err_index])) |
| 22380 | break :disjoint false; | 22382 | break :disjoint false; |
| 22381 | } | 22383 | } |
| 22382 | 22384 | ||
| ... | @@ -38780,17 +38782,18 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type { | ... | @@ -38780,17 +38782,18 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type { |
| 38780 | /// Asserts that lhs and rhs are both error sets and are resolved. | 38782 | /// Asserts that lhs and rhs are both error sets and are resolved. |
| 38781 | fn errorSetMerge(sema: *Sema, lhs: Type, rhs: Type) !Type { | 38783 | fn errorSetMerge(sema: *Sema, lhs: Type, rhs: Type) !Type { |
| 38782 | const mod = sema.mod; | 38784 | const mod = sema.mod; |
| 38785 | const ip = &mod.intern_pool; | ||
| 38783 | const arena = sema.arena; | 38786 | const arena = sema.arena; |
| 38784 | const lhs_names = lhs.errorSetNames(mod); | 38787 | const lhs_names = lhs.errorSetNames(mod); |
| 38785 | const rhs_names = rhs.errorSetNames(mod); | 38788 | const rhs_names = rhs.errorSetNames(mod); |
| 38786 | var names: InferredErrorSet.NameMap = .{}; | 38789 | var names: InferredErrorSet.NameMap = .{}; |
| 38787 | try names.ensureUnusedCapacity(arena, lhs_names.len); | 38790 | try names.ensureUnusedCapacity(arena, lhs_names.len); |
| 38788 | 38791 | ||
| 38789 | for (lhs_names) |name| { | 38792 | for (0..lhs_names.len) |lhs_index| { |
| 38790 | names.putAssumeCapacityNoClobber(name, {}); | 38793 | names.putAssumeCapacityNoClobber(lhs_names.get(ip)[lhs_index], {}); |
| 38791 | } | 38794 | } |
| 38792 | for (rhs_names) |name| { | 38795 | for (0..rhs_names.len) |rhs_index| { |
| 38793 | try names.put(arena, name, {}); | 38796 | try names.put(arena, rhs_names.get(ip)[rhs_index], {}); |
| 38794 | } | 38797 | } |
| 38795 | 38798 | ||
| 38796 | return mod.errorSetFromUnsortedNames(names.keys()); | 38799 | return mod.errorSetFromUnsortedNames(names.keys()); |
src/arch/wasm/CodeGen.zig+9-7| ... | @@ -7216,13 +7216,14 @@ fn airTagName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { | ... | @@ -7216,13 +7216,14 @@ fn airTagName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7216 | 7216 | ||
| 7217 | fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { | 7217 | fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { |
| 7218 | const mod = func.bin_file.base.comp.module.?; | 7218 | const mod = func.bin_file.base.comp.module.?; |
| 7219 | const ip = &mod.intern_pool; | ||
| 7219 | const enum_decl_index = enum_ty.getOwnerDecl(mod); | 7220 | const enum_decl_index = enum_ty.getOwnerDecl(mod); |
| 7220 | 7221 | ||
| 7221 | var arena_allocator = std.heap.ArenaAllocator.init(func.gpa); | 7222 | var arena_allocator = std.heap.ArenaAllocator.init(func.gpa); |
| 7222 | defer arena_allocator.deinit(); | 7223 | defer arena_allocator.deinit(); |
| 7223 | const arena = arena_allocator.allocator(); | 7224 | const arena = arena_allocator.allocator(); |
| 7224 | 7225 | ||
| 7225 | const fqn = mod.intern_pool.stringToSlice(try mod.declPtr(enum_decl_index).getFullyQualifiedName(mod)); | 7226 | const fqn = ip.stringToSlice(try mod.declPtr(enum_decl_index).getFullyQualifiedName(mod)); |
| 7226 | const func_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{s}", .{fqn}); | 7227 | const func_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{s}", .{fqn}); |
| 7227 | 7228 | ||
| 7228 | // check if we already generated code for this. | 7229 | // check if we already generated code for this. |
| ... | @@ -7252,9 +7253,9 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { | ... | @@ -7252,9 +7253,9 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { |
| 7252 | 7253 | ||
| 7253 | // TODO: Make switch implementation generic so we can use a jump table for this when the tags are not sparse. | 7254 | // TODO: Make switch implementation generic so we can use a jump table for this when the tags are not sparse. |
| 7254 | // generate an if-else chain for each tag value as well as constant. | 7255 | // generate an if-else chain for each tag value as well as constant. |
| 7255 | for (enum_ty.enumFields(mod), 0..) |tag_name_ip, field_index_usize| { | 7256 | const tag_names = enum_ty.enumFields(mod); |
| 7256 | const field_index = @as(u32, @intCast(field_index_usize)); | 7257 | for (0..tag_names.len) |tag_index| { |
| 7257 | const tag_name = mod.intern_pool.stringToSlice(tag_name_ip); | 7258 | const tag_name = ip.stringToSlice(tag_names.get(ip)[tag_index]); |
| 7258 | // for each tag name, create an unnamed const, | 7259 | // for each tag name, create an unnamed const, |
| 7259 | // and then get a pointer to its value. | 7260 | // and then get a pointer to its value. |
| 7260 | const name_ty = try mod.arrayType(.{ | 7261 | const name_ty = try mod.arrayType(.{ |
| ... | @@ -7279,7 +7280,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { | ... | @@ -7279,7 +7280,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { |
| 7279 | try writer.writeByte(std.wasm.opcode(.local_get)); | 7280 | try writer.writeByte(std.wasm.opcode(.local_get)); |
| 7280 | try leb.writeULEB128(writer, @as(u32, 1)); | 7281 | try leb.writeULEB128(writer, @as(u32, 1)); |
| 7281 | 7282 | ||
| 7282 | const tag_val = try mod.enumValueFieldIndex(enum_ty, field_index); | 7283 | const tag_val = try mod.enumValueFieldIndex(enum_ty, @intCast(tag_index)); |
| 7283 | const tag_value = try func.lowerConstant(tag_val, enum_ty); | 7284 | const tag_value = try func.lowerConstant(tag_val, enum_ty); |
| 7284 | 7285 | ||
| 7285 | switch (tag_value) { | 7286 | switch (tag_value) { |
| ... | @@ -7372,6 +7373,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { | ... | @@ -7372,6 +7373,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { |
| 7372 | 7373 | ||
| 7373 | fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { | 7374 | fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7374 | const mod = func.bin_file.base.comp.module.?; | 7375 | const mod = func.bin_file.base.comp.module.?; |
| 7376 | const ip = &mod.intern_pool; | ||
| 7375 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 7377 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 7376 | 7378 | ||
| 7377 | const operand = try func.resolveInst(ty_op.operand); | 7379 | const operand = try func.resolveInst(ty_op.operand); |
| ... | @@ -7384,8 +7386,8 @@ fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { | ... | @@ -7384,8 +7386,8 @@ fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7384 | 7386 | ||
| 7385 | var lowest: ?u32 = null; | 7387 | var lowest: ?u32 = null; |
| 7386 | var highest: ?u32 = null; | 7388 | var highest: ?u32 = null; |
| 7387 | for (names) |name| { | 7389 | for (0..names.len) |name_index| { |
| 7388 | const err_int = @as(Module.ErrorInt, @intCast(mod.global_error_set.getIndex(name).?)); | 7390 | const err_int: Module.ErrorInt = @intCast(mod.global_error_set.getIndex(names.get(ip)[name_index]).?); |
| 7389 | if (lowest) |*l| { | 7391 | if (lowest) |*l| { |
| 7390 | if (err_int < l.*) { | 7392 | if (err_int < l.*) { |
| 7391 | l.* = err_int; | 7393 | l.* = err_int; |
src/arch/x86_64/CodeGen.zig+7-6| ... | @@ -2187,6 +2187,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { | ... | @@ -2187,6 +2187,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 2187 | 2187 | ||
| 2188 | fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void { | 2188 | fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void { |
| 2189 | const mod = self.bin_file.comp.module.?; | 2189 | const mod = self.bin_file.comp.module.?; |
| 2190 | const ip = &mod.intern_pool; | ||
| 2190 | switch (lazy_sym.ty.zigTypeTag(mod)) { | 2191 | switch (lazy_sym.ty.zigTypeTag(mod)) { |
| 2191 | .Enum => { | 2192 | .Enum => { |
| 2192 | const enum_ty = lazy_sym.ty; | 2193 | const enum_ty = lazy_sym.ty; |
| ... | @@ -2209,10 +2210,10 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void { | ... | @@ -2209,10 +2210,10 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void { |
| 2209 | try self.genLazySymbolRef(.lea, data_reg, .{ .kind = .const_data, .ty = enum_ty }); | 2210 | try self.genLazySymbolRef(.lea, data_reg, .{ .kind = .const_data, .ty = enum_ty }); |
| 2210 | 2211 | ||
| 2211 | var data_off: i32 = 0; | 2212 | var data_off: i32 = 0; |
| 2212 | for (exitlude_jump_relocs, 0..) |*exitlude_jump_reloc, index_usize| { | 2213 | const tag_names = enum_ty.enumFields(mod); |
| 2213 | const index: u32 = @intCast(index_usize); | 2214 | for (exitlude_jump_relocs, 0..) |*exitlude_jump_reloc, tag_index| { |
| 2214 | const tag_name = mod.intern_pool.stringToSlice(enum_ty.enumFields(mod)[index_usize]); | 2215 | const tag_name_len = ip.stringToSlice(tag_names.get(ip)[tag_index]).len; |
| 2215 | const tag_val = try mod.enumValueFieldIndex(enum_ty, index); | 2216 | const tag_val = try mod.enumValueFieldIndex(enum_ty, @intCast(tag_index)); |
| 2216 | const tag_mcv = try self.genTypedValue(.{ .ty = enum_ty, .val = tag_val }); | 2217 | const tag_mcv = try self.genTypedValue(.{ .ty = enum_ty, .val = tag_val }); |
| 2217 | try self.genBinOpMir(.{ ._, .cmp }, enum_ty, enum_mcv, tag_mcv); | 2218 | try self.genBinOpMir(.{ ._, .cmp }, enum_ty, enum_mcv, tag_mcv); |
| 2218 | const skip_reloc = try self.asmJccReloc(.ne, undefined); | 2219 | const skip_reloc = try self.asmJccReloc(.ne, undefined); |
| ... | @@ -2228,14 +2229,14 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void { | ... | @@ -2228,14 +2229,14 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void { |
| 2228 | .{ .reg = ret_reg }, | 2229 | .{ .reg = ret_reg }, |
| 2229 | 8, | 2230 | 8, |
| 2230 | Type.usize, | 2231 | Type.usize, |
| 2231 | .{ .immediate = tag_name.len }, | 2232 | .{ .immediate = tag_name_len }, |
| 2232 | .{}, | 2233 | .{}, |
| 2233 | ); | 2234 | ); |
| 2234 | 2235 | ||
| 2235 | exitlude_jump_reloc.* = try self.asmJmpReloc(undefined); | 2236 | exitlude_jump_reloc.* = try self.asmJmpReloc(undefined); |
| 2236 | self.performReloc(skip_reloc); | 2237 | self.performReloc(skip_reloc); |
| 2237 | 2238 | ||
| 2238 | data_off += @intCast(tag_name.len + 1); | 2239 | data_off += @intCast(tag_name_len + 1); |
| 2239 | } | 2240 | } |
| 2240 | 2241 | ||
| 2241 | try self.airTrap(); | 2242 | try self.airTrap(); |
src/codegen.zig+4-2| ... | @@ -119,6 +119,7 @@ pub fn generateLazySymbol( | ... | @@ -119,6 +119,7 @@ pub fn generateLazySymbol( |
| 119 | 119 | ||
| 120 | const comp = bin_file.comp; | 120 | const comp = bin_file.comp; |
| 121 | const zcu = comp.module.?; | 121 | const zcu = comp.module.?; |
| 122 | const ip = &zcu.intern_pool; | ||
| 122 | const target = comp.root_mod.resolved_target.result; | 123 | const target = comp.root_mod.resolved_target.result; |
| 123 | const endian = target.cpu.arch.endian(); | 124 | const endian = target.cpu.arch.endian(); |
| 124 | const gpa = comp.gpa; | 125 | const gpa = comp.gpa; |
| ... | @@ -151,8 +152,9 @@ pub fn generateLazySymbol( | ... | @@ -151,8 +152,9 @@ pub fn generateLazySymbol( |
| 151 | return Result.ok; | 152 | return Result.ok; |
| 152 | } else if (lazy_sym.ty.zigTypeTag(zcu) == .Enum) { | 153 | } else if (lazy_sym.ty.zigTypeTag(zcu) == .Enum) { |
| 153 | alignment.* = .@"1"; | 154 | alignment.* = .@"1"; |
| 154 | for (lazy_sym.ty.enumFields(zcu)) |tag_name_ip| { | 155 | const tag_names = lazy_sym.ty.enumFields(zcu); |
| 155 | const tag_name = zcu.intern_pool.stringToSlice(tag_name_ip); | 156 | for (0..tag_names.len) |tag_index| { |
| 157 | const tag_name = zcu.intern_pool.stringToSlice(tag_names.get(ip)[tag_index]); | ||
| 156 | try code.ensureUnusedCapacity(tag_name.len + 1); | 158 | try code.ensureUnusedCapacity(tag_name.len + 1); |
| 157 | code.appendSliceAssumeCapacity(tag_name); | 159 | code.appendSliceAssumeCapacity(tag_name); |
| 158 | code.appendAssumeCapacity(0); | 160 | code.appendAssumeCapacity(0); |
src/codegen/c.zig+13-11| ... | @@ -2595,6 +2595,7 @@ pub fn genGlobalAsm(mod: *Module, writer: anytype) !void { | ... | @@ -2595,6 +2595,7 @@ pub fn genGlobalAsm(mod: *Module, writer: anytype) !void { |
| 2595 | 2595 | ||
| 2596 | pub fn genErrDecls(o: *Object) !void { | 2596 | pub fn genErrDecls(o: *Object) !void { |
| 2597 | const mod = o.dg.module; | 2597 | const mod = o.dg.module; |
| 2598 | const ip = &mod.intern_pool; | ||
| 2598 | const writer = o.writer(); | 2599 | const writer = o.writer(); |
| 2599 | 2600 | ||
| 2600 | var max_name_len: usize = 0; | 2601 | var max_name_len: usize = 0; |
| ... | @@ -2603,7 +2604,7 @@ pub fn genErrDecls(o: *Object) !void { | ... | @@ -2603,7 +2604,7 @@ pub fn genErrDecls(o: *Object) !void { |
| 2603 | try writer.writeAll("enum {\n"); | 2604 | try writer.writeAll("enum {\n"); |
| 2604 | o.indent_writer.pushIndent(); | 2605 | o.indent_writer.pushIndent(); |
| 2605 | for (mod.global_error_set.keys()[1..], 1..) |name_nts, value| { | 2606 | for (mod.global_error_set.keys()[1..], 1..) |name_nts, value| { |
| 2606 | const name = mod.intern_pool.stringToSlice(name_nts); | 2607 | const name = ip.stringToSlice(name_nts); |
| 2607 | max_name_len = @max(name.len, max_name_len); | 2608 | max_name_len = @max(name.len, max_name_len); |
| 2608 | const err_val = try mod.intern(.{ .err = .{ | 2609 | const err_val = try mod.intern(.{ .err = .{ |
| 2609 | .ty = .anyerror_type, | 2610 | .ty = .anyerror_type, |
| ... | @@ -2621,8 +2622,8 @@ pub fn genErrDecls(o: *Object) !void { | ... | @@ -2621,8 +2622,8 @@ pub fn genErrDecls(o: *Object) !void { |
| 2621 | defer o.dg.gpa.free(name_buf); | 2622 | defer o.dg.gpa.free(name_buf); |
| 2622 | 2623 | ||
| 2623 | @memcpy(name_buf[0..name_prefix.len], name_prefix); | 2624 | @memcpy(name_buf[0..name_prefix.len], name_prefix); |
| 2624 | for (mod.global_error_set.keys()) |name_nts| { | 2625 | for (mod.global_error_set.keys()) |name_ip| { |
| 2625 | const name = mod.intern_pool.stringToSlice(name_nts); | 2626 | const name = ip.stringToSlice(name_ip); |
| 2626 | @memcpy(name_buf[name_prefix.len..][0..name.len], name); | 2627 | @memcpy(name_buf[name_prefix.len..][0..name.len], name); |
| 2627 | const identifier = name_buf[0 .. name_prefix.len + name.len]; | 2628 | const identifier = name_buf[0 .. name_prefix.len + name.len]; |
| 2628 | 2629 | ||
| ... | @@ -2652,7 +2653,7 @@ pub fn genErrDecls(o: *Object) !void { | ... | @@ -2652,7 +2653,7 @@ pub fn genErrDecls(o: *Object) !void { |
| 2652 | try o.dg.renderTypeAndName(writer, name_array_ty, .{ .identifier = array_identifier }, Const, .none, .complete); | 2653 | try o.dg.renderTypeAndName(writer, name_array_ty, .{ .identifier = array_identifier }, Const, .none, .complete); |
| 2653 | try writer.writeAll(" = {"); | 2654 | try writer.writeAll(" = {"); |
| 2654 | for (mod.global_error_set.keys(), 0..) |name_nts, value| { | 2655 | for (mod.global_error_set.keys(), 0..) |name_nts, value| { |
| 2655 | const name = mod.intern_pool.stringToSlice(name_nts); | 2656 | const name = ip.stringToSlice(name_nts); |
| 2656 | if (value != 0) try writer.writeByte(','); | 2657 | if (value != 0) try writer.writeByte(','); |
| 2657 | 2658 | ||
| 2658 | const len_val = try mod.intValue(Type.usize, name.len); | 2659 | const len_val = try mod.intValue(Type.usize, name.len); |
| ... | @@ -2730,6 +2731,7 @@ fn genExports(o: *Object) !void { | ... | @@ -2730,6 +2731,7 @@ fn genExports(o: *Object) !void { |
| 2730 | 2731 | ||
| 2731 | pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void { | 2732 | pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void { |
| 2732 | const mod = o.dg.module; | 2733 | const mod = o.dg.module; |
| 2734 | const ip = &mod.intern_pool; | ||
| 2733 | const w = o.writer(); | 2735 | const w = o.writer(); |
| 2734 | const key = lazy_fn.key_ptr.*; | 2736 | const key = lazy_fn.key_ptr.*; |
| 2735 | const val = lazy_fn.value_ptr; | 2737 | const val = lazy_fn.value_ptr; |
| ... | @@ -2747,23 +2749,23 @@ pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void { | ... | @@ -2747,23 +2749,23 @@ pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void { |
| 2747 | try w.writeByte('('); | 2749 | try w.writeByte('('); |
| 2748 | try o.dg.renderTypeAndName(w, enum_ty, .{ .identifier = "tag" }, Const, .none, .complete); | 2750 | try o.dg.renderTypeAndName(w, enum_ty, .{ .identifier = "tag" }, Const, .none, .complete); |
| 2749 | try w.writeAll(") {\n switch (tag) {\n"); | 2751 | try w.writeAll(") {\n switch (tag) {\n"); |
| 2750 | for (enum_ty.enumFields(mod), 0..) |name_ip, index_usize| { | 2752 | const tag_names = enum_ty.enumFields(mod); |
| 2751 | const index = @as(u32, @intCast(index_usize)); | 2753 | for (0..tag_names.len) |tag_index| { |
| 2752 | const name = mod.intern_pool.stringToSlice(name_ip); | 2754 | const tag_name = ip.stringToSlice(tag_names.get(ip)[tag_index]); |
| 2753 | const tag_val = try mod.enumValueFieldIndex(enum_ty, index); | 2755 | const tag_val = try mod.enumValueFieldIndex(enum_ty, @intCast(tag_index)); |
| 2754 | 2756 | ||
| 2755 | const int_val = try tag_val.intFromEnum(enum_ty, mod); | 2757 | const int_val = try tag_val.intFromEnum(enum_ty, mod); |
| 2756 | 2758 | ||
| 2757 | const name_ty = try mod.arrayType(.{ | 2759 | const name_ty = try mod.arrayType(.{ |
| 2758 | .len = name.len, | 2760 | .len = tag_name.len, |
| 2759 | .child = .u8_type, | 2761 | .child = .u8_type, |
| 2760 | .sentinel = .zero_u8, | 2762 | .sentinel = .zero_u8, |
| 2761 | }); | 2763 | }); |
| 2762 | const name_val = try mod.intern(.{ .aggregate = .{ | 2764 | const name_val = try mod.intern(.{ .aggregate = .{ |
| 2763 | .ty = name_ty.toIntern(), | 2765 | .ty = name_ty.toIntern(), |
| 2764 | .storage = .{ .bytes = name }, | 2766 | .storage = .{ .bytes = tag_name }, |
| 2765 | } }); | 2767 | } }); |
| 2766 | const len_val = try mod.intValue(Type.usize, name.len); | 2768 | const len_val = try mod.intValue(Type.usize, tag_name.len); |
| 2767 | 2769 | ||
| 2768 | try w.print(" case {}: {{\n static ", .{ | 2770 | try w.print(" case {}: {{\n static ", .{ |
| 2769 | try o.dg.fmtIntLiteral(enum_ty, int_val, .Other), | 2771 | try o.dg.fmtIntLiteral(enum_ty, int_val, .Other), |
src/codegen/llvm.zig+3-2| ... | @@ -9574,6 +9574,7 @@ pub const FuncGen = struct { | ... | @@ -9574,6 +9574,7 @@ pub const FuncGen = struct { |
| 9574 | fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 9574 | fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 9575 | const o = self.dg.object; | 9575 | const o = self.dg.object; |
| 9576 | const mod = o.module; | 9576 | const mod = o.module; |
| 9577 | const ip = &mod.intern_pool; | ||
| 9577 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; | 9578 | const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 9578 | const operand = try self.resolveInst(ty_op.operand); | 9579 | const operand = try self.resolveInst(ty_op.operand); |
| 9579 | const error_set_ty = ty_op.ty.toType(); | 9580 | const error_set_ty = ty_op.ty.toType(); |
| ... | @@ -9585,8 +9586,8 @@ pub const FuncGen = struct { | ... | @@ -9585,8 +9586,8 @@ pub const FuncGen = struct { |
| 9585 | var wip_switch = try self.wip.@"switch"(operand, invalid_block, @intCast(names.len)); | 9586 | var wip_switch = try self.wip.@"switch"(operand, invalid_block, @intCast(names.len)); |
| 9586 | defer wip_switch.finish(&self.wip); | 9587 | defer wip_switch.finish(&self.wip); |
| 9587 | 9588 | ||
| 9588 | for (names) |name| { | 9589 | for (0..names.len) |name_index| { |
| 9589 | const err_int = mod.global_error_set.getIndex(name).?; | 9590 | const err_int = mod.global_error_set.getIndex(names.get(ip)[name_index]).?; |
| 9590 | const this_tag_int_value = try o.builder.intConst(try o.errorIntType(), err_int); | 9591 | const this_tag_int_value = try o.builder.intConst(try o.errorIntType(), err_int); |
| 9591 | try wip_switch.addCase(this_tag_int_value, valid_block, &self.wip); | 9592 | try wip_switch.addCase(this_tag_int_value, valid_block, &self.wip); |
| 9592 | } | 9593 | } |
src/link/Dwarf.zig+1-1| ... | @@ -2828,7 +2828,7 @@ fn addDbgInfoErrorSet( | ... | @@ -2828,7 +2828,7 @@ fn addDbgInfoErrorSet( |
| 2828 | target: std.Target, | 2828 | target: std.Target, |
| 2829 | dbg_info_buffer: *std.ArrayList(u8), | 2829 | dbg_info_buffer: *std.ArrayList(u8), |
| 2830 | ) !void { | 2830 | ) !void { |
| 2831 | return addDbgInfoErrorSetNames(mod, ty, ty.errorSetNames(mod), target, dbg_info_buffer); | 2831 | return addDbgInfoErrorSetNames(mod, ty, ty.errorSetNames(mod).get(&mod.intern_pool), target, dbg_info_buffer); |
| 2832 | } | 2832 | } |
| 2833 | 2833 | ||
| 2834 | fn addDbgInfoErrorSetNames( | 2834 | fn addDbgInfoErrorSetNames( |
src/type.zig+5-6| ... | @@ -2908,22 +2908,21 @@ pub const Type = struct { | ... | @@ -2908,22 +2908,21 @@ pub const Type = struct { |
| 2908 | 2908 | ||
| 2909 | // Asserts that `ty` is an error set and not `anyerror`. | 2909 | // Asserts that `ty` is an error set and not `anyerror`. |
| 2910 | // Asserts that `ty` is resolved if it is an inferred error set. | 2910 | // Asserts that `ty` is resolved if it is an inferred error set. |
| 2911 | pub fn errorSetNames(ty: Type, mod: *Module) []const InternPool.NullTerminatedString { | 2911 | pub fn errorSetNames(ty: Type, mod: *Module) InternPool.NullTerminatedString.Slice { |
| 2912 | const ip = &mod.intern_pool; | 2912 | const ip = &mod.intern_pool; |
| 2913 | return switch (ip.indexToKey(ty.toIntern())) { | 2913 | return switch (ip.indexToKey(ty.toIntern())) { |
| 2914 | .error_set_type => |x| x.names.get(ip), | 2914 | .error_set_type => |x| x.names, |
| 2915 | .inferred_error_set_type => |i| switch (ip.funcIesResolved(i).*) { | 2915 | .inferred_error_set_type => |i| switch (ip.funcIesResolved(i).*) { |
| 2916 | .none => unreachable, // unresolved inferred error set | 2916 | .none => unreachable, // unresolved inferred error set |
| 2917 | .anyerror_type => unreachable, | 2917 | .anyerror_type => unreachable, |
| 2918 | else => |t| ip.indexToKey(t).error_set_type.names.get(ip), | 2918 | else => |t| ip.indexToKey(t).error_set_type.names, |
| 2919 | }, | 2919 | }, |
| 2920 | else => unreachable, | 2920 | else => unreachable, |
| 2921 | }; | 2921 | }; |
| 2922 | } | 2922 | } |
| 2923 | 2923 | ||
| 2924 | pub fn enumFields(ty: Type, mod: *Module) []const InternPool.NullTerminatedString { | 2924 | pub fn enumFields(ty: Type, mod: *Module) InternPool.NullTerminatedString.Slice { |
| 2925 | const ip = &mod.intern_pool; | 2925 | return mod.intern_pool.indexToKey(ty.toIntern()).enum_type.names; |
| 2926 | return ip.indexToKey(ty.toIntern()).enum_type.names.get(ip); | ||
| 2927 | } | 2926 | } |
| 2928 | 2927 | ||
| 2929 | pub fn enumFieldCount(ty: Type, mod: *Module) usize { | 2928 | pub fn enumFieldCount(ty: Type, mod: *Module) usize { |
test/cbe.zig+15-16| ... | @@ -219,23 +219,22 @@ pub fn addCases(ctx: *Cases, b: *std.Build) !void { | ... | @@ -219,23 +219,22 @@ pub fn addCases(ctx: *Cases, b: *std.Build) !void { |
| 219 | , ""); | 219 | , ""); |
| 220 | } | 220 | } |
| 221 | 221 | ||
| 222 | // https://github.com/ziglang/zig/issues/18954 | 222 | { |
| 223 | //{ | 223 | var case = ctx.exeFromCompiledC("inferred local const and var", .{}, b); |
| 224 | // var case = ctx.exeFromCompiledC("inferred local const and var", .{}, b); | ||
| 225 | 224 | ||
| 226 | // case.addCompareOutput( | 225 | case.addCompareOutput( |
| 227 | // \\fn add(a: i32, b: i32) i32 { | 226 | \\fn add(a: i32, b: i32) i32 { |
| 228 | // \\ return a + b; | 227 | \\ return a + b; |
| 229 | // \\} | 228 | \\} |
| 230 | // \\ | 229 | \\ |
| 231 | // \\pub export fn main() c_int { | 230 | \\pub export fn main() c_int { |
| 232 | // \\ const x = add(1, 2); | 231 | \\ const x = add(1, 2); |
| 233 | // \\ var y = add(3, 0); | 232 | \\ var y = add(3, 0); |
| 234 | // \\ y -= x; | 233 | \\ y -= x; |
| 235 | // \\ return y; | 234 | \\ return y; |
| 236 | // \\} | 235 | \\} |
| 237 | // , ""); | 236 | , ""); |
| 238 | //} | 237 | } |
| 239 | { | 238 | { |
| 240 | var case = ctx.exeFromCompiledC("control flow", .{}, b); | 239 | var case = ctx.exeFromCompiledC("control flow", .{}, b); |
| 241 | 240 |