| author | |
| committer | |
| log | 275652f620541919087bc92da0d2f9e97c66d3c0 |
| tree | 0b19398252ef29e6b0a6c6758ac90f564a235f13 |
| parent | e94a81c951905a6b5bcf2a6028589ac1e33d1edd |
21 files changed, 935 insertions(+), 808 deletions(-)
src/Compilation.zig+11-13| ... | @@ -2048,7 +2048,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void | ... | @@ -2048,7 +2048,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void |
| 2048 | assert(decl.deletion_flag); | 2048 | assert(decl.deletion_flag); |
| 2049 | assert(decl.dependants.count() == 0); | 2049 | assert(decl.dependants.count() == 0); |
| 2050 | const is_anon = if (decl.zir_decl_index == 0) blk: { | 2050 | const is_anon = if (decl.zir_decl_index == 0) blk: { |
| 2051 | break :blk decl.src_namespace.anon_decls.swapRemove(decl_index); | 2051 | break :blk module.namespacePtr(decl.src_namespace).anon_decls.swapRemove(decl_index); |
| 2052 | } else false; | 2052 | } else false; |
| 2053 | 2053 | ||
| 2054 | try module.clearDecl(decl_index, null); | 2054 | try module.clearDecl(decl_index, null); |
| ... | @@ -2530,8 +2530,7 @@ pub fn totalErrorCount(self: *Compilation) u32 { | ... | @@ -2530,8 +2530,7 @@ pub fn totalErrorCount(self: *Compilation) u32 { |
| 2530 | // the previous parse success, including compile errors, but we cannot | 2530 | // the previous parse success, including compile errors, but we cannot |
| 2531 | // emit them until the file succeeds parsing. | 2531 | // emit them until the file succeeds parsing. |
| 2532 | for (module.failed_decls.keys()) |key| { | 2532 | for (module.failed_decls.keys()) |key| { |
| 2533 | const decl = module.declPtr(key); | 2533 | if (module.declFileScope(key).okToReportErrors()) { |
| 2534 | if (decl.getFileScope().okToReportErrors()) { | ||
| 2535 | total += 1; | 2534 | total += 1; |
| 2536 | if (module.cimport_errors.get(key)) |errors| { | 2535 | if (module.cimport_errors.get(key)) |errors| { |
| 2537 | total += errors.len; | 2536 | total += errors.len; |
| ... | @@ -2540,8 +2539,7 @@ pub fn totalErrorCount(self: *Compilation) u32 { | ... | @@ -2540,8 +2539,7 @@ pub fn totalErrorCount(self: *Compilation) u32 { |
| 2540 | } | 2539 | } |
| 2541 | if (module.emit_h) |emit_h| { | 2540 | if (module.emit_h) |emit_h| { |
| 2542 | for (emit_h.failed_decls.keys()) |key| { | 2541 | for (emit_h.failed_decls.keys()) |key| { |
| 2543 | const decl = module.declPtr(key); | 2542 | if (module.declFileScope(key).okToReportErrors()) { |
| 2544 | if (decl.getFileScope().okToReportErrors()) { | ||
| 2545 | total += 1; | 2543 | total += 1; |
| 2546 | } | 2544 | } |
| 2547 | } | 2545 | } |
| ... | @@ -2644,10 +2642,10 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { | ... | @@ -2644,10 +2642,10 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { |
| 2644 | { | 2642 | { |
| 2645 | var it = module.failed_decls.iterator(); | 2643 | var it = module.failed_decls.iterator(); |
| 2646 | while (it.next()) |entry| { | 2644 | while (it.next()) |entry| { |
| 2647 | const decl = module.declPtr(entry.key_ptr.*); | 2645 | const decl_index = entry.key_ptr.*; |
| 2648 | // Skip errors for Decls within files that had a parse failure. | 2646 | // Skip errors for Decls within files that had a parse failure. |
| 2649 | // We'll try again once parsing succeeds. | 2647 | // We'll try again once parsing succeeds. |
| 2650 | if (decl.getFileScope().okToReportErrors()) { | 2648 | if (module.declFileScope(decl_index).okToReportErrors()) { |
| 2651 | try addModuleErrorMsg(&bundle, entry.value_ptr.*.*); | 2649 | try addModuleErrorMsg(&bundle, entry.value_ptr.*.*); |
| 2652 | if (module.cimport_errors.get(entry.key_ptr.*)) |cimport_errors| for (cimport_errors) |c_error| { | 2650 | if (module.cimport_errors.get(entry.key_ptr.*)) |cimport_errors| for (cimport_errors) |c_error| { |
| 2653 | try bundle.addRootErrorMessage(.{ | 2651 | try bundle.addRootErrorMessage(.{ |
| ... | @@ -2669,10 +2667,10 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { | ... | @@ -2669,10 +2667,10 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { |
| 2669 | if (module.emit_h) |emit_h| { | 2667 | if (module.emit_h) |emit_h| { |
| 2670 | var it = emit_h.failed_decls.iterator(); | 2668 | var it = emit_h.failed_decls.iterator(); |
| 2671 | while (it.next()) |entry| { | 2669 | while (it.next()) |entry| { |
| 2672 | const decl = module.declPtr(entry.key_ptr.*); | 2670 | const decl_index = entry.key_ptr.*; |
| 2673 | // Skip errors for Decls within files that had a parse failure. | 2671 | // Skip errors for Decls within files that had a parse failure. |
| 2674 | // We'll try again once parsing succeeds. | 2672 | // We'll try again once parsing succeeds. |
| 2675 | if (decl.getFileScope().okToReportErrors()) { | 2673 | if (module.declFileScope(decl_index).okToReportErrors()) { |
| 2676 | try addModuleErrorMsg(&bundle, entry.value_ptr.*.*); | 2674 | try addModuleErrorMsg(&bundle, entry.value_ptr.*.*); |
| 2677 | } | 2675 | } |
| 2678 | } | 2676 | } |
| ... | @@ -2710,7 +2708,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { | ... | @@ -2710,7 +2708,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { |
| 2710 | const values = module.compile_log_decls.values(); | 2708 | const values = module.compile_log_decls.values(); |
| 2711 | // First one will be the error; subsequent ones will be notes. | 2709 | // First one will be the error; subsequent ones will be notes. |
| 2712 | const err_decl = module.declPtr(keys[0]); | 2710 | const err_decl = module.declPtr(keys[0]); |
| 2713 | const src_loc = err_decl.nodeOffsetSrcLoc(values[0]); | 2711 | const src_loc = err_decl.nodeOffsetSrcLoc(values[0], module); |
| 2714 | const err_msg = Module.ErrorMsg{ | 2712 | const err_msg = Module.ErrorMsg{ |
| 2715 | .src_loc = src_loc, | 2713 | .src_loc = src_loc, |
| 2716 | .msg = "found compile log statement", | 2714 | .msg = "found compile log statement", |
| ... | @@ -2721,7 +2719,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { | ... | @@ -2721,7 +2719,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { |
| 2721 | for (keys[1..], 0..) |key, i| { | 2719 | for (keys[1..], 0..) |key, i| { |
| 2722 | const note_decl = module.declPtr(key); | 2720 | const note_decl = module.declPtr(key); |
| 2723 | err_msg.notes[i] = .{ | 2721 | err_msg.notes[i] = .{ |
| 2724 | .src_loc = note_decl.nodeOffsetSrcLoc(values[i + 1]), | 2722 | .src_loc = note_decl.nodeOffsetSrcLoc(values[i + 1], module), |
| 2725 | .msg = "also here", | 2723 | .msg = "also here", |
| 2726 | }; | 2724 | }; |
| 2727 | } | 2725 | } |
| ... | @@ -3235,7 +3233,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: *std.Progress.Node) !v | ... | @@ -3235,7 +3233,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: *std.Progress.Node) !v |
| 3235 | try module.failed_decls.ensureUnusedCapacity(gpa, 1); | 3233 | try module.failed_decls.ensureUnusedCapacity(gpa, 1); |
| 3236 | module.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create( | 3234 | module.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create( |
| 3237 | gpa, | 3235 | gpa, |
| 3238 | decl.srcLoc(), | 3236 | decl.srcLoc(module), |
| 3239 | "unable to update line number: {s}", | 3237 | "unable to update line number: {s}", |
| 3240 | .{@errorName(err)}, | 3238 | .{@errorName(err)}, |
| 3241 | )); | 3239 | )); |
| ... | @@ -3848,7 +3846,7 @@ fn reportRetryableEmbedFileError( | ... | @@ -3848,7 +3846,7 @@ fn reportRetryableEmbedFileError( |
| 3848 | const mod = comp.bin_file.options.module.?; | 3846 | const mod = comp.bin_file.options.module.?; |
| 3849 | const gpa = mod.gpa; | 3847 | const gpa = mod.gpa; |
| 3850 | 3848 | ||
| 3851 | const src_loc: Module.SrcLoc = mod.declPtr(embed_file.owner_decl).srcLoc(); | 3849 | const src_loc: Module.SrcLoc = mod.declPtr(embed_file.owner_decl).srcLoc(mod); |
| 3852 | 3850 | ||
| 3853 | const err_msg = if (embed_file.pkg.root_src_directory.path) |dir_path| | 3851 | const err_msg = if (embed_file.pkg.root_src_directory.path) |dir_path| |
| 3854 | try Module.ErrorMsg.create( | 3852 | try Module.ErrorMsg.create( |
src/InternPool.zig+54-19| ... | @@ -17,7 +17,8 @@ const BigIntMutable = std.math.big.int.Mutable; | ... | @@ -17,7 +17,8 @@ const BigIntMutable = std.math.big.int.Mutable; |
| 17 | const Limb = std.math.big.Limb; | 17 | const Limb = std.math.big.Limb; |
| 18 | 18 | ||
| 19 | const InternPool = @This(); | 19 | const InternPool = @This(); |
| 20 | const DeclIndex = enum(u32) { _ }; | 20 | const DeclIndex = @import("Module.zig").Decl.Index; |
| 21 | const NamespaceIndex = @import("Module.zig").Namespace.Index; | ||
| 21 | 22 | ||
| 22 | const KeyAdapter = struct { | 23 | const KeyAdapter = struct { |
| 23 | intern_pool: *const InternPool, | 24 | intern_pool: *const InternPool, |
| ... | @@ -48,7 +49,7 @@ pub const Key = union(enum) { | ... | @@ -48,7 +49,7 @@ pub const Key = union(enum) { |
| 48 | extern_func: struct { | 49 | extern_func: struct { |
| 49 | ty: Index, | 50 | ty: Index, |
| 50 | /// The Decl that corresponds to the function itself. | 51 | /// The Decl that corresponds to the function itself. |
| 51 | owner_decl: DeclIndex, | 52 | decl: DeclIndex, |
| 52 | /// Library name if specified. | 53 | /// Library name if specified. |
| 53 | /// For example `extern "c" fn write(...) usize` would have 'c' as library name. | 54 | /// For example `extern "c" fn write(...) usize` would have 'c' as library name. |
| 54 | /// Index into the string table bytes. | 55 | /// Index into the string table bytes. |
| ... | @@ -62,6 +63,7 @@ pub const Key = union(enum) { | ... | @@ -62,6 +63,7 @@ pub const Key = union(enum) { |
| 62 | tag: BigIntConst, | 63 | tag: BigIntConst, |
| 63 | }, | 64 | }, |
| 64 | struct_type: StructType, | 65 | struct_type: StructType, |
| 66 | opaque_type: OpaqueType, | ||
| 65 | 67 | ||
| 66 | union_type: struct { | 68 | union_type: struct { |
| 67 | fields_len: u32, | 69 | fields_len: u32, |
| ... | @@ -116,6 +118,13 @@ pub const Key = union(enum) { | ... | @@ -116,6 +118,13 @@ pub const Key = union(enum) { |
| 116 | // TODO move Module.Struct data to InternPool | 118 | // TODO move Module.Struct data to InternPool |
| 117 | }; | 119 | }; |
| 118 | 120 | ||
| 121 | pub const OpaqueType = struct { | ||
| 122 | /// The Decl that corresponds to the opaque itself. | ||
| 123 | decl: DeclIndex, | ||
| 124 | /// Represents the declarations inside this opaque. | ||
| 125 | namespace: NamespaceIndex, | ||
| 126 | }; | ||
| 127 | |||
| 119 | pub const Int = struct { | 128 | pub const Int = struct { |
| 120 | ty: Index, | 129 | ty: Index, |
| 121 | storage: Storage, | 130 | storage: Storage, |
| ... | @@ -221,6 +230,7 @@ pub const Key = union(enum) { | ... | @@ -221,6 +230,7 @@ pub const Key = union(enum) { |
| 221 | _ = union_type; | 230 | _ = union_type; |
| 222 | @panic("TODO"); | 231 | @panic("TODO"); |
| 223 | }, | 232 | }, |
| 233 | .opaque_type => |opaque_type| std.hash.autoHash(hasher, opaque_type.decl), | ||
| 224 | } | 234 | } |
| 225 | } | 235 | } |
| 226 | 236 | ||
| ... | @@ -338,6 +348,11 @@ pub const Key = union(enum) { | ... | @@ -338,6 +348,11 @@ pub const Key = union(enum) { |
| 338 | _ = b_info; | 348 | _ = b_info; |
| 339 | @panic("TODO"); | 349 | @panic("TODO"); |
| 340 | }, | 350 | }, |
| 351 | |||
| 352 | .opaque_type => |a_info| { | ||
| 353 | const b_info = b.opaque_type; | ||
| 354 | return a_info.decl == b_info.decl; | ||
| 355 | }, | ||
| 341 | } | 356 | } |
| 342 | } | 357 | } |
| 343 | 358 | ||
| ... | @@ -352,6 +367,7 @@ pub const Key = union(enum) { | ... | @@ -352,6 +367,7 @@ pub const Key = union(enum) { |
| 352 | .simple_type, | 367 | .simple_type, |
| 353 | .struct_type, | 368 | .struct_type, |
| 354 | .union_type, | 369 | .union_type, |
| 370 | .opaque_type, | ||
| 355 | => return .type_type, | 371 | => return .type_type, |
| 356 | 372 | ||
| 357 | inline .ptr, | 373 | inline .ptr, |
| ... | @@ -770,10 +786,13 @@ pub const Tag = enum(u8) { | ... | @@ -770,10 +786,13 @@ pub const Tag = enum(u8) { |
| 770 | /// are auto-numbered, and there are no declarations. | 786 | /// are auto-numbered, and there are no declarations. |
| 771 | /// data is payload index to `EnumSimple`. | 787 | /// data is payload index to `EnumSimple`. |
| 772 | type_enum_simple, | 788 | type_enum_simple, |
| 773 | |||
| 774 | /// A type that can be represented with only an enum tag. | 789 | /// A type that can be represented with only an enum tag. |
| 775 | /// data is SimpleType enum value. | 790 | /// data is SimpleType enum value. |
| 776 | simple_type, | 791 | simple_type, |
| 792 | /// An opaque type. | ||
| 793 | /// data is index of Key.OpaqueType in extra. | ||
| 794 | type_opaque, | ||
| 795 | |||
| 777 | /// A value that can be represented with only an enum tag. | 796 | /// A value that can be represented with only an enum tag. |
| 778 | /// data is SimpleValue enum value. | 797 | /// data is SimpleValue enum value. |
| 779 | simple_value, | 798 | simple_value, |
| ... | @@ -986,7 +1005,7 @@ pub const ErrorUnion = struct { | ... | @@ -986,7 +1005,7 @@ pub const ErrorUnion = struct { |
| 986 | /// 0. field name: null-terminated string index for each fields_len; declaration order | 1005 | /// 0. field name: null-terminated string index for each fields_len; declaration order |
| 987 | pub const EnumSimple = struct { | 1006 | pub const EnumSimple = struct { |
| 988 | /// The Decl that corresponds to the enum itself. | 1007 | /// The Decl that corresponds to the enum itself. |
| 989 | owner_decl: DeclIndex, | 1008 | decl: DeclIndex, |
| 990 | /// An integer type which is used for the numerical value of the enum. This | 1009 | /// An integer type which is used for the numerical value of the enum. This |
| 991 | /// is inferred by Zig to be the smallest power of two unsigned int that | 1010 | /// is inferred by Zig to be the smallest power of two unsigned int that |
| 992 | /// fits the number of fields. It is stored here to avoid unnecessary | 1011 | /// fits the number of fields. It is stored here to avoid unnecessary |
| ... | @@ -1146,6 +1165,9 @@ pub fn indexToKey(ip: InternPool, index: Index) Key { | ... | @@ -1146,6 +1165,9 @@ pub fn indexToKey(ip: InternPool, index: Index) Key { |
| 1146 | 1165 | ||
| 1147 | .type_error_union => @panic("TODO"), | 1166 | .type_error_union => @panic("TODO"), |
| 1148 | .type_enum_simple => @panic("TODO"), | 1167 | .type_enum_simple => @panic("TODO"), |
| 1168 | |||
| 1169 | .type_opaque => .{ .opaque_type = ip.extraData(Key.OpaqueType, data) }, | ||
| 1170 | |||
| 1149 | .simple_internal => switch (@intToEnum(SimpleInternal, data)) { | 1171 | .simple_internal => switch (@intToEnum(SimpleInternal, data)) { |
| 1150 | .type_empty_struct => .{ .struct_type = .{ | 1172 | .type_empty_struct => .{ .struct_type = .{ |
| 1151 | .fields_len = 0, | 1173 | .fields_len = 0, |
| ... | @@ -1335,6 +1357,29 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { | ... | @@ -1335,6 +1357,29 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 1335 | .data = @enumToInt(simple_value), | 1357 | .data = @enumToInt(simple_value), |
| 1336 | }); | 1358 | }); |
| 1337 | }, | 1359 | }, |
| 1360 | |||
| 1361 | .struct_type => |struct_type| { | ||
| 1362 | if (struct_type.fields_len != 0) { | ||
| 1363 | @panic("TODO"); // handle structs other than empty_struct | ||
| 1364 | } | ||
| 1365 | ip.items.appendAssumeCapacity(.{ | ||
| 1366 | .tag = .simple_internal, | ||
| 1367 | .data = @enumToInt(SimpleInternal.type_empty_struct), | ||
| 1368 | }); | ||
| 1369 | }, | ||
| 1370 | |||
| 1371 | .union_type => |union_type| { | ||
| 1372 | _ = union_type; | ||
| 1373 | @panic("TODO"); | ||
| 1374 | }, | ||
| 1375 | |||
| 1376 | .opaque_type => |opaque_type| { | ||
| 1377 | ip.items.appendAssumeCapacity(.{ | ||
| 1378 | .tag = .type_opaque, | ||
| 1379 | .data = try ip.addExtra(gpa, opaque_type), | ||
| 1380 | }); | ||
| 1381 | }, | ||
| 1382 | |||
| 1338 | .extern_func => @panic("TODO"), | 1383 | .extern_func => @panic("TODO"), |
| 1339 | 1384 | ||
| 1340 | .ptr => |ptr| switch (ptr.addr) { | 1385 | .ptr => |ptr| switch (ptr.addr) { |
| ... | @@ -1504,21 +1549,6 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { | ... | @@ -1504,21 +1549,6 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 1504 | const tag: Tag = if (enum_tag.tag.positive) .enum_tag_positive else .enum_tag_negative; | 1549 | const tag: Tag = if (enum_tag.tag.positive) .enum_tag_positive else .enum_tag_negative; |
| 1505 | try addInt(ip, gpa, enum_tag.ty, tag, enum_tag.tag.limbs); | 1550 | try addInt(ip, gpa, enum_tag.ty, tag, enum_tag.tag.limbs); |
| 1506 | }, | 1551 | }, |
| 1507 | |||
| 1508 | .struct_type => |struct_type| { | ||
| 1509 | if (struct_type.fields_len != 0) { | ||
| 1510 | @panic("TODO"); // handle structs other than empty_struct | ||
| 1511 | } | ||
| 1512 | ip.items.appendAssumeCapacity(.{ | ||
| 1513 | .tag = .simple_internal, | ||
| 1514 | .data = @enumToInt(SimpleInternal.type_empty_struct), | ||
| 1515 | }); | ||
| 1516 | }, | ||
| 1517 | |||
| 1518 | .union_type => |union_type| { | ||
| 1519 | _ = union_type; | ||
| 1520 | @panic("TODO"); | ||
| 1521 | }, | ||
| 1522 | } | 1552 | } |
| 1523 | return @intToEnum(Index, ip.items.len - 1); | 1553 | return @intToEnum(Index, ip.items.len - 1); |
| 1524 | } | 1554 | } |
| ... | @@ -1548,6 +1578,8 @@ fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 { | ... | @@ -1548,6 +1578,8 @@ fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 { |
| 1548 | ip.extra.appendAssumeCapacity(switch (field.type) { | 1578 | ip.extra.appendAssumeCapacity(switch (field.type) { |
| 1549 | u32 => @field(extra, field.name), | 1579 | u32 => @field(extra, field.name), |
| 1550 | Index => @enumToInt(@field(extra, field.name)), | 1580 | Index => @enumToInt(@field(extra, field.name)), |
| 1581 | DeclIndex => @enumToInt(@field(extra, field.name)), | ||
| 1582 | NamespaceIndex => @enumToInt(@field(extra, field.name)), | ||
| 1551 | i32 => @bitCast(u32, @field(extra, field.name)), | 1583 | i32 => @bitCast(u32, @field(extra, field.name)), |
| 1552 | Pointer.Flags => @bitCast(u32, @field(extra, field.name)), | 1584 | Pointer.Flags => @bitCast(u32, @field(extra, field.name)), |
| 1553 | Pointer.PackedOffset => @bitCast(u32, @field(extra, field.name)), | 1585 | Pointer.PackedOffset => @bitCast(u32, @field(extra, field.name)), |
| ... | @@ -1603,6 +1635,8 @@ fn extraData(ip: InternPool, comptime T: type, index: usize) T { | ... | @@ -1603,6 +1635,8 @@ fn extraData(ip: InternPool, comptime T: type, index: usize) T { |
| 1603 | @field(result, field.name) = switch (field.type) { | 1635 | @field(result, field.name) = switch (field.type) { |
| 1604 | u32 => int32, | 1636 | u32 => int32, |
| 1605 | Index => @intToEnum(Index, int32), | 1637 | Index => @intToEnum(Index, int32), |
| 1638 | DeclIndex => @intToEnum(DeclIndex, int32), | ||
| 1639 | NamespaceIndex => @intToEnum(NamespaceIndex, int32), | ||
| 1606 | i32 => @bitCast(i32, int32), | 1640 | i32 => @bitCast(i32, int32), |
| 1607 | Pointer.Flags => @bitCast(Pointer.Flags, int32), | 1641 | Pointer.Flags => @bitCast(Pointer.Flags, int32), |
| 1608 | Pointer.PackedOffset => @bitCast(Pointer.PackedOffset, int32), | 1642 | Pointer.PackedOffset => @bitCast(Pointer.PackedOffset, int32), |
| ... | @@ -1824,6 +1858,7 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void { | ... | @@ -1824,6 +1858,7 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void { |
| 1824 | .type_optional => 0, | 1858 | .type_optional => 0, |
| 1825 | .type_error_union => @sizeOf(ErrorUnion), | 1859 | .type_error_union => @sizeOf(ErrorUnion), |
| 1826 | .type_enum_simple => @sizeOf(EnumSimple), | 1860 | .type_enum_simple => @sizeOf(EnumSimple), |
| 1861 | .type_opaque => @sizeOf(Key.OpaqueType), | ||
| 1827 | .simple_type => 0, | 1862 | .simple_type => 0, |
| 1828 | .simple_value => 0, | 1863 | .simple_value => 0, |
| 1829 | .simple_internal => 0, | 1864 | .simple_internal => 0, |
src/Module.zig+239-156| ... | @@ -185,6 +185,11 @@ allocated_decls: std.SegmentedList(Decl, 0) = .{}, | ... | @@ -185,6 +185,11 @@ allocated_decls: std.SegmentedList(Decl, 0) = .{}, |
| 185 | /// When a Decl object is freed from `allocated_decls`, it is pushed into this stack. | 185 | /// When a Decl object is freed from `allocated_decls`, it is pushed into this stack. |
| 186 | decls_free_list: ArrayListUnmanaged(Decl.Index) = .{}, | 186 | decls_free_list: ArrayListUnmanaged(Decl.Index) = .{}, |
| 187 | 187 | ||
| 188 | /// Same pattern as with `allocated_decls`. | ||
| 189 | allocated_namespaces: std.SegmentedList(Namespace, 0) = .{}, | ||
| 190 | /// Same pattern as with `decls_free_list`. | ||
| 191 | namespaces_free_list: ArrayListUnmanaged(Namespace.Index) = .{}, | ||
| 192 | |||
| 188 | global_assembly: std.AutoHashMapUnmanaged(Decl.Index, []u8) = .{}, | 193 | global_assembly: std.AutoHashMapUnmanaged(Decl.Index, []u8) = .{}, |
| 189 | 194 | ||
| 190 | reference_table: std.AutoHashMapUnmanaged(Decl.Index, struct { | 195 | reference_table: std.AutoHashMapUnmanaged(Decl.Index, struct { |
| ... | @@ -363,7 +368,7 @@ pub const Export = struct { | ... | @@ -363,7 +368,7 @@ pub const Export = struct { |
| 363 | pub fn getSrcLoc(exp: Export, mod: *Module) SrcLoc { | 368 | pub fn getSrcLoc(exp: Export, mod: *Module) SrcLoc { |
| 364 | const src_decl = mod.declPtr(exp.src_decl); | 369 | const src_decl = mod.declPtr(exp.src_decl); |
| 365 | return .{ | 370 | return .{ |
| 366 | .file_scope = src_decl.getFileScope(), | 371 | .file_scope = src_decl.getFileScope(mod), |
| 367 | .parent_decl_node = src_decl.src_node, | 372 | .parent_decl_node = src_decl.src_node, |
| 368 | .lazy = exp.src, | 373 | .lazy = exp.src, |
| 369 | }; | 374 | }; |
| ... | @@ -494,7 +499,7 @@ pub const Decl = struct { | ... | @@ -494,7 +499,7 @@ pub const Decl = struct { |
| 494 | /// Reference to externally owned memory. | 499 | /// Reference to externally owned memory. |
| 495 | /// In the case of the Decl corresponding to a file, this is | 500 | /// In the case of the Decl corresponding to a file, this is |
| 496 | /// the namespace of the struct, since there is no parent. | 501 | /// the namespace of the struct, since there is no parent. |
| 497 | src_namespace: *Namespace, | 502 | src_namespace: Namespace.Index, |
| 498 | 503 | ||
| 499 | /// The scope which lexically contains this decl. A decl must depend | 504 | /// The scope which lexically contains this decl. A decl must depend |
| 500 | /// on its lexical parent, in order to ensure that this pointer is valid. | 505 | /// on its lexical parent, in order to ensure that this pointer is valid. |
| ... | @@ -691,8 +696,8 @@ pub const Decl = struct { | ... | @@ -691,8 +696,8 @@ pub const Decl = struct { |
| 691 | 696 | ||
| 692 | /// This name is relative to the containing namespace of the decl. | 697 | /// This name is relative to the containing namespace of the decl. |
| 693 | /// The memory is owned by the containing File ZIR. | 698 | /// The memory is owned by the containing File ZIR. |
| 694 | pub fn getName(decl: Decl) ?[:0]const u8 { | 699 | pub fn getName(decl: Decl, mod: *Module) ?[:0]const u8 { |
| 695 | const zir = decl.getFileScope().zir; | 700 | const zir = decl.getFileScope(mod).zir; |
| 696 | return decl.getNameZir(zir); | 701 | return decl.getNameZir(zir); |
| 697 | } | 702 | } |
| 698 | 703 | ||
| ... | @@ -703,8 +708,8 @@ pub const Decl = struct { | ... | @@ -703,8 +708,8 @@ pub const Decl = struct { |
| 703 | return zir.nullTerminatedString(name_index); | 708 | return zir.nullTerminatedString(name_index); |
| 704 | } | 709 | } |
| 705 | 710 | ||
| 706 | pub fn contentsHash(decl: Decl) std.zig.SrcHash { | 711 | pub fn contentsHash(decl: Decl, mod: *Module) std.zig.SrcHash { |
| 707 | const zir = decl.getFileScope().zir; | 712 | const zir = decl.getFileScope(mod).zir; |
| 708 | return decl.contentsHashZir(zir); | 713 | return decl.contentsHashZir(zir); |
| 709 | } | 714 | } |
| 710 | 715 | ||
| ... | @@ -715,31 +720,31 @@ pub const Decl = struct { | ... | @@ -715,31 +720,31 @@ pub const Decl = struct { |
| 715 | return contents_hash; | 720 | return contents_hash; |
| 716 | } | 721 | } |
| 717 | 722 | ||
| 718 | pub fn zirBlockIndex(decl: *const Decl) Zir.Inst.Index { | 723 | pub fn zirBlockIndex(decl: *const Decl, mod: *Module) Zir.Inst.Index { |
| 719 | assert(decl.zir_decl_index != 0); | 724 | assert(decl.zir_decl_index != 0); |
| 720 | const zir = decl.getFileScope().zir; | 725 | const zir = decl.getFileScope(mod).zir; |
| 721 | return zir.extra[decl.zir_decl_index + 6]; | 726 | return zir.extra[decl.zir_decl_index + 6]; |
| 722 | } | 727 | } |
| 723 | 728 | ||
| 724 | pub fn zirAlignRef(decl: Decl) Zir.Inst.Ref { | 729 | pub fn zirAlignRef(decl: Decl, mod: *Module) Zir.Inst.Ref { |
| 725 | if (!decl.has_align) return .none; | 730 | if (!decl.has_align) return .none; |
| 726 | assert(decl.zir_decl_index != 0); | 731 | assert(decl.zir_decl_index != 0); |
| 727 | const zir = decl.getFileScope().zir; | 732 | const zir = decl.getFileScope(mod).zir; |
| 728 | return @intToEnum(Zir.Inst.Ref, zir.extra[decl.zir_decl_index + 8]); | 733 | return @intToEnum(Zir.Inst.Ref, zir.extra[decl.zir_decl_index + 8]); |
| 729 | } | 734 | } |
| 730 | 735 | ||
| 731 | pub fn zirLinksectionRef(decl: Decl) Zir.Inst.Ref { | 736 | pub fn zirLinksectionRef(decl: Decl, mod: *Module) Zir.Inst.Ref { |
| 732 | if (!decl.has_linksection_or_addrspace) return .none; | 737 | if (!decl.has_linksection_or_addrspace) return .none; |
| 733 | assert(decl.zir_decl_index != 0); | 738 | assert(decl.zir_decl_index != 0); |
| 734 | const zir = decl.getFileScope().zir; | 739 | const zir = decl.getFileScope(mod).zir; |
| 735 | const extra_index = decl.zir_decl_index + 8 + @boolToInt(decl.has_align); | 740 | const extra_index = decl.zir_decl_index + 8 + @boolToInt(decl.has_align); |
| 736 | return @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]); | 741 | return @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]); |
| 737 | } | 742 | } |
| 738 | 743 | ||
| 739 | pub fn zirAddrspaceRef(decl: Decl) Zir.Inst.Ref { | 744 | pub fn zirAddrspaceRef(decl: Decl, mod: *Module) Zir.Inst.Ref { |
| 740 | if (!decl.has_linksection_or_addrspace) return .none; | 745 | if (!decl.has_linksection_or_addrspace) return .none; |
| 741 | assert(decl.zir_decl_index != 0); | 746 | assert(decl.zir_decl_index != 0); |
| 742 | const zir = decl.getFileScope().zir; | 747 | const zir = decl.getFileScope(mod).zir; |
| 743 | const extra_index = decl.zir_decl_index + 8 + @boolToInt(decl.has_align) + 1; | 748 | const extra_index = decl.zir_decl_index + 8 + @boolToInt(decl.has_align) + 1; |
| 744 | return @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]); | 749 | return @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]); |
| 745 | } | 750 | } |
| ... | @@ -764,25 +769,25 @@ pub const Decl = struct { | ... | @@ -764,25 +769,25 @@ pub const Decl = struct { |
| 764 | return LazySrcLoc.nodeOffset(decl.nodeIndexToRelative(node_index)); | 769 | return LazySrcLoc.nodeOffset(decl.nodeIndexToRelative(node_index)); |
| 765 | } | 770 | } |
| 766 | 771 | ||
| 767 | pub fn srcLoc(decl: Decl) SrcLoc { | 772 | pub fn srcLoc(decl: Decl, mod: *Module) SrcLoc { |
| 768 | return decl.nodeOffsetSrcLoc(0); | 773 | return decl.nodeOffsetSrcLoc(0, mod); |
| 769 | } | 774 | } |
| 770 | 775 | ||
| 771 | pub fn nodeOffsetSrcLoc(decl: Decl, node_offset: i32) SrcLoc { | 776 | pub fn nodeOffsetSrcLoc(decl: Decl, node_offset: i32, mod: *Module) SrcLoc { |
| 772 | return .{ | 777 | return .{ |
| 773 | .file_scope = decl.getFileScope(), | 778 | .file_scope = decl.getFileScope(mod), |
| 774 | .parent_decl_node = decl.src_node, | 779 | .parent_decl_node = decl.src_node, |
| 775 | .lazy = LazySrcLoc.nodeOffset(node_offset), | 780 | .lazy = LazySrcLoc.nodeOffset(node_offset), |
| 776 | }; | 781 | }; |
| 777 | } | 782 | } |
| 778 | 783 | ||
| 779 | pub fn srcToken(decl: Decl) Ast.TokenIndex { | 784 | pub fn srcToken(decl: Decl, mod: *Module) Ast.TokenIndex { |
| 780 | const tree = &decl.getFileScope().tree; | 785 | const tree = &decl.getFileScope(mod).tree; |
| 781 | return tree.firstToken(decl.src_node); | 786 | return tree.firstToken(decl.src_node); |
| 782 | } | 787 | } |
| 783 | 788 | ||
| 784 | pub fn srcByteOffset(decl: Decl) u32 { | 789 | pub fn srcByteOffset(decl: Decl, mod: *Module) u32 { |
| 785 | const tree = &decl.getFileScope().tree; | 790 | const tree = &decl.getFileScope(mod).tree; |
| 786 | return tree.tokens.items(.start)[decl.srcToken()]; | 791 | return tree.tokens.items(.start)[decl.srcToken()]; |
| 787 | } | 792 | } |
| 788 | 793 | ||
| ... | @@ -791,12 +796,12 @@ pub const Decl = struct { | ... | @@ -791,12 +796,12 @@ pub const Decl = struct { |
| 791 | if (decl.name_fully_qualified) { | 796 | if (decl.name_fully_qualified) { |
| 792 | return writer.writeAll(unqualified_name); | 797 | return writer.writeAll(unqualified_name); |
| 793 | } | 798 | } |
| 794 | return decl.src_namespace.renderFullyQualifiedName(mod, unqualified_name, writer); | 799 | return mod.namespacePtr(decl.src_namespace).renderFullyQualifiedName(mod, unqualified_name, writer); |
| 795 | } | 800 | } |
| 796 | 801 | ||
| 797 | pub fn renderFullyQualifiedDebugName(decl: Decl, mod: *Module, writer: anytype) !void { | 802 | pub fn renderFullyQualifiedDebugName(decl: Decl, mod: *Module, writer: anytype) !void { |
| 798 | const unqualified_name = mem.sliceTo(decl.name, 0); | 803 | const unqualified_name = mem.sliceTo(decl.name, 0); |
| 799 | return decl.src_namespace.renderFullyQualifiedDebugName(mod, unqualified_name, writer); | 804 | return mod.namespacePtr(decl.src_namespace).renderFullyQualifiedDebugName(mod, unqualified_name, writer); |
| 800 | } | 805 | } |
| 801 | 806 | ||
| 802 | pub fn getFullyQualifiedName(decl: Decl, mod: *Module) ![:0]u8 { | 807 | pub fn getFullyQualifiedName(decl: Decl, mod: *Module) ![:0]u8 { |
| ... | @@ -877,32 +882,39 @@ pub const Decl = struct { | ... | @@ -877,32 +882,39 @@ pub const Decl = struct { |
| 877 | /// Gets the namespace that this Decl creates by being a struct, union, | 882 | /// Gets the namespace that this Decl creates by being a struct, union, |
| 878 | /// enum, or opaque. | 883 | /// enum, or opaque. |
| 879 | /// Only returns it if the Decl is the owner. | 884 | /// Only returns it if the Decl is the owner. |
| 880 | pub fn getInnerNamespace(decl: *Decl) ?*Namespace { | 885 | pub fn getInnerNamespaceIndex(decl: *Decl, mod: *Module) Namespace.OptionalIndex { |
| 881 | if (!decl.owns_tv) return null; | 886 | if (!decl.owns_tv) return .none; |
| 882 | const ty = (decl.val.castTag(.ty) orelse return null).data; | 887 | if (decl.val.ip_index == .none) { |
| 883 | switch (ty.tag()) { | 888 | const ty = (decl.val.castTag(.ty) orelse return .none).data; |
| 884 | .@"struct" => { | 889 | switch (ty.tag()) { |
| 885 | const struct_obj = ty.castTag(.@"struct").?.data; | 890 | .@"struct" => { |
| 886 | return &struct_obj.namespace; | 891 | const struct_obj = ty.castTag(.@"struct").?.data; |
| 887 | }, | 892 | return struct_obj.namespace.toOptional(); |
| 888 | .enum_full, .enum_nonexhaustive => { | 893 | }, |
| 889 | const enum_obj = ty.cast(Type.Payload.EnumFull).?.data; | 894 | .enum_full, .enum_nonexhaustive => { |
| 890 | return &enum_obj.namespace; | 895 | const enum_obj = ty.cast(Type.Payload.EnumFull).?.data; |
| 891 | }, | 896 | return enum_obj.namespace.toOptional(); |
| 892 | .empty_struct => { | 897 | }, |
| 893 | return ty.castTag(.empty_struct).?.data; | 898 | .empty_struct => { |
| 894 | }, | 899 | @panic("TODO"); |
| 895 | .@"opaque" => { | 900 | }, |
| 896 | const opaque_obj = ty.cast(Type.Payload.Opaque).?.data; | 901 | .@"union", .union_safety_tagged, .union_tagged => { |
| 897 | return &opaque_obj.namespace; | 902 | const union_obj = ty.cast(Type.Payload.Union).?.data; |
| 898 | }, | 903 | return union_obj.namespace.toOptional(); |
| 899 | .@"union", .union_safety_tagged, .union_tagged => { | 904 | }, |
| 900 | const union_obj = ty.cast(Type.Payload.Union).?.data; | ||
| 901 | return &union_obj.namespace; | ||
| 902 | }, | ||
| 903 | 905 | ||
| 904 | else => return null, | 906 | else => return .none, |
| 907 | } | ||
| 905 | } | 908 | } |
| 909 | return switch (mod.intern_pool.indexToKey(decl.val.ip_index)) { | ||
| 910 | .opaque_type => |opaque_type| opaque_type.namespace.toOptional(), | ||
| 911 | else => .none, | ||
| 912 | }; | ||
| 913 | } | ||
| 914 | |||
| 915 | /// Same as `getInnerNamespaceIndex` but additionally obtains the pointer. | ||
| 916 | pub fn getInnerNamespace(decl: *Decl, mod: *Module) ?*Namespace { | ||
| 917 | return if (getInnerNamespaceIndex(decl, mod).unwrap()) |i| mod.namespacePtr(i) else null; | ||
| 906 | } | 918 | } |
| 907 | 919 | ||
| 908 | pub fn dump(decl: *Decl) void { | 920 | pub fn dump(decl: *Decl) void { |
| ... | @@ -920,8 +932,8 @@ pub const Decl = struct { | ... | @@ -920,8 +932,8 @@ pub const Decl = struct { |
| 920 | std.debug.print("\n", .{}); | 932 | std.debug.print("\n", .{}); |
| 921 | } | 933 | } |
| 922 | 934 | ||
| 923 | pub fn getFileScope(decl: Decl) *File { | 935 | pub fn getFileScope(decl: Decl, mod: *Module) *File { |
| 924 | return decl.src_namespace.file_scope; | 936 | return mod.namespacePtr(decl.src_namespace).file_scope; |
| 925 | } | 937 | } |
| 926 | 938 | ||
| 927 | pub fn removeDependant(decl: *Decl, other: Decl.Index) void { | 939 | pub fn removeDependant(decl: *Decl, other: Decl.Index) void { |
| ... | @@ -974,7 +986,7 @@ pub const ErrorSet = struct { | ... | @@ -974,7 +986,7 @@ pub const ErrorSet = struct { |
| 974 | pub fn srcLoc(self: ErrorSet, mod: *Module) SrcLoc { | 986 | pub fn srcLoc(self: ErrorSet, mod: *Module) SrcLoc { |
| 975 | const owner_decl = mod.declPtr(self.owner_decl); | 987 | const owner_decl = mod.declPtr(self.owner_decl); |
| 976 | return .{ | 988 | return .{ |
| 977 | .file_scope = owner_decl.getFileScope(), | 989 | .file_scope = owner_decl.getFileScope(mod), |
| 978 | .parent_decl_node = owner_decl.src_node, | 990 | .parent_decl_node = owner_decl.src_node, |
| 979 | .lazy = LazySrcLoc.nodeOffset(0), | 991 | .lazy = LazySrcLoc.nodeOffset(0), |
| 980 | }; | 992 | }; |
| ... | @@ -1000,7 +1012,7 @@ pub const Struct = struct { | ... | @@ -1000,7 +1012,7 @@ pub const Struct = struct { |
| 1000 | /// Set of field names in declaration order. | 1012 | /// Set of field names in declaration order. |
| 1001 | fields: Fields, | 1013 | fields: Fields, |
| 1002 | /// Represents the declarations inside this struct. | 1014 | /// Represents the declarations inside this struct. |
| 1003 | namespace: Namespace, | 1015 | namespace: Namespace.Index, |
| 1004 | /// The Decl that corresponds to the struct itself. | 1016 | /// The Decl that corresponds to the struct itself. |
| 1005 | owner_decl: Decl.Index, | 1017 | owner_decl: Decl.Index, |
| 1006 | /// Index of the struct_decl ZIR instruction. | 1018 | /// Index of the struct_decl ZIR instruction. |
| ... | @@ -1101,7 +1113,7 @@ pub const Struct = struct { | ... | @@ -1101,7 +1113,7 @@ pub const Struct = struct { |
| 1101 | pub fn srcLoc(s: Struct, mod: *Module) SrcLoc { | 1113 | pub fn srcLoc(s: Struct, mod: *Module) SrcLoc { |
| 1102 | const owner_decl = mod.declPtr(s.owner_decl); | 1114 | const owner_decl = mod.declPtr(s.owner_decl); |
| 1103 | return .{ | 1115 | return .{ |
| 1104 | .file_scope = owner_decl.getFileScope(), | 1116 | .file_scope = owner_decl.getFileScope(mod), |
| 1105 | .parent_decl_node = owner_decl.src_node, | 1117 | .parent_decl_node = owner_decl.src_node, |
| 1106 | .lazy = LazySrcLoc.nodeOffset(0), | 1118 | .lazy = LazySrcLoc.nodeOffset(0), |
| 1107 | }; | 1119 | }; |
| ... | @@ -1110,7 +1122,7 @@ pub const Struct = struct { | ... | @@ -1110,7 +1122,7 @@ pub const Struct = struct { |
| 1110 | pub fn fieldSrcLoc(s: Struct, mod: *Module, query: FieldSrcQuery) SrcLoc { | 1122 | pub fn fieldSrcLoc(s: Struct, mod: *Module, query: FieldSrcQuery) SrcLoc { |
| 1111 | @setCold(true); | 1123 | @setCold(true); |
| 1112 | const owner_decl = mod.declPtr(s.owner_decl); | 1124 | const owner_decl = mod.declPtr(s.owner_decl); |
| 1113 | const file = owner_decl.getFileScope(); | 1125 | const file = owner_decl.getFileScope(mod); |
| 1114 | const tree = file.getTree(mod.gpa) catch |err| { | 1126 | const tree = file.getTree(mod.gpa) catch |err| { |
| 1115 | // In this case we emit a warning + a less precise source location. | 1127 | // In this case we emit a warning + a less precise source location. |
| 1116 | log.warn("unable to load {s}: {s}", .{ | 1128 | log.warn("unable to load {s}: {s}", .{ |
| ... | @@ -1224,7 +1236,7 @@ pub const EnumSimple = struct { | ... | @@ -1224,7 +1236,7 @@ pub const EnumSimple = struct { |
| 1224 | pub fn srcLoc(self: EnumSimple, mod: *Module) SrcLoc { | 1236 | pub fn srcLoc(self: EnumSimple, mod: *Module) SrcLoc { |
| 1225 | const owner_decl = mod.declPtr(self.owner_decl); | 1237 | const owner_decl = mod.declPtr(self.owner_decl); |
| 1226 | return .{ | 1238 | return .{ |
| 1227 | .file_scope = owner_decl.getFileScope(), | 1239 | .file_scope = owner_decl.getFileScope(mod), |
| 1228 | .parent_decl_node = owner_decl.src_node, | 1240 | .parent_decl_node = owner_decl.src_node, |
| 1229 | .lazy = LazySrcLoc.nodeOffset(0), | 1241 | .lazy = LazySrcLoc.nodeOffset(0), |
| 1230 | }; | 1242 | }; |
| ... | @@ -1253,7 +1265,7 @@ pub const EnumNumbered = struct { | ... | @@ -1253,7 +1265,7 @@ pub const EnumNumbered = struct { |
| 1253 | pub fn srcLoc(self: EnumNumbered, mod: *Module) SrcLoc { | 1265 | pub fn srcLoc(self: EnumNumbered, mod: *Module) SrcLoc { |
| 1254 | const owner_decl = mod.declPtr(self.owner_decl); | 1266 | const owner_decl = mod.declPtr(self.owner_decl); |
| 1255 | return .{ | 1267 | return .{ |
| 1256 | .file_scope = owner_decl.getFileScope(), | 1268 | .file_scope = owner_decl.getFileScope(mod), |
| 1257 | .parent_decl_node = owner_decl.src_node, | 1269 | .parent_decl_node = owner_decl.src_node, |
| 1258 | .lazy = LazySrcLoc.nodeOffset(0), | 1270 | .lazy = LazySrcLoc.nodeOffset(0), |
| 1259 | }; | 1271 | }; |
| ... | @@ -1275,7 +1287,7 @@ pub const EnumFull = struct { | ... | @@ -1275,7 +1287,7 @@ pub const EnumFull = struct { |
| 1275 | /// If this hash map is empty, it means the enum tags are auto-numbered. | 1287 | /// If this hash map is empty, it means the enum tags are auto-numbered. |
| 1276 | values: ValueMap, | 1288 | values: ValueMap, |
| 1277 | /// Represents the declarations inside this enum. | 1289 | /// Represents the declarations inside this enum. |
| 1278 | namespace: Namespace, | 1290 | namespace: Namespace.Index, |
| 1279 | /// true if zig inferred this tag type, false if user specified it | 1291 | /// true if zig inferred this tag type, false if user specified it |
| 1280 | tag_ty_inferred: bool, | 1292 | tag_ty_inferred: bool, |
| 1281 | 1293 | ||
| ... | @@ -1285,7 +1297,7 @@ pub const EnumFull = struct { | ... | @@ -1285,7 +1297,7 @@ pub const EnumFull = struct { |
| 1285 | pub fn srcLoc(self: EnumFull, mod: *Module) SrcLoc { | 1297 | pub fn srcLoc(self: EnumFull, mod: *Module) SrcLoc { |
| 1286 | const owner_decl = mod.declPtr(self.owner_decl); | 1298 | const owner_decl = mod.declPtr(self.owner_decl); |
| 1287 | return .{ | 1299 | return .{ |
| 1288 | .file_scope = owner_decl.getFileScope(), | 1300 | .file_scope = owner_decl.getFileScope(mod), |
| 1289 | .parent_decl_node = owner_decl.src_node, | 1301 | .parent_decl_node = owner_decl.src_node, |
| 1290 | .lazy = LazySrcLoc.nodeOffset(0), | 1302 | .lazy = LazySrcLoc.nodeOffset(0), |
| 1291 | }; | 1303 | }; |
| ... | @@ -1294,7 +1306,7 @@ pub const EnumFull = struct { | ... | @@ -1294,7 +1306,7 @@ pub const EnumFull = struct { |
| 1294 | pub fn fieldSrcLoc(e: EnumFull, mod: *Module, query: FieldSrcQuery) SrcLoc { | 1306 | pub fn fieldSrcLoc(e: EnumFull, mod: *Module, query: FieldSrcQuery) SrcLoc { |
| 1295 | @setCold(true); | 1307 | @setCold(true); |
| 1296 | const owner_decl = mod.declPtr(e.owner_decl); | 1308 | const owner_decl = mod.declPtr(e.owner_decl); |
| 1297 | const file = owner_decl.getFileScope(); | 1309 | const file = owner_decl.getFileScope(mod); |
| 1298 | const tree = file.getTree(mod.gpa) catch |err| { | 1310 | const tree = file.getTree(mod.gpa) catch |err| { |
| 1299 | // In this case we emit a warning + a less precise source location. | 1311 | // In this case we emit a warning + a less precise source location. |
| 1300 | log.warn("unable to load {s}: {s}", .{ | 1312 | log.warn("unable to load {s}: {s}", .{ |
| ... | @@ -1323,7 +1335,7 @@ pub const Union = struct { | ... | @@ -1323,7 +1335,7 @@ pub const Union = struct { |
| 1323 | /// Set of field names in declaration order. | 1335 | /// Set of field names in declaration order. |
| 1324 | fields: Fields, | 1336 | fields: Fields, |
| 1325 | /// Represents the declarations inside this union. | 1337 | /// Represents the declarations inside this union. |
| 1326 | namespace: Namespace, | 1338 | namespace: Namespace.Index, |
| 1327 | /// The Decl that corresponds to the union itself. | 1339 | /// The Decl that corresponds to the union itself. |
| 1328 | owner_decl: Decl.Index, | 1340 | owner_decl: Decl.Index, |
| 1329 | /// Index of the union_decl ZIR instruction. | 1341 | /// Index of the union_decl ZIR instruction. |
| ... | @@ -1371,7 +1383,7 @@ pub const Union = struct { | ... | @@ -1371,7 +1383,7 @@ pub const Union = struct { |
| 1371 | pub fn srcLoc(self: Union, mod: *Module) SrcLoc { | 1383 | pub fn srcLoc(self: Union, mod: *Module) SrcLoc { |
| 1372 | const owner_decl = mod.declPtr(self.owner_decl); | 1384 | const owner_decl = mod.declPtr(self.owner_decl); |
| 1373 | return .{ | 1385 | return .{ |
| 1374 | .file_scope = owner_decl.getFileScope(), | 1386 | .file_scope = owner_decl.getFileScope(mod), |
| 1375 | .parent_decl_node = owner_decl.src_node, | 1387 | .parent_decl_node = owner_decl.src_node, |
| 1376 | .lazy = LazySrcLoc.nodeOffset(0), | 1388 | .lazy = LazySrcLoc.nodeOffset(0), |
| 1377 | }; | 1389 | }; |
| ... | @@ -1380,7 +1392,7 @@ pub const Union = struct { | ... | @@ -1380,7 +1392,7 @@ pub const Union = struct { |
| 1380 | pub fn fieldSrcLoc(u: Union, mod: *Module, query: FieldSrcQuery) SrcLoc { | 1392 | pub fn fieldSrcLoc(u: Union, mod: *Module, query: FieldSrcQuery) SrcLoc { |
| 1381 | @setCold(true); | 1393 | @setCold(true); |
| 1382 | const owner_decl = mod.declPtr(u.owner_decl); | 1394 | const owner_decl = mod.declPtr(u.owner_decl); |
| 1383 | const file = owner_decl.getFileScope(); | 1395 | const file = owner_decl.getFileScope(mod); |
| 1384 | const tree = file.getTree(mod.gpa) catch |err| { | 1396 | const tree = file.getTree(mod.gpa) catch |err| { |
| 1385 | // In this case we emit a warning + a less precise source location. | 1397 | // In this case we emit a warning + a less precise source location. |
| 1386 | log.warn("unable to load {s}: {s}", .{ | 1398 | log.warn("unable to load {s}: {s}", .{ |
| ... | @@ -1563,26 +1575,6 @@ pub const Union = struct { | ... | @@ -1563,26 +1575,6 @@ pub const Union = struct { |
| 1563 | } | 1575 | } |
| 1564 | }; | 1576 | }; |
| 1565 | 1577 | ||
| 1566 | pub const Opaque = struct { | ||
| 1567 | /// The Decl that corresponds to the opaque itself. | ||
| 1568 | owner_decl: Decl.Index, | ||
| 1569 | /// Represents the declarations inside this opaque. | ||
| 1570 | namespace: Namespace, | ||
| 1571 | |||
| 1572 | pub fn srcLoc(self: Opaque, mod: *Module) SrcLoc { | ||
| 1573 | const owner_decl = mod.declPtr(self.owner_decl); | ||
| 1574 | return .{ | ||
| 1575 | .file_scope = owner_decl.getFileScope(), | ||
| 1576 | .parent_decl_node = owner_decl.src_node, | ||
| 1577 | .lazy = LazySrcLoc.nodeOffset(0), | ||
| 1578 | }; | ||
| 1579 | } | ||
| 1580 | |||
| 1581 | pub fn getFullyQualifiedName(s: *Opaque, mod: *Module) ![:0]u8 { | ||
| 1582 | return mod.declPtr(s.owner_decl).getFullyQualifiedName(mod); | ||
| 1583 | } | ||
| 1584 | }; | ||
| 1585 | |||
| 1586 | /// Some extern function struct memory is owned by the Decl's TypedValue.Managed | 1578 | /// Some extern function struct memory is owned by the Decl's TypedValue.Managed |
| 1587 | /// arena allocator. | 1579 | /// arena allocator. |
| 1588 | pub const ExternFn = struct { | 1580 | pub const ExternFn = struct { |
| ... | @@ -1759,7 +1751,7 @@ pub const Fn = struct { | ... | @@ -1759,7 +1751,7 @@ pub const Fn = struct { |
| 1759 | } | 1751 | } |
| 1760 | 1752 | ||
| 1761 | pub fn isAnytypeParam(func: Fn, mod: *Module, index: u32) bool { | 1753 | pub fn isAnytypeParam(func: Fn, mod: *Module, index: u32) bool { |
| 1762 | const file = mod.declPtr(func.owner_decl).getFileScope(); | 1754 | const file = mod.declPtr(func.owner_decl).getFileScope(mod); |
| 1763 | 1755 | ||
| 1764 | const tags = file.zir.instructions.items(.tag); | 1756 | const tags = file.zir.instructions.items(.tag); |
| 1765 | 1757 | ||
| ... | @@ -1774,7 +1766,7 @@ pub const Fn = struct { | ... | @@ -1774,7 +1766,7 @@ pub const Fn = struct { |
| 1774 | } | 1766 | } |
| 1775 | 1767 | ||
| 1776 | pub fn getParamName(func: Fn, mod: *Module, index: u32) [:0]const u8 { | 1768 | pub fn getParamName(func: Fn, mod: *Module, index: u32) [:0]const u8 { |
| 1777 | const file = mod.declPtr(func.owner_decl).getFileScope(); | 1769 | const file = mod.declPtr(func.owner_decl).getFileScope(mod); |
| 1778 | 1770 | ||
| 1779 | const tags = file.zir.instructions.items(.tag); | 1771 | const tags = file.zir.instructions.items(.tag); |
| 1780 | const data = file.zir.instructions.items(.data); | 1772 | const data = file.zir.instructions.items(.data); |
| ... | @@ -1797,7 +1789,7 @@ pub const Fn = struct { | ... | @@ -1797,7 +1789,7 @@ pub const Fn = struct { |
| 1797 | 1789 | ||
| 1798 | pub fn hasInferredErrorSet(func: Fn, mod: *Module) bool { | 1790 | pub fn hasInferredErrorSet(func: Fn, mod: *Module) bool { |
| 1799 | const owner_decl = mod.declPtr(func.owner_decl); | 1791 | const owner_decl = mod.declPtr(func.owner_decl); |
| 1800 | const zir = owner_decl.getFileScope().zir; | 1792 | const zir = owner_decl.getFileScope(mod).zir; |
| 1801 | const zir_tags = zir.instructions.items(.tag); | 1793 | const zir_tags = zir.instructions.items(.tag); |
| 1802 | switch (zir_tags[func.zir_body_inst]) { | 1794 | switch (zir_tags[func.zir_body_inst]) { |
| 1803 | .func => return false, | 1795 | .func => return false, |
| ... | @@ -1851,7 +1843,7 @@ pub const DeclAdapter = struct { | ... | @@ -1851,7 +1843,7 @@ pub const DeclAdapter = struct { |
| 1851 | 1843 | ||
| 1852 | /// The container that structs, enums, unions, and opaques have. | 1844 | /// The container that structs, enums, unions, and opaques have. |
| 1853 | pub const Namespace = struct { | 1845 | pub const Namespace = struct { |
| 1854 | parent: ?*Namespace, | 1846 | parent: OptionalIndex, |
| 1855 | file_scope: *File, | 1847 | file_scope: *File, |
| 1856 | /// Will be a struct, enum, union, or opaque. | 1848 | /// Will be a struct, enum, union, or opaque. |
| 1857 | ty: Type, | 1849 | ty: Type, |
| ... | @@ -1869,6 +1861,28 @@ pub const Namespace = struct { | ... | @@ -1869,6 +1861,28 @@ pub const Namespace = struct { |
| 1869 | /// Value is whether the usingnamespace decl is marked `pub`. | 1861 | /// Value is whether the usingnamespace decl is marked `pub`. |
| 1870 | usingnamespace_set: std.AutoHashMapUnmanaged(Decl.Index, bool) = .{}, | 1862 | usingnamespace_set: std.AutoHashMapUnmanaged(Decl.Index, bool) = .{}, |
| 1871 | 1863 | ||
| 1864 | pub const Index = enum(u32) { | ||
| 1865 | _, | ||
| 1866 | |||
| 1867 | pub fn toOptional(i: Index) OptionalIndex { | ||
| 1868 | return @intToEnum(OptionalIndex, @enumToInt(i)); | ||
| 1869 | } | ||
| 1870 | }; | ||
| 1871 | |||
| 1872 | pub const OptionalIndex = enum(u32) { | ||
| 1873 | none = std.math.maxInt(u32), | ||
| 1874 | _, | ||
| 1875 | |||
| 1876 | pub fn init(oi: ?Index) OptionalIndex { | ||
| 1877 | return @intToEnum(OptionalIndex, @enumToInt(oi orelse return .none)); | ||
| 1878 | } | ||
| 1879 | |||
| 1880 | pub fn unwrap(oi: OptionalIndex) ?Index { | ||
| 1881 | if (oi == .none) return null; | ||
| 1882 | return @intToEnum(Index, @enumToInt(oi)); | ||
| 1883 | } | ||
| 1884 | }; | ||
| 1885 | |||
| 1872 | const DeclContext = struct { | 1886 | const DeclContext = struct { |
| 1873 | module: *Module, | 1887 | module: *Module, |
| 1874 | 1888 | ||
| ... | @@ -1955,10 +1969,10 @@ pub const Namespace = struct { | ... | @@ -1955,10 +1969,10 @@ pub const Namespace = struct { |
| 1955 | name: []const u8, | 1969 | name: []const u8, |
| 1956 | writer: anytype, | 1970 | writer: anytype, |
| 1957 | ) @TypeOf(writer).Error!void { | 1971 | ) @TypeOf(writer).Error!void { |
| 1958 | if (ns.parent) |parent| { | 1972 | if (ns.parent.unwrap()) |parent| { |
| 1959 | const decl_index = ns.getDeclIndex(); | 1973 | const decl_index = ns.getDeclIndex(mod); |
| 1960 | const decl = mod.declPtr(decl_index); | 1974 | const decl = mod.declPtr(decl_index); |
| 1961 | try parent.renderFullyQualifiedName(mod, mem.sliceTo(decl.name, 0), writer); | 1975 | try mod.namespacePtr(parent).renderFullyQualifiedName(mod, mem.sliceTo(decl.name, 0), writer); |
| 1962 | } else { | 1976 | } else { |
| 1963 | try ns.file_scope.renderFullyQualifiedName(writer); | 1977 | try ns.file_scope.renderFullyQualifiedName(writer); |
| 1964 | } | 1978 | } |
| ... | @@ -1976,10 +1990,10 @@ pub const Namespace = struct { | ... | @@ -1976,10 +1990,10 @@ pub const Namespace = struct { |
| 1976 | writer: anytype, | 1990 | writer: anytype, |
| 1977 | ) @TypeOf(writer).Error!void { | 1991 | ) @TypeOf(writer).Error!void { |
| 1978 | var separator_char: u8 = '.'; | 1992 | var separator_char: u8 = '.'; |
| 1979 | if (ns.parent) |parent| { | 1993 | if (ns.parent.unwrap()) |parent| { |
| 1980 | const decl_index = ns.getDeclIndex(); | 1994 | const decl_index = ns.getDeclIndex(mod); |
| 1981 | const decl = mod.declPtr(decl_index); | 1995 | const decl = mod.declPtr(decl_index); |
| 1982 | try parent.renderFullyQualifiedDebugName(mod, mem.sliceTo(decl.name, 0), writer); | 1996 | try mod.namespacePtr(parent).renderFullyQualifiedDebugName(mod, mem.sliceTo(decl.name, 0), writer); |
| 1983 | } else { | 1997 | } else { |
| 1984 | try ns.file_scope.renderFullyQualifiedDebugName(writer); | 1998 | try ns.file_scope.renderFullyQualifiedDebugName(writer); |
| 1985 | separator_char = ':'; | 1999 | separator_char = ':'; |
| ... | @@ -1990,8 +2004,8 @@ pub const Namespace = struct { | ... | @@ -1990,8 +2004,8 @@ pub const Namespace = struct { |
| 1990 | } | 2004 | } |
| 1991 | } | 2005 | } |
| 1992 | 2006 | ||
| 1993 | pub fn getDeclIndex(ns: Namespace) Decl.Index { | 2007 | pub fn getDeclIndex(ns: Namespace, mod: *Module) Decl.Index { |
| 1994 | return ns.ty.getOwnerDecl(); | 2008 | return ns.ty.getOwnerDecl(mod); |
| 1995 | } | 2009 | } |
| 1996 | }; | 2010 | }; |
| 1997 | 2011 | ||
| ... | @@ -3320,7 +3334,7 @@ pub const LazySrcLoc = union(enum) { | ... | @@ -3320,7 +3334,7 @@ pub const LazySrcLoc = union(enum) { |
| 3320 | } | 3334 | } |
| 3321 | 3335 | ||
| 3322 | /// Upgrade to a `SrcLoc` based on the `Decl` provided. | 3336 | /// Upgrade to a `SrcLoc` based on the `Decl` provided. |
| 3323 | pub fn toSrcLoc(lazy: LazySrcLoc, decl: *Decl) SrcLoc { | 3337 | pub fn toSrcLoc(lazy: LazySrcLoc, decl: *Decl, mod: *Module) SrcLoc { |
| 3324 | return switch (lazy) { | 3338 | return switch (lazy) { |
| 3325 | .unneeded, | 3339 | .unneeded, |
| 3326 | .entire_file, | 3340 | .entire_file, |
| ... | @@ -3328,7 +3342,7 @@ pub const LazySrcLoc = union(enum) { | ... | @@ -3328,7 +3342,7 @@ pub const LazySrcLoc = union(enum) { |
| 3328 | .token_abs, | 3342 | .token_abs, |
| 3329 | .node_abs, | 3343 | .node_abs, |
| 3330 | => .{ | 3344 | => .{ |
| 3331 | .file_scope = decl.getFileScope(), | 3345 | .file_scope = decl.getFileScope(mod), |
| 3332 | .parent_decl_node = 0, | 3346 | .parent_decl_node = 0, |
| 3333 | .lazy = lazy, | 3347 | .lazy = lazy, |
| 3334 | }, | 3348 | }, |
| ... | @@ -3394,7 +3408,7 @@ pub const LazySrcLoc = union(enum) { | ... | @@ -3394,7 +3408,7 @@ pub const LazySrcLoc = union(enum) { |
| 3394 | .for_input, | 3408 | .for_input, |
| 3395 | .for_capture_from_input, | 3409 | .for_capture_from_input, |
| 3396 | => .{ | 3410 | => .{ |
| 3397 | .file_scope = decl.getFileScope(), | 3411 | .file_scope = decl.getFileScope(mod), |
| 3398 | .parent_decl_node = decl.src_node, | 3412 | .parent_decl_node = decl.src_node, |
| 3399 | .lazy = lazy, | 3413 | .lazy = lazy, |
| 3400 | }, | 3414 | }, |
| ... | @@ -3555,6 +3569,9 @@ pub fn deinit(mod: *Module) void { | ... | @@ -3555,6 +3569,9 @@ pub fn deinit(mod: *Module) void { |
| 3555 | mod.global_assembly.deinit(gpa); | 3569 | mod.global_assembly.deinit(gpa); |
| 3556 | mod.reference_table.deinit(gpa); | 3570 | mod.reference_table.deinit(gpa); |
| 3557 | 3571 | ||
| 3572 | mod.namespaces_free_list.deinit(gpa); | ||
| 3573 | mod.allocated_namespaces.deinit(gpa); | ||
| 3574 | |||
| 3558 | mod.string_literal_table.deinit(gpa); | 3575 | mod.string_literal_table.deinit(gpa); |
| 3559 | mod.string_literal_bytes.deinit(gpa); | 3576 | mod.string_literal_bytes.deinit(gpa); |
| 3560 | 3577 | ||
| ... | @@ -3575,8 +3592,9 @@ pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void { | ... | @@ -3575,8 +3592,9 @@ pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void { |
| 3575 | gpa.free(kv.value); | 3592 | gpa.free(kv.value); |
| 3576 | } | 3593 | } |
| 3577 | if (decl.has_tv) { | 3594 | if (decl.has_tv) { |
| 3578 | if (decl.getInnerNamespace()) |namespace| { | 3595 | if (decl.getInnerNamespaceIndex(mod).unwrap()) |i| { |
| 3579 | namespace.destroyDecls(mod); | 3596 | mod.namespacePtr(i).destroyDecls(mod); |
| 3597 | mod.destroyNamespace(i); | ||
| 3580 | } | 3598 | } |
| 3581 | } | 3599 | } |
| 3582 | decl.clearValues(mod); | 3600 | decl.clearValues(mod); |
| ... | @@ -3596,16 +3614,21 @@ pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void { | ... | @@ -3596,16 +3614,21 @@ pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void { |
| 3596 | } | 3614 | } |
| 3597 | } | 3615 | } |
| 3598 | 3616 | ||
| 3599 | pub fn declPtr(mod: *Module, decl_index: Decl.Index) *Decl { | 3617 | pub fn declPtr(mod: *Module, index: Decl.Index) *Decl { |
| 3600 | return mod.allocated_decls.at(@enumToInt(decl_index)); | 3618 | return mod.allocated_decls.at(@enumToInt(index)); |
| 3619 | } | ||
| 3620 | |||
| 3621 | pub fn namespacePtr(mod: *Module, index: Namespace.Index) *Namespace { | ||
| 3622 | return mod.allocated_namespaces.at(@enumToInt(index)); | ||
| 3601 | } | 3623 | } |
| 3602 | 3624 | ||
| 3603 | /// Returns true if and only if the Decl is the top level struct associated with a File. | 3625 | /// Returns true if and only if the Decl is the top level struct associated with a File. |
| 3604 | pub fn declIsRoot(mod: *Module, decl_index: Decl.Index) bool { | 3626 | pub fn declIsRoot(mod: *Module, decl_index: Decl.Index) bool { |
| 3605 | const decl = mod.declPtr(decl_index); | 3627 | const decl = mod.declPtr(decl_index); |
| 3606 | if (decl.src_namespace.parent != null) | 3628 | const namespace = mod.namespacePtr(decl.src_namespace); |
| 3629 | if (namespace.parent != .none) | ||
| 3607 | return false; | 3630 | return false; |
| 3608 | return decl_index == decl.src_namespace.getDeclIndex(); | 3631 | return decl_index == namespace.getDeclIndex(mod); |
| 3609 | } | 3632 | } |
| 3610 | 3633 | ||
| 3611 | fn freeExportList(gpa: Allocator, export_list: *ArrayListUnmanaged(*Export)) void { | 3634 | fn freeExportList(gpa: Allocator, export_list: *ArrayListUnmanaged(*Export)) void { |
| ... | @@ -4076,7 +4099,7 @@ fn updateZirRefs(mod: *Module, file: *File, old_zir: Zir) !void { | ... | @@ -4076,7 +4099,7 @@ fn updateZirRefs(mod: *Module, file: *File, old_zir: Zir) !void { |
| 4076 | }; | 4099 | }; |
| 4077 | } | 4100 | } |
| 4078 | 4101 | ||
| 4079 | if (decl.getInnerNamespace()) |namespace| { | 4102 | if (decl.getInnerNamespace(mod)) |namespace| { |
| 4080 | for (namespace.decls.keys()) |sub_decl| { | 4103 | for (namespace.decls.keys()) |sub_decl| { |
| 4081 | try decl_stack.append(gpa, sub_decl); | 4104 | try decl_stack.append(gpa, sub_decl); |
| 4082 | } | 4105 | } |
| ... | @@ -4306,7 +4329,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void { | ... | @@ -4306,7 +4329,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void { |
| 4306 | try mod.failed_decls.ensureUnusedCapacity(mod.gpa, 1); | 4329 | try mod.failed_decls.ensureUnusedCapacity(mod.gpa, 1); |
| 4307 | mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create( | 4330 | mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create( |
| 4308 | mod.gpa, | 4331 | mod.gpa, |
| 4309 | decl.srcLoc(), | 4332 | decl.srcLoc(mod), |
| 4310 | "unable to analyze: {s}", | 4333 | "unable to analyze: {s}", |
| 4311 | .{@errorName(e)}, | 4334 | .{@errorName(e)}, |
| 4312 | )); | 4335 | )); |
| ... | @@ -4437,7 +4460,7 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func: *Fn) SemaError!void { | ... | @@ -4437,7 +4460,7 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func: *Fn) SemaError!void { |
| 4437 | decl_index, | 4460 | decl_index, |
| 4438 | try Module.ErrorMsg.create( | 4461 | try Module.ErrorMsg.create( |
| 4439 | gpa, | 4462 | gpa, |
| 4440 | decl.srcLoc(), | 4463 | decl.srcLoc(mod), |
| 4441 | "invalid liveness: {s}", | 4464 | "invalid liveness: {s}", |
| 4442 | .{@errorName(err)}, | 4465 | .{@errorName(err)}, |
| 4443 | ), | 4466 | ), |
| ... | @@ -4460,7 +4483,7 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func: *Fn) SemaError!void { | ... | @@ -4460,7 +4483,7 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func: *Fn) SemaError!void { |
| 4460 | try mod.failed_decls.ensureUnusedCapacity(gpa, 1); | 4483 | try mod.failed_decls.ensureUnusedCapacity(gpa, 1); |
| 4461 | mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create( | 4484 | mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create( |
| 4462 | gpa, | 4485 | gpa, |
| 4463 | decl.srcLoc(), | 4486 | decl.srcLoc(mod), |
| 4464 | "unable to codegen: {s}", | 4487 | "unable to codegen: {s}", |
| 4465 | .{@errorName(err)}, | 4488 | .{@errorName(err)}, |
| 4466 | )); | 4489 | )); |
| ... | @@ -4586,13 +4609,13 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void { | ... | @@ -4586,13 +4609,13 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void { |
| 4586 | .status = .none, | 4609 | .status = .none, |
| 4587 | .known_non_opv = undefined, | 4610 | .known_non_opv = undefined, |
| 4588 | .is_tuple = undefined, // set below | 4611 | .is_tuple = undefined, // set below |
| 4589 | .namespace = .{ | 4612 | .namespace = try mod.createNamespace(.{ |
| 4590 | .parent = null, | 4613 | .parent = .none, |
| 4591 | .ty = struct_ty, | 4614 | .ty = struct_ty, |
| 4592 | .file_scope = file, | 4615 | .file_scope = file, |
| 4593 | }, | 4616 | }), |
| 4594 | }; | 4617 | }; |
| 4595 | const new_decl_index = try mod.allocateNewDecl(&struct_obj.namespace, 0, null); | 4618 | const new_decl_index = try mod.allocateNewDecl(struct_obj.namespace, 0, null); |
| 4596 | const new_decl = mod.declPtr(new_decl_index); | 4619 | const new_decl = mod.declPtr(new_decl_index); |
| 4597 | file.root_decl = new_decl_index.toOptional(); | 4620 | file.root_decl = new_decl_index.toOptional(); |
| 4598 | struct_obj.owner_decl = new_decl_index; | 4621 | struct_obj.owner_decl = new_decl_index; |
| ... | @@ -4688,12 +4711,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool { | ... | @@ -4688,12 +4711,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool { |
| 4688 | 4711 | ||
| 4689 | const decl = mod.declPtr(decl_index); | 4712 | const decl = mod.declPtr(decl_index); |
| 4690 | 4713 | ||
| 4691 | if (decl.getFileScope().status != .success_zir) { | 4714 | if (decl.getFileScope(mod).status != .success_zir) { |
| 4692 | return error.AnalysisFail; | 4715 | return error.AnalysisFail; |
| 4693 | } | 4716 | } |
| 4694 | 4717 | ||
| 4695 | const gpa = mod.gpa; | 4718 | const gpa = mod.gpa; |
| 4696 | const zir = decl.getFileScope().zir; | 4719 | const zir = decl.getFileScope(mod).zir; |
| 4697 | const zir_datas = zir.instructions.items(.data); | 4720 | const zir_datas = zir.instructions.items(.data); |
| 4698 | 4721 | ||
| 4699 | decl.analysis = .in_progress; | 4722 | decl.analysis = .in_progress; |
| ... | @@ -4767,7 +4790,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool { | ... | @@ -4767,7 +4790,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool { |
| 4767 | block_scope.params.deinit(gpa); | 4790 | block_scope.params.deinit(gpa); |
| 4768 | } | 4791 | } |
| 4769 | 4792 | ||
| 4770 | const zir_block_index = decl.zirBlockIndex(); | 4793 | const zir_block_index = decl.zirBlockIndex(mod); |
| 4771 | const inst_data = zir_datas[zir_block_index].pl_node; | 4794 | const inst_data = zir_datas[zir_block_index].pl_node; |
| 4772 | const extra = zir.extraData(Zir.Inst.Block, inst_data.payload_index); | 4795 | const extra = zir.extraData(Zir.Inst.Block, inst_data.payload_index); |
| 4773 | const body = zir.extra[extra.end..][0..extra.data.body_len]; | 4796 | const body = zir.extra[extra.end..][0..extra.data.body_len]; |
| ... | @@ -4792,7 +4815,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool { | ... | @@ -4792,7 +4815,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool { |
| 4792 | }); | 4815 | }); |
| 4793 | } | 4816 | } |
| 4794 | const ty = try decl_tv.val.toType().copy(decl_arena_allocator); | 4817 | const ty = try decl_tv.val.toType().copy(decl_arena_allocator); |
| 4795 | if (ty.getNamespace() == null) { | 4818 | if (ty.getNamespace(mod) == null) { |
| 4796 | return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(mod)}); | 4819 | return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(mod)}); |
| 4797 | } | 4820 | } |
| 4798 | 4821 | ||
| ... | @@ -4895,12 +4918,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool { | ... | @@ -4895,12 +4918,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool { |
| 4895 | decl.ty = try decl_tv.ty.copy(decl_arena_allocator); | 4918 | decl.ty = try decl_tv.ty.copy(decl_arena_allocator); |
| 4896 | decl.val = try decl_tv.val.copy(decl_arena_allocator); | 4919 | decl.val = try decl_tv.val.copy(decl_arena_allocator); |
| 4897 | decl.@"align" = blk: { | 4920 | decl.@"align" = blk: { |
| 4898 | const align_ref = decl.zirAlignRef(); | 4921 | const align_ref = decl.zirAlignRef(mod); |
| 4899 | if (align_ref == .none) break :blk 0; | 4922 | if (align_ref == .none) break :blk 0; |
| 4900 | break :blk try sema.resolveAlign(&block_scope, align_src, align_ref); | 4923 | break :blk try sema.resolveAlign(&block_scope, align_src, align_ref); |
| 4901 | }; | 4924 | }; |
| 4902 | decl.@"linksection" = blk: { | 4925 | decl.@"linksection" = blk: { |
| 4903 | const linksection_ref = decl.zirLinksectionRef(); | 4926 | const linksection_ref = decl.zirLinksectionRef(mod); |
| 4904 | if (linksection_ref == .none) break :blk null; | 4927 | if (linksection_ref == .none) break :blk null; |
| 4905 | const bytes = try sema.resolveConstString(&block_scope, section_src, linksection_ref, "linksection must be comptime-known"); | 4928 | const bytes = try sema.resolveConstString(&block_scope, section_src, linksection_ref, "linksection must be comptime-known"); |
| 4906 | if (mem.indexOfScalar(u8, bytes, 0) != null) { | 4929 | if (mem.indexOfScalar(u8, bytes, 0) != null) { |
| ... | @@ -4921,7 +4944,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool { | ... | @@ -4921,7 +4944,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool { |
| 4921 | }; | 4944 | }; |
| 4922 | 4945 | ||
| 4923 | const target = sema.mod.getTarget(); | 4946 | const target = sema.mod.getTarget(); |
| 4924 | break :blk switch (decl.zirAddrspaceRef()) { | 4947 | break :blk switch (decl.zirAddrspaceRef(mod)) { |
| 4925 | .none => switch (addrspace_ctx) { | 4948 | .none => switch (addrspace_ctx) { |
| 4926 | .function => target_util.defaultAddressSpace(target, .function), | 4949 | .function => target_util.defaultAddressSpace(target, .function), |
| 4927 | .variable => target_util.defaultAddressSpace(target, .global_mutable), | 4950 | .variable => target_util.defaultAddressSpace(target, .global_mutable), |
| ... | @@ -5273,7 +5296,7 @@ pub fn detectEmbedFileUpdate(mod: *Module, embed_file: *EmbedFile) !void { | ... | @@ -5273,7 +5296,7 @@ pub fn detectEmbedFileUpdate(mod: *Module, embed_file: *EmbedFile) !void { |
| 5273 | 5296 | ||
| 5274 | pub fn scanNamespace( | 5297 | pub fn scanNamespace( |
| 5275 | mod: *Module, | 5298 | mod: *Module, |
| 5276 | namespace: *Namespace, | 5299 | namespace_index: Namespace.Index, |
| 5277 | extra_start: usize, | 5300 | extra_start: usize, |
| 5278 | decls_len: u32, | 5301 | decls_len: u32, |
| 5279 | parent_decl: *Decl, | 5302 | parent_decl: *Decl, |
| ... | @@ -5282,6 +5305,7 @@ pub fn scanNamespace( | ... | @@ -5282,6 +5305,7 @@ pub fn scanNamespace( |
| 5282 | defer tracy.end(); | 5305 | defer tracy.end(); |
| 5283 | 5306 | ||
| 5284 | const gpa = mod.gpa; | 5307 | const gpa = mod.gpa; |
| 5308 | const namespace = mod.namespacePtr(namespace_index); | ||
| 5285 | const zir = namespace.file_scope.zir; | 5309 | const zir = namespace.file_scope.zir; |
| 5286 | 5310 | ||
| 5287 | try mod.comp.work_queue.ensureUnusedCapacity(decls_len); | 5311 | try mod.comp.work_queue.ensureUnusedCapacity(decls_len); |
| ... | @@ -5294,7 +5318,7 @@ pub fn scanNamespace( | ... | @@ -5294,7 +5318,7 @@ pub fn scanNamespace( |
| 5294 | var decl_i: u32 = 0; | 5318 | var decl_i: u32 = 0; |
| 5295 | var scan_decl_iter: ScanDeclIter = .{ | 5319 | var scan_decl_iter: ScanDeclIter = .{ |
| 5296 | .module = mod, | 5320 | .module = mod, |
| 5297 | .namespace = namespace, | 5321 | .namespace_index = namespace_index, |
| 5298 | .parent_decl = parent_decl, | 5322 | .parent_decl = parent_decl, |
| 5299 | }; | 5323 | }; |
| 5300 | while (decl_i < decls_len) : (decl_i += 1) { | 5324 | while (decl_i < decls_len) : (decl_i += 1) { |
| ... | @@ -5317,7 +5341,7 @@ pub fn scanNamespace( | ... | @@ -5317,7 +5341,7 @@ pub fn scanNamespace( |
| 5317 | 5341 | ||
| 5318 | const ScanDeclIter = struct { | 5342 | const ScanDeclIter = struct { |
| 5319 | module: *Module, | 5343 | module: *Module, |
| 5320 | namespace: *Namespace, | 5344 | namespace_index: Namespace.Index, |
| 5321 | parent_decl: *Decl, | 5345 | parent_decl: *Decl, |
| 5322 | usingnamespace_index: usize = 0, | 5346 | usingnamespace_index: usize = 0, |
| 5323 | comptime_index: usize = 0, | 5347 | comptime_index: usize = 0, |
| ... | @@ -5329,7 +5353,8 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err | ... | @@ -5329,7 +5353,8 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err |
| 5329 | defer tracy.end(); | 5353 | defer tracy.end(); |
| 5330 | 5354 | ||
| 5331 | const mod = iter.module; | 5355 | const mod = iter.module; |
| 5332 | const namespace = iter.namespace; | 5356 | const namespace_index = iter.namespace_index; |
| 5357 | const namespace = mod.namespacePtr(namespace_index); | ||
| 5333 | const gpa = mod.gpa; | 5358 | const gpa = mod.gpa; |
| 5334 | const zir = namespace.file_scope.zir; | 5359 | const zir = namespace.file_scope.zir; |
| 5335 | 5360 | ||
| ... | @@ -5404,7 +5429,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err | ... | @@ -5404,7 +5429,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err |
| 5404 | ); | 5429 | ); |
| 5405 | const comp = mod.comp; | 5430 | const comp = mod.comp; |
| 5406 | if (!gop.found_existing) { | 5431 | if (!gop.found_existing) { |
| 5407 | const new_decl_index = try mod.allocateNewDecl(namespace, decl_node, iter.parent_decl.src_scope); | 5432 | const new_decl_index = try mod.allocateNewDecl(namespace_index, decl_node, iter.parent_decl.src_scope); |
| 5408 | const new_decl = mod.declPtr(new_decl_index); | 5433 | const new_decl = mod.declPtr(new_decl_index); |
| 5409 | new_decl.kind = kind; | 5434 | new_decl.kind = kind; |
| 5410 | new_decl.name = decl_name; | 5435 | new_decl.name = decl_name; |
| ... | @@ -5456,7 +5481,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err | ... | @@ -5456,7 +5481,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err |
| 5456 | const decl = mod.declPtr(decl_index); | 5481 | const decl = mod.declPtr(decl_index); |
| 5457 | if (kind == .@"test") { | 5482 | if (kind == .@"test") { |
| 5458 | const src_loc = SrcLoc{ | 5483 | const src_loc = SrcLoc{ |
| 5459 | .file_scope = decl.getFileScope(), | 5484 | .file_scope = decl.getFileScope(mod), |
| 5460 | .parent_decl_node = decl.src_node, | 5485 | .parent_decl_node = decl.src_node, |
| 5461 | .lazy = .{ .token_offset = 1 }, | 5486 | .lazy = .{ .token_offset = 1 }, |
| 5462 | }; | 5487 | }; |
| ... | @@ -5564,7 +5589,7 @@ pub fn clearDecl( | ... | @@ -5564,7 +5589,7 @@ pub fn clearDecl( |
| 5564 | if (decl.ty.isFnOrHasRuntimeBits(mod)) { | 5589 | if (decl.ty.isFnOrHasRuntimeBits(mod)) { |
| 5565 | mod.comp.bin_file.freeDecl(decl_index); | 5590 | mod.comp.bin_file.freeDecl(decl_index); |
| 5566 | } | 5591 | } |
| 5567 | if (decl.getInnerNamespace()) |namespace| { | 5592 | if (decl.getInnerNamespace(mod)) |namespace| { |
| 5568 | try namespace.deleteAllDecls(mod, outdated_decls); | 5593 | try namespace.deleteAllDecls(mod, outdated_decls); |
| 5569 | } | 5594 | } |
| 5570 | } | 5595 | } |
| ... | @@ -5584,7 +5609,7 @@ pub fn deleteUnusedDecl(mod: *Module, decl_index: Decl.Index) void { | ... | @@ -5584,7 +5609,7 @@ pub fn deleteUnusedDecl(mod: *Module, decl_index: Decl.Index) void { |
| 5584 | log.debug("deleteUnusedDecl {d} ({s})", .{ decl_index, decl.name }); | 5609 | log.debug("deleteUnusedDecl {d} ({s})", .{ decl_index, decl.name }); |
| 5585 | 5610 | ||
| 5586 | assert(!mod.declIsRoot(decl_index)); | 5611 | assert(!mod.declIsRoot(decl_index)); |
| 5587 | assert(decl.src_namespace.anon_decls.swapRemove(decl_index)); | 5612 | assert(mod.namespacePtr(decl.src_namespace).anon_decls.swapRemove(decl_index)); |
| 5588 | 5613 | ||
| 5589 | const dependants = decl.dependants.keys(); | 5614 | const dependants = decl.dependants.keys(); |
| 5590 | for (dependants) |dep| { | 5615 | for (dependants) |dep| { |
| ... | @@ -5612,7 +5637,7 @@ pub fn abortAnonDecl(mod: *Module, decl_index: Decl.Index) void { | ... | @@ -5612,7 +5637,7 @@ pub fn abortAnonDecl(mod: *Module, decl_index: Decl.Index) void { |
| 5612 | log.debug("abortAnonDecl {*} ({s})", .{ decl, decl.name }); | 5637 | log.debug("abortAnonDecl {*} ({s})", .{ decl, decl.name }); |
| 5613 | 5638 | ||
| 5614 | assert(!mod.declIsRoot(decl_index)); | 5639 | assert(!mod.declIsRoot(decl_index)); |
| 5615 | assert(decl.src_namespace.anon_decls.swapRemove(decl_index)); | 5640 | assert(mod.namespacePtr(decl.src_namespace).anon_decls.swapRemove(decl_index)); |
| 5616 | 5641 | ||
| 5617 | // An aborted decl must not have dependants -- they must have | 5642 | // An aborted decl must not have dependants -- they must have |
| 5618 | // been aborted first and removed from this list. | 5643 | // been aborted first and removed from this list. |
| ... | @@ -5689,7 +5714,7 @@ pub fn analyzeFnBody(mod: *Module, func: *Fn, arena: Allocator) SemaError!Air { | ... | @@ -5689,7 +5714,7 @@ pub fn analyzeFnBody(mod: *Module, func: *Fn, arena: Allocator) SemaError!Air { |
| 5689 | .gpa = gpa, | 5714 | .gpa = gpa, |
| 5690 | .arena = arena, | 5715 | .arena = arena, |
| 5691 | .perm_arena = decl_arena_allocator, | 5716 | .perm_arena = decl_arena_allocator, |
| 5692 | .code = decl.getFileScope().zir, | 5717 | .code = decl.getFileScope(mod).zir, |
| 5693 | .owner_decl = decl, | 5718 | .owner_decl = decl, |
| 5694 | .owner_decl_index = decl_index, | 5719 | .owner_decl_index = decl_index, |
| 5695 | .func = func, | 5720 | .func = func, |
| ... | @@ -5920,9 +5945,34 @@ fn markOutdatedDecl(mod: *Module, decl_index: Decl.Index) !void { | ... | @@ -5920,9 +5945,34 @@ fn markOutdatedDecl(mod: *Module, decl_index: Decl.Index) !void { |
| 5920 | decl.analysis = .outdated; | 5945 | decl.analysis = .outdated; |
| 5921 | } | 5946 | } |
| 5922 | 5947 | ||
| 5948 | pub const CreateNamespaceOptions = struct { | ||
| 5949 | parent: Namespace.OptionalIndex, | ||
| 5950 | file_scope: *File, | ||
| 5951 | ty: Type, | ||
| 5952 | }; | ||
| 5953 | |||
| 5954 | pub fn createNamespace(mod: *Module, options: CreateNamespaceOptions) !Namespace.Index { | ||
| 5955 | if (mod.namespaces_free_list.popOrNull()) |index| return index; | ||
| 5956 | const ptr = try mod.allocated_namespaces.addOne(mod.gpa); | ||
| 5957 | ptr.* = .{ | ||
| 5958 | .parent = options.parent, | ||
| 5959 | .file_scope = options.file_scope, | ||
| 5960 | .ty = options.ty, | ||
| 5961 | }; | ||
| 5962 | return @intToEnum(Namespace.Index, mod.allocated_namespaces.len - 1); | ||
| 5963 | } | ||
| 5964 | |||
| 5965 | pub fn destroyNamespace(mod: *Module, index: Namespace.Index) void { | ||
| 5966 | mod.namespacePtr(index).* = undefined; | ||
| 5967 | mod.namespaces_free_list.append(mod.gpa, index) catch { | ||
| 5968 | // In order to keep `destroyNamespace` a non-fallible function, we ignore memory | ||
| 5969 | // allocation failures here, instead leaking the Namespace until garbage collection. | ||
| 5970 | }; | ||
| 5971 | } | ||
| 5972 | |||
| 5923 | pub fn allocateNewDecl( | 5973 | pub fn allocateNewDecl( |
| 5924 | mod: *Module, | 5974 | mod: *Module, |
| 5925 | namespace: *Namespace, | 5975 | namespace: Namespace.Index, |
| 5926 | src_node: Ast.Node.Index, | 5976 | src_node: Ast.Node.Index, |
| 5927 | src_scope: ?*CaptureScope, | 5977 | src_scope: ?*CaptureScope, |
| 5928 | ) !Decl.Index { | 5978 | ) !Decl.Index { |
| ... | @@ -6004,7 +6054,7 @@ pub fn createAnonymousDecl(mod: *Module, block: *Sema.Block, typed_value: TypedV | ... | @@ -6004,7 +6054,7 @@ pub fn createAnonymousDecl(mod: *Module, block: *Sema.Block, typed_value: TypedV |
| 6004 | pub fn createAnonymousDeclFromDecl( | 6054 | pub fn createAnonymousDeclFromDecl( |
| 6005 | mod: *Module, | 6055 | mod: *Module, |
| 6006 | src_decl: *Decl, | 6056 | src_decl: *Decl, |
| 6007 | namespace: *Namespace, | 6057 | namespace: Namespace.Index, |
| 6008 | src_scope: ?*CaptureScope, | 6058 | src_scope: ?*CaptureScope, |
| 6009 | tv: TypedValue, | 6059 | tv: TypedValue, |
| 6010 | ) !Decl.Index { | 6060 | ) !Decl.Index { |
| ... | @@ -6022,7 +6072,7 @@ pub fn initNewAnonDecl( | ... | @@ -6022,7 +6072,7 @@ pub fn initNewAnonDecl( |
| 6022 | mod: *Module, | 6072 | mod: *Module, |
| 6023 | new_decl_index: Decl.Index, | 6073 | new_decl_index: Decl.Index, |
| 6024 | src_line: u32, | 6074 | src_line: u32, |
| 6025 | namespace: *Namespace, | 6075 | namespace: Namespace.Index, |
| 6026 | typed_value: TypedValue, | 6076 | typed_value: TypedValue, |
| 6027 | name: [:0]u8, | 6077 | name: [:0]u8, |
| 6028 | ) !void { | 6078 | ) !void { |
| ... | @@ -6040,7 +6090,7 @@ pub fn initNewAnonDecl( | ... | @@ -6040,7 +6090,7 @@ pub fn initNewAnonDecl( |
| 6040 | new_decl.analysis = .complete; | 6090 | new_decl.analysis = .complete; |
| 6041 | new_decl.generation = mod.generation; | 6091 | new_decl.generation = mod.generation; |
| 6042 | 6092 | ||
| 6043 | try namespace.anon_decls.putNoClobber(mod.gpa, new_decl_index, {}); | 6093 | try mod.namespacePtr(namespace).anon_decls.putNoClobber(mod.gpa, new_decl_index, {}); |
| 6044 | 6094 | ||
| 6045 | // The Decl starts off with alive=false and the codegen backend will set alive=true | 6095 | // The Decl starts off with alive=false and the codegen backend will set alive=true |
| 6046 | // if the Decl is referenced by an instruction or another constant. Otherwise, | 6096 | // if the Decl is referenced by an instruction or another constant. Otherwise, |
| ... | @@ -6110,16 +6160,17 @@ pub const SwitchProngSrc = union(enum) { | ... | @@ -6110,16 +6160,17 @@ pub const SwitchProngSrc = union(enum) { |
| 6110 | /// the LazySrcLoc in order to emit a compile error. | 6160 | /// the LazySrcLoc in order to emit a compile error. |
| 6111 | pub fn resolve( | 6161 | pub fn resolve( |
| 6112 | prong_src: SwitchProngSrc, | 6162 | prong_src: SwitchProngSrc, |
| 6113 | gpa: Allocator, | 6163 | mod: *Module, |
| 6114 | decl: *Decl, | 6164 | decl: *Decl, |
| 6115 | switch_node_offset: i32, | 6165 | switch_node_offset: i32, |
| 6116 | range_expand: RangeExpand, | 6166 | range_expand: RangeExpand, |
| 6117 | ) LazySrcLoc { | 6167 | ) LazySrcLoc { |
| 6118 | @setCold(true); | 6168 | @setCold(true); |
| 6119 | const tree = decl.getFileScope().getTree(gpa) catch |err| { | 6169 | const gpa = mod.gpa; |
| 6170 | const tree = decl.getFileScope(mod).getTree(gpa) catch |err| { | ||
| 6120 | // In this case we emit a warning + a less precise source location. | 6171 | // In this case we emit a warning + a less precise source location. |
| 6121 | log.warn("unable to load {s}: {s}", .{ | 6172 | log.warn("unable to load {s}: {s}", .{ |
| 6122 | decl.getFileScope().sub_file_path, @errorName(err), | 6173 | decl.getFileScope(mod).sub_file_path, @errorName(err), |
| 6123 | }); | 6174 | }); |
| 6124 | return LazySrcLoc.nodeOffset(0); | 6175 | return LazySrcLoc.nodeOffset(0); |
| 6125 | }; | 6176 | }; |
| ... | @@ -6203,11 +6254,12 @@ pub const PeerTypeCandidateSrc = union(enum) { | ... | @@ -6203,11 +6254,12 @@ pub const PeerTypeCandidateSrc = union(enum) { |
| 6203 | 6254 | ||
| 6204 | pub fn resolve( | 6255 | pub fn resolve( |
| 6205 | self: PeerTypeCandidateSrc, | 6256 | self: PeerTypeCandidateSrc, |
| 6206 | gpa: Allocator, | 6257 | mod: *Module, |
| 6207 | decl: *Decl, | 6258 | decl: *Decl, |
| 6208 | candidate_i: usize, | 6259 | candidate_i: usize, |
| 6209 | ) ?LazySrcLoc { | 6260 | ) ?LazySrcLoc { |
| 6210 | @setCold(true); | 6261 | @setCold(true); |
| 6262 | const gpa = mod.gpa; | ||
| 6211 | 6263 | ||
| 6212 | switch (self) { | 6264 | switch (self) { |
| 6213 | .none => { | 6265 | .none => { |
| ... | @@ -6229,10 +6281,10 @@ pub const PeerTypeCandidateSrc = union(enum) { | ... | @@ -6229,10 +6281,10 @@ pub const PeerTypeCandidateSrc = union(enum) { |
| 6229 | else => {}, | 6281 | else => {}, |
| 6230 | } | 6282 | } |
| 6231 | 6283 | ||
| 6232 | const tree = decl.getFileScope().getTree(gpa) catch |err| { | 6284 | const tree = decl.getFileScope(mod).getTree(gpa) catch |err| { |
| 6233 | // In this case we emit a warning + a less precise source location. | 6285 | // In this case we emit a warning + a less precise source location. |
| 6234 | log.warn("unable to load {s}: {s}", .{ | 6286 | log.warn("unable to load {s}: {s}", .{ |
| 6235 | decl.getFileScope().sub_file_path, @errorName(err), | 6287 | decl.getFileScope(mod).sub_file_path, @errorName(err), |
| 6236 | }); | 6288 | }); |
| 6237 | return LazySrcLoc.nodeOffset(0); | 6289 | return LazySrcLoc.nodeOffset(0); |
| 6238 | }; | 6290 | }; |
| ... | @@ -6291,15 +6343,16 @@ fn queryFieldSrc( | ... | @@ -6291,15 +6343,16 @@ fn queryFieldSrc( |
| 6291 | 6343 | ||
| 6292 | pub fn paramSrc( | 6344 | pub fn paramSrc( |
| 6293 | func_node_offset: i32, | 6345 | func_node_offset: i32, |
| 6294 | gpa: Allocator, | 6346 | mod: *Module, |
| 6295 | decl: *Decl, | 6347 | decl: *Decl, |
| 6296 | param_i: usize, | 6348 | param_i: usize, |
| 6297 | ) LazySrcLoc { | 6349 | ) LazySrcLoc { |
| 6298 | @setCold(true); | 6350 | @setCold(true); |
| 6299 | const tree = decl.getFileScope().getTree(gpa) catch |err| { | 6351 | const gpa = mod.gpa; |
| 6352 | const tree = decl.getFileScope(mod).getTree(gpa) catch |err| { | ||
| 6300 | // In this case we emit a warning + a less precise source location. | 6353 | // In this case we emit a warning + a less precise source location. |
| 6301 | log.warn("unable to load {s}: {s}", .{ | 6354 | log.warn("unable to load {s}: {s}", .{ |
| 6302 | decl.getFileScope().sub_file_path, @errorName(err), | 6355 | decl.getFileScope(mod).sub_file_path, @errorName(err), |
| 6303 | }); | 6356 | }); |
| 6304 | return LazySrcLoc.nodeOffset(0); | 6357 | return LazySrcLoc.nodeOffset(0); |
| 6305 | }; | 6358 | }; |
| ... | @@ -6321,19 +6374,20 @@ pub fn paramSrc( | ... | @@ -6321,19 +6374,20 @@ pub fn paramSrc( |
| 6321 | } | 6374 | } |
| 6322 | 6375 | ||
| 6323 | pub fn argSrc( | 6376 | pub fn argSrc( |
| 6377 | mod: *Module, | ||
| 6324 | call_node_offset: i32, | 6378 | call_node_offset: i32, |
| 6325 | gpa: Allocator, | ||
| 6326 | decl: *Decl, | 6379 | decl: *Decl, |
| 6327 | start_arg_i: usize, | 6380 | start_arg_i: usize, |
| 6328 | bound_arg_src: ?LazySrcLoc, | 6381 | bound_arg_src: ?LazySrcLoc, |
| 6329 | ) LazySrcLoc { | 6382 | ) LazySrcLoc { |
| 6383 | @setCold(true); | ||
| 6384 | const gpa = mod.gpa; | ||
| 6330 | if (start_arg_i == 0 and bound_arg_src != null) return bound_arg_src.?; | 6385 | if (start_arg_i == 0 and bound_arg_src != null) return bound_arg_src.?; |
| 6331 | const arg_i = start_arg_i - @boolToInt(bound_arg_src != null); | 6386 | const arg_i = start_arg_i - @boolToInt(bound_arg_src != null); |
| 6332 | @setCold(true); | 6387 | const tree = decl.getFileScope(mod).getTree(gpa) catch |err| { |
| 6333 | const tree = decl.getFileScope().getTree(gpa) catch |err| { | ||
| 6334 | // In this case we emit a warning + a less precise source location. | 6388 | // In this case we emit a warning + a less precise source location. |
| 6335 | log.warn("unable to load {s}: {s}", .{ | 6389 | log.warn("unable to load {s}: {s}", .{ |
| 6336 | decl.getFileScope().sub_file_path, @errorName(err), | 6390 | decl.getFileScope(mod).sub_file_path, @errorName(err), |
| 6337 | }); | 6391 | }); |
| 6338 | return LazySrcLoc.nodeOffset(0); | 6392 | return LazySrcLoc.nodeOffset(0); |
| 6339 | }; | 6393 | }; |
| ... | @@ -6347,7 +6401,7 @@ pub fn argSrc( | ... | @@ -6347,7 +6401,7 @@ pub fn argSrc( |
| 6347 | const node_datas = tree.nodes.items(.data); | 6401 | const node_datas = tree.nodes.items(.data); |
| 6348 | const call_args_node = tree.extra_data[node_datas[node].rhs - 1]; | 6402 | const call_args_node = tree.extra_data[node_datas[node].rhs - 1]; |
| 6349 | const call_args_offset = decl.nodeIndexToRelative(call_args_node); | 6403 | const call_args_offset = decl.nodeIndexToRelative(call_args_node); |
| 6350 | return initSrc(call_args_offset, gpa, decl, arg_i); | 6404 | return mod.initSrc(call_args_offset, decl, arg_i); |
| 6351 | }, | 6405 | }, |
| 6352 | else => unreachable, | 6406 | else => unreachable, |
| 6353 | }; | 6407 | }; |
| ... | @@ -6355,16 +6409,17 @@ pub fn argSrc( | ... | @@ -6355,16 +6409,17 @@ pub fn argSrc( |
| 6355 | } | 6409 | } |
| 6356 | 6410 | ||
| 6357 | pub fn initSrc( | 6411 | pub fn initSrc( |
| 6412 | mod: *Module, | ||
| 6358 | init_node_offset: i32, | 6413 | init_node_offset: i32, |
| 6359 | gpa: Allocator, | ||
| 6360 | decl: *Decl, | 6414 | decl: *Decl, |
| 6361 | init_index: usize, | 6415 | init_index: usize, |
| 6362 | ) LazySrcLoc { | 6416 | ) LazySrcLoc { |
| 6363 | @setCold(true); | 6417 | @setCold(true); |
| 6364 | const tree = decl.getFileScope().getTree(gpa) catch |err| { | 6418 | const gpa = mod.gpa; |
| 6419 | const tree = decl.getFileScope(mod).getTree(gpa) catch |err| { | ||
| 6365 | // In this case we emit a warning + a less precise source location. | 6420 | // In this case we emit a warning + a less precise source location. |
| 6366 | log.warn("unable to load {s}: {s}", .{ | 6421 | log.warn("unable to load {s}: {s}", .{ |
| 6367 | decl.getFileScope().sub_file_path, @errorName(err), | 6422 | decl.getFileScope(mod).sub_file_path, @errorName(err), |
| 6368 | }); | 6423 | }); |
| 6369 | return LazySrcLoc.nodeOffset(0); | 6424 | return LazySrcLoc.nodeOffset(0); |
| 6370 | }; | 6425 | }; |
| ... | @@ -6400,12 +6455,13 @@ pub fn initSrc( | ... | @@ -6400,12 +6455,13 @@ pub fn initSrc( |
| 6400 | } | 6455 | } |
| 6401 | } | 6456 | } |
| 6402 | 6457 | ||
| 6403 | pub fn optionsSrc(gpa: Allocator, decl: *Decl, base_src: LazySrcLoc, wanted: []const u8) LazySrcLoc { | 6458 | pub fn optionsSrc(mod: *Module, decl: *Decl, base_src: LazySrcLoc, wanted: []const u8) LazySrcLoc { |
| 6404 | @setCold(true); | 6459 | @setCold(true); |
| 6405 | const tree = decl.getFileScope().getTree(gpa) catch |err| { | 6460 | const gpa = mod.gpa; |
| 6461 | const tree = decl.getFileScope(mod).getTree(gpa) catch |err| { | ||
| 6406 | // In this case we emit a warning + a less precise source location. | 6462 | // In this case we emit a warning + a less precise source location. |
| 6407 | log.warn("unable to load {s}: {s}", .{ | 6463 | log.warn("unable to load {s}: {s}", .{ |
| 6408 | decl.getFileScope().sub_file_path, @errorName(err), | 6464 | decl.getFileScope(mod).sub_file_path, @errorName(err), |
| 6409 | }); | 6465 | }); |
| 6410 | return LazySrcLoc.nodeOffset(0); | 6466 | return LazySrcLoc.nodeOffset(0); |
| 6411 | }; | 6467 | }; |
| ... | @@ -6471,7 +6527,10 @@ pub fn processOutdatedAndDeletedDecls(mod: *Module) !void { | ... | @@ -6471,7 +6527,10 @@ pub fn processOutdatedAndDeletedDecls(mod: *Module) !void { |
| 6471 | 6527 | ||
| 6472 | // Remove from the namespace it resides in, preserving declaration order. | 6528 | // Remove from the namespace it resides in, preserving declaration order. |
| 6473 | assert(decl.zir_decl_index != 0); | 6529 | assert(decl.zir_decl_index != 0); |
| 6474 | _ = decl.src_namespace.decls.orderedRemoveAdapted(@as([]const u8, mem.sliceTo(decl.name, 0)), DeclAdapter{ .mod = mod }); | 6530 | _ = mod.namespacePtr(decl.src_namespace).decls.orderedRemoveAdapted( |
| 6531 | @as([]const u8, mem.sliceTo(decl.name, 0)), | ||
| 6532 | DeclAdapter{ .mod = mod }, | ||
| 6533 | ); | ||
| 6475 | 6534 | ||
| 6476 | try mod.clearDecl(decl_index, &outdated_decls); | 6535 | try mod.clearDecl(decl_index, &outdated_decls); |
| 6477 | mod.destroyDecl(decl_index); | 6536 | mod.destroyDecl(decl_index); |
| ... | @@ -6541,8 +6600,11 @@ pub fn populateTestFunctions( | ... | @@ -6541,8 +6600,11 @@ pub fn populateTestFunctions( |
| 6541 | const builtin_pkg = mod.main_pkg.table.get("builtin").?; | 6600 | const builtin_pkg = mod.main_pkg.table.get("builtin").?; |
| 6542 | const builtin_file = (mod.importPkg(builtin_pkg) catch unreachable).file; | 6601 | const builtin_file = (mod.importPkg(builtin_pkg) catch unreachable).file; |
| 6543 | const root_decl = mod.declPtr(builtin_file.root_decl.unwrap().?); | 6602 | const root_decl = mod.declPtr(builtin_file.root_decl.unwrap().?); |
| 6544 | const builtin_namespace = root_decl.src_namespace; | 6603 | const builtin_namespace = mod.namespacePtr(root_decl.src_namespace); |
| 6545 | const decl_index = builtin_namespace.decls.getKeyAdapted(@as([]const u8, "test_functions"), DeclAdapter{ .mod = mod }).?; | 6604 | const decl_index = builtin_namespace.decls.getKeyAdapted( |
| 6605 | @as([]const u8, "test_functions"), | ||
| 6606 | DeclAdapter{ .mod = mod }, | ||
| 6607 | ).?; | ||
| 6546 | { | 6608 | { |
| 6547 | // We have to call `ensureDeclAnalyzed` here in case `builtin.test_functions` | 6609 | // We have to call `ensureDeclAnalyzed` here in case `builtin.test_functions` |
| 6548 | // was not referenced by start code. | 6610 | // was not referenced by start code. |
| ... | @@ -6673,7 +6735,7 @@ pub fn linkerUpdateDecl(mod: *Module, decl_index: Decl.Index) !void { | ... | @@ -6673,7 +6735,7 @@ pub fn linkerUpdateDecl(mod: *Module, decl_index: Decl.Index) !void { |
| 6673 | try mod.failed_decls.ensureUnusedCapacity(gpa, 1); | 6735 | try mod.failed_decls.ensureUnusedCapacity(gpa, 1); |
| 6674 | mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create( | 6736 | mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create( |
| 6675 | gpa, | 6737 | gpa, |
| 6676 | decl.srcLoc(), | 6738 | decl.srcLoc(mod), |
| 6677 | "unable to codegen: {s}", | 6739 | "unable to codegen: {s}", |
| 6678 | .{@errorName(err)}, | 6740 | .{@errorName(err)}, |
| 6679 | )); | 6741 | )); |
| ... | @@ -7138,3 +7200,24 @@ pub fn atomicPtrAlignment( | ... | @@ -7138,3 +7200,24 @@ pub fn atomicPtrAlignment( |
| 7138 | 7200 | ||
| 7139 | return 0; | 7201 | return 0; |
| 7140 | } | 7202 | } |
| 7203 | |||
| 7204 | pub fn opaqueSrcLoc(mod: *Module, opaque_type: InternPool.Key.OpaqueType) SrcLoc { | ||
| 7205 | const owner_decl = mod.declPtr(opaque_type.decl); | ||
| 7206 | return .{ | ||
| 7207 | .file_scope = owner_decl.getFileScope(mod), | ||
| 7208 | .parent_decl_node = owner_decl.src_node, | ||
| 7209 | .lazy = LazySrcLoc.nodeOffset(0), | ||
| 7210 | }; | ||
| 7211 | } | ||
| 7212 | |||
| 7213 | pub fn opaqueFullyQualifiedName(mod: *Module, opaque_type: InternPool.Key.OpaqueType) ![:0]u8 { | ||
| 7214 | return mod.declPtr(opaque_type.decl).getFullyQualifiedName(mod); | ||
| 7215 | } | ||
| 7216 | |||
| 7217 | pub fn declFileScope(mod: *Module, decl_index: Decl.Index) *File { | ||
| 7218 | return mod.declPtr(decl_index).getFileScope(mod); | ||
| 7219 | } | ||
| 7220 | |||
| 7221 | pub fn namespaceDeclIndex(mod: *Module, namespace_index: Namespace.Index) Decl.Index { | ||
| 7222 | return mod.namespacePtr(namespace_index).getDeclIndex(mod); | ||
| 7223 | } |
src/Sema.zig+325-312| ... | @@ -227,7 +227,7 @@ pub const Block = struct { | ... | @@ -227,7 +227,7 @@ pub const Block = struct { |
| 227 | sema: *Sema, | 227 | sema: *Sema, |
| 228 | /// The namespace to use for lookups from this source block | 228 | /// The namespace to use for lookups from this source block |
| 229 | /// When analyzing fields, this is different from src_decl.src_namespace. | 229 | /// When analyzing fields, this is different from src_decl.src_namespace. |
| 230 | namespace: *Namespace, | 230 | namespace: Namespace.Index, |
| 231 | /// The AIR instructions generated for this block. | 231 | /// The AIR instructions generated for this block. |
| 232 | instructions: std.ArrayListUnmanaged(Air.Inst.Index), | 232 | instructions: std.ArrayListUnmanaged(Air.Inst.Index), |
| 233 | // `param` instructions are collected here to be used by the `func` instruction. | 233 | // `param` instructions are collected here to be used by the `func` instruction. |
| ... | @@ -286,6 +286,7 @@ pub const Block = struct { | ... | @@ -286,6 +286,7 @@ pub const Block = struct { |
| 286 | 286 | ||
| 287 | fn explain(cr: ComptimeReason, sema: *Sema, msg: ?*Module.ErrorMsg) !void { | 287 | fn explain(cr: ComptimeReason, sema: *Sema, msg: ?*Module.ErrorMsg) !void { |
| 288 | const parent = msg orelse return; | 288 | const parent = msg orelse return; |
| 289 | const mod = sema.mod; | ||
| 289 | const prefix = "expression is evaluated at comptime because "; | 290 | const prefix = "expression is evaluated at comptime because "; |
| 290 | switch (cr) { | 291 | switch (cr) { |
| 291 | .c_import => |ci| { | 292 | .c_import => |ci| { |
| ... | @@ -293,12 +294,12 @@ pub const Block = struct { | ... | @@ -293,12 +294,12 @@ pub const Block = struct { |
| 293 | }, | 294 | }, |
| 294 | .comptime_ret_ty => |rt| { | 295 | .comptime_ret_ty => |rt| { |
| 295 | const src_loc = if (try sema.funcDeclSrc(rt.func)) |fn_decl| blk: { | 296 | const src_loc = if (try sema.funcDeclSrc(rt.func)) |fn_decl| blk: { |
| 296 | var src_loc = fn_decl.srcLoc(); | 297 | var src_loc = fn_decl.srcLoc(mod); |
| 297 | src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 }; | 298 | src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 }; |
| 298 | break :blk src_loc; | 299 | break :blk src_loc; |
| 299 | } else blk: { | 300 | } else blk: { |
| 300 | const src_decl = sema.mod.declPtr(rt.block.src_decl); | 301 | const src_decl = sema.mod.declPtr(rt.block.src_decl); |
| 301 | break :blk rt.func_src.toSrcLoc(src_decl); | 302 | break :blk rt.func_src.toSrcLoc(src_decl, mod); |
| 302 | }; | 303 | }; |
| 303 | if (rt.return_ty.isGenericPoison()) { | 304 | if (rt.return_ty.isGenericPoison()) { |
| 304 | return sema.mod.errNoteNonLazy(src_loc, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{}); | 305 | return sema.mod.errNoteNonLazy(src_loc, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{}); |
| ... | @@ -399,8 +400,8 @@ pub const Block = struct { | ... | @@ -399,8 +400,8 @@ pub const Block = struct { |
| 399 | }; | 400 | }; |
| 400 | } | 401 | } |
| 401 | 402 | ||
| 402 | pub fn getFileScope(block: *Block) *Module.File { | 403 | pub fn getFileScope(block: *Block, mod: *Module) *Module.File { |
| 403 | return block.namespace.file_scope; | 404 | return mod.namespacePtr(block.namespace).file_scope; |
| 404 | } | 405 | } |
| 405 | 406 | ||
| 406 | fn addTy( | 407 | fn addTy( |
| ... | @@ -876,6 +877,7 @@ fn analyzeBodyInner( | ... | @@ -876,6 +877,7 @@ fn analyzeBodyInner( |
| 876 | wip_captures.deinit(); | 877 | wip_captures.deinit(); |
| 877 | }; | 878 | }; |
| 878 | 879 | ||
| 880 | const mod = sema.mod; | ||
| 879 | const map = &sema.inst_map; | 881 | const map = &sema.inst_map; |
| 880 | const tags = sema.code.instructions.items(.tag); | 882 | const tags = sema.code.instructions.items(.tag); |
| 881 | const datas = sema.code.instructions.items(.data); | 883 | const datas = sema.code.instructions.items(.data); |
| ... | @@ -896,7 +898,7 @@ fn analyzeBodyInner( | ... | @@ -896,7 +898,7 @@ fn analyzeBodyInner( |
| 896 | crash_info.setBodyIndex(i); | 898 | crash_info.setBodyIndex(i); |
| 897 | const inst = body[i]; | 899 | const inst = body[i]; |
| 898 | std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{ | 900 | std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{ |
| 899 | sema.mod.declPtr(block.src_decl).src_namespace.file_scope.sub_file_path, inst, | 901 | mod.namespacePtr(mod.declPtr(block.src_decl).src_namespace).file_scope.sub_file_path, inst, |
| 900 | }); | 902 | }); |
| 901 | const air_inst: Air.Inst.Ref = switch (tags[inst]) { | 903 | const air_inst: Air.Inst.Ref = switch (tags[inst]) { |
| 902 | // zig fmt: off | 904 | // zig fmt: off |
| ... | @@ -1574,7 +1576,6 @@ fn analyzeBodyInner( | ... | @@ -1574,7 +1576,6 @@ fn analyzeBodyInner( |
| 1574 | }, | 1576 | }, |
| 1575 | .condbr => blk: { | 1577 | .condbr => blk: { |
| 1576 | if (!block.is_comptime) break sema.zirCondbr(block, inst); | 1578 | if (!block.is_comptime) break sema.zirCondbr(block, inst); |
| 1577 | const mod = sema.mod; | ||
| 1578 | // Same as condbr_inline. TODO https://github.com/ziglang/zig/issues/8220 | 1579 | // Same as condbr_inline. TODO https://github.com/ziglang/zig/issues/8220 |
| 1579 | const inst_data = datas[inst].pl_node; | 1580 | const inst_data = datas[inst].pl_node; |
| 1580 | const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node }; | 1581 | const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node }; |
| ... | @@ -1597,7 +1598,6 @@ fn analyzeBodyInner( | ... | @@ -1597,7 +1598,6 @@ fn analyzeBodyInner( |
| 1597 | } | 1598 | } |
| 1598 | }, | 1599 | }, |
| 1599 | .condbr_inline => blk: { | 1600 | .condbr_inline => blk: { |
| 1600 | const mod = sema.mod; | ||
| 1601 | const inst_data = datas[inst].pl_node; | 1601 | const inst_data = datas[inst].pl_node; |
| 1602 | const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node }; | 1602 | const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node }; |
| 1603 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); | 1603 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); |
| ... | @@ -1622,7 +1622,6 @@ fn analyzeBodyInner( | ... | @@ -1622,7 +1622,6 @@ fn analyzeBodyInner( |
| 1622 | }, | 1622 | }, |
| 1623 | .@"try" => blk: { | 1623 | .@"try" => blk: { |
| 1624 | if (!block.is_comptime) break :blk try sema.zirTry(block, inst); | 1624 | if (!block.is_comptime) break :blk try sema.zirTry(block, inst); |
| 1625 | const mod = sema.mod; | ||
| 1626 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 1625 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 1627 | const src = inst_data.src(); | 1626 | const src = inst_data.src(); |
| 1628 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 1627 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| ... | @@ -1632,7 +1631,7 @@ fn analyzeBodyInner( | ... | @@ -1632,7 +1631,7 @@ fn analyzeBodyInner( |
| 1632 | const err_union_ty = sema.typeOf(err_union); | 1631 | const err_union_ty = sema.typeOf(err_union); |
| 1633 | if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) { | 1632 | if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) { |
| 1634 | return sema.fail(block, operand_src, "expected error union type, found '{}'", .{ | 1633 | return sema.fail(block, operand_src, "expected error union type, found '{}'", .{ |
| 1635 | err_union_ty.fmt(sema.mod), | 1634 | err_union_ty.fmt(mod), |
| 1636 | }); | 1635 | }); |
| 1637 | } | 1636 | } |
| 1638 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); | 1637 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); |
| ... | @@ -1654,7 +1653,6 @@ fn analyzeBodyInner( | ... | @@ -1654,7 +1653,6 @@ fn analyzeBodyInner( |
| 1654 | }, | 1653 | }, |
| 1655 | .try_ptr => blk: { | 1654 | .try_ptr => blk: { |
| 1656 | if (!block.is_comptime) break :blk try sema.zirTryPtr(block, inst); | 1655 | if (!block.is_comptime) break :blk try sema.zirTryPtr(block, inst); |
| 1657 | const mod = sema.mod; | ||
| 1658 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 1656 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 1659 | const src = inst_data.src(); | 1657 | const src = inst_data.src(); |
| 1660 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 1658 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| ... | @@ -1713,7 +1711,7 @@ fn analyzeBodyInner( | ... | @@ -1713,7 +1711,7 @@ fn analyzeBodyInner( |
| 1713 | const noreturn_inst = block.instructions.popOrNull(); | 1711 | const noreturn_inst = block.instructions.popOrNull(); |
| 1714 | while (dbg_block_begins > 0) { | 1712 | while (dbg_block_begins > 0) { |
| 1715 | dbg_block_begins -= 1; | 1713 | dbg_block_begins -= 1; |
| 1716 | if (block.is_comptime or sema.mod.comp.bin_file.options.strip) continue; | 1714 | if (block.is_comptime or mod.comp.bin_file.options.strip) continue; |
| 1717 | 1715 | ||
| 1718 | _ = try block.addInst(.{ | 1716 | _ = try block.addInst(.{ |
| 1719 | .tag = .dbg_block_end, | 1717 | .tag = .dbg_block_end, |
| ... | @@ -2172,7 +2170,7 @@ fn errNote( | ... | @@ -2172,7 +2170,7 @@ fn errNote( |
| 2172 | ) error{OutOfMemory}!void { | 2170 | ) error{OutOfMemory}!void { |
| 2173 | const mod = sema.mod; | 2171 | const mod = sema.mod; |
| 2174 | const src_decl = mod.declPtr(block.src_decl); | 2172 | const src_decl = mod.declPtr(block.src_decl); |
| 2175 | return mod.errNoteNonLazy(src.toSrcLoc(src_decl), parent, format, args); | 2173 | return mod.errNoteNonLazy(src.toSrcLoc(src_decl, mod), parent, format, args); |
| 2176 | } | 2174 | } |
| 2177 | 2175 | ||
| 2178 | fn addFieldErrNote( | 2176 | fn addFieldErrNote( |
| ... | @@ -2185,19 +2183,19 @@ fn addFieldErrNote( | ... | @@ -2185,19 +2183,19 @@ fn addFieldErrNote( |
| 2185 | ) !void { | 2183 | ) !void { |
| 2186 | @setCold(true); | 2184 | @setCold(true); |
| 2187 | const mod = sema.mod; | 2185 | const mod = sema.mod; |
| 2188 | const decl_index = container_ty.getOwnerDecl(); | 2186 | const decl_index = container_ty.getOwnerDecl(mod); |
| 2189 | const decl = mod.declPtr(decl_index); | 2187 | const decl = mod.declPtr(decl_index); |
| 2190 | 2188 | ||
| 2191 | const field_src = blk: { | 2189 | const field_src = blk: { |
| 2192 | const tree = decl.getFileScope().getTree(sema.gpa) catch |err| { | 2190 | const tree = decl.getFileScope(mod).getTree(sema.gpa) catch |err| { |
| 2193 | log.err("unable to load AST to report compile error: {s}", .{@errorName(err)}); | 2191 | log.err("unable to load AST to report compile error: {s}", .{@errorName(err)}); |
| 2194 | break :blk decl.srcLoc(); | 2192 | break :blk decl.srcLoc(mod); |
| 2195 | }; | 2193 | }; |
| 2196 | 2194 | ||
| 2197 | const container_node = decl.relativeToNodeIndex(0); | 2195 | const container_node = decl.relativeToNodeIndex(0); |
| 2198 | const node_tags = tree.nodes.items(.tag); | 2196 | const node_tags = tree.nodes.items(.tag); |
| 2199 | var buf: [2]std.zig.Ast.Node.Index = undefined; | 2197 | var buf: [2]std.zig.Ast.Node.Index = undefined; |
| 2200 | const container_decl = tree.fullContainerDecl(&buf, container_node) orelse break :blk decl.srcLoc(); | 2198 | const container_decl = tree.fullContainerDecl(&buf, container_node) orelse break :blk decl.srcLoc(mod); |
| 2201 | 2199 | ||
| 2202 | var it_index: usize = 0; | 2200 | var it_index: usize = 0; |
| 2203 | for (container_decl.ast.members) |member_node| { | 2201 | for (container_decl.ast.members) |member_node| { |
| ... | @@ -2207,7 +2205,7 @@ fn addFieldErrNote( | ... | @@ -2207,7 +2205,7 @@ fn addFieldErrNote( |
| 2207 | .container_field, | 2205 | .container_field, |
| 2208 | => { | 2206 | => { |
| 2209 | if (it_index == field_index) { | 2207 | if (it_index == field_index) { |
| 2210 | break :blk decl.nodeOffsetSrcLoc(decl.nodeIndexToRelative(member_node)); | 2208 | break :blk decl.nodeOffsetSrcLoc(decl.nodeIndexToRelative(member_node), mod); |
| 2211 | } | 2209 | } |
| 2212 | it_index += 1; | 2210 | it_index += 1; |
| 2213 | }, | 2211 | }, |
| ... | @@ -2228,7 +2226,7 @@ fn errMsg( | ... | @@ -2228,7 +2226,7 @@ fn errMsg( |
| 2228 | ) error{OutOfMemory}!*Module.ErrorMsg { | 2226 | ) error{OutOfMemory}!*Module.ErrorMsg { |
| 2229 | const mod = sema.mod; | 2227 | const mod = sema.mod; |
| 2230 | const src_decl = mod.declPtr(block.src_decl); | 2228 | const src_decl = mod.declPtr(block.src_decl); |
| 2231 | return Module.ErrorMsg.create(sema.gpa, src.toSrcLoc(src_decl), format, args); | 2229 | return Module.ErrorMsg.create(sema.gpa, src.toSrcLoc(src_decl, mod), format, args); |
| 2232 | } | 2230 | } |
| 2233 | 2231 | ||
| 2234 | pub fn fail( | 2232 | pub fn fail( |
| ... | @@ -2287,7 +2285,7 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { | ... | @@ -2287,7 +2285,7 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { |
| 2287 | if (gop.found_existing) break; | 2285 | if (gop.found_existing) break; |
| 2288 | if (cur_reference_trace < max_references) { | 2286 | if (cur_reference_trace < max_references) { |
| 2289 | const decl = sema.mod.declPtr(ref.referencer); | 2287 | const decl = sema.mod.declPtr(ref.referencer); |
| 2290 | try reference_stack.append(.{ .decl = decl.name, .src_loc = ref.src.toSrcLoc(decl) }); | 2288 | try reference_stack.append(.{ .decl = decl.name, .src_loc = ref.src.toSrcLoc(decl, mod) }); |
| 2291 | } | 2289 | } |
| 2292 | referenced_by = ref.referencer; | 2290 | referenced_by = ref.referencer; |
| 2293 | } | 2291 | } |
| ... | @@ -2664,7 +2662,7 @@ pub fn analyzeStructDecl( | ... | @@ -2664,7 +2662,7 @@ pub fn analyzeStructDecl( |
| 2664 | } | 2662 | } |
| 2665 | } | 2663 | } |
| 2666 | 2664 | ||
| 2667 | _ = try sema.mod.scanNamespace(&struct_obj.namespace, extra_index, decls_len, new_decl); | 2665 | _ = try sema.mod.scanNamespace(struct_obj.namespace, extra_index, decls_len, new_decl); |
| 2668 | } | 2666 | } |
| 2669 | 2667 | ||
| 2670 | fn zirStructDecl( | 2668 | fn zirStructDecl( |
| ... | @@ -2702,15 +2700,12 @@ fn zirStructDecl( | ... | @@ -2702,15 +2700,12 @@ fn zirStructDecl( |
| 2702 | .status = .none, | 2700 | .status = .none, |
| 2703 | .known_non_opv = undefined, | 2701 | .known_non_opv = undefined, |
| 2704 | .is_tuple = small.is_tuple, | 2702 | .is_tuple = small.is_tuple, |
| 2705 | .namespace = .{ | 2703 | .namespace = try mod.createNamespace(.{ |
| 2706 | .parent = block.namespace, | 2704 | .parent = block.namespace.toOptional(), |
| 2707 | .ty = struct_ty, | 2705 | .ty = struct_ty, |
| 2708 | .file_scope = block.getFileScope(), | 2706 | .file_scope = block.getFileScope(mod), |
| 2709 | }, | 2707 | }), |
| 2710 | }; | 2708 | }; |
| 2711 | std.log.scoped(.module).debug("create struct {*} owned by {*} ({s})", .{ | ||
| 2712 | &struct_obj.namespace, new_decl, new_decl.name, | ||
| 2713 | }); | ||
| 2714 | try sema.analyzeStructDecl(new_decl, inst, struct_obj); | 2709 | try sema.analyzeStructDecl(new_decl, inst, struct_obj); |
| 2715 | try new_decl.finalizeNewArena(&new_decl_arena); | 2710 | try new_decl.finalizeNewArena(&new_decl_arena); |
| 2716 | return sema.analyzeDeclVal(block, src, new_decl_index); | 2711 | return sema.analyzeDeclVal(block, src, new_decl_index); |
| ... | @@ -2887,15 +2882,12 @@ fn zirEnumDecl( | ... | @@ -2887,15 +2882,12 @@ fn zirEnumDecl( |
| 2887 | .tag_ty_inferred = true, | 2882 | .tag_ty_inferred = true, |
| 2888 | .fields = .{}, | 2883 | .fields = .{}, |
| 2889 | .values = .{}, | 2884 | .values = .{}, |
| 2890 | .namespace = .{ | 2885 | .namespace = try mod.createNamespace(.{ |
| 2891 | .parent = block.namespace, | 2886 | .parent = block.namespace.toOptional(), |
| 2892 | .ty = enum_ty, | 2887 | .ty = enum_ty, |
| 2893 | .file_scope = block.getFileScope(), | 2888 | .file_scope = block.getFileScope(mod), |
| 2894 | }, | 2889 | }), |
| 2895 | }; | 2890 | }; |
| 2896 | std.log.scoped(.module).debug("create enum {*} owned by {*} ({s})", .{ | ||
| 2897 | &enum_obj.namespace, new_decl, new_decl.name, | ||
| 2898 | }); | ||
| 2899 | 2891 | ||
| 2900 | try new_decl.finalizeNewArena(&new_decl_arena); | 2892 | try new_decl.finalizeNewArena(&new_decl_arena); |
| 2901 | const decl_val = try sema.analyzeDeclVal(block, src, new_decl_index); | 2893 | const decl_val = try sema.analyzeDeclVal(block, src, new_decl_index); |
| ... | @@ -2905,7 +2897,7 @@ fn zirEnumDecl( | ... | @@ -2905,7 +2897,7 @@ fn zirEnumDecl( |
| 2905 | const decl_arena_allocator = new_decl.value_arena.?.acquire(gpa, &decl_arena); | 2897 | const decl_arena_allocator = new_decl.value_arena.?.acquire(gpa, &decl_arena); |
| 2906 | defer new_decl.value_arena.?.release(&decl_arena); | 2898 | defer new_decl.value_arena.?.release(&decl_arena); |
| 2907 | 2899 | ||
| 2908 | extra_index = try mod.scanNamespace(&enum_obj.namespace, extra_index, decls_len, new_decl); | 2900 | extra_index = try mod.scanNamespace(enum_obj.namespace, extra_index, decls_len, new_decl); |
| 2909 | 2901 | ||
| 2910 | const body = sema.code.extra[extra_index..][0..body_len]; | 2902 | const body = sema.code.extra[extra_index..][0..body_len]; |
| 2911 | extra_index += body.len; | 2903 | extra_index += body.len; |
| ... | @@ -2944,7 +2936,7 @@ fn zirEnumDecl( | ... | @@ -2944,7 +2936,7 @@ fn zirEnumDecl( |
| 2944 | .parent = null, | 2936 | .parent = null, |
| 2945 | .sema = sema, | 2937 | .sema = sema, |
| 2946 | .src_decl = new_decl_index, | 2938 | .src_decl = new_decl_index, |
| 2947 | .namespace = &enum_obj.namespace, | 2939 | .namespace = enum_obj.namespace, |
| 2948 | .wip_capture_scope = wip_captures.scope, | 2940 | .wip_capture_scope = wip_captures.scope, |
| 2949 | .instructions = .{}, | 2941 | .instructions = .{}, |
| 2950 | .inlining = null, | 2942 | .inlining = null, |
| ... | @@ -3164,17 +3156,14 @@ fn zirUnionDecl( | ... | @@ -3164,17 +3156,14 @@ fn zirUnionDecl( |
| 3164 | .zir_index = inst, | 3156 | .zir_index = inst, |
| 3165 | .layout = small.layout, | 3157 | .layout = small.layout, |
| 3166 | .status = .none, | 3158 | .status = .none, |
| 3167 | .namespace = .{ | 3159 | .namespace = try mod.createNamespace(.{ |
| 3168 | .parent = block.namespace, | 3160 | .parent = block.namespace.toOptional(), |
| 3169 | .ty = union_ty, | 3161 | .ty = union_ty, |
| 3170 | .file_scope = block.getFileScope(), | 3162 | .file_scope = block.getFileScope(mod), |
| 3171 | }, | 3163 | }), |
| 3172 | }; | 3164 | }; |
| 3173 | std.log.scoped(.module).debug("create union {*} owned by {*} ({s})", .{ | ||
| 3174 | &union_obj.namespace, new_decl, new_decl.name, | ||
| 3175 | }); | ||
| 3176 | 3165 | ||
| 3177 | _ = try mod.scanNamespace(&union_obj.namespace, extra_index, decls_len, new_decl); | 3166 | _ = try mod.scanNamespace(union_obj.namespace, extra_index, decls_len, new_decl); |
| 3178 | 3167 | ||
| 3179 | try new_decl.finalizeNewArena(&new_decl_arena); | 3168 | try new_decl.finalizeNewArena(&new_decl_arena); |
| 3180 | return sema.analyzeDeclVal(block, src, new_decl_index); | 3169 | return sema.analyzeDeclVal(block, src, new_decl_index); |
| ... | @@ -3208,37 +3197,37 @@ fn zirOpaqueDecl( | ... | @@ -3208,37 +3197,37 @@ fn zirOpaqueDecl( |
| 3208 | 3197 | ||
| 3209 | var new_decl_arena = std.heap.ArenaAllocator.init(gpa); | 3198 | var new_decl_arena = std.heap.ArenaAllocator.init(gpa); |
| 3210 | errdefer new_decl_arena.deinit(); | 3199 | errdefer new_decl_arena.deinit(); |
| 3211 | const new_decl_arena_allocator = new_decl_arena.allocator(); | ||
| 3212 | 3200 | ||
| 3213 | const opaque_obj = try new_decl_arena_allocator.create(Module.Opaque); | 3201 | // Because these three things each reference each other, `undefined` |
| 3214 | const opaque_ty_payload = try new_decl_arena_allocator.create(Type.Payload.Opaque); | 3202 | // placeholders are used in two places before being set after the opaque |
| 3215 | opaque_ty_payload.* = .{ | 3203 | // type gains an InternPool index. |
| 3216 | .base = .{ .tag = .@"opaque" }, | 3204 | |
| 3217 | .data = opaque_obj, | ||
| 3218 | }; | ||
| 3219 | const opaque_ty = Type.initPayload(&opaque_ty_payload.base); | ||
| 3220 | const opaque_val = try Value.Tag.ty.create(new_decl_arena_allocator, opaque_ty); | ||
| 3221 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{ | 3205 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{ |
| 3222 | .ty = Type.type, | 3206 | .ty = Type.type, |
| 3223 | .val = opaque_val, | 3207 | .val = undefined, |
| 3224 | }, small.name_strategy, "opaque", inst); | 3208 | }, small.name_strategy, "opaque", inst); |
| 3225 | const new_decl = mod.declPtr(new_decl_index); | 3209 | const new_decl = mod.declPtr(new_decl_index); |
| 3226 | new_decl.owns_tv = true; | 3210 | new_decl.owns_tv = true; |
| 3227 | errdefer mod.abortAnonDecl(new_decl_index); | 3211 | errdefer mod.abortAnonDecl(new_decl_index); |
| 3228 | 3212 | ||
| 3229 | opaque_obj.* = .{ | 3213 | const new_namespace_index = try mod.createNamespace(.{ |
| 3230 | .owner_decl = new_decl_index, | 3214 | .parent = block.namespace.toOptional(), |
| 3231 | .namespace = .{ | 3215 | .ty = undefined, |
| 3232 | .parent = block.namespace, | 3216 | .file_scope = block.getFileScope(mod), |
| 3233 | .ty = opaque_ty, | ||
| 3234 | .file_scope = block.getFileScope(), | ||
| 3235 | }, | ||
| 3236 | }; | ||
| 3237 | std.log.scoped(.module).debug("create opaque {*} owned by {*} ({s})", .{ | ||
| 3238 | &opaque_obj.namespace, new_decl, new_decl.name, | ||
| 3239 | }); | 3217 | }); |
| 3218 | const new_namespace = mod.namespacePtr(new_namespace_index); | ||
| 3219 | errdefer @panic("TODO error handling"); | ||
| 3220 | |||
| 3221 | const opaque_ty = try mod.intern_pool.get(gpa, .{ .opaque_type = .{ | ||
| 3222 | .decl = new_decl_index, | ||
| 3223 | .namespace = new_namespace_index, | ||
| 3224 | } }); | ||
| 3225 | errdefer @panic("TODO error handling"); | ||
| 3226 | |||
| 3227 | new_decl.val = opaque_ty.toValue(); | ||
| 3228 | new_namespace.ty = opaque_ty.toType(); | ||
| 3240 | 3229 | ||
| 3241 | extra_index = try mod.scanNamespace(&opaque_obj.namespace, extra_index, decls_len, new_decl); | 3230 | extra_index = try mod.scanNamespace(new_namespace_index, extra_index, decls_len, new_decl); |
| 3242 | 3231 | ||
| 3243 | try new_decl.finalizeNewArena(&new_decl_arena); | 3232 | try new_decl.finalizeNewArena(&new_decl_arena); |
| 3244 | return sema.analyzeDeclVal(block, src, new_decl_index); | 3233 | return sema.analyzeDeclVal(block, src, new_decl_index); |
| ... | @@ -4848,7 +4837,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -4848,7 +4837,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 4848 | errdefer msg.destroy(sema.gpa); | 4837 | errdefer msg.destroy(sema.gpa); |
| 4849 | 4838 | ||
| 4850 | const src_decl = sema.mod.declPtr(block.src_decl); | 4839 | const src_decl = sema.mod.declPtr(block.src_decl); |
| 4851 | try sema.explainWhyTypeIsComptime(msg, src.toSrcLoc(src_decl), elem_ty); | 4840 | try sema.explainWhyTypeIsComptime(msg, src.toSrcLoc(src_decl, mod), elem_ty); |
| 4852 | break :msg msg; | 4841 | break :msg msg; |
| 4853 | }; | 4842 | }; |
| 4854 | return sema.failWithOwnedErrorMsg(msg); | 4843 | return sema.failWithOwnedErrorMsg(msg); |
| ... | @@ -4870,7 +4859,7 @@ fn failWithBadMemberAccess( | ... | @@ -4870,7 +4859,7 @@ fn failWithBadMemberAccess( |
| 4870 | .Enum => "enum", | 4859 | .Enum => "enum", |
| 4871 | else => unreachable, | 4860 | else => unreachable, |
| 4872 | }; | 4861 | }; |
| 4873 | if (agg_ty.getOwnerDeclOrNull()) |some| if (sema.mod.declIsRoot(some)) { | 4862 | if (agg_ty.getOwnerDeclOrNull(mod)) |some| if (sema.mod.declIsRoot(some)) { |
| 4874 | return sema.fail(block, field_src, "root struct of file '{}' has no member named '{s}'", .{ | 4863 | return sema.fail(block, field_src, "root struct of file '{}' has no member named '{s}'", .{ |
| 4875 | agg_ty.fmt(sema.mod), field_name, | 4864 | agg_ty.fmt(sema.mod), field_name, |
| 4876 | }); | 4865 | }); |
| ... | @@ -5632,7 +5621,7 @@ fn analyzeBlockBody( | ... | @@ -5632,7 +5621,7 @@ fn analyzeBlockBody( |
| 5632 | try sema.errNote(child_block, runtime_src, msg, "runtime control flow here", .{}); | 5621 | try sema.errNote(child_block, runtime_src, msg, "runtime control flow here", .{}); |
| 5633 | 5622 | ||
| 5634 | const child_src_decl = mod.declPtr(child_block.src_decl); | 5623 | const child_src_decl = mod.declPtr(child_block.src_decl); |
| 5635 | try sema.explainWhyTypeIsComptime(msg, type_src.toSrcLoc(child_src_decl), resolved_ty); | 5624 | try sema.explainWhyTypeIsComptime(msg, type_src.toSrcLoc(child_src_decl, mod), resolved_ty); |
| 5636 | 5625 | ||
| 5637 | break :msg msg; | 5626 | break :msg msg; |
| 5638 | }; | 5627 | }; |
| ... | @@ -5703,6 +5692,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -5703,6 +5692,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5703 | const tracy = trace(@src()); | 5692 | const tracy = trace(@src()); |
| 5704 | defer tracy.end(); | 5693 | defer tracy.end(); |
| 5705 | 5694 | ||
| 5695 | const mod = sema.mod; | ||
| 5706 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 5696 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5707 | const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data; | 5697 | const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data; |
| 5708 | const src = inst_data.src(); | 5698 | const src = inst_data.src(); |
| ... | @@ -5711,7 +5701,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -5711,7 +5701,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5711 | const decl_name = sema.code.nullTerminatedString(extra.decl_name); | 5701 | const decl_name = sema.code.nullTerminatedString(extra.decl_name); |
| 5712 | const decl_index = if (extra.namespace != .none) index_blk: { | 5702 | const decl_index = if (extra.namespace != .none) index_blk: { |
| 5713 | const container_ty = try sema.resolveType(block, operand_src, extra.namespace); | 5703 | const container_ty = try sema.resolveType(block, operand_src, extra.namespace); |
| 5714 | const container_namespace = container_ty.getNamespace().?; | 5704 | const container_namespace = container_ty.getNamespaceIndex(mod).unwrap().?; |
| 5715 | 5705 | ||
| 5716 | const maybe_index = try sema.lookupInNamespace(block, operand_src, container_namespace, decl_name, false); | 5706 | const maybe_index = try sema.lookupInNamespace(block, operand_src, container_namespace, decl_name, false); |
| 5717 | break :index_blk maybe_index orelse | 5707 | break :index_blk maybe_index orelse |
| ... | @@ -5725,8 +5715,8 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -5725,8 +5715,8 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5725 | else => |e| return e, | 5715 | else => |e| return e, |
| 5726 | }; | 5716 | }; |
| 5727 | { | 5717 | { |
| 5728 | try sema.mod.ensureDeclAnalyzed(decl_index); | 5718 | try mod.ensureDeclAnalyzed(decl_index); |
| 5729 | const exported_decl = sema.mod.declPtr(decl_index); | 5719 | const exported_decl = mod.declPtr(decl_index); |
| 5730 | if (exported_decl.val.castTag(.function)) |some| { | 5720 | if (exported_decl.val.castTag(.function)) |some| { |
| 5731 | return sema.analyzeExport(block, src, options, some.data.owner_decl); | 5721 | return sema.analyzeExport(block, src, options, some.data.owner_decl); |
| 5732 | } | 5722 | } |
| ... | @@ -5789,7 +5779,7 @@ pub fn analyzeExport( | ... | @@ -5789,7 +5779,7 @@ pub fn analyzeExport( |
| 5789 | errdefer msg.destroy(sema.gpa); | 5779 | errdefer msg.destroy(sema.gpa); |
| 5790 | 5780 | ||
| 5791 | const src_decl = sema.mod.declPtr(block.src_decl); | 5781 | const src_decl = sema.mod.declPtr(block.src_decl); |
| 5792 | try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl), exported_decl.ty, .other); | 5782 | try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), exported_decl.ty, .other); |
| 5793 | 5783 | ||
| 5794 | try sema.addDeclaredHereNote(msg, exported_decl.ty); | 5784 | try sema.addDeclaredHereNote(msg, exported_decl.ty); |
| 5795 | break :msg msg; | 5785 | break :msg msg; |
| ... | @@ -6075,12 +6065,13 @@ fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -6075,12 +6065,13 @@ fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 6075 | } | 6065 | } |
| 6076 | 6066 | ||
| 6077 | fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: []const u8) !Decl.Index { | 6067 | fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: []const u8) !Decl.Index { |
| 6068 | const mod = sema.mod; | ||
| 6078 | var namespace = block.namespace; | 6069 | var namespace = block.namespace; |
| 6079 | while (true) { | 6070 | while (true) { |
| 6080 | if (try sema.lookupInNamespace(block, src, namespace, name, false)) |decl_index| { | 6071 | if (try sema.lookupInNamespace(block, src, namespace, name, false)) |decl_index| { |
| 6081 | return decl_index; | 6072 | return decl_index; |
| 6082 | } | 6073 | } |
| 6083 | namespace = namespace.parent orelse break; | 6074 | namespace = mod.namespacePtr(namespace).parent.unwrap() orelse break; |
| 6084 | } | 6075 | } |
| 6085 | unreachable; // AstGen detects use of undeclared identifier errors. | 6076 | unreachable; // AstGen detects use of undeclared identifier errors. |
| 6086 | } | 6077 | } |
| ... | @@ -6091,13 +6082,14 @@ fn lookupInNamespace( | ... | @@ -6091,13 +6082,14 @@ fn lookupInNamespace( |
| 6091 | sema: *Sema, | 6082 | sema: *Sema, |
| 6092 | block: *Block, | 6083 | block: *Block, |
| 6093 | src: LazySrcLoc, | 6084 | src: LazySrcLoc, |
| 6094 | namespace: *Namespace, | 6085 | namespace_index: Namespace.Index, |
| 6095 | ident_name: []const u8, | 6086 | ident_name: []const u8, |
| 6096 | observe_usingnamespace: bool, | 6087 | observe_usingnamespace: bool, |
| 6097 | ) CompileError!?Decl.Index { | 6088 | ) CompileError!?Decl.Index { |
| 6098 | const mod = sema.mod; | 6089 | const mod = sema.mod; |
| 6099 | 6090 | ||
| 6100 | const namespace_decl_index = namespace.getDeclIndex(); | 6091 | const namespace = mod.namespacePtr(namespace_index); |
| 6092 | const namespace_decl_index = namespace.getDeclIndex(mod); | ||
| 6101 | const namespace_decl = sema.mod.declPtr(namespace_decl_index); | 6093 | const namespace_decl = sema.mod.declPtr(namespace_decl_index); |
| 6102 | if (namespace_decl.analysis == .file_failure) { | 6094 | if (namespace_decl.analysis == .file_failure) { |
| 6103 | try mod.declareDeclDependency(sema.owner_decl_index, namespace_decl_index); | 6095 | try mod.declareDeclDependency(sema.owner_decl_index, namespace_decl_index); |
| ... | @@ -6105,7 +6097,7 @@ fn lookupInNamespace( | ... | @@ -6105,7 +6097,7 @@ fn lookupInNamespace( |
| 6105 | } | 6097 | } |
| 6106 | 6098 | ||
| 6107 | if (observe_usingnamespace and namespace.usingnamespace_set.count() != 0) { | 6099 | if (observe_usingnamespace and namespace.usingnamespace_set.count() != 0) { |
| 6108 | const src_file = block.namespace.file_scope; | 6100 | const src_file = mod.namespacePtr(block.namespace).file_scope; |
| 6109 | 6101 | ||
| 6110 | const gpa = sema.gpa; | 6102 | const gpa = sema.gpa; |
| 6111 | var checked_namespaces: std.AutoArrayHashMapUnmanaged(*Namespace, bool) = .{}; | 6103 | var checked_namespaces: std.AutoArrayHashMapUnmanaged(*Namespace, bool) = .{}; |
| ... | @@ -6124,7 +6116,7 @@ fn lookupInNamespace( | ... | @@ -6124,7 +6116,7 @@ fn lookupInNamespace( |
| 6124 | // Skip decls which are not marked pub, which are in a different | 6116 | // Skip decls which are not marked pub, which are in a different |
| 6125 | // file than the `a.b`/`@hasDecl` syntax. | 6117 | // file than the `a.b`/`@hasDecl` syntax. |
| 6126 | const decl = mod.declPtr(decl_index); | 6118 | const decl = mod.declPtr(decl_index); |
| 6127 | if (decl.is_pub or (src_file == decl.getFileScope() and checked_namespaces.values()[check_i])) { | 6119 | if (decl.is_pub or (src_file == decl.getFileScope(mod) and checked_namespaces.values()[check_i])) { |
| 6128 | try candidates.append(gpa, decl_index); | 6120 | try candidates.append(gpa, decl_index); |
| 6129 | } | 6121 | } |
| 6130 | } | 6122 | } |
| ... | @@ -6135,15 +6127,15 @@ fn lookupInNamespace( | ... | @@ -6135,15 +6127,15 @@ fn lookupInNamespace( |
| 6135 | if (sub_usingnamespace_decl_index == sema.owner_decl_index) continue; | 6127 | if (sub_usingnamespace_decl_index == sema.owner_decl_index) continue; |
| 6136 | const sub_usingnamespace_decl = mod.declPtr(sub_usingnamespace_decl_index); | 6128 | const sub_usingnamespace_decl = mod.declPtr(sub_usingnamespace_decl_index); |
| 6137 | const sub_is_pub = entry.value_ptr.*; | 6129 | const sub_is_pub = entry.value_ptr.*; |
| 6138 | if (!sub_is_pub and src_file != sub_usingnamespace_decl.getFileScope()) { | 6130 | if (!sub_is_pub and src_file != sub_usingnamespace_decl.getFileScope(mod)) { |
| 6139 | // Skip usingnamespace decls which are not marked pub, which are in | 6131 | // Skip usingnamespace decls which are not marked pub, which are in |
| 6140 | // a different file than the `a.b`/`@hasDecl` syntax. | 6132 | // a different file than the `a.b`/`@hasDecl` syntax. |
| 6141 | continue; | 6133 | continue; |
| 6142 | } | 6134 | } |
| 6143 | try sema.ensureDeclAnalyzed(sub_usingnamespace_decl_index); | 6135 | try sema.ensureDeclAnalyzed(sub_usingnamespace_decl_index); |
| 6144 | const ns_ty = sub_usingnamespace_decl.val.castTag(.ty).?.data; | 6136 | const ns_ty = sub_usingnamespace_decl.val.castTag(.ty).?.data; |
| 6145 | const sub_ns = ns_ty.getNamespace().?; | 6137 | const sub_ns = ns_ty.getNamespace(mod).?; |
| 6146 | try checked_namespaces.put(gpa, sub_ns, src_file == sub_usingnamespace_decl.getFileScope()); | 6138 | try checked_namespaces.put(gpa, sub_ns, src_file == sub_usingnamespace_decl.getFileScope(mod)); |
| 6147 | } | 6139 | } |
| 6148 | } | 6140 | } |
| 6149 | 6141 | ||
| ... | @@ -6171,7 +6163,7 @@ fn lookupInNamespace( | ... | @@ -6171,7 +6163,7 @@ fn lookupInNamespace( |
| 6171 | errdefer msg.destroy(gpa); | 6163 | errdefer msg.destroy(gpa); |
| 6172 | for (candidates.items) |candidate_index| { | 6164 | for (candidates.items) |candidate_index| { |
| 6173 | const candidate = mod.declPtr(candidate_index); | 6165 | const candidate = mod.declPtr(candidate_index); |
| 6174 | const src_loc = candidate.srcLoc(); | 6166 | const src_loc = candidate.srcLoc(mod); |
| 6175 | try mod.errNoteNonLazy(src_loc, msg, "declared here", .{}); | 6167 | try mod.errNoteNonLazy(src_loc, msg, "declared here", .{}); |
| 6176 | } | 6168 | } |
| 6177 | break :msg msg; | 6169 | break :msg msg; |
| ... | @@ -6532,7 +6524,7 @@ fn checkCallArgumentCount( | ... | @@ -6532,7 +6524,7 @@ fn checkCallArgumentCount( |
| 6532 | ); | 6524 | ); |
| 6533 | errdefer msg.destroy(sema.gpa); | 6525 | errdefer msg.destroy(sema.gpa); |
| 6534 | 6526 | ||
| 6535 | if (maybe_decl) |fn_decl| try sema.mod.errNoteNonLazy(fn_decl.srcLoc(), msg, "function declared here", .{}); | 6527 | if (maybe_decl) |fn_decl| try sema.mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{}); |
| 6536 | break :msg msg; | 6528 | break :msg msg; |
| 6537 | }; | 6529 | }; |
| 6538 | return sema.failWithOwnedErrorMsg(msg); | 6530 | return sema.failWithOwnedErrorMsg(msg); |
| ... | @@ -6669,7 +6661,7 @@ fn analyzeCall( | ... | @@ -6669,7 +6661,7 @@ fn analyzeCall( |
| 6669 | ); | 6661 | ); |
| 6670 | errdefer msg.destroy(sema.gpa); | 6662 | errdefer msg.destroy(sema.gpa); |
| 6671 | 6663 | ||
| 6672 | if (maybe_decl) |fn_decl| try sema.mod.errNoteNonLazy(fn_decl.srcLoc(), msg, "function declared here", .{}); | 6664 | if (maybe_decl) |fn_decl| try sema.mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{}); |
| 6673 | break :msg msg; | 6665 | break :msg msg; |
| 6674 | }; | 6666 | }; |
| 6675 | return sema.failWithOwnedErrorMsg(msg); | 6667 | return sema.failWithOwnedErrorMsg(msg); |
| ... | @@ -6811,7 +6803,7 @@ fn analyzeCall( | ... | @@ -6811,7 +6803,7 @@ fn analyzeCall( |
| 6811 | // than create a child one. | 6803 | // than create a child one. |
| 6812 | const parent_zir = sema.code; | 6804 | const parent_zir = sema.code; |
| 6813 | const fn_owner_decl = mod.declPtr(module_fn.owner_decl); | 6805 | const fn_owner_decl = mod.declPtr(module_fn.owner_decl); |
| 6814 | sema.code = fn_owner_decl.getFileScope().zir; | 6806 | sema.code = fn_owner_decl.getFileScope(mod).zir; |
| 6815 | defer sema.code = parent_zir; | 6807 | defer sema.code = parent_zir; |
| 6816 | 6808 | ||
| 6817 | try mod.declareDeclDependencyType(sema.owner_decl_index, module_fn.owner_decl, .function_body); | 6809 | try mod.declareDeclDependencyType(sema.owner_decl_index, module_fn.owner_decl, .function_body); |
| ... | @@ -6911,7 +6903,7 @@ fn analyzeCall( | ... | @@ -6911,7 +6903,7 @@ fn analyzeCall( |
| 6911 | try sema.analyzeInlineCallArg( | 6903 | try sema.analyzeInlineCallArg( |
| 6912 | block, | 6904 | block, |
| 6913 | &child_block, | 6905 | &child_block, |
| 6914 | Module.argSrc(call_src.node_offset.x, sema.gpa, decl, arg_i, bound_arg_src), | 6906 | mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src), |
| 6915 | inst, | 6907 | inst, |
| 6916 | new_fn_info, | 6908 | new_fn_info, |
| 6917 | &arg_i, | 6909 | &arg_i, |
| ... | @@ -7098,7 +7090,7 @@ fn analyzeCall( | ... | @@ -7098,7 +7090,7 @@ fn analyzeCall( |
| 7098 | const decl = sema.mod.declPtr(block.src_decl); | 7090 | const decl = sema.mod.declPtr(block.src_decl); |
| 7099 | _ = try sema.analyzeCallArg( | 7091 | _ = try sema.analyzeCallArg( |
| 7100 | block, | 7092 | block, |
| 7101 | Module.argSrc(call_src.node_offset.x, sema.gpa, decl, i, bound_arg_src), | 7093 | mod.argSrc(call_src.node_offset.x, decl, i, bound_arg_src), |
| 7102 | param_ty, | 7094 | param_ty, |
| 7103 | uncasted_arg, | 7095 | uncasted_arg, |
| 7104 | opts, | 7096 | opts, |
| ... | @@ -7114,7 +7106,7 @@ fn analyzeCall( | ... | @@ -7114,7 +7106,7 @@ fn analyzeCall( |
| 7114 | _ = try sema.coerceVarArgParam( | 7106 | _ = try sema.coerceVarArgParam( |
| 7115 | block, | 7107 | block, |
| 7116 | uncasted_arg, | 7108 | uncasted_arg, |
| 7117 | Module.argSrc(call_src.node_offset.x, sema.gpa, decl, i, bound_arg_src), | 7109 | mod.argSrc(call_src.node_offset.x, decl, i, bound_arg_src), |
| 7118 | ); | 7110 | ); |
| 7119 | unreachable; | 7111 | unreachable; |
| 7120 | }, | 7112 | }, |
| ... | @@ -7406,7 +7398,8 @@ fn instantiateGenericCall( | ... | @@ -7406,7 +7398,8 @@ fn instantiateGenericCall( |
| 7406 | // can match against `uncasted_args` rather than doing the work below to create a | 7398 | // can match against `uncasted_args` rather than doing the work below to create a |
| 7407 | // generic Scope only to junk it if it matches an existing instantiation. | 7399 | // generic Scope only to junk it if it matches an existing instantiation. |
| 7408 | const fn_owner_decl = mod.declPtr(module_fn.owner_decl); | 7400 | const fn_owner_decl = mod.declPtr(module_fn.owner_decl); |
| 7409 | const namespace = fn_owner_decl.src_namespace; | 7401 | const namespace_index = fn_owner_decl.src_namespace; |
| 7402 | const namespace = mod.namespacePtr(namespace_index); | ||
| 7410 | const fn_zir = namespace.file_scope.zir; | 7403 | const fn_zir = namespace.file_scope.zir; |
| 7411 | const fn_info = fn_zir.getFnInfo(module_fn.zir_body_inst); | 7404 | const fn_info = fn_zir.getFnInfo(module_fn.zir_body_inst); |
| 7412 | const zir_tags = fn_zir.instructions.items(.tag); | 7405 | const zir_tags = fn_zir.instructions.items(.tag); |
| ... | @@ -7456,7 +7449,7 @@ fn instantiateGenericCall( | ... | @@ -7456,7 +7449,7 @@ fn instantiateGenericCall( |
| 7456 | const arg_val = sema.analyzeGenericCallArgVal(block, .unneeded, uncasted_args[i]) catch |err| switch (err) { | 7449 | const arg_val = sema.analyzeGenericCallArgVal(block, .unneeded, uncasted_args[i]) catch |err| switch (err) { |
| 7457 | error.NeededSourceLocation => { | 7450 | error.NeededSourceLocation => { |
| 7458 | const decl = sema.mod.declPtr(block.src_decl); | 7451 | const decl = sema.mod.declPtr(block.src_decl); |
| 7459 | const arg_src = Module.argSrc(call_src.node_offset.x, sema.gpa, decl, i, bound_arg_src); | 7452 | const arg_src = mod.argSrc(call_src.node_offset.x, decl, i, bound_arg_src); |
| 7460 | _ = try sema.analyzeGenericCallArgVal(block, arg_src, uncasted_args[i]); | 7453 | _ = try sema.analyzeGenericCallArgVal(block, arg_src, uncasted_args[i]); |
| 7461 | unreachable; | 7454 | unreachable; |
| 7462 | }, | 7455 | }, |
| ... | @@ -7519,9 +7512,9 @@ fn instantiateGenericCall( | ... | @@ -7519,9 +7512,9 @@ fn instantiateGenericCall( |
| 7519 | try namespace.anon_decls.ensureUnusedCapacity(gpa, 1); | 7512 | try namespace.anon_decls.ensureUnusedCapacity(gpa, 1); |
| 7520 | 7513 | ||
| 7521 | // Create a Decl for the new function. | 7514 | // Create a Decl for the new function. |
| 7522 | const src_decl_index = namespace.getDeclIndex(); | 7515 | const src_decl_index = namespace.getDeclIndex(mod); |
| 7523 | const src_decl = mod.declPtr(src_decl_index); | 7516 | const src_decl = mod.declPtr(src_decl_index); |
| 7524 | const new_decl_index = try mod.allocateNewDecl(namespace, fn_owner_decl.src_node, src_decl.src_scope); | 7517 | const new_decl_index = try mod.allocateNewDecl(namespace_index, fn_owner_decl.src_node, src_decl.src_scope); |
| 7525 | const new_decl = mod.declPtr(new_decl_index); | 7518 | const new_decl = mod.declPtr(new_decl_index); |
| 7526 | // TODO better names for generic function instantiations | 7519 | // TODO better names for generic function instantiations |
| 7527 | const decl_name = try std.fmt.allocPrintZ(gpa, "{s}__anon_{d}", .{ | 7520 | const decl_name = try std.fmt.allocPrintZ(gpa, "{s}__anon_{d}", .{ |
| ... | @@ -7559,7 +7552,7 @@ fn instantiateGenericCall( | ... | @@ -7559,7 +7552,7 @@ fn instantiateGenericCall( |
| 7559 | uncasted_args, | 7552 | uncasted_args, |
| 7560 | module_fn, | 7553 | module_fn, |
| 7561 | new_module_func, | 7554 | new_module_func, |
| 7562 | namespace, | 7555 | namespace_index, |
| 7563 | func_ty_info, | 7556 | func_ty_info, |
| 7564 | call_src, | 7557 | call_src, |
| 7565 | bound_arg_src, | 7558 | bound_arg_src, |
| ... | @@ -7631,7 +7624,7 @@ fn instantiateGenericCall( | ... | @@ -7631,7 +7624,7 @@ fn instantiateGenericCall( |
| 7631 | const decl = sema.mod.declPtr(block.src_decl); | 7624 | const decl = sema.mod.declPtr(block.src_decl); |
| 7632 | _ = try sema.analyzeGenericCallArg( | 7625 | _ = try sema.analyzeGenericCallArg( |
| 7633 | block, | 7626 | block, |
| 7634 | Module.argSrc(call_src.node_offset.x, sema.gpa, decl, total_i, bound_arg_src), | 7627 | mod.argSrc(call_src.node_offset.x, decl, total_i, bound_arg_src), |
| 7635 | uncasted_args[total_i], | 7628 | uncasted_args[total_i], |
| 7636 | comptime_args[total_i], | 7629 | comptime_args[total_i], |
| 7637 | runtime_args, | 7630 | runtime_args, |
| ... | @@ -7692,7 +7685,7 @@ fn resolveGenericInstantiationType( | ... | @@ -7692,7 +7685,7 @@ fn resolveGenericInstantiationType( |
| 7692 | uncasted_args: []const Air.Inst.Ref, | 7685 | uncasted_args: []const Air.Inst.Ref, |
| 7693 | module_fn: *Module.Fn, | 7686 | module_fn: *Module.Fn, |
| 7694 | new_module_func: *Module.Fn, | 7687 | new_module_func: *Module.Fn, |
| 7695 | namespace: *Namespace, | 7688 | namespace: Namespace.Index, |
| 7696 | func_ty_info: Type.Payload.Function.Data, | 7689 | func_ty_info: Type.Payload.Function.Data, |
| 7697 | call_src: LazySrcLoc, | 7690 | call_src: LazySrcLoc, |
| 7698 | bound_arg_src: ?LazySrcLoc, | 7691 | bound_arg_src: ?LazySrcLoc, |
| ... | @@ -7779,7 +7772,7 @@ fn resolveGenericInstantiationType( | ... | @@ -7779,7 +7772,7 @@ fn resolveGenericInstantiationType( |
| 7779 | const arg_val = sema.resolveConstValue(block, .unneeded, arg, "") catch |err| switch (err) { | 7772 | const arg_val = sema.resolveConstValue(block, .unneeded, arg, "") catch |err| switch (err) { |
| 7780 | error.NeededSourceLocation => { | 7773 | error.NeededSourceLocation => { |
| 7781 | const decl = sema.mod.declPtr(block.src_decl); | 7774 | const decl = sema.mod.declPtr(block.src_decl); |
| 7782 | const arg_src = Module.argSrc(call_src.node_offset.x, sema.gpa, decl, arg_i, bound_arg_src); | 7775 | const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src); |
| 7783 | _ = try sema.resolveConstValue(block, arg_src, arg, "argument to parameter with comptime-only type must be comptime-known"); | 7776 | _ = try sema.resolveConstValue(block, arg_src, arg, "argument to parameter with comptime-only type must be comptime-known"); |
| 7784 | unreachable; | 7777 | unreachable; |
| 7785 | }, | 7778 | }, |
| ... | @@ -8987,7 +8980,7 @@ fn funcCommon( | ... | @@ -8987,7 +8980,7 @@ fn funcCommon( |
| 8987 | const decl = sema.mod.declPtr(block.src_decl); | 8980 | const decl = sema.mod.declPtr(block.src_decl); |
| 8988 | try sema.analyzeParameter( | 8981 | try sema.analyzeParameter( |
| 8989 | block, | 8982 | block, |
| 8990 | Module.paramSrc(src_node_offset, sema.gpa, decl, i), | 8983 | Module.paramSrc(src_node_offset, mod, decl, i), |
| 8991 | param, | 8984 | param, |
| 8992 | comptime_params, | 8985 | comptime_params, |
| 8993 | i, | 8986 | i, |
| ... | @@ -9050,7 +9043,7 @@ fn funcCommon( | ... | @@ -9050,7 +9043,7 @@ fn funcCommon( |
| 9050 | errdefer msg.destroy(sema.gpa); | 9043 | errdefer msg.destroy(sema.gpa); |
| 9051 | 9044 | ||
| 9052 | const src_decl = sema.mod.declPtr(block.src_decl); | 9045 | const src_decl = sema.mod.declPtr(block.src_decl); |
| 9053 | try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src.toSrcLoc(src_decl), return_type, .ret_ty); | 9046 | try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src.toSrcLoc(src_decl, mod), return_type, .ret_ty); |
| 9054 | 9047 | ||
| 9055 | try sema.addDeclaredHereNote(msg, return_type); | 9048 | try sema.addDeclaredHereNote(msg, return_type); |
| 9056 | break :msg msg; | 9049 | break :msg msg; |
| ... | @@ -9070,7 +9063,7 @@ fn funcCommon( | ... | @@ -9070,7 +9063,7 @@ fn funcCommon( |
| 9070 | "function with comptime-only return type '{}' requires all parameters to be comptime", | 9063 | "function with comptime-only return type '{}' requires all parameters to be comptime", |
| 9071 | .{return_type.fmt(sema.mod)}, | 9064 | .{return_type.fmt(sema.mod)}, |
| 9072 | ); | 9065 | ); |
| 9073 | try sema.explainWhyTypeIsComptime(msg, ret_ty_src.toSrcLoc(sema.owner_decl), return_type); | 9066 | try sema.explainWhyTypeIsComptime(msg, ret_ty_src.toSrcLoc(sema.owner_decl, mod), return_type); |
| 9074 | 9067 | ||
| 9075 | const tags = sema.code.instructions.items(.tag); | 9068 | const tags = sema.code.instructions.items(.tag); |
| 9076 | const data = sema.code.instructions.items(.data); | 9069 | const data = sema.code.instructions.items(.data); |
| ... | @@ -9278,7 +9271,7 @@ fn analyzeParameter( | ... | @@ -9278,7 +9271,7 @@ fn analyzeParameter( |
| 9278 | errdefer msg.destroy(sema.gpa); | 9271 | errdefer msg.destroy(sema.gpa); |
| 9279 | 9272 | ||
| 9280 | const src_decl = mod.declPtr(block.src_decl); | 9273 | const src_decl = mod.declPtr(block.src_decl); |
| 9281 | try sema.explainWhyTypeIsNotExtern(msg, param_src.toSrcLoc(src_decl), param.ty, .param_ty); | 9274 | try sema.explainWhyTypeIsNotExtern(msg, param_src.toSrcLoc(src_decl, mod), param.ty, .param_ty); |
| 9282 | 9275 | ||
| 9283 | try sema.addDeclaredHereNote(msg, param.ty); | 9276 | try sema.addDeclaredHereNote(msg, param.ty); |
| 9284 | break :msg msg; | 9277 | break :msg msg; |
| ... | @@ -9293,7 +9286,7 @@ fn analyzeParameter( | ... | @@ -9293,7 +9286,7 @@ fn analyzeParameter( |
| 9293 | errdefer msg.destroy(sema.gpa); | 9286 | errdefer msg.destroy(sema.gpa); |
| 9294 | 9287 | ||
| 9295 | const src_decl = mod.declPtr(block.src_decl); | 9288 | const src_decl = mod.declPtr(block.src_decl); |
| 9296 | try sema.explainWhyTypeIsComptime(msg, param_src.toSrcLoc(src_decl), param.ty); | 9289 | try sema.explainWhyTypeIsComptime(msg, param_src.toSrcLoc(src_decl, mod), param.ty); |
| 9297 | 9290 | ||
| 9298 | try sema.addDeclaredHereNote(msg, param.ty); | 9291 | try sema.addDeclaredHereNote(msg, param.ty); |
| 9299 | break :msg msg; | 9292 | break :msg msg; |
| ... | @@ -10233,15 +10226,15 @@ fn zirSwitchCapture( | ... | @@ -10233,15 +10226,15 @@ fn zirSwitchCapture( |
| 10233 | if (!field.ty.eql(first_field.ty, sema.mod)) { | 10226 | if (!field.ty.eql(first_field.ty, sema.mod)) { |
| 10234 | const msg = msg: { | 10227 | const msg = msg: { |
| 10235 | const raw_capture_src = Module.SwitchProngSrc{ .multi_capture = capture_info.prong_index }; | 10228 | const raw_capture_src = Module.SwitchProngSrc{ .multi_capture = capture_info.prong_index }; |
| 10236 | const capture_src = raw_capture_src.resolve(sema.gpa, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first); | 10229 | const capture_src = raw_capture_src.resolve(mod, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first); |
| 10237 | 10230 | ||
| 10238 | const msg = try sema.errMsg(block, capture_src, "capture group with incompatible types", .{}); | 10231 | const msg = try sema.errMsg(block, capture_src, "capture group with incompatible types", .{}); |
| 10239 | errdefer msg.destroy(sema.gpa); | 10232 | errdefer msg.destroy(sema.gpa); |
| 10240 | 10233 | ||
| 10241 | const raw_first_item_src = Module.SwitchProngSrc{ .multi = .{ .prong = capture_info.prong_index, .item = 0 } }; | 10234 | const raw_first_item_src = Module.SwitchProngSrc{ .multi = .{ .prong = capture_info.prong_index, .item = 0 } }; |
| 10242 | const first_item_src = raw_first_item_src.resolve(sema.gpa, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first); | 10235 | const first_item_src = raw_first_item_src.resolve(mod, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first); |
| 10243 | const raw_item_src = Module.SwitchProngSrc{ .multi = .{ .prong = capture_info.prong_index, .item = 1 + @intCast(u32, i) } }; | 10236 | const raw_item_src = Module.SwitchProngSrc{ .multi = .{ .prong = capture_info.prong_index, .item = 1 + @intCast(u32, i) } }; |
| 10244 | const item_src = raw_item_src.resolve(sema.gpa, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first); | 10237 | const item_src = raw_item_src.resolve(mod, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first); |
| 10245 | try sema.errNote(block, first_item_src, msg, "type '{}' here", .{first_field.ty.fmt(sema.mod)}); | 10238 | try sema.errNote(block, first_item_src, msg, "type '{}' here", .{first_field.ty.fmt(sema.mod)}); |
| 10246 | try sema.errNote(block, item_src, msg, "type '{}' here", .{field.ty.fmt(sema.mod)}); | 10239 | try sema.errNote(block, item_src, msg, "type '{}' here", .{field.ty.fmt(sema.mod)}); |
| 10247 | break :msg msg; | 10240 | break :msg msg; |
| ... | @@ -11265,7 +11258,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -11265,7 +11258,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 11265 | error.NeededSourceLocation => { | 11258 | error.NeededSourceLocation => { |
| 11266 | const case_src = Module.SwitchProngSrc{ .range = .{ .prong = multi_i, .item = range_i } }; | 11259 | const case_src = Module.SwitchProngSrc{ .range = .{ .prong = multi_i, .item = range_i } }; |
| 11267 | const decl = mod.declPtr(case_block.src_decl); | 11260 | const decl = mod.declPtr(case_block.src_decl); |
| 11268 | try sema.emitBackwardBranch(block, case_src.resolve(sema.gpa, decl, src_node_offset, .none)); | 11261 | try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none)); |
| 11269 | unreachable; | 11262 | unreachable; |
| 11270 | }, | 11263 | }, |
| 11271 | else => return err, | 11264 | else => return err, |
| ... | @@ -11301,7 +11294,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -11301,7 +11294,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 11301 | error.NeededSourceLocation => { | 11294 | error.NeededSourceLocation => { |
| 11302 | const case_src = Module.SwitchProngSrc{ .multi = .{ .prong = multi_i, .item = @intCast(u32, item_i) } }; | 11295 | const case_src = Module.SwitchProngSrc{ .multi = .{ .prong = multi_i, .item = @intCast(u32, item_i) } }; |
| 11303 | const decl = mod.declPtr(case_block.src_decl); | 11296 | const decl = mod.declPtr(case_block.src_decl); |
| 11304 | try sema.emitBackwardBranch(block, case_src.resolve(sema.gpa, decl, src_node_offset, .none)); | 11297 | try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none)); |
| 11305 | unreachable; | 11298 | unreachable; |
| 11306 | }, | 11299 | }, |
| 11307 | else => return err, | 11300 | else => return err, |
| ... | @@ -11724,6 +11717,7 @@ fn resolveSwitchItemVal( | ... | @@ -11724,6 +11717,7 @@ fn resolveSwitchItemVal( |
| 11724 | switch_prong_src: Module.SwitchProngSrc, | 11717 | switch_prong_src: Module.SwitchProngSrc, |
| 11725 | range_expand: Module.SwitchProngSrc.RangeExpand, | 11718 | range_expand: Module.SwitchProngSrc.RangeExpand, |
| 11726 | ) CompileError!TypedValue { | 11719 | ) CompileError!TypedValue { |
| 11720 | const mod = sema.mod; | ||
| 11727 | const item = try sema.resolveInst(item_ref); | 11721 | const item = try sema.resolveInst(item_ref); |
| 11728 | const item_ty = sema.typeOf(item); | 11722 | const item_ty = sema.typeOf(item); |
| 11729 | // Constructing a LazySrcLoc is costly because we only have the switch AST node. | 11723 | // Constructing a LazySrcLoc is costly because we only have the switch AST node. |
| ... | @@ -11734,7 +11728,7 @@ fn resolveSwitchItemVal( | ... | @@ -11734,7 +11728,7 @@ fn resolveSwitchItemVal( |
| 11734 | return TypedValue{ .ty = item_ty, .val = val }; | 11728 | return TypedValue{ .ty = item_ty, .val = val }; |
| 11735 | } else |err| switch (err) { | 11729 | } else |err| switch (err) { |
| 11736 | error.NeededSourceLocation => { | 11730 | error.NeededSourceLocation => { |
| 11737 | const src = switch_prong_src.resolve(sema.gpa, sema.mod.declPtr(block.src_decl), switch_node_offset, range_expand); | 11731 | const src = switch_prong_src.resolve(mod, sema.mod.declPtr(block.src_decl), switch_node_offset, range_expand); |
| 11738 | _ = try sema.resolveConstValue(block, src, item, "switch prong values must be comptime-known"); | 11732 | _ = try sema.resolveConstValue(block, src, item, "switch prong values must be comptime-known"); |
| 11739 | unreachable; | 11733 | unreachable; |
| 11740 | }, | 11734 | }, |
| ... | @@ -11752,10 +11746,11 @@ fn validateSwitchRange( | ... | @@ -11752,10 +11746,11 @@ fn validateSwitchRange( |
| 11752 | src_node_offset: i32, | 11746 | src_node_offset: i32, |
| 11753 | switch_prong_src: Module.SwitchProngSrc, | 11747 | switch_prong_src: Module.SwitchProngSrc, |
| 11754 | ) CompileError!void { | 11748 | ) CompileError!void { |
| 11749 | const mod = sema.mod; | ||
| 11755 | const first_val = (try sema.resolveSwitchItemVal(block, first_ref, src_node_offset, switch_prong_src, .first)).val; | 11750 | const first_val = (try sema.resolveSwitchItemVal(block, first_ref, src_node_offset, switch_prong_src, .first)).val; |
| 11756 | const last_val = (try sema.resolveSwitchItemVal(block, last_ref, src_node_offset, switch_prong_src, .last)).val; | 11751 | const last_val = (try sema.resolveSwitchItemVal(block, last_ref, src_node_offset, switch_prong_src, .last)).val; |
| 11757 | if (first_val.compareScalar(.gt, last_val, operand_ty, sema.mod)) { | 11752 | if (first_val.compareScalar(.gt, last_val, operand_ty, mod)) { |
| 11758 | const src = switch_prong_src.resolve(sema.gpa, sema.mod.declPtr(block.src_decl), src_node_offset, .first); | 11753 | const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), src_node_offset, .first); |
| 11759 | return sema.fail(block, src, "range start value is greater than the end value", .{}); | 11754 | return sema.fail(block, src, "range start value is greater than the end value", .{}); |
| 11760 | } | 11755 | } |
| 11761 | const maybe_prev_src = try range_set.add(first_val, last_val, operand_ty, switch_prong_src); | 11756 | const maybe_prev_src = try range_set.add(first_val, last_val, operand_ty, switch_prong_src); |
| ... | @@ -11821,10 +11816,10 @@ fn validateSwitchDupe( | ... | @@ -11821,10 +11816,10 @@ fn validateSwitchDupe( |
| 11821 | src_node_offset: i32, | 11816 | src_node_offset: i32, |
| 11822 | ) CompileError!void { | 11817 | ) CompileError!void { |
| 11823 | const prev_prong_src = maybe_prev_src orelse return; | 11818 | const prev_prong_src = maybe_prev_src orelse return; |
| 11824 | const gpa = sema.gpa; | 11819 | const mod = sema.mod; |
| 11825 | const block_src_decl = sema.mod.declPtr(block.src_decl); | 11820 | const block_src_decl = sema.mod.declPtr(block.src_decl); |
| 11826 | const src = switch_prong_src.resolve(gpa, block_src_decl, src_node_offset, .none); | 11821 | const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none); |
| 11827 | const prev_src = prev_prong_src.resolve(gpa, block_src_decl, src_node_offset, .none); | 11822 | const prev_src = prev_prong_src.resolve(mod, block_src_decl, src_node_offset, .none); |
| 11828 | const msg = msg: { | 11823 | const msg = msg: { |
| 11829 | const msg = try sema.errMsg( | 11824 | const msg = try sema.errMsg( |
| 11830 | block, | 11825 | block, |
| ... | @@ -11863,7 +11858,7 @@ fn validateSwitchItemBool( | ... | @@ -11863,7 +11858,7 @@ fn validateSwitchItemBool( |
| 11863 | } | 11858 | } |
| 11864 | if (true_count.* + false_count.* > 2) { | 11859 | if (true_count.* + false_count.* > 2) { |
| 11865 | const block_src_decl = sema.mod.declPtr(block.src_decl); | 11860 | const block_src_decl = sema.mod.declPtr(block.src_decl); |
| 11866 | const src = switch_prong_src.resolve(sema.gpa, block_src_decl, src_node_offset, .none); | 11861 | const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none); |
| 11867 | return sema.fail(block, src, "duplicate switch value", .{}); | 11862 | return sema.fail(block, src, "duplicate switch value", .{}); |
| 11868 | } | 11863 | } |
| 11869 | } | 11864 | } |
| ... | @@ -12068,6 +12063,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12068,6 +12063,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12068 | } | 12063 | } |
| 12069 | 12064 | ||
| 12070 | fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 12065 | fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 12066 | const mod = sema.mod; | ||
| 12071 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 12067 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 12072 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 12068 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 12073 | const src = inst_data.src(); | 12069 | const src = inst_data.src(); |
| ... | @@ -12078,10 +12074,11 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -12078,10 +12074,11 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 12078 | 12074 | ||
| 12079 | try sema.checkNamespaceType(block, lhs_src, container_type); | 12075 | try sema.checkNamespaceType(block, lhs_src, container_type); |
| 12080 | 12076 | ||
| 12081 | const namespace = container_type.getNamespace() orelse return Air.Inst.Ref.bool_false; | 12077 | const namespace = container_type.getNamespaceIndex(mod).unwrap() orelse |
| 12078 | return Air.Inst.Ref.bool_false; | ||
| 12082 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl_index| { | 12079 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl_index| { |
| 12083 | const decl = sema.mod.declPtr(decl_index); | 12080 | const decl = mod.declPtr(decl_index); |
| 12084 | if (decl.is_pub or decl.getFileScope() == block.getFileScope()) { | 12081 | if (decl.is_pub or decl.getFileScope(mod) == block.getFileScope(mod)) { |
| 12085 | return Air.Inst.Ref.bool_true; | 12082 | return Air.Inst.Ref.bool_true; |
| 12086 | } | 12083 | } |
| 12087 | } | 12084 | } |
| ... | @@ -12097,12 +12094,12 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -12097,12 +12094,12 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 12097 | const operand_src = inst_data.src(); | 12094 | const operand_src = inst_data.src(); |
| 12098 | const operand = inst_data.get(sema.code); | 12095 | const operand = inst_data.get(sema.code); |
| 12099 | 12096 | ||
| 12100 | const result = mod.importFile(block.getFileScope(), operand) catch |err| switch (err) { | 12097 | const result = mod.importFile(block.getFileScope(mod), operand) catch |err| switch (err) { |
| 12101 | error.ImportOutsidePkgPath => { | 12098 | error.ImportOutsidePkgPath => { |
| 12102 | return sema.fail(block, operand_src, "import of file outside package path: '{s}'", .{operand}); | 12099 | return sema.fail(block, operand_src, "import of file outside package path: '{s}'", .{operand}); |
| 12103 | }, | 12100 | }, |
| 12104 | error.PackageNotFound => { | 12101 | error.PackageNotFound => { |
| 12105 | const name = try block.getFileScope().pkg.getName(sema.gpa, mod.*); | 12102 | const name = try block.getFileScope(mod).pkg.getName(sema.gpa, mod.*); |
| 12106 | defer sema.gpa.free(name); | 12103 | defer sema.gpa.free(name); |
| 12107 | return sema.fail(block, operand_src, "no package named '{s}' available within package '{s}'", .{ operand, name }); | 12104 | return sema.fail(block, operand_src, "no package named '{s}' available within package '{s}'", .{ operand, name }); |
| 12108 | }, | 12105 | }, |
| ... | @@ -12128,7 +12125,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -12128,7 +12125,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 12128 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 12125 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 12129 | const name = try sema.resolveConstString(block, operand_src, inst_data.operand, "file path name must be comptime-known"); | 12126 | const name = try sema.resolveConstString(block, operand_src, inst_data.operand, "file path name must be comptime-known"); |
| 12130 | 12127 | ||
| 12131 | const embed_file = mod.embedFile(block.getFileScope(), name) catch |err| switch (err) { | 12128 | const embed_file = mod.embedFile(block.getFileScope(mod), name) catch |err| switch (err) { |
| 12132 | error.ImportOutsidePkgPath => { | 12129 | error.ImportOutsidePkgPath => { |
| 12133 | return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name}); | 12130 | return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name}); |
| 12134 | }, | 12131 | }, |
| ... | @@ -15666,7 +15663,8 @@ fn zirThis( | ... | @@ -15666,7 +15663,8 @@ fn zirThis( |
| 15666 | block: *Block, | 15663 | block: *Block, |
| 15667 | extended: Zir.Inst.Extended.InstData, | 15664 | extended: Zir.Inst.Extended.InstData, |
| 15668 | ) CompileError!Air.Inst.Ref { | 15665 | ) CompileError!Air.Inst.Ref { |
| 15669 | const this_decl_index = block.namespace.getDeclIndex(); | 15666 | const mod = sema.mod; |
| 15667 | const this_decl_index = mod.namespaceDeclIndex(block.namespace); | ||
| 15670 | const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand)); | 15668 | const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand)); |
| 15671 | return sema.analyzeDeclVal(block, src, this_decl_index); | 15669 | return sema.analyzeDeclVal(block, src, this_decl_index); |
| 15672 | } | 15670 | } |
| ... | @@ -15698,9 +15696,10 @@ fn zirClosureGet( | ... | @@ -15698,9 +15696,10 @@ fn zirClosureGet( |
| 15698 | block: *Block, | 15696 | block: *Block, |
| 15699 | inst: Zir.Inst.Index, | 15697 | inst: Zir.Inst.Index, |
| 15700 | ) CompileError!Air.Inst.Ref { | 15698 | ) CompileError!Air.Inst.Ref { |
| 15699 | const mod = sema.mod; | ||
| 15701 | // TODO CLOSURE: Test this with inline functions | 15700 | // TODO CLOSURE: Test this with inline functions |
| 15702 | const inst_data = sema.code.instructions.items(.data)[inst].inst_node; | 15701 | const inst_data = sema.code.instructions.items(.data)[inst].inst_node; |
| 15703 | var scope: *CaptureScope = sema.mod.declPtr(block.src_decl).src_scope.?; | 15702 | var scope: *CaptureScope = mod.declPtr(block.src_decl).src_scope.?; |
| 15704 | // Note: The target closure must be in this scope list. | 15703 | // Note: The target closure must be in this scope list. |
| 15705 | // If it's not here, the zir is invalid, or the list is broken. | 15704 | // If it's not here, the zir is invalid, or the list is broken. |
| 15706 | const tv = while (true) { | 15705 | const tv = while (true) { |
| ... | @@ -15725,8 +15724,8 @@ fn zirClosureGet( | ... | @@ -15725,8 +15724,8 @@ fn zirClosureGet( |
| 15725 | if (tv.val.ip_index == .unreachable_value and !block.is_typeof and sema.func == null) { | 15724 | if (tv.val.ip_index == .unreachable_value and !block.is_typeof and sema.func == null) { |
| 15726 | const msg = msg: { | 15725 | const msg = msg: { |
| 15727 | const name = name: { | 15726 | const name = name: { |
| 15728 | const file = sema.owner_decl.getFileScope(); | 15727 | const file = sema.owner_decl.getFileScope(mod); |
| 15729 | const tree = file.getTree(sema.mod.gpa) catch |err| { | 15728 | const tree = file.getTree(mod.gpa) catch |err| { |
| 15730 | // In this case we emit a warning + a less precise source location. | 15729 | // In this case we emit a warning + a less precise source location. |
| 15731 | log.warn("unable to load {s}: {s}", .{ | 15730 | log.warn("unable to load {s}: {s}", .{ |
| 15732 | file.sub_file_path, @errorName(err), | 15731 | file.sub_file_path, @errorName(err), |
| ... | @@ -15753,8 +15752,8 @@ fn zirClosureGet( | ... | @@ -15753,8 +15752,8 @@ fn zirClosureGet( |
| 15753 | if (tv.val.ip_index == .unreachable_value and !block.is_typeof and !block.is_comptime and sema.func != null) { | 15752 | if (tv.val.ip_index == .unreachable_value and !block.is_typeof and !block.is_comptime and sema.func != null) { |
| 15754 | const msg = msg: { | 15753 | const msg = msg: { |
| 15755 | const name = name: { | 15754 | const name = name: { |
| 15756 | const file = sema.owner_decl.getFileScope(); | 15755 | const file = sema.owner_decl.getFileScope(mod); |
| 15757 | const tree = file.getTree(sema.mod.gpa) catch |err| { | 15756 | const tree = file.getTree(mod.gpa) catch |err| { |
| 15758 | // In this case we emit a warning + a less precise source location. | 15757 | // In this case we emit a warning + a less precise source location. |
| 15759 | log.warn("unable to load {s}: {s}", .{ | 15758 | log.warn("unable to load {s}: {s}", .{ |
| 15760 | file.sub_file_path, @errorName(err), | 15759 | file.sub_file_path, @errorName(err), |
| ... | @@ -15825,7 +15824,7 @@ fn zirBuiltinSrc( | ... | @@ -15825,7 +15824,7 @@ fn zirBuiltinSrc( |
| 15825 | const extra = sema.code.extraData(Zir.Inst.Src, extended.operand).data; | 15824 | const extra = sema.code.extraData(Zir.Inst.Src, extended.operand).data; |
| 15826 | const src = LazySrcLoc.nodeOffset(extra.node); | 15825 | const src = LazySrcLoc.nodeOffset(extra.node); |
| 15827 | const func = sema.func orelse return sema.fail(block, src, "@src outside function", .{}); | 15826 | const func = sema.func orelse return sema.fail(block, src, "@src outside function", .{}); |
| 15828 | const fn_owner_decl = sema.mod.declPtr(func.owner_decl); | 15827 | const fn_owner_decl = mod.declPtr(func.owner_decl); |
| 15829 | 15828 | ||
| 15830 | const func_name_val = blk: { | 15829 | const func_name_val = blk: { |
| 15831 | var anon_decl = try block.startAnonDecl(); | 15830 | var anon_decl = try block.startAnonDecl(); |
| ... | @@ -15844,7 +15843,7 @@ fn zirBuiltinSrc( | ... | @@ -15844,7 +15843,7 @@ fn zirBuiltinSrc( |
| 15844 | var anon_decl = try block.startAnonDecl(); | 15843 | var anon_decl = try block.startAnonDecl(); |
| 15845 | defer anon_decl.deinit(); | 15844 | defer anon_decl.deinit(); |
| 15846 | // The compiler must not call realpath anywhere. | 15845 | // The compiler must not call realpath anywhere. |
| 15847 | const name = try fn_owner_decl.getFileScope().fullPathZ(anon_decl.arena()); | 15846 | const name = try fn_owner_decl.getFileScope(mod).fullPathZ(anon_decl.arena()); |
| 15848 | const new_decl = try anon_decl.finish( | 15847 | const new_decl = try anon_decl.finish( |
| 15849 | try Type.array(anon_decl.arena(), name.len, try mod.intValue(Type.u8, 0), Type.u8, mod), | 15848 | try Type.array(anon_decl.arena(), name.len, try mod.intValue(Type.u8, 0), Type.u8, mod), |
| 15850 | try Value.Tag.bytes.create(anon_decl.arena(), name[0 .. name.len + 1]), | 15849 | try Value.Tag.bytes.create(anon_decl.arena(), name[0 .. name.len + 1]), |
| ... | @@ -15980,22 +15979,22 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15980,22 +15979,22 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15980 | const fn_info_decl_index = (try sema.namespaceLookup( | 15979 | const fn_info_decl_index = (try sema.namespaceLookup( |
| 15981 | block, | 15980 | block, |
| 15982 | src, | 15981 | src, |
| 15983 | type_info_ty.getNamespace().?, | 15982 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 15984 | "Fn", | 15983 | "Fn", |
| 15985 | )).?; | 15984 | )).?; |
| 15986 | try sema.mod.declareDeclDependency(sema.owner_decl_index, fn_info_decl_index); | 15985 | try mod.declareDeclDependency(sema.owner_decl_index, fn_info_decl_index); |
| 15987 | try sema.ensureDeclAnalyzed(fn_info_decl_index); | 15986 | try sema.ensureDeclAnalyzed(fn_info_decl_index); |
| 15988 | const fn_info_decl = sema.mod.declPtr(fn_info_decl_index); | 15987 | const fn_info_decl = mod.declPtr(fn_info_decl_index); |
| 15989 | const fn_ty = fn_info_decl.val.toType(); | 15988 | const fn_ty = fn_info_decl.val.toType(); |
| 15990 | const param_info_decl_index = (try sema.namespaceLookup( | 15989 | const param_info_decl_index = (try sema.namespaceLookup( |
| 15991 | block, | 15990 | block, |
| 15992 | src, | 15991 | src, |
| 15993 | fn_ty.getNamespace().?, | 15992 | fn_ty.getNamespaceIndex(mod).unwrap().?, |
| 15994 | "Param", | 15993 | "Param", |
| 15995 | )).?; | 15994 | )).?; |
| 15996 | try sema.mod.declareDeclDependency(sema.owner_decl_index, param_info_decl_index); | 15995 | try mod.declareDeclDependency(sema.owner_decl_index, param_info_decl_index); |
| 15997 | try sema.ensureDeclAnalyzed(param_info_decl_index); | 15996 | try sema.ensureDeclAnalyzed(param_info_decl_index); |
| 15998 | const param_info_decl = sema.mod.declPtr(param_info_decl_index); | 15997 | const param_info_decl = mod.declPtr(param_info_decl_index); |
| 15999 | const param_ty = param_info_decl.val.toType(); | 15998 | const param_ty = param_info_decl.val.toType(); |
| 16000 | const new_decl = try params_anon_decl.finish( | 15999 | const new_decl = try params_anon_decl.finish( |
| 16001 | try Type.Tag.array.create(params_anon_decl.arena(), .{ | 16000 | try Type.Tag.array.create(params_anon_decl.arena(), .{ |
| ... | @@ -16169,12 +16168,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16169,12 +16168,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16169 | const set_field_ty_decl_index = (try sema.namespaceLookup( | 16168 | const set_field_ty_decl_index = (try sema.namespaceLookup( |
| 16170 | block, | 16169 | block, |
| 16171 | src, | 16170 | src, |
| 16172 | type_info_ty.getNamespace().?, | 16171 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16173 | "Error", | 16172 | "Error", |
| 16174 | )).?; | 16173 | )).?; |
| 16175 | try sema.mod.declareDeclDependency(sema.owner_decl_index, set_field_ty_decl_index); | 16174 | try mod.declareDeclDependency(sema.owner_decl_index, set_field_ty_decl_index); |
| 16176 | try sema.ensureDeclAnalyzed(set_field_ty_decl_index); | 16175 | try sema.ensureDeclAnalyzed(set_field_ty_decl_index); |
| 16177 | const set_field_ty_decl = sema.mod.declPtr(set_field_ty_decl_index); | 16176 | const set_field_ty_decl = mod.declPtr(set_field_ty_decl_index); |
| 16178 | break :t try set_field_ty_decl.val.toType().copy(fields_anon_decl.arena()); | 16177 | break :t try set_field_ty_decl.val.toType().copy(fields_anon_decl.arena()); |
| 16179 | }; | 16178 | }; |
| 16180 | 16179 | ||
| ... | @@ -16277,12 +16276,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16277,12 +16276,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16277 | const enum_field_ty_decl_index = (try sema.namespaceLookup( | 16276 | const enum_field_ty_decl_index = (try sema.namespaceLookup( |
| 16278 | block, | 16277 | block, |
| 16279 | src, | 16278 | src, |
| 16280 | type_info_ty.getNamespace().?, | 16279 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16281 | "EnumField", | 16280 | "EnumField", |
| 16282 | )).?; | 16281 | )).?; |
| 16283 | try sema.mod.declareDeclDependency(sema.owner_decl_index, enum_field_ty_decl_index); | 16282 | try mod.declareDeclDependency(sema.owner_decl_index, enum_field_ty_decl_index); |
| 16284 | try sema.ensureDeclAnalyzed(enum_field_ty_decl_index); | 16283 | try sema.ensureDeclAnalyzed(enum_field_ty_decl_index); |
| 16285 | const enum_field_ty_decl = sema.mod.declPtr(enum_field_ty_decl_index); | 16284 | const enum_field_ty_decl = mod.declPtr(enum_field_ty_decl_index); |
| 16286 | break :t try enum_field_ty_decl.val.toType().copy(fields_anon_decl.arena()); | 16285 | break :t try enum_field_ty_decl.val.toType().copy(fields_anon_decl.arena()); |
| 16287 | }; | 16286 | }; |
| 16288 | 16287 | ||
| ... | @@ -16336,7 +16335,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16336,7 +16335,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16336 | break :v try Value.Tag.decl_ref.create(sema.arena, new_decl); | 16335 | break :v try Value.Tag.decl_ref.create(sema.arena, new_decl); |
| 16337 | }; | 16336 | }; |
| 16338 | 16337 | ||
| 16339 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace()); | 16338 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace(mod)); |
| 16340 | 16339 | ||
| 16341 | const field_values = try sema.arena.create([4]Value); | 16340 | const field_values = try sema.arena.create([4]Value); |
| 16342 | field_values.* = .{ | 16341 | field_values.* = .{ |
| ... | @@ -16368,12 +16367,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16368,12 +16367,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16368 | const union_field_ty_decl_index = (try sema.namespaceLookup( | 16367 | const union_field_ty_decl_index = (try sema.namespaceLookup( |
| 16369 | block, | 16368 | block, |
| 16370 | src, | 16369 | src, |
| 16371 | type_info_ty.getNamespace().?, | 16370 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16372 | "UnionField", | 16371 | "UnionField", |
| 16373 | )).?; | 16372 | )).?; |
| 16374 | try sema.mod.declareDeclDependency(sema.owner_decl_index, union_field_ty_decl_index); | 16373 | try mod.declareDeclDependency(sema.owner_decl_index, union_field_ty_decl_index); |
| 16375 | try sema.ensureDeclAnalyzed(union_field_ty_decl_index); | 16374 | try sema.ensureDeclAnalyzed(union_field_ty_decl_index); |
| 16376 | const union_field_ty_decl = sema.mod.declPtr(union_field_ty_decl_index); | 16375 | const union_field_ty_decl = mod.declPtr(union_field_ty_decl_index); |
| 16377 | break :t try union_field_ty_decl.val.toType().copy(fields_anon_decl.arena()); | 16376 | break :t try union_field_ty_decl.val.toType().copy(fields_anon_decl.arena()); |
| 16378 | }; | 16377 | }; |
| 16379 | 16378 | ||
| ... | @@ -16434,7 +16433,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16434,7 +16433,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16434 | }); | 16433 | }); |
| 16435 | }; | 16434 | }; |
| 16436 | 16435 | ||
| 16437 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, union_ty.getNamespace()); | 16436 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, union_ty.getNamespace(mod)); |
| 16438 | 16437 | ||
| 16439 | const enum_tag_ty_val = if (union_ty.unionTagType()) |tag_ty| v: { | 16438 | const enum_tag_ty_val = if (union_ty.unionTagType()) |tag_ty| v: { |
| 16440 | const ty_val = try Value.Tag.ty.create(sema.arena, tag_ty); | 16439 | const ty_val = try Value.Tag.ty.create(sema.arena, tag_ty); |
| ... | @@ -16475,12 +16474,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16475,12 +16474,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16475 | const struct_field_ty_decl_index = (try sema.namespaceLookup( | 16474 | const struct_field_ty_decl_index = (try sema.namespaceLookup( |
| 16476 | block, | 16475 | block, |
| 16477 | src, | 16476 | src, |
| 16478 | type_info_ty.getNamespace().?, | 16477 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16479 | "StructField", | 16478 | "StructField", |
| 16480 | )).?; | 16479 | )).?; |
| 16481 | try sema.mod.declareDeclDependency(sema.owner_decl_index, struct_field_ty_decl_index); | 16480 | try mod.declareDeclDependency(sema.owner_decl_index, struct_field_ty_decl_index); |
| 16482 | try sema.ensureDeclAnalyzed(struct_field_ty_decl_index); | 16481 | try sema.ensureDeclAnalyzed(struct_field_ty_decl_index); |
| 16483 | const struct_field_ty_decl = sema.mod.declPtr(struct_field_ty_decl_index); | 16482 | const struct_field_ty_decl = mod.declPtr(struct_field_ty_decl_index); |
| 16484 | break :t try struct_field_ty_decl.val.toType().copy(fields_anon_decl.arena()); | 16483 | break :t try struct_field_ty_decl.val.toType().copy(fields_anon_decl.arena()); |
| 16485 | }; | 16484 | }; |
| 16486 | const struct_ty = try sema.resolveTypeFields(ty); | 16485 | const struct_ty = try sema.resolveTypeFields(ty); |
| ... | @@ -16597,7 +16596,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16597,7 +16596,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16597 | }); | 16596 | }); |
| 16598 | }; | 16597 | }; |
| 16599 | 16598 | ||
| 16600 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, struct_ty.getNamespace()); | 16599 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, struct_ty.getNamespace(mod)); |
| 16601 | 16600 | ||
| 16602 | const backing_integer_val = blk: { | 16601 | const backing_integer_val = blk: { |
| 16603 | if (layout == .Packed) { | 16602 | if (layout == .Packed) { |
| ... | @@ -16640,7 +16639,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16640,7 +16639,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16640 | // TODO: look into memoizing this result. | 16639 | // TODO: look into memoizing this result. |
| 16641 | 16640 | ||
| 16642 | const opaque_ty = try sema.resolveTypeFields(ty); | 16641 | const opaque_ty = try sema.resolveTypeFields(ty); |
| 16643 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, opaque_ty.getNamespace()); | 16642 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, opaque_ty.getNamespace(mod)); |
| 16644 | 16643 | ||
| 16645 | const field_values = try sema.arena.create([1]Value); | 16644 | const field_values = try sema.arena.create([1]Value); |
| 16646 | field_values.* = .{ | 16645 | field_values.* = .{ |
| ... | @@ -16676,7 +16675,7 @@ fn typeInfoDecls( | ... | @@ -16676,7 +16675,7 @@ fn typeInfoDecls( |
| 16676 | const declaration_ty_decl_index = (try sema.namespaceLookup( | 16675 | const declaration_ty_decl_index = (try sema.namespaceLookup( |
| 16677 | block, | 16676 | block, |
| 16678 | src, | 16677 | src, |
| 16679 | type_info_ty.getNamespace().?, | 16678 | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 16680 | "Declaration", | 16679 | "Declaration", |
| 16681 | )).?; | 16680 | )).?; |
| 16682 | try mod.declareDeclDependency(sema.owner_decl_index, declaration_ty_decl_index); | 16681 | try mod.declareDeclDependency(sema.owner_decl_index, declaration_ty_decl_index); |
| ... | @@ -16730,7 +16729,7 @@ fn typeInfoNamespaceDecls( | ... | @@ -16730,7 +16729,7 @@ fn typeInfoNamespaceDecls( |
| 16730 | if (decl.kind == .@"usingnamespace") { | 16729 | if (decl.kind == .@"usingnamespace") { |
| 16731 | if (decl.analysis == .in_progress) continue; | 16730 | if (decl.analysis == .in_progress) continue; |
| 16732 | try mod.ensureDeclAnalyzed(decl_index); | 16731 | try mod.ensureDeclAnalyzed(decl_index); |
| 16733 | const new_ns = decl.val.toType().getNamespace().?; | 16732 | const new_ns = decl.val.toType().getNamespace(mod).?; |
| 16734 | try sema.typeInfoNamespaceDecls(block, decls_anon_decl, new_ns, decl_vals, seen_namespaces); | 16733 | try sema.typeInfoNamespaceDecls(block, decls_anon_decl, new_ns, decl_vals, seen_namespaces); |
| 16735 | continue; | 16734 | continue; |
| 16736 | } | 16735 | } |
| ... | @@ -17750,7 +17749,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -17750,7 +17749,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 17750 | errdefer msg.destroy(sema.gpa); | 17749 | errdefer msg.destroy(sema.gpa); |
| 17751 | 17750 | ||
| 17752 | const src_decl = sema.mod.declPtr(block.src_decl); | 17751 | const src_decl = sema.mod.declPtr(block.src_decl); |
| 17753 | try sema.explainWhyTypeIsNotExtern(msg, elem_ty_src.toSrcLoc(src_decl), elem_ty, .other); | 17752 | try sema.explainWhyTypeIsNotExtern(msg, elem_ty_src.toSrcLoc(src_decl, mod), elem_ty, .other); |
| 17754 | 17753 | ||
| 17755 | try sema.addDeclaredHereNote(msg, elem_ty); | 17754 | try sema.addDeclaredHereNote(msg, elem_ty); |
| 17756 | break :msg msg; | 17755 | break :msg msg; |
| ... | @@ -18006,6 +18005,7 @@ fn finishStructInit( | ... | @@ -18006,6 +18005,7 @@ fn finishStructInit( |
| 18006 | struct_ty: Type, | 18005 | struct_ty: Type, |
| 18007 | is_ref: bool, | 18006 | is_ref: bool, |
| 18008 | ) CompileError!Air.Inst.Ref { | 18007 | ) CompileError!Air.Inst.Ref { |
| 18008 | const mod = sema.mod; | ||
| 18009 | const gpa = sema.gpa; | 18009 | const gpa = sema.gpa; |
| 18010 | 18010 | ||
| 18011 | var root_msg: ?*Module.ErrorMsg = null; | 18011 | var root_msg: ?*Module.ErrorMsg = null; |
| ... | @@ -18118,8 +18118,8 @@ fn finishStructInit( | ... | @@ -18118,8 +18118,8 @@ fn finishStructInit( |
| 18118 | 18118 | ||
| 18119 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { | 18119 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { |
| 18120 | error.NeededSourceLocation => { | 18120 | error.NeededSourceLocation => { |
| 18121 | const decl = sema.mod.declPtr(block.src_decl); | 18121 | const decl = mod.declPtr(block.src_decl); |
| 18122 | const field_src = Module.initSrc(dest_src.node_offset.x, sema.gpa, decl, runtime_index); | 18122 | const field_src = mod.initSrc(dest_src.node_offset.x, decl, runtime_index); |
| 18123 | try sema.requireRuntimeBlock(block, dest_src, field_src); | 18123 | try sema.requireRuntimeBlock(block, dest_src, field_src); |
| 18124 | unreachable; | 18124 | unreachable; |
| 18125 | }, | 18125 | }, |
| ... | @@ -18158,11 +18158,11 @@ fn zirStructInitAnon( | ... | @@ -18158,11 +18158,11 @@ fn zirStructInitAnon( |
| 18158 | if (gop.found_existing) { | 18158 | if (gop.found_existing) { |
| 18159 | const msg = msg: { | 18159 | const msg = msg: { |
| 18160 | const decl = sema.mod.declPtr(block.src_decl); | 18160 | const decl = sema.mod.declPtr(block.src_decl); |
| 18161 | const field_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, i); | 18161 | const field_src = mod.initSrc(src.node_offset.x, decl, i); |
| 18162 | const msg = try sema.errMsg(block, field_src, "duplicate field", .{}); | 18162 | const msg = try sema.errMsg(block, field_src, "duplicate field", .{}); |
| 18163 | errdefer msg.destroy(sema.gpa); | 18163 | errdefer msg.destroy(sema.gpa); |
| 18164 | 18164 | ||
| 18165 | const prev_source = Module.initSrc(src.node_offset.x, sema.gpa, decl, gop.value_ptr.*); | 18165 | const prev_source = mod.initSrc(src.node_offset.x, decl, gop.value_ptr.*); |
| 18166 | try sema.errNote(block, prev_source, msg, "other field here", .{}); | 18166 | try sema.errNote(block, prev_source, msg, "other field here", .{}); |
| 18167 | break :msg msg; | 18167 | break :msg msg; |
| 18168 | }; | 18168 | }; |
| ... | @@ -18175,7 +18175,7 @@ fn zirStructInitAnon( | ... | @@ -18175,7 +18175,7 @@ fn zirStructInitAnon( |
| 18175 | if (types[i].zigTypeTag(mod) == .Opaque) { | 18175 | if (types[i].zigTypeTag(mod) == .Opaque) { |
| 18176 | const msg = msg: { | 18176 | const msg = msg: { |
| 18177 | const decl = sema.mod.declPtr(block.src_decl); | 18177 | const decl = sema.mod.declPtr(block.src_decl); |
| 18178 | const field_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, i); | 18178 | const field_src = mod.initSrc(src.node_offset.x, decl, i); |
| 18179 | const msg = try sema.errMsg(block, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); | 18179 | const msg = try sema.errMsg(block, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); |
| 18180 | errdefer msg.destroy(sema.gpa); | 18180 | errdefer msg.destroy(sema.gpa); |
| 18181 | 18181 | ||
| ... | @@ -18208,7 +18208,7 @@ fn zirStructInitAnon( | ... | @@ -18208,7 +18208,7 @@ fn zirStructInitAnon( |
| 18208 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { | 18208 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { |
| 18209 | error.NeededSourceLocation => { | 18209 | error.NeededSourceLocation => { |
| 18210 | const decl = sema.mod.declPtr(block.src_decl); | 18210 | const decl = sema.mod.declPtr(block.src_decl); |
| 18211 | const field_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, runtime_index); | 18211 | const field_src = mod.initSrc(src.node_offset.x, decl, runtime_index); |
| 18212 | try sema.requireRuntimeBlock(block, src, field_src); | 18212 | try sema.requireRuntimeBlock(block, src, field_src); |
| 18213 | unreachable; | 18213 | unreachable; |
| 18214 | }, | 18214 | }, |
| ... | @@ -18283,7 +18283,7 @@ fn zirArrayInit( | ... | @@ -18283,7 +18283,7 @@ fn zirArrayInit( |
| 18283 | resolved_args[i] = sema.coerce(block, elem_ty, resolved_arg, .unneeded) catch |err| switch (err) { | 18283 | resolved_args[i] = sema.coerce(block, elem_ty, resolved_arg, .unneeded) catch |err| switch (err) { |
| 18284 | error.NeededSourceLocation => { | 18284 | error.NeededSourceLocation => { |
| 18285 | const decl = sema.mod.declPtr(block.src_decl); | 18285 | const decl = sema.mod.declPtr(block.src_decl); |
| 18286 | const elem_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, i); | 18286 | const elem_src = mod.initSrc(src.node_offset.x, decl, i); |
| 18287 | _ = try sema.coerce(block, elem_ty, resolved_arg, elem_src); | 18287 | _ = try sema.coerce(block, elem_ty, resolved_arg, elem_src); |
| 18288 | unreachable; | 18288 | unreachable; |
| 18289 | }, | 18289 | }, |
| ... | @@ -18315,7 +18315,7 @@ fn zirArrayInit( | ... | @@ -18315,7 +18315,7 @@ fn zirArrayInit( |
| 18315 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { | 18315 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { |
| 18316 | error.NeededSourceLocation => { | 18316 | error.NeededSourceLocation => { |
| 18317 | const decl = sema.mod.declPtr(block.src_decl); | 18317 | const decl = sema.mod.declPtr(block.src_decl); |
| 18318 | const elem_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, runtime_index); | 18318 | const elem_src = mod.initSrc(src.node_offset.x, decl, runtime_index); |
| 18319 | try sema.requireRuntimeBlock(block, src, elem_src); | 18319 | try sema.requireRuntimeBlock(block, src, elem_src); |
| 18320 | unreachable; | 18320 | unreachable; |
| 18321 | }, | 18321 | }, |
| ... | @@ -18724,7 +18724,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -18724,7 +18724,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18724 | enum_ty.fmt(mod), | 18724 | enum_ty.fmt(mod), |
| 18725 | }); | 18725 | }); |
| 18726 | } | 18726 | } |
| 18727 | const enum_decl_index = enum_ty.getOwnerDecl(); | 18727 | const enum_decl_index = enum_ty.getOwnerDecl(mod); |
| 18728 | const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src); | 18728 | const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src); |
| 18729 | if (try sema.resolveDefinedValue(block, operand_src, casted_operand)) |val| { | 18729 | if (try sema.resolveDefinedValue(block, operand_src, casted_operand)) |val| { |
| 18730 | const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse { | 18730 | const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse { |
| ... | @@ -18734,7 +18734,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -18734,7 +18734,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18734 | val.fmtValue(enum_ty, sema.mod), enum_decl.name, | 18734 | val.fmtValue(enum_ty, sema.mod), enum_decl.name, |
| 18735 | }); | 18735 | }); |
| 18736 | errdefer msg.destroy(sema.gpa); | 18736 | errdefer msg.destroy(sema.gpa); |
| 18737 | try mod.errNoteNonLazy(enum_decl.srcLoc(), msg, "declared here", .{}); | 18737 | try mod.errNoteNonLazy(enum_decl.srcLoc(mod), msg, "declared here", .{}); |
| 18738 | break :msg msg; | 18738 | break :msg msg; |
| 18739 | }; | 18739 | }; |
| 18740 | return sema.failWithOwnedErrorMsg(msg); | 18740 | return sema.failWithOwnedErrorMsg(msg); |
| ... | @@ -18760,6 +18760,7 @@ fn zirReify( | ... | @@ -18760,6 +18760,7 @@ fn zirReify( |
| 18760 | inst: Zir.Inst.Index, | 18760 | inst: Zir.Inst.Index, |
| 18761 | ) CompileError!Air.Inst.Ref { | 18761 | ) CompileError!Air.Inst.Ref { |
| 18762 | const mod = sema.mod; | 18762 | const mod = sema.mod; |
| 18763 | const gpa = sema.gpa; | ||
| 18763 | const name_strategy = @intToEnum(Zir.Inst.NameStrategy, extended.small); | 18764 | const name_strategy = @intToEnum(Zir.Inst.NameStrategy, extended.small); |
| 18764 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 18765 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 18765 | const src = LazySrcLoc.nodeOffset(extra.node); | 18766 | const src = LazySrcLoc.nodeOffset(extra.node); |
| ... | @@ -18887,10 +18888,10 @@ fn zirReify( | ... | @@ -18887,10 +18888,10 @@ fn zirReify( |
| 18887 | if (!try sema.validateExternType(elem_ty, .other)) { | 18888 | if (!try sema.validateExternType(elem_ty, .other)) { |
| 18888 | const msg = msg: { | 18889 | const msg = msg: { |
| 18889 | const msg = try sema.errMsg(block, src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)}); | 18890 | const msg = try sema.errMsg(block, src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)}); |
| 18890 | errdefer msg.destroy(sema.gpa); | 18891 | errdefer msg.destroy(gpa); |
| 18891 | 18892 | ||
| 18892 | const src_decl = mod.declPtr(block.src_decl); | 18893 | const src_decl = mod.declPtr(block.src_decl); |
| 18893 | try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl), elem_ty, .other); | 18894 | try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), elem_ty, .other); |
| 18894 | 18895 | ||
| 18895 | try sema.addDeclaredHereNote(msg, elem_ty); | 18896 | try sema.addDeclaredHereNote(msg, elem_ty); |
| 18896 | break :msg msg; | 18897 | break :msg msg; |
| ... | @@ -19043,7 +19044,6 @@ fn zirReify( | ... | @@ -19043,7 +19044,6 @@ fn zirReify( |
| 19043 | return sema.fail(block, src, "reified enums must have no decls", .{}); | 19044 | return sema.fail(block, src, "reified enums must have no decls", .{}); |
| 19044 | } | 19045 | } |
| 19045 | 19046 | ||
| 19046 | const gpa = sema.gpa; | ||
| 19047 | var new_decl_arena = std.heap.ArenaAllocator.init(gpa); | 19047 | var new_decl_arena = std.heap.ArenaAllocator.init(gpa); |
| 19048 | errdefer new_decl_arena.deinit(); | 19048 | errdefer new_decl_arena.deinit(); |
| 19049 | const new_decl_arena_allocator = new_decl_arena.allocator(); | 19049 | const new_decl_arena_allocator = new_decl_arena.allocator(); |
| ... | @@ -19076,11 +19076,11 @@ fn zirReify( | ... | @@ -19076,11 +19076,11 @@ fn zirReify( |
| 19076 | .tag_ty_inferred = false, | 19076 | .tag_ty_inferred = false, |
| 19077 | .fields = .{}, | 19077 | .fields = .{}, |
| 19078 | .values = .{}, | 19078 | .values = .{}, |
| 19079 | .namespace = .{ | 19079 | .namespace = try mod.createNamespace(.{ |
| 19080 | .parent = block.namespace, | 19080 | .parent = block.namespace.toOptional(), |
| 19081 | .ty = enum_ty, | 19081 | .ty = enum_ty, |
| 19082 | .file_scope = block.getFileScope(), | 19082 | .file_scope = block.getFileScope(mod), |
| 19083 | }, | 19083 | }), |
| 19084 | }; | 19084 | }; |
| 19085 | 19085 | ||
| 19086 | // Enum tag type | 19086 | // Enum tag type |
| ... | @@ -19164,34 +19164,37 @@ fn zirReify( | ... | @@ -19164,34 +19164,37 @@ fn zirReify( |
| 19164 | return sema.fail(block, src, "reified opaque must have no decls", .{}); | 19164 | return sema.fail(block, src, "reified opaque must have no decls", .{}); |
| 19165 | } | 19165 | } |
| 19166 | 19166 | ||
| 19167 | var new_decl_arena = std.heap.ArenaAllocator.init(sema.gpa); | 19167 | var new_decl_arena = std.heap.ArenaAllocator.init(gpa); |
| 19168 | errdefer new_decl_arena.deinit(); | 19168 | errdefer new_decl_arena.deinit(); |
| 19169 | const new_decl_arena_allocator = new_decl_arena.allocator(); | ||
| 19170 | 19169 | ||
| 19171 | const opaque_obj = try new_decl_arena_allocator.create(Module.Opaque); | 19170 | // Because these three things each reference each other, |
| 19172 | const opaque_ty_payload = try new_decl_arena_allocator.create(Type.Payload.Opaque); | 19171 | // `undefined` placeholders are used in two places before being set |
| 19173 | opaque_ty_payload.* = .{ | 19172 | // after the opaque type gains an InternPool index. |
| 19174 | .base = .{ .tag = .@"opaque" }, | 19173 | |
| 19175 | .data = opaque_obj, | ||
| 19176 | }; | ||
| 19177 | const opaque_ty = Type.initPayload(&opaque_ty_payload.base); | ||
| 19178 | const opaque_val = try Value.Tag.ty.create(new_decl_arena_allocator, opaque_ty); | ||
| 19179 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{ | 19174 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{ |
| 19180 | .ty = Type.type, | 19175 | .ty = Type.type, |
| 19181 | .val = opaque_val, | 19176 | .val = undefined, |
| 19182 | }, name_strategy, "opaque", inst); | 19177 | }, name_strategy, "opaque", inst); |
| 19183 | const new_decl = mod.declPtr(new_decl_index); | 19178 | const new_decl = mod.declPtr(new_decl_index); |
| 19184 | new_decl.owns_tv = true; | 19179 | new_decl.owns_tv = true; |
| 19185 | errdefer mod.abortAnonDecl(new_decl_index); | 19180 | errdefer mod.abortAnonDecl(new_decl_index); |
| 19186 | 19181 | ||
| 19187 | opaque_obj.* = .{ | 19182 | const new_namespace_index = try mod.createNamespace(.{ |
| 19188 | .owner_decl = new_decl_index, | 19183 | .parent = block.namespace.toOptional(), |
| 19189 | .namespace = .{ | 19184 | .ty = undefined, |
| 19190 | .parent = block.namespace, | 19185 | .file_scope = block.getFileScope(mod), |
| 19191 | .ty = opaque_ty, | 19186 | }); |
| 19192 | .file_scope = block.getFileScope(), | 19187 | const new_namespace = mod.namespacePtr(new_namespace_index); |
| 19193 | }, | 19188 | errdefer @panic("TODO error handling"); |
| 19194 | }; | 19189 | |
| 19190 | const opaque_ty = try mod.intern_pool.get(gpa, .{ .opaque_type = .{ | ||
| 19191 | .decl = new_decl_index, | ||
| 19192 | .namespace = new_namespace_index, | ||
| 19193 | } }); | ||
| 19194 | errdefer @panic("TODO error handling"); | ||
| 19195 | |||
| 19196 | new_decl.val = opaque_ty.toValue(); | ||
| 19197 | new_namespace.ty = opaque_ty.toType(); | ||
| 19195 | 19198 | ||
| 19196 | try new_decl.finalizeNewArena(&new_decl_arena); | 19199 | try new_decl.finalizeNewArena(&new_decl_arena); |
| 19197 | return sema.analyzeDeclVal(block, src, new_decl_index); | 19200 | return sema.analyzeDeclVal(block, src, new_decl_index); |
| ... | @@ -19214,7 +19217,7 @@ fn zirReify( | ... | @@ -19214,7 +19217,7 @@ fn zirReify( |
| 19214 | } | 19217 | } |
| 19215 | const layout = layout_val.toEnum(std.builtin.Type.ContainerLayout); | 19218 | const layout = layout_val.toEnum(std.builtin.Type.ContainerLayout); |
| 19216 | 19219 | ||
| 19217 | var new_decl_arena = std.heap.ArenaAllocator.init(sema.gpa); | 19220 | var new_decl_arena = std.heap.ArenaAllocator.init(gpa); |
| 19218 | errdefer new_decl_arena.deinit(); | 19221 | errdefer new_decl_arena.deinit(); |
| 19219 | const new_decl_arena_allocator = new_decl_arena.allocator(); | 19222 | const new_decl_arena_allocator = new_decl_arena.allocator(); |
| 19220 | 19223 | ||
| ... | @@ -19248,11 +19251,11 @@ fn zirReify( | ... | @@ -19248,11 +19251,11 @@ fn zirReify( |
| 19248 | .zir_index = inst, | 19251 | .zir_index = inst, |
| 19249 | .layout = layout, | 19252 | .layout = layout, |
| 19250 | .status = .have_field_types, | 19253 | .status = .have_field_types, |
| 19251 | .namespace = .{ | 19254 | .namespace = try mod.createNamespace(.{ |
| 19252 | .parent = block.namespace, | 19255 | .parent = block.namespace.toOptional(), |
| 19253 | .ty = union_ty, | 19256 | .ty = union_ty, |
| 19254 | .file_scope = block.getFileScope(), | 19257 | .file_scope = block.getFileScope(mod), |
| 19255 | }, | 19258 | }), |
| 19256 | }; | 19259 | }; |
| 19257 | 19260 | ||
| 19258 | // Tag type | 19261 | // Tag type |
| ... | @@ -19301,7 +19304,7 @@ fn zirReify( | ... | @@ -19301,7 +19304,7 @@ fn zirReify( |
| 19301 | if (!enum_has_field) { | 19304 | if (!enum_has_field) { |
| 19302 | const msg = msg: { | 19305 | const msg = msg: { |
| 19303 | const msg = try sema.errMsg(block, src, "no field named '{s}' in enum '{}'", .{ field_name, union_obj.tag_ty.fmt(mod) }); | 19306 | const msg = try sema.errMsg(block, src, "no field named '{s}' in enum '{}'", .{ field_name, union_obj.tag_ty.fmt(mod) }); |
| 19304 | errdefer msg.destroy(sema.gpa); | 19307 | errdefer msg.destroy(gpa); |
| 19305 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); | 19308 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); |
| 19306 | break :msg msg; | 19309 | break :msg msg; |
| 19307 | }; | 19310 | }; |
| ... | @@ -19324,7 +19327,7 @@ fn zirReify( | ... | @@ -19324,7 +19327,7 @@ fn zirReify( |
| 19324 | if (field_ty.zigTypeTag(mod) == .Opaque) { | 19327 | if (field_ty.zigTypeTag(mod) == .Opaque) { |
| 19325 | const msg = msg: { | 19328 | const msg = msg: { |
| 19326 | const msg = try sema.errMsg(block, src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{}); | 19329 | const msg = try sema.errMsg(block, src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{}); |
| 19327 | errdefer msg.destroy(sema.gpa); | 19330 | errdefer msg.destroy(gpa); |
| 19328 | 19331 | ||
| 19329 | try sema.addDeclaredHereNote(msg, field_ty); | 19332 | try sema.addDeclaredHereNote(msg, field_ty); |
| 19330 | break :msg msg; | 19333 | break :msg msg; |
| ... | @@ -19334,10 +19337,10 @@ fn zirReify( | ... | @@ -19334,10 +19337,10 @@ fn zirReify( |
| 19334 | if (union_obj.layout == .Extern and !try sema.validateExternType(field_ty, .union_field)) { | 19337 | if (union_obj.layout == .Extern and !try sema.validateExternType(field_ty, .union_field)) { |
| 19335 | const msg = msg: { | 19338 | const msg = msg: { |
| 19336 | const msg = try sema.errMsg(block, src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); | 19339 | const msg = try sema.errMsg(block, src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| 19337 | errdefer msg.destroy(sema.gpa); | 19340 | errdefer msg.destroy(gpa); |
| 19338 | 19341 | ||
| 19339 | const src_decl = mod.declPtr(block.src_decl); | 19342 | const src_decl = mod.declPtr(block.src_decl); |
| 19340 | try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl), field_ty, .union_field); | 19343 | try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), field_ty, .union_field); |
| 19341 | 19344 | ||
| 19342 | try sema.addDeclaredHereNote(msg, field_ty); | 19345 | try sema.addDeclaredHereNote(msg, field_ty); |
| 19343 | break :msg msg; | 19346 | break :msg msg; |
| ... | @@ -19346,10 +19349,10 @@ fn zirReify( | ... | @@ -19346,10 +19349,10 @@ fn zirReify( |
| 19346 | } else if (union_obj.layout == .Packed and !(validatePackedType(field_ty, mod))) { | 19349 | } else if (union_obj.layout == .Packed and !(validatePackedType(field_ty, mod))) { |
| 19347 | const msg = msg: { | 19350 | const msg = msg: { |
| 19348 | const msg = try sema.errMsg(block, src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); | 19351 | const msg = try sema.errMsg(block, src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| 19349 | errdefer msg.destroy(sema.gpa); | 19352 | errdefer msg.destroy(gpa); |
| 19350 | 19353 | ||
| 19351 | const src_decl = mod.declPtr(block.src_decl); | 19354 | const src_decl = mod.declPtr(block.src_decl); |
| 19352 | try sema.explainWhyTypeIsNotPacked(msg, src.toSrcLoc(src_decl), field_ty); | 19355 | try sema.explainWhyTypeIsNotPacked(msg, src.toSrcLoc(src_decl, mod), field_ty); |
| 19353 | 19356 | ||
| 19354 | try sema.addDeclaredHereNote(msg, field_ty); | 19357 | try sema.addDeclaredHereNote(msg, field_ty); |
| 19355 | break :msg msg; | 19358 | break :msg msg; |
| ... | @@ -19362,7 +19365,7 @@ fn zirReify( | ... | @@ -19362,7 +19365,7 @@ fn zirReify( |
| 19362 | if (names.count() > 0) { | 19365 | if (names.count() > 0) { |
| 19363 | const msg = msg: { | 19366 | const msg = msg: { |
| 19364 | const msg = try sema.errMsg(block, src, "enum field(s) missing in union", .{}); | 19367 | const msg = try sema.errMsg(block, src, "enum field(s) missing in union", .{}); |
| 19365 | errdefer msg.destroy(sema.gpa); | 19368 | errdefer msg.destroy(gpa); |
| 19366 | 19369 | ||
| 19367 | const enum_ty = union_obj.tag_ty; | 19370 | const enum_ty = union_obj.tag_ty; |
| 19368 | for (names.keys()) |field_name| { | 19371 | for (names.keys()) |field_name| { |
| ... | @@ -19513,11 +19516,11 @@ fn reifyStruct( | ... | @@ -19513,11 +19516,11 @@ fn reifyStruct( |
| 19513 | .status = .have_field_types, | 19516 | .status = .have_field_types, |
| 19514 | .known_non_opv = false, | 19517 | .known_non_opv = false, |
| 19515 | .is_tuple = is_tuple, | 19518 | .is_tuple = is_tuple, |
| 19516 | .namespace = .{ | 19519 | .namespace = try mod.createNamespace(.{ |
| 19517 | .parent = block.namespace, | 19520 | .parent = block.namespace.toOptional(), |
| 19518 | .ty = struct_ty, | 19521 | .ty = struct_ty, |
| 19519 | .file_scope = block.getFileScope(), | 19522 | .file_scope = block.getFileScope(mod), |
| 19520 | }, | 19523 | }), |
| 19521 | }; | 19524 | }; |
| 19522 | 19525 | ||
| 19523 | // Fields | 19526 | // Fields |
| ... | @@ -19629,7 +19632,7 @@ fn reifyStruct( | ... | @@ -19629,7 +19632,7 @@ fn reifyStruct( |
| 19629 | errdefer msg.destroy(sema.gpa); | 19632 | errdefer msg.destroy(sema.gpa); |
| 19630 | 19633 | ||
| 19631 | const src_decl = sema.mod.declPtr(block.src_decl); | 19634 | const src_decl = sema.mod.declPtr(block.src_decl); |
| 19632 | try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl), field_ty, .struct_field); | 19635 | try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), field_ty, .struct_field); |
| 19633 | 19636 | ||
| 19634 | try sema.addDeclaredHereNote(msg, field_ty); | 19637 | try sema.addDeclaredHereNote(msg, field_ty); |
| 19635 | break :msg msg; | 19638 | break :msg msg; |
| ... | @@ -19641,7 +19644,7 @@ fn reifyStruct( | ... | @@ -19641,7 +19644,7 @@ fn reifyStruct( |
| 19641 | errdefer msg.destroy(sema.gpa); | 19644 | errdefer msg.destroy(sema.gpa); |
| 19642 | 19645 | ||
| 19643 | const src_decl = sema.mod.declPtr(block.src_decl); | 19646 | const src_decl = sema.mod.declPtr(block.src_decl); |
| 19644 | try sema.explainWhyTypeIsNotPacked(msg, src.toSrcLoc(src_decl), field_ty); | 19647 | try sema.explainWhyTypeIsNotPacked(msg, src.toSrcLoc(src_decl, mod), field_ty); |
| 19645 | 19648 | ||
| 19646 | try sema.addDeclaredHereNote(msg, field_ty); | 19649 | try sema.addDeclaredHereNote(msg, field_ty); |
| 19647 | break :msg msg; | 19650 | break :msg msg; |
| ... | @@ -19741,6 +19744,7 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In | ... | @@ -19741,6 +19744,7 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In |
| 19741 | } | 19744 | } |
| 19742 | 19745 | ||
| 19743 | fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | 19746 | fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 19747 | const mod = sema.mod; | ||
| 19744 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 19748 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 19745 | const src = LazySrcLoc.nodeOffset(extra.node); | 19749 | const src = LazySrcLoc.nodeOffset(extra.node); |
| 19746 | const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 19750 | const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| ... | @@ -19755,7 +19759,7 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C | ... | @@ -19755,7 +19759,7 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 19755 | errdefer msg.destroy(sema.gpa); | 19759 | errdefer msg.destroy(sema.gpa); |
| 19756 | 19760 | ||
| 19757 | const src_decl = sema.mod.declPtr(block.src_decl); | 19761 | const src_decl = sema.mod.declPtr(block.src_decl); |
| 19758 | try sema.explainWhyTypeIsNotExtern(msg, ty_src.toSrcLoc(src_decl), arg_ty, .param_ty); | 19762 | try sema.explainWhyTypeIsNotExtern(msg, ty_src.toSrcLoc(src_decl, mod), arg_ty, .param_ty); |
| 19759 | 19763 | ||
| 19760 | try sema.addDeclaredHereNote(msg, arg_ty); | 19764 | try sema.addDeclaredHereNote(msg, arg_ty); |
| 19761 | break :msg msg; | 19765 | break :msg msg; |
| ... | @@ -21006,7 +21010,8 @@ fn checkVectorizableBinaryOperands( | ... | @@ -21006,7 +21010,8 @@ fn checkVectorizableBinaryOperands( |
| 21006 | 21010 | ||
| 21007 | fn maybeOptionsSrc(sema: *Sema, block: *Block, base_src: LazySrcLoc, wanted: []const u8) LazySrcLoc { | 21011 | fn maybeOptionsSrc(sema: *Sema, block: *Block, base_src: LazySrcLoc, wanted: []const u8) LazySrcLoc { |
| 21008 | if (base_src == .unneeded) return .unneeded; | 21012 | if (base_src == .unneeded) return .unneeded; |
| 21009 | return Module.optionsSrc(sema.gpa, sema.mod.declPtr(block.src_decl), base_src, wanted); | 21013 | const mod = sema.mod; |
| 21014 | return mod.optionsSrc(sema.mod.declPtr(block.src_decl), base_src, wanted); | ||
| 21010 | } | 21015 | } |
| 21011 | 21016 | ||
| 21012 | fn resolveExportOptions( | 21017 | fn resolveExportOptions( |
| ... | @@ -23067,7 +23072,7 @@ fn zirBuiltinExtern( | ... | @@ -23067,7 +23072,7 @@ fn zirBuiltinExtern( |
| 23067 | const msg = try sema.errMsg(block, ty_src, "extern symbol cannot have type '{}'", .{ty.fmt(mod)}); | 23072 | const msg = try sema.errMsg(block, ty_src, "extern symbol cannot have type '{}'", .{ty.fmt(mod)}); |
| 23068 | errdefer msg.destroy(sema.gpa); | 23073 | errdefer msg.destroy(sema.gpa); |
| 23069 | const src_decl = sema.mod.declPtr(block.src_decl); | 23074 | const src_decl = sema.mod.declPtr(block.src_decl); |
| 23070 | try sema.explainWhyTypeIsNotExtern(msg, ty_src.toSrcLoc(src_decl), ty, .other); | 23075 | try sema.explainWhyTypeIsNotExtern(msg, ty_src.toSrcLoc(src_decl, mod), ty, .other); |
| 23071 | break :msg msg; | 23076 | break :msg msg; |
| 23072 | }; | 23077 | }; |
| 23073 | return sema.failWithOwnedErrorMsg(msg); | 23078 | return sema.failWithOwnedErrorMsg(msg); |
| ... | @@ -23087,9 +23092,9 @@ fn zirBuiltinExtern( | ... | @@ -23087,9 +23092,9 @@ fn zirBuiltinExtern( |
| 23087 | 23092 | ||
| 23088 | // TODO check duplicate extern | 23093 | // TODO check duplicate extern |
| 23089 | 23094 | ||
| 23090 | const new_decl_index = try sema.mod.allocateNewDecl(sema.owner_decl.src_namespace, sema.owner_decl.src_node, null); | 23095 | const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace, sema.owner_decl.src_node, null); |
| 23091 | errdefer sema.mod.destroyDecl(new_decl_index); | 23096 | errdefer mod.destroyDecl(new_decl_index); |
| 23092 | const new_decl = sema.mod.declPtr(new_decl_index); | 23097 | const new_decl = mod.declPtr(new_decl_index); |
| 23093 | new_decl.name = try sema.gpa.dupeZ(u8, options.name); | 23098 | new_decl.name = try sema.gpa.dupeZ(u8, options.name); |
| 23094 | 23099 | ||
| 23095 | { | 23100 | { |
| ... | @@ -23117,12 +23122,12 @@ fn zirBuiltinExtern( | ... | @@ -23117,12 +23122,12 @@ fn zirBuiltinExtern( |
| 23117 | new_decl.@"linksection" = null; | 23122 | new_decl.@"linksection" = null; |
| 23118 | new_decl.has_tv = true; | 23123 | new_decl.has_tv = true; |
| 23119 | new_decl.analysis = .complete; | 23124 | new_decl.analysis = .complete; |
| 23120 | new_decl.generation = sema.mod.generation; | 23125 | new_decl.generation = mod.generation; |
| 23121 | 23126 | ||
| 23122 | try new_decl.finalizeNewArena(&new_decl_arena); | 23127 | try new_decl.finalizeNewArena(&new_decl_arena); |
| 23123 | } | 23128 | } |
| 23124 | 23129 | ||
| 23125 | try sema.mod.declareDeclDependency(sema.owner_decl_index, new_decl_index); | 23130 | try mod.declareDeclDependency(sema.owner_decl_index, new_decl_index); |
| 23126 | try sema.ensureDeclAnalyzed(new_decl_index); | 23131 | try sema.ensureDeclAnalyzed(new_decl_index); |
| 23127 | 23132 | ||
| 23128 | const ref = try Value.Tag.decl_ref.create(sema.arena, new_decl_index); | 23133 | const ref = try Value.Tag.decl_ref.create(sema.arena, new_decl_index); |
| ... | @@ -23209,7 +23214,7 @@ fn validateVarType( | ... | @@ -23209,7 +23214,7 @@ fn validateVarType( |
| 23209 | const msg = try sema.errMsg(block, src, "extern variable cannot have type '{}'", .{var_ty.fmt(mod)}); | 23214 | const msg = try sema.errMsg(block, src, "extern variable cannot have type '{}'", .{var_ty.fmt(mod)}); |
| 23210 | errdefer msg.destroy(sema.gpa); | 23215 | errdefer msg.destroy(sema.gpa); |
| 23211 | const src_decl = mod.declPtr(block.src_decl); | 23216 | const src_decl = mod.declPtr(block.src_decl); |
| 23212 | try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl), var_ty, .other); | 23217 | try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), var_ty, .other); |
| 23213 | break :msg msg; | 23218 | break :msg msg; |
| 23214 | }; | 23219 | }; |
| 23215 | return sema.failWithOwnedErrorMsg(msg); | 23220 | return sema.failWithOwnedErrorMsg(msg); |
| ... | @@ -23222,7 +23227,7 @@ fn validateVarType( | ... | @@ -23222,7 +23227,7 @@ fn validateVarType( |
| 23222 | errdefer msg.destroy(sema.gpa); | 23227 | errdefer msg.destroy(sema.gpa); |
| 23223 | 23228 | ||
| 23224 | const src_decl = mod.declPtr(block.src_decl); | 23229 | const src_decl = mod.declPtr(block.src_decl); |
| 23225 | try sema.explainWhyTypeIsComptime(msg, src.toSrcLoc(src_decl), var_ty); | 23230 | try sema.explainWhyTypeIsComptime(msg, src.toSrcLoc(src_decl, mod), var_ty); |
| 23226 | if (var_ty.zigTypeTag(mod) == .ComptimeInt or var_ty.zigTypeTag(mod) == .ComptimeFloat) { | 23231 | if (var_ty.zigTypeTag(mod) == .ComptimeInt or var_ty.zigTypeTag(mod) == .ComptimeFloat) { |
| 23227 | try sema.errNote(block, src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{}); | 23232 | try sema.errNote(block, src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{}); |
| 23228 | } | 23233 | } |
| ... | @@ -23939,11 +23944,12 @@ fn safetyPanic( | ... | @@ -23939,11 +23944,12 @@ fn safetyPanic( |
| 23939 | block: *Block, | 23944 | block: *Block, |
| 23940 | panic_id: PanicId, | 23945 | panic_id: PanicId, |
| 23941 | ) CompileError!void { | 23946 | ) CompileError!void { |
| 23947 | const mod = sema.mod; | ||
| 23942 | const panic_messages_ty = try sema.getBuiltinType("panic_messages"); | 23948 | const panic_messages_ty = try sema.getBuiltinType("panic_messages"); |
| 23943 | const msg_decl_index = (try sema.namespaceLookup( | 23949 | const msg_decl_index = (try sema.namespaceLookup( |
| 23944 | block, | 23950 | block, |
| 23945 | sema.src, | 23951 | sema.src, |
| 23946 | panic_messages_ty.getNamespace().?, | 23952 | panic_messages_ty.getNamespaceIndex(mod).unwrap().?, |
| 23947 | @tagName(panic_id), | 23953 | @tagName(panic_id), |
| 23948 | )).?; | 23954 | )).?; |
| 23949 | 23955 | ||
| ... | @@ -24006,7 +24012,7 @@ fn fieldVal( | ... | @@ -24006,7 +24012,7 @@ fn fieldVal( |
| 24006 | ); | 24012 | ); |
| 24007 | } else if (mem.eql(u8, field_name, "ptr") and is_pointer_to) { | 24013 | } else if (mem.eql(u8, field_name, "ptr") and is_pointer_to) { |
| 24008 | const ptr_info = object_ty.ptrInfo(mod); | 24014 | const ptr_info = object_ty.ptrInfo(mod); |
| 24009 | const result_ty = try Type.ptr(sema.arena, sema.mod, .{ | 24015 | const result_ty = try Type.ptr(sema.arena, mod, .{ |
| 24010 | .pointee_type = ptr_info.pointee_type.childType(mod), | 24016 | .pointee_type = ptr_info.pointee_type.childType(mod), |
| 24011 | .sentinel = ptr_info.sentinel, | 24017 | .sentinel = ptr_info.sentinel, |
| 24012 | .@"align" = ptr_info.@"align", | 24018 | .@"align" = ptr_info.@"align", |
| ... | @@ -24025,7 +24031,7 @@ fn fieldVal( | ... | @@ -24025,7 +24031,7 @@ fn fieldVal( |
| 24025 | block, | 24031 | block, |
| 24026 | field_name_src, | 24032 | field_name_src, |
| 24027 | "no member named '{s}' in '{}'", | 24033 | "no member named '{s}' in '{}'", |
| 24028 | .{ field_name, object_ty.fmt(sema.mod) }, | 24034 | .{ field_name, object_ty.fmt(mod) }, |
| 24029 | ); | 24035 | ); |
| 24030 | } | 24036 | } |
| 24031 | }, | 24037 | }, |
| ... | @@ -24049,7 +24055,7 @@ fn fieldVal( | ... | @@ -24049,7 +24055,7 @@ fn fieldVal( |
| 24049 | block, | 24055 | block, |
| 24050 | field_name_src, | 24056 | field_name_src, |
| 24051 | "no member named '{s}' in '{}'", | 24057 | "no member named '{s}' in '{}'", |
| 24052 | .{ field_name, object_ty.fmt(sema.mod) }, | 24058 | .{ field_name, object_ty.fmt(mod) }, |
| 24053 | ); | 24059 | ); |
| 24054 | } | 24060 | } |
| 24055 | } | 24061 | } |
| ... | @@ -24071,14 +24077,14 @@ fn fieldVal( | ... | @@ -24071,14 +24077,14 @@ fn fieldVal( |
| 24071 | } | 24077 | } |
| 24072 | const msg = msg: { | 24078 | const msg = msg: { |
| 24073 | const msg = try sema.errMsg(block, src, "no error named '{s}' in '{}'", .{ | 24079 | const msg = try sema.errMsg(block, src, "no error named '{s}' in '{}'", .{ |
| 24074 | field_name, child_type.fmt(sema.mod), | 24080 | field_name, child_type.fmt(mod), |
| 24075 | }); | 24081 | }); |
| 24076 | errdefer msg.destroy(sema.gpa); | 24082 | errdefer msg.destroy(sema.gpa); |
| 24077 | try sema.addDeclaredHereNote(msg, child_type); | 24083 | try sema.addDeclaredHereNote(msg, child_type); |
| 24078 | break :msg msg; | 24084 | break :msg msg; |
| 24079 | }; | 24085 | }; |
| 24080 | return sema.failWithOwnedErrorMsg(msg); | 24086 | return sema.failWithOwnedErrorMsg(msg); |
| 24081 | } else (try sema.mod.getErrorValue(field_name)).key; | 24087 | } else (try mod.getErrorValue(field_name)).key; |
| 24082 | 24088 | ||
| 24083 | return sema.addConstant( | 24089 | return sema.addConstant( |
| 24084 | if (!child_type.isAnyError()) | 24090 | if (!child_type.isAnyError()) |
| ... | @@ -24089,7 +24095,7 @@ fn fieldVal( | ... | @@ -24089,7 +24095,7 @@ fn fieldVal( |
| 24089 | ); | 24095 | ); |
| 24090 | }, | 24096 | }, |
| 24091 | .Union => { | 24097 | .Union => { |
| 24092 | if (child_type.getNamespace()) |namespace| { | 24098 | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 24093 | if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| { | 24099 | if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| { |
| 24094 | return inst; | 24100 | return inst; |
| 24095 | } | 24101 | } |
| ... | @@ -24107,7 +24113,7 @@ fn fieldVal( | ... | @@ -24107,7 +24113,7 @@ fn fieldVal( |
| 24107 | return sema.failWithBadMemberAccess(block, union_ty, field_name_src, field_name); | 24113 | return sema.failWithBadMemberAccess(block, union_ty, field_name_src, field_name); |
| 24108 | }, | 24114 | }, |
| 24109 | .Enum => { | 24115 | .Enum => { |
| 24110 | if (child_type.getNamespace()) |namespace| { | 24116 | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 24111 | if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| { | 24117 | if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| { |
| 24112 | return inst; | 24118 | return inst; |
| 24113 | } | 24119 | } |
| ... | @@ -24119,7 +24125,7 @@ fn fieldVal( | ... | @@ -24119,7 +24125,7 @@ fn fieldVal( |
| 24119 | return sema.addConstant(try child_type.copy(arena), enum_val); | 24125 | return sema.addConstant(try child_type.copy(arena), enum_val); |
| 24120 | }, | 24126 | }, |
| 24121 | .Struct, .Opaque => { | 24127 | .Struct, .Opaque => { |
| 24122 | if (child_type.getNamespace()) |namespace| { | 24128 | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 24123 | if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| { | 24129 | if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| { |
| 24124 | return inst; | 24130 | return inst; |
| 24125 | } | 24131 | } |
| ... | @@ -24128,7 +24134,7 @@ fn fieldVal( | ... | @@ -24128,7 +24134,7 @@ fn fieldVal( |
| 24128 | }, | 24134 | }, |
| 24129 | else => { | 24135 | else => { |
| 24130 | const msg = msg: { | 24136 | const msg = msg: { |
| 24131 | const msg = try sema.errMsg(block, src, "type '{}' has no members", .{child_type.fmt(sema.mod)}); | 24137 | const msg = try sema.errMsg(block, src, "type '{}' has no members", .{child_type.fmt(mod)}); |
| 24132 | errdefer msg.destroy(sema.gpa); | 24138 | errdefer msg.destroy(sema.gpa); |
| 24133 | if (child_type.isSlice(mod)) try sema.errNote(block, src, msg, "slice values have 'len' and 'ptr' members", .{}); | 24139 | if (child_type.isSlice(mod)) try sema.errNote(block, src, msg, "slice values have 'len' and 'ptr' members", .{}); |
| 24134 | if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(block, src, msg, "array values have 'len' member", .{}); | 24140 | if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(block, src, msg, "array values have 'len' member", .{}); |
| ... | @@ -24174,7 +24180,7 @@ fn fieldPtr( | ... | @@ -24174,7 +24180,7 @@ fn fieldPtr( |
| 24174 | const object_ptr_ty = sema.typeOf(object_ptr); | 24180 | const object_ptr_ty = sema.typeOf(object_ptr); |
| 24175 | const object_ty = switch (object_ptr_ty.zigTypeTag(mod)) { | 24181 | const object_ty = switch (object_ptr_ty.zigTypeTag(mod)) { |
| 24176 | .Pointer => object_ptr_ty.childType(mod), | 24182 | .Pointer => object_ptr_ty.childType(mod), |
| 24177 | else => return sema.fail(block, object_ptr_src, "expected pointer, found '{}'", .{object_ptr_ty.fmt(sema.mod)}), | 24183 | else => return sema.fail(block, object_ptr_src, "expected pointer, found '{}'", .{object_ptr_ty.fmt(mod)}), |
| 24178 | }; | 24184 | }; |
| 24179 | 24185 | ||
| 24180 | // Zig allows dereferencing a single pointer during field lookup. Note that | 24186 | // Zig allows dereferencing a single pointer during field lookup. Note that |
| ... | @@ -24202,7 +24208,7 @@ fn fieldPtr( | ... | @@ -24202,7 +24208,7 @@ fn fieldPtr( |
| 24202 | block, | 24208 | block, |
| 24203 | field_name_src, | 24209 | field_name_src, |
| 24204 | "no member named '{s}' in '{}'", | 24210 | "no member named '{s}' in '{}'", |
| 24205 | .{ field_name, object_ty.fmt(sema.mod) }, | 24211 | .{ field_name, object_ty.fmt(mod) }, |
| 24206 | ); | 24212 | ); |
| 24207 | } | 24213 | } |
| 24208 | }, | 24214 | }, |
| ... | @@ -24218,7 +24224,7 @@ fn fieldPtr( | ... | @@ -24218,7 +24224,7 @@ fn fieldPtr( |
| 24218 | const buf = try sema.arena.create(Type.SlicePtrFieldTypeBuffer); | 24224 | const buf = try sema.arena.create(Type.SlicePtrFieldTypeBuffer); |
| 24219 | const slice_ptr_ty = inner_ty.slicePtrFieldType(buf, mod); | 24225 | const slice_ptr_ty = inner_ty.slicePtrFieldType(buf, mod); |
| 24220 | 24226 | ||
| 24221 | const result_ty = try Type.ptr(sema.arena, sema.mod, .{ | 24227 | const result_ty = try Type.ptr(sema.arena, mod, .{ |
| 24222 | .pointee_type = slice_ptr_ty, | 24228 | .pointee_type = slice_ptr_ty, |
| 24223 | .mutable = attr_ptr_ty.ptrIsMutable(mod), | 24229 | .mutable = attr_ptr_ty.ptrIsMutable(mod), |
| 24224 | .@"volatile" = attr_ptr_ty.isVolatilePtr(mod), | 24230 | .@"volatile" = attr_ptr_ty.isVolatilePtr(mod), |
| ... | @@ -24239,7 +24245,7 @@ fn fieldPtr( | ... | @@ -24239,7 +24245,7 @@ fn fieldPtr( |
| 24239 | 24245 | ||
| 24240 | return block.addTyOp(.ptr_slice_ptr_ptr, result_ty, inner_ptr); | 24246 | return block.addTyOp(.ptr_slice_ptr_ptr, result_ty, inner_ptr); |
| 24241 | } else if (mem.eql(u8, field_name, "len")) { | 24247 | } else if (mem.eql(u8, field_name, "len")) { |
| 24242 | const result_ty = try Type.ptr(sema.arena, sema.mod, .{ | 24248 | const result_ty = try Type.ptr(sema.arena, mod, .{ |
| 24243 | .pointee_type = Type.usize, | 24249 | .pointee_type = Type.usize, |
| 24244 | .mutable = attr_ptr_ty.ptrIsMutable(mod), | 24250 | .mutable = attr_ptr_ty.ptrIsMutable(mod), |
| 24245 | .@"volatile" = attr_ptr_ty.isVolatilePtr(mod), | 24251 | .@"volatile" = attr_ptr_ty.isVolatilePtr(mod), |
| ... | @@ -24264,7 +24270,7 @@ fn fieldPtr( | ... | @@ -24264,7 +24270,7 @@ fn fieldPtr( |
| 24264 | block, | 24270 | block, |
| 24265 | field_name_src, | 24271 | field_name_src, |
| 24266 | "no member named '{s}' in '{}'", | 24272 | "no member named '{s}' in '{}'", |
| 24267 | .{ field_name, object_ty.fmt(sema.mod) }, | 24273 | .{ field_name, object_ty.fmt(mod) }, |
| 24268 | ); | 24274 | ); |
| 24269 | } | 24275 | } |
| 24270 | }, | 24276 | }, |
| ... | @@ -24287,9 +24293,9 @@ fn fieldPtr( | ... | @@ -24287,9 +24293,9 @@ fn fieldPtr( |
| 24287 | break :blk entry.key_ptr.*; | 24293 | break :blk entry.key_ptr.*; |
| 24288 | } | 24294 | } |
| 24289 | return sema.fail(block, src, "no error named '{s}' in '{}'", .{ | 24295 | return sema.fail(block, src, "no error named '{s}' in '{}'", .{ |
| 24290 | field_name, child_type.fmt(sema.mod), | 24296 | field_name, child_type.fmt(mod), |
| 24291 | }); | 24297 | }); |
| 24292 | } else (try sema.mod.getErrorValue(field_name)).key; | 24298 | } else (try mod.getErrorValue(field_name)).key; |
| 24293 | 24299 | ||
| 24294 | var anon_decl = try block.startAnonDecl(); | 24300 | var anon_decl = try block.startAnonDecl(); |
| 24295 | defer anon_decl.deinit(); | 24301 | defer anon_decl.deinit(); |
| ... | @@ -24303,7 +24309,7 @@ fn fieldPtr( | ... | @@ -24303,7 +24309,7 @@ fn fieldPtr( |
| 24303 | )); | 24309 | )); |
| 24304 | }, | 24310 | }, |
| 24305 | .Union => { | 24311 | .Union => { |
| 24306 | if (child_type.getNamespace()) |namespace| { | 24312 | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 24307 | if (try sema.namespaceLookupRef(block, src, namespace, field_name)) |inst| { | 24313 | if (try sema.namespaceLookupRef(block, src, namespace, field_name)) |inst| { |
| 24308 | return inst; | 24314 | return inst; |
| 24309 | } | 24315 | } |
| ... | @@ -24324,7 +24330,7 @@ fn fieldPtr( | ... | @@ -24324,7 +24330,7 @@ fn fieldPtr( |
| 24324 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); | 24330 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| 24325 | }, | 24331 | }, |
| 24326 | .Enum => { | 24332 | .Enum => { |
| 24327 | if (child_type.getNamespace()) |namespace| { | 24333 | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 24328 | if (try sema.namespaceLookupRef(block, src, namespace, field_name)) |inst| { | 24334 | if (try sema.namespaceLookupRef(block, src, namespace, field_name)) |inst| { |
| 24329 | return inst; | 24335 | return inst; |
| 24330 | } | 24336 | } |
| ... | @@ -24342,14 +24348,14 @@ fn fieldPtr( | ... | @@ -24342,14 +24348,14 @@ fn fieldPtr( |
| 24342 | )); | 24348 | )); |
| 24343 | }, | 24349 | }, |
| 24344 | .Struct, .Opaque => { | 24350 | .Struct, .Opaque => { |
| 24345 | if (child_type.getNamespace()) |namespace| { | 24351 | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 24346 | if (try sema.namespaceLookupRef(block, src, namespace, field_name)) |inst| { | 24352 | if (try sema.namespaceLookupRef(block, src, namespace, field_name)) |inst| { |
| 24347 | return inst; | 24353 | return inst; |
| 24348 | } | 24354 | } |
| 24349 | } | 24355 | } |
| 24350 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); | 24356 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| 24351 | }, | 24357 | }, |
| 24352 | else => return sema.fail(block, src, "type '{}' has no members", .{child_type.fmt(sema.mod)}), | 24358 | else => return sema.fail(block, src, "type '{}' has no members", .{child_type.fmt(mod)}), |
| 24353 | } | 24359 | } |
| 24354 | }, | 24360 | }, |
| 24355 | .Struct => { | 24361 | .Struct => { |
| ... | @@ -24398,7 +24404,7 @@ fn fieldCallBind( | ... | @@ -24398,7 +24404,7 @@ fn fieldCallBind( |
| 24398 | const inner_ty = if (raw_ptr_ty.zigTypeTag(mod) == .Pointer and (raw_ptr_ty.ptrSize(mod) == .One or raw_ptr_ty.ptrSize(mod) == .C)) | 24404 | const inner_ty = if (raw_ptr_ty.zigTypeTag(mod) == .Pointer and (raw_ptr_ty.ptrSize(mod) == .One or raw_ptr_ty.ptrSize(mod) == .C)) |
| 24399 | raw_ptr_ty.childType(mod) | 24405 | raw_ptr_ty.childType(mod) |
| 24400 | else | 24406 | else |
| 24401 | return sema.fail(block, raw_ptr_src, "expected single pointer, found '{}'", .{raw_ptr_ty.fmt(sema.mod)}); | 24407 | return sema.fail(block, raw_ptr_src, "expected single pointer, found '{}'", .{raw_ptr_ty.fmt(mod)}); |
| 24402 | 24408 | ||
| 24403 | // Optionally dereference a second pointer to get the concrete type. | 24409 | // Optionally dereference a second pointer to get the concrete type. |
| 24404 | const is_double_ptr = inner_ty.zigTypeTag(mod) == .Pointer and inner_ty.ptrSize(mod) == .One; | 24410 | const is_double_ptr = inner_ty.zigTypeTag(mod) == .Pointer and inner_ty.ptrSize(mod) == .One; |
| ... | @@ -24458,7 +24464,7 @@ fn fieldCallBind( | ... | @@ -24458,7 +24464,7 @@ fn fieldCallBind( |
| 24458 | // If we get here, we need to look for a decl in the struct type instead. | 24464 | // If we get here, we need to look for a decl in the struct type instead. |
| 24459 | const found_decl = switch (concrete_ty.zigTypeTag(mod)) { | 24465 | const found_decl = switch (concrete_ty.zigTypeTag(mod)) { |
| 24460 | .Struct, .Opaque, .Union, .Enum => found_decl: { | 24466 | .Struct, .Opaque, .Union, .Enum => found_decl: { |
| 24461 | if (concrete_ty.getNamespace()) |namespace| { | 24467 | if (concrete_ty.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 24462 | if (try sema.namespaceLookup(block, src, namespace, field_name)) |decl_idx| { | 24468 | if (try sema.namespaceLookup(block, src, namespace, field_name)) |decl_idx| { |
| 24463 | try sema.addReferencedBy(block, src, decl_idx); | 24469 | try sema.addReferencedBy(block, src, decl_idx); |
| 24464 | const decl_val = try sema.analyzeDeclVal(block, src, decl_idx); | 24470 | const decl_val = try sema.analyzeDeclVal(block, src, decl_idx); |
| ... | @@ -24472,7 +24478,7 @@ fn fieldCallBind( | ... | @@ -24472,7 +24478,7 @@ fn fieldCallBind( |
| 24472 | first_param_type.zigTypeTag(mod) == .Pointer and | 24478 | first_param_type.zigTypeTag(mod) == .Pointer and |
| 24473 | (first_param_type.ptrSize(mod) == .One or | 24479 | (first_param_type.ptrSize(mod) == .One or |
| 24474 | first_param_type.ptrSize(mod) == .C) and | 24480 | first_param_type.ptrSize(mod) == .C) and |
| 24475 | first_param_type.childType(mod).eql(concrete_ty, sema.mod))) | 24481 | first_param_type.childType(mod).eql(concrete_ty, mod))) |
| 24476 | { | 24482 | { |
| 24477 | // zig fmt: on | 24483 | // zig fmt: on |
| 24478 | // Note that if the param type is generic poison, we know that it must | 24484 | // Note that if the param type is generic poison, we know that it must |
| ... | @@ -24484,7 +24490,7 @@ fn fieldCallBind( | ... | @@ -24484,7 +24490,7 @@ fn fieldCallBind( |
| 24484 | .func_inst = decl_val, | 24490 | .func_inst = decl_val, |
| 24485 | .arg0_inst = object_ptr, | 24491 | .arg0_inst = object_ptr, |
| 24486 | } }; | 24492 | } }; |
| 24487 | } else if (first_param_type.eql(concrete_ty, sema.mod)) { | 24493 | } else if (first_param_type.eql(concrete_ty, mod)) { |
| 24488 | const deref = try sema.analyzeLoad(block, src, object_ptr, src); | 24494 | const deref = try sema.analyzeLoad(block, src, object_ptr, src); |
| 24489 | return .{ .method = .{ | 24495 | return .{ .method = .{ |
| 24490 | .func_inst = decl_val, | 24496 | .func_inst = decl_val, |
| ... | @@ -24492,7 +24498,7 @@ fn fieldCallBind( | ... | @@ -24492,7 +24498,7 @@ fn fieldCallBind( |
| 24492 | } }; | 24498 | } }; |
| 24493 | } else if (first_param_type.zigTypeTag(mod) == .Optional) { | 24499 | } else if (first_param_type.zigTypeTag(mod) == .Optional) { |
| 24494 | const child = first_param_type.optionalChild(mod); | 24500 | const child = first_param_type.optionalChild(mod); |
| 24495 | if (child.eql(concrete_ty, sema.mod)) { | 24501 | if (child.eql(concrete_ty, mod)) { |
| 24496 | const deref = try sema.analyzeLoad(block, src, object_ptr, src); | 24502 | const deref = try sema.analyzeLoad(block, src, object_ptr, src); |
| 24497 | return .{ .method = .{ | 24503 | return .{ .method = .{ |
| 24498 | .func_inst = decl_val, | 24504 | .func_inst = decl_val, |
| ... | @@ -24500,7 +24506,7 @@ fn fieldCallBind( | ... | @@ -24500,7 +24506,7 @@ fn fieldCallBind( |
| 24500 | } }; | 24506 | } }; |
| 24501 | } else if (child.zigTypeTag(mod) == .Pointer and | 24507 | } else if (child.zigTypeTag(mod) == .Pointer and |
| 24502 | child.ptrSize(mod) == .One and | 24508 | child.ptrSize(mod) == .One and |
| 24503 | child.childType(mod).eql(concrete_ty, sema.mod)) | 24509 | child.childType(mod).eql(concrete_ty, mod)) |
| 24504 | { | 24510 | { |
| 24505 | return .{ .method = .{ | 24511 | return .{ .method = .{ |
| 24506 | .func_inst = decl_val, | 24512 | .func_inst = decl_val, |
| ... | @@ -24508,7 +24514,7 @@ fn fieldCallBind( | ... | @@ -24508,7 +24514,7 @@ fn fieldCallBind( |
| 24508 | } }; | 24514 | } }; |
| 24509 | } | 24515 | } |
| 24510 | } else if (first_param_type.zigTypeTag(mod) == .ErrorUnion and | 24516 | } else if (first_param_type.zigTypeTag(mod) == .ErrorUnion and |
| 24511 | first_param_type.errorUnionPayload().eql(concrete_ty, sema.mod)) | 24517 | first_param_type.errorUnionPayload().eql(concrete_ty, mod)) |
| 24512 | { | 24518 | { |
| 24513 | const deref = try sema.analyzeLoad(block, src, object_ptr, src); | 24519 | const deref = try sema.analyzeLoad(block, src, object_ptr, src); |
| 24514 | return .{ .method = .{ | 24520 | return .{ .method = .{ |
| ... | @@ -24526,12 +24532,12 @@ fn fieldCallBind( | ... | @@ -24526,12 +24532,12 @@ fn fieldCallBind( |
| 24526 | }; | 24532 | }; |
| 24527 | 24533 | ||
| 24528 | const msg = msg: { | 24534 | const msg = msg: { |
| 24529 | const msg = try sema.errMsg(block, src, "no field or member function named '{s}' in '{}'", .{ field_name, concrete_ty.fmt(sema.mod) }); | 24535 | const msg = try sema.errMsg(block, src, "no field or member function named '{s}' in '{}'", .{ field_name, concrete_ty.fmt(mod) }); |
| 24530 | errdefer msg.destroy(sema.gpa); | 24536 | errdefer msg.destroy(sema.gpa); |
| 24531 | try sema.addDeclaredHereNote(msg, concrete_ty); | 24537 | try sema.addDeclaredHereNote(msg, concrete_ty); |
| 24532 | if (found_decl) |decl_idx| { | 24538 | if (found_decl) |decl_idx| { |
| 24533 | const decl = sema.mod.declPtr(decl_idx); | 24539 | const decl = mod.declPtr(decl_idx); |
| 24534 | try sema.mod.errNoteNonLazy(decl.srcLoc(), msg, "'{s}' is not a member function", .{field_name}); | 24540 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "'{s}' is not a member function", .{field_name}); |
| 24535 | } | 24541 | } |
| 24536 | break :msg msg; | 24542 | break :msg msg; |
| 24537 | }; | 24543 | }; |
| ... | @@ -24549,7 +24555,7 @@ fn finishFieldCallBind( | ... | @@ -24549,7 +24555,7 @@ fn finishFieldCallBind( |
| 24549 | ) CompileError!ResolvedFieldCallee { | 24555 | ) CompileError!ResolvedFieldCallee { |
| 24550 | const mod = sema.mod; | 24556 | const mod = sema.mod; |
| 24551 | const arena = sema.arena; | 24557 | const arena = sema.arena; |
| 24552 | const ptr_field_ty = try Type.ptr(arena, sema.mod, .{ | 24558 | const ptr_field_ty = try Type.ptr(arena, mod, .{ |
| 24553 | .pointee_type = field_ty, | 24559 | .pointee_type = field_ty, |
| 24554 | .mutable = ptr_ty.ptrIsMutable(mod), | 24560 | .mutable = ptr_ty.ptrIsMutable(mod), |
| 24555 | .@"addrspace" = ptr_ty.ptrAddressSpace(mod), | 24561 | .@"addrspace" = ptr_ty.ptrAddressSpace(mod), |
| ... | @@ -24583,19 +24589,20 @@ fn namespaceLookup( | ... | @@ -24583,19 +24589,20 @@ fn namespaceLookup( |
| 24583 | sema: *Sema, | 24589 | sema: *Sema, |
| 24584 | block: *Block, | 24590 | block: *Block, |
| 24585 | src: LazySrcLoc, | 24591 | src: LazySrcLoc, |
| 24586 | namespace: *Namespace, | 24592 | namespace: Namespace.Index, |
| 24587 | decl_name: []const u8, | 24593 | decl_name: []const u8, |
| 24588 | ) CompileError!?Decl.Index { | 24594 | ) CompileError!?Decl.Index { |
| 24595 | const mod = sema.mod; | ||
| 24589 | const gpa = sema.gpa; | 24596 | const gpa = sema.gpa; |
| 24590 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl_index| { | 24597 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl_index| { |
| 24591 | const decl = sema.mod.declPtr(decl_index); | 24598 | const decl = mod.declPtr(decl_index); |
| 24592 | if (!decl.is_pub and decl.getFileScope() != block.getFileScope()) { | 24599 | if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) { |
| 24593 | const msg = msg: { | 24600 | const msg = msg: { |
| 24594 | const msg = try sema.errMsg(block, src, "'{s}' is not marked 'pub'", .{ | 24601 | const msg = try sema.errMsg(block, src, "'{s}' is not marked 'pub'", .{ |
| 24595 | decl_name, | 24602 | decl_name, |
| 24596 | }); | 24603 | }); |
| 24597 | errdefer msg.destroy(gpa); | 24604 | errdefer msg.destroy(gpa); |
| 24598 | try sema.mod.errNoteNonLazy(decl.srcLoc(), msg, "declared here", .{}); | 24605 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "declared here", .{}); |
| 24599 | break :msg msg; | 24606 | break :msg msg; |
| 24600 | }; | 24607 | }; |
| 24601 | return sema.failWithOwnedErrorMsg(msg); | 24608 | return sema.failWithOwnedErrorMsg(msg); |
| ... | @@ -24609,7 +24616,7 @@ fn namespaceLookupRef( | ... | @@ -24609,7 +24616,7 @@ fn namespaceLookupRef( |
| 24609 | sema: *Sema, | 24616 | sema: *Sema, |
| 24610 | block: *Block, | 24617 | block: *Block, |
| 24611 | src: LazySrcLoc, | 24618 | src: LazySrcLoc, |
| 24612 | namespace: *Namespace, | 24619 | namespace: Namespace.Index, |
| 24613 | decl_name: []const u8, | 24620 | decl_name: []const u8, |
| 24614 | ) CompileError!?Air.Inst.Ref { | 24621 | ) CompileError!?Air.Inst.Ref { |
| 24615 | const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null; | 24622 | const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null; |
| ... | @@ -24621,7 +24628,7 @@ fn namespaceLookupVal( | ... | @@ -24621,7 +24628,7 @@ fn namespaceLookupVal( |
| 24621 | sema: *Sema, | 24628 | sema: *Sema, |
| 24622 | block: *Block, | 24629 | block: *Block, |
| 24623 | src: LazySrcLoc, | 24630 | src: LazySrcLoc, |
| 24624 | namespace: *Namespace, | 24631 | namespace: Namespace.Index, |
| 24625 | decl_name: []const u8, | 24632 | decl_name: []const u8, |
| 24626 | ) CompileError!?Air.Inst.Ref { | 24633 | ) CompileError!?Air.Inst.Ref { |
| 24627 | const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null; | 24634 | const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null; |
| ... | @@ -24692,7 +24699,7 @@ fn structFieldPtrByIndex( | ... | @@ -24692,7 +24699,7 @@ fn structFieldPtrByIndex( |
| 24692 | .@"addrspace" = struct_ptr_ty_info.@"addrspace", | 24699 | .@"addrspace" = struct_ptr_ty_info.@"addrspace", |
| 24693 | }; | 24700 | }; |
| 24694 | 24701 | ||
| 24695 | const target = sema.mod.getTarget(); | 24702 | const target = mod.getTarget(); |
| 24696 | 24703 | ||
| 24697 | if (struct_obj.layout == .Packed) { | 24704 | if (struct_obj.layout == .Packed) { |
| 24698 | comptime assert(Type.packed_struct_layout_version == 2); | 24705 | comptime assert(Type.packed_struct_layout_version == 2); |
| ... | @@ -24746,7 +24753,7 @@ fn structFieldPtrByIndex( | ... | @@ -24746,7 +24753,7 @@ fn structFieldPtrByIndex( |
| 24746 | ptr_ty_data.@"align" = field.abi_align; | 24753 | ptr_ty_data.@"align" = field.abi_align; |
| 24747 | } | 24754 | } |
| 24748 | 24755 | ||
| 24749 | const ptr_field_ty = try Type.ptr(sema.arena, sema.mod, ptr_ty_data); | 24756 | const ptr_field_ty = try Type.ptr(sema.arena, mod, ptr_ty_data); |
| 24750 | 24757 | ||
| 24751 | if (field.is_comptime) { | 24758 | if (field.is_comptime) { |
| 24752 | const val = try Value.Tag.comptime_field_ptr.create(sema.arena, .{ | 24759 | const val = try Value.Tag.comptime_field_ptr.create(sema.arena, .{ |
| ... | @@ -24848,16 +24855,17 @@ fn tupleFieldIndex( | ... | @@ -24848,16 +24855,17 @@ fn tupleFieldIndex( |
| 24848 | field_name: []const u8, | 24855 | field_name: []const u8, |
| 24849 | field_name_src: LazySrcLoc, | 24856 | field_name_src: LazySrcLoc, |
| 24850 | ) CompileError!u32 { | 24857 | ) CompileError!u32 { |
| 24858 | const mod = sema.mod; | ||
| 24851 | assert(!std.mem.eql(u8, field_name, "len")); | 24859 | assert(!std.mem.eql(u8, field_name, "len")); |
| 24852 | if (std.fmt.parseUnsigned(u32, field_name, 10)) |field_index| { | 24860 | if (std.fmt.parseUnsigned(u32, field_name, 10)) |field_index| { |
| 24853 | if (field_index < tuple_ty.structFieldCount()) return field_index; | 24861 | if (field_index < tuple_ty.structFieldCount()) return field_index; |
| 24854 | return sema.fail(block, field_name_src, "index '{s}' out of bounds of tuple '{}'", .{ | 24862 | return sema.fail(block, field_name_src, "index '{s}' out of bounds of tuple '{}'", .{ |
| 24855 | field_name, tuple_ty.fmt(sema.mod), | 24863 | field_name, tuple_ty.fmt(mod), |
| 24856 | }); | 24864 | }); |
| 24857 | } else |_| {} | 24865 | } else |_| {} |
| 24858 | 24866 | ||
| 24859 | return sema.fail(block, field_name_src, "no field named '{s}' in tuple '{}'", .{ | 24867 | return sema.fail(block, field_name_src, "no field named '{s}' in tuple '{}'", .{ |
| 24860 | field_name, tuple_ty.fmt(sema.mod), | 24868 | field_name, tuple_ty.fmt(mod), |
| 24861 | }); | 24869 | }); |
| 24862 | } | 24870 | } |
| 24863 | 24871 | ||
| ... | @@ -24913,7 +24921,7 @@ fn unionFieldPtr( | ... | @@ -24913,7 +24921,7 @@ fn unionFieldPtr( |
| 24913 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; | 24921 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; |
| 24914 | const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src); | 24922 | const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src); |
| 24915 | const field = union_obj.fields.values()[field_index]; | 24923 | const field = union_obj.fields.values()[field_index]; |
| 24916 | const ptr_field_ty = try Type.ptr(arena, sema.mod, .{ | 24924 | const ptr_field_ty = try Type.ptr(arena, mod, .{ |
| 24917 | .pointee_type = field.ty, | 24925 | .pointee_type = field.ty, |
| 24918 | .mutable = union_ptr_ty.ptrIsMutable(mod), | 24926 | .mutable = union_ptr_ty.ptrIsMutable(mod), |
| 24919 | .@"volatile" = union_ptr_ty.isVolatilePtr(mod), | 24927 | .@"volatile" = union_ptr_ty.isVolatilePtr(mod), |
| ... | @@ -24947,7 +24955,7 @@ fn unionFieldPtr( | ... | @@ -24947,7 +24955,7 @@ fn unionFieldPtr( |
| 24947 | .data = enum_field_index, | 24955 | .data = enum_field_index, |
| 24948 | }; | 24956 | }; |
| 24949 | const field_tag = Value.initPayload(&field_tag_buf.base); | 24957 | const field_tag = Value.initPayload(&field_tag_buf.base); |
| 24950 | const tag_matches = tag_and_val.tag.eql(field_tag, union_obj.tag_ty, sema.mod); | 24958 | const tag_matches = tag_and_val.tag.eql(field_tag, union_obj.tag_ty, mod); |
| 24951 | if (!tag_matches) { | 24959 | if (!tag_matches) { |
| 24952 | const msg = msg: { | 24960 | const msg = msg: { |
| 24953 | const active_index = tag_and_val.tag.castTag(.enum_field_index).?.data; | 24961 | const active_index = tag_and_val.tag.castTag(.enum_field_index).?.data; |
| ... | @@ -25017,7 +25025,7 @@ fn unionFieldVal( | ... | @@ -25017,7 +25025,7 @@ fn unionFieldVal( |
| 25017 | .data = enum_field_index, | 25025 | .data = enum_field_index, |
| 25018 | }; | 25026 | }; |
| 25019 | const field_tag = Value.initPayload(&field_tag_buf.base); | 25027 | const field_tag = Value.initPayload(&field_tag_buf.base); |
| 25020 | const tag_matches = tag_and_val.tag.eql(field_tag, union_obj.tag_ty, sema.mod); | 25028 | const tag_matches = tag_and_val.tag.eql(field_tag, union_obj.tag_ty, mod); |
| 25021 | switch (union_obj.layout) { | 25029 | switch (union_obj.layout) { |
| 25022 | .Auto => { | 25030 | .Auto => { |
| 25023 | if (tag_matches) { | 25031 | if (tag_matches) { |
| ... | @@ -25038,7 +25046,7 @@ fn unionFieldVal( | ... | @@ -25038,7 +25046,7 @@ fn unionFieldVal( |
| 25038 | if (tag_matches) { | 25046 | if (tag_matches) { |
| 25039 | return sema.addConstant(field.ty, tag_and_val.val); | 25047 | return sema.addConstant(field.ty, tag_and_val.val); |
| 25040 | } else { | 25048 | } else { |
| 25041 | const old_ty = union_ty.unionFieldType(tag_and_val.tag, sema.mod); | 25049 | const old_ty = union_ty.unionFieldType(tag_and_val.tag, mod); |
| 25042 | if (try sema.bitCastVal(block, src, tag_and_val.val, old_ty, field.ty, 0)) |new_val| { | 25050 | if (try sema.bitCastVal(block, src, tag_and_val.val, old_ty, field.ty, 0)) |new_val| { |
| 25043 | return sema.addConstant(field.ty, new_val); | 25051 | return sema.addConstant(field.ty, new_val); |
| 25044 | } | 25052 | } |
| ... | @@ -25079,7 +25087,7 @@ fn elemPtr( | ... | @@ -25079,7 +25087,7 @@ fn elemPtr( |
| 25079 | 25087 | ||
| 25080 | const indexable_ty = switch (indexable_ptr_ty.zigTypeTag(mod)) { | 25088 | const indexable_ty = switch (indexable_ptr_ty.zigTypeTag(mod)) { |
| 25081 | .Pointer => indexable_ptr_ty.childType(mod), | 25089 | .Pointer => indexable_ptr_ty.childType(mod), |
| 25082 | else => return sema.fail(block, indexable_ptr_src, "expected pointer, found '{}'", .{indexable_ptr_ty.fmt(sema.mod)}), | 25090 | else => return sema.fail(block, indexable_ptr_src, "expected pointer, found '{}'", .{indexable_ptr_ty.fmt(mod)}), |
| 25083 | }; | 25091 | }; |
| 25084 | try checkIndexable(sema, block, src, indexable_ty); | 25092 | try checkIndexable(sema, block, src, indexable_ty); |
| 25085 | 25093 | ||
| ... | @@ -25124,7 +25132,7 @@ fn elemPtrOneLayerOnly( | ... | @@ -25124,7 +25132,7 @@ fn elemPtrOneLayerOnly( |
| 25124 | const ptr_val = maybe_ptr_val orelse break :rs indexable_src; | 25132 | const ptr_val = maybe_ptr_val orelse break :rs indexable_src; |
| 25125 | const index_val = maybe_index_val orelse break :rs elem_index_src; | 25133 | const index_val = maybe_index_val orelse break :rs elem_index_src; |
| 25126 | const index = @intCast(usize, index_val.toUnsignedInt(mod)); | 25134 | const index = @intCast(usize, index_val.toUnsignedInt(mod)); |
| 25127 | const elem_ptr = try ptr_val.elemPtr(indexable_ty, sema.arena, index, sema.mod); | 25135 | const elem_ptr = try ptr_val.elemPtr(indexable_ty, sema.arena, index, mod); |
| 25128 | const result_ty = try sema.elemPtrType(indexable_ty, index); | 25136 | const result_ty = try sema.elemPtrType(indexable_ty, index); |
| 25129 | return sema.addConstant(result_ty, elem_ptr); | 25137 | return sema.addConstant(result_ty, elem_ptr); |
| 25130 | }; | 25138 | }; |
| ... | @@ -25170,7 +25178,7 @@ fn elemVal( | ... | @@ -25170,7 +25178,7 @@ fn elemVal( |
| 25170 | const indexable_val = maybe_indexable_val orelse break :rs indexable_src; | 25178 | const indexable_val = maybe_indexable_val orelse break :rs indexable_src; |
| 25171 | const index_val = maybe_index_val orelse break :rs elem_index_src; | 25179 | const index_val = maybe_index_val orelse break :rs elem_index_src; |
| 25172 | const index = @intCast(usize, index_val.toUnsignedInt(mod)); | 25180 | const index = @intCast(usize, index_val.toUnsignedInt(mod)); |
| 25173 | const elem_ptr_val = try indexable_val.elemPtr(indexable_ty, sema.arena, index, sema.mod); | 25181 | const elem_ptr_val = try indexable_val.elemPtr(indexable_ty, sema.arena, index, mod); |
| 25174 | if (try sema.pointerDeref(block, indexable_src, elem_ptr_val, indexable_ty)) |elem_val| { | 25182 | if (try sema.pointerDeref(block, indexable_src, elem_ptr_val, indexable_ty)) |elem_val| { |
| 25175 | return sema.addConstant(indexable_ty.elemType2(mod), elem_val); | 25183 | return sema.addConstant(indexable_ty.elemType2(mod), elem_val); |
| 25176 | } | 25184 | } |
| ... | @@ -25209,6 +25217,7 @@ fn validateRuntimeElemAccess( | ... | @@ -25209,6 +25217,7 @@ fn validateRuntimeElemAccess( |
| 25209 | parent_ty: Type, | 25217 | parent_ty: Type, |
| 25210 | parent_src: LazySrcLoc, | 25218 | parent_src: LazySrcLoc, |
| 25211 | ) CompileError!void { | 25219 | ) CompileError!void { |
| 25220 | const mod = sema.mod; | ||
| 25212 | const valid_rt = try sema.validateRunTimeType(elem_ty, false); | 25221 | const valid_rt = try sema.validateRunTimeType(elem_ty, false); |
| 25213 | if (!valid_rt) { | 25222 | if (!valid_rt) { |
| 25214 | const msg = msg: { | 25223 | const msg = msg: { |
| ... | @@ -25216,12 +25225,12 @@ fn validateRuntimeElemAccess( | ... | @@ -25216,12 +25225,12 @@ fn validateRuntimeElemAccess( |
| 25216 | block, | 25225 | block, |
| 25217 | elem_index_src, | 25226 | elem_index_src, |
| 25218 | "values of type '{}' must be comptime-known, but index value is runtime-known", | 25227 | "values of type '{}' must be comptime-known, but index value is runtime-known", |
| 25219 | .{parent_ty.fmt(sema.mod)}, | 25228 | .{parent_ty.fmt(mod)}, |
| 25220 | ); | 25229 | ); |
| 25221 | errdefer msg.destroy(sema.gpa); | 25230 | errdefer msg.destroy(sema.gpa); |
| 25222 | 25231 | ||
| 25223 | const src_decl = sema.mod.declPtr(block.src_decl); | 25232 | const src_decl = mod.declPtr(block.src_decl); |
| 25224 | try sema.explainWhyTypeIsComptime(msg, parent_src.toSrcLoc(src_decl), parent_ty); | 25233 | try sema.explainWhyTypeIsComptime(msg, parent_src.toSrcLoc(src_decl, mod), parent_ty); |
| 25225 | 25234 | ||
| 25226 | break :msg msg; | 25235 | break :msg msg; |
| 25227 | }; | 25236 | }; |
| ... | @@ -25255,7 +25264,7 @@ fn tupleFieldPtr( | ... | @@ -25255,7 +25264,7 @@ fn tupleFieldPtr( |
| 25255 | } | 25264 | } |
| 25256 | 25265 | ||
| 25257 | const field_ty = tuple_ty.structFieldType(field_index); | 25266 | const field_ty = tuple_ty.structFieldType(field_index); |
| 25258 | const ptr_field_ty = try Type.ptr(sema.arena, sema.mod, .{ | 25267 | const ptr_field_ty = try Type.ptr(sema.arena, mod, .{ |
| 25259 | .pointee_type = field_ty, | 25268 | .pointee_type = field_ty, |
| 25260 | .mutable = tuple_ptr_ty.ptrIsMutable(mod), | 25269 | .mutable = tuple_ptr_ty.ptrIsMutable(mod), |
| 25261 | .@"volatile" = tuple_ptr_ty.isVolatilePtr(mod), | 25270 | .@"volatile" = tuple_ptr_ty.isVolatilePtr(mod), |
| ... | @@ -25431,7 +25440,7 @@ fn elemPtrArray( | ... | @@ -25431,7 +25440,7 @@ fn elemPtrArray( |
| 25431 | return sema.addConstUndef(elem_ptr_ty); | 25440 | return sema.addConstUndef(elem_ptr_ty); |
| 25432 | } | 25441 | } |
| 25433 | if (offset) |index| { | 25442 | if (offset) |index| { |
| 25434 | const elem_ptr = try array_ptr_val.elemPtr(array_ptr_ty, sema.arena, index, sema.mod); | 25443 | const elem_ptr = try array_ptr_val.elemPtr(array_ptr_ty, sema.arena, index, mod); |
| 25435 | return sema.addConstant(elem_ptr_ty, elem_ptr); | 25444 | return sema.addConstant(elem_ptr_ty, elem_ptr); |
| 25436 | } | 25445 | } |
| 25437 | } | 25446 | } |
| ... | @@ -25476,7 +25485,7 @@ fn elemValSlice( | ... | @@ -25476,7 +25485,7 @@ fn elemValSlice( |
| 25476 | 25485 | ||
| 25477 | if (maybe_slice_val) |slice_val| { | 25486 | if (maybe_slice_val) |slice_val| { |
| 25478 | runtime_src = elem_index_src; | 25487 | runtime_src = elem_index_src; |
| 25479 | const slice_len = slice_val.sliceLen(sema.mod); | 25488 | const slice_len = slice_val.sliceLen(mod); |
| 25480 | const slice_len_s = slice_len + @boolToInt(slice_sent); | 25489 | const slice_len_s = slice_len + @boolToInt(slice_sent); |
| 25481 | if (slice_len_s == 0) { | 25490 | if (slice_len_s == 0) { |
| 25482 | return sema.fail(block, slice_src, "indexing into empty slice is not allowed", .{}); | 25491 | return sema.fail(block, slice_src, "indexing into empty slice is not allowed", .{}); |
| ... | @@ -25487,7 +25496,7 @@ fn elemValSlice( | ... | @@ -25487,7 +25496,7 @@ fn elemValSlice( |
| 25487 | const sentinel_label: []const u8 = if (slice_sent) " +1 (sentinel)" else ""; | 25496 | const sentinel_label: []const u8 = if (slice_sent) " +1 (sentinel)" else ""; |
| 25488 | return sema.fail(block, elem_index_src, "index {d} outside slice of length {d}{s}", .{ index, slice_len, sentinel_label }); | 25497 | return sema.fail(block, elem_index_src, "index {d} outside slice of length {d}{s}", .{ index, slice_len, sentinel_label }); |
| 25489 | } | 25498 | } |
| 25490 | const elem_ptr_val = try slice_val.elemPtr(slice_ty, sema.arena, index, sema.mod); | 25499 | const elem_ptr_val = try slice_val.elemPtr(slice_ty, sema.arena, index, mod); |
| 25491 | if (try sema.pointerDeref(block, slice_src, elem_ptr_val, slice_ty)) |elem_val| { | 25500 | if (try sema.pointerDeref(block, slice_src, elem_ptr_val, slice_ty)) |elem_val| { |
| 25492 | return sema.addConstant(elem_ty, elem_val); | 25501 | return sema.addConstant(elem_ty, elem_val); |
| 25493 | } | 25502 | } |
| ... | @@ -25500,7 +25509,7 @@ fn elemValSlice( | ... | @@ -25500,7 +25509,7 @@ fn elemValSlice( |
| 25500 | try sema.requireRuntimeBlock(block, src, runtime_src); | 25509 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 25501 | if (oob_safety and block.wantSafety()) { | 25510 | if (oob_safety and block.wantSafety()) { |
| 25502 | const len_inst = if (maybe_slice_val) |slice_val| | 25511 | const len_inst = if (maybe_slice_val) |slice_val| |
| 25503 | try sema.addIntUnsigned(Type.usize, slice_val.sliceLen(sema.mod)) | 25512 | try sema.addIntUnsigned(Type.usize, slice_val.sliceLen(mod)) |
| 25504 | else | 25513 | else |
| 25505 | try block.addTyOp(.slice_len, Type.usize, slice); | 25514 | try block.addTyOp(.slice_len, Type.usize, slice); |
| 25506 | const cmp_op: Air.Inst.Tag = if (slice_sent) .cmp_lte else .cmp_lt; | 25515 | const cmp_op: Air.Inst.Tag = if (slice_sent) .cmp_lte else .cmp_lt; |
| ... | @@ -25537,7 +25546,7 @@ fn elemPtrSlice( | ... | @@ -25537,7 +25546,7 @@ fn elemPtrSlice( |
| 25537 | if (slice_val.isUndef()) { | 25546 | if (slice_val.isUndef()) { |
| 25538 | return sema.addConstUndef(elem_ptr_ty); | 25547 | return sema.addConstUndef(elem_ptr_ty); |
| 25539 | } | 25548 | } |
| 25540 | const slice_len = slice_val.sliceLen(sema.mod); | 25549 | const slice_len = slice_val.sliceLen(mod); |
| 25541 | const slice_len_s = slice_len + @boolToInt(slice_sent); | 25550 | const slice_len_s = slice_len + @boolToInt(slice_sent); |
| 25542 | if (slice_len_s == 0) { | 25551 | if (slice_len_s == 0) { |
| 25543 | return sema.fail(block, slice_src, "indexing into empty slice is not allowed", .{}); | 25552 | return sema.fail(block, slice_src, "indexing into empty slice is not allowed", .{}); |
| ... | @@ -25547,7 +25556,7 @@ fn elemPtrSlice( | ... | @@ -25547,7 +25556,7 @@ fn elemPtrSlice( |
| 25547 | const sentinel_label: []const u8 = if (slice_sent) " +1 (sentinel)" else ""; | 25556 | const sentinel_label: []const u8 = if (slice_sent) " +1 (sentinel)" else ""; |
| 25548 | return sema.fail(block, elem_index_src, "index {d} outside slice of length {d}{s}", .{ index, slice_len, sentinel_label }); | 25557 | return sema.fail(block, elem_index_src, "index {d} outside slice of length {d}{s}", .{ index, slice_len, sentinel_label }); |
| 25549 | } | 25558 | } |
| 25550 | const elem_ptr_val = try slice_val.elemPtr(slice_ty, sema.arena, index, sema.mod); | 25559 | const elem_ptr_val = try slice_val.elemPtr(slice_ty, sema.arena, index, mod); |
| 25551 | return sema.addConstant(elem_ptr_ty, elem_ptr_val); | 25560 | return sema.addConstant(elem_ptr_ty, elem_ptr_val); |
| 25552 | } | 25561 | } |
| 25553 | } | 25562 | } |
| ... | @@ -25560,7 +25569,7 @@ fn elemPtrSlice( | ... | @@ -25560,7 +25569,7 @@ fn elemPtrSlice( |
| 25560 | const len_inst = len: { | 25569 | const len_inst = len: { |
| 25561 | if (maybe_undef_slice_val) |slice_val| | 25570 | if (maybe_undef_slice_val) |slice_val| |
| 25562 | if (!slice_val.isUndef()) | 25571 | if (!slice_val.isUndef()) |
| 25563 | break :len try sema.addIntUnsigned(Type.usize, slice_val.sliceLen(sema.mod)); | 25572 | break :len try sema.addIntUnsigned(Type.usize, slice_val.sliceLen(mod)); |
| 25564 | break :len try block.addTyOp(.slice_len, Type.usize, slice); | 25573 | break :len try block.addTyOp(.slice_len, Type.usize, slice); |
| 25565 | }; | 25574 | }; |
| 25566 | const cmp_op: Air.Inst.Tag = if (slice_sent) .cmp_lte else .cmp_lt; | 25575 | const cmp_op: Air.Inst.Tag = if (slice_sent) .cmp_lte else .cmp_lt; |
| ... | @@ -25602,16 +25611,17 @@ const CoerceOpts = struct { | ... | @@ -25602,16 +25611,17 @@ const CoerceOpts = struct { |
| 25602 | 25611 | ||
| 25603 | fn get(info: @This(), sema: *Sema) !?Module.SrcLoc { | 25612 | fn get(info: @This(), sema: *Sema) !?Module.SrcLoc { |
| 25604 | if (info.func_inst == .none) return null; | 25613 | if (info.func_inst == .none) return null; |
| 25614 | const mod = sema.mod; | ||
| 25605 | const fn_decl = (try sema.funcDeclSrc(info.func_inst)) orelse return null; | 25615 | const fn_decl = (try sema.funcDeclSrc(info.func_inst)) orelse return null; |
| 25606 | const param_src = Module.paramSrc(0, sema.gpa, fn_decl, info.param_i); | 25616 | const param_src = Module.paramSrc(0, mod, fn_decl, info.param_i); |
| 25607 | if (param_src == .node_offset_param) { | 25617 | if (param_src == .node_offset_param) { |
| 25608 | return Module.SrcLoc{ | 25618 | return Module.SrcLoc{ |
| 25609 | .file_scope = fn_decl.getFileScope(), | 25619 | .file_scope = fn_decl.getFileScope(mod), |
| 25610 | .parent_decl_node = fn_decl.src_node, | 25620 | .parent_decl_node = fn_decl.src_node, |
| 25611 | .lazy = LazySrcLoc.nodeOffset(param_src.node_offset_param), | 25621 | .lazy = LazySrcLoc.nodeOffset(param_src.node_offset_param), |
| 25612 | }; | 25622 | }; |
| 25613 | } | 25623 | } |
| 25614 | return param_src.toSrcLoc(fn_decl); | 25624 | return param_src.toSrcLoc(fn_decl, mod); |
| 25615 | } | 25625 | } |
| 25616 | } = .{}, | 25626 | } = .{}, |
| 25617 | }; | 25627 | }; |
| ... | @@ -25625,13 +25635,13 @@ fn coerceExtra( | ... | @@ -25625,13 +25635,13 @@ fn coerceExtra( |
| 25625 | opts: CoerceOpts, | 25635 | opts: CoerceOpts, |
| 25626 | ) CoersionError!Air.Inst.Ref { | 25636 | ) CoersionError!Air.Inst.Ref { |
| 25627 | if (dest_ty_unresolved.isGenericPoison()) return inst; | 25637 | if (dest_ty_unresolved.isGenericPoison()) return inst; |
| 25638 | const mod = sema.mod; | ||
| 25628 | const dest_ty_src = inst_src; // TODO better source location | 25639 | const dest_ty_src = inst_src; // TODO better source location |
| 25629 | const dest_ty = try sema.resolveTypeFields(dest_ty_unresolved); | 25640 | const dest_ty = try sema.resolveTypeFields(dest_ty_unresolved); |
| 25630 | const inst_ty = try sema.resolveTypeFields(sema.typeOf(inst)); | 25641 | const inst_ty = try sema.resolveTypeFields(sema.typeOf(inst)); |
| 25631 | const mod = sema.mod; | 25642 | const target = mod.getTarget(); |
| 25632 | const target = sema.mod.getTarget(); | ||
| 25633 | // If the types are the same, we can return the operand. | 25643 | // If the types are the same, we can return the operand. |
| 25634 | if (dest_ty.eql(inst_ty, sema.mod)) | 25644 | if (dest_ty.eql(inst_ty, mod)) |
| 25635 | return inst; | 25645 | return inst; |
| 25636 | 25646 | ||
| 25637 | const arena = sema.arena; | 25647 | const arena = sema.arena; |
| ... | @@ -26254,7 +26264,7 @@ fn coerceExtra( | ... | @@ -26254,7 +26264,7 @@ fn coerceExtra( |
| 26254 | 26264 | ||
| 26255 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 }; | 26265 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 }; |
| 26256 | const src_decl = sema.mod.declPtr(sema.func.?.owner_decl); | 26266 | const src_decl = sema.mod.declPtr(sema.func.?.owner_decl); |
| 26257 | try sema.mod.errNoteNonLazy(ret_ty_src.toSrcLoc(src_decl), msg, "'noreturn' declared here", .{}); | 26267 | try sema.mod.errNoteNonLazy(ret_ty_src.toSrcLoc(src_decl, mod), msg, "'noreturn' declared here", .{}); |
| 26258 | break :msg msg; | 26268 | break :msg msg; |
| 26259 | }; | 26269 | }; |
| 26260 | return sema.failWithOwnedErrorMsg(msg); | 26270 | return sema.failWithOwnedErrorMsg(msg); |
| ... | @@ -26287,9 +26297,9 @@ fn coerceExtra( | ... | @@ -26287,9 +26297,9 @@ fn coerceExtra( |
| 26287 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 }; | 26297 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 }; |
| 26288 | const src_decl = sema.mod.declPtr(sema.func.?.owner_decl); | 26298 | const src_decl = sema.mod.declPtr(sema.func.?.owner_decl); |
| 26289 | if (inst_ty.isError(mod) and !dest_ty.isError(mod)) { | 26299 | if (inst_ty.isError(mod) and !dest_ty.isError(mod)) { |
| 26290 | try sema.mod.errNoteNonLazy(ret_ty_src.toSrcLoc(src_decl), msg, "function cannot return an error", .{}); | 26300 | try sema.mod.errNoteNonLazy(ret_ty_src.toSrcLoc(src_decl, mod), msg, "function cannot return an error", .{}); |
| 26291 | } else { | 26301 | } else { |
| 26292 | try sema.mod.errNoteNonLazy(ret_ty_src.toSrcLoc(src_decl), msg, "function return type declared here", .{}); | 26302 | try sema.mod.errNoteNonLazy(ret_ty_src.toSrcLoc(src_decl, mod), msg, "function return type declared here", .{}); |
| 26293 | } | 26303 | } |
| 26294 | } | 26304 | } |
| 26295 | 26305 | ||
| ... | @@ -27246,7 +27256,7 @@ fn coerceVarArgParam( | ... | @@ -27246,7 +27256,7 @@ fn coerceVarArgParam( |
| 27246 | errdefer msg.destroy(sema.gpa); | 27256 | errdefer msg.destroy(sema.gpa); |
| 27247 | 27257 | ||
| 27248 | const src_decl = sema.mod.declPtr(block.src_decl); | 27258 | const src_decl = sema.mod.declPtr(block.src_decl); |
| 27249 | try sema.explainWhyTypeIsNotExtern(msg, inst_src.toSrcLoc(src_decl), coerced_ty, .param_ty); | 27259 | try sema.explainWhyTypeIsNotExtern(msg, inst_src.toSrcLoc(src_decl, mod), coerced_ty, .param_ty); |
| 27250 | 27260 | ||
| 27251 | try sema.addDeclaredHereNote(msg, coerced_ty); | 27261 | try sema.addDeclaredHereNote(msg, coerced_ty); |
| 27252 | break :msg msg; | 27262 | break :msg msg; |
| ... | @@ -29186,13 +29196,14 @@ fn addReferencedBy( | ... | @@ -29186,13 +29196,14 @@ fn addReferencedBy( |
| 29186 | } | 29196 | } |
| 29187 | 29197 | ||
| 29188 | fn ensureDeclAnalyzed(sema: *Sema, decl_index: Decl.Index) CompileError!void { | 29198 | fn ensureDeclAnalyzed(sema: *Sema, decl_index: Decl.Index) CompileError!void { |
| 29189 | const decl = sema.mod.declPtr(decl_index); | 29199 | const mod = sema.mod; |
| 29200 | const decl = mod.declPtr(decl_index); | ||
| 29190 | if (decl.analysis == .in_progress) { | 29201 | if (decl.analysis == .in_progress) { |
| 29191 | const msg = try Module.ErrorMsg.create(sema.gpa, decl.srcLoc(), "dependency loop detected", .{}); | 29202 | const msg = try Module.ErrorMsg.create(sema.gpa, decl.srcLoc(mod), "dependency loop detected", .{}); |
| 29192 | return sema.failWithOwnedErrorMsg(msg); | 29203 | return sema.failWithOwnedErrorMsg(msg); |
| 29193 | } | 29204 | } |
| 29194 | 29205 | ||
| 29195 | sema.mod.ensureDeclAnalyzed(decl_index) catch |err| { | 29206 | mod.ensureDeclAnalyzed(decl_index) catch |err| { |
| 29196 | if (sema.owner_func) |owner_func| { | 29207 | if (sema.owner_func) |owner_func| { |
| 29197 | owner_func.state = .dependency_failure; | 29208 | owner_func.state = .dependency_failure; |
| 29198 | } else { | 29209 | } else { |
| ... | @@ -31015,12 +31026,12 @@ fn resolvePeerTypes( | ... | @@ -31015,12 +31026,12 @@ fn resolvePeerTypes( |
| 31015 | // At this point, we hit a compile error. We need to recover | 31026 | // At this point, we hit a compile error. We need to recover |
| 31016 | // the source locations. | 31027 | // the source locations. |
| 31017 | const chosen_src = candidate_srcs.resolve( | 31028 | const chosen_src = candidate_srcs.resolve( |
| 31018 | sema.gpa, | 31029 | mod, |
| 31019 | mod.declPtr(block.src_decl), | 31030 | mod.declPtr(block.src_decl), |
| 31020 | chosen_i, | 31031 | chosen_i, |
| 31021 | ); | 31032 | ); |
| 31022 | const candidate_src = candidate_srcs.resolve( | 31033 | const candidate_src = candidate_srcs.resolve( |
| 31023 | sema.gpa, | 31034 | mod, |
| 31024 | mod.declPtr(block.src_decl), | 31035 | mod.declPtr(block.src_decl), |
| 31025 | candidate_i + 1, | 31036 | candidate_i + 1, |
| 31026 | ); | 31037 | ); |
| ... | @@ -31315,7 +31326,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi | ... | @@ -31315,7 +31326,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi |
| 31315 | const decl_arena_allocator = decl.value_arena.?.acquire(gpa, &decl_arena); | 31326 | const decl_arena_allocator = decl.value_arena.?.acquire(gpa, &decl_arena); |
| 31316 | defer decl.value_arena.?.release(&decl_arena); | 31327 | defer decl.value_arena.?.release(&decl_arena); |
| 31317 | 31328 | ||
| 31318 | const zir = struct_obj.namespace.file_scope.zir; | 31329 | const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir; |
| 31319 | const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended; | 31330 | const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended; |
| 31320 | assert(extended.opcode == .struct_decl); | 31331 | assert(extended.opcode == .struct_decl); |
| 31321 | const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small); | 31332 | const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small); |
| ... | @@ -31353,7 +31364,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi | ... | @@ -31353,7 +31364,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi |
| 31353 | .parent = null, | 31364 | .parent = null, |
| 31354 | .sema = &sema, | 31365 | .sema = &sema, |
| 31355 | .src_decl = decl_index, | 31366 | .src_decl = decl_index, |
| 31356 | .namespace = &struct_obj.namespace, | 31367 | .namespace = struct_obj.namespace, |
| 31357 | .wip_capture_scope = wip_captures.scope, | 31368 | .wip_capture_scope = wip_captures.scope, |
| 31358 | .instructions = .{}, | 31369 | .instructions = .{}, |
| 31359 | .inlining = null, | 31370 | .inlining = null, |
| ... | @@ -31399,7 +31410,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi | ... | @@ -31399,7 +31410,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi |
| 31399 | .parent = null, | 31410 | .parent = null, |
| 31400 | .sema = &sema, | 31411 | .sema = &sema, |
| 31401 | .src_decl = decl_index, | 31412 | .src_decl = decl_index, |
| 31402 | .namespace = &struct_obj.namespace, | 31413 | .namespace = struct_obj.namespace, |
| 31403 | .wip_capture_scope = undefined, | 31414 | .wip_capture_scope = undefined, |
| 31404 | .instructions = .{}, | 31415 | .instructions = .{}, |
| 31405 | .inlining = null, | 31416 | .inlining = null, |
| ... | @@ -31522,7 +31533,6 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { | ... | @@ -31522,7 +31533,6 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 31522 | .error_set_single, | 31533 | .error_set_single, |
| 31523 | .error_set_inferred, | 31534 | .error_set_inferred, |
| 31524 | .error_set_merged, | 31535 | .error_set_merged, |
| 31525 | .@"opaque", | ||
| 31526 | .enum_simple, | 31536 | .enum_simple, |
| 31527 | => false, | 31537 | => false, |
| 31528 | 31538 | ||
| ... | @@ -31678,6 +31688,7 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { | ... | @@ -31678,6 +31688,7 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 31678 | }, | 31688 | }, |
| 31679 | .struct_type => @panic("TODO"), | 31689 | .struct_type => @panic("TODO"), |
| 31680 | .union_type => @panic("TODO"), | 31690 | .union_type => @panic("TODO"), |
| 31691 | .opaque_type => false, | ||
| 31681 | 31692 | ||
| 31682 | // values, not types | 31693 | // values, not types |
| 31683 | .simple_value => unreachable, | 31694 | .simple_value => unreachable, |
| ... | @@ -31991,6 +32002,8 @@ fn resolveInferredErrorSet( | ... | @@ -31991,6 +32002,8 @@ fn resolveInferredErrorSet( |
| 31991 | return sema.fail(block, src, "unable to resolve inferred error set", .{}); | 32002 | return sema.fail(block, src, "unable to resolve inferred error set", .{}); |
| 31992 | } | 32003 | } |
| 31993 | 32004 | ||
| 32005 | const mod = sema.mod; | ||
| 32006 | |||
| 31994 | // In order to ensure that all dependencies are properly added to the set, we | 32007 | // In order to ensure that all dependencies are properly added to the set, we |
| 31995 | // need to ensure the function body is analyzed of the inferred error set. | 32008 | // need to ensure the function body is analyzed of the inferred error set. |
| 31996 | // However, in the case of comptime/inline function calls with inferred error sets, | 32009 | // However, in the case of comptime/inline function calls with inferred error sets, |
| ... | @@ -32011,7 +32024,7 @@ fn resolveInferredErrorSet( | ... | @@ -32011,7 +32024,7 @@ fn resolveInferredErrorSet( |
| 32011 | const msg = try sema.errMsg(block, src, "unable to resolve inferred error set of generic function", .{}); | 32024 | const msg = try sema.errMsg(block, src, "unable to resolve inferred error set of generic function", .{}); |
| 32012 | errdefer msg.destroy(sema.gpa); | 32025 | errdefer msg.destroy(sema.gpa); |
| 32013 | 32026 | ||
| 32014 | try sema.mod.errNoteNonLazy(ies_func_owner_decl.srcLoc(), msg, "generic function declared here", .{}); | 32027 | try sema.mod.errNoteNonLazy(ies_func_owner_decl.srcLoc(mod), msg, "generic function declared here", .{}); |
| 32015 | break :msg msg; | 32028 | break :msg msg; |
| 32016 | }; | 32029 | }; |
| 32017 | return sema.failWithOwnedErrorMsg(msg); | 32030 | return sema.failWithOwnedErrorMsg(msg); |
| ... | @@ -32049,7 +32062,7 @@ fn resolveInferredErrorSetTy( | ... | @@ -32049,7 +32062,7 @@ fn resolveInferredErrorSetTy( |
| 32049 | fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void { | 32062 | fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void { |
| 32050 | const gpa = mod.gpa; | 32063 | const gpa = mod.gpa; |
| 32051 | const decl_index = struct_obj.owner_decl; | 32064 | const decl_index = struct_obj.owner_decl; |
| 32052 | const zir = struct_obj.namespace.file_scope.zir; | 32065 | const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir; |
| 32053 | const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended; | 32066 | const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended; |
| 32054 | assert(extended.opcode == .struct_decl); | 32067 | assert(extended.opcode == .struct_decl); |
| 32055 | const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small); | 32068 | const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small); |
| ... | @@ -32123,7 +32136,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -32123,7 +32136,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 32123 | .parent = null, | 32136 | .parent = null, |
| 32124 | .sema = &sema, | 32137 | .sema = &sema, |
| 32125 | .src_decl = decl_index, | 32138 | .src_decl = decl_index, |
| 32126 | .namespace = &struct_obj.namespace, | 32139 | .namespace = struct_obj.namespace, |
| 32127 | .wip_capture_scope = wip_captures.scope, | 32140 | .wip_capture_scope = wip_captures.scope, |
| 32128 | .instructions = .{}, | 32141 | .instructions = .{}, |
| 32129 | .inlining = null, | 32142 | .inlining = null, |
| ... | @@ -32393,7 +32406,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { | ... | @@ -32393,7 +32406,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 32393 | 32406 | ||
| 32394 | const gpa = mod.gpa; | 32407 | const gpa = mod.gpa; |
| 32395 | const decl_index = union_obj.owner_decl; | 32408 | const decl_index = union_obj.owner_decl; |
| 32396 | const zir = union_obj.namespace.file_scope.zir; | 32409 | const zir = mod.namespacePtr(union_obj.namespace).file_scope.zir; |
| 32397 | const extended = zir.instructions.items(.data)[union_obj.zir_index].extended; | 32410 | const extended = zir.instructions.items(.data)[union_obj.zir_index].extended; |
| 32398 | assert(extended.opcode == .union_decl); | 32411 | assert(extended.opcode == .union_decl); |
| 32399 | const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small); | 32412 | const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small); |
| ... | @@ -32463,7 +32476,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { | ... | @@ -32463,7 +32476,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 32463 | .parent = null, | 32476 | .parent = null, |
| 32464 | .sema = &sema, | 32477 | .sema = &sema, |
| 32465 | .src_decl = decl_index, | 32478 | .src_decl = decl_index, |
| 32466 | .namespace = &union_obj.namespace, | 32479 | .namespace = union_obj.namespace, |
| 32467 | .wip_capture_scope = wip_captures.scope, | 32480 | .wip_capture_scope = wip_captures.scope, |
| 32468 | .instructions = .{}, | 32481 | .instructions = .{}, |
| 32469 | .inlining = null, | 32482 | .inlining = null, |
| ... | @@ -32665,7 +32678,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { | ... | @@ -32665,7 +32678,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 32665 | 32678 | ||
| 32666 | const prev_field_index = union_obj.fields.getIndex(field_name).?; | 32679 | const prev_field_index = union_obj.fields.getIndex(field_name).?; |
| 32667 | const prev_field_src = union_obj.fieldSrcLoc(sema.mod, .{ .index = prev_field_index }).lazy; | 32680 | const prev_field_src = union_obj.fieldSrcLoc(sema.mod, .{ .index = prev_field_index }).lazy; |
| 32668 | try sema.mod.errNoteNonLazy(prev_field_src.toSrcLoc(decl), msg, "other field here", .{}); | 32681 | try sema.mod.errNoteNonLazy(prev_field_src.toSrcLoc(decl, mod), msg, "other field here", .{}); |
| 32669 | try sema.errNote(&block_scope, src, msg, "union declared here", .{}); | 32682 | try sema.errNote(&block_scope, src, msg, "union declared here", .{}); |
| 32670 | break :msg msg; | 32683 | break :msg msg; |
| 32671 | }; | 32684 | }; |
| ... | @@ -32929,7 +32942,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { | ... | @@ -32929,7 +32942,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { |
| 32929 | const opt_ty_decl = (try sema.namespaceLookup( | 32942 | const opt_ty_decl = (try sema.namespaceLookup( |
| 32930 | &block, | 32943 | &block, |
| 32931 | src, | 32944 | src, |
| 32932 | builtin_ty.getNamespace().?, | 32945 | builtin_ty.getNamespaceIndex(mod).unwrap().?, |
| 32933 | name, | 32946 | name, |
| 32934 | )) orelse std.debug.panic("lib/std/builtin.zig is corrupt and missing '{s}'", .{name}); | 32947 | )) orelse std.debug.panic("lib/std/builtin.zig is corrupt and missing '{s}'", .{name}); |
| 32935 | return sema.analyzeDeclVal(&block, src, opt_ty_decl); | 32948 | return sema.analyzeDeclVal(&block, src, opt_ty_decl); |
| ... | @@ -32984,7 +32997,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -32984,7 +32997,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 32984 | .function, | 32997 | .function, |
| 32985 | .array_sentinel, | 32998 | .array_sentinel, |
| 32986 | .error_set_inferred, | 32999 | .error_set_inferred, |
| 32987 | .@"opaque", | ||
| 32988 | .anyframe_T, | 33000 | .anyframe_T, |
| 32989 | .pointer, | 33001 | .pointer, |
| 32990 | => return null, | 33002 | => return null, |
| ... | @@ -33123,7 +33135,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -33123,7 +33135,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 33123 | .inferred_alloc_mut => unreachable, | 33135 | .inferred_alloc_mut => unreachable, |
| 33124 | }, | 33136 | }, |
| 33125 | 33137 | ||
| 33126 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 33138 | else => return switch (mod.intern_pool.indexToKey(ty.ip_index)) { |
| 33127 | .int_type => |int_type| { | 33139 | .int_type => |int_type| { |
| 33128 | if (int_type.bits == 0) { | 33140 | if (int_type.bits == 0) { |
| 33129 | return try mod.intValue(ty, 0); | 33141 | return try mod.intValue(ty, 0); |
| ... | @@ -33131,7 +33143,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -33131,7 +33143,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 33131 | return null; | 33143 | return null; |
| 33132 | } | 33144 | } |
| 33133 | }, | 33145 | }, |
| 33134 | .ptr_type => return null, | 33146 | .ptr_type => null, |
| 33135 | .array_type => |array_type| { | 33147 | .array_type => |array_type| { |
| 33136 | if (array_type.len == 0) | 33148 | if (array_type.len == 0) |
| 33137 | return Value.initTag(.empty_array); | 33149 | return Value.initTag(.empty_array); |
| ... | @@ -33152,7 +33164,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -33152,7 +33164,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 33152 | return null; | 33164 | return null; |
| 33153 | } | 33165 | } |
| 33154 | }, | 33166 | }, |
| 33155 | .error_union_type => return null, | 33167 | .error_union_type => null, |
| 33156 | .simple_type => |t| switch (t) { | 33168 | .simple_type => |t| switch (t) { |
| 33157 | .f16, | 33169 | .f16, |
| 33158 | .f32, | 33170 | .f32, |
| ... | @@ -33190,18 +33202,19 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -33190,18 +33202,19 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 33190 | .export_options, | 33202 | .export_options, |
| 33191 | .extern_options, | 33203 | .extern_options, |
| 33192 | .type_info, | 33204 | .type_info, |
| 33193 | => return null, | 33205 | => null, |
| 33194 | 33206 | ||
| 33195 | .void => return Value.void, | 33207 | .void => Value.void, |
| 33196 | .noreturn => return Value.@"unreachable", | 33208 | .noreturn => Value.@"unreachable", |
| 33197 | .null => return Value.null, | 33209 | .null => Value.null, |
| 33198 | .undefined => return Value.undef, | 33210 | .undefined => Value.undef, |
| 33199 | 33211 | ||
| 33200 | .generic_poison => return error.GenericPoison, | 33212 | .generic_poison => return error.GenericPoison, |
| 33201 | .var_args_param => unreachable, | 33213 | .var_args_param => unreachable, |
| 33202 | }, | 33214 | }, |
| 33203 | .struct_type => @panic("TODO"), | 33215 | .struct_type => @panic("TODO"), |
| 33204 | .union_type => @panic("TODO"), | 33216 | .union_type => @panic("TODO"), |
| 33217 | .opaque_type => null, | ||
| 33205 | 33218 | ||
| 33206 | // values, not types | 33219 | // values, not types |
| 33207 | .simple_value => unreachable, | 33220 | .simple_value => unreachable, |
| ... | @@ -33606,7 +33619,6 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { | ... | @@ -33606,7 +33619,6 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 33606 | .error_set_single, | 33619 | .error_set_single, |
| 33607 | .error_set_inferred, | 33620 | .error_set_inferred, |
| 33608 | .error_set_merged, | 33621 | .error_set_merged, |
| 33609 | .@"opaque", | ||
| 33610 | .enum_simple, | 33622 | .enum_simple, |
| 33611 | => false, | 33623 | => false, |
| 33612 | 33624 | ||
| ... | @@ -33772,6 +33784,7 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { | ... | @@ -33772,6 +33784,7 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 33772 | }, | 33784 | }, |
| 33773 | .struct_type => @panic("TODO"), | 33785 | .struct_type => @panic("TODO"), |
| 33774 | .union_type => @panic("TODO"), | 33786 | .union_type => @panic("TODO"), |
| 33787 | .opaque_type => false, | ||
| 33775 | 33788 | ||
| 33776 | // values, not types | 33789 | // values, not types |
| 33777 | .simple_value => unreachable, | 33790 | .simple_value => unreachable, |
src/arch/wasm/CodeGen.zig+3-2| ... | @@ -764,8 +764,9 @@ pub fn deinit(func: *CodeGen) void { | ... | @@ -764,8 +764,9 @@ pub fn deinit(func: *CodeGen) void { |
| 764 | 764 | ||
| 765 | /// Sets `err_msg` on `CodeGen` and returns `error.CodegenFail` which is caught in link/Wasm.zig | 765 | /// Sets `err_msg` on `CodeGen` and returns `error.CodegenFail` which is caught in link/Wasm.zig |
| 766 | fn fail(func: *CodeGen, comptime fmt: []const u8, args: anytype) InnerError { | 766 | fn fail(func: *CodeGen, comptime fmt: []const u8, args: anytype) InnerError { |
| 767 | const mod = func.bin_file.base.options.module.?; | ||
| 767 | const src = LazySrcLoc.nodeOffset(0); | 768 | const src = LazySrcLoc.nodeOffset(0); |
| 768 | const src_loc = src.toSrcLoc(func.decl); | 769 | const src_loc = src.toSrcLoc(func.decl, mod); |
| 769 | func.err_msg = try Module.ErrorMsg.create(func.gpa, src_loc, fmt, args); | 770 | func.err_msg = try Module.ErrorMsg.create(func.gpa, src_loc, fmt, args); |
| 770 | return error.CodegenFail; | 771 | return error.CodegenFail; |
| 771 | } | 772 | } |
| ... | @@ -6799,7 +6800,7 @@ fn airTagName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { | ... | @@ -6799,7 +6800,7 @@ fn airTagName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6799 | 6800 | ||
| 6800 | fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { | 6801 | fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { |
| 6801 | const mod = func.bin_file.base.options.module.?; | 6802 | const mod = func.bin_file.base.options.module.?; |
| 6802 | const enum_decl_index = enum_ty.getOwnerDecl(); | 6803 | const enum_decl_index = enum_ty.getOwnerDecl(mod); |
| 6803 | 6804 | ||
| 6804 | var arena_allocator = std.heap.ArenaAllocator.init(func.gpa); | 6805 | var arena_allocator = std.heap.ArenaAllocator.init(func.gpa); |
| 6805 | defer arena_allocator.deinit(); | 6806 | defer arena_allocator.deinit(); |
src/arch/wasm/Emit.zig+1-1| ... | @@ -254,7 +254,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { | ... | @@ -254,7 +254,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { |
| 254 | @setCold(true); | 254 | @setCold(true); |
| 255 | std.debug.assert(emit.error_msg == null); | 255 | std.debug.assert(emit.error_msg == null); |
| 256 | const mod = emit.bin_file.base.options.module.?; | 256 | const mod = emit.bin_file.base.options.module.?; |
| 257 | emit.error_msg = try Module.ErrorMsg.create(emit.bin_file.base.allocator, mod.declPtr(emit.decl_index).srcLoc(), format, args); | 257 | emit.error_msg = try Module.ErrorMsg.create(emit.bin_file.base.allocator, mod.declPtr(emit.decl_index).srcLoc(mod), format, args); |
| 258 | return error.EmitFail; | 258 | return error.EmitFail; |
| 259 | } | 259 | } |
| 260 | 260 |
src/arch/x86_64/CodeGen.zig+9-6| ... | @@ -112,10 +112,10 @@ const Owner = union(enum) { | ... | @@ -112,10 +112,10 @@ const Owner = union(enum) { |
| 112 | mod_fn: *const Module.Fn, | 112 | mod_fn: *const Module.Fn, |
| 113 | lazy_sym: link.File.LazySymbol, | 113 | lazy_sym: link.File.LazySymbol, |
| 114 | 114 | ||
| 115 | fn getDecl(owner: Owner) Module.Decl.Index { | 115 | fn getDecl(owner: Owner, mod: *Module) Module.Decl.Index { |
| 116 | return switch (owner) { | 116 | return switch (owner) { |
| 117 | .mod_fn => |mod_fn| mod_fn.owner_decl, | 117 | .mod_fn => |mod_fn| mod_fn.owner_decl, |
| 118 | .lazy_sym => |lazy_sym| lazy_sym.ty.getOwnerDecl(), | 118 | .lazy_sym => |lazy_sym| lazy_sym.ty.getOwnerDecl(mod), |
| 119 | }; | 119 | }; |
| 120 | } | 120 | } |
| 121 | 121 | ||
| ... | @@ -7926,6 +7926,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -7926,6 +7926,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void { |
| 7926 | } | 7926 | } |
| 7927 | 7927 | ||
| 7928 | fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void { | 7928 | fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void { |
| 7929 | const mod = self.bin_file.options.module.?; | ||
| 7929 | switch (self.debug_output) { | 7930 | switch (self.debug_output) { |
| 7930 | .dwarf => |dw| { | 7931 | .dwarf => |dw| { |
| 7931 | const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (mcv) { | 7932 | const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (mcv) { |
| ... | @@ -7944,7 +7945,7 @@ fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void { | ... | @@ -7944,7 +7945,7 @@ fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void { |
| 7944 | // TODO: this might need adjusting like the linkers do. | 7945 | // TODO: this might need adjusting like the linkers do. |
| 7945 | // Instead of flattening the owner and passing Decl.Index here we may | 7946 | // Instead of flattening the owner and passing Decl.Index here we may |
| 7946 | // want to special case LazySymbol in DWARF linker too. | 7947 | // want to special case LazySymbol in DWARF linker too. |
| 7947 | try dw.genArgDbgInfo(name, ty, self.owner.getDecl(), loc); | 7948 | try dw.genArgDbgInfo(name, ty, self.owner.getDecl(mod), loc); |
| 7948 | }, | 7949 | }, |
| 7949 | .plan9 => {}, | 7950 | .plan9 => {}, |
| 7950 | .none => {}, | 7951 | .none => {}, |
| ... | @@ -7958,6 +7959,7 @@ fn genVarDbgInfo( | ... | @@ -7958,6 +7959,7 @@ fn genVarDbgInfo( |
| 7958 | mcv: MCValue, | 7959 | mcv: MCValue, |
| 7959 | name: [:0]const u8, | 7960 | name: [:0]const u8, |
| 7960 | ) !void { | 7961 | ) !void { |
| 7962 | const mod = self.bin_file.options.module.?; | ||
| 7961 | const is_ptr = switch (tag) { | 7963 | const is_ptr = switch (tag) { |
| 7962 | .dbg_var_ptr => true, | 7964 | .dbg_var_ptr => true, |
| 7963 | .dbg_var_val => false, | 7965 | .dbg_var_val => false, |
| ... | @@ -7988,7 +7990,7 @@ fn genVarDbgInfo( | ... | @@ -7988,7 +7990,7 @@ fn genVarDbgInfo( |
| 7988 | // TODO: this might need adjusting like the linkers do. | 7990 | // TODO: this might need adjusting like the linkers do. |
| 7989 | // Instead of flattening the owner and passing Decl.Index here we may | 7991 | // Instead of flattening the owner and passing Decl.Index here we may |
| 7990 | // want to special case LazySymbol in DWARF linker too. | 7992 | // want to special case LazySymbol in DWARF linker too. |
| 7991 | try dw.genVarDbgInfo(name, ty, self.owner.getDecl(), is_ptr, loc); | 7993 | try dw.genVarDbgInfo(name, ty, self.owner.getDecl(mod), is_ptr, loc); |
| 7992 | }, | 7994 | }, |
| 7993 | .plan9 => {}, | 7995 | .plan9 => {}, |
| 7994 | .none => {}, | 7996 | .none => {}, |
| ... | @@ -10936,7 +10938,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -10936,7 +10938,7 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void { |
| 10936 | try self.genLazySymbolRef( | 10938 | try self.genLazySymbolRef( |
| 10937 | .call, | 10939 | .call, |
| 10938 | .rax, | 10940 | .rax, |
| 10939 | link.File.LazySymbol.initDecl(.code, enum_ty.getOwnerDecl(), mod), | 10941 | link.File.LazySymbol.initDecl(.code, enum_ty.getOwnerDecl(mod), mod), |
| 10940 | ); | 10942 | ); |
| 10941 | 10943 | ||
| 10942 | return self.finishAir(inst, dst_mcv, .{ un_op, .none, .none }); | 10944 | return self.finishAir(inst, dst_mcv, .{ un_op, .none, .none }); |
| ... | @@ -11651,7 +11653,8 @@ fn limitImmediateType(self: *Self, operand: Air.Inst.Ref, comptime T: type) !MCV | ... | @@ -11651,7 +11653,8 @@ fn limitImmediateType(self: *Self, operand: Air.Inst.Ref, comptime T: type) !MCV |
| 11651 | } | 11653 | } |
| 11652 | 11654 | ||
| 11653 | fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue { | 11655 | fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue { |
| 11654 | return switch (try codegen.genTypedValue(self.bin_file, self.src_loc, arg_tv, self.owner.getDecl())) { | 11656 | const mod = self.bin_file.options.module.?; |
| 11657 | return switch (try codegen.genTypedValue(self.bin_file, self.src_loc, arg_tv, self.owner.getDecl(mod))) { | ||
| 11655 | .mcv => |mcv| switch (mcv) { | 11658 | .mcv => |mcv| switch (mcv) { |
| 11656 | .none => .none, | 11659 | .none => .none, |
| 11657 | .undef => .undef, | 11660 | .undef => .undef, |
src/codegen/c.zig+4-2| ... | @@ -524,8 +524,9 @@ pub const DeclGen = struct { | ... | @@ -524,8 +524,9 @@ pub const DeclGen = struct { |
| 524 | 524 | ||
| 525 | fn fail(dg: *DeclGen, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } { | 525 | fn fail(dg: *DeclGen, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } { |
| 526 | @setCold(true); | 526 | @setCold(true); |
| 527 | const mod = dg.module; | ||
| 527 | const src = LazySrcLoc.nodeOffset(0); | 528 | const src = LazySrcLoc.nodeOffset(0); |
| 528 | const src_loc = src.toSrcLoc(dg.decl.?); | 529 | const src_loc = src.toSrcLoc(dg.decl.?, mod); |
| 529 | dg.error_msg = try Module.ErrorMsg.create(dg.gpa, src_loc, format, args); | 530 | dg.error_msg = try Module.ErrorMsg.create(dg.gpa, src_loc, format, args); |
| 530 | return error.AnalysisFail; | 531 | return error.AnalysisFail; |
| 531 | } | 532 | } |
| ... | @@ -6484,6 +6485,7 @@ fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6484,6 +6485,7 @@ fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6484 | } | 6485 | } |
| 6485 | 6486 | ||
| 6486 | fn airTagName(f: *Function, inst: Air.Inst.Index) !CValue { | 6487 | fn airTagName(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6488 | const mod = f.object.dg.module; | ||
| 6487 | const un_op = f.air.instructions.items(.data)[inst].un_op; | 6489 | const un_op = f.air.instructions.items(.data)[inst].un_op; |
| 6488 | 6490 | ||
| 6489 | const inst_ty = f.typeOfIndex(inst); | 6491 | const inst_ty = f.typeOfIndex(inst); |
| ... | @@ -6495,7 +6497,7 @@ fn airTagName(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6495,7 +6497,7 @@ fn airTagName(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6495 | const local = try f.allocLocal(inst, inst_ty); | 6497 | const local = try f.allocLocal(inst, inst_ty); |
| 6496 | try f.writeCValue(writer, local, .Other); | 6498 | try f.writeCValue(writer, local, .Other); |
| 6497 | try writer.print(" = {s}(", .{ | 6499 | try writer.print(" = {s}(", .{ |
| 6498 | try f.getLazyFnName(.{ .tag_name = enum_ty.getOwnerDecl() }, .{ .tag_name = enum_ty }), | 6500 | try f.getLazyFnName(.{ .tag_name = enum_ty.getOwnerDecl(mod) }, .{ .tag_name = enum_ty }), |
| 6499 | }); | 6501 | }); |
| 6500 | try f.writeCValue(writer, operand, .Other); | 6502 | try f.writeCValue(writer, operand, .Other); |
| 6501 | try writer.writeAll(");\n"); | 6503 | try writer.writeAll(");\n"); |
src/codegen/c/type.zig+4-4| ... | @@ -1538,7 +1538,7 @@ pub const CType = extern union { | ... | @@ -1538,7 +1538,7 @@ pub const CType = extern union { |
| 1538 | .forward, .forward_parameter => { | 1538 | .forward, .forward_parameter => { |
| 1539 | self.storage = .{ .fwd = .{ | 1539 | self.storage = .{ .fwd = .{ |
| 1540 | .base = .{ .tag = if (is_struct) .fwd_struct else .fwd_union }, | 1540 | .base = .{ .tag = if (is_struct) .fwd_struct else .fwd_union }, |
| 1541 | .data = ty.getOwnerDecl(), | 1541 | .data = ty.getOwnerDecl(mod), |
| 1542 | } }; | 1542 | } }; |
| 1543 | self.value = .{ .cty = initPayload(&self.storage.fwd) }; | 1543 | self.value = .{ .cty = initPayload(&self.storage.fwd) }; |
| 1544 | }, | 1544 | }, |
| ... | @@ -1985,7 +1985,7 @@ pub const CType = extern union { | ... | @@ -1985,7 +1985,7 @@ pub const CType = extern union { |
| 1985 | const unnamed_pl = try arena.create(Payload.Unnamed); | 1985 | const unnamed_pl = try arena.create(Payload.Unnamed); |
| 1986 | unnamed_pl.* = .{ .base = .{ .tag = t }, .data = .{ | 1986 | unnamed_pl.* = .{ .base = .{ .tag = t }, .data = .{ |
| 1987 | .fields = fields_pl, | 1987 | .fields = fields_pl, |
| 1988 | .owner_decl = ty.getOwnerDecl(), | 1988 | .owner_decl = ty.getOwnerDecl(mod), |
| 1989 | .id = if (ty.unionTagTypeSafety()) |_| 0 else unreachable, | 1989 | .id = if (ty.unionTagTypeSafety()) |_| 0 else unreachable, |
| 1990 | } }; | 1990 | } }; |
| 1991 | return initPayload(unnamed_pl); | 1991 | return initPayload(unnamed_pl); |
| ... | @@ -2124,7 +2124,7 @@ pub const CType = extern union { | ... | @@ -2124,7 +2124,7 @@ pub const CType = extern union { |
| 2124 | .forward, .forward_parameter, .complete, .parameter, .global => unreachable, | 2124 | .forward, .forward_parameter, .complete, .parameter, .global => unreachable, |
| 2125 | .payload => if (ty.unionTagTypeSafety()) |_| { | 2125 | .payload => if (ty.unionTagTypeSafety()) |_| { |
| 2126 | const data = cty.cast(Payload.Unnamed).?.data; | 2126 | const data = cty.cast(Payload.Unnamed).?.data; |
| 2127 | return ty.getOwnerDecl() == data.owner_decl and data.id == 0; | 2127 | return ty.getOwnerDecl(mod) == data.owner_decl and data.id == 0; |
| 2128 | } else unreachable, | 2128 | } else unreachable, |
| 2129 | }, | 2129 | }, |
| 2130 | 2130 | ||
| ... | @@ -2242,7 +2242,7 @@ pub const CType = extern union { | ... | @@ -2242,7 +2242,7 @@ pub const CType = extern union { |
| 2242 | => switch (self.kind) { | 2242 | => switch (self.kind) { |
| 2243 | .forward, .forward_parameter, .complete, .parameter, .global => unreachable, | 2243 | .forward, .forward_parameter, .complete, .parameter, .global => unreachable, |
| 2244 | .payload => if (ty.unionTagTypeSafety()) |_| { | 2244 | .payload => if (ty.unionTagTypeSafety()) |_| { |
| 2245 | autoHash(hasher, ty.getOwnerDecl()); | 2245 | autoHash(hasher, ty.getOwnerDecl(mod)); |
| 2246 | autoHash(hasher, @as(u32, 0)); | 2246 | autoHash(hasher, @as(u32, 0)); |
| 2247 | } else unreachable, | 2247 | } else unreachable, |
| 2248 | }, | 2248 | }, |
src/codegen/llvm.zig+33-33| ... | @@ -1177,7 +1177,7 @@ pub const Object = struct { | ... | @@ -1177,7 +1177,7 @@ pub const Object = struct { |
| 1177 | var di_scope: ?*llvm.DIScope = null; | 1177 | var di_scope: ?*llvm.DIScope = null; |
| 1178 | 1178 | ||
| 1179 | if (dg.object.di_builder) |dib| { | 1179 | if (dg.object.di_builder) |dib| { |
| 1180 | di_file = try dg.object.getDIFile(gpa, decl.src_namespace.file_scope); | 1180 | di_file = try dg.object.getDIFile(gpa, mod.namespacePtr(decl.src_namespace).file_scope); |
| 1181 | 1181 | ||
| 1182 | const line_number = decl.src_line + 1; | 1182 | const line_number = decl.src_line + 1; |
| 1183 | const is_internal_linkage = decl.val.tag() != .extern_fn and | 1183 | const is_internal_linkage = decl.val.tag() != .extern_fn and |
| ... | @@ -1505,7 +1505,7 @@ pub const Object = struct { | ... | @@ -1505,7 +1505,7 @@ pub const Object = struct { |
| 1505 | return di_type; | 1505 | return di_type; |
| 1506 | }, | 1506 | }, |
| 1507 | .Enum => { | 1507 | .Enum => { |
| 1508 | const owner_decl_index = ty.getOwnerDecl(); | 1508 | const owner_decl_index = ty.getOwnerDecl(mod); |
| 1509 | const owner_decl = o.module.declPtr(owner_decl_index); | 1509 | const owner_decl = o.module.declPtr(owner_decl_index); |
| 1510 | 1510 | ||
| 1511 | if (!ty.hasRuntimeBitsIgnoreComptime(mod)) { | 1511 | if (!ty.hasRuntimeBitsIgnoreComptime(mod)) { |
| ... | @@ -1558,7 +1558,7 @@ pub const Object = struct { | ... | @@ -1558,7 +1558,7 @@ pub const Object = struct { |
| 1558 | @panic("TODO implement bigint debug enumerators to llvm int for 32-bit compiler builds"); | 1558 | @panic("TODO implement bigint debug enumerators to llvm int for 32-bit compiler builds"); |
| 1559 | } | 1559 | } |
| 1560 | 1560 | ||
| 1561 | const di_file = try o.getDIFile(gpa, owner_decl.src_namespace.file_scope); | 1561 | const di_file = try o.getDIFile(gpa, mod.namespacePtr(owner_decl.src_namespace).file_scope); |
| 1562 | const di_scope = try o.namespaceToDebugScope(owner_decl.src_namespace); | 1562 | const di_scope = try o.namespaceToDebugScope(owner_decl.src_namespace); |
| 1563 | 1563 | ||
| 1564 | const name = try ty.nameAlloc(gpa, o.module); | 1564 | const name = try ty.nameAlloc(gpa, o.module); |
| ... | @@ -1737,13 +1737,13 @@ pub const Object = struct { | ... | @@ -1737,13 +1737,13 @@ pub const Object = struct { |
| 1737 | } | 1737 | } |
| 1738 | const name = try ty.nameAlloc(gpa, o.module); | 1738 | const name = try ty.nameAlloc(gpa, o.module); |
| 1739 | defer gpa.free(name); | 1739 | defer gpa.free(name); |
| 1740 | const owner_decl_index = ty.getOwnerDecl(); | 1740 | const owner_decl_index = ty.getOwnerDecl(mod); |
| 1741 | const owner_decl = o.module.declPtr(owner_decl_index); | 1741 | const owner_decl = o.module.declPtr(owner_decl_index); |
| 1742 | const opaque_di_ty = dib.createForwardDeclType( | 1742 | const opaque_di_ty = dib.createForwardDeclType( |
| 1743 | DW.TAG.structure_type, | 1743 | DW.TAG.structure_type, |
| 1744 | name, | 1744 | name, |
| 1745 | try o.namespaceToDebugScope(owner_decl.src_namespace), | 1745 | try o.namespaceToDebugScope(owner_decl.src_namespace), |
| 1746 | try o.getDIFile(gpa, owner_decl.src_namespace.file_scope), | 1746 | try o.getDIFile(gpa, mod.namespacePtr(owner_decl.src_namespace).file_scope), |
| 1747 | owner_decl.src_node + 1, | 1747 | owner_decl.src_node + 1, |
| 1748 | ); | 1748 | ); |
| 1749 | // The recursive call to `lowerDebugType` va `namespaceToDebugScope` | 1749 | // The recursive call to `lowerDebugType` va `namespaceToDebugScope` |
| ... | @@ -2085,7 +2085,7 @@ pub const Object = struct { | ... | @@ -2085,7 +2085,7 @@ pub const Object = struct { |
| 2085 | // into. Therefore we can satisfy this by making an empty namespace, | 2085 | // into. Therefore we can satisfy this by making an empty namespace, |
| 2086 | // rather than changing the frontend to unnecessarily resolve the | 2086 | // rather than changing the frontend to unnecessarily resolve the |
| 2087 | // struct field types. | 2087 | // struct field types. |
| 2088 | const owner_decl_index = ty.getOwnerDecl(); | 2088 | const owner_decl_index = ty.getOwnerDecl(mod); |
| 2089 | const struct_di_ty = try o.makeEmptyNamespaceDIType(owner_decl_index); | 2089 | const struct_di_ty = try o.makeEmptyNamespaceDIType(owner_decl_index); |
| 2090 | dib.replaceTemporary(fwd_decl, struct_di_ty); | 2090 | dib.replaceTemporary(fwd_decl, struct_di_ty); |
| 2091 | // The recursive call to `lowerDebugType` via `makeEmptyNamespaceDIType` | 2091 | // The recursive call to `lowerDebugType` via `makeEmptyNamespaceDIType` |
| ... | @@ -2096,7 +2096,7 @@ pub const Object = struct { | ... | @@ -2096,7 +2096,7 @@ pub const Object = struct { |
| 2096 | } | 2096 | } |
| 2097 | 2097 | ||
| 2098 | if (!ty.hasRuntimeBitsIgnoreComptime(mod)) { | 2098 | if (!ty.hasRuntimeBitsIgnoreComptime(mod)) { |
| 2099 | const owner_decl_index = ty.getOwnerDecl(); | 2099 | const owner_decl_index = ty.getOwnerDecl(mod); |
| 2100 | const struct_di_ty = try o.makeEmptyNamespaceDIType(owner_decl_index); | 2100 | const struct_di_ty = try o.makeEmptyNamespaceDIType(owner_decl_index); |
| 2101 | dib.replaceTemporary(fwd_decl, struct_di_ty); | 2101 | dib.replaceTemporary(fwd_decl, struct_di_ty); |
| 2102 | // The recursive call to `lowerDebugType` via `makeEmptyNamespaceDIType` | 2102 | // The recursive call to `lowerDebugType` via `makeEmptyNamespaceDIType` |
| ... | @@ -2162,7 +2162,7 @@ pub const Object = struct { | ... | @@ -2162,7 +2162,7 @@ pub const Object = struct { |
| 2162 | }, | 2162 | }, |
| 2163 | .Union => { | 2163 | .Union => { |
| 2164 | const compile_unit_scope = o.di_compile_unit.?.toScope(); | 2164 | const compile_unit_scope = o.di_compile_unit.?.toScope(); |
| 2165 | const owner_decl_index = ty.getOwnerDecl(); | 2165 | const owner_decl_index = ty.getOwnerDecl(mod); |
| 2166 | 2166 | ||
| 2167 | const name = try ty.nameAlloc(gpa, o.module); | 2167 | const name = try ty.nameAlloc(gpa, o.module); |
| 2168 | defer gpa.free(name); | 2168 | defer gpa.free(name); |
| ... | @@ -2395,8 +2395,10 @@ pub const Object = struct { | ... | @@ -2395,8 +2395,10 @@ pub const Object = struct { |
| 2395 | } | 2395 | } |
| 2396 | } | 2396 | } |
| 2397 | 2397 | ||
| 2398 | fn namespaceToDebugScope(o: *Object, namespace: *const Module.Namespace) !*llvm.DIScope { | 2398 | fn namespaceToDebugScope(o: *Object, namespace_index: Module.Namespace.Index) !*llvm.DIScope { |
| 2399 | if (namespace.parent == null) { | 2399 | const mod = o.module; |
| 2400 | const namespace = mod.namespacePtr(namespace_index); | ||
| 2401 | if (namespace.parent == .none) { | ||
| 2400 | const di_file = try o.getDIFile(o.gpa, namespace.file_scope); | 2402 | const di_file = try o.getDIFile(o.gpa, namespace.file_scope); |
| 2401 | return di_file.toScope(); | 2403 | return di_file.toScope(); |
| 2402 | } | 2404 | } |
| ... | @@ -2408,12 +2410,13 @@ pub const Object = struct { | ... | @@ -2408,12 +2410,13 @@ pub const Object = struct { |
| 2408 | /// Assertion `!isa<DIType>(Scope) && "shouldn't make a namespace scope for a type"' | 2410 | /// Assertion `!isa<DIType>(Scope) && "shouldn't make a namespace scope for a type"' |
| 2409 | /// when targeting CodeView (Windows). | 2411 | /// when targeting CodeView (Windows). |
| 2410 | fn makeEmptyNamespaceDIType(o: *Object, decl_index: Module.Decl.Index) !*llvm.DIType { | 2412 | fn makeEmptyNamespaceDIType(o: *Object, decl_index: Module.Decl.Index) !*llvm.DIType { |
| 2411 | const decl = o.module.declPtr(decl_index); | 2413 | const mod = o.module; |
| 2414 | const decl = mod.declPtr(decl_index); | ||
| 2412 | const fields: [0]*llvm.DIType = .{}; | 2415 | const fields: [0]*llvm.DIType = .{}; |
| 2413 | return o.di_builder.?.createStructType( | 2416 | return o.di_builder.?.createStructType( |
| 2414 | try o.namespaceToDebugScope(decl.src_namespace), | 2417 | try o.namespaceToDebugScope(decl.src_namespace), |
| 2415 | decl.name, // TODO use fully qualified name | 2418 | decl.name, // TODO use fully qualified name |
| 2416 | try o.getDIFile(o.gpa, decl.src_namespace.file_scope), | 2419 | try o.getDIFile(o.gpa, mod.namespacePtr(decl.src_namespace).file_scope), |
| 2417 | decl.src_line + 1, | 2420 | decl.src_line + 1, |
| 2418 | 0, // size in bits | 2421 | 0, // size in bits |
| 2419 | 0, // align in bits | 2422 | 0, // align in bits |
| ... | @@ -2434,14 +2437,14 @@ pub const Object = struct { | ... | @@ -2434,14 +2437,14 @@ pub const Object = struct { |
| 2434 | const std_file = (mod.importPkg(std_pkg) catch unreachable).file; | 2437 | const std_file = (mod.importPkg(std_pkg) catch unreachable).file; |
| 2435 | 2438 | ||
| 2436 | const builtin_str: []const u8 = "builtin"; | 2439 | const builtin_str: []const u8 = "builtin"; |
| 2437 | const std_namespace = mod.declPtr(std_file.root_decl.unwrap().?).src_namespace; | 2440 | const std_namespace = mod.namespacePtr(mod.declPtr(std_file.root_decl.unwrap().?).src_namespace); |
| 2438 | const builtin_decl = std_namespace.decls | 2441 | const builtin_decl = std_namespace.decls |
| 2439 | .getKeyAdapted(builtin_str, Module.DeclAdapter{ .mod = mod }).?; | 2442 | .getKeyAdapted(builtin_str, Module.DeclAdapter{ .mod = mod }).?; |
| 2440 | 2443 | ||
| 2441 | const stack_trace_str: []const u8 = "StackTrace"; | 2444 | const stack_trace_str: []const u8 = "StackTrace"; |
| 2442 | // buffer is only used for int_type, `builtin` is a struct. | 2445 | // buffer is only used for int_type, `builtin` is a struct. |
| 2443 | const builtin_ty = mod.declPtr(builtin_decl).val.toType(); | 2446 | const builtin_ty = mod.declPtr(builtin_decl).val.toType(); |
| 2444 | const builtin_namespace = builtin_ty.getNamespace().?; | 2447 | const builtin_namespace = builtin_ty.getNamespace(mod).?; |
| 2445 | const stack_trace_decl_index = builtin_namespace.decls | 2448 | const stack_trace_decl_index = builtin_namespace.decls |
| 2446 | .getKeyAdapted(stack_trace_str, Module.DeclAdapter{ .mod = mod }).?; | 2449 | .getKeyAdapted(stack_trace_str, Module.DeclAdapter{ .mod = mod }).?; |
| 2447 | const stack_trace_decl = mod.declPtr(stack_trace_decl_index); | 2450 | const stack_trace_decl = mod.declPtr(stack_trace_decl_index); |
| ... | @@ -2464,7 +2467,8 @@ pub const DeclGen = struct { | ... | @@ -2464,7 +2467,8 @@ pub const DeclGen = struct { |
| 2464 | fn todo(self: *DeclGen, comptime format: []const u8, args: anytype) Error { | 2467 | fn todo(self: *DeclGen, comptime format: []const u8, args: anytype) Error { |
| 2465 | @setCold(true); | 2468 | @setCold(true); |
| 2466 | assert(self.err_msg == null); | 2469 | assert(self.err_msg == null); |
| 2467 | const src_loc = LazySrcLoc.nodeOffset(0).toSrcLoc(self.decl); | 2470 | const mod = self.module; |
| 2471 | const src_loc = LazySrcLoc.nodeOffset(0).toSrcLoc(self.decl, mod); | ||
| 2468 | self.err_msg = try Module.ErrorMsg.create(self.gpa, src_loc, "TODO (LLVM): " ++ format, args); | 2472 | self.err_msg = try Module.ErrorMsg.create(self.gpa, src_loc, "TODO (LLVM): " ++ format, args); |
| 2469 | return error.CodegenFail; | 2473 | return error.CodegenFail; |
| 2470 | } | 2474 | } |
| ... | @@ -2536,7 +2540,7 @@ pub const DeclGen = struct { | ... | @@ -2536,7 +2540,7 @@ pub const DeclGen = struct { |
| 2536 | } | 2540 | } |
| 2537 | 2541 | ||
| 2538 | if (dg.object.di_builder) |dib| { | 2542 | if (dg.object.di_builder) |dib| { |
| 2539 | const di_file = try dg.object.getDIFile(dg.gpa, decl.src_namespace.file_scope); | 2543 | const di_file = try dg.object.getDIFile(dg.gpa, mod.namespacePtr(decl.src_namespace).file_scope); |
| 2540 | 2544 | ||
| 2541 | const line_number = decl.src_line + 1; | 2545 | const line_number = decl.src_line + 1; |
| 2542 | const is_internal_linkage = !dg.module.decl_exports.contains(decl_index); | 2546 | const is_internal_linkage = !dg.module.decl_exports.contains(decl_index); |
| ... | @@ -2837,15 +2841,11 @@ pub const DeclGen = struct { | ... | @@ -2837,15 +2841,11 @@ pub const DeclGen = struct { |
| 2837 | .Opaque => { | 2841 | .Opaque => { |
| 2838 | if (t.ip_index == .anyopaque_type) return dg.context.intType(8); | 2842 | if (t.ip_index == .anyopaque_type) return dg.context.intType(8); |
| 2839 | 2843 | ||
| 2840 | const gop = try dg.object.type_map.getOrPutContext(gpa, t, .{ .mod = dg.module }); | 2844 | const gop = try dg.object.type_map.getOrPutContext(gpa, t, .{ .mod = mod }); |
| 2841 | if (gop.found_existing) return gop.value_ptr.*; | 2845 | if (gop.found_existing) return gop.value_ptr.*; |
| 2842 | 2846 | ||
| 2843 | // The Type memory is ephemeral; since we want to store a longer-lived | 2847 | const opaque_type = mod.intern_pool.indexToKey(t.ip_index).opaque_type; |
| 2844 | // reference, we need to copy it here. | 2848 | const name = try mod.opaqueFullyQualifiedName(opaque_type); |
| 2845 | gop.key_ptr.* = try t.copy(dg.object.type_map_arena.allocator()); | ||
| 2846 | |||
| 2847 | const opaque_obj = t.castTag(.@"opaque").?.data; | ||
| 2848 | const name = try opaque_obj.getFullyQualifiedName(dg.module); | ||
| 2849 | defer gpa.free(name); | 2849 | defer gpa.free(name); |
| 2850 | 2850 | ||
| 2851 | const llvm_struct_ty = dg.context.structCreateNamed(name); | 2851 | const llvm_struct_ty = dg.context.structCreateNamed(name); |
| ... | @@ -2931,7 +2931,7 @@ pub const DeclGen = struct { | ... | @@ -2931,7 +2931,7 @@ pub const DeclGen = struct { |
| 2931 | }, | 2931 | }, |
| 2932 | .ErrorSet => return dg.context.intType(16), | 2932 | .ErrorSet => return dg.context.intType(16), |
| 2933 | .Struct => { | 2933 | .Struct => { |
| 2934 | const gop = try dg.object.type_map.getOrPutContext(gpa, t, .{ .mod = dg.module }); | 2934 | const gop = try dg.object.type_map.getOrPutContext(gpa, t, .{ .mod = mod }); |
| 2935 | if (gop.found_existing) return gop.value_ptr.*; | 2935 | if (gop.found_existing) return gop.value_ptr.*; |
| 2936 | 2936 | ||
| 2937 | // The Type memory is ephemeral; since we want to store a longer-lived | 2937 | // The Type memory is ephemeral; since we want to store a longer-lived |
| ... | @@ -2999,7 +2999,7 @@ pub const DeclGen = struct { | ... | @@ -2999,7 +2999,7 @@ pub const DeclGen = struct { |
| 2999 | return int_llvm_ty; | 2999 | return int_llvm_ty; |
| 3000 | } | 3000 | } |
| 3001 | 3001 | ||
| 3002 | const name = try struct_obj.getFullyQualifiedName(dg.module); | 3002 | const name = try struct_obj.getFullyQualifiedName(mod); |
| 3003 | defer gpa.free(name); | 3003 | defer gpa.free(name); |
| 3004 | 3004 | ||
| 3005 | const llvm_struct_ty = dg.context.structCreateNamed(name); | 3005 | const llvm_struct_ty = dg.context.structCreateNamed(name); |
| ... | @@ -3057,7 +3057,7 @@ pub const DeclGen = struct { | ... | @@ -3057,7 +3057,7 @@ pub const DeclGen = struct { |
| 3057 | return llvm_struct_ty; | 3057 | return llvm_struct_ty; |
| 3058 | }, | 3058 | }, |
| 3059 | .Union => { | 3059 | .Union => { |
| 3060 | const gop = try dg.object.type_map.getOrPutContext(gpa, t, .{ .mod = dg.module }); | 3060 | const gop = try dg.object.type_map.getOrPutContext(gpa, t, .{ .mod = mod }); |
| 3061 | if (gop.found_existing) return gop.value_ptr.*; | 3061 | if (gop.found_existing) return gop.value_ptr.*; |
| 3062 | 3062 | ||
| 3063 | // The Type memory is ephemeral; since we want to store a longer-lived | 3063 | // The Type memory is ephemeral; since we want to store a longer-lived |
| ... | @@ -3080,7 +3080,7 @@ pub const DeclGen = struct { | ... | @@ -3080,7 +3080,7 @@ pub const DeclGen = struct { |
| 3080 | return enum_tag_llvm_ty; | 3080 | return enum_tag_llvm_ty; |
| 3081 | } | 3081 | } |
| 3082 | 3082 | ||
| 3083 | const name = try union_obj.getFullyQualifiedName(dg.module); | 3083 | const name = try union_obj.getFullyQualifiedName(mod); |
| 3084 | defer gpa.free(name); | 3084 | defer gpa.free(name); |
| 3085 | 3085 | ||
| 3086 | const llvm_union_ty = dg.context.structCreateNamed(name); | 3086 | const llvm_union_ty = dg.context.structCreateNamed(name); |
| ... | @@ -6131,7 +6131,7 @@ pub const FuncGen = struct { | ... | @@ -6131,7 +6131,7 @@ pub const FuncGen = struct { |
| 6131 | const func = self.air.values[ty_pl.payload].castTag(.function).?.data; | 6131 | const func = self.air.values[ty_pl.payload].castTag(.function).?.data; |
| 6132 | const decl_index = func.owner_decl; | 6132 | const decl_index = func.owner_decl; |
| 6133 | const decl = mod.declPtr(decl_index); | 6133 | const decl = mod.declPtr(decl_index); |
| 6134 | const di_file = try self.dg.object.getDIFile(self.gpa, decl.src_namespace.file_scope); | 6134 | const di_file = try self.dg.object.getDIFile(self.gpa, mod.namespacePtr(decl.src_namespace).file_scope); |
| 6135 | self.di_file = di_file; | 6135 | self.di_file = di_file; |
| 6136 | const line_number = decl.src_line + 1; | 6136 | const line_number = decl.src_line + 1; |
| 6137 | const cur_debug_location = self.builder.getCurrentDebugLocation2(); | 6137 | const cur_debug_location = self.builder.getCurrentDebugLocation2(); |
| ... | @@ -6193,7 +6193,7 @@ pub const FuncGen = struct { | ... | @@ -6193,7 +6193,7 @@ pub const FuncGen = struct { |
| 6193 | const func = self.air.values[ty_pl.payload].castTag(.function).?.data; | 6193 | const func = self.air.values[ty_pl.payload].castTag(.function).?.data; |
| 6194 | const mod = self.dg.module; | 6194 | const mod = self.dg.module; |
| 6195 | const decl = mod.declPtr(func.owner_decl); | 6195 | const decl = mod.declPtr(func.owner_decl); |
| 6196 | const di_file = try self.dg.object.getDIFile(self.gpa, decl.src_namespace.file_scope); | 6196 | const di_file = try self.dg.object.getDIFile(self.gpa, mod.namespacePtr(decl.src_namespace).file_scope); |
| 6197 | self.di_file = di_file; | 6197 | self.di_file = di_file; |
| 6198 | const old = self.dbg_inlined.pop(); | 6198 | const old = self.dbg_inlined.pop(); |
| 6199 | self.di_scope = old.scope; | 6199 | self.di_scope = old.scope; |
| ... | @@ -8853,7 +8853,8 @@ pub const FuncGen = struct { | ... | @@ -8853,7 +8853,8 @@ pub const FuncGen = struct { |
| 8853 | } | 8853 | } |
| 8854 | 8854 | ||
| 8855 | fn getIsNamedEnumValueFunction(self: *FuncGen, enum_ty: Type) !*llvm.Value { | 8855 | fn getIsNamedEnumValueFunction(self: *FuncGen, enum_ty: Type) !*llvm.Value { |
| 8856 | const enum_decl = enum_ty.getOwnerDecl(); | 8856 | const mod = self.dg.module; |
| 8857 | const enum_decl = enum_ty.getOwnerDecl(mod); | ||
| 8857 | 8858 | ||
| 8858 | // TODO: detect when the type changes and re-emit this function. | 8859 | // TODO: detect when the type changes and re-emit this function. |
| 8859 | const gop = try self.dg.object.named_enum_map.getOrPut(self.dg.gpa, enum_decl); | 8860 | const gop = try self.dg.object.named_enum_map.getOrPut(self.dg.gpa, enum_decl); |
| ... | @@ -8864,7 +8865,6 @@ pub const FuncGen = struct { | ... | @@ -8864,7 +8865,6 @@ pub const FuncGen = struct { |
| 8864 | defer arena_allocator.deinit(); | 8865 | defer arena_allocator.deinit(); |
| 8865 | const arena = arena_allocator.allocator(); | 8866 | const arena = arena_allocator.allocator(); |
| 8866 | 8867 | ||
| 8867 | const mod = self.dg.module; | ||
| 8868 | const fqn = try mod.declPtr(enum_decl).getFullyQualifiedName(mod); | 8868 | const fqn = try mod.declPtr(enum_decl).getFullyQualifiedName(mod); |
| 8869 | defer self.gpa.free(fqn); | 8869 | defer self.gpa.free(fqn); |
| 8870 | const llvm_fn_name = try std.fmt.allocPrintZ(arena, "__zig_is_named_enum_value_{s}", .{fqn}); | 8870 | const llvm_fn_name = try std.fmt.allocPrintZ(arena, "__zig_is_named_enum_value_{s}", .{fqn}); |
| ... | @@ -8931,7 +8931,8 @@ pub const FuncGen = struct { | ... | @@ -8931,7 +8931,8 @@ pub const FuncGen = struct { |
| 8931 | } | 8931 | } |
| 8932 | 8932 | ||
| 8933 | fn getEnumTagNameFunction(self: *FuncGen, enum_ty: Type) !*llvm.Value { | 8933 | fn getEnumTagNameFunction(self: *FuncGen, enum_ty: Type) !*llvm.Value { |
| 8934 | const enum_decl = enum_ty.getOwnerDecl(); | 8934 | const mod = self.dg.module; |
| 8935 | const enum_decl = enum_ty.getOwnerDecl(mod); | ||
| 8935 | 8936 | ||
| 8936 | // TODO: detect when the type changes and re-emit this function. | 8937 | // TODO: detect when the type changes and re-emit this function. |
| 8937 | const gop = try self.dg.object.decl_map.getOrPut(self.dg.gpa, enum_decl); | 8938 | const gop = try self.dg.object.decl_map.getOrPut(self.dg.gpa, enum_decl); |
| ... | @@ -8942,7 +8943,6 @@ pub const FuncGen = struct { | ... | @@ -8942,7 +8943,6 @@ pub const FuncGen = struct { |
| 8942 | defer arena_allocator.deinit(); | 8943 | defer arena_allocator.deinit(); |
| 8943 | const arena = arena_allocator.allocator(); | 8944 | const arena = arena_allocator.allocator(); |
| 8944 | 8945 | ||
| 8945 | const mod = self.dg.module; | ||
| 8946 | const fqn = try mod.declPtr(enum_decl).getFullyQualifiedName(mod); | 8946 | const fqn = try mod.declPtr(enum_decl).getFullyQualifiedName(mod); |
| 8947 | defer self.gpa.free(fqn); | 8947 | defer self.gpa.free(fqn); |
| 8948 | const llvm_fn_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{s}", .{fqn}); | 8948 | const llvm_fn_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{s}", .{fqn}); |
src/codegen/spirv.zig+8-3| ... | @@ -218,8 +218,9 @@ pub const DeclGen = struct { | ... | @@ -218,8 +218,9 @@ pub const DeclGen = struct { |
| 218 | 218 | ||
| 219 | pub fn fail(self: *DeclGen, comptime format: []const u8, args: anytype) Error { | 219 | pub fn fail(self: *DeclGen, comptime format: []const u8, args: anytype) Error { |
| 220 | @setCold(true); | 220 | @setCold(true); |
| 221 | const mod = self.module; | ||
| 221 | const src = LazySrcLoc.nodeOffset(0); | 222 | const src = LazySrcLoc.nodeOffset(0); |
| 222 | const src_loc = src.toSrcLoc(self.module.declPtr(self.decl_index)); | 223 | const src_loc = src.toSrcLoc(self.module.declPtr(self.decl_index), mod); |
| 223 | assert(self.error_msg == null); | 224 | assert(self.error_msg == null); |
| 224 | self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, format, args); | 225 | self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, format, args); |
| 225 | return error.CodegenFail; | 226 | return error.CodegenFail; |
| ... | @@ -2775,7 +2776,10 @@ pub const DeclGen = struct { | ... | @@ -2775,7 +2776,10 @@ pub const DeclGen = struct { |
| 2775 | 2776 | ||
| 2776 | fn airDbgStmt(self: *DeclGen, inst: Air.Inst.Index) !void { | 2777 | fn airDbgStmt(self: *DeclGen, inst: Air.Inst.Index) !void { |
| 2777 | const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt; | 2778 | const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt; |
| 2778 | const src_fname_id = try self.spv.resolveSourceFileName(self.module.declPtr(self.decl_index)); | 2779 | const src_fname_id = try self.spv.resolveSourceFileName( |
| 2780 | self.module, | ||
| 2781 | self.module.declPtr(self.decl_index), | ||
| 2782 | ); | ||
| 2779 | try self.func.body.emit(self.spv.gpa, .OpLine, .{ | 2783 | try self.func.body.emit(self.spv.gpa, .OpLine, .{ |
| 2780 | .file = src_fname_id, | 2784 | .file = src_fname_id, |
| 2781 | .line = dbg_stmt.line, | 2785 | .line = dbg_stmt.line, |
| ... | @@ -3192,6 +3196,7 @@ pub const DeclGen = struct { | ... | @@ -3192,6 +3196,7 @@ pub const DeclGen = struct { |
| 3192 | } | 3196 | } |
| 3193 | 3197 | ||
| 3194 | fn airAssembly(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { | 3198 | fn airAssembly(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 3199 | const mod = self.module; | ||
| 3195 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | 3200 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; |
| 3196 | const extra = self.air.extraData(Air.Asm, ty_pl.payload); | 3201 | const extra = self.air.extraData(Air.Asm, ty_pl.payload); |
| 3197 | 3202 | ||
| ... | @@ -3274,7 +3279,7 @@ pub const DeclGen = struct { | ... | @@ -3274,7 +3279,7 @@ pub const DeclGen = struct { |
| 3274 | assert(as.errors.items.len != 0); | 3279 | assert(as.errors.items.len != 0); |
| 3275 | assert(self.error_msg == null); | 3280 | assert(self.error_msg == null); |
| 3276 | const loc = LazySrcLoc.nodeOffset(0); | 3281 | const loc = LazySrcLoc.nodeOffset(0); |
| 3277 | const src_loc = loc.toSrcLoc(self.module.declPtr(self.decl_index)); | 3282 | const src_loc = loc.toSrcLoc(self.module.declPtr(self.decl_index), mod); |
| 3278 | self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, "failed to assemble SPIR-V inline assembly", .{}); | 3283 | self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, "failed to assemble SPIR-V inline assembly", .{}); |
| 3279 | const notes = try self.module.gpa.alloc(Module.ErrorMsg, as.errors.items.len); | 3284 | const notes = try self.module.gpa.alloc(Module.ErrorMsg, as.errors.items.len); |
| 3280 | 3285 |
src/codegen/spirv/Module.zig+2-2| ... | @@ -390,8 +390,8 @@ pub fn addFunction(self: *Module, decl_index: Decl.Index, func: Fn) !void { | ... | @@ -390,8 +390,8 @@ pub fn addFunction(self: *Module, decl_index: Decl.Index, func: Fn) !void { |
| 390 | /// Fetch the result-id of an OpString instruction that encodes the path of the source | 390 | /// Fetch the result-id of an OpString instruction that encodes the path of the source |
| 391 | /// file of the decl. This function may also emit an OpSource with source-level information regarding | 391 | /// file of the decl. This function may also emit an OpSource with source-level information regarding |
| 392 | /// the decl. | 392 | /// the decl. |
| 393 | pub fn resolveSourceFileName(self: *Module, decl: *ZigDecl) !IdRef { | 393 | pub fn resolveSourceFileName(self: *Module, zig_module: *ZigModule, zig_decl: *ZigDecl) !IdRef { |
| 394 | const path = decl.getFileScope().sub_file_path; | 394 | const path = zig_decl.getFileScope(zig_module).sub_file_path; |
| 395 | const result = try self.source_file_names.getOrPut(self.gpa, path); | 395 | const result = try self.source_file_names.getOrPut(self.gpa, path); |
| 396 | if (!result.found_existing) { | 396 | if (!result.found_existing) { |
| 397 | const file_result_id = self.allocId(); | 397 | const file_result_id = self.allocId(); |
src/crash_report.zig+4-4| ... | @@ -99,7 +99,7 @@ fn dumpStatusReport() !void { | ... | @@ -99,7 +99,7 @@ fn dumpStatusReport() !void { |
| 99 | allocator, | 99 | allocator, |
| 100 | anal.body, | 100 | anal.body, |
| 101 | anal.body_index, | 101 | anal.body_index, |
| 102 | block.namespace.file_scope, | 102 | mod.namespacePtr(block.namespace).file_scope, |
| 103 | block_src_decl.src_node, | 103 | block_src_decl.src_node, |
| 104 | 6, // indent | 104 | 6, // indent |
| 105 | stderr, | 105 | stderr, |
| ... | @@ -108,7 +108,7 @@ fn dumpStatusReport() !void { | ... | @@ -108,7 +108,7 @@ fn dumpStatusReport() !void { |
| 108 | else => |e| return e, | 108 | else => |e| return e, |
| 109 | }; | 109 | }; |
| 110 | try stderr.writeAll(" For full context, use the command\n zig ast-check -t "); | 110 | try stderr.writeAll(" For full context, use the command\n zig ast-check -t "); |
| 111 | try writeFilePath(block.namespace.file_scope, stderr); | 111 | try writeFilePath(mod.namespacePtr(block.namespace).file_scope, stderr); |
| 112 | try stderr.writeAll("\n\n"); | 112 | try stderr.writeAll("\n\n"); |
| 113 | 113 | ||
| 114 | var parent = anal.parent; | 114 | var parent = anal.parent; |
| ... | @@ -121,7 +121,7 @@ fn dumpStatusReport() !void { | ... | @@ -121,7 +121,7 @@ fn dumpStatusReport() !void { |
| 121 | print_zir.renderSingleInstruction( | 121 | print_zir.renderSingleInstruction( |
| 122 | allocator, | 122 | allocator, |
| 123 | curr.body[curr.body_index], | 123 | curr.body[curr.body_index], |
| 124 | curr.block.namespace.file_scope, | 124 | mod.namespacePtr(curr.block.namespace).file_scope, |
| 125 | curr_block_src_decl.src_node, | 125 | curr_block_src_decl.src_node, |
| 126 | 6, // indent | 126 | 6, // indent |
| 127 | stderr, | 127 | stderr, |
| ... | @@ -148,7 +148,7 @@ fn writeFilePath(file: *Module.File, stream: anytype) !void { | ... | @@ -148,7 +148,7 @@ fn writeFilePath(file: *Module.File, stream: anytype) !void { |
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | fn writeFullyQualifiedDeclWithFile(mod: *Module, decl: *Decl, stream: anytype) !void { | 150 | fn writeFullyQualifiedDeclWithFile(mod: *Module, decl: *Decl, stream: anytype) !void { |
| 151 | try writeFilePath(decl.getFileScope(), stream); | 151 | try writeFilePath(decl.getFileScope(mod), stream); |
| 152 | try stream.writeAll(": "); | 152 | try stream.writeAll(": "); |
| 153 | try decl.renderFullyQualifiedDebugName(mod, stream); | 153 | try decl.renderFullyQualifiedDebugName(mod, stream); |
| 154 | } | 154 | } |
src/link.zig+2-2| ... | @@ -1129,8 +1129,8 @@ pub const File = struct { | ... | @@ -1129,8 +1129,8 @@ pub const File = struct { |
| 1129 | Type.anyerror }; | 1129 | Type.anyerror }; |
| 1130 | } | 1130 | } |
| 1131 | 1131 | ||
| 1132 | pub fn getDecl(self: LazySymbol) Module.Decl.OptionalIndex { | 1132 | pub fn getDecl(self: LazySymbol, mod: *Module) Module.Decl.OptionalIndex { |
| 1133 | return Module.Decl.OptionalIndex.init(self.ty.getOwnerDeclOrNull()); | 1133 | return Module.Decl.OptionalIndex.init(self.ty.getOwnerDeclOrNull(mod)); |
| 1134 | } | 1134 | } |
| 1135 | }; | 1135 | }; |
| 1136 | 1136 |
src/link/Coff.zig+34-33| ... | @@ -1032,20 +1032,20 @@ fn freeAtom(self: *Coff, atom_index: Atom.Index) void { | ... | @@ -1032,20 +1032,20 @@ fn freeAtom(self: *Coff, atom_index: Atom.Index) void { |
| 1032 | self.getAtomPtr(atom_index).sym_index = 0; | 1032 | self.getAtomPtr(atom_index).sym_index = 0; |
| 1033 | } | 1033 | } |
| 1034 | 1034 | ||
| 1035 | pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void { | 1035 | pub fn updateFunc(self: *Coff, mod: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void { |
| 1036 | if (build_options.skip_non_native and builtin.object_format != .coff) { | 1036 | if (build_options.skip_non_native and builtin.object_format != .coff) { |
| 1037 | @panic("Attempted to compile for object format that was disabled by build configuration"); | 1037 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 1038 | } | 1038 | } |
| 1039 | if (build_options.have_llvm) { | 1039 | if (build_options.have_llvm) { |
| 1040 | if (self.llvm_object) |llvm_object| { | 1040 | if (self.llvm_object) |llvm_object| { |
| 1041 | return llvm_object.updateFunc(module, func, air, liveness); | 1041 | return llvm_object.updateFunc(mod, func, air, liveness); |
| 1042 | } | 1042 | } |
| 1043 | } | 1043 | } |
| 1044 | const tracy = trace(@src()); | 1044 | const tracy = trace(@src()); |
| 1045 | defer tracy.end(); | 1045 | defer tracy.end(); |
| 1046 | 1046 | ||
| 1047 | const decl_index = func.owner_decl; | 1047 | const decl_index = func.owner_decl; |
| 1048 | const decl = module.declPtr(decl_index); | 1048 | const decl = mod.declPtr(decl_index); |
| 1049 | 1049 | ||
| 1050 | const atom_index = try self.getOrCreateAtomForDecl(decl_index); | 1050 | const atom_index = try self.getOrCreateAtomForDecl(decl_index); |
| 1051 | self.freeUnnamedConsts(decl_index); | 1051 | self.freeUnnamedConsts(decl_index); |
| ... | @@ -1056,7 +1056,7 @@ pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, live | ... | @@ -1056,7 +1056,7 @@ pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, live |
| 1056 | 1056 | ||
| 1057 | const res = try codegen.generateFunction( | 1057 | const res = try codegen.generateFunction( |
| 1058 | &self.base, | 1058 | &self.base, |
| 1059 | decl.srcLoc(), | 1059 | decl.srcLoc(mod), |
| 1060 | func, | 1060 | func, |
| 1061 | air, | 1061 | air, |
| 1062 | liveness, | 1062 | liveness, |
| ... | @@ -1067,7 +1067,7 @@ pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, live | ... | @@ -1067,7 +1067,7 @@ pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, live |
| 1067 | .ok => code_buffer.items, | 1067 | .ok => code_buffer.items, |
| 1068 | .fail => |em| { | 1068 | .fail => |em| { |
| 1069 | decl.analysis = .codegen_failure; | 1069 | decl.analysis = .codegen_failure; |
| 1070 | try module.failed_decls.put(module.gpa, decl_index, em); | 1070 | try mod.failed_decls.put(mod.gpa, decl_index, em); |
| 1071 | return; | 1071 | return; |
| 1072 | }, | 1072 | }, |
| 1073 | }; | 1073 | }; |
| ... | @@ -1076,7 +1076,7 @@ pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, live | ... | @@ -1076,7 +1076,7 @@ pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, live |
| 1076 | 1076 | ||
| 1077 | // Since we updated the vaddr and the size, each corresponding export | 1077 | // Since we updated the vaddr and the size, each corresponding export |
| 1078 | // symbol also needs to be updated. | 1078 | // symbol also needs to be updated. |
| 1079 | return self.updateDeclExports(module, decl_index, module.getDeclExports(decl_index)); | 1079 | return self.updateDeclExports(mod, decl_index, mod.getDeclExports(decl_index)); |
| 1080 | } | 1080 | } |
| 1081 | 1081 | ||
| 1082 | pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.Index) !u32 { | 1082 | pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.Index) !u32 { |
| ... | @@ -1110,7 +1110,7 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In | ... | @@ -1110,7 +1110,7 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In |
| 1110 | sym.section_number = @intToEnum(coff.SectionNumber, self.rdata_section_index.? + 1); | 1110 | sym.section_number = @intToEnum(coff.SectionNumber, self.rdata_section_index.? + 1); |
| 1111 | } | 1111 | } |
| 1112 | 1112 | ||
| 1113 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(), tv, &code_buffer, .none, .{ | 1113 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), tv, &code_buffer, .none, .{ |
| 1114 | .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?, | 1114 | .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?, |
| 1115 | }); | 1115 | }); |
| 1116 | var code = switch (res) { | 1116 | var code = switch (res) { |
| ... | @@ -1141,19 +1141,19 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In | ... | @@ -1141,19 +1141,19 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In |
| 1141 | 1141 | ||
| 1142 | pub fn updateDecl( | 1142 | pub fn updateDecl( |
| 1143 | self: *Coff, | 1143 | self: *Coff, |
| 1144 | module: *Module, | 1144 | mod: *Module, |
| 1145 | decl_index: Module.Decl.Index, | 1145 | decl_index: Module.Decl.Index, |
| 1146 | ) link.File.UpdateDeclError!void { | 1146 | ) link.File.UpdateDeclError!void { |
| 1147 | if (build_options.skip_non_native and builtin.object_format != .coff) { | 1147 | if (build_options.skip_non_native and builtin.object_format != .coff) { |
| 1148 | @panic("Attempted to compile for object format that was disabled by build configuration"); | 1148 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 1149 | } | 1149 | } |
| 1150 | if (build_options.have_llvm) { | 1150 | if (build_options.have_llvm) { |
| 1151 | if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(module, decl_index); | 1151 | if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index); |
| 1152 | } | 1152 | } |
| 1153 | const tracy = trace(@src()); | 1153 | const tracy = trace(@src()); |
| 1154 | defer tracy.end(); | 1154 | defer tracy.end(); |
| 1155 | 1155 | ||
| 1156 | const decl = module.declPtr(decl_index); | 1156 | const decl = mod.declPtr(decl_index); |
| 1157 | 1157 | ||
| 1158 | if (decl.val.tag() == .extern_fn) { | 1158 | if (decl.val.tag() == .extern_fn) { |
| 1159 | return; // TODO Should we do more when front-end analyzed extern decl? | 1159 | return; // TODO Should we do more when front-end analyzed extern decl? |
| ... | @@ -1173,7 +1173,7 @@ pub fn updateDecl( | ... | @@ -1173,7 +1173,7 @@ pub fn updateDecl( |
| 1173 | defer code_buffer.deinit(); | 1173 | defer code_buffer.deinit(); |
| 1174 | 1174 | ||
| 1175 | const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val; | 1175 | const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val; |
| 1176 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(), .{ | 1176 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{ |
| 1177 | .ty = decl.ty, | 1177 | .ty = decl.ty, |
| 1178 | .val = decl_val, | 1178 | .val = decl_val, |
| 1179 | }, &code_buffer, .none, .{ | 1179 | }, &code_buffer, .none, .{ |
| ... | @@ -1183,7 +1183,7 @@ pub fn updateDecl( | ... | @@ -1183,7 +1183,7 @@ pub fn updateDecl( |
| 1183 | .ok => code_buffer.items, | 1183 | .ok => code_buffer.items, |
| 1184 | .fail => |em| { | 1184 | .fail => |em| { |
| 1185 | decl.analysis = .codegen_failure; | 1185 | decl.analysis = .codegen_failure; |
| 1186 | try module.failed_decls.put(module.gpa, decl_index, em); | 1186 | try mod.failed_decls.put(mod.gpa, decl_index, em); |
| 1187 | return; | 1187 | return; |
| 1188 | }, | 1188 | }, |
| 1189 | }; | 1189 | }; |
| ... | @@ -1192,7 +1192,7 @@ pub fn updateDecl( | ... | @@ -1192,7 +1192,7 @@ pub fn updateDecl( |
| 1192 | 1192 | ||
| 1193 | // Since we updated the vaddr and the size, each corresponding export | 1193 | // Since we updated the vaddr and the size, each corresponding export |
| 1194 | // symbol also needs to be updated. | 1194 | // symbol also needs to be updated. |
| 1195 | return self.updateDeclExports(module, decl_index, module.getDeclExports(decl_index)); | 1195 | return self.updateDeclExports(mod, decl_index, mod.getDeclExports(decl_index)); |
| 1196 | } | 1196 | } |
| 1197 | 1197 | ||
| 1198 | fn updateLazySymbolAtom( | 1198 | fn updateLazySymbolAtom( |
| ... | @@ -1217,8 +1217,8 @@ fn updateLazySymbolAtom( | ... | @@ -1217,8 +1217,8 @@ fn updateLazySymbolAtom( |
| 1217 | const atom = self.getAtomPtr(atom_index); | 1217 | const atom = self.getAtomPtr(atom_index); |
| 1218 | const local_sym_index = atom.getSymbolIndex().?; | 1218 | const local_sym_index = atom.getSymbolIndex().?; |
| 1219 | 1219 | ||
| 1220 | const src = if (sym.ty.getOwnerDeclOrNull()) |owner_decl| | 1220 | const src = if (sym.ty.getOwnerDeclOrNull(mod)) |owner_decl| |
| 1221 | mod.declPtr(owner_decl).srcLoc() | 1221 | mod.declPtr(owner_decl).srcLoc(mod) |
| 1222 | else | 1222 | else |
| 1223 | Module.SrcLoc{ | 1223 | Module.SrcLoc{ |
| 1224 | .file_scope = undefined, | 1224 | .file_scope = undefined, |
| ... | @@ -1262,7 +1262,8 @@ fn updateLazySymbolAtom( | ... | @@ -1262,7 +1262,8 @@ fn updateLazySymbolAtom( |
| 1262 | } | 1262 | } |
| 1263 | 1263 | ||
| 1264 | pub fn getOrCreateAtomForLazySymbol(self: *Coff, sym: link.File.LazySymbol) !Atom.Index { | 1264 | pub fn getOrCreateAtomForLazySymbol(self: *Coff, sym: link.File.LazySymbol) !Atom.Index { |
| 1265 | const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl()); | 1265 | const mod = self.base.options.module.?; |
| 1266 | const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl(mod)); | ||
| 1266 | errdefer _ = if (!gop.found_existing) self.lazy_syms.pop(); | 1267 | errdefer _ = if (!gop.found_existing) self.lazy_syms.pop(); |
| 1267 | if (!gop.found_existing) gop.value_ptr.* = .{}; | 1268 | if (!gop.found_existing) gop.value_ptr.* = .{}; |
| 1268 | const metadata: struct { atom: *Atom.Index, state: *LazySymbolMetadata.State } = switch (sym.kind) { | 1269 | const metadata: struct { atom: *Atom.Index, state: *LazySymbolMetadata.State } = switch (sym.kind) { |
| ... | @@ -1277,7 +1278,7 @@ pub fn getOrCreateAtomForLazySymbol(self: *Coff, sym: link.File.LazySymbol) !Ato | ... | @@ -1277,7 +1278,7 @@ pub fn getOrCreateAtomForLazySymbol(self: *Coff, sym: link.File.LazySymbol) !Ato |
| 1277 | metadata.state.* = .pending_flush; | 1278 | metadata.state.* = .pending_flush; |
| 1278 | const atom = metadata.atom.*; | 1279 | const atom = metadata.atom.*; |
| 1279 | // anyerror needs to be deferred until flushModule | 1280 | // anyerror needs to be deferred until flushModule |
| 1280 | if (sym.getDecl() != .none) try self.updateLazySymbolAtom(sym, atom, switch (sym.kind) { | 1281 | if (sym.getDecl(mod) != .none) try self.updateLazySymbolAtom(sym, atom, switch (sym.kind) { |
| 1281 | .code => self.text_section_index.?, | 1282 | .code => self.text_section_index.?, |
| 1282 | .const_data => self.rdata_section_index.?, | 1283 | .const_data => self.rdata_section_index.?, |
| 1283 | }); | 1284 | }); |
| ... | @@ -1411,7 +1412,7 @@ pub fn freeDecl(self: *Coff, decl_index: Module.Decl.Index) void { | ... | @@ -1411,7 +1412,7 @@ pub fn freeDecl(self: *Coff, decl_index: Module.Decl.Index) void { |
| 1411 | 1412 | ||
| 1412 | pub fn updateDeclExports( | 1413 | pub fn updateDeclExports( |
| 1413 | self: *Coff, | 1414 | self: *Coff, |
| 1414 | module: *Module, | 1415 | mod: *Module, |
| 1415 | decl_index: Module.Decl.Index, | 1416 | decl_index: Module.Decl.Index, |
| 1416 | exports: []const *Module.Export, | 1417 | exports: []const *Module.Export, |
| 1417 | ) link.File.UpdateDeclExportsError!void { | 1418 | ) link.File.UpdateDeclExportsError!void { |
| ... | @@ -1423,7 +1424,7 @@ pub fn updateDeclExports( | ... | @@ -1423,7 +1424,7 @@ pub fn updateDeclExports( |
| 1423 | // Even in the case of LLVM, we need to notice certain exported symbols in order to | 1424 | // Even in the case of LLVM, we need to notice certain exported symbols in order to |
| 1424 | // detect the default subsystem. | 1425 | // detect the default subsystem. |
| 1425 | for (exports) |exp| { | 1426 | for (exports) |exp| { |
| 1426 | const exported_decl = module.declPtr(exp.exported_decl); | 1427 | const exported_decl = mod.declPtr(exp.exported_decl); |
| 1427 | if (exported_decl.getFunction() == null) continue; | 1428 | if (exported_decl.getFunction() == null) continue; |
| 1428 | const winapi_cc = switch (self.base.options.target.cpu.arch) { | 1429 | const winapi_cc = switch (self.base.options.target.cpu.arch) { |
| 1429 | .x86 => std.builtin.CallingConvention.Stdcall, | 1430 | .x86 => std.builtin.CallingConvention.Stdcall, |
| ... | @@ -1433,23 +1434,23 @@ pub fn updateDeclExports( | ... | @@ -1433,23 +1434,23 @@ pub fn updateDeclExports( |
| 1433 | if (decl_cc == .C and mem.eql(u8, exp.options.name, "main") and | 1434 | if (decl_cc == .C and mem.eql(u8, exp.options.name, "main") and |
| 1434 | self.base.options.link_libc) | 1435 | self.base.options.link_libc) |
| 1435 | { | 1436 | { |
| 1436 | module.stage1_flags.have_c_main = true; | 1437 | mod.stage1_flags.have_c_main = true; |
| 1437 | } else if (decl_cc == winapi_cc and self.base.options.target.os.tag == .windows) { | 1438 | } else if (decl_cc == winapi_cc and self.base.options.target.os.tag == .windows) { |
| 1438 | if (mem.eql(u8, exp.options.name, "WinMain")) { | 1439 | if (mem.eql(u8, exp.options.name, "WinMain")) { |
| 1439 | module.stage1_flags.have_winmain = true; | 1440 | mod.stage1_flags.have_winmain = true; |
| 1440 | } else if (mem.eql(u8, exp.options.name, "wWinMain")) { | 1441 | } else if (mem.eql(u8, exp.options.name, "wWinMain")) { |
| 1441 | module.stage1_flags.have_wwinmain = true; | 1442 | mod.stage1_flags.have_wwinmain = true; |
| 1442 | } else if (mem.eql(u8, exp.options.name, "WinMainCRTStartup")) { | 1443 | } else if (mem.eql(u8, exp.options.name, "WinMainCRTStartup")) { |
| 1443 | module.stage1_flags.have_winmain_crt_startup = true; | 1444 | mod.stage1_flags.have_winmain_crt_startup = true; |
| 1444 | } else if (mem.eql(u8, exp.options.name, "wWinMainCRTStartup")) { | 1445 | } else if (mem.eql(u8, exp.options.name, "wWinMainCRTStartup")) { |
| 1445 | module.stage1_flags.have_wwinmain_crt_startup = true; | 1446 | mod.stage1_flags.have_wwinmain_crt_startup = true; |
| 1446 | } else if (mem.eql(u8, exp.options.name, "DllMainCRTStartup")) { | 1447 | } else if (mem.eql(u8, exp.options.name, "DllMainCRTStartup")) { |
| 1447 | module.stage1_flags.have_dllmain_crt_startup = true; | 1448 | mod.stage1_flags.have_dllmain_crt_startup = true; |
| 1448 | } | 1449 | } |
| 1449 | } | 1450 | } |
| 1450 | } | 1451 | } |
| 1451 | 1452 | ||
| 1452 | if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(module, decl_index, exports); | 1453 | if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports); |
| 1453 | } | 1454 | } |
| 1454 | 1455 | ||
| 1455 | const tracy = trace(@src()); | 1456 | const tracy = trace(@src()); |
| ... | @@ -1457,7 +1458,7 @@ pub fn updateDeclExports( | ... | @@ -1457,7 +1458,7 @@ pub fn updateDeclExports( |
| 1457 | 1458 | ||
| 1458 | const gpa = self.base.allocator; | 1459 | const gpa = self.base.allocator; |
| 1459 | 1460 | ||
| 1460 | const decl = module.declPtr(decl_index); | 1461 | const decl = mod.declPtr(decl_index); |
| 1461 | const atom_index = try self.getOrCreateAtomForDecl(decl_index); | 1462 | const atom_index = try self.getOrCreateAtomForDecl(decl_index); |
| 1462 | const atom = self.getAtom(atom_index); | 1463 | const atom = self.getAtom(atom_index); |
| 1463 | const decl_sym = atom.getSymbol(self); | 1464 | const decl_sym = atom.getSymbol(self); |
| ... | @@ -1468,12 +1469,12 @@ pub fn updateDeclExports( | ... | @@ -1468,12 +1469,12 @@ pub fn updateDeclExports( |
| 1468 | 1469 | ||
| 1469 | if (exp.options.section) |section_name| { | 1470 | if (exp.options.section) |section_name| { |
| 1470 | if (!mem.eql(u8, section_name, ".text")) { | 1471 | if (!mem.eql(u8, section_name, ".text")) { |
| 1471 | try module.failed_exports.putNoClobber( | 1472 | try mod.failed_exports.putNoClobber( |
| 1472 | module.gpa, | 1473 | mod.gpa, |
| 1473 | exp, | 1474 | exp, |
| 1474 | try Module.ErrorMsg.create( | 1475 | try Module.ErrorMsg.create( |
| 1475 | gpa, | 1476 | gpa, |
| 1476 | decl.srcLoc(), | 1477 | decl.srcLoc(mod), |
| 1477 | "Unimplemented: ExportOptions.section", | 1478 | "Unimplemented: ExportOptions.section", |
| 1478 | .{}, | 1479 | .{}, |
| 1479 | ), | 1480 | ), |
| ... | @@ -1483,12 +1484,12 @@ pub fn updateDeclExports( | ... | @@ -1483,12 +1484,12 @@ pub fn updateDeclExports( |
| 1483 | } | 1484 | } |
| 1484 | 1485 | ||
| 1485 | if (exp.options.linkage == .LinkOnce) { | 1486 | if (exp.options.linkage == .LinkOnce) { |
| 1486 | try module.failed_exports.putNoClobber( | 1487 | try mod.failed_exports.putNoClobber( |
| 1487 | module.gpa, | 1488 | mod.gpa, |
| 1488 | exp, | 1489 | exp, |
| 1489 | try Module.ErrorMsg.create( | 1490 | try Module.ErrorMsg.create( |
| 1490 | gpa, | 1491 | gpa, |
| 1491 | decl.srcLoc(), | 1492 | decl.srcLoc(mod), |
| 1492 | "Unimplemented: GlobalLinkage.LinkOnce", | 1493 | "Unimplemented: GlobalLinkage.LinkOnce", |
| 1493 | .{}, | 1494 | .{}, |
| 1494 | ), | 1495 | ), |
src/link/Dwarf.zig+1-1| ... | @@ -2597,7 +2597,7 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void { | ... | @@ -2597,7 +2597,7 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void { |
| 2597 | 2597 | ||
| 2598 | fn addDIFile(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index) !u28 { | 2598 | fn addDIFile(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index) !u28 { |
| 2599 | const decl = mod.declPtr(decl_index); | 2599 | const decl = mod.declPtr(decl_index); |
| 2600 | const file_scope = decl.getFileScope(); | 2600 | const file_scope = decl.getFileScope(mod); |
| 2601 | const gop = try self.di_files.getOrPut(self.allocator, file_scope); | 2601 | const gop = try self.di_files.getOrPut(self.allocator, file_scope); |
| 2602 | if (!gop.found_existing) { | 2602 | if (!gop.found_existing) { |
| 2603 | switch (self.bin_file.tag) { | 2603 | switch (self.bin_file.tag) { |
src/link/Elf.zig+33-32| ... | @@ -2414,7 +2414,8 @@ pub fn freeDecl(self: *Elf, decl_index: Module.Decl.Index) void { | ... | @@ -2414,7 +2414,8 @@ pub fn freeDecl(self: *Elf, decl_index: Module.Decl.Index) void { |
| 2414 | } | 2414 | } |
| 2415 | 2415 | ||
| 2416 | pub fn getOrCreateAtomForLazySymbol(self: *Elf, sym: File.LazySymbol) !Atom.Index { | 2416 | pub fn getOrCreateAtomForLazySymbol(self: *Elf, sym: File.LazySymbol) !Atom.Index { |
| 2417 | const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl()); | 2417 | const mod = self.base.options.module.?; |
| 2418 | const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl(mod)); | ||
| 2418 | errdefer _ = if (!gop.found_existing) self.lazy_syms.pop(); | 2419 | errdefer _ = if (!gop.found_existing) self.lazy_syms.pop(); |
| 2419 | if (!gop.found_existing) gop.value_ptr.* = .{}; | 2420 | if (!gop.found_existing) gop.value_ptr.* = .{}; |
| 2420 | const metadata: struct { atom: *Atom.Index, state: *LazySymbolMetadata.State } = switch (sym.kind) { | 2421 | const metadata: struct { atom: *Atom.Index, state: *LazySymbolMetadata.State } = switch (sym.kind) { |
| ... | @@ -2429,7 +2430,7 @@ pub fn getOrCreateAtomForLazySymbol(self: *Elf, sym: File.LazySymbol) !Atom.Inde | ... | @@ -2429,7 +2430,7 @@ pub fn getOrCreateAtomForLazySymbol(self: *Elf, sym: File.LazySymbol) !Atom.Inde |
| 2429 | metadata.state.* = .pending_flush; | 2430 | metadata.state.* = .pending_flush; |
| 2430 | const atom = metadata.atom.*; | 2431 | const atom = metadata.atom.*; |
| 2431 | // anyerror needs to be deferred until flushModule | 2432 | // anyerror needs to be deferred until flushModule |
| 2432 | if (sym.getDecl() != .none) try self.updateLazySymbolAtom(sym, atom, switch (sym.kind) { | 2433 | if (sym.getDecl(mod) != .none) try self.updateLazySymbolAtom(sym, atom, switch (sym.kind) { |
| 2433 | .code => self.text_section_index.?, | 2434 | .code => self.text_section_index.?, |
| 2434 | .const_data => self.rodata_section_index.?, | 2435 | .const_data => self.rodata_section_index.?, |
| 2435 | }); | 2436 | }); |
| ... | @@ -2573,19 +2574,19 @@ fn updateDeclCode(self: *Elf, decl_index: Module.Decl.Index, code: []const u8, s | ... | @@ -2573,19 +2574,19 @@ fn updateDeclCode(self: *Elf, decl_index: Module.Decl.Index, code: []const u8, s |
| 2573 | return local_sym; | 2574 | return local_sym; |
| 2574 | } | 2575 | } |
| 2575 | 2576 | ||
| 2576 | pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void { | 2577 | pub fn updateFunc(self: *Elf, mod: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void { |
| 2577 | if (build_options.skip_non_native and builtin.object_format != .elf) { | 2578 | if (build_options.skip_non_native and builtin.object_format != .elf) { |
| 2578 | @panic("Attempted to compile for object format that was disabled by build configuration"); | 2579 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 2579 | } | 2580 | } |
| 2580 | if (build_options.have_llvm) { | 2581 | if (build_options.have_llvm) { |
| 2581 | if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(module, func, air, liveness); | 2582 | if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func, air, liveness); |
| 2582 | } | 2583 | } |
| 2583 | 2584 | ||
| 2584 | const tracy = trace(@src()); | 2585 | const tracy = trace(@src()); |
| 2585 | defer tracy.end(); | 2586 | defer tracy.end(); |
| 2586 | 2587 | ||
| 2587 | const decl_index = func.owner_decl; | 2588 | const decl_index = func.owner_decl; |
| 2588 | const decl = module.declPtr(decl_index); | 2589 | const decl = mod.declPtr(decl_index); |
| 2589 | 2590 | ||
| 2590 | const atom_index = try self.getOrCreateAtomForDecl(decl_index); | 2591 | const atom_index = try self.getOrCreateAtomForDecl(decl_index); |
| 2591 | self.freeUnnamedConsts(decl_index); | 2592 | self.freeUnnamedConsts(decl_index); |
| ... | @@ -2594,28 +2595,28 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven | ... | @@ -2594,28 +2595,28 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven |
| 2594 | var code_buffer = std.ArrayList(u8).init(self.base.allocator); | 2595 | var code_buffer = std.ArrayList(u8).init(self.base.allocator); |
| 2595 | defer code_buffer.deinit(); | 2596 | defer code_buffer.deinit(); |
| 2596 | 2597 | ||
| 2597 | var decl_state: ?Dwarf.DeclState = if (self.dwarf) |*dw| try dw.initDeclState(module, decl_index) else null; | 2598 | var decl_state: ?Dwarf.DeclState = if (self.dwarf) |*dw| try dw.initDeclState(mod, decl_index) else null; |
| 2598 | defer if (decl_state) |*ds| ds.deinit(); | 2599 | defer if (decl_state) |*ds| ds.deinit(); |
| 2599 | 2600 | ||
| 2600 | const res = if (decl_state) |*ds| | 2601 | const res = if (decl_state) |*ds| |
| 2601 | try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .{ | 2602 | try codegen.generateFunction(&self.base, decl.srcLoc(mod), func, air, liveness, &code_buffer, .{ |
| 2602 | .dwarf = ds, | 2603 | .dwarf = ds, |
| 2603 | }) | 2604 | }) |
| 2604 | else | 2605 | else |
| 2605 | try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .none); | 2606 | try codegen.generateFunction(&self.base, decl.srcLoc(mod), func, air, liveness, &code_buffer, .none); |
| 2606 | 2607 | ||
| 2607 | const code = switch (res) { | 2608 | const code = switch (res) { |
| 2608 | .ok => code_buffer.items, | 2609 | .ok => code_buffer.items, |
| 2609 | .fail => |em| { | 2610 | .fail => |em| { |
| 2610 | decl.analysis = .codegen_failure; | 2611 | decl.analysis = .codegen_failure; |
| 2611 | try module.failed_decls.put(module.gpa, decl_index, em); | 2612 | try mod.failed_decls.put(mod.gpa, decl_index, em); |
| 2612 | return; | 2613 | return; |
| 2613 | }, | 2614 | }, |
| 2614 | }; | 2615 | }; |
| 2615 | const local_sym = try self.updateDeclCode(decl_index, code, elf.STT_FUNC); | 2616 | const local_sym = try self.updateDeclCode(decl_index, code, elf.STT_FUNC); |
| 2616 | if (decl_state) |*ds| { | 2617 | if (decl_state) |*ds| { |
| 2617 | try self.dwarf.?.commitDeclState( | 2618 | try self.dwarf.?.commitDeclState( |
| 2618 | module, | 2619 | mod, |
| 2619 | decl_index, | 2620 | decl_index, |
| 2620 | local_sym.st_value, | 2621 | local_sym.st_value, |
| 2621 | local_sym.st_size, | 2622 | local_sym.st_size, |
| ... | @@ -2625,25 +2626,25 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven | ... | @@ -2625,25 +2626,25 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven |
| 2625 | 2626 | ||
| 2626 | // Since we updated the vaddr and the size, each corresponding export | 2627 | // Since we updated the vaddr and the size, each corresponding export |
| 2627 | // symbol also needs to be updated. | 2628 | // symbol also needs to be updated. |
| 2628 | return self.updateDeclExports(module, decl_index, module.getDeclExports(decl_index)); | 2629 | return self.updateDeclExports(mod, decl_index, mod.getDeclExports(decl_index)); |
| 2629 | } | 2630 | } |
| 2630 | 2631 | ||
| 2631 | pub fn updateDecl( | 2632 | pub fn updateDecl( |
| 2632 | self: *Elf, | 2633 | self: *Elf, |
| 2633 | module: *Module, | 2634 | mod: *Module, |
| 2634 | decl_index: Module.Decl.Index, | 2635 | decl_index: Module.Decl.Index, |
| 2635 | ) File.UpdateDeclError!void { | 2636 | ) File.UpdateDeclError!void { |
| 2636 | if (build_options.skip_non_native and builtin.object_format != .elf) { | 2637 | if (build_options.skip_non_native and builtin.object_format != .elf) { |
| 2637 | @panic("Attempted to compile for object format that was disabled by build configuration"); | 2638 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 2638 | } | 2639 | } |
| 2639 | if (build_options.have_llvm) { | 2640 | if (build_options.have_llvm) { |
| 2640 | if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(module, decl_index); | 2641 | if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index); |
| 2641 | } | 2642 | } |
| 2642 | 2643 | ||
| 2643 | const tracy = trace(@src()); | 2644 | const tracy = trace(@src()); |
| 2644 | defer tracy.end(); | 2645 | defer tracy.end(); |
| 2645 | 2646 | ||
| 2646 | const decl = module.declPtr(decl_index); | 2647 | const decl = mod.declPtr(decl_index); |
| 2647 | 2648 | ||
| 2648 | if (decl.val.tag() == .extern_fn) { | 2649 | if (decl.val.tag() == .extern_fn) { |
| 2649 | return; // TODO Should we do more when front-end analyzed extern decl? | 2650 | return; // TODO Should we do more when front-end analyzed extern decl? |
| ... | @@ -2662,13 +2663,13 @@ pub fn updateDecl( | ... | @@ -2662,13 +2663,13 @@ pub fn updateDecl( |
| 2662 | var code_buffer = std.ArrayList(u8).init(self.base.allocator); | 2663 | var code_buffer = std.ArrayList(u8).init(self.base.allocator); |
| 2663 | defer code_buffer.deinit(); | 2664 | defer code_buffer.deinit(); |
| 2664 | 2665 | ||
| 2665 | var decl_state: ?Dwarf.DeclState = if (self.dwarf) |*dw| try dw.initDeclState(module, decl_index) else null; | 2666 | var decl_state: ?Dwarf.DeclState = if (self.dwarf) |*dw| try dw.initDeclState(mod, decl_index) else null; |
| 2666 | defer if (decl_state) |*ds| ds.deinit(); | 2667 | defer if (decl_state) |*ds| ds.deinit(); |
| 2667 | 2668 | ||
| 2668 | // TODO implement .debug_info for global variables | 2669 | // TODO implement .debug_info for global variables |
| 2669 | const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val; | 2670 | const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val; |
| 2670 | const res = if (decl_state) |*ds| | 2671 | const res = if (decl_state) |*ds| |
| 2671 | try codegen.generateSymbol(&self.base, decl.srcLoc(), .{ | 2672 | try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{ |
| 2672 | .ty = decl.ty, | 2673 | .ty = decl.ty, |
| 2673 | .val = decl_val, | 2674 | .val = decl_val, |
| 2674 | }, &code_buffer, .{ | 2675 | }, &code_buffer, .{ |
| ... | @@ -2677,7 +2678,7 @@ pub fn updateDecl( | ... | @@ -2677,7 +2678,7 @@ pub fn updateDecl( |
| 2677 | .parent_atom_index = atom.getSymbolIndex().?, | 2678 | .parent_atom_index = atom.getSymbolIndex().?, |
| 2678 | }) | 2679 | }) |
| 2679 | else | 2680 | else |
| 2680 | try codegen.generateSymbol(&self.base, decl.srcLoc(), .{ | 2681 | try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{ |
| 2681 | .ty = decl.ty, | 2682 | .ty = decl.ty, |
| 2682 | .val = decl_val, | 2683 | .val = decl_val, |
| 2683 | }, &code_buffer, .none, .{ | 2684 | }, &code_buffer, .none, .{ |
| ... | @@ -2688,7 +2689,7 @@ pub fn updateDecl( | ... | @@ -2688,7 +2689,7 @@ pub fn updateDecl( |
| 2688 | .ok => code_buffer.items, | 2689 | .ok => code_buffer.items, |
| 2689 | .fail => |em| { | 2690 | .fail => |em| { |
| 2690 | decl.analysis = .codegen_failure; | 2691 | decl.analysis = .codegen_failure; |
| 2691 | try module.failed_decls.put(module.gpa, decl_index, em); | 2692 | try mod.failed_decls.put(mod.gpa, decl_index, em); |
| 2692 | return; | 2693 | return; |
| 2693 | }, | 2694 | }, |
| 2694 | }; | 2695 | }; |
| ... | @@ -2696,7 +2697,7 @@ pub fn updateDecl( | ... | @@ -2696,7 +2697,7 @@ pub fn updateDecl( |
| 2696 | const local_sym = try self.updateDeclCode(decl_index, code, elf.STT_OBJECT); | 2697 | const local_sym = try self.updateDeclCode(decl_index, code, elf.STT_OBJECT); |
| 2697 | if (decl_state) |*ds| { | 2698 | if (decl_state) |*ds| { |
| 2698 | try self.dwarf.?.commitDeclState( | 2699 | try self.dwarf.?.commitDeclState( |
| 2699 | module, | 2700 | mod, |
| 2700 | decl_index, | 2701 | decl_index, |
| 2701 | local_sym.st_value, | 2702 | local_sym.st_value, |
| 2702 | local_sym.st_size, | 2703 | local_sym.st_size, |
| ... | @@ -2706,7 +2707,7 @@ pub fn updateDecl( | ... | @@ -2706,7 +2707,7 @@ pub fn updateDecl( |
| 2706 | 2707 | ||
| 2707 | // Since we updated the vaddr and the size, each corresponding export | 2708 | // Since we updated the vaddr and the size, each corresponding export |
| 2708 | // symbol also needs to be updated. | 2709 | // symbol also needs to be updated. |
| 2709 | return self.updateDeclExports(module, decl_index, module.getDeclExports(decl_index)); | 2710 | return self.updateDeclExports(mod, decl_index, mod.getDeclExports(decl_index)); |
| 2710 | } | 2711 | } |
| 2711 | 2712 | ||
| 2712 | fn updateLazySymbolAtom( | 2713 | fn updateLazySymbolAtom( |
| ... | @@ -2735,8 +2736,8 @@ fn updateLazySymbolAtom( | ... | @@ -2735,8 +2736,8 @@ fn updateLazySymbolAtom( |
| 2735 | const atom = self.getAtom(atom_index); | 2736 | const atom = self.getAtom(atom_index); |
| 2736 | const local_sym_index = atom.getSymbolIndex().?; | 2737 | const local_sym_index = atom.getSymbolIndex().?; |
| 2737 | 2738 | ||
| 2738 | const src = if (sym.ty.getOwnerDeclOrNull()) |owner_decl| | 2739 | const src = if (sym.ty.getOwnerDeclOrNull(mod)) |owner_decl| |
| 2739 | mod.declPtr(owner_decl).srcLoc() | 2740 | mod.declPtr(owner_decl).srcLoc(mod) |
| 2740 | else | 2741 | else |
| 2741 | Module.SrcLoc{ | 2742 | Module.SrcLoc{ |
| 2742 | .file_scope = undefined, | 2743 | .file_scope = undefined, |
| ... | @@ -2812,7 +2813,7 @@ pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl_index: Module | ... | @@ -2812,7 +2813,7 @@ pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl_index: Module |
| 2812 | 2813 | ||
| 2813 | const atom_index = try self.createAtom(); | 2814 | const atom_index = try self.createAtom(); |
| 2814 | 2815 | ||
| 2815 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(), typed_value, &code_buffer, .{ | 2816 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), typed_value, &code_buffer, .{ |
| 2816 | .none = {}, | 2817 | .none = {}, |
| 2817 | }, .{ | 2818 | }, .{ |
| 2818 | .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?, | 2819 | .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?, |
| ... | @@ -2853,7 +2854,7 @@ pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl_index: Module | ... | @@ -2853,7 +2854,7 @@ pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl_index: Module |
| 2853 | 2854 | ||
| 2854 | pub fn updateDeclExports( | 2855 | pub fn updateDeclExports( |
| 2855 | self: *Elf, | 2856 | self: *Elf, |
| 2856 | module: *Module, | 2857 | mod: *Module, |
| 2857 | decl_index: Module.Decl.Index, | 2858 | decl_index: Module.Decl.Index, |
| 2858 | exports: []const *Module.Export, | 2859 | exports: []const *Module.Export, |
| 2859 | ) File.UpdateDeclExportsError!void { | 2860 | ) File.UpdateDeclExportsError!void { |
| ... | @@ -2861,7 +2862,7 @@ pub fn updateDeclExports( | ... | @@ -2861,7 +2862,7 @@ pub fn updateDeclExports( |
| 2861 | @panic("Attempted to compile for object format that was disabled by build configuration"); | 2862 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 2862 | } | 2863 | } |
| 2863 | if (build_options.have_llvm) { | 2864 | if (build_options.have_llvm) { |
| 2864 | if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(module, decl_index, exports); | 2865 | if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports); |
| 2865 | } | 2866 | } |
| 2866 | 2867 | ||
| 2867 | const tracy = trace(@src()); | 2868 | const tracy = trace(@src()); |
| ... | @@ -2869,7 +2870,7 @@ pub fn updateDeclExports( | ... | @@ -2869,7 +2870,7 @@ pub fn updateDeclExports( |
| 2869 | 2870 | ||
| 2870 | const gpa = self.base.allocator; | 2871 | const gpa = self.base.allocator; |
| 2871 | 2872 | ||
| 2872 | const decl = module.declPtr(decl_index); | 2873 | const decl = mod.declPtr(decl_index); |
| 2873 | const atom_index = try self.getOrCreateAtomForDecl(decl_index); | 2874 | const atom_index = try self.getOrCreateAtomForDecl(decl_index); |
| 2874 | const atom = self.getAtom(atom_index); | 2875 | const atom = self.getAtom(atom_index); |
| 2875 | const decl_sym = atom.getSymbol(self); | 2876 | const decl_sym = atom.getSymbol(self); |
| ... | @@ -2881,10 +2882,10 @@ pub fn updateDeclExports( | ... | @@ -2881,10 +2882,10 @@ pub fn updateDeclExports( |
| 2881 | for (exports) |exp| { | 2882 | for (exports) |exp| { |
| 2882 | if (exp.options.section) |section_name| { | 2883 | if (exp.options.section) |section_name| { |
| 2883 | if (!mem.eql(u8, section_name, ".text")) { | 2884 | if (!mem.eql(u8, section_name, ".text")) { |
| 2884 | try module.failed_exports.ensureUnusedCapacity(module.gpa, 1); | 2885 | try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1); |
| 2885 | module.failed_exports.putAssumeCapacityNoClobber( | 2886 | mod.failed_exports.putAssumeCapacityNoClobber( |
| 2886 | exp, | 2887 | exp, |
| 2887 | try Module.ErrorMsg.create(self.base.allocator, decl.srcLoc(), "Unimplemented: ExportOptions.section", .{}), | 2888 | try Module.ErrorMsg.create(self.base.allocator, decl.srcLoc(mod), "Unimplemented: ExportOptions.section", .{}), |
| 2888 | ); | 2889 | ); |
| 2889 | continue; | 2890 | continue; |
| 2890 | } | 2891 | } |
| ... | @@ -2900,10 +2901,10 @@ pub fn updateDeclExports( | ... | @@ -2900,10 +2901,10 @@ pub fn updateDeclExports( |
| 2900 | }, | 2901 | }, |
| 2901 | .Weak => elf.STB_WEAK, | 2902 | .Weak => elf.STB_WEAK, |
| 2902 | .LinkOnce => { | 2903 | .LinkOnce => { |
| 2903 | try module.failed_exports.ensureUnusedCapacity(module.gpa, 1); | 2904 | try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1); |
| 2904 | module.failed_exports.putAssumeCapacityNoClobber( | 2905 | mod.failed_exports.putAssumeCapacityNoClobber( |
| 2905 | exp, | 2906 | exp, |
| 2906 | try Module.ErrorMsg.create(self.base.allocator, decl.srcLoc(), "Unimplemented: GlobalLinkage.LinkOnce", .{}), | 2907 | try Module.ErrorMsg.create(self.base.allocator, decl.srcLoc(mod), "Unimplemented: GlobalLinkage.LinkOnce", .{}), |
| 2907 | ); | 2908 | ); |
| 2908 | continue; | 2909 | continue; |
| 2909 | }, | 2910 | }, |
src/link/MachO.zig+42-42| ... | @@ -1847,18 +1847,18 @@ fn addStubEntry(self: *MachO, target: SymbolWithLoc) !void { | ... | @@ -1847,18 +1847,18 @@ fn addStubEntry(self: *MachO, target: SymbolWithLoc) !void { |
| 1847 | self.markRelocsDirtyByTarget(target); | 1847 | self.markRelocsDirtyByTarget(target); |
| 1848 | } | 1848 | } |
| 1849 | 1849 | ||
| 1850 | pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void { | 1850 | pub fn updateFunc(self: *MachO, mod: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void { |
| 1851 | if (build_options.skip_non_native and builtin.object_format != .macho) { | 1851 | if (build_options.skip_non_native and builtin.object_format != .macho) { |
| 1852 | @panic("Attempted to compile for object format that was disabled by build configuration"); | 1852 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 1853 | } | 1853 | } |
| 1854 | if (build_options.have_llvm) { | 1854 | if (build_options.have_llvm) { |
| 1855 | if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(module, func, air, liveness); | 1855 | if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func, air, liveness); |
| 1856 | } | 1856 | } |
| 1857 | const tracy = trace(@src()); | 1857 | const tracy = trace(@src()); |
| 1858 | defer tracy.end(); | 1858 | defer tracy.end(); |
| 1859 | 1859 | ||
| 1860 | const decl_index = func.owner_decl; | 1860 | const decl_index = func.owner_decl; |
| 1861 | const decl = module.declPtr(decl_index); | 1861 | const decl = mod.declPtr(decl_index); |
| 1862 | 1862 | ||
| 1863 | const atom_index = try self.getOrCreateAtomForDecl(decl_index); | 1863 | const atom_index = try self.getOrCreateAtomForDecl(decl_index); |
| 1864 | self.freeUnnamedConsts(decl_index); | 1864 | self.freeUnnamedConsts(decl_index); |
| ... | @@ -1868,23 +1868,23 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv | ... | @@ -1868,23 +1868,23 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv |
| 1868 | defer code_buffer.deinit(); | 1868 | defer code_buffer.deinit(); |
| 1869 | 1869 | ||
| 1870 | var decl_state = if (self.d_sym) |*d_sym| | 1870 | var decl_state = if (self.d_sym) |*d_sym| |
| 1871 | try d_sym.dwarf.initDeclState(module, decl_index) | 1871 | try d_sym.dwarf.initDeclState(mod, decl_index) |
| 1872 | else | 1872 | else |
| 1873 | null; | 1873 | null; |
| 1874 | defer if (decl_state) |*ds| ds.deinit(); | 1874 | defer if (decl_state) |*ds| ds.deinit(); |
| 1875 | 1875 | ||
| 1876 | const res = if (decl_state) |*ds| | 1876 | const res = if (decl_state) |*ds| |
| 1877 | try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .{ | 1877 | try codegen.generateFunction(&self.base, decl.srcLoc(mod), func, air, liveness, &code_buffer, .{ |
| 1878 | .dwarf = ds, | 1878 | .dwarf = ds, |
| 1879 | }) | 1879 | }) |
| 1880 | else | 1880 | else |
| 1881 | try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .none); | 1881 | try codegen.generateFunction(&self.base, decl.srcLoc(mod), func, air, liveness, &code_buffer, .none); |
| 1882 | 1882 | ||
| 1883 | var code = switch (res) { | 1883 | var code = switch (res) { |
| 1884 | .ok => code_buffer.items, | 1884 | .ok => code_buffer.items, |
| 1885 | .fail => |em| { | 1885 | .fail => |em| { |
| 1886 | decl.analysis = .codegen_failure; | 1886 | decl.analysis = .codegen_failure; |
| 1887 | try module.failed_decls.put(module.gpa, decl_index, em); | 1887 | try mod.failed_decls.put(mod.gpa, decl_index, em); |
| 1888 | return; | 1888 | return; |
| 1889 | }, | 1889 | }, |
| 1890 | }; | 1890 | }; |
| ... | @@ -1893,7 +1893,7 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv | ... | @@ -1893,7 +1893,7 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv |
| 1893 | 1893 | ||
| 1894 | if (decl_state) |*ds| { | 1894 | if (decl_state) |*ds| { |
| 1895 | try self.d_sym.?.dwarf.commitDeclState( | 1895 | try self.d_sym.?.dwarf.commitDeclState( |
| 1896 | module, | 1896 | mod, |
| 1897 | decl_index, | 1897 | decl_index, |
| 1898 | addr, | 1898 | addr, |
| 1899 | self.getAtom(atom_index).size, | 1899 | self.getAtom(atom_index).size, |
| ... | @@ -1903,7 +1903,7 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv | ... | @@ -1903,7 +1903,7 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv |
| 1903 | 1903 | ||
| 1904 | // Since we updated the vaddr and the size, each corresponding export symbol also | 1904 | // Since we updated the vaddr and the size, each corresponding export symbol also |
| 1905 | // needs to be updated. | 1905 | // needs to be updated. |
| 1906 | try self.updateDeclExports(module, decl_index, module.getDeclExports(decl_index)); | 1906 | try self.updateDeclExports(mod, decl_index, mod.getDeclExports(decl_index)); |
| 1907 | } | 1907 | } |
| 1908 | 1908 | ||
| 1909 | pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Module.Decl.Index) !u32 { | 1909 | pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Module.Decl.Index) !u32 { |
| ... | @@ -1912,15 +1912,15 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Modu | ... | @@ -1912,15 +1912,15 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Modu |
| 1912 | var code_buffer = std.ArrayList(u8).init(gpa); | 1912 | var code_buffer = std.ArrayList(u8).init(gpa); |
| 1913 | defer code_buffer.deinit(); | 1913 | defer code_buffer.deinit(); |
| 1914 | 1914 | ||
| 1915 | const module = self.base.options.module.?; | 1915 | const mod = self.base.options.module.?; |
| 1916 | const gop = try self.unnamed_const_atoms.getOrPut(gpa, decl_index); | 1916 | const gop = try self.unnamed_const_atoms.getOrPut(gpa, decl_index); |
| 1917 | if (!gop.found_existing) { | 1917 | if (!gop.found_existing) { |
| 1918 | gop.value_ptr.* = .{}; | 1918 | gop.value_ptr.* = .{}; |
| 1919 | } | 1919 | } |
| 1920 | const unnamed_consts = gop.value_ptr; | 1920 | const unnamed_consts = gop.value_ptr; |
| 1921 | 1921 | ||
| 1922 | const decl = module.declPtr(decl_index); | 1922 | const decl = mod.declPtr(decl_index); |
| 1923 | const decl_name = try decl.getFullyQualifiedName(module); | 1923 | const decl_name = try decl.getFullyQualifiedName(mod); |
| 1924 | defer gpa.free(decl_name); | 1924 | defer gpa.free(decl_name); |
| 1925 | 1925 | ||
| 1926 | const name_str_index = blk: { | 1926 | const name_str_index = blk: { |
| ... | @@ -1935,20 +1935,19 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Modu | ... | @@ -1935,20 +1935,19 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Modu |
| 1935 | 1935 | ||
| 1936 | const atom_index = try self.createAtom(); | 1936 | const atom_index = try self.createAtom(); |
| 1937 | 1937 | ||
| 1938 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(), typed_value, &code_buffer, .none, .{ | 1938 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), typed_value, &code_buffer, .none, .{ |
| 1939 | .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?, | 1939 | .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?, |
| 1940 | }); | 1940 | }); |
| 1941 | var code = switch (res) { | 1941 | var code = switch (res) { |
| 1942 | .ok => code_buffer.items, | 1942 | .ok => code_buffer.items, |
| 1943 | .fail => |em| { | 1943 | .fail => |em| { |
| 1944 | decl.analysis = .codegen_failure; | 1944 | decl.analysis = .codegen_failure; |
| 1945 | try module.failed_decls.put(module.gpa, decl_index, em); | 1945 | try mod.failed_decls.put(mod.gpa, decl_index, em); |
| 1946 | log.err("{s}", .{em.msg}); | 1946 | log.err("{s}", .{em.msg}); |
| 1947 | return error.CodegenFail; | 1947 | return error.CodegenFail; |
| 1948 | }, | 1948 | }, |
| 1949 | }; | 1949 | }; |
| 1950 | 1950 | ||
| 1951 | const mod = self.base.options.module.?; | ||
| 1952 | const required_alignment = typed_value.ty.abiAlignment(mod); | 1951 | const required_alignment = typed_value.ty.abiAlignment(mod); |
| 1953 | const atom = self.getAtomPtr(atom_index); | 1952 | const atom = self.getAtomPtr(atom_index); |
| 1954 | atom.size = code.len; | 1953 | atom.size = code.len; |
| ... | @@ -1972,17 +1971,17 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Modu | ... | @@ -1972,17 +1971,17 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Modu |
| 1972 | return atom.getSymbolIndex().?; | 1971 | return atom.getSymbolIndex().?; |
| 1973 | } | 1972 | } |
| 1974 | 1973 | ||
| 1975 | pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index) !void { | 1974 | pub fn updateDecl(self: *MachO, mod: *Module, decl_index: Module.Decl.Index) !void { |
| 1976 | if (build_options.skip_non_native and builtin.object_format != .macho) { | 1975 | if (build_options.skip_non_native and builtin.object_format != .macho) { |
| 1977 | @panic("Attempted to compile for object format that was disabled by build configuration"); | 1976 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 1978 | } | 1977 | } |
| 1979 | if (build_options.have_llvm) { | 1978 | if (build_options.have_llvm) { |
| 1980 | if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(module, decl_index); | 1979 | if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index); |
| 1981 | } | 1980 | } |
| 1982 | const tracy = trace(@src()); | 1981 | const tracy = trace(@src()); |
| 1983 | defer tracy.end(); | 1982 | defer tracy.end(); |
| 1984 | 1983 | ||
| 1985 | const decl = module.declPtr(decl_index); | 1984 | const decl = mod.declPtr(decl_index); |
| 1986 | 1985 | ||
| 1987 | if (decl.val.tag() == .extern_fn) { | 1986 | if (decl.val.tag() == .extern_fn) { |
| 1988 | return; // TODO Should we do more when front-end analyzed extern decl? | 1987 | return; // TODO Should we do more when front-end analyzed extern decl? |
| ... | @@ -1998,7 +1997,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index) | ... | @@ -1998,7 +1997,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index) |
| 1998 | payload.data.is_threadlocal and !self.base.options.single_threaded | 1997 | payload.data.is_threadlocal and !self.base.options.single_threaded |
| 1999 | else | 1998 | else |
| 2000 | false; | 1999 | false; |
| 2001 | if (is_threadlocal) return self.updateThreadlocalVariable(module, decl_index); | 2000 | if (is_threadlocal) return self.updateThreadlocalVariable(mod, decl_index); |
| 2002 | 2001 | ||
| 2003 | const atom_index = try self.getOrCreateAtomForDecl(decl_index); | 2002 | const atom_index = try self.getOrCreateAtomForDecl(decl_index); |
| 2004 | const sym_index = self.getAtom(atom_index).getSymbolIndex().?; | 2003 | const sym_index = self.getAtom(atom_index).getSymbolIndex().?; |
| ... | @@ -2008,14 +2007,14 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index) | ... | @@ -2008,14 +2007,14 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index) |
| 2008 | defer code_buffer.deinit(); | 2007 | defer code_buffer.deinit(); |
| 2009 | 2008 | ||
| 2010 | var decl_state: ?Dwarf.DeclState = if (self.d_sym) |*d_sym| | 2009 | var decl_state: ?Dwarf.DeclState = if (self.d_sym) |*d_sym| |
| 2011 | try d_sym.dwarf.initDeclState(module, decl_index) | 2010 | try d_sym.dwarf.initDeclState(mod, decl_index) |
| 2012 | else | 2011 | else |
| 2013 | null; | 2012 | null; |
| 2014 | defer if (decl_state) |*ds| ds.deinit(); | 2013 | defer if (decl_state) |*ds| ds.deinit(); |
| 2015 | 2014 | ||
| 2016 | const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val; | 2015 | const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val; |
| 2017 | const res = if (decl_state) |*ds| | 2016 | const res = if (decl_state) |*ds| |
| 2018 | try codegen.generateSymbol(&self.base, decl.srcLoc(), .{ | 2017 | try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{ |
| 2019 | .ty = decl.ty, | 2018 | .ty = decl.ty, |
| 2020 | .val = decl_val, | 2019 | .val = decl_val, |
| 2021 | }, &code_buffer, .{ | 2020 | }, &code_buffer, .{ |
| ... | @@ -2024,7 +2023,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index) | ... | @@ -2024,7 +2023,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index) |
| 2024 | .parent_atom_index = sym_index, | 2023 | .parent_atom_index = sym_index, |
| 2025 | }) | 2024 | }) |
| 2026 | else | 2025 | else |
| 2027 | try codegen.generateSymbol(&self.base, decl.srcLoc(), .{ | 2026 | try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{ |
| 2028 | .ty = decl.ty, | 2027 | .ty = decl.ty, |
| 2029 | .val = decl_val, | 2028 | .val = decl_val, |
| 2030 | }, &code_buffer, .none, .{ | 2029 | }, &code_buffer, .none, .{ |
| ... | @@ -2035,7 +2034,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index) | ... | @@ -2035,7 +2034,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index) |
| 2035 | .ok => code_buffer.items, | 2034 | .ok => code_buffer.items, |
| 2036 | .fail => |em| { | 2035 | .fail => |em| { |
| 2037 | decl.analysis = .codegen_failure; | 2036 | decl.analysis = .codegen_failure; |
| 2038 | try module.failed_decls.put(module.gpa, decl_index, em); | 2037 | try mod.failed_decls.put(mod.gpa, decl_index, em); |
| 2039 | return; | 2038 | return; |
| 2040 | }, | 2039 | }, |
| 2041 | }; | 2040 | }; |
| ... | @@ -2043,7 +2042,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index) | ... | @@ -2043,7 +2042,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index) |
| 2043 | 2042 | ||
| 2044 | if (decl_state) |*ds| { | 2043 | if (decl_state) |*ds| { |
| 2045 | try self.d_sym.?.dwarf.commitDeclState( | 2044 | try self.d_sym.?.dwarf.commitDeclState( |
| 2046 | module, | 2045 | mod, |
| 2047 | decl_index, | 2046 | decl_index, |
| 2048 | addr, | 2047 | addr, |
| 2049 | self.getAtom(atom_index).size, | 2048 | self.getAtom(atom_index).size, |
| ... | @@ -2053,7 +2052,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index) | ... | @@ -2053,7 +2052,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index) |
| 2053 | 2052 | ||
| 2054 | // Since we updated the vaddr and the size, each corresponding export symbol also | 2053 | // Since we updated the vaddr and the size, each corresponding export symbol also |
| 2055 | // needs to be updated. | 2054 | // needs to be updated. |
| 2056 | try self.updateDeclExports(module, decl_index, module.getDeclExports(decl_index)); | 2055 | try self.updateDeclExports(mod, decl_index, mod.getDeclExports(decl_index)); |
| 2057 | } | 2056 | } |
| 2058 | 2057 | ||
| 2059 | fn updateLazySymbolAtom( | 2058 | fn updateLazySymbolAtom( |
| ... | @@ -2082,8 +2081,8 @@ fn updateLazySymbolAtom( | ... | @@ -2082,8 +2081,8 @@ fn updateLazySymbolAtom( |
| 2082 | const atom = self.getAtomPtr(atom_index); | 2081 | const atom = self.getAtomPtr(atom_index); |
| 2083 | const local_sym_index = atom.getSymbolIndex().?; | 2082 | const local_sym_index = atom.getSymbolIndex().?; |
| 2084 | 2083 | ||
| 2085 | const src = if (sym.ty.getOwnerDeclOrNull()) |owner_decl| | 2084 | const src = if (sym.ty.getOwnerDeclOrNull(mod)) |owner_decl| |
| 2086 | mod.declPtr(owner_decl).srcLoc() | 2085 | mod.declPtr(owner_decl).srcLoc(mod) |
| 2087 | else | 2086 | else |
| 2088 | Module.SrcLoc{ | 2087 | Module.SrcLoc{ |
| 2089 | .file_scope = undefined, | 2088 | .file_scope = undefined, |
| ... | @@ -2127,7 +2126,8 @@ fn updateLazySymbolAtom( | ... | @@ -2127,7 +2126,8 @@ fn updateLazySymbolAtom( |
| 2127 | } | 2126 | } |
| 2128 | 2127 | ||
| 2129 | pub fn getOrCreateAtomForLazySymbol(self: *MachO, sym: File.LazySymbol) !Atom.Index { | 2128 | pub fn getOrCreateAtomForLazySymbol(self: *MachO, sym: File.LazySymbol) !Atom.Index { |
| 2130 | const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl()); | 2129 | const mod = self.base.options.module.?; |
| 2130 | const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl(mod)); | ||
| 2131 | errdefer _ = if (!gop.found_existing) self.lazy_syms.pop(); | 2131 | errdefer _ = if (!gop.found_existing) self.lazy_syms.pop(); |
| 2132 | if (!gop.found_existing) gop.value_ptr.* = .{}; | 2132 | if (!gop.found_existing) gop.value_ptr.* = .{}; |
| 2133 | const metadata: struct { atom: *Atom.Index, state: *LazySymbolMetadata.State } = switch (sym.kind) { | 2133 | const metadata: struct { atom: *Atom.Index, state: *LazySymbolMetadata.State } = switch (sym.kind) { |
| ... | @@ -2145,7 +2145,7 @@ pub fn getOrCreateAtomForLazySymbol(self: *MachO, sym: File.LazySymbol) !Atom.In | ... | @@ -2145,7 +2145,7 @@ pub fn getOrCreateAtomForLazySymbol(self: *MachO, sym: File.LazySymbol) !Atom.In |
| 2145 | metadata.state.* = .pending_flush; | 2145 | metadata.state.* = .pending_flush; |
| 2146 | const atom = metadata.atom.*; | 2146 | const atom = metadata.atom.*; |
| 2147 | // anyerror needs to be deferred until flushModule | 2147 | // anyerror needs to be deferred until flushModule |
| 2148 | if (sym.getDecl() != .none) try self.updateLazySymbolAtom(sym, atom, switch (sym.kind) { | 2148 | if (sym.getDecl(mod) != .none) try self.updateLazySymbolAtom(sym, atom, switch (sym.kind) { |
| 2149 | .code => self.text_section_index.?, | 2149 | .code => self.text_section_index.?, |
| 2150 | .const_data => self.data_const_section_index.?, | 2150 | .const_data => self.data_const_section_index.?, |
| 2151 | }); | 2151 | }); |
| ... | @@ -2179,7 +2179,7 @@ fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: Module.D | ... | @@ -2179,7 +2179,7 @@ fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: Module.D |
| 2179 | const decl_metadata = self.decls.get(decl_index).?; | 2179 | const decl_metadata = self.decls.get(decl_index).?; |
| 2180 | const decl_val = decl.val.castTag(.variable).?.data.init; | 2180 | const decl_val = decl.val.castTag(.variable).?.data.init; |
| 2181 | const res = if (decl_state) |*ds| | 2181 | const res = if (decl_state) |*ds| |
| 2182 | try codegen.generateSymbol(&self.base, decl.srcLoc(), .{ | 2182 | try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{ |
| 2183 | .ty = decl.ty, | 2183 | .ty = decl.ty, |
| 2184 | .val = decl_val, | 2184 | .val = decl_val, |
| 2185 | }, &code_buffer, .{ | 2185 | }, &code_buffer, .{ |
| ... | @@ -2188,7 +2188,7 @@ fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: Module.D | ... | @@ -2188,7 +2188,7 @@ fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: Module.D |
| 2188 | .parent_atom_index = init_sym_index, | 2188 | .parent_atom_index = init_sym_index, |
| 2189 | }) | 2189 | }) |
| 2190 | else | 2190 | else |
| 2191 | try codegen.generateSymbol(&self.base, decl.srcLoc(), .{ | 2191 | try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{ |
| 2192 | .ty = decl.ty, | 2192 | .ty = decl.ty, |
| 2193 | .val = decl_val, | 2193 | .val = decl_val, |
| 2194 | }, &code_buffer, .none, .{ | 2194 | }, &code_buffer, .none, .{ |
| ... | @@ -2379,7 +2379,7 @@ pub fn updateDeclLineNumber(self: *MachO, module: *Module, decl_index: Module.De | ... | @@ -2379,7 +2379,7 @@ pub fn updateDeclLineNumber(self: *MachO, module: *Module, decl_index: Module.De |
| 2379 | 2379 | ||
| 2380 | pub fn updateDeclExports( | 2380 | pub fn updateDeclExports( |
| 2381 | self: *MachO, | 2381 | self: *MachO, |
| 2382 | module: *Module, | 2382 | mod: *Module, |
| 2383 | decl_index: Module.Decl.Index, | 2383 | decl_index: Module.Decl.Index, |
| 2384 | exports: []const *Module.Export, | 2384 | exports: []const *Module.Export, |
| 2385 | ) File.UpdateDeclExportsError!void { | 2385 | ) File.UpdateDeclExportsError!void { |
| ... | @@ -2388,7 +2388,7 @@ pub fn updateDeclExports( | ... | @@ -2388,7 +2388,7 @@ pub fn updateDeclExports( |
| 2388 | } | 2388 | } |
| 2389 | if (build_options.have_llvm) { | 2389 | if (build_options.have_llvm) { |
| 2390 | if (self.llvm_object) |llvm_object| | 2390 | if (self.llvm_object) |llvm_object| |
| 2391 | return llvm_object.updateDeclExports(module, decl_index, exports); | 2391 | return llvm_object.updateDeclExports(mod, decl_index, exports); |
| 2392 | } | 2392 | } |
| 2393 | 2393 | ||
| 2394 | const tracy = trace(@src()); | 2394 | const tracy = trace(@src()); |
| ... | @@ -2396,7 +2396,7 @@ pub fn updateDeclExports( | ... | @@ -2396,7 +2396,7 @@ pub fn updateDeclExports( |
| 2396 | 2396 | ||
| 2397 | const gpa = self.base.allocator; | 2397 | const gpa = self.base.allocator; |
| 2398 | 2398 | ||
| 2399 | const decl = module.declPtr(decl_index); | 2399 | const decl = mod.declPtr(decl_index); |
| 2400 | const atom_index = try self.getOrCreateAtomForDecl(decl_index); | 2400 | const atom_index = try self.getOrCreateAtomForDecl(decl_index); |
| 2401 | const atom = self.getAtom(atom_index); | 2401 | const atom = self.getAtom(atom_index); |
| 2402 | const decl_sym = atom.getSymbol(self); | 2402 | const decl_sym = atom.getSymbol(self); |
| ... | @@ -2410,12 +2410,12 @@ pub fn updateDeclExports( | ... | @@ -2410,12 +2410,12 @@ pub fn updateDeclExports( |
| 2410 | 2410 | ||
| 2411 | if (exp.options.section) |section_name| { | 2411 | if (exp.options.section) |section_name| { |
| 2412 | if (!mem.eql(u8, section_name, "__text")) { | 2412 | if (!mem.eql(u8, section_name, "__text")) { |
| 2413 | try module.failed_exports.putNoClobber( | 2413 | try mod.failed_exports.putNoClobber( |
| 2414 | module.gpa, | 2414 | mod.gpa, |
| 2415 | exp, | 2415 | exp, |
| 2416 | try Module.ErrorMsg.create( | 2416 | try Module.ErrorMsg.create( |
| 2417 | gpa, | 2417 | gpa, |
| 2418 | decl.srcLoc(), | 2418 | decl.srcLoc(mod), |
| 2419 | "Unimplemented: ExportOptions.section", | 2419 | "Unimplemented: ExportOptions.section", |
| 2420 | .{}, | 2420 | .{}, |
| 2421 | ), | 2421 | ), |
| ... | @@ -2425,12 +2425,12 @@ pub fn updateDeclExports( | ... | @@ -2425,12 +2425,12 @@ pub fn updateDeclExports( |
| 2425 | } | 2425 | } |
| 2426 | 2426 | ||
| 2427 | if (exp.options.linkage == .LinkOnce) { | 2427 | if (exp.options.linkage == .LinkOnce) { |
| 2428 | try module.failed_exports.putNoClobber( | 2428 | try mod.failed_exports.putNoClobber( |
| 2429 | module.gpa, | 2429 | mod.gpa, |
| 2430 | exp, | 2430 | exp, |
| 2431 | try Module.ErrorMsg.create( | 2431 | try Module.ErrorMsg.create( |
| 2432 | gpa, | 2432 | gpa, |
| 2433 | decl.srcLoc(), | 2433 | decl.srcLoc(mod), |
| 2434 | "Unimplemented: GlobalLinkage.LinkOnce", | 2434 | "Unimplemented: GlobalLinkage.LinkOnce", |
| 2435 | .{}, | 2435 | .{}, |
| 2436 | ), | 2436 | ), |
| ... | @@ -2474,9 +2474,9 @@ pub fn updateDeclExports( | ... | @@ -2474,9 +2474,9 @@ pub fn updateDeclExports( |
| 2474 | // TODO: this needs rethinking | 2474 | // TODO: this needs rethinking |
| 2475 | const global = self.getGlobal(exp_name).?; | 2475 | const global = self.getGlobal(exp_name).?; |
| 2476 | if (sym_loc.sym_index != global.sym_index and global.file != null) { | 2476 | if (sym_loc.sym_index != global.sym_index and global.file != null) { |
| 2477 | _ = try module.failed_exports.put(module.gpa, exp, try Module.ErrorMsg.create( | 2477 | _ = try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create( |
| 2478 | gpa, | 2478 | gpa, |
| 2479 | decl.srcLoc(), | 2479 | decl.srcLoc(mod), |
| 2480 | \\LinkError: symbol '{s}' defined multiple times | 2480 | \\LinkError: symbol '{s}' defined multiple times |
| 2481 | , | 2481 | , |
| 2482 | .{exp_name}, | 2482 | .{exp_name}, |
src/link/Plan9.zig+16-16| ... | @@ -213,14 +213,14 @@ fn putFn(self: *Plan9, decl_index: Module.Decl.Index, out: FnDeclOutput) !void { | ... | @@ -213,14 +213,14 @@ fn putFn(self: *Plan9, decl_index: Module.Decl.Index, out: FnDeclOutput) !void { |
| 213 | const gpa = self.base.allocator; | 213 | const gpa = self.base.allocator; |
| 214 | const mod = self.base.options.module.?; | 214 | const mod = self.base.options.module.?; |
| 215 | const decl = mod.declPtr(decl_index); | 215 | const decl = mod.declPtr(decl_index); |
| 216 | const fn_map_res = try self.fn_decl_table.getOrPut(gpa, decl.getFileScope()); | 216 | const fn_map_res = try self.fn_decl_table.getOrPut(gpa, decl.getFileScope(mod)); |
| 217 | if (fn_map_res.found_existing) { | 217 | if (fn_map_res.found_existing) { |
| 218 | if (try fn_map_res.value_ptr.functions.fetchPut(gpa, decl_index, out)) |old_entry| { | 218 | if (try fn_map_res.value_ptr.functions.fetchPut(gpa, decl_index, out)) |old_entry| { |
| 219 | gpa.free(old_entry.value.code); | 219 | gpa.free(old_entry.value.code); |
| 220 | gpa.free(old_entry.value.lineinfo); | 220 | gpa.free(old_entry.value.lineinfo); |
| 221 | } | 221 | } |
| 222 | } else { | 222 | } else { |
| 223 | const file = decl.getFileScope(); | 223 | const file = decl.getFileScope(mod); |
| 224 | const arena = self.path_arena.allocator(); | 224 | const arena = self.path_arena.allocator(); |
| 225 | // each file gets a symbol | 225 | // each file gets a symbol |
| 226 | fn_map_res.value_ptr.* = .{ | 226 | fn_map_res.value_ptr.* = .{ |
| ... | @@ -276,13 +276,13 @@ fn addPathComponents(self: *Plan9, path: []const u8, a: *std.ArrayList(u8)) !voi | ... | @@ -276,13 +276,13 @@ fn addPathComponents(self: *Plan9, path: []const u8, a: *std.ArrayList(u8)) !voi |
| 276 | } | 276 | } |
| 277 | } | 277 | } |
| 278 | 278 | ||
| 279 | pub fn updateFunc(self: *Plan9, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void { | 279 | pub fn updateFunc(self: *Plan9, mod: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void { |
| 280 | if (build_options.skip_non_native and builtin.object_format != .plan9) { | 280 | if (build_options.skip_non_native and builtin.object_format != .plan9) { |
| 281 | @panic("Attempted to compile for object format that was disabled by build configuration"); | 281 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 282 | } | 282 | } |
| 283 | 283 | ||
| 284 | const decl_index = func.owner_decl; | 284 | const decl_index = func.owner_decl; |
| 285 | const decl = module.declPtr(decl_index); | 285 | const decl = mod.declPtr(decl_index); |
| 286 | self.freeUnnamedConsts(decl_index); | 286 | self.freeUnnamedConsts(decl_index); |
| 287 | 287 | ||
| 288 | _ = try self.seeDecl(decl_index); | 288 | _ = try self.seeDecl(decl_index); |
| ... | @@ -298,7 +298,7 @@ pub fn updateFunc(self: *Plan9, module: *Module, func: *Module.Fn, air: Air, liv | ... | @@ -298,7 +298,7 @@ pub fn updateFunc(self: *Plan9, module: *Module, func: *Module.Fn, air: Air, liv |
| 298 | 298 | ||
| 299 | const res = try codegen.generateFunction( | 299 | const res = try codegen.generateFunction( |
| 300 | &self.base, | 300 | &self.base, |
| 301 | decl.srcLoc(), | 301 | decl.srcLoc(mod), |
| 302 | func, | 302 | func, |
| 303 | air, | 303 | air, |
| 304 | liveness, | 304 | liveness, |
| ... | @@ -316,7 +316,7 @@ pub fn updateFunc(self: *Plan9, module: *Module, func: *Module.Fn, air: Air, liv | ... | @@ -316,7 +316,7 @@ pub fn updateFunc(self: *Plan9, module: *Module, func: *Module.Fn, air: Air, liv |
| 316 | .ok => try code_buffer.toOwnedSlice(), | 316 | .ok => try code_buffer.toOwnedSlice(), |
| 317 | .fail => |em| { | 317 | .fail => |em| { |
| 318 | decl.analysis = .codegen_failure; | 318 | decl.analysis = .codegen_failure; |
| 319 | try module.failed_decls.put(module.gpa, decl_index, em); | 319 | try mod.failed_decls.put(mod.gpa, decl_index, em); |
| 320 | return; | 320 | return; |
| 321 | }, | 321 | }, |
| 322 | }; | 322 | }; |
| ... | @@ -366,7 +366,7 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I | ... | @@ -366,7 +366,7 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I |
| 366 | }; | 366 | }; |
| 367 | self.syms.items[info.sym_index.?] = sym; | 367 | self.syms.items[info.sym_index.?] = sym; |
| 368 | 368 | ||
| 369 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(), tv, &code_buffer, .{ | 369 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), tv, &code_buffer, .{ |
| 370 | .none = {}, | 370 | .none = {}, |
| 371 | }, .{ | 371 | }, .{ |
| 372 | .parent_atom_index = @enumToInt(decl_index), | 372 | .parent_atom_index = @enumToInt(decl_index), |
| ... | @@ -388,8 +388,8 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I | ... | @@ -388,8 +388,8 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I |
| 388 | return @intCast(u32, info.got_index.?); | 388 | return @intCast(u32, info.got_index.?); |
| 389 | } | 389 | } |
| 390 | 390 | ||
| 391 | pub fn updateDecl(self: *Plan9, module: *Module, decl_index: Module.Decl.Index) !void { | 391 | pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: Module.Decl.Index) !void { |
| 392 | const decl = module.declPtr(decl_index); | 392 | const decl = mod.declPtr(decl_index); |
| 393 | 393 | ||
| 394 | if (decl.val.tag() == .extern_fn) { | 394 | if (decl.val.tag() == .extern_fn) { |
| 395 | return; // TODO Should we do more when front-end analyzed extern decl? | 395 | return; // TODO Should we do more when front-end analyzed extern decl? |
| ... | @@ -409,7 +409,7 @@ pub fn updateDecl(self: *Plan9, module: *Module, decl_index: Module.Decl.Index) | ... | @@ -409,7 +409,7 @@ pub fn updateDecl(self: *Plan9, module: *Module, decl_index: Module.Decl.Index) |
| 409 | defer code_buffer.deinit(); | 409 | defer code_buffer.deinit(); |
| 410 | const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val; | 410 | const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val; |
| 411 | // TODO we need the symbol index for symbol in the table of locals for the containing atom | 411 | // TODO we need the symbol index for symbol in the table of locals for the containing atom |
| 412 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(), .{ | 412 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{ |
| 413 | .ty = decl.ty, | 413 | .ty = decl.ty, |
| 414 | .val = decl_val, | 414 | .val = decl_val, |
| 415 | }, &code_buffer, .{ .none = {} }, .{ | 415 | }, &code_buffer, .{ .none = {} }, .{ |
| ... | @@ -419,7 +419,7 @@ pub fn updateDecl(self: *Plan9, module: *Module, decl_index: Module.Decl.Index) | ... | @@ -419,7 +419,7 @@ pub fn updateDecl(self: *Plan9, module: *Module, decl_index: Module.Decl.Index) |
| 419 | .ok => code_buffer.items, | 419 | .ok => code_buffer.items, |
| 420 | .fail => |em| { | 420 | .fail => |em| { |
| 421 | decl.analysis = .codegen_failure; | 421 | decl.analysis = .codegen_failure; |
| 422 | try module.failed_decls.put(module.gpa, decl_index, em); | 422 | try mod.failed_decls.put(mod.gpa, decl_index, em); |
| 423 | return; | 423 | return; |
| 424 | }, | 424 | }, |
| 425 | }; | 425 | }; |
| ... | @@ -707,7 +707,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No | ... | @@ -707,7 +707,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No |
| 707 | const code = blk: { | 707 | const code = blk: { |
| 708 | const is_fn = source_decl.ty.zigTypeTag(mod) == .Fn; | 708 | const is_fn = source_decl.ty.zigTypeTag(mod) == .Fn; |
| 709 | if (is_fn) { | 709 | if (is_fn) { |
| 710 | const table = self.fn_decl_table.get(source_decl.getFileScope()).?.functions; | 710 | const table = self.fn_decl_table.get(source_decl.getFileScope(mod)).?.functions; |
| 711 | const output = table.get(source_decl_index).?; | 711 | const output = table.get(source_decl_index).?; |
| 712 | break :blk output.code; | 712 | break :blk output.code; |
| 713 | } else { | 713 | } else { |
| ... | @@ -729,7 +729,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No | ... | @@ -729,7 +729,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No |
| 729 | } | 729 | } |
| 730 | fn addDeclExports( | 730 | fn addDeclExports( |
| 731 | self: *Plan9, | 731 | self: *Plan9, |
| 732 | module: *Module, | 732 | mod: *Module, |
| 733 | decl_index: Module.Decl.Index, | 733 | decl_index: Module.Decl.Index, |
| 734 | exports: []const *Module.Export, | 734 | exports: []const *Module.Export, |
| 735 | ) !void { | 735 | ) !void { |
| ... | @@ -740,9 +740,9 @@ fn addDeclExports( | ... | @@ -740,9 +740,9 @@ fn addDeclExports( |
| 740 | // plan9 does not support custom sections | 740 | // plan9 does not support custom sections |
| 741 | if (exp.options.section) |section_name| { | 741 | if (exp.options.section) |section_name| { |
| 742 | if (!mem.eql(u8, section_name, ".text") or !mem.eql(u8, section_name, ".data")) { | 742 | if (!mem.eql(u8, section_name, ".text") or !mem.eql(u8, section_name, ".data")) { |
| 743 | try module.failed_exports.put(module.gpa, exp, try Module.ErrorMsg.create( | 743 | try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create( |
| 744 | self.base.allocator, | 744 | self.base.allocator, |
| 745 | module.declPtr(decl_index).srcLoc(), | 745 | mod.declPtr(decl_index).srcLoc(mod), |
| 746 | "plan9 does not support extra sections", | 746 | "plan9 does not support extra sections", |
| 747 | .{}, | 747 | .{}, |
| 748 | )); | 748 | )); |
| ... | @@ -773,7 +773,7 @@ pub fn freeDecl(self: *Plan9, decl_index: Module.Decl.Index) void { | ... | @@ -773,7 +773,7 @@ pub fn freeDecl(self: *Plan9, decl_index: Module.Decl.Index) void { |
| 773 | const decl = mod.declPtr(decl_index); | 773 | const decl = mod.declPtr(decl_index); |
| 774 | const is_fn = (decl.val.tag() == .function); | 774 | const is_fn = (decl.val.tag() == .function); |
| 775 | if (is_fn) { | 775 | if (is_fn) { |
| 776 | var symidx_and_submap = self.fn_decl_table.get(decl.getFileScope()).?; | 776 | var symidx_and_submap = self.fn_decl_table.get(decl.getFileScope(mod)).?; |
| 777 | var submap = symidx_and_submap.functions; | 777 | var submap = symidx_and_submap.functions; |
| 778 | if (submap.fetchSwapRemove(decl_index)) |removed_entry| { | 778 | if (submap.fetchSwapRemove(decl_index)) |removed_entry| { |
| 779 | self.base.allocator.free(removed_entry.value.code); | 779 | self.base.allocator.free(removed_entry.value.code); |
src/link/Wasm.zig+7-7| ... | @@ -1348,7 +1348,7 @@ pub fn updateFunc(wasm: *Wasm, mod: *Module, func: *Module.Fn, air: Air, livenes | ... | @@ -1348,7 +1348,7 @@ pub fn updateFunc(wasm: *Wasm, mod: *Module, func: *Module.Fn, air: Air, livenes |
| 1348 | defer code_writer.deinit(); | 1348 | defer code_writer.deinit(); |
| 1349 | // const result = try codegen.generateFunction( | 1349 | // const result = try codegen.generateFunction( |
| 1350 | // &wasm.base, | 1350 | // &wasm.base, |
| 1351 | // decl.srcLoc(), | 1351 | // decl.srcLoc(mod), |
| 1352 | // func, | 1352 | // func, |
| 1353 | // air, | 1353 | // air, |
| 1354 | // liveness, | 1354 | // liveness, |
| ... | @@ -1357,7 +1357,7 @@ pub fn updateFunc(wasm: *Wasm, mod: *Module, func: *Module.Fn, air: Air, livenes | ... | @@ -1357,7 +1357,7 @@ pub fn updateFunc(wasm: *Wasm, mod: *Module, func: *Module.Fn, air: Air, livenes |
| 1357 | // ); | 1357 | // ); |
| 1358 | const result = try codegen.generateFunction( | 1358 | const result = try codegen.generateFunction( |
| 1359 | &wasm.base, | 1359 | &wasm.base, |
| 1360 | decl.srcLoc(), | 1360 | decl.srcLoc(mod), |
| 1361 | func, | 1361 | func, |
| 1362 | air, | 1362 | air, |
| 1363 | liveness, | 1363 | liveness, |
| ... | @@ -1425,7 +1425,7 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi | ... | @@ -1425,7 +1425,7 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi |
| 1425 | 1425 | ||
| 1426 | const res = try codegen.generateSymbol( | 1426 | const res = try codegen.generateSymbol( |
| 1427 | &wasm.base, | 1427 | &wasm.base, |
| 1428 | decl.srcLoc(), | 1428 | decl.srcLoc(mod), |
| 1429 | .{ .ty = decl.ty, .val = val }, | 1429 | .{ .ty = decl.ty, .val = val }, |
| 1430 | &code_writer, | 1430 | &code_writer, |
| 1431 | .none, | 1431 | .none, |
| ... | @@ -1554,7 +1554,7 @@ pub fn lowerUnnamedConst(wasm: *Wasm, tv: TypedValue, decl_index: Module.Decl.In | ... | @@ -1554,7 +1554,7 @@ pub fn lowerUnnamedConst(wasm: *Wasm, tv: TypedValue, decl_index: Module.Decl.In |
| 1554 | 1554 | ||
| 1555 | const result = try codegen.generateSymbol( | 1555 | const result = try codegen.generateSymbol( |
| 1556 | &wasm.base, | 1556 | &wasm.base, |
| 1557 | decl.srcLoc(), | 1557 | decl.srcLoc(mod), |
| 1558 | tv, | 1558 | tv, |
| 1559 | &value_bytes, | 1559 | &value_bytes, |
| 1560 | .none, | 1560 | .none, |
| ... | @@ -1693,7 +1693,7 @@ pub fn updateDeclExports( | ... | @@ -1693,7 +1693,7 @@ pub fn updateDeclExports( |
| 1693 | if (exp.options.section) |section| { | 1693 | if (exp.options.section) |section| { |
| 1694 | try mod.failed_exports.putNoClobber(mod.gpa, exp, try Module.ErrorMsg.create( | 1694 | try mod.failed_exports.putNoClobber(mod.gpa, exp, try Module.ErrorMsg.create( |
| 1695 | mod.gpa, | 1695 | mod.gpa, |
| 1696 | decl.srcLoc(), | 1696 | decl.srcLoc(mod), |
| 1697 | "Unimplemented: ExportOptions.section '{s}'", | 1697 | "Unimplemented: ExportOptions.section '{s}'", |
| 1698 | .{section}, | 1698 | .{section}, |
| 1699 | )); | 1699 | )); |
| ... | @@ -1712,7 +1712,7 @@ pub fn updateDeclExports( | ... | @@ -1712,7 +1712,7 @@ pub fn updateDeclExports( |
| 1712 | if (!exp_is_weak and !existing_sym.isWeak()) { | 1712 | if (!exp_is_weak and !existing_sym.isWeak()) { |
| 1713 | try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create( | 1713 | try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create( |
| 1714 | mod.gpa, | 1714 | mod.gpa, |
| 1715 | decl.srcLoc(), | 1715 | decl.srcLoc(mod), |
| 1716 | \\LinkError: symbol '{s}' defined multiple times | 1716 | \\LinkError: symbol '{s}' defined multiple times |
| 1717 | \\ first definition in '{s}' | 1717 | \\ first definition in '{s}' |
| 1718 | \\ next definition in '{s}' | 1718 | \\ next definition in '{s}' |
| ... | @@ -1745,7 +1745,7 @@ pub fn updateDeclExports( | ... | @@ -1745,7 +1745,7 @@ pub fn updateDeclExports( |
| 1745 | .LinkOnce => { | 1745 | .LinkOnce => { |
| 1746 | try mod.failed_exports.putNoClobber(mod.gpa, exp, try Module.ErrorMsg.create( | 1746 | try mod.failed_exports.putNoClobber(mod.gpa, exp, try Module.ErrorMsg.create( |
| 1747 | mod.gpa, | 1747 | mod.gpa, |
| 1748 | decl.srcLoc(), | 1748 | decl.srcLoc(mod), |
| 1749 | "Unimplemented: LinkOnce", | 1749 | "Unimplemented: LinkOnce", |
| 1750 | .{}, | 1750 | .{}, |
| 1751 | )); | 1751 | )); |
src/type.zig+103-118| ... | @@ -42,8 +42,6 @@ pub const Type = struct { | ... | @@ -42,8 +42,6 @@ pub const Type = struct { |
| 42 | .error_set_merged, | 42 | .error_set_merged, |
| 43 | => return .ErrorSet, | 43 | => return .ErrorSet, |
| 44 | 44 | ||
| 45 | .@"opaque" => return .Opaque, | ||
| 46 | |||
| 47 | .function => return .Fn, | 45 | .function => return .Fn, |
| 48 | 46 | ||
| 49 | .array, | 47 | .array, |
| ... | @@ -87,6 +85,7 @@ pub const Type = struct { | ... | @@ -87,6 +85,7 @@ pub const Type = struct { |
| 87 | .error_union_type => return .ErrorUnion, | 85 | .error_union_type => return .ErrorUnion, |
| 88 | .struct_type => return .Struct, | 86 | .struct_type => return .Struct, |
| 89 | .union_type => return .Union, | 87 | .union_type => return .Union, |
| 88 | .opaque_type => return .Opaque, | ||
| 90 | .simple_type => |s| switch (s) { | 89 | .simple_type => |s| switch (s) { |
| 91 | .f16, | 90 | .f16, |
| 92 | .f32, | 91 | .f32, |
| ... | @@ -361,12 +360,6 @@ pub const Type = struct { | ... | @@ -361,12 +360,6 @@ pub const Type = struct { |
| 361 | return true; | 360 | return true; |
| 362 | }, | 361 | }, |
| 363 | 362 | ||
| 364 | .@"opaque" => { | ||
| 365 | const opaque_obj_a = a.castTag(.@"opaque").?.data; | ||
| 366 | const opaque_obj_b = (b.castTag(.@"opaque") orelse return false).data; | ||
| 367 | return opaque_obj_a == opaque_obj_b; | ||
| 368 | }, | ||
| 369 | |||
| 370 | .function => { | 363 | .function => { |
| 371 | if (b.zigTypeTag(mod) != .Fn) return false; | 364 | if (b.zigTypeTag(mod) != .Fn) return false; |
| 372 | 365 | ||
| ... | @@ -649,12 +642,6 @@ pub const Type = struct { | ... | @@ -649,12 +642,6 @@ pub const Type = struct { |
| 649 | std.hash.autoHash(hasher, ies); | 642 | std.hash.autoHash(hasher, ies); |
| 650 | }, | 643 | }, |
| 651 | 644 | ||
| 652 | .@"opaque" => { | ||
| 653 | std.hash.autoHash(hasher, std.builtin.TypeId.Opaque); | ||
| 654 | const opaque_obj = ty.castTag(.@"opaque").?.data; | ||
| 655 | std.hash.autoHash(hasher, opaque_obj); | ||
| 656 | }, | ||
| 657 | |||
| 658 | .function => { | 645 | .function => { |
| 659 | std.hash.autoHash(hasher, std.builtin.TypeId.Fn); | 646 | std.hash.autoHash(hasher, std.builtin.TypeId.Fn); |
| 660 | 647 | ||
| ... | @@ -974,7 +961,6 @@ pub const Type = struct { | ... | @@ -974,7 +961,6 @@ pub const Type = struct { |
| 974 | .enum_simple => return self.copyPayloadShallow(allocator, Payload.EnumSimple), | 961 | .enum_simple => return self.copyPayloadShallow(allocator, Payload.EnumSimple), |
| 975 | .enum_numbered => return self.copyPayloadShallow(allocator, Payload.EnumNumbered), | 962 | .enum_numbered => return self.copyPayloadShallow(allocator, Payload.EnumNumbered), |
| 976 | .enum_full, .enum_nonexhaustive => return self.copyPayloadShallow(allocator, Payload.EnumFull), | 963 | .enum_full, .enum_nonexhaustive => return self.copyPayloadShallow(allocator, Payload.EnumFull), |
| 977 | .@"opaque" => return self.copyPayloadShallow(allocator, Payload.Opaque), | ||
| 978 | } | 964 | } |
| 979 | } | 965 | } |
| 980 | 966 | ||
| ... | @@ -1079,12 +1065,6 @@ pub const Type = struct { | ... | @@ -1079,12 +1065,6 @@ pub const Type = struct { |
| 1079 | @tagName(t), enum_numbered.owner_decl, | 1065 | @tagName(t), enum_numbered.owner_decl, |
| 1080 | }); | 1066 | }); |
| 1081 | }, | 1067 | }, |
| 1082 | .@"opaque" => { | ||
| 1083 | const opaque_obj = ty.castTag(.@"opaque").?.data; | ||
| 1084 | return writer.print("({s} decl={d})", .{ | ||
| 1085 | @tagName(t), opaque_obj.owner_decl, | ||
| 1086 | }); | ||
| 1087 | }, | ||
| 1088 | 1068 | ||
| 1089 | .function => { | 1069 | .function => { |
| 1090 | const payload = ty.castTag(.function).?.data; | 1070 | const payload = ty.castTag(.function).?.data; |
| ... | @@ -1303,11 +1283,6 @@ pub const Type = struct { | ... | @@ -1303,11 +1283,6 @@ pub const Type = struct { |
| 1303 | const decl = mod.declPtr(enum_numbered.owner_decl); | 1283 | const decl = mod.declPtr(enum_numbered.owner_decl); |
| 1304 | try decl.renderFullyQualifiedName(mod, writer); | 1284 | try decl.renderFullyQualifiedName(mod, writer); |
| 1305 | }, | 1285 | }, |
| 1306 | .@"opaque" => { | ||
| 1307 | const opaque_obj = ty.cast(Payload.Opaque).?.data; | ||
| 1308 | const decl = mod.declPtr(opaque_obj.owner_decl); | ||
| 1309 | try decl.renderFullyQualifiedName(mod, writer); | ||
| 1310 | }, | ||
| 1311 | 1286 | ||
| 1312 | .error_set_inferred => { | 1287 | .error_set_inferred => { |
| 1313 | const func = ty.castTag(.error_set_inferred).?.data.func; | 1288 | const func = ty.castTag(.error_set_inferred).?.data.func; |
| ... | @@ -1575,6 +1550,10 @@ pub const Type = struct { | ... | @@ -1575,6 +1550,10 @@ pub const Type = struct { |
| 1575 | .simple_type => |s| return writer.writeAll(@tagName(s)), | 1550 | .simple_type => |s| return writer.writeAll(@tagName(s)), |
| 1576 | .struct_type => @panic("TODO"), | 1551 | .struct_type => @panic("TODO"), |
| 1577 | .union_type => @panic("TODO"), | 1552 | .union_type => @panic("TODO"), |
| 1553 | .opaque_type => |opaque_type| { | ||
| 1554 | const decl = mod.declPtr(opaque_type.decl); | ||
| 1555 | try decl.renderFullyQualifiedName(mod, writer); | ||
| 1556 | }, | ||
| 1578 | 1557 | ||
| 1579 | // values, not types | 1558 | // values, not types |
| 1580 | .simple_value => unreachable, | 1559 | .simple_value => unreachable, |
| ... | @@ -1622,7 +1601,6 @@ pub const Type = struct { | ... | @@ -1622,7 +1601,6 @@ pub const Type = struct { |
| 1622 | .none => switch (ty.tag()) { | 1601 | .none => switch (ty.tag()) { |
| 1623 | .error_set_inferred, | 1602 | .error_set_inferred, |
| 1624 | 1603 | ||
| 1625 | .@"opaque", | ||
| 1626 | .error_set_single, | 1604 | .error_set_single, |
| 1627 | .error_union, | 1605 | .error_union, |
| 1628 | .error_set, | 1606 | .error_set, |
| ... | @@ -1759,8 +1737,8 @@ pub const Type = struct { | ... | @@ -1759,8 +1737,8 @@ pub const Type = struct { |
| 1759 | .inferred_alloc_const => unreachable, | 1737 | .inferred_alloc_const => unreachable, |
| 1760 | .inferred_alloc_mut => unreachable, | 1738 | .inferred_alloc_mut => unreachable, |
| 1761 | }, | 1739 | }, |
| 1762 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 1740 | else => return switch (mod.intern_pool.indexToKey(ty.ip_index)) { |
| 1763 | .int_type => |int_type| return int_type.bits != 0, | 1741 | .int_type => |int_type| int_type.bits != 0, |
| 1764 | .ptr_type => |ptr_type| { | 1742 | .ptr_type => |ptr_type| { |
| 1765 | // Pointers to zero-bit types still have a runtime address; however, pointers | 1743 | // Pointers to zero-bit types still have a runtime address; however, pointers |
| 1766 | // to comptime-only types do not, with the exception of function pointers. | 1744 | // to comptime-only types do not, with the exception of function pointers. |
| ... | @@ -1797,7 +1775,7 @@ pub const Type = struct { | ... | @@ -1797,7 +1775,7 @@ pub const Type = struct { |
| 1797 | } | 1775 | } |
| 1798 | }, | 1776 | }, |
| 1799 | .error_union_type => @panic("TODO"), | 1777 | .error_union_type => @panic("TODO"), |
| 1800 | .simple_type => |t| return switch (t) { | 1778 | .simple_type => |t| switch (t) { |
| 1801 | .f16, | 1779 | .f16, |
| 1802 | .f32, | 1780 | .f32, |
| 1803 | .f64, | 1781 | .f64, |
| ... | @@ -1848,6 +1826,7 @@ pub const Type = struct { | ... | @@ -1848,6 +1826,7 @@ pub const Type = struct { |
| 1848 | }, | 1826 | }, |
| 1849 | .struct_type => @panic("TODO"), | 1827 | .struct_type => @panic("TODO"), |
| 1850 | .union_type => @panic("TODO"), | 1828 | .union_type => @panic("TODO"), |
| 1829 | .opaque_type => true, | ||
| 1851 | 1830 | ||
| 1852 | // values, not types | 1831 | // values, not types |
| 1853 | .simple_value => unreachable, | 1832 | .simple_value => unreachable, |
| ... | @@ -1876,7 +1855,6 @@ pub const Type = struct { | ... | @@ -1876,7 +1855,6 @@ pub const Type = struct { |
| 1876 | .error_set_single, | 1855 | .error_set_single, |
| 1877 | .error_set_inferred, | 1856 | .error_set_inferred, |
| 1878 | .error_set_merged, | 1857 | .error_set_merged, |
| 1879 | .@"opaque", | ||
| 1880 | // These are function bodies, not function pointers. | 1858 | // These are function bodies, not function pointers. |
| 1881 | .function, | 1859 | .function, |
| 1882 | .enum_simple, | 1860 | .enum_simple, |
| ... | @@ -1960,6 +1938,7 @@ pub const Type = struct { | ... | @@ -1960,6 +1938,7 @@ pub const Type = struct { |
| 1960 | }, | 1938 | }, |
| 1961 | .struct_type => @panic("TODO"), | 1939 | .struct_type => @panic("TODO"), |
| 1962 | .union_type => @panic("TODO"), | 1940 | .union_type => @panic("TODO"), |
| 1941 | .opaque_type => false, | ||
| 1963 | 1942 | ||
| 1964 | // values, not types | 1943 | // values, not types |
| 1965 | .simple_value => unreachable, | 1944 | .simple_value => unreachable, |
| ... | @@ -2144,8 +2123,6 @@ pub const Type = struct { | ... | @@ -2144,8 +2123,6 @@ pub const Type = struct { |
| 2144 | switch (ty.ip_index) { | 2123 | switch (ty.ip_index) { |
| 2145 | .empty_struct_type => return AbiAlignmentAdvanced{ .scalar = 0 }, | 2124 | .empty_struct_type => return AbiAlignmentAdvanced{ .scalar = 0 }, |
| 2146 | .none => switch (ty.tag()) { | 2125 | .none => switch (ty.tag()) { |
| 2147 | .@"opaque" => return AbiAlignmentAdvanced{ .scalar = 1 }, | ||
| 2148 | |||
| 2149 | // represents machine code; not a pointer | 2126 | // represents machine code; not a pointer |
| 2150 | .function => { | 2127 | .function => { |
| 2151 | const alignment = ty.castTag(.function).?.data.alignment; | 2128 | const alignment = ty.castTag(.function).?.data.alignment; |
| ... | @@ -2362,6 +2339,7 @@ pub const Type = struct { | ... | @@ -2362,6 +2339,7 @@ pub const Type = struct { |
| 2362 | }, | 2339 | }, |
| 2363 | .struct_type => @panic("TODO"), | 2340 | .struct_type => @panic("TODO"), |
| 2364 | .union_type => @panic("TODO"), | 2341 | .union_type => @panic("TODO"), |
| 2342 | .opaque_type => return AbiAlignmentAdvanced{ .scalar = 1 }, | ||
| 2365 | 2343 | ||
| 2366 | // values, not types | 2344 | // values, not types |
| 2367 | .simple_value => unreachable, | 2345 | .simple_value => unreachable, |
| ... | @@ -2536,7 +2514,6 @@ pub const Type = struct { | ... | @@ -2536,7 +2514,6 @@ pub const Type = struct { |
| 2536 | 2514 | ||
| 2537 | .none => switch (ty.tag()) { | 2515 | .none => switch (ty.tag()) { |
| 2538 | .function => unreachable, // represents machine code; not a pointer | 2516 | .function => unreachable, // represents machine code; not a pointer |
| 2539 | .@"opaque" => unreachable, // no size available | ||
| 2540 | .inferred_alloc_const => unreachable, | 2517 | .inferred_alloc_const => unreachable, |
| 2541 | .inferred_alloc_mut => unreachable, | 2518 | .inferred_alloc_mut => unreachable, |
| 2542 | 2519 | ||
| ... | @@ -2777,6 +2754,7 @@ pub const Type = struct { | ... | @@ -2777,6 +2754,7 @@ pub const Type = struct { |
| 2777 | }, | 2754 | }, |
| 2778 | .struct_type => @panic("TODO"), | 2755 | .struct_type => @panic("TODO"), |
| 2779 | .union_type => @panic("TODO"), | 2756 | .union_type => @panic("TODO"), |
| 2757 | .opaque_type => unreachable, // no size available | ||
| 2780 | 2758 | ||
| 2781 | // values, not types | 2759 | // values, not types |
| 2782 | .simple_value => unreachable, | 2760 | .simple_value => unreachable, |
| ... | @@ -2948,6 +2926,7 @@ pub const Type = struct { | ... | @@ -2948,6 +2926,7 @@ pub const Type = struct { |
| 2948 | }, | 2926 | }, |
| 2949 | .struct_type => @panic("TODO"), | 2927 | .struct_type => @panic("TODO"), |
| 2950 | .union_type => @panic("TODO"), | 2928 | .union_type => @panic("TODO"), |
| 2929 | .opaque_type => unreachable, | ||
| 2951 | 2930 | ||
| 2952 | // values, not types | 2931 | // values, not types |
| 2953 | .simple_value => unreachable, | 2932 | .simple_value => unreachable, |
| ... | @@ -2965,7 +2944,6 @@ pub const Type = struct { | ... | @@ -2965,7 +2944,6 @@ pub const Type = struct { |
| 2965 | .empty_struct => unreachable, | 2944 | .empty_struct => unreachable, |
| 2966 | .inferred_alloc_const => unreachable, | 2945 | .inferred_alloc_const => unreachable, |
| 2967 | .inferred_alloc_mut => unreachable, | 2946 | .inferred_alloc_mut => unreachable, |
| 2968 | .@"opaque" => unreachable, | ||
| 2969 | 2947 | ||
| 2970 | .@"struct" => { | 2948 | .@"struct" => { |
| 2971 | const struct_obj = ty.castTag(.@"struct").?.data; | 2949 | const struct_obj = ty.castTag(.@"struct").?.data; |
| ... | @@ -3806,6 +3784,7 @@ pub const Type = struct { | ... | @@ -3806,6 +3784,7 @@ pub const Type = struct { |
| 3806 | .simple_type => unreachable, // handled via Index enum tag above | 3784 | .simple_type => unreachable, // handled via Index enum tag above |
| 3807 | .struct_type => @panic("TODO"), | 3785 | .struct_type => @panic("TODO"), |
| 3808 | .union_type => unreachable, | 3786 | .union_type => unreachable, |
| 3787 | .opaque_type => unreachable, | ||
| 3809 | 3788 | ||
| 3810 | // values, not types | 3789 | // values, not types |
| 3811 | .simple_value => unreachable, | 3790 | .simple_value => unreachable, |
| ... | @@ -4004,7 +3983,6 @@ pub const Type = struct { | ... | @@ -4004,7 +3983,6 @@ pub const Type = struct { |
| 4004 | .function, | 3983 | .function, |
| 4005 | .array_sentinel, | 3984 | .array_sentinel, |
| 4006 | .error_set_inferred, | 3985 | .error_set_inferred, |
| 4007 | .@"opaque", | ||
| 4008 | .anyframe_T, | 3986 | .anyframe_T, |
| 4009 | .pointer, | 3987 | .pointer, |
| 4010 | => return null, | 3988 | => return null, |
| ... | @@ -4182,6 +4160,7 @@ pub const Type = struct { | ... | @@ -4182,6 +4160,7 @@ pub const Type = struct { |
| 4182 | }, | 4160 | }, |
| 4183 | .struct_type => @panic("TODO"), | 4161 | .struct_type => @panic("TODO"), |
| 4184 | .union_type => @panic("TODO"), | 4162 | .union_type => @panic("TODO"), |
| 4163 | .opaque_type => return null, | ||
| 4185 | 4164 | ||
| 4186 | // values, not types | 4165 | // values, not types |
| 4187 | .simple_value => unreachable, | 4166 | .simple_value => unreachable, |
| ... | @@ -4208,7 +4187,6 @@ pub const Type = struct { | ... | @@ -4208,7 +4187,6 @@ pub const Type = struct { |
| 4208 | .error_set_single, | 4187 | .error_set_single, |
| 4209 | .error_set_inferred, | 4188 | .error_set_inferred, |
| 4210 | .error_set_merged, | 4189 | .error_set_merged, |
| 4211 | .@"opaque", | ||
| 4212 | .enum_simple, | 4190 | .enum_simple, |
| 4213 | => false, | 4191 | => false, |
| 4214 | 4192 | ||
| ... | @@ -4350,6 +4328,7 @@ pub const Type = struct { | ... | @@ -4350,6 +4328,7 @@ pub const Type = struct { |
| 4350 | }, | 4328 | }, |
| 4351 | .struct_type => @panic("TODO"), | 4329 | .struct_type => @panic("TODO"), |
| 4352 | .union_type => @panic("TODO"), | 4330 | .union_type => @panic("TODO"), |
| 4331 | .opaque_type => false, | ||
| 4353 | 4332 | ||
| 4354 | // values, not types | 4333 | // values, not types |
| 4355 | .simple_value => unreachable, | 4334 | .simple_value => unreachable, |
| ... | @@ -4399,21 +4378,31 @@ pub const Type = struct { | ... | @@ -4399,21 +4378,31 @@ pub const Type = struct { |
| 4399 | } | 4378 | } |
| 4400 | 4379 | ||
| 4401 | /// Returns null if the type has no namespace. | 4380 | /// Returns null if the type has no namespace. |
| 4402 | pub fn getNamespace(self: Type) ?*Module.Namespace { | 4381 | pub fn getNamespaceIndex(ty: Type, mod: *Module) Module.Namespace.OptionalIndex { |
| 4403 | return switch (self.tag()) { | 4382 | return switch (ty.ip_index) { |
| 4404 | .@"struct" => &self.castTag(.@"struct").?.data.namespace, | 4383 | .none => switch (ty.tag()) { |
| 4405 | .enum_full => &self.castTag(.enum_full).?.data.namespace, | 4384 | .@"struct" => ty.castTag(.@"struct").?.data.namespace.toOptional(), |
| 4406 | .enum_nonexhaustive => &self.castTag(.enum_nonexhaustive).?.data.namespace, | 4385 | .enum_full => ty.castTag(.enum_full).?.data.namespace.toOptional(), |
| 4407 | .empty_struct => self.castTag(.empty_struct).?.data, | 4386 | .enum_nonexhaustive => ty.castTag(.enum_nonexhaustive).?.data.namespace.toOptional(), |
| 4408 | .@"opaque" => &self.castTag(.@"opaque").?.data.namespace, | 4387 | .empty_struct => @panic("TODO"), |
| 4409 | .@"union" => &self.castTag(.@"union").?.data.namespace, | 4388 | .@"union" => ty.castTag(.@"union").?.data.namespace.toOptional(), |
| 4410 | .union_safety_tagged => &self.castTag(.union_safety_tagged).?.data.namespace, | 4389 | .union_safety_tagged => ty.castTag(.union_safety_tagged).?.data.namespace.toOptional(), |
| 4411 | .union_tagged => &self.castTag(.union_tagged).?.data.namespace, | 4390 | .union_tagged => ty.castTag(.union_tagged).?.data.namespace.toOptional(), |
| 4412 | 4391 | ||
| 4413 | else => null, | 4392 | else => .none, |
| 4393 | }, | ||
| 4394 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | ||
| 4395 | .opaque_type => |opaque_type| opaque_type.namespace.toOptional(), | ||
| 4396 | else => .none, | ||
| 4397 | }, | ||
| 4414 | }; | 4398 | }; |
| 4415 | } | 4399 | } |
| 4416 | 4400 | ||
| 4401 | /// Returns null if the type has no namespace. | ||
| 4402 | pub fn getNamespace(ty: Type, mod: *Module) ?*Module.Namespace { | ||
| 4403 | return if (getNamespaceIndex(ty, mod).unwrap()) |i| mod.namespacePtr(i) else null; | ||
| 4404 | } | ||
| 4405 | |||
| 4417 | // Works for vectors and vectors of integers. | 4406 | // Works for vectors and vectors of integers. |
| 4418 | pub fn minInt(ty: Type, arena: Allocator, mod: *Module) !Value { | 4407 | pub fn minInt(ty: Type, arena: Allocator, mod: *Module) !Value { |
| 4419 | const scalar = try minIntScalar(ty.scalarType(mod), mod); | 4408 | const scalar = try minIntScalar(ty.scalarType(mod), mod); |
| ... | @@ -4911,78 +4900,81 @@ pub const Type = struct { | ... | @@ -4911,78 +4900,81 @@ pub const Type = struct { |
| 4911 | } | 4900 | } |
| 4912 | 4901 | ||
| 4913 | pub fn declSrcLocOrNull(ty: Type, mod: *Module) ?Module.SrcLoc { | 4902 | pub fn declSrcLocOrNull(ty: Type, mod: *Module) ?Module.SrcLoc { |
| 4914 | if (ty.ip_index != .none) switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 4903 | switch (ty.ip_index) { |
| 4915 | .struct_type => @panic("TODO"), | 4904 | .none => switch (ty.tag()) { |
| 4916 | .union_type => @panic("TODO"), | 4905 | .enum_full, .enum_nonexhaustive => { |
| 4917 | else => return null, | 4906 | const enum_full = ty.cast(Payload.EnumFull).?.data; |
| 4918 | }; | 4907 | return enum_full.srcLoc(mod); |
| 4919 | switch (ty.tag()) { | 4908 | }, |
| 4920 | .enum_full, .enum_nonexhaustive => { | 4909 | .enum_numbered => { |
| 4921 | const enum_full = ty.cast(Payload.EnumFull).?.data; | 4910 | const enum_numbered = ty.castTag(.enum_numbered).?.data; |
| 4922 | return enum_full.srcLoc(mod); | 4911 | return enum_numbered.srcLoc(mod); |
| 4923 | }, | 4912 | }, |
| 4924 | .enum_numbered => { | 4913 | .enum_simple => { |
| 4925 | const enum_numbered = ty.castTag(.enum_numbered).?.data; | 4914 | const enum_simple = ty.castTag(.enum_simple).?.data; |
| 4926 | return enum_numbered.srcLoc(mod); | 4915 | return enum_simple.srcLoc(mod); |
| 4927 | }, | 4916 | }, |
| 4928 | .enum_simple => { | 4917 | .@"struct" => { |
| 4929 | const enum_simple = ty.castTag(.enum_simple).?.data; | 4918 | const struct_obj = ty.castTag(.@"struct").?.data; |
| 4930 | return enum_simple.srcLoc(mod); | 4919 | return struct_obj.srcLoc(mod); |
| 4931 | }, | 4920 | }, |
| 4932 | .@"struct" => { | 4921 | .error_set => { |
| 4933 | const struct_obj = ty.castTag(.@"struct").?.data; | 4922 | const error_set = ty.castTag(.error_set).?.data; |
| 4934 | return struct_obj.srcLoc(mod); | 4923 | return error_set.srcLoc(mod); |
| 4935 | }, | 4924 | }, |
| 4936 | .error_set => { | 4925 | .@"union", .union_safety_tagged, .union_tagged => { |
| 4937 | const error_set = ty.castTag(.error_set).?.data; | 4926 | const union_obj = ty.cast(Payload.Union).?.data; |
| 4938 | return error_set.srcLoc(mod); | 4927 | return union_obj.srcLoc(mod); |
| 4939 | }, | 4928 | }, |
| 4940 | .@"union", .union_safety_tagged, .union_tagged => { | 4929 | |
| 4941 | const union_obj = ty.cast(Payload.Union).?.data; | 4930 | else => return null, |
| 4942 | return union_obj.srcLoc(mod); | ||
| 4943 | }, | 4931 | }, |
| 4944 | .@"opaque" => { | 4932 | else => return switch (mod.intern_pool.indexToKey(ty.ip_index)) { |
| 4945 | const opaque_obj = ty.cast(Payload.Opaque).?.data; | 4933 | .struct_type => @panic("TODO"), |
| 4946 | return opaque_obj.srcLoc(mod); | 4934 | .union_type => @panic("TODO"), |
| 4935 | .opaque_type => |opaque_type| mod.opaqueSrcLoc(opaque_type), | ||
| 4936 | else => null, | ||
| 4947 | }, | 4937 | }, |
| 4948 | |||
| 4949 | else => return null, | ||
| 4950 | } | 4938 | } |
| 4951 | } | 4939 | } |
| 4952 | 4940 | ||
| 4953 | pub fn getOwnerDecl(ty: Type) Module.Decl.Index { | 4941 | pub fn getOwnerDecl(ty: Type, mod: *Module) Module.Decl.Index { |
| 4954 | return ty.getOwnerDeclOrNull() orelse unreachable; | 4942 | return ty.getOwnerDeclOrNull(mod) orelse unreachable; |
| 4955 | } | 4943 | } |
| 4956 | 4944 | ||
| 4957 | pub fn getOwnerDeclOrNull(ty: Type) ?Module.Decl.Index { | 4945 | pub fn getOwnerDeclOrNull(ty: Type, mod: *Module) ?Module.Decl.Index { |
| 4958 | switch (ty.tag()) { | 4946 | switch (ty.ip_index) { |
| 4959 | .enum_full, .enum_nonexhaustive => { | 4947 | .none => switch (ty.tag()) { |
| 4960 | const enum_full = ty.cast(Payload.EnumFull).?.data; | 4948 | .enum_full, .enum_nonexhaustive => { |
| 4961 | return enum_full.owner_decl; | 4949 | const enum_full = ty.cast(Payload.EnumFull).?.data; |
| 4962 | }, | 4950 | return enum_full.owner_decl; |
| 4963 | .enum_numbered => return ty.castTag(.enum_numbered).?.data.owner_decl, | 4951 | }, |
| 4964 | .enum_simple => { | 4952 | .enum_numbered => return ty.castTag(.enum_numbered).?.data.owner_decl, |
| 4965 | const enum_simple = ty.castTag(.enum_simple).?.data; | 4953 | .enum_simple => { |
| 4966 | return enum_simple.owner_decl; | 4954 | const enum_simple = ty.castTag(.enum_simple).?.data; |
| 4967 | }, | 4955 | return enum_simple.owner_decl; |
| 4968 | .@"struct" => { | 4956 | }, |
| 4969 | const struct_obj = ty.castTag(.@"struct").?.data; | 4957 | .@"struct" => { |
| 4970 | return struct_obj.owner_decl; | 4958 | const struct_obj = ty.castTag(.@"struct").?.data; |
| 4971 | }, | 4959 | return struct_obj.owner_decl; |
| 4972 | .error_set => { | 4960 | }, |
| 4973 | const error_set = ty.castTag(.error_set).?.data; | 4961 | .error_set => { |
| 4974 | return error_set.owner_decl; | 4962 | const error_set = ty.castTag(.error_set).?.data; |
| 4975 | }, | 4963 | return error_set.owner_decl; |
| 4976 | .@"union", .union_safety_tagged, .union_tagged => { | 4964 | }, |
| 4977 | const union_obj = ty.cast(Payload.Union).?.data; | 4965 | .@"union", .union_safety_tagged, .union_tagged => { |
| 4978 | return union_obj.owner_decl; | 4966 | const union_obj = ty.cast(Payload.Union).?.data; |
| 4967 | return union_obj.owner_decl; | ||
| 4968 | }, | ||
| 4969 | |||
| 4970 | else => return null, | ||
| 4979 | }, | 4971 | }, |
| 4980 | .@"opaque" => { | 4972 | else => return switch (mod.intern_pool.indexToKey(ty.ip_index)) { |
| 4981 | const opaque_obj = ty.cast(Payload.Opaque).?.data; | 4973 | .struct_type => @panic("TODO"), |
| 4982 | return opaque_obj.owner_decl; | 4974 | .union_type => @panic("TODO"), |
| 4975 | .opaque_type => |opaque_type| opaque_type.decl, | ||
| 4976 | else => null, | ||
| 4983 | }, | 4977 | }, |
| 4984 | |||
| 4985 | else => return null, | ||
| 4986 | } | 4978 | } |
| 4987 | } | 4979 | } |
| 4988 | 4980 | ||
| ... | @@ -5022,7 +5014,6 @@ pub const Type = struct { | ... | @@ -5022,7 +5014,6 @@ pub const Type = struct { |
| 5022 | error_set_inferred, | 5014 | error_set_inferred, |
| 5023 | error_set_merged, | 5015 | error_set_merged, |
| 5024 | empty_struct, | 5016 | empty_struct, |
| 5025 | @"opaque", | ||
| 5026 | @"struct", | 5017 | @"struct", |
| 5027 | @"union", | 5018 | @"union", |
| 5028 | union_safety_tagged, | 5019 | union_safety_tagged, |
| ... | @@ -5055,7 +5046,6 @@ pub const Type = struct { | ... | @@ -5055,7 +5046,6 @@ pub const Type = struct { |
| 5055 | .function => Payload.Function, | 5046 | .function => Payload.Function, |
| 5056 | .error_union => Payload.ErrorUnion, | 5047 | .error_union => Payload.ErrorUnion, |
| 5057 | .error_set_single => Payload.Name, | 5048 | .error_set_single => Payload.Name, |
| 5058 | .@"opaque" => Payload.Opaque, | ||
| 5059 | .@"struct" => Payload.Struct, | 5049 | .@"struct" => Payload.Struct, |
| 5060 | .@"union", .union_safety_tagged, .union_tagged => Payload.Union, | 5050 | .@"union", .union_safety_tagged, .union_tagged => Payload.Union, |
| 5061 | .enum_full, .enum_nonexhaustive => Payload.EnumFull, | 5051 | .enum_full, .enum_nonexhaustive => Payload.EnumFull, |
| ... | @@ -5336,11 +5326,6 @@ pub const Type = struct { | ... | @@ -5336,11 +5326,6 @@ pub const Type = struct { |
| 5336 | data: *Module.Namespace, | 5326 | data: *Module.Namespace, |
| 5337 | }; | 5327 | }; |
| 5338 | 5328 | ||
| 5339 | pub const Opaque = struct { | ||
| 5340 | base: Payload = .{ .tag = .@"opaque" }, | ||
| 5341 | data: *Module.Opaque, | ||
| 5342 | }; | ||
| 5343 | |||
| 5344 | pub const Struct = struct { | 5329 | pub const Struct = struct { |
| 5345 | base: Payload = .{ .tag = .@"struct" }, | 5330 | base: Payload = .{ .tag = .@"struct" }, |
| 5346 | data: *Module.Struct, | 5331 | data: *Module.Struct, |