diff options
| author | Matthew Lugg <mlugg@mlugg.co.uk> | 2024-06-20 11:07:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-20 11:07:17 +0100 |
| commit | f73be120f4254c080c48081dfc5834a7ebc9d9cf (patch) | |
| tree | e70598bed09659eb61c230620c1ddf88c14db905 /src/type.zig | |
| parent | ccd3cc3266762c1fea93cdc0190eaf71718d9e6a (diff) | |
| parent | 2b677d1660018434757f9c9efec3c712675e6c47 (diff) | |
| download | zig-f73be120f4254c080c48081dfc5834a7ebc9d9cf.tar.gz zig-f73be120f4254c080c48081dfc5834a7ebc9d9cf.zip | |
Merge pull request #20299 from mlugg/the-great-decl-split
The Great Decl Split (preliminary work): refactor source locations and eliminate `Sema.Block.src_decl`.
Diffstat (limited to 'src/type.zig')
| -rw-r--r-- | src/type.zig | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/type.zig b/src/type.zig index 5dad904ca0..215320ad79 100644 --- a/src/type.zig +++ b/src/type.zig @@ -3317,15 +3317,6 @@ pub const Type = struct { } } - pub fn declSrcLoc(ty: Type, mod: *Module) Module.SrcLoc { - return declSrcLocOrNull(ty, mod).?; - } - - pub fn declSrcLocOrNull(ty: Type, mod: *Module) ?Module.SrcLoc { - const decl = ty.getOwnerDeclOrNull(mod) orelse return null; - return mod.declPtr(decl).srcLoc(mod); - } - pub fn getOwnerDecl(ty: Type, mod: *Module) InternPool.DeclIndex { return ty.getOwnerDeclOrNull(mod) orelse unreachable; } @@ -3341,6 +3332,26 @@ pub const Type = struct { }; } + pub fn srcLocOrNull(ty: Type, zcu: *Zcu) ?Module.LazySrcLoc { + const ip = &zcu.intern_pool; + return .{ + .base_node_inst = switch (ip.indexToKey(ty.toIntern())) { + .struct_type, .union_type, .opaque_type, .enum_type => |info| switch (info) { + .declared => |d| d.zir_index, + .reified => |r| r.zir_index, + .generated_tag => |gt| ip.loadUnionType(gt.union_type).zir_index, // must be declared since we can't generate tags when reifying + .empty_struct => return null, + }, + else => return null, + }, + .offset = Module.LazySrcLoc.Offset.nodeOffset(0), + }; + } + + pub fn srcLoc(ty: Type, zcu: *Zcu) Module.LazySrcLoc { + return ty.srcLocOrNull(zcu).?; + } + pub fn isGenericPoison(ty: Type) bool { return ty.toIntern() == .generic_poison_type; } |
