]> git.lizzy.rs Git - rust.git/commitdiff
expand comment on how statics work
authorRalf Jung <post@ralfj.de>
Sat, 25 Aug 2018 15:10:08 +0000 (17:10 +0200)
committerRalf Jung <post@ralfj.de>
Mon, 27 Aug 2018 16:12:49 +0000 (18:12 +0200)
src/librustc_mir/interpret/place.rs

index d4300f251767be954363afd42bf2b9f857791e26..e031c86ee96de0df6eb2623d392756b27b9b763b 100644 (file)
@@ -489,11 +489,17 @@ pub(super) fn eval_place_to_mplace(
                     promoted: None
                 };
                 // Just create a lazy reference, so we can support recursive statics.
+                // tcx takes are of assigning every static one and only one unique AllocId.
                 // When the data here is ever actually used, memory will notice,
                 // and it knows how to deal with alloc_id that are present in the
-                // global table but not in its local memory.
-                let alloc = self.tcx.alloc_map.lock()
-                    .intern_static(cid.instance.def_id());
+                // global table but not in its local memory: It calls back into tcx through
+                // a query, triggering the CTFE machinery to actually turn this lazy reference
+                // into a bunch of bytes.  IOW, statics are evaluated with CTFE even when
+                // this EvalContext uses another Machine (e.g., in miri).  This is what we
+                // want!  This way, computing statics works concistently between codegen
+                // and miri: They use the same query to eventually obtain a `ty::Const`
+                // and use that for further computation.
+                let alloc = self.tcx.alloc_map.lock().intern_static(cid.instance.def_id());
                 MPlaceTy::from_aligned_ptr(alloc.into(), layout)
             }