| ... | ... | @@ -61,11 +61,17 @@ pub const Type = extern union { |
| 61 | 61 | .c_longdouble, |
| 62 | 62 | => return .Float, |
| 63 | 63 | |
| 64 | .error_set, |
| 65 | .error_set_single, |
| 66 | .anyerror, |
| 67 | .error_set_inferred, |
| 68 | .error_set_merged, |
| 69 | => return .ErrorSet, |
| 70 | |
| 64 | 71 | .c_void, .@"opaque" => return .Opaque, |
| 65 | 72 | .bool => return .Bool, |
| 66 | 73 | .void => return .Void, |
| 67 | 74 | .type => return .Type, |
| 68 | | .error_set, .error_set_single, .anyerror, .error_set_inferred => return .ErrorSet, |
| 69 | 75 | .comptime_int => return .ComptimeInt, |
| 70 | 76 | .comptime_float => return .ComptimeFloat, |
| 71 | 77 | .noreturn => return .NoReturn, |
| ... | ... | @@ -608,6 +614,9 @@ pub const Type = extern union { |
| 608 | 614 | return true; |
| 609 | 615 | }, |
| 610 | 616 | .ErrorSet => { |
| 617 | // TODO: revisit the language specification for how to evaluate equality |
| 618 | // for error set types. |
| 619 | |
| 611 | 620 | if (a.tag() == .anyerror and b.tag() == .anyerror) { |
| 612 | 621 | return true; |
| 613 | 622 | } |
| ... | ... | @@ -892,6 +901,14 @@ pub const Type = extern union { |
| 892 | 901 | .payload = try payload.payload.copy(allocator), |
| 893 | 902 | }); |
| 894 | 903 | }, |
| 904 | .error_set_merged => { |
| 905 | const names = self.castTag(.error_set_merged).?.data; |
| 906 | const duped_names = try allocator.alloc([]const u8, names.len); |
| 907 | for (duped_names) |*name, i| { |
| 908 | name.* = try allocator.dupe(u8, names[i]); |
| 909 | } |
| 910 | return Tag.error_set_merged.create(allocator, duped_names); |
| 911 | }, |
| 895 | 912 | .error_set => return self.copyPayloadShallow(allocator, Payload.ErrorSet), |
| 896 | 913 | .error_set_inferred => return self.copyPayloadShallow(allocator, Payload.ErrorSetInferred), |
| 897 | 914 | .error_set_single => return self.copyPayloadShallow(allocator, Payload.Name), |
| ... | ... | @@ -1185,6 +1202,16 @@ pub const Type = extern union { |
| 1185 | 1202 | const func = ty.castTag(.error_set_inferred).?.data.func; |
| 1186 | 1203 | return writer.print("(inferred error set of {s})", .{func.owner_decl.name}); |
| 1187 | 1204 | }, |
| 1205 | .error_set_merged => { |
| 1206 | const names = ty.castTag(.error_set_merged).?.data; |
| 1207 | try writer.writeAll("error{"); |
| 1208 | for (names) |name, i| { |
| 1209 | if (i != 0) try writer.writeByte(','); |
| 1210 | try writer.writeAll(name); |
| 1211 | } |
| 1212 | try writer.writeAll("}"); |
| 1213 | return; |
| 1214 | }, |
| 1188 | 1215 | .error_set_single => { |
| 1189 | 1216 | const name = ty.castTag(.error_set_single).?.data; |
| 1190 | 1217 | return writer.print("error{{{s}}}", .{name}); |
| ... | ... | @@ -1365,6 +1392,7 @@ pub const Type = extern union { |
| 1365 | 1392 | .error_set, |
| 1366 | 1393 | .error_set_single, |
| 1367 | 1394 | .error_set_inferred, |
| 1395 | .error_set_merged, |
| 1368 | 1396 | .@"opaque", |
| 1369 | 1397 | .generic_poison, |
| 1370 | 1398 | .array_u8, |
| ... | ... | @@ -1525,6 +1553,7 @@ pub const Type = extern union { |
| 1525 | 1553 | .error_set, |
| 1526 | 1554 | .error_set_single, |
| 1527 | 1555 | .error_set_inferred, |
| 1556 | .error_set_merged, |
| 1528 | 1557 | .manyptr_u8, |
| 1529 | 1558 | .manyptr_const_u8, |
| 1530 | 1559 | .atomic_order, |
| ... | ... | @@ -1783,6 +1812,7 @@ pub const Type = extern union { |
| 1783 | 1812 | .anyerror_void_error_union, |
| 1784 | 1813 | .anyerror, |
| 1785 | 1814 | .error_set_inferred, |
| 1815 | .error_set_merged, |
| 1786 | 1816 | => return 2, // TODO revisit this when we have the concept of the error tag type |
| 1787 | 1817 | |
| 1788 | 1818 | .array, .array_sentinel => return self.elemType().abiAlignment(target), |
| ... | ... | @@ -2021,6 +2051,7 @@ pub const Type = extern union { |
| 2021 | 2051 | .anyerror_void_error_union, |
| 2022 | 2052 | .anyerror, |
| 2023 | 2053 | .error_set_inferred, |
| 2054 | .error_set_merged, |
| 2024 | 2055 | => return 2, // TODO revisit this when we have the concept of the error tag type |
| 2025 | 2056 | |
| 2026 | 2057 | .int_signed, .int_unsigned => { |
| ... | ... | @@ -2199,6 +2230,7 @@ pub const Type = extern union { |
| 2199 | 2230 | .anyerror_void_error_union, |
| 2200 | 2231 | .anyerror, |
| 2201 | 2232 | .error_set_inferred, |
| 2233 | .error_set_merged, |
| 2202 | 2234 | => return 16, // TODO revisit this when we have the concept of the error tag type |
| 2203 | 2235 | |
| 2204 | 2236 | .int_signed, .int_unsigned => self.cast(Payload.Bits).?.data, |
| ... | ... | @@ -2961,7 +2993,7 @@ pub const Type = extern union { |
| 2961 | 2993 | return .{ .signedness = .unsigned, .bits = smallestUnsignedBits(field_count - 1) }; |
| 2962 | 2994 | }, |
| 2963 | 2995 | |
| 2964 | | .error_set, .error_set_single, .anyerror, .error_set_inferred => { |
| 2996 | .error_set, .error_set_single, .anyerror, .error_set_inferred, .error_set_merged => { |
| 2965 | 2997 | // TODO revisit this when error sets support custom int types |
| 2966 | 2998 | return .{ .signedness = .unsigned, .bits = 16 }; |
| 2967 | 2999 | }, |
| ... | ... | @@ -3250,6 +3282,7 @@ pub const Type = extern union { |
| 3250 | 3282 | .error_set, |
| 3251 | 3283 | .error_set_single, |
| 3252 | 3284 | .error_set_inferred, |
| 3285 | .error_set_merged, |
| 3253 | 3286 | .@"opaque", |
| 3254 | 3287 | .var_args_param, |
| 3255 | 3288 | .manyptr_u8, |
| ... | ... | @@ -3882,6 +3915,7 @@ pub const Type = extern union { |
| 3882 | 3915 | error_set_single, |
| 3883 | 3916 | /// The type is the inferred error set of a specific function. |
| 3884 | 3917 | error_set_inferred, |
| 3918 | error_set_merged, |
| 3885 | 3919 | empty_struct, |
| 3886 | 3920 | @"opaque", |
| 3887 | 3921 | @"struct", |
| ... | ... | @@ -3986,6 +4020,7 @@ pub const Type = extern union { |
| 3986 | 4020 | |
| 3987 | 4021 | .error_set => Payload.ErrorSet, |
| 3988 | 4022 | .error_set_inferred => Payload.ErrorSetInferred, |
| 4023 | .error_set_merged => Payload.ErrorSetMerged, |
| 3989 | 4024 | |
| 3990 | 4025 | .array, .vector => Payload.Array, |
| 3991 | 4026 | .array_sentinel => Payload.ArraySentinel, |
| ... | ... | @@ -4090,6 +4125,13 @@ pub const Type = extern union { |
| 4090 | 4125 | data: *Module.ErrorSet, |
| 4091 | 4126 | }; |
| 4092 | 4127 | |
| 4128 | pub const ErrorSetMerged = struct { |
| 4129 | pub const base_tag = Tag.error_set_merged; |
| 4130 | |
| 4131 | base: Payload = Payload{ .tag = base_tag }, |
| 4132 | data: []const []const u8, |
| 4133 | }; |
| 4134 | |
| 4093 | 4135 | pub const ErrorSetInferred = struct { |
| 4094 | 4136 | pub const base_tag = Tag.error_set_inferred; |
| 4095 | 4137 | |
| ... | ... | @@ -4125,6 +4167,12 @@ pub const Type = extern union { |
| 4125 | 4167 | try self.map.put(gpa, entry.key_ptr.*, {}); |
| 4126 | 4168 | } |
| 4127 | 4169 | }, |
| 4170 | .error_set_merged => { |
| 4171 | const names = err_set_ty.castTag(.error_set_merged).?.data; |
| 4172 | for (names) |name| { |
| 4173 | try self.map.put(gpa, name, {}); |
| 4174 | } |
| 4175 | }, |
| 4128 | 4176 | .anyerror => { |
| 4129 | 4177 | self.is_anyerror = true; |
| 4130 | 4178 | }, |