From 52ec121469d7bf10116fb22c122cbce8ceddd028 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Tue, 20 Jun 2023 13:48:19 -0400 Subject: Sema: optimize callers of `indexToKey` --- src/InternPool.zig | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/InternPool.zig') diff --git a/src/InternPool.zig b/src/InternPool.zig index f93539daf8..d77b82932c 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -5694,11 +5694,26 @@ pub fn aggregateTypeLenIncludingSentinel(ip: *const InternPool, ty: Index) u64 { }; } +pub fn funcReturnType(ip: *const InternPool, ty: Index) Index { + const item = ip.items.get(@intFromEnum(ty)); + const child_item = switch (item.tag) { + .type_pointer => ip.items.get(ip.extra.items[ + item.data + std.meta.fieldIndex(Tag.TypePointer, "child").? + ]), + .type_function => item, + else => unreachable, + }; + assert(child_item.tag == .type_function); + return @enumFromInt(Index, ip.extra.items[ + child_item.data + std.meta.fieldIndex(TypeFunction, "return_type").? + ]); +} + pub fn isNoReturn(ip: *const InternPool, ty: Index) bool { return switch (ty) { .noreturn_type => true, - else => switch (ip.indexToKey(ty)) { - .error_set_type => |error_set_type| error_set_type.names.len == 0, + else => switch (ip.items.items(.tag)[@intFromEnum(ty)]) { + .type_error_set => ip.extra.items[ip.items.items(.data)[@intFromEnum(ty)] + std.meta.fieldIndex(ErrorSet, "names_len").?] == 0, else => false, }, }; -- cgit v1.2.3