-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Description of the bug:
The toolchain crashes when dumping textual SemIR in certain cases, because the formatter tries to access a specific that's unresolved because it's non-canonical.
What did you do, or what's a simple way to reproduce the bug?
To reproduce, compile this with carbon compile --no-prelude-import --dump-sem-ir:
fn IntLiteral() -> type = "int_literal.make_type";
private fn Int(size: IntLiteral()) -> type = "int.make_type_signed";
class C(N:! IntLiteral()) {
fn Op() {
fn AsInt(n: IntLiteral()) -> Int(N) = "int.convert_checked";
AsInt(1);
}
}
(or compile anything with --dump-sem-ir; this example is reduced from the prelude)
What did you expect to happen?
This code should compile.
What actually happened?
It crashes with the following error:
CHECK failure at toolchain/sem_ir/generic.cpp:95: specific_ir.generics().GetSelfSpecific( specific_ir.specifics().Get(specific_id).generic_id) == specific_id: Queried generic_inst_in_decl2 in specific60000005 for {kind: FunctionDecl, arg0: function60000003, arg1: inst_block60000027, type: type(symbolic_constant6000000F)} before it was resolved.
Any other information, logs, or outputs that you want to share?
The raw SemIR for this file includes the following:
inst6000006E: {kind: SpecificFunction, arg0: inst6000006B, arg1: specific60000003, type: type(inst(SpecificFunctionType))}
inst6000006F: {kind: SpecificFunction, arg0: inst60000062, arg1: specific60000003, type: type(inst(SpecificFunctionType))}
inst60000070: {kind: SpecificFunction, arg0: inst60000065, arg1: specific60000005, type: type(inst(SpecificFunctionType))}
inst60000071: {kind: Call, arg0: inst6000006E, arg1: inst_block6000002D, type: type(symbolic_constant60000015)}
inst60000072: {kind: Call, arg0: inst6000006F, arg1: inst_block6000002E, type: type(symbolic_constant60000009)}
inst60000073: {kind: Call, arg0: inst60000070, arg1: inst_block6000002E, type: type(symbolic_constant60000015)}
These are all emitted as part of the AsInt(1) call, and inst60000073 is the inst that crashes the formatter. specific60000003 is the self-specific for AsInt, and specific60000005 is an unresolved, non-canonical representation of the same specific. inst60000071 is created in the usual way for a runtime call, but in the course of that, inst60000072 is created by MakeConstantForBuiltinCall, and then in the course of that, inst60000073 is created here.
See here for some discussion of possible fixes.