File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
compiler/rustc_middle/src/mir/interpret Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments