Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
30659cd
older toolchains not valid any more
andjo403 Jul 19, 2020
2cfcc0c
Fix regionck failure when converting Index to IndexMut
nbdd0121 Jul 30, 2020
000f5cd
Add UI test for issue 74933
nbdd0121 Jul 30, 2020
b5cef24
Update asm! documentation in unstable book
Amanieu Aug 6, 2020
26792a6
Move to doc links inside std/time.rs
poliorcetics Aug 10, 2020
a6e492b
Move to doc links inside the prelude
poliorcetics Aug 10, 2020
29045b6
Switch to intra-doc links in library/std/src/os/*/fs.rs
nixphix Aug 11, 2020
1a0a4ac
Add a function to `TyCtxt` for computing an `Allocation` for a `stati…
oli-obk Aug 11, 2020
32fccc4
Revert #tymethods
nixphix Aug 11, 2020
3ff06a9
Move the std::vec link back to a path-based link to make it compile w…
poliorcetics Aug 11, 2020
bd01bf9
Remove two links by changing the doc for SystemTimeError::duration
poliorcetics Aug 11, 2020
883dffa
Accept more safety comments (notably those that are on multiple lines…
poliorcetics Aug 11, 2020
df5c889
word change
joseluis Aug 11, 2020
7e503a0
Rollup merge of #74521 - andjo403:readme, r=nikic
JohnTitor Aug 12, 2020
43babed
Rollup merge of #74960 - nbdd0121:typeck, r=nikomatsakis
JohnTitor Aug 12, 2020
0bdb839
Rollup merge of #75234 - Amanieu:asm_unstable_book, r=nikomatsakis
JohnTitor Aug 12, 2020
c423fde
Rollup merge of #75368 - poliorcetics:intra-doc-links-std-prelude, r=…
JohnTitor Aug 12, 2020
261773e
Rollup merge of #75371 - poliorcetics:intra-doc-links-std-time, r=jyn514
JohnTitor Aug 12, 2020
5ef0a0a
Rollup merge of #75394 - oli-obk:get_static, r=RalfJung
JohnTitor Aug 12, 2020
7a90083
Rollup merge of #75395 - nixphix:docs/os-fs, r=jyn514
JohnTitor Aug 12, 2020
a8b0a3c
Rollup merge of #75422 - poliorcetics:tidy-accept-more-safety-comment…
JohnTitor Aug 12, 2020
2cc7da6
Rollup merge of #75424 - joseluis:patch-1, r=joshtriplett
JohnTitor Aug 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/librustc_middle/mir/interpret/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,27 @@ impl<'tcx> TyCtxt<'tcx> {
self.const_eval_validated(inputs)
}
}

/// Evaluate a static's initializer, returning the allocation of the initializer's memory.
pub fn eval_static_initializer(
self,
def_id: DefId,
) -> Result<&'tcx mir::Allocation, ErrorHandled> {
trace!("eval_static_initializer: Need to compute {:?}", def_id);
assert!(self.is_static(def_id));
let instance = ty::Instance::mono(self, def_id);
let gid = GlobalId { instance, promoted: None };
self.eval_to_allocation(gid, ty::ParamEnv::reveal_all())
}

/// Evaluate anything constant-like, returning the allocation of the final memory.
fn eval_to_allocation(
self,
gid: GlobalId<'tcx>,
param_env: ty::ParamEnv<'tcx>,
) -> Result<&'tcx mir::Allocation, ErrorHandled> {
trace!("eval_to_allocation: Need to compute {:?}", gid);
let raw_const = self.const_eval_raw(param_env.and(gid))?;
Ok(self.global_alloc(raw_const.alloc_id).unwrap_memory())
}
}
20 changes: 4 additions & 16 deletions src/librustc_mir/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ use std::ptr;

use rustc_ast::ast::Mutability;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::def_id::DefId;
use rustc_middle::ty::{self, Instance, ParamEnv, TyCtxt};
use rustc_middle::ty::{Instance, ParamEnv, TyCtxt};
use rustc_target::abi::{Align, HasDataLayout, Size, TargetDataLayout};

use super::{
AllocId, AllocMap, Allocation, AllocationExtra, CheckInAllocMsg, GlobalAlloc, GlobalId,
InterpResult, Machine, MayLeak, Pointer, PointerArithmetic, Scalar,
AllocId, AllocMap, Allocation, AllocationExtra, CheckInAllocMsg, GlobalAlloc, InterpResult,
Machine, MayLeak, Pointer, PointerArithmetic, Scalar,
};
use crate::util::pretty;

Expand Down Expand Up @@ -119,17 +118,6 @@ pub struct Memory<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
pub tcx: TyCtxt<'tcx>,
}

/// Return the `tcx` allocation containing the initial value of the given static
pub fn get_static(tcx: TyCtxt<'tcx>, def_id: DefId) -> InterpResult<'tcx, &'tcx Allocation> {
trace!("get_static: Need to compute {:?}", def_id);
let instance = Instance::mono(tcx, def_id);
let gid = GlobalId { instance, promoted: None };
// Use the raw query here to break validation cycles. Later uses of the static
// will call the full query anyway.
let raw_const = tcx.const_eval_raw(ty::ParamEnv::reveal_all().and(gid))?;
Ok(tcx.global_alloc(raw_const.alloc_id).unwrap_memory())
}

impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout for Memory<'mir, 'tcx, M> {
#[inline]
fn data_layout(&self) -> &TargetDataLayout {
Expand Down Expand Up @@ -489,7 +477,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
throw_unsup!(ReadExternStatic(def_id));
}

(get_static(tcx, def_id)?, Some(def_id))
(tcx.eval_static_initializer(def_id)?, Some(def_id))
}
};
M::before_access_global(memory_extra, id, alloc, def_id, is_write)?;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub use rustc_middle::mir::interpret::*; // have all the `interpret` symbols in
pub use self::eval_context::{Frame, FrameInfo, InterpCx, LocalState, LocalValue, StackPopCleanup};
pub use self::intern::{intern_const_alloc_recursive, InternKind};
pub use self::machine::{compile_time_machine, AllocMap, Machine, MayLeak, StackPopJump};
pub use self::memory::{get_static, AllocCheck, FnVal, Memory, MemoryKind};
pub use self::memory::{AllocCheck, FnVal, Memory, MemoryKind};
pub use self::operand::{ImmTy, Immediate, OpTy, Operand};
pub use self::place::{MPlaceTy, MemPlace, MemPlaceMeta, Place, PlaceTy};
pub use self::validity::RefTracking;
Expand Down