| ... | @@ -1196,7 +1196,81 @@ fn zirErrorValue(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorValue) InnerE | ... | @@ -1196,7 +1196,81 @@ fn zirErrorValue(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorValue) InnerE |
| 1196 | fn zirMergeErrorSets(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst { | 1196 | fn zirMergeErrorSets(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst { |
| 1197 | const tracy = trace(@src()); | 1197 | const tracy = trace(@src()); |
| 1198 | defer tracy.end(); | 1198 | defer tracy.end(); |
| 1199 | return mod.fail(scope, inst.base.src, "TODO implement merge_error_sets", .{}); | 1199 | |
| | 1200 | const rhs_ty = try resolveType(mod, scope, inst.positionals.rhs); |
| | 1201 | const lhs_ty = try resolveType(mod, scope, inst.positionals.lhs); |
| | 1202 | if (rhs_ty.zigTypeTag() != .ErrorSet) |
| | 1203 | return mod.fail(scope, inst.positionals.rhs.src, "expected error set type, found {}", .{rhs_ty}); |
| | 1204 | if (lhs_ty.zigTypeTag() != .ErrorSet) |
| | 1205 | return mod.fail(scope, inst.positionals.lhs.src, "expected error set type, found {}", .{lhs_ty}); |
| | 1206 | |
| | 1207 | // anything merged with anyerror is anyerror |
| | 1208 | if (lhs_ty.tag() == .anyerror or rhs_ty.tag() == .anyerror) |
| | 1209 | return mod.constInst(scope, inst.base.src, .{ |
| | 1210 | .ty = Type.initTag(.type), |
| | 1211 | .val = Value.initTag(.anyerror_type), |
| | 1212 | }); |
| | 1213 | // The declarations arena will store the hashmap. |
| | 1214 | var new_decl_arena = std.heap.ArenaAllocator.init(mod.gpa); |
| | 1215 | errdefer new_decl_arena.deinit(); |
| | 1216 | |
| | 1217 | const payload = try new_decl_arena.allocator.create(Value.Payload.ErrorSet); |
| | 1218 | payload.* = .{ |
| | 1219 | .base = .{ .tag = .error_set }, |
| | 1220 | .data = .{ |
| | 1221 | .fields = .{}, |
| | 1222 | .decl = undefined, // populated below |
| | 1223 | }, |
| | 1224 | }; |
| | 1225 | try payload.data.fields.ensureCapacity(&new_decl_arena.allocator, @intCast(u32, switch (rhs_ty.tag()) { |
| | 1226 | .error_set_single => 1, |
| | 1227 | .error_set => rhs_ty.castTag(.error_set).?.data.typed_value.most_recent.typed_value.val.castTag(.error_set).?.data.fields.size, |
| | 1228 | else => unreachable, |
| | 1229 | } + switch (lhs_ty.tag()) { |
| | 1230 | .error_set_single => 1, |
| | 1231 | .error_set => lhs_ty.castTag(.error_set).?.data.typed_value.most_recent.typed_value.val.castTag(.error_set).?.data.fields.size, |
| | 1232 | else => unreachable, |
| | 1233 | })); |
| | 1234 | |
| | 1235 | switch (lhs_ty.tag()) { |
| | 1236 | .error_set_single => { |
| | 1237 | const name = lhs_ty.castTag(.error_set_single).?.data; |
| | 1238 | const num = mod.global_error_set.get(name).?; |
| | 1239 | payload.data.fields.putAssumeCapacity(name, num); |
| | 1240 | }, |
| | 1241 | .error_set => { |
| | 1242 | var multiple = lhs_ty.castTag(.error_set).?.data.typed_value.most_recent.typed_value.val.castTag(.error_set).?.data.fields; |
| | 1243 | var it = multiple.iterator(); |
| | 1244 | while (it.next()) |entry| { |
| | 1245 | payload.data.fields.putAssumeCapacity(entry.key, entry.value); |
| | 1246 | } |
| | 1247 | }, |
| | 1248 | else => unreachable, |
| | 1249 | } |
| | 1250 | |
| | 1251 | switch (rhs_ty.tag()) { |
| | 1252 | .error_set_single => { |
| | 1253 | const name = rhs_ty.castTag(.error_set_single).?.data; |
| | 1254 | const num = mod.global_error_set.get(name).?; |
| | 1255 | payload.data.fields.putAssumeCapacity(name, num); |
| | 1256 | }, |
| | 1257 | .error_set => { |
| | 1258 | var multiple = rhs_ty.castTag(.error_set).?.data.typed_value.most_recent.typed_value.val.castTag(.error_set).?.data.fields; |
| | 1259 | var it = multiple.iterator(); |
| | 1260 | while (it.next()) |entry| { |
| | 1261 | payload.data.fields.putAssumeCapacity(entry.key, entry.value); |
| | 1262 | } |
| | 1263 | }, |
| | 1264 | else => unreachable, |
| | 1265 | } |
| | 1266 | // TODO create name in format "error:line:column" |
| | 1267 | const new_decl = try mod.createAnonymousDecl(scope, &new_decl_arena, .{ |
| | 1268 | .ty = Type.initTag(.type), |
| | 1269 | .val = Value.initPayload(&payload.base), |
| | 1270 | }); |
| | 1271 | payload.data.decl = new_decl; |
| | 1272 | |
| | 1273 | return mod.analyzeDeclVal(scope, inst.base.src, new_decl); |
| 1200 | } | 1274 | } |
| 1201 | | 1275 | |
| 1202 | fn zirEnumLiteral(mod: *Module, scope: *Scope, inst: *zir.Inst.EnumLiteral) InnerError!*Inst { | 1276 | fn zirEnumLiteral(mod: *Module, scope: *Scope, inst: *zir.Inst.EnumLiteral) InnerError!*Inst { |