Skip to content

Commit 107cf98

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

File tree

1 file changed

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

1 file changed

+13
-1
lines changed

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,21 @@ 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+
//
212+
// At the time of writing, it is only possible to create an allocation that contains a pointer
213+
// to itself using the const_allocate intrinsic (which is for testing only), and even attempting
214+
// to evaluate such consts blows the stack. If we ever grow a mechanism for producing
215+
// cyclic allocations, we will need a new strategy for decoding that doesn't bring back
216+
// https://github.com/rust-lang/rust/issues/126741.
217+
//
218+
// It is also impossible to create two allocations (call them A and B) where A is a pointer to B, and B
219+
// is a pointer to A, because attempting to evaluate either of those consts will produce a
220+
// query cycle, failing compilation.
221+
let mut entry = self.state.decoding_state[idx].lock();
209222
// Check the decoding state to see if it's already decoded or if we should
210223
// decode it here.
211-
let mut entry = self.state.decoding_state[idx].lock();
212224
if let State::Done(alloc_id) = *entry {
213225
return alloc_id;
214226
}

0 commit comments

Comments
 (0)