Skip to content

Commit 2ab9fa2

Browse files
committed
Explain why the new setup can't deadlock
1 parent 3623c76 commit 2ab9fa2

File tree

1 file changed

+8
-1
lines changed
  • compiler/rustc_middle/src/mir/interpret

1 file changed

+8
-1
lines changed

compiler/rustc_middle/src/mir/interpret/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,16 @@ impl<'s> AllocDecodingSession<'s> {
206206
(alloc_kind, decoder.position())
207207
});
208208

209+
// We are going to hold this lock during the entire decoding of this allocation, which may
210+
// require that we decode other allocations. This cannot deadlock for two reasons:
211+
// It is impossible to create an allocation that contains a pointer to itself and thus
212+
// deadlock with a single thread, because attempting to create such a pointer immediately
213+
// blows the stack.
214+
// It is also impossible to create two allocations (call them A and B) where A is a pointer to B, and B
215+
// is a pointer to A, because const eval itself rejects such cycles.
216+
let mut entry = self.state.decoding_state[idx].lock();
209217
// Check the decoding state to see if it's already decoded or if we should
210218
// decode it here.
211-
let mut entry = self.state.decoding_state[idx].lock();
212219
if let State::Done(alloc_id) = *entry {
213220
return alloc_id;
214221
}

0 commit comments

Comments
 (0)