From aa1bb5517d57ae7540ce2c7a4315b2f242d1470c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 3 May 2023 13:56:01 -0700 Subject: InternPool: implement isSinglePointer --- src/type.zig | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'src/type.zig') diff --git a/src/type.zig b/src/type.zig index 8fd0ea6869..934bfd35ca 100644 --- a/src/type.zig +++ b/src/type.zig @@ -4039,19 +4039,25 @@ pub const Type = struct { } } - pub fn isSinglePointer(self: Type) bool { - return switch (self.tag()) { - .single_const_pointer, - .single_mut_pointer, - .single_const_pointer_to_comptime_int, - .inferred_alloc_const, - .inferred_alloc_mut, - => true, + pub fn isSinglePointer(ty: Type, mod: *const Module) bool { + switch (ty.ip_index) { + .none => return switch (ty.tag()) { + .single_const_pointer, + .single_mut_pointer, + .single_const_pointer_to_comptime_int, + .inferred_alloc_const, + .inferred_alloc_mut, + => true, - .pointer => self.castTag(.pointer).?.data.size == .One, + .pointer => ty.castTag(.pointer).?.data.size == .One, - else => false, - }; + else => false, + }, + else => return switch (mod.intern_pool.indexToKey(ty.ip_index)) { + .ptr_type => |ptr_info| ptr_info.size == .One, + else => false, + }, + } } /// Asserts `ty` is a pointer. @@ -6142,6 +6148,11 @@ pub const Type = struct { } pub fn declSrcLocOrNull(ty: Type, mod: *Module) ?Module.SrcLoc { + if (ty.ip_index != .none) switch (mod.intern_pool.indexToKey(ty.ip_index)) { + .struct_type => @panic("TODO"), + .union_type => @panic("TODO"), + else => return null, + }; switch (ty.tag()) { .enum_full, .enum_nonexhaustive => { const enum_full = ty.cast(Payload.EnumFull).?.data; -- cgit v1.2.3