| ... | ... | @@ -5227,6 +5227,8 @@ fn zirStr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 5227 | 5227 | fn addStrLit(sema: *Sema, block: *Block, bytes: []const u8) CompileError!Air.Inst.Ref { |
| 5228 | 5228 | const mod = sema.mod; |
| 5229 | 5229 | const gpa = sema.gpa; |
| 5230 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 5231 | const duped_bytes = try sema.arena.dupe(u8, bytes); |
| 5230 | 5232 | const ty = try mod.arrayType(.{ |
| 5231 | 5233 | .len = bytes.len, |
| 5232 | 5234 | .child = .u8_type, |
| ... | ... | @@ -5234,7 +5236,7 @@ fn addStrLit(sema: *Sema, block: *Block, bytes: []const u8) CompileError!Air.Ins |
| 5234 | 5236 | }); |
| 5235 | 5237 | const val = try mod.intern(.{ .aggregate = .{ |
| 5236 | 5238 | .ty = ty.toIntern(), |
| 5237 | | .storage = .{ .bytes = bytes }, |
| 5239 | .storage = .{ .bytes = duped_bytes }, |
| 5238 | 5240 | } }); |
| 5239 | 5241 | const gop = try mod.memoized_decls.getOrPut(gpa, val); |
| 5240 | 5242 | if (!gop.found_existing) { |
| ... | ... | @@ -11478,7 +11480,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 11478 | 11480 | operand_ty.fmt(mod), |
| 11479 | 11481 | }); |
| 11480 | 11482 | } |
| 11481 | | for (operand_ty.errorSetNames(mod)) |error_name_ip| { |
| 11483 | for (0..operand_ty.errorSetNames(mod).len) |i| { |
| 11484 | const error_name_ip = operand_ty.errorSetNames(mod)[i]; |
| 11482 | 11485 | const error_name = mod.intern_pool.stringToSlice(error_name_ip); |
| 11483 | 11486 | if (seen_errors.contains(error_name)) continue; |
| 11484 | 11487 | cases_len += 1; |
| ... | ... | @@ -15851,7 +15854,8 @@ fn zirBuiltinSrc( |
| 15851 | 15854 | const func_name_val = blk: { |
| 15852 | 15855 | var anon_decl = try block.startAnonDecl(); |
| 15853 | 15856 | defer anon_decl.deinit(); |
| 15854 | | const name = mod.intern_pool.stringToSlice(fn_owner_decl.name); |
| 15857 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 15858 | const name = try sema.arena.dupe(u8, mod.intern_pool.stringToSlice(fn_owner_decl.name)); |
| 15855 | 15859 | const new_decl_ty = try mod.arrayType(.{ |
| 15856 | 15860 | .len = name.len, |
| 15857 | 15861 | .child = .u8_type, |
| ... | ... | @@ -16287,7 +16291,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16287 | 16291 | const error_field_vals = if (ty.isAnyError(mod)) null else blk: { |
| 16288 | 16292 | const vals = try sema.arena.alloc(InternPool.Index, ty.errorSetNames(mod).len); |
| 16289 | 16293 | for (vals, 0..) |*field_val, i| { |
| 16290 | | const name = ip.stringToSlice(ty.errorSetNames(mod)[i]); |
| 16294 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 16295 | const name = try sema.arena.dupe(u8, ip.stringToSlice(ty.errorSetNames(mod)[i])); |
| 16291 | 16296 | const name_val = v: { |
| 16292 | 16297 | var anon_decl = try block.startAnonDecl(); |
| 16293 | 16298 | defer anon_decl.deinit(); |
| ... | ... | @@ -16417,8 +16422,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16417 | 16422 | |
| 16418 | 16423 | const enum_field_vals = try sema.arena.alloc(InternPool.Index, enum_type.names.len); |
| 16419 | 16424 | for (enum_field_vals, 0..) |*field_val, i| { |
| 16420 | | const name_ip = ip.indexToKey(ty.toIntern()).enum_type.names[i]; |
| 16421 | | const name = ip.stringToSlice(name_ip); |
| 16425 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 16426 | const name = try sema.arena.dupe(u8, ip.stringToSlice(ip.indexToKey(ty.toIntern()).enum_type.names[i])); |
| 16422 | 16427 | const name_val = v: { |
| 16423 | 16428 | var anon_decl = try block.startAnonDecl(); |
| 16424 | 16429 | defer anon_decl.deinit(); |
| ... | ... | @@ -16556,7 +16561,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16556 | 16561 | |
| 16557 | 16562 | for (union_field_vals, 0..) |*field_val, i| { |
| 16558 | 16563 | const field = union_fields.values()[i]; |
| 16559 | | const name = ip.stringToSlice(union_fields.keys()[i]); |
| 16564 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 16565 | const name = try sema.arena.dupe(u8, ip.stringToSlice(union_fields.keys()[i])); |
| 16560 | 16566 | const name_val = v: { |
| 16561 | 16567 | var anon_decl = try block.startAnonDecl(); |
| 16562 | 16568 | defer anon_decl.deinit(); |
| ... | ... | @@ -16714,9 +16720,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16714 | 16720 | const name_val = v: { |
| 16715 | 16721 | var anon_decl = try block.startAnonDecl(); |
| 16716 | 16722 | defer anon_decl.deinit(); |
| 16723 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 16717 | 16724 | const bytes = if (tuple.names.len != 0) |
| 16718 | 16725 | // https://github.com/ziglang/zig/issues/15709 |
| 16719 | | @as([]const u8, ip.stringToSlice(tuple.names[i])) |
| 16726 | try sema.arena.dupe(u8, ip.stringToSlice(ip.indexToKey(struct_ty.toIntern()).anon_struct_type.names[i])) |
| 16720 | 16727 | else |
| 16721 | 16728 | try std.fmt.allocPrint(sema.arena, "{d}", .{i}); |
| 16722 | 16729 | const new_decl_ty = try mod.arrayType(.{ |
| ... | ... | @@ -16771,7 +16778,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16771 | 16778 | struct_obj.fields.keys(), |
| 16772 | 16779 | struct_obj.fields.values(), |
| 16773 | 16780 | ) |*field_val, name_nts, field| { |
| 16774 | | const name = ip.stringToSlice(name_nts); |
| 16781 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 16782 | const name = try sema.arena.dupe(u8, ip.stringToSlice(name_nts)); |
| 16775 | 16783 | const name_val = v: { |
| 16776 | 16784 | var anon_decl = try block.startAnonDecl(); |
| 16777 | 16785 | defer anon_decl.deinit(); |
| ... | ... | @@ -17020,9 +17028,8 @@ fn typeInfoNamespaceDecls( |
| 17020 | 17028 | const name_val = v: { |
| 17021 | 17029 | var anon_decl = try block.startAnonDecl(); |
| 17022 | 17030 | defer anon_decl.deinit(); |
| 17023 | | // Protects the decl name slice from being invalidated at the call to intern(). |
| 17024 | | try ip.string_bytes.ensureUnusedCapacity(sema.gpa, ip.stringToSlice(decl.name).len + 1); |
| 17025 | | const name = ip.stringToSlice(decl.name); |
| 17031 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 17032 | const name = try sema.arena.dupe(u8, ip.stringToSlice(decl.name)); |
| 17026 | 17033 | const new_decl_ty = try mod.arrayType(.{ |
| 17027 | 17034 | .len = name.len, |
| 17028 | 17035 | .child = .u8_type, |
| ... | ... | @@ -19060,6 +19067,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19060 | 19067 | }; |
| 19061 | 19068 | return sema.failWithOwnedErrorMsg(msg); |
| 19062 | 19069 | }; |
| 19070 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 19063 | 19071 | const field_name = enum_ty.enumFieldName(field_index, mod); |
| 19064 | 19072 | return sema.addStrLit(block, ip.stringToSlice(field_name)); |
| 19065 | 19073 | } |
| ... | ... | @@ -19601,7 +19609,6 @@ fn zirReify( |
| 19601 | 19609 | // Tag type |
| 19602 | 19610 | const fields_len = try sema.usizeCast(block, src, fields_val.sliceLen(mod)); |
| 19603 | 19611 | var explicit_tags_seen: []bool = &.{}; |
| 19604 | | var explicit_enum_info: ?InternPool.Key.EnumType = null; |
| 19605 | 19612 | var enum_field_names: []InternPool.NullTerminatedString = &.{}; |
| 19606 | 19613 | if (tag_type_val.optionalValue(mod)) |payload_val| { |
| 19607 | 19614 | union_obj.tag_ty = payload_val.toType(); |
| ... | ... | @@ -19611,7 +19618,6 @@ fn zirReify( |
| 19611 | 19618 | else => return sema.fail(block, src, "Type.Union.tag_type must be an enum type", .{}), |
| 19612 | 19619 | }; |
| 19613 | 19620 | |
| 19614 | | explicit_enum_info = enum_type; |
| 19615 | 19621 | explicit_tags_seen = try sema.arena.alloc(bool, enum_type.names.len); |
| 19616 | 19622 | @memset(explicit_tags_seen, false); |
| 19617 | 19623 | } else { |
| ... | ... | @@ -19640,7 +19646,8 @@ fn zirReify( |
| 19640 | 19646 | enum_field_names[i] = field_name; |
| 19641 | 19647 | } |
| 19642 | 19648 | |
| 19643 | | if (explicit_enum_info) |tag_info| { |
| 19649 | if (explicit_tags_seen.len > 0) { |
| 19650 | const tag_info = ip.indexToKey(union_obj.tag_ty.toIntern()).enum_type; |
| 19644 | 19651 | const enum_index = tag_info.nameIndex(ip, field_name) orelse { |
| 19645 | 19652 | const msg = msg: { |
| 19646 | 19653 | const msg = try sema.errMsg(block, src, "no field named '{s}' in enum '{}'", .{ ip.stringToSlice(field_name), union_obj.tag_ty.fmt(mod) }); |
| ... | ... | @@ -19705,7 +19712,8 @@ fn zirReify( |
| 19705 | 19712 | } |
| 19706 | 19713 | } |
| 19707 | 19714 | |
| 19708 | | if (explicit_enum_info) |tag_info| { |
| 19715 | if (explicit_tags_seen.len > 0) { |
| 19716 | const tag_info = ip.indexToKey(union_obj.tag_ty.toIntern()).enum_type; |
| 19709 | 19717 | if (tag_info.names.len > fields_len) { |
| 19710 | 19718 | const msg = msg: { |
| 19711 | 19719 | const msg = try sema.errMsg(block, src, "enum field(s) missing in union", .{}); |
| ... | ... | @@ -31625,17 +31633,17 @@ fn resolvePeerTypes( |
| 31625 | 31633 | return chosen_ty; |
| 31626 | 31634 | } |
| 31627 | 31635 | |
| 31628 | | pub fn resolveFnTypes(sema: *Sema, fn_info: InternPool.Key.FuncType) CompileError!void { |
| 31636 | pub fn resolveFnTypes(sema: *Sema, fn_ty: Type) CompileError!void { |
| 31629 | 31637 | const mod = sema.mod; |
| 31630 | | try sema.resolveTypeFully(fn_info.return_type.toType()); |
| 31638 | try sema.resolveTypeFully(mod.typeToFunc(fn_ty).?.return_type.toType()); |
| 31631 | 31639 | |
| 31632 | | if (mod.comp.bin_file.options.error_return_tracing and fn_info.return_type.toType().isError(mod)) { |
| 31640 | if (mod.comp.bin_file.options.error_return_tracing and mod.typeToFunc(fn_ty).?.return_type.toType().isError(mod)) { |
| 31633 | 31641 | // Ensure the type exists so that backends can assume that. |
| 31634 | 31642 | _ = try sema.getBuiltinType("StackTrace"); |
| 31635 | 31643 | } |
| 31636 | 31644 | |
| 31637 | | for (fn_info.param_types) |param_ty| { |
| 31638 | | try sema.resolveTypeFully(param_ty.toType()); |
| 31645 | for (0..mod.typeToFunc(fn_ty).?.param_types.len) |i| { |
| 31646 | try sema.resolveTypeFully(mod.typeToFunc(fn_ty).?.param_types[i].toType()); |
| 31639 | 31647 | } |
| 31640 | 31648 | } |
| 31641 | 31649 | |
| ... | ... | @@ -33077,7 +33085,6 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 33077 | 33085 | var enum_field_names: []InternPool.NullTerminatedString = &.{}; |
| 33078 | 33086 | var enum_field_vals: std.AutoArrayHashMapUnmanaged(InternPool.Index, void) = .{}; |
| 33079 | 33087 | var explicit_tags_seen: []bool = &.{}; |
| 33080 | | var explicit_enum_info: ?InternPool.Key.EnumType = null; |
| 33081 | 33088 | if (tag_type_ref != .none) { |
| 33082 | 33089 | const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = src.node_offset.x }; |
| 33083 | 33090 | const provided_ty = try sema.resolveType(&block_scope, tag_ty_src, tag_type_ref); |
| ... | ... | @@ -33114,7 +33121,6 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 33114 | 33121 | }; |
| 33115 | 33122 | // The fields of the union must match the enum exactly. |
| 33116 | 33123 | // A flag per field is used to check for missing and extraneous fields. |
| 33117 | | explicit_enum_info = enum_type; |
| 33118 | 33124 | explicit_tags_seen = try sema.arena.alloc(bool, enum_type.names.len); |
| 33119 | 33125 | @memset(explicit_tags_seen, false); |
| 33120 | 33126 | } |
| ... | ... | @@ -33256,7 +33262,8 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 33256 | 33262 | return sema.failWithOwnedErrorMsg(msg); |
| 33257 | 33263 | } |
| 33258 | 33264 | |
| 33259 | | if (explicit_enum_info) |tag_info| { |
| 33265 | if (explicit_tags_seen.len > 0) { |
| 33266 | const tag_info = ip.indexToKey(union_obj.tag_ty.toIntern()).enum_type; |
| 33260 | 33267 | const enum_index = tag_info.nameIndex(ip, field_name) orelse { |
| 33261 | 33268 | const msg = msg: { |
| 33262 | 33269 | const ty_src = mod.fieldSrcLoc(union_obj.owner_decl, .{ |
| ... | ... | @@ -33346,7 +33353,8 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 33346 | 33353 | } |
| 33347 | 33354 | } |
| 33348 | 33355 | |
| 33349 | | if (explicit_enum_info) |tag_info| { |
| 33356 | if (explicit_tags_seen.len > 0) { |
| 33357 | const tag_info = ip.indexToKey(union_obj.tag_ty.toIntern()).enum_type; |
| 33350 | 33358 | if (tag_info.names.len > fields_len) { |
| 33351 | 33359 | const msg = msg: { |
| 33352 | 33360 | const msg = try sema.errMsg(&block_scope, src, "enum field(s) missing in union", .{}); |
| ... | ... | @@ -33706,9 +33714,10 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 33706 | 33714 | } |
| 33707 | 33715 | // In this case the struct has all comptime-known fields and |
| 33708 | 33716 | // therefore has one possible value. |
| 33717 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 33709 | 33718 | return (try mod.intern(.{ .aggregate = .{ |
| 33710 | 33719 | .ty = ty.toIntern(), |
| 33711 | | .storage = .{ .elems = tuple.values }, |
| 33720 | .storage = .{ .elems = try sema.arena.dupe(InternPool.Index, tuple.values) }, |
| 33712 | 33721 | } })).toValue(); |
| 33713 | 33722 | }, |
| 33714 | 33723 | |