diff options
| author | Ralf Jung <post@ralfj.de> | 2018-08-25 17:10:08 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2018-08-27 18:12:49 +0200 |
| commit | 07bdd48b604c314ef081636662a0ef35e941e39b (patch) | |
| tree | dc3e546d23bb42ecc13c308b96439786af7465da | |
| parent | c898e1911d3e7280441839762a86ea351f3fdae5 (diff) | |
| download | rust-07bdd48b604c314ef081636662a0ef35e941e39b.tar.gz rust-07bdd48b604c314ef081636662a0ef35e941e39b.zip | |
expand comment on how statics work
| -rw-r--r-- | src/librustc_mir/interpret/place.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index d4300f25176..e031c86ee96 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -489,11 +489,17 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> { 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) } |
