Skip to content

Commit 039f53f

Browse files
committed
expand comment on how statics work
1 parent f92ee9f commit 039f53f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/librustc_mir/interpret/place.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,17 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
489489
promoted: None
490490
};
491491
// Just create a lazy reference, so we can support recursive statics.
492+
// tcx takes are of assigning every static one and only one unique AllocId.
492493
// When the data here is ever actually used, memory will notice,
493494
// and it knows how to deal with alloc_id that are present in the
494-
// global table but not in its local memory.
495-
let alloc = self.tcx.alloc_map.lock()
496-
.intern_static(cid.instance.def_id());
495+
// global table but not in its local memory: It calls back into tcx through
496+
// a query, triggering the CTFE machinery to actually turn this lazy reference
497+
// into a bunch of bytes. IOW, statics are evaluated with CTFE even when
498+
// this EvalContext uses another Machine (e.g., in miri). This is what we
499+
// want! This way, computing statics works concistently between codegen
500+
// and miri: They use the same query to eventually obtain a `ty::Const`
501+
// and use that for further computation.
502+
let alloc = self.tcx.alloc_map.lock().intern_static(cid.instance.def_id());
497503
MPlaceTy::from_aligned_ptr(alloc.into(), layout)
498504
}
499505

0 commit comments

Comments
 (0)