Skip to content

Commit

Permalink
Explain why the new setup can't deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Jul 19, 2024
1 parent 3623c76 commit 2ab9fa2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion compiler/rustc_middle/src/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,16 @@ impl<'s> AllocDecodingSession<'s> {
(alloc_kind, decoder.position())
});

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

0 comments on commit 2ab9fa2

Please sign in to comment.