| ... | ... | @@ -947,9 +947,10 @@ pub const DeclGen = struct { |
| 947 | 947 | return try self.resolveType(union_obj.enum_tag_ty.toType(), .indirect); |
| 948 | 948 | } |
| 949 | 949 | |
| 950 | | // TODO: We need to add the active field to the key. |
| 951 | | // const entry = try self.type_map.getOrPut(self.gpa, ty.toIntern()); |
| 952 | | // if (entry.found_existing) return entry.value_ptr.ty_ref; |
| 950 | // TODO: We need to add the active field to the key, somehow. |
| 951 | if (maybe_active_field == null) { |
| 952 | if (self.type_map.get(ty.toIntern())) |info| return info.ty_ref; |
| 953 | } |
| 953 | 954 | |
| 954 | 955 | var member_types: [4]CacheRef = undefined; |
| 955 | 956 | var member_names: [4]CacheString = undefined; |
| ... | ... | @@ -986,10 +987,9 @@ pub const DeclGen = struct { |
| 986 | 987 | .member_names = member_names[0..layout.total_fields], |
| 987 | 988 | } }); |
| 988 | 989 | |
| 989 | | // entry.value_ptr.* = .{ |
| 990 | | // .ty_ref = ty_ref, |
| 991 | | // }; |
| 992 | | |
| 990 | if (maybe_active_field == null) { |
| 991 | try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref }); |
| 992 | } |
| 993 | 993 | return ty_ref; |
| 994 | 994 | } |
| 995 | 995 | |
| ... | ... | @@ -1033,8 +1033,7 @@ pub const DeclGen = struct { |
| 1033 | 1033 | return try self.spv.resolve(.{ .float_type = .{ .bits = bits } }); |
| 1034 | 1034 | }, |
| 1035 | 1035 | .Array => { |
| 1036 | | const entry = try self.type_map.getOrPut(self.gpa, ty.toIntern()); |
| 1037 | | if (entry.found_existing) return entry.value_ptr.ty_ref; |
| 1036 | if (self.type_map.get(ty.toIntern())) |info| return info.ty_ref; |
| 1038 | 1037 | |
| 1039 | 1038 | const elem_ty = ty.childType(mod); |
| 1040 | 1039 | const elem_ty_ref = try self.resolveType(elem_ty, .indirect); |
| ... | ... | @@ -1042,15 +1041,12 @@ pub const DeclGen = struct { |
| 1042 | 1041 | return self.fail("array type of {} elements is too large", .{ty.arrayLenIncludingSentinel(mod)}); |
| 1043 | 1042 | }; |
| 1044 | 1043 | const ty_ref = try self.spv.arrayType(total_len, elem_ty_ref); |
| 1045 | | entry.value_ptr.* = .{ |
| 1046 | | .ty_ref = ty_ref, |
| 1047 | | }; |
| 1044 | try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref }); |
| 1048 | 1045 | return ty_ref; |
| 1049 | 1046 | }, |
| 1050 | 1047 | .Fn => switch (repr) { |
| 1051 | 1048 | .direct => { |
| 1052 | | const entry = try self.type_map.getOrPut(self.gpa, ty.toIntern()); |
| 1053 | | if (entry.found_existing) return entry.value_ptr.ty_ref; |
| 1049 | if (self.type_map.get(ty.toIntern())) |info| return info.ty_ref; |
| 1054 | 1050 | |
| 1055 | 1051 | const fn_info = mod.typeToFunc(ty).?; |
| 1056 | 1052 | // TODO: Put this somewhere in Sema.zig |
| ... | ... | @@ -1069,10 +1065,7 @@ pub const DeclGen = struct { |
| 1069 | 1065 | .parameters = param_ty_refs, |
| 1070 | 1066 | } }); |
| 1071 | 1067 | |
| 1072 | | entry.value_ptr.* = .{ |
| 1073 | | .ty_ref = ty_ref, |
| 1074 | | }; |
| 1075 | | |
| 1068 | try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref }); |
| 1076 | 1069 | return ty_ref; |
| 1077 | 1070 | }, |
| 1078 | 1071 | .indirect => { |
| ... | ... | @@ -1119,8 +1112,7 @@ pub const DeclGen = struct { |
| 1119 | 1112 | } }); |
| 1120 | 1113 | }, |
| 1121 | 1114 | .Struct => { |
| 1122 | | const entry = try self.type_map.getOrPut(self.gpa, ty.toIntern()); |
| 1123 | | if (entry.found_existing) return entry.value_ptr.ty_ref; |
| 1115 | if (self.type_map.get(ty.toIntern())) |info| return info.ty_ref; |
| 1124 | 1116 | |
| 1125 | 1117 | const struct_type = switch (ip.indexToKey(ty.toIntern())) { |
| 1126 | 1118 | .anon_struct_type => |tuple| { |
| ... | ... | @@ -1140,9 +1132,7 @@ pub const DeclGen = struct { |
| 1140 | 1132 | .member_types = member_types[0..member_index], |
| 1141 | 1133 | } }); |
| 1142 | 1134 | |
| 1143 | | entry.value_ptr.* = .{ |
| 1144 | | .ty_ref = ty_ref, |
| 1145 | | }; |
| 1135 | try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref }); |
| 1146 | 1136 | return ty_ref; |
| 1147 | 1137 | }, |
| 1148 | 1138 | .struct_type => |struct_type| struct_type, |
| ... | ... | @@ -1151,6 +1141,7 @@ pub const DeclGen = struct { |
| 1151 | 1141 | |
| 1152 | 1142 | if (struct_type.layout == .Packed) { |
| 1153 | 1143 | return try self.resolveType(struct_type.backingIntType(ip).toType(), .direct); |
| 1144 | } |
| 1154 | 1145 | |
| 1155 | 1146 | var member_types = std.ArrayList(CacheRef).init(self.gpa); |
| 1156 | 1147 | defer member_types.deinit(); |
| ... | ... | @@ -1172,9 +1163,7 @@ pub const DeclGen = struct { |
| 1172 | 1163 | .member_names = member_names.items, |
| 1173 | 1164 | } }); |
| 1174 | 1165 | |
| 1175 | | entry.value_ptr.* = .{ |
| 1176 | | .ty_ref = ty_ref, |
| 1177 | | }; |
| 1166 | try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref }); |
| 1178 | 1167 | return ty_ref; |
| 1179 | 1168 | }, |
| 1180 | 1169 | .Optional => { |
| ... | ... | @@ -1192,8 +1181,7 @@ pub const DeclGen = struct { |
| 1192 | 1181 | return payload_ty_ref; |
| 1193 | 1182 | } |
| 1194 | 1183 | |
| 1195 | | const entry = try self.type_map.getOrPut(self.gpa, ty.toIntern()); |
| 1196 | | if (entry.found_existing) return entry.value_ptr.ty_ref; |
| 1184 | if (self.type_map.get(ty.toIntern())) |info| return info.ty_ref; |
| 1197 | 1185 | |
| 1198 | 1186 | const bool_ty_ref = try self.resolveType(Type.bool, .indirect); |
| 1199 | 1187 | |
| ... | ... | @@ -1205,9 +1193,7 @@ pub const DeclGen = struct { |
| 1205 | 1193 | }, |
| 1206 | 1194 | } }); |
| 1207 | 1195 | |
| 1208 | | entry.value_ptr.* = .{ |
| 1209 | | .ty_ref = ty_ref, |
| 1210 | | }; |
| 1196 | try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref }); |
| 1211 | 1197 | return ty_ref; |
| 1212 | 1198 | }, |
| 1213 | 1199 | .Union => return try self.resolveUnionType(ty, null), |
| ... | ... | @@ -1221,8 +1207,7 @@ pub const DeclGen = struct { |
| 1221 | 1207 | return error_ty_ref; |
| 1222 | 1208 | } |
| 1223 | 1209 | |
| 1224 | | const entry = try self.type_map.getOrPut(self.gpa, ty.toIntern()); |
| 1225 | | if (entry.found_existing) return entry.value_ptr.ty_ref; |
| 1210 | if (self.type_map.get(ty.toIntern())) |info| return info.ty_ref; |
| 1226 | 1211 | |
| 1227 | 1212 | const payload_ty_ref = try self.resolveType(payload_ty, .indirect); |
| 1228 | 1213 | |
| ... | ... | @@ -1252,9 +1237,7 @@ pub const DeclGen = struct { |
| 1252 | 1237 | .member_names = &member_names, |
| 1253 | 1238 | } }); |
| 1254 | 1239 | |
| 1255 | | entry.value_ptr.* = .{ |
| 1256 | | .ty_ref = ty_ref, |
| 1257 | | }; |
| 1240 | try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref }); |
| 1258 | 1241 | return ty_ref; |
| 1259 | 1242 | }, |
| 1260 | 1243 | |