diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-05-02 14:37:33 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-06-10 20:40:03 -0700 |
| commit | 00f82f1c46126f1fc6655c6142ef16e8e5afbf4e (patch) | |
| tree | aa9f759bddb01a7469083363da65ef4717509a52 /src/type.zig | |
| parent | c7e84ddb722df0403dd6ae8283820c02efc77e50 (diff) | |
| download | zig-00f82f1c46126f1fc6655c6142ef16e8e5afbf4e.tar.gz zig-00f82f1c46126f1fc6655c6142ef16e8e5afbf4e.zip | |
stage2: add `interned` AIR tag
This required additionally passing the `InternPool` into some AIR
methods.
Also, implement `Type.isNoReturn` for interned types.
Diffstat (limited to 'src/type.zig')
| -rw-r--r-- | src/type.zig | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/src/type.zig b/src/type.zig index 259079a26c..94fd4c2eaf 100644 --- a/src/type.zig +++ b/src/type.zig @@ -2827,21 +2827,35 @@ pub const Type = struct { }; } - /// TODO add enums with no fields here pub fn isNoReturn(ty: Type) bool { - switch (ty.tag()) { - .noreturn => return true, - .error_set => { - const err_set_obj = ty.castTag(.error_set).?.data; - const names = err_set_obj.names.keys(); - return names.len == 0; - }, - .error_set_merged => { - const name_map = ty.castTag(.error_set_merged).?.data; - const names = name_map.keys(); - return names.len == 0; - }, + switch (@enumToInt(ty.ip_index)) { + @enumToInt(InternPool.Index.first_type)...@enumToInt(InternPool.Index.noreturn_type) - 1 => return false, + + @enumToInt(InternPool.Index.noreturn_type) => return true, + + @enumToInt(InternPool.Index.noreturn_type) + 1...@enumToInt(InternPool.Index.last_type) => return false, + + @enumToInt(InternPool.Index.first_value)...@enumToInt(InternPool.Index.last_value) => unreachable, + @enumToInt(InternPool.Index.generic_poison) => unreachable, + + // TODO add empty error sets here + // TODO add enums with no fields here else => return false, + + @enumToInt(InternPool.Index.none) => switch (ty.tag()) { + .noreturn => return true, + .error_set => { + const err_set_obj = ty.castTag(.error_set).?.data; + const names = err_set_obj.names.keys(); + return names.len == 0; + }, + .error_set_merged => { + const name_map = ty.castTag(.error_set_merged).?.data; + const names = name_map.keys(); + return names.len == 0; + }, + else => return false, + }, } } |
