Skip to content

Commit 4a412e7

Browse files
authored
Allow fingerprinting instructions to work for the special InstIds (#6400)
Use the index of the special id instead of crashing. Fixes #6370.
1 parent 0678501 commit 4a412e7

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

toolchain/check/testdata/impl/error_recovery.carbon

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,29 @@ fn G() {
107107
//@dump-sem-ir-end
108108
}
109109

110+
// --- fail_invalid_fn_syntax_in_impl.carbon
111+
library "[[@TEST_NAME]]";
112+
113+
interface I {
114+
fn Op[self: Self]();
115+
}
116+
117+
class C {};
118+
//@dump-sem-ir-begin
119+
impl C as I {
120+
// This leaves the impl with a placeholder instruction in the witness table.
121+
// CHECK:STDERR: fail_invalid_fn_syntax_in_impl.carbon:[[@LINE+8]]:11: error: expected `:` or `:!` in binding pattern [ExpectedBindingPattern]
122+
// CHECK:STDERR: fn Op[x self: C]() {}
123+
// CHECK:STDERR: ^~~~
124+
// CHECK:STDERR:
125+
// CHECK:STDERR: fail_invalid_fn_syntax_in_impl.carbon:[[@LINE+4]]:11: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
126+
// CHECK:STDERR: fn Op[x self: C]() {}
127+
// CHECK:STDERR: ^~~~
128+
// CHECK:STDERR:
129+
fn Op[x self: C]() {}
130+
}
131+
//@dump-sem-ir-end
132+
110133
// CHECK:STDOUT: --- fail_runtime_generic_param.carbon
111134
// CHECK:STDOUT:
112135
// CHECK:STDOUT: constants {
@@ -260,3 +283,10 @@ fn G() {
260283
// CHECK:STDOUT: <elided>
261284
// CHECK:STDOUT: }
262285
// CHECK:STDOUT:
286+
// CHECK:STDOUT: --- fail_invalid_fn_syntax_in_impl.carbon
287+
// CHECK:STDOUT:
288+
// CHECK:STDOUT: constants {
289+
// CHECK:STDOUT: }
290+
// CHECK:STDOUT:
291+
// CHECK:STDOUT: impl @<null name>: <unexpected>.inst{{[0-9A-F]+}}.loc9_6 as <unexpected>.inst5800002D.loc9_11;
292+
// CHECK:STDOUT:

toolchain/sem_ir/inst_fingerprinter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ struct Worklist {
5252
if (store.size() == 0) {
5353
return 0;
5454
}
55+
// These InstIds are constant values, so not in the ValueStore. We use a
56+
// constant (negative) fingerprint for them.
57+
if (inst_id == InstId::InitTombstone ||
58+
inst_id == InstId::ImplWitnessTablePlaceholder) {
59+
return inst_id.index;
60+
}
5561
return store.Get(inst_id);
5662
}
5763

0 commit comments

Comments
 (0)