2019-04-22 15:29:04 +01:00
|
|
|
// ignore-tidy-filelength
|
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
//! Type context book-keeping.
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2019-03-29 17:49:11 +01:00
|
|
|
use crate::arena::Arena;
|
2019-02-05 11:20:45 -06:00
|
|
|
use crate::dep_graph::DepGraph;
|
2019-01-20 05:44:02 +01:00
|
|
|
use crate::dep_graph::{self, DepNode, DepConstructor};
|
2019-02-05 11:20:45 -06:00
|
|
|
use crate::session::Session;
|
|
|
|
use crate::session::config::{BorrowckMode, OutputFilenames};
|
|
|
|
use crate::session::config::CrateType;
|
|
|
|
use crate::middle;
|
|
|
|
use crate::hir::{TraitCandidate, HirId, ItemKind, ItemLocalId, Node};
|
2019-04-20 19:36:05 +03:00
|
|
|
use crate::hir::def::{Res, DefKind, Export};
|
2019-02-05 11:20:45 -06:00
|
|
|
use crate::hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE};
|
|
|
|
use crate::hir::map as hir_map;
|
|
|
|
use crate::hir::map::DefPathHash;
|
|
|
|
use crate::lint::{self, Lint};
|
|
|
|
use crate::ich::{StableHashingContext, NodeIdHashingMode};
|
|
|
|
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
|
|
|
|
use crate::infer::outlives::free_region_map::FreeRegionMap;
|
|
|
|
use crate::middle::cstore::CrateStoreDyn;
|
|
|
|
use crate::middle::cstore::EncodedMetadata;
|
|
|
|
use crate::middle::lang_items;
|
|
|
|
use crate::middle::resolve_lifetime::{self, ObjectLifetimeDefault};
|
|
|
|
use crate::middle::stability;
|
2019-05-17 23:55:04 +02:00
|
|
|
use crate::mir::{self, Body, interpret, ProjectionKind};
|
2019-04-03 15:29:31 +02:00
|
|
|
use crate::mir::interpret::{ConstValue, Allocation, Scalar};
|
2019-02-20 01:14:56 +00:00
|
|
|
use crate::ty::subst::{Kind, InternalSubsts, SubstsRef, Subst};
|
2019-02-05 11:20:45 -06:00
|
|
|
use crate::ty::ReprOptions;
|
|
|
|
use crate::traits;
|
|
|
|
use crate::traits::{Clause, Clauses, GoalKind, Goal, Goals};
|
2018-12-19 12:20:59 +02:00
|
|
|
use crate::ty::{self, DefIdTree, Ty, TypeAndMut};
|
2019-02-05 11:20:45 -06:00
|
|
|
use crate::ty::{TyS, TyKind, List};
|
2019-03-14 10:19:31 +01:00
|
|
|
use crate::ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorSubsts, Region, Const};
|
2019-02-05 11:20:45 -06:00
|
|
|
use crate::ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate};
|
|
|
|
use crate::ty::RegionKind;
|
2019-02-20 01:14:56 +00:00
|
|
|
use crate::ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid, ConstVid};
|
2019-02-05 11:20:45 -06:00
|
|
|
use crate::ty::TyKind::*;
|
2019-02-20 01:14:56 +00:00
|
|
|
use crate::ty::{InferConst, ParamConst};
|
2019-02-05 11:20:45 -06:00
|
|
|
use crate::ty::GenericParamDefKind;
|
|
|
|
use crate::ty::layout::{LayoutDetails, TargetDataLayout, VariantIdx};
|
|
|
|
use crate::ty::query;
|
|
|
|
use crate::ty::steal::Steal;
|
|
|
|
use crate::ty::subst::{UserSubsts, UnpackedKind};
|
|
|
|
use crate::ty::{BoundVar, BindingMode};
|
|
|
|
use crate::ty::CanonicalPolyFnSig;
|
2019-04-20 19:46:19 +03:00
|
|
|
use crate::util::common::ErrorReported;
|
2019-02-23 16:11:34 +05:30
|
|
|
use crate::util::nodemap::{DefIdMap, DefIdSet, ItemLocalMap, ItemLocalSet};
|
2019-02-05 11:20:45 -06:00
|
|
|
use crate::util::nodemap::{FxHashMap, FxHashSet};
|
2019-02-09 11:24:02 +09:00
|
|
|
use errors::DiagnosticBuilder;
|
2018-05-17 05:19:08 +02:00
|
|
|
use rustc_data_structures::interner::HashInterner;
|
2018-08-24 13:51:32 +10:00
|
|
|
use smallvec::SmallVec;
|
2017-09-13 18:20:27 +02:00
|
|
|
use rustc_data_structures::stable_hasher::{HashStable, hash_stable_hashmap,
|
2017-09-14 17:40:37 +02:00
|
|
|
StableHasher, StableHasherResult,
|
|
|
|
StableVec};
|
2018-04-15 16:01:38 +02:00
|
|
|
use arena::{TypedArena, SyncDroplessArena};
|
2018-11-16 22:56:18 +01:00
|
|
|
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
|
2018-12-08 20:30:23 +01:00
|
|
|
use rustc_data_structures::sync::{Lrc, Lock, WorkerLocal};
|
2017-09-07 13:21:46 -07:00
|
|
|
use std::any::Any;
|
2015-09-06 21:51:58 +03:00
|
|
|
use std::borrow::Borrow;
|
2017-04-27 13:04:57 -04:00
|
|
|
use std::cmp::Ordering;
|
2017-08-10 16:10:04 +02:00
|
|
|
use std::collections::hash_map::{self, Entry};
|
2015-09-06 21:51:58 +03:00
|
|
|
use std::hash::{Hash, Hasher};
|
2018-06-27 06:01:19 -04:00
|
|
|
use std::fmt;
|
2016-05-11 04:14:41 +03:00
|
|
|
use std::mem;
|
2018-09-10 13:40:34 +02:00
|
|
|
use std::ops::{Deref, Bound};
|
2016-10-24 18:23:29 -06:00
|
|
|
use std::iter;
|
2017-09-13 16:03:24 -07:00
|
|
|
use std::sync::mpsc;
|
2017-09-13 20:26:39 -07:00
|
|
|
use std::sync::Arc;
|
2018-12-07 06:59:27 +01:00
|
|
|
use std::marker::PhantomData;
|
2018-04-25 19:30:39 +03:00
|
|
|
use rustc_target::spec::abi;
|
2018-12-03 01:14:35 +01:00
|
|
|
use rustc_macros::HashStable;
|
2019-02-26 11:48:34 +01:00
|
|
|
use syntax::ast;
|
2015-09-14 21:58:20 +12:00
|
|
|
use syntax::attr;
|
2018-08-18 12:14:03 +02:00
|
|
|
use syntax::source_map::MultiSpan;
|
2018-02-14 16:11:02 +01:00
|
|
|
use syntax::feature_gate;
|
2019-05-11 17:41:37 +03:00
|
|
|
use syntax::symbol::{Symbol, InternedString, kw, sym};
|
2017-05-24 16:23:02 +01:00
|
|
|
use syntax_pos::Span;
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2019-02-05 11:20:45 -06:00
|
|
|
use crate::hir;
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2017-12-03 13:57:25 +01:00
|
|
|
pub struct AllArenas<'tcx> {
|
2018-01-22 14:31:23 +01:00
|
|
|
pub global: WorkerLocal<GlobalArenas<'tcx>>,
|
2018-04-15 16:01:38 +02:00
|
|
|
pub interner: SyncDroplessArena,
|
2017-12-03 13:57:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> AllArenas<'tcx> {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
AllArenas {
|
2018-10-16 16:57:53 +02:00
|
|
|
global: WorkerLocal::new(|_| GlobalArenas::default()),
|
|
|
|
interner: SyncDroplessArena::default(),
|
2017-12-03 13:57:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
/// Internal storage
|
2018-10-16 16:57:53 +02:00
|
|
|
#[derive(Default)]
|
2016-12-23 20:48:21 -07:00
|
|
|
pub struct GlobalArenas<'tcx> {
|
2015-09-06 21:51:58 +03:00
|
|
|
// internings
|
2017-10-28 16:52:41 +03:00
|
|
|
layout: TypedArena<LayoutDetails>,
|
2015-09-06 21:51:58 +03:00
|
|
|
|
|
|
|
// references
|
2017-01-25 22:01:11 +02:00
|
|
|
generics: TypedArena<ty::Generics>,
|
2016-11-25 02:29:26 +02:00
|
|
|
trait_def: TypedArena<ty::TraitDef>,
|
2016-11-25 01:33:29 +02:00
|
|
|
adt_def: TypedArena<ty::AdtDef>,
|
2019-05-17 23:55:04 +02:00
|
|
|
steal_mir: TypedArena<Steal<Body<'tcx>>>,
|
|
|
|
mir: TypedArena<Body<'tcx>>,
|
2017-01-25 16:24:00 -05:00
|
|
|
tables: TypedArena<ty::TypeckTables<'tcx>>,
|
2017-12-06 09:25:29 +01:00
|
|
|
/// miri allocations
|
|
|
|
const_allocs: TypedArena<interpret::Allocation>,
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-05-17 05:19:08 +02:00
|
|
|
type InternedSet<'tcx, T> = Lock<FxHashMap<Interned<'tcx, T>, ()>>;
|
2018-04-09 16:38:00 +09:00
|
|
|
|
2016-05-11 04:14:41 +03:00
|
|
|
pub struct CtxtInterners<'tcx> {
|
2016-12-23 20:48:21 -07:00
|
|
|
/// The arena that types, regions, etc are allocated from
|
2018-04-15 16:01:38 +02:00
|
|
|
arena: &'tcx SyncDroplessArena,
|
2016-04-28 03:13:17 +03:00
|
|
|
|
|
|
|
/// Specifically use a speedy hash algorithm for these hash sets,
|
|
|
|
/// they're accessed quite often.
|
2018-04-09 16:38:00 +09:00
|
|
|
type_: InternedSet<'tcx, TyS<'tcx>>,
|
2018-08-22 00:35:01 +01:00
|
|
|
type_list: InternedSet<'tcx, List<Ty<'tcx>>>,
|
2019-02-26 09:30:34 +08:00
|
|
|
substs: InternedSet<'tcx, InternalSubsts<'tcx>>,
|
2018-08-22 00:35:01 +01:00
|
|
|
canonical_var_infos: InternedSet<'tcx, List<CanonicalVarInfo>>,
|
2018-04-09 16:38:00 +09:00
|
|
|
region: InternedSet<'tcx, RegionKind>,
|
2018-08-22 00:35:01 +01:00
|
|
|
existential_predicates: InternedSet<'tcx, List<ExistentialPredicate<'tcx>>>,
|
|
|
|
predicates: InternedSet<'tcx, List<Predicate<'tcx>>>,
|
|
|
|
clauses: InternedSet<'tcx, List<Clause<'tcx>>>,
|
2018-10-06 13:51:02 +02:00
|
|
|
goal: InternedSet<'tcx, GoalKind<'tcx>>,
|
|
|
|
goal_list: InternedSet<'tcx, List<Goal<'tcx>>>,
|
2019-03-28 18:00:17 -07:00
|
|
|
projs: InternedSet<'tcx, List<ProjectionKind>>,
|
2019-03-14 10:19:31 +01:00
|
|
|
const_: InternedSet<'tcx, Const<'tcx>>,
|
2016-04-28 03:13:17 +03:00
|
|
|
}
|
|
|
|
|
2016-05-11 04:14:41 +03:00
|
|
|
impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
|
2018-04-15 16:01:38 +02:00
|
|
|
fn new(arena: &'tcx SyncDroplessArena) -> CtxtInterners<'tcx> {
|
2016-04-28 03:13:17 +03:00
|
|
|
CtxtInterners {
|
2018-04-09 16:38:00 +09:00
|
|
|
arena,
|
|
|
|
type_: Default::default(),
|
|
|
|
type_list: Default::default(),
|
|
|
|
substs: Default::default(),
|
|
|
|
region: Default::default(),
|
|
|
|
existential_predicates: Default::default(),
|
|
|
|
canonical_var_infos: Default::default(),
|
|
|
|
predicates: Default::default(),
|
|
|
|
clauses: Default::default(),
|
2018-10-06 13:51:02 +02:00
|
|
|
goal: Default::default(),
|
|
|
|
goal_list: Default::default(),
|
2018-10-26 11:28:40 +02:00
|
|
|
projs: Default::default(),
|
2019-03-14 10:19:31 +01:00
|
|
|
const_: Default::default(),
|
2016-04-28 03:13:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-30 08:59:23 +02:00
|
|
|
/// Intern a type
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline(never)]
|
2018-04-30 08:59:23 +02:00
|
|
|
fn intern_ty(
|
|
|
|
local: &CtxtInterners<'tcx>,
|
|
|
|
global: &CtxtInterners<'gcx>,
|
2018-08-22 01:34:12 +01:00
|
|
|
st: TyKind<'tcx>
|
2018-04-30 08:59:23 +02:00
|
|
|
) -> Ty<'tcx> {
|
|
|
|
let flags = super::flags::FlagComputation::for_sty(&st);
|
|
|
|
|
|
|
|
// HACK(eddyb) Depend on flags being accurate to
|
|
|
|
// determine that all contents are in the global tcx.
|
|
|
|
// See comments on Lift for why we can't use that.
|
|
|
|
if flags.flags.intersects(ty::TypeFlags::KEEP_IN_LOCAL_TCX) {
|
2018-05-17 05:19:08 +02:00
|
|
|
local.type_.borrow_mut().intern(st, |st| {
|
|
|
|
let ty_struct = TyS {
|
|
|
|
sty: st,
|
|
|
|
flags: flags.flags,
|
|
|
|
outer_exclusive_binder: flags.outer_exclusive_binder,
|
|
|
|
};
|
2016-05-11 04:14:41 +03:00
|
|
|
|
2018-05-17 05:19:08 +02:00
|
|
|
// Make sure we don't end up with inference
|
|
|
|
// types/regions in the global interner
|
2019-02-23 14:25:03 +00:00
|
|
|
if ptr_eq(local, global) {
|
2018-05-17 05:19:08 +02:00
|
|
|
bug!("Attempted to intern `{:?}` which contains \
|
|
|
|
inference types/regions in the global type context",
|
|
|
|
&ty_struct);
|
|
|
|
}
|
2016-04-28 03:13:17 +03:00
|
|
|
|
2018-05-17 05:19:08 +02:00
|
|
|
Interned(local.arena.alloc(ty_struct))
|
|
|
|
}).0
|
2018-04-30 08:59:23 +02:00
|
|
|
} else {
|
2018-05-17 05:19:08 +02:00
|
|
|
global.type_.borrow_mut().intern(st, |st| {
|
|
|
|
let ty_struct = TyS {
|
|
|
|
sty: st,
|
|
|
|
flags: flags.flags,
|
|
|
|
outer_exclusive_binder: flags.outer_exclusive_binder,
|
|
|
|
};
|
2018-04-30 08:59:23 +02:00
|
|
|
|
2018-05-17 05:19:08 +02:00
|
|
|
// This is safe because all the types the ty_struct can point to
|
|
|
|
// already is in the global arena
|
|
|
|
let ty_struct: TyS<'gcx> = unsafe {
|
|
|
|
mem::transmute(ty_struct)
|
|
|
|
};
|
2016-04-28 03:13:17 +03:00
|
|
|
|
2018-05-17 05:19:08 +02:00
|
|
|
Interned(global.arena.alloc(ty_struct))
|
|
|
|
}).0
|
2018-04-30 08:59:23 +02:00
|
|
|
}
|
|
|
|
}
|
2016-04-28 03:13:17 +03:00
|
|
|
}
|
|
|
|
|
2018-12-01 18:13:27 +01:00
|
|
|
pub struct Common<'tcx> {
|
|
|
|
pub empty_predicates: ty::GenericPredicates<'tcx>,
|
|
|
|
}
|
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
pub struct CommonTypes<'tcx> {
|
2018-11-29 21:13:04 +01:00
|
|
|
pub unit: Ty<'tcx>,
|
2015-09-06 21:51:58 +03:00
|
|
|
pub bool: Ty<'tcx>,
|
|
|
|
pub char: Ty<'tcx>,
|
|
|
|
pub isize: Ty<'tcx>,
|
|
|
|
pub i8: Ty<'tcx>,
|
|
|
|
pub i16: Ty<'tcx>,
|
|
|
|
pub i32: Ty<'tcx>,
|
|
|
|
pub i64: Ty<'tcx>,
|
2016-08-23 03:56:52 +03:00
|
|
|
pub i128: Ty<'tcx>,
|
2015-09-06 21:51:58 +03:00
|
|
|
pub usize: Ty<'tcx>,
|
|
|
|
pub u8: Ty<'tcx>,
|
|
|
|
pub u16: Ty<'tcx>,
|
|
|
|
pub u32: Ty<'tcx>,
|
|
|
|
pub u64: Ty<'tcx>,
|
2016-08-23 03:56:52 +03:00
|
|
|
pub u128: Ty<'tcx>,
|
2015-09-06 21:51:58 +03:00
|
|
|
pub f32: Ty<'tcx>,
|
|
|
|
pub f64: Ty<'tcx>,
|
2016-08-02 15:56:20 +08:00
|
|
|
pub never: Ty<'tcx>,
|
2015-09-06 21:51:58 +03:00
|
|
|
pub err: Ty<'tcx>,
|
2017-04-20 01:58:12 +03:00
|
|
|
|
2019-04-03 11:46:40 +02:00
|
|
|
/// Dummy type used for the `Self` of a `TraitRef` created for converting
|
|
|
|
/// a trait object, and which gets removed in `ExistentialTraitRef`.
|
|
|
|
/// This type must not appear anywhere in other converted types.
|
|
|
|
pub trait_object_dummy_self: Ty<'tcx>,
|
2019-04-25 22:04:51 +01:00
|
|
|
}
|
2019-04-03 11:46:40 +02:00
|
|
|
|
2019-04-25 22:04:51 +01:00
|
|
|
pub struct CommonLifetimes<'tcx> {
|
2017-04-20 04:45:53 -04:00
|
|
|
pub re_empty: Region<'tcx>,
|
|
|
|
pub re_static: Region<'tcx>,
|
|
|
|
pub re_erased: Region<'tcx>,
|
2019-05-01 23:09:53 +01:00
|
|
|
}
|
2019-03-08 01:15:37 +00:00
|
|
|
|
2019-05-01 23:09:53 +01:00
|
|
|
pub struct CommonConsts<'tcx> {
|
|
|
|
pub err: &'tcx Const<'tcx>,
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2017-08-10 16:10:04 +02:00
|
|
|
pub struct LocalTableInContext<'a, V: 'a> {
|
2017-08-11 11:56:26 +02:00
|
|
|
local_id_root: Option<DefId>,
|
2017-08-10 16:10:04 +02:00
|
|
|
data: &'a ItemLocalMap<V>
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Validate that the given HirId (respectively its `local_id` part) can be
|
|
|
|
/// safely used as a key in the tables of a TypeckTable. For that to be
|
|
|
|
/// the case, the HirId must have the same `owner` as all the other IDs in
|
|
|
|
/// this table (signified by `local_id_root`). Otherwise the HirId
|
|
|
|
/// would be in a different frame of reference and using its `local_id`
|
|
|
|
/// would result in lookup errors, or worse, in silently wrong data being
|
|
|
|
/// stored/returned.
|
2017-08-11 11:56:26 +02:00
|
|
|
fn validate_hir_id_for_typeck_tables(local_id_root: Option<DefId>,
|
|
|
|
hir_id: hir::HirId,
|
|
|
|
mut_access: bool) {
|
2017-08-14 14:56:35 +02:00
|
|
|
if cfg!(debug_assertions) {
|
2017-08-11 11:56:26 +02:00
|
|
|
if let Some(local_id_root) = local_id_root {
|
|
|
|
if hir_id.owner != local_id_root.index {
|
2017-08-10 16:10:04 +02:00
|
|
|
ty::tls::with(|tcx| {
|
2018-12-04 13:45:36 +01:00
|
|
|
let node_id = tcx.hir().hir_to_node_id(hir_id);
|
2017-08-10 16:10:04 +02:00
|
|
|
|
|
|
|
bug!("node {} with HirId::owner {:?} cannot be placed in \
|
|
|
|
TypeckTables with local_id_root {:?}",
|
2018-12-04 13:45:36 +01:00
|
|
|
tcx.hir().node_to_string(node_id),
|
2018-10-01 15:26:53 +02:00
|
|
|
DefId::local(hir_id.owner),
|
|
|
|
local_id_root)
|
2017-08-10 16:10:04 +02:00
|
|
|
});
|
|
|
|
}
|
2017-08-11 11:56:26 +02:00
|
|
|
} else {
|
|
|
|
// We use "Null Object" TypeckTables in some of the analysis passes.
|
|
|
|
// These are just expected to be empty and their `local_id_root` is
|
|
|
|
// `None`. Therefore we cannot verify whether a given `HirId` would
|
|
|
|
// be a valid key for the given table. Instead we make sure that
|
|
|
|
// nobody tries to write to such a Null Object table.
|
|
|
|
if mut_access {
|
|
|
|
bug!("access to invalid TypeckTables")
|
|
|
|
}
|
2017-08-10 16:10:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, V> LocalTableInContext<'a, V> {
|
|
|
|
pub fn contains_key(&self, id: hir::HirId) -> bool {
|
2017-08-11 11:56:26 +02:00
|
|
|
validate_hir_id_for_typeck_tables(self.local_id_root, id, false);
|
2017-08-10 16:10:04 +02:00
|
|
|
self.data.contains_key(&id.local_id)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get(&self, id: hir::HirId) -> Option<&V> {
|
2017-08-11 11:56:26 +02:00
|
|
|
validate_hir_id_for_typeck_tables(self.local_id_root, id, false);
|
2017-08-10 16:10:04 +02:00
|
|
|
self.data.get(&id.local_id)
|
|
|
|
}
|
|
|
|
|
2018-08-29 22:02:42 -07:00
|
|
|
pub fn iter(&self) -> hash_map::Iter<'_, hir::ItemLocalId, V> {
|
2017-08-10 16:10:04 +02:00
|
|
|
self.data.iter()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, V> ::std::ops::Index<hir::HirId> for LocalTableInContext<'a, V> {
|
|
|
|
type Output = V;
|
|
|
|
|
|
|
|
fn index(&self, key: hir::HirId) -> &V {
|
|
|
|
self.get(key).expect("LocalTableInContext: key not found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct LocalTableInContextMut<'a, V: 'a> {
|
2017-08-11 11:56:26 +02:00
|
|
|
local_id_root: Option<DefId>,
|
2017-08-10 16:10:04 +02:00
|
|
|
data: &'a mut ItemLocalMap<V>
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, V> LocalTableInContextMut<'a, V> {
|
|
|
|
pub fn get_mut(&mut self, id: hir::HirId) -> Option<&mut V> {
|
2017-08-11 11:56:26 +02:00
|
|
|
validate_hir_id_for_typeck_tables(self.local_id_root, id, true);
|
2017-08-10 16:10:04 +02:00
|
|
|
self.data.get_mut(&id.local_id)
|
|
|
|
}
|
|
|
|
|
2018-08-29 22:02:42 -07:00
|
|
|
pub fn entry(&mut self, id: hir::HirId) -> Entry<'_, hir::ItemLocalId, V> {
|
2017-08-11 11:56:26 +02:00
|
|
|
validate_hir_id_for_typeck_tables(self.local_id_root, id, true);
|
2017-08-10 16:10:04 +02:00
|
|
|
self.data.entry(id.local_id)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn insert(&mut self, id: hir::HirId, val: V) -> Option<V> {
|
2017-08-11 11:56:26 +02:00
|
|
|
validate_hir_id_for_typeck_tables(self.local_id_root, id, true);
|
2017-08-10 16:10:04 +02:00
|
|
|
self.data.insert(id.local_id, val)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn remove(&mut self, id: hir::HirId) -> Option<V> {
|
2017-08-11 11:56:26 +02:00
|
|
|
validate_hir_id_for_typeck_tables(self.local_id_root, id, true);
|
2017-08-10 16:10:04 +02:00
|
|
|
self.data.remove(&id.local_id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-29 16:33:53 +01:00
|
|
|
/// All information necessary to validate and reveal an `impl Trait` or `existential Type`
|
2018-12-03 01:14:35 +01:00
|
|
|
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
|
2019-01-29 16:33:53 +01:00
|
|
|
pub struct ResolvedOpaqueTy<'tcx> {
|
|
|
|
/// The revealed type as seen by this function.
|
|
|
|
pub concrete_type: Ty<'tcx>,
|
|
|
|
/// Generic parameters on the opaque type as passed by this function.
|
|
|
|
/// For `existential type Foo<A, B>; fn foo<T, U>() -> Foo<T, U> { .. }` this is `[T, U]`, not
|
|
|
|
/// `[A, B]`
|
2019-02-09 22:11:53 +08:00
|
|
|
pub substs: SubstsRef<'tcx>,
|
2019-01-29 16:33:53 +01:00
|
|
|
}
|
|
|
|
|
2017-09-22 19:13:19 -07:00
|
|
|
#[derive(RustcEncodable, RustcDecodable, Debug)]
|
2017-01-25 16:24:00 -05:00
|
|
|
pub struct TypeckTables<'tcx> {
|
2017-08-04 09:49:40 +02:00
|
|
|
/// The HirId::owner all ItemLocalIds in this table are relative to.
|
2017-08-11 11:56:26 +02:00
|
|
|
pub local_id_root: Option<DefId>,
|
2017-08-04 09:49:40 +02:00
|
|
|
|
2017-05-20 16:11:07 +03:00
|
|
|
/// Resolved definitions for `<T>::X` associated paths and
|
|
|
|
/// method calls, including those of overloaded operators.
|
2019-04-20 19:46:19 +03:00
|
|
|
type_dependent_defs: ItemLocalMap<Result<(DefKind, DefId), ErrorReported>>,
|
2016-11-25 13:21:19 +02:00
|
|
|
|
2018-04-05 03:20:21 +03:00
|
|
|
/// Resolved field indices for field accesses in expressions (`S { field }`, `obj.field`)
|
|
|
|
/// or patterns (`S { field }`). The index is often useful by itself, but to learn more
|
|
|
|
/// about the field you also need definition of the variant to which the field
|
|
|
|
/// belongs, but it may not exist if it's a tuple field (`tuple.0`).
|
|
|
|
field_indices: ItemLocalMap<usize>,
|
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Stores the types for various nodes in the AST. Note that this table
|
|
|
|
/// is not guaranteed to be populated until after typeck. See
|
2015-09-06 21:51:58 +03:00
|
|
|
/// typeck::check::fn_ctxt for details.
|
2017-08-10 16:10:04 +02:00
|
|
|
node_types: ItemLocalMap<Ty<'tcx>>,
|
2015-09-06 21:51:58 +03:00
|
|
|
|
|
|
|
/// Stores the type parameters which were substituted to obtain the type
|
2019-02-08 14:53:55 +01:00
|
|
|
/// of this node. This only applies to nodes that refer to entities
|
2015-09-06 21:51:58 +03:00
|
|
|
/// parameterized by type parameters, such as generic fns, types, or
|
|
|
|
/// other items.
|
2019-02-09 22:11:53 +08:00
|
|
|
node_substs: ItemLocalMap<SubstsRef<'tcx>>,
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2018-11-16 22:56:18 +01:00
|
|
|
/// This will either store the canonicalized types provided by the user
|
|
|
|
/// or the substitutions that the user explicitly gave (if any) attached
|
|
|
|
/// to `id`. These will not include any inferred values. The canonical form
|
|
|
|
/// is used to capture things like `_` or other unspecified values.
|
|
|
|
///
|
|
|
|
/// For example, if the user wrote `foo.collect::<Vec<_>>()`, then the
|
|
|
|
/// canonical substitutions would include only `for<X> { Vec<X> }`.
|
|
|
|
///
|
|
|
|
/// See also `AscribeUserType` statement in MIR.
|
2019-01-06 16:04:00 +00:00
|
|
|
user_provided_types: ItemLocalMap<CanonicalUserType<'tcx>>,
|
2018-10-19 06:25:12 -04:00
|
|
|
|
|
|
|
/// Stores the canonicalized types provided by the user. See also
|
|
|
|
/// `AscribeUserType` statement in MIR.
|
2018-10-19 17:19:29 -04:00
|
|
|
pub user_provided_sigs: DefIdMap<CanonicalPolyFnSig<'tcx>>,
|
2018-10-19 06:25:12 -04:00
|
|
|
|
2017-08-10 16:10:04 +02:00
|
|
|
adjustments: ItemLocalMap<Vec<ty::adjustment::Adjustment<'tcx>>>,
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2017-10-06 16:30:23 -04:00
|
|
|
/// Stores the actual binding mode for all instances of hir::BindingAnnotation.
|
2017-08-10 16:10:04 +02:00
|
|
|
pat_binding_modes: ItemLocalMap<BindingMode>,
|
2017-07-21 19:29:43 -04:00
|
|
|
|
2017-10-06 16:30:23 -04:00
|
|
|
/// Stores the types which were implicitly dereferenced in pattern binding modes
|
|
|
|
/// for later usage in HAIR lowering. For example,
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// match &&Some(5i32) {
|
|
|
|
/// Some(n) => {},
|
|
|
|
/// _ => {},
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
/// leads to a `vec![&&Option<i32>, &Option<i32>]`. Empty vectors are not stored.
|
|
|
|
///
|
|
|
|
/// See:
|
|
|
|
/// https://github.com/rust-lang/rfcs/blob/master/text/2005-match-ergonomics.md#definitions
|
|
|
|
pat_adjustments: ItemLocalMap<Vec<Ty<'tcx>>>,
|
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
/// Borrows
|
2016-08-25 23:58:52 +03:00
|
|
|
pub upvar_capture_map: ty::UpvarCaptureMap<'tcx>,
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2017-11-08 12:36:28 -05:00
|
|
|
/// Records the reasons that we picked the kind of each closure;
|
|
|
|
/// not all closures are present in the map.
|
|
|
|
closure_kind_origins: ItemLocalMap<(Span, ast::Name)>,
|
2016-12-26 14:34:03 +01:00
|
|
|
|
2015-10-21 15:46:30 -04:00
|
|
|
/// For each fn, records the "liberated" types of its arguments
|
|
|
|
/// and return type. Liberated means that all bound regions
|
|
|
|
/// (including late-bound regions) are replaced with free
|
2018-05-08 16:10:16 +03:00
|
|
|
/// equivalents. This table is not used in codegen (since regions
|
2015-10-21 15:46:30 -04:00
|
|
|
/// are erased there) and hence is not serialized to metadata.
|
2017-08-10 16:10:04 +02:00
|
|
|
liberated_fn_sigs: ItemLocalMap<ty::FnSig<'tcx>>,
|
2016-02-11 18:31:42 +02:00
|
|
|
|
|
|
|
/// For each FRU expression, record the normalized types of the fields
|
|
|
|
/// of the struct - this is needed because it is non-trivial to
|
|
|
|
/// normalize while preserving regions. This table is used only in
|
|
|
|
/// MIR construction and hence is not serialized to metadata.
|
2017-08-10 16:10:04 +02:00
|
|
|
fru_field_types: ItemLocalMap<Vec<Ty<'tcx>>>,
|
2017-01-27 16:16:43 -05:00
|
|
|
|
2019-02-23 16:11:34 +05:30
|
|
|
/// For every coercion cast we add the HIR node ID of the cast
|
|
|
|
/// expression to this set.
|
|
|
|
coercion_casts: ItemLocalSet,
|
2017-01-28 18:13:21 -05:00
|
|
|
|
2017-02-14 11:32:00 +02:00
|
|
|
/// Set of trait imports actually used in the method resolution.
|
2017-10-16 23:41:51 -07:00
|
|
|
/// This is used for warning unused imports. During type
|
2018-02-27 17:11:14 +01:00
|
|
|
/// checking, this `Lrc` should not be cloned: it must have a ref-count
|
2017-10-19 23:06:22 -07:00
|
|
|
/// of 1 so that we can insert things into the set mutably.
|
2018-02-27 17:11:14 +01:00
|
|
|
pub used_trait_imports: Lrc<DefIdSet>,
|
2017-02-15 15:00:20 +02:00
|
|
|
|
|
|
|
/// If any errors occurred while type-checking this body,
|
|
|
|
/// this field will be set to `true`.
|
|
|
|
pub tainted_by_errors: bool,
|
2017-02-16 12:46:44 -05:00
|
|
|
|
|
|
|
/// Stores the free-region relationships that were deduced from
|
2019-02-08 14:53:55 +01:00
|
|
|
/// its where-clauses and parameter types. These are then
|
2017-02-16 12:46:44 -05:00
|
|
|
/// read-again by borrowck.
|
2017-04-20 04:45:53 -04:00
|
|
|
pub free_region_map: FreeRegionMap<'tcx>,
|
2018-05-22 14:31:56 +02:00
|
|
|
|
|
|
|
/// All the existential types that are restricted to concrete types
|
|
|
|
/// by this function
|
2019-01-29 16:33:53 +01:00
|
|
|
pub concrete_existential_types: FxHashMap<DefId, ResolvedOpaqueTy<'tcx>>,
|
2018-12-16 17:01:57 -08:00
|
|
|
|
|
|
|
/// Given the closure ID this map provides the list of UpvarIDs used by it.
|
|
|
|
/// The upvarID contains the HIR node ID and it also contains the full path
|
|
|
|
/// leading to the member of the struct or tuple that is used instead of the
|
|
|
|
/// entire variable.
|
2018-12-22 15:06:14 -08:00
|
|
|
pub upvar_list: ty::UpvarListMap,
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2017-01-25 16:24:00 -05:00
|
|
|
impl<'tcx> TypeckTables<'tcx> {
|
2017-08-11 11:56:26 +02:00
|
|
|
pub fn empty(local_id_root: Option<DefId>) -> TypeckTables<'tcx> {
|
2017-01-25 16:24:00 -05:00
|
|
|
TypeckTables {
|
2017-08-04 09:49:40 +02:00
|
|
|
local_id_root,
|
2018-07-21 22:15:11 +03:00
|
|
|
type_dependent_defs: Default::default(),
|
|
|
|
field_indices: Default::default(),
|
2018-11-16 22:56:18 +01:00
|
|
|
user_provided_types: Default::default(),
|
2018-10-19 06:25:12 -04:00
|
|
|
user_provided_sigs: Default::default(),
|
2018-07-21 22:15:11 +03:00
|
|
|
node_types: Default::default(),
|
|
|
|
node_substs: Default::default(),
|
|
|
|
adjustments: Default::default(),
|
|
|
|
pat_binding_modes: Default::default(),
|
|
|
|
pat_adjustments: Default::default(),
|
2018-10-16 16:57:53 +02:00
|
|
|
upvar_capture_map: Default::default(),
|
2018-07-21 22:15:11 +03:00
|
|
|
closure_kind_origins: Default::default(),
|
|
|
|
liberated_fn_sigs: Default::default(),
|
|
|
|
fru_field_types: Default::default(),
|
2019-02-23 16:11:34 +05:30
|
|
|
coercion_casts: Default::default(),
|
2018-07-21 22:15:11 +03:00
|
|
|
used_trait_imports: Lrc::new(Default::default()),
|
2017-02-15 15:00:20 +02:00
|
|
|
tainted_by_errors: false,
|
2018-10-16 16:57:53 +02:00
|
|
|
free_region_map: Default::default(),
|
|
|
|
concrete_existential_types: Default::default(),
|
2018-12-16 17:01:57 -08:00
|
|
|
upvar_list: Default::default(),
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
}
|
2016-10-27 04:52:10 +03:00
|
|
|
|
2016-11-25 13:21:19 +02:00
|
|
|
/// Returns the final resolution of a `QPath` in an `Expr` or `Pat` node.
|
2019-04-20 19:36:05 +03:00
|
|
|
pub fn qpath_res(&self, qpath: &hir::QPath, id: hir::HirId) -> Res {
|
2016-11-25 13:21:19 +02:00
|
|
|
match *qpath {
|
2019-04-20 19:36:05 +03:00
|
|
|
hir::QPath::Resolved(_, ref path) => path.res,
|
2019-04-20 19:46:19 +03:00
|
|
|
hir::QPath::TypeRelative(..) => self.type_dependent_def(id)
|
2019-04-20 19:36:05 +03:00
|
|
|
.map_or(Res::Err, |(kind, def_id)| Res::Def(kind, def_id)),
|
2016-11-25 13:21:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-20 19:46:19 +03:00
|
|
|
pub fn type_dependent_defs(
|
|
|
|
&self,
|
|
|
|
) -> LocalTableInContext<'_, Result<(DefKind, DefId), ErrorReported>> {
|
2017-08-10 16:10:04 +02:00
|
|
|
LocalTableInContext {
|
|
|
|
local_id_root: self.local_id_root,
|
|
|
|
data: &self.type_dependent_defs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-20 19:46:19 +03:00
|
|
|
pub fn type_dependent_def(&self, id: HirId) -> Option<(DefKind, DefId)> {
|
2019-03-15 17:42:34 +01:00
|
|
|
validate_hir_id_for_typeck_tables(self.local_id_root, id, false);
|
2019-04-20 19:46:19 +03:00
|
|
|
self.type_dependent_defs.get(&id.local_id).cloned().and_then(|r| r.ok())
|
2019-03-15 17:42:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn type_dependent_def_id(&self, id: HirId) -> Option<DefId> {
|
2019-04-20 19:46:19 +03:00
|
|
|
self.type_dependent_def(id).map(|(_, def_id)| def_id)
|
2019-03-15 17:42:34 +01:00
|
|
|
}
|
|
|
|
|
2019-04-20 19:46:19 +03:00
|
|
|
pub fn type_dependent_defs_mut(
|
|
|
|
&mut self,
|
|
|
|
) -> LocalTableInContextMut<'_, Result<(DefKind, DefId), ErrorReported>> {
|
2017-08-10 16:10:04 +02:00
|
|
|
LocalTableInContextMut {
|
|
|
|
local_id_root: self.local_id_root,
|
|
|
|
data: &mut self.type_dependent_defs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-29 22:02:42 -07:00
|
|
|
pub fn field_indices(&self) -> LocalTableInContext<'_, usize> {
|
2018-04-05 03:20:21 +03:00
|
|
|
LocalTableInContext {
|
|
|
|
local_id_root: self.local_id_root,
|
|
|
|
data: &self.field_indices
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-29 22:02:42 -07:00
|
|
|
pub fn field_indices_mut(&mut self) -> LocalTableInContextMut<'_, usize> {
|
2018-04-05 03:20:21 +03:00
|
|
|
LocalTableInContextMut {
|
|
|
|
local_id_root: self.local_id_root,
|
|
|
|
data: &mut self.field_indices
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-16 22:56:18 +01:00
|
|
|
pub fn user_provided_types(
|
|
|
|
&self
|
2019-01-06 16:04:00 +00:00
|
|
|
) -> LocalTableInContext<'_, CanonicalUserType<'tcx>> {
|
2018-03-15 18:49:10 +00:00
|
|
|
LocalTableInContext {
|
|
|
|
local_id_root: self.local_id_root,
|
2018-11-16 22:56:18 +01:00
|
|
|
data: &self.user_provided_types
|
2018-03-15 18:49:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-16 22:56:18 +01:00
|
|
|
pub fn user_provided_types_mut(
|
|
|
|
&mut self
|
2019-01-06 16:04:00 +00:00
|
|
|
) -> LocalTableInContextMut<'_, CanonicalUserType<'tcx>> {
|
2018-03-15 18:49:10 +00:00
|
|
|
LocalTableInContextMut {
|
|
|
|
local_id_root: self.local_id_root,
|
2018-11-16 22:56:18 +01:00
|
|
|
data: &mut self.user_provided_types
|
2018-03-15 18:49:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-29 22:02:42 -07:00
|
|
|
pub fn node_types(&self) -> LocalTableInContext<'_, Ty<'tcx>> {
|
2017-08-10 16:10:04 +02:00
|
|
|
LocalTableInContext {
|
|
|
|
local_id_root: self.local_id_root,
|
|
|
|
data: &self.node_types
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-29 22:02:42 -07:00
|
|
|
pub fn node_types_mut(&mut self) -> LocalTableInContextMut<'_, Ty<'tcx>> {
|
2017-08-10 16:10:04 +02:00
|
|
|
LocalTableInContextMut {
|
|
|
|
local_id_root: self.local_id_root,
|
|
|
|
data: &mut self.node_types
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-04 09:38:11 +01:00
|
|
|
pub fn node_type(&self, id: hir::HirId) -> Ty<'tcx> {
|
|
|
|
self.node_type_opt(id).unwrap_or_else(||
|
|
|
|
bug!("node_type: no type for node `{}`",
|
|
|
|
tls::with(|tcx| tcx.hir().hir_to_string(id)))
|
2018-10-01 15:37:14 +02:00
|
|
|
)
|
2016-10-27 04:52:10 +03:00
|
|
|
}
|
|
|
|
|
2019-02-04 09:38:11 +01:00
|
|
|
pub fn node_type_opt(&self, id: hir::HirId) -> Option<Ty<'tcx>> {
|
2017-08-11 11:56:26 +02:00
|
|
|
validate_hir_id_for_typeck_tables(self.local_id_root, id, false);
|
2017-08-07 14:43:43 +02:00
|
|
|
self.node_types.get(&id.local_id).cloned()
|
2016-10-27 04:52:10 +03:00
|
|
|
}
|
|
|
|
|
2019-02-09 22:11:53 +08:00
|
|
|
pub fn node_substs_mut(&mut self) -> LocalTableInContextMut<'_, SubstsRef<'tcx>> {
|
2017-08-10 16:10:04 +02:00
|
|
|
LocalTableInContextMut {
|
|
|
|
local_id_root: self.local_id_root,
|
|
|
|
data: &mut self.node_substs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-09 22:11:53 +08:00
|
|
|
pub fn node_substs(&self, id: hir::HirId) -> SubstsRef<'tcx> {
|
2017-08-11 11:56:26 +02:00
|
|
|
validate_hir_id_for_typeck_tables(self.local_id_root, id, false);
|
2019-02-26 09:30:34 +08:00
|
|
|
self.node_substs.get(&id.local_id).cloned().unwrap_or_else(|| InternalSubsts::empty())
|
2016-10-27 04:52:10 +03:00
|
|
|
}
|
|
|
|
|
2019-02-09 22:11:53 +08:00
|
|
|
pub fn node_substs_opt(&self, id: hir::HirId) -> Option<SubstsRef<'tcx>> {
|
2017-08-11 11:56:26 +02:00
|
|
|
validate_hir_id_for_typeck_tables(self.local_id_root, id, false);
|
2017-08-10 16:10:04 +02:00
|
|
|
self.node_substs.get(&id.local_id).cloned()
|
2016-10-27 04:52:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the type of a pattern as a monotype. Like @expr_ty, this function
|
|
|
|
// doesn't provide type parameter substitutions.
|
|
|
|
pub fn pat_ty(&self, pat: &hir::Pat) -> Ty<'tcx> {
|
2019-02-04 09:38:11 +01:00
|
|
|
self.node_type(pat.hir_id)
|
2016-10-27 04:52:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn pat_ty_opt(&self, pat: &hir::Pat) -> Option<Ty<'tcx>> {
|
2019-02-04 09:38:11 +01:00
|
|
|
self.node_type_opt(pat.hir_id)
|
2016-10-27 04:52:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the type of an expression as a monotype.
|
|
|
|
//
|
|
|
|
// NB (1): This is the PRE-ADJUSTMENT TYPE for the expression. That is, in
|
2016-10-20 06:33:20 +03:00
|
|
|
// some cases, we insert `Adjustment` annotations such as auto-deref or
|
2016-10-27 04:52:10 +03:00
|
|
|
// auto-ref. The type returned by this function does not consider such
|
|
|
|
// adjustments. See `expr_ty_adjusted()` instead.
|
|
|
|
//
|
2018-11-27 02:59:49 +00:00
|
|
|
// NB (2): This type doesn't provide type parameter substitutions; e.g., if you
|
2016-10-27 04:52:10 +03:00
|
|
|
// ask for the type of "id" in "id(3)", it will return "fn(&isize) -> isize"
|
|
|
|
// instead of "fn(ty) -> T with T = isize".
|
|
|
|
pub fn expr_ty(&self, expr: &hir::Expr) -> Ty<'tcx> {
|
2019-02-04 09:38:11 +01:00
|
|
|
self.node_type(expr.hir_id)
|
2016-10-27 04:52:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn expr_ty_opt(&self, expr: &hir::Expr) -> Option<Ty<'tcx>> {
|
2019-02-04 09:38:11 +01:00
|
|
|
self.node_type_opt(expr.hir_id)
|
2016-10-27 04:52:10 +03:00
|
|
|
}
|
|
|
|
|
2018-08-29 22:02:42 -07:00
|
|
|
pub fn adjustments(&self) -> LocalTableInContext<'_, Vec<ty::adjustment::Adjustment<'tcx>>> {
|
2017-08-10 16:10:04 +02:00
|
|
|
LocalTableInContext {
|
|
|
|
local_id_root: self.local_id_root,
|
|
|
|
data: &self.adjustments
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn adjustments_mut(&mut self)
|
2018-08-29 22:02:42 -07:00
|
|
|
-> LocalTableInContextMut<'_, Vec<ty::adjustment::Adjustment<'tcx>>> {
|
2017-08-10 16:10:04 +02:00
|
|
|
LocalTableInContextMut {
|
|
|
|
local_id_root: self.local_id_root,
|
|
|
|
data: &mut self.adjustments
|
|
|
|
}
|
2016-10-27 04:52:10 +03:00
|
|
|
}
|
|
|
|
|
2017-05-27 10:29:24 +03:00
|
|
|
pub fn expr_adjustments(&self, expr: &hir::Expr)
|
|
|
|
-> &[ty::adjustment::Adjustment<'tcx>] {
|
2017-08-11 11:56:26 +02:00
|
|
|
validate_hir_id_for_typeck_tables(self.local_id_root, expr.hir_id, false);
|
2017-08-07 14:43:43 +02:00
|
|
|
self.adjustments.get(&expr.hir_id.local_id).map_or(&[], |a| &a[..])
|
2017-05-27 10:29:24 +03:00
|
|
|
}
|
|
|
|
|
2016-10-20 06:33:20 +03:00
|
|
|
/// Returns the type of `expr`, considering any `Adjustment`
|
|
|
|
/// entry recorded for that expression.
|
|
|
|
pub fn expr_ty_adjusted(&self, expr: &hir::Expr) -> Ty<'tcx> {
|
2017-05-27 10:29:24 +03:00
|
|
|
self.expr_adjustments(expr)
|
|
|
|
.last()
|
2016-10-20 06:33:20 +03:00
|
|
|
.map_or_else(|| self.expr_ty(expr), |adj| adj.target)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn expr_ty_adjusted_opt(&self, expr: &hir::Expr) -> Option<Ty<'tcx>> {
|
2017-05-27 10:29:24 +03:00
|
|
|
self.expr_adjustments(expr)
|
|
|
|
.last()
|
|
|
|
.map(|adj| adj.target)
|
|
|
|
.or_else(|| self.expr_ty_opt(expr))
|
2016-10-20 06:33:20 +03:00
|
|
|
}
|
2016-10-27 04:52:10 +03:00
|
|
|
|
2017-05-20 16:11:07 +03:00
|
|
|
pub fn is_method_call(&self, expr: &hir::Expr) -> bool {
|
|
|
|
// Only paths and method calls/overloaded operators have
|
|
|
|
// entries in type_dependent_defs, ignore the former here.
|
2018-07-11 20:05:29 +08:00
|
|
|
if let hir::ExprKind::Path(_) = expr.node {
|
2017-05-20 16:11:07 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-10-27 04:52:10 +03:00
|
|
|
|
2017-08-10 16:10:04 +02:00
|
|
|
match self.type_dependent_defs().get(expr.hir_id) {
|
2019-04-20 19:46:19 +03:00
|
|
|
Some(Ok((DefKind::Method, _))) => true,
|
2017-05-20 16:11:07 +03:00
|
|
|
_ => false
|
|
|
|
}
|
2016-10-27 04:52:10 +03:00
|
|
|
}
|
|
|
|
|
2018-08-29 22:02:42 -07:00
|
|
|
pub fn pat_binding_modes(&self) -> LocalTableInContext<'_, BindingMode> {
|
2017-08-10 16:10:04 +02:00
|
|
|
LocalTableInContext {
|
|
|
|
local_id_root: self.local_id_root,
|
|
|
|
data: &self.pat_binding_modes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn pat_binding_modes_mut(&mut self)
|
2018-08-29 22:02:42 -07:00
|
|
|
-> LocalTableInContextMut<'_, BindingMode> {
|
2017-08-10 16:10:04 +02:00
|
|
|
LocalTableInContextMut {
|
|
|
|
local_id_root: self.local_id_root,
|
|
|
|
data: &mut self.pat_binding_modes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-29 22:02:42 -07:00
|
|
|
pub fn pat_adjustments(&self) -> LocalTableInContext<'_, Vec<Ty<'tcx>>> {
|
2017-10-06 16:30:23 -04:00
|
|
|
LocalTableInContext {
|
|
|
|
local_id_root: self.local_id_root,
|
|
|
|
data: &self.pat_adjustments,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn pat_adjustments_mut(&mut self)
|
2018-10-01 15:26:53 +02:00
|
|
|
-> LocalTableInContextMut<'_, Vec<Ty<'tcx>>> {
|
2017-10-06 16:30:23 -04:00
|
|
|
LocalTableInContextMut {
|
|
|
|
local_id_root: self.local_id_root,
|
|
|
|
data: &mut self.pat_adjustments,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-08 13:38:30 +03:00
|
|
|
pub fn upvar_capture(&self, upvar_id: ty::UpvarId) -> ty::UpvarCapture<'tcx> {
|
|
|
|
self.upvar_capture_map[&upvar_id]
|
2016-10-27 04:52:10 +03:00
|
|
|
}
|
2017-08-04 09:49:40 +02:00
|
|
|
|
2018-08-29 22:02:42 -07:00
|
|
|
pub fn closure_kind_origins(&self) -> LocalTableInContext<'_, (Span, ast::Name)> {
|
2017-08-10 16:10:04 +02:00
|
|
|
LocalTableInContext {
|
|
|
|
local_id_root: self.local_id_root,
|
2017-11-08 12:36:28 -05:00
|
|
|
data: &self.closure_kind_origins
|
2017-08-10 16:10:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-29 22:02:42 -07:00
|
|
|
pub fn closure_kind_origins_mut(&mut self) -> LocalTableInContextMut<'_, (Span, ast::Name)> {
|
2017-08-10 16:10:04 +02:00
|
|
|
LocalTableInContextMut {
|
|
|
|
local_id_root: self.local_id_root,
|
2017-11-08 12:36:28 -05:00
|
|
|
data: &mut self.closure_kind_origins
|
2017-08-10 16:10:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-29 22:02:42 -07:00
|
|
|
pub fn liberated_fn_sigs(&self) -> LocalTableInContext<'_, ty::FnSig<'tcx>> {
|
2017-08-10 16:10:04 +02:00
|
|
|
LocalTableInContext {
|
|
|
|
local_id_root: self.local_id_root,
|
|
|
|
data: &self.liberated_fn_sigs
|
2017-08-04 09:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
2017-08-10 16:10:04 +02:00
|
|
|
|
2018-08-29 22:02:42 -07:00
|
|
|
pub fn liberated_fn_sigs_mut(&mut self) -> LocalTableInContextMut<'_, ty::FnSig<'tcx>> {
|
2017-08-10 16:10:04 +02:00
|
|
|
LocalTableInContextMut {
|
|
|
|
local_id_root: self.local_id_root,
|
|
|
|
data: &mut self.liberated_fn_sigs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-29 22:02:42 -07:00
|
|
|
pub fn fru_field_types(&self) -> LocalTableInContext<'_, Vec<Ty<'tcx>>> {
|
2017-08-10 16:10:04 +02:00
|
|
|
LocalTableInContext {
|
|
|
|
local_id_root: self.local_id_root,
|
|
|
|
data: &self.fru_field_types
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-29 22:02:42 -07:00
|
|
|
pub fn fru_field_types_mut(&mut self) -> LocalTableInContextMut<'_, Vec<Ty<'tcx>>> {
|
2017-08-10 16:10:04 +02:00
|
|
|
LocalTableInContextMut {
|
|
|
|
local_id_root: self.local_id_root,
|
|
|
|
data: &mut self.fru_field_types
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-23 16:11:34 +05:30
|
|
|
pub fn is_coercion_cast(&self, hir_id: hir::HirId) -> bool {
|
|
|
|
validate_hir_id_for_typeck_tables(self.local_id_root, hir_id, true);
|
|
|
|
self.coercion_casts.contains(&hir_id.local_id)
|
2017-08-10 16:10:04 +02:00
|
|
|
}
|
|
|
|
|
2019-02-23 16:11:34 +05:30
|
|
|
pub fn set_coercion_cast(&mut self, id: ItemLocalId) {
|
|
|
|
self.coercion_casts.insert(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn coercion_casts(&self) -> &ItemLocalSet {
|
|
|
|
&self.coercion_casts
|
2017-08-10 16:10:04 +02:00
|
|
|
}
|
2019-02-23 16:11:34 +05:30
|
|
|
|
2017-08-10 16:10:04 +02:00
|
|
|
}
|
|
|
|
|
2018-01-16 10:16:38 +01:00
|
|
|
impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TypeckTables<'gcx> {
|
2017-08-10 16:10:04 +02:00
|
|
|
fn hash_stable<W: StableHasherResult>(&self,
|
2018-01-16 10:16:38 +01:00
|
|
|
hcx: &mut StableHashingContext<'a>,
|
2017-08-10 16:10:04 +02:00
|
|
|
hasher: &mut StableHasher<W>) {
|
|
|
|
let ty::TypeckTables {
|
|
|
|
local_id_root,
|
|
|
|
ref type_dependent_defs,
|
2018-04-05 03:20:21 +03:00
|
|
|
ref field_indices,
|
2018-11-16 22:56:18 +01:00
|
|
|
ref user_provided_types,
|
2018-10-19 06:25:12 -04:00
|
|
|
ref user_provided_sigs,
|
2017-08-10 16:10:04 +02:00
|
|
|
ref node_types,
|
|
|
|
ref node_substs,
|
|
|
|
ref adjustments,
|
|
|
|
ref pat_binding_modes,
|
2017-10-06 16:30:23 -04:00
|
|
|
ref pat_adjustments,
|
2017-08-10 16:10:04 +02:00
|
|
|
ref upvar_capture_map,
|
2017-11-08 12:36:28 -05:00
|
|
|
ref closure_kind_origins,
|
2017-08-10 16:10:04 +02:00
|
|
|
ref liberated_fn_sigs,
|
|
|
|
ref fru_field_types,
|
|
|
|
|
2019-02-23 16:11:34 +05:30
|
|
|
ref coercion_casts,
|
2017-08-10 16:10:04 +02:00
|
|
|
|
|
|
|
ref used_trait_imports,
|
|
|
|
tainted_by_errors,
|
|
|
|
ref free_region_map,
|
2018-05-22 14:31:56 +02:00
|
|
|
ref concrete_existential_types,
|
2018-12-16 17:01:57 -08:00
|
|
|
ref upvar_list,
|
|
|
|
|
2017-08-10 16:10:04 +02:00
|
|
|
} = *self;
|
|
|
|
|
|
|
|
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
|
2017-09-13 18:20:27 +02:00
|
|
|
type_dependent_defs.hash_stable(hcx, hasher);
|
2018-04-05 03:20:21 +03:00
|
|
|
field_indices.hash_stable(hcx, hasher);
|
2018-11-16 22:56:18 +01:00
|
|
|
user_provided_types.hash_stable(hcx, hasher);
|
2018-10-19 06:25:12 -04:00
|
|
|
user_provided_sigs.hash_stable(hcx, hasher);
|
2017-09-13 18:20:27 +02:00
|
|
|
node_types.hash_stable(hcx, hasher);
|
|
|
|
node_substs.hash_stable(hcx, hasher);
|
|
|
|
adjustments.hash_stable(hcx, hasher);
|
|
|
|
pat_binding_modes.hash_stable(hcx, hasher);
|
2017-10-06 16:30:23 -04:00
|
|
|
pat_adjustments.hash_stable(hcx, hasher);
|
2017-09-13 18:20:27 +02:00
|
|
|
hash_stable_hashmap(hcx, hasher, upvar_capture_map, |up_var_id, hcx| {
|
2017-08-10 16:10:04 +02:00
|
|
|
let ty::UpvarId {
|
2018-11-14 21:14:46 -08:00
|
|
|
var_path,
|
2017-08-10 16:10:04 +02:00
|
|
|
closure_expr_id
|
|
|
|
} = *up_var_id;
|
|
|
|
|
2017-08-11 11:56:26 +02:00
|
|
|
let local_id_root =
|
|
|
|
local_id_root.expect("trying to hash invalid TypeckTables");
|
|
|
|
|
2017-04-29 14:39:47 +03:00
|
|
|
let var_owner_def_id = DefId {
|
2017-08-10 16:10:04 +02:00
|
|
|
krate: local_id_root.krate,
|
2018-11-14 21:14:46 -08:00
|
|
|
index: var_path.hir_id.owner,
|
2017-08-10 16:10:04 +02:00
|
|
|
};
|
|
|
|
let closure_def_id = DefId {
|
|
|
|
krate: local_id_root.krate,
|
2017-11-16 14:04:01 +01:00
|
|
|
index: closure_expr_id.to_def_id().index,
|
2017-08-10 16:10:04 +02:00
|
|
|
};
|
2017-09-14 14:01:40 +02:00
|
|
|
(hcx.def_path_hash(var_owner_def_id),
|
2018-11-14 21:14:46 -08:00
|
|
|
var_path.hir_id.local_id,
|
2017-09-14 14:01:40 +02:00
|
|
|
hcx.def_path_hash(closure_def_id))
|
2017-08-10 16:10:04 +02:00
|
|
|
});
|
|
|
|
|
2017-11-08 12:36:28 -05:00
|
|
|
closure_kind_origins.hash_stable(hcx, hasher);
|
2017-09-13 18:20:27 +02:00
|
|
|
liberated_fn_sigs.hash_stable(hcx, hasher);
|
|
|
|
fru_field_types.hash_stable(hcx, hasher);
|
2019-02-23 16:11:34 +05:30
|
|
|
coercion_casts.hash_stable(hcx, hasher);
|
2017-09-13 18:20:27 +02:00
|
|
|
used_trait_imports.hash_stable(hcx, hasher);
|
2017-08-10 16:10:04 +02:00
|
|
|
tainted_by_errors.hash_stable(hcx, hasher);
|
|
|
|
free_region_map.hash_stable(hcx, hasher);
|
2018-05-22 14:31:56 +02:00
|
|
|
concrete_existential_types.hash_stable(hcx, hasher);
|
2018-12-16 17:01:57 -08:00
|
|
|
upvar_list.hash_stable(hcx, hasher);
|
2017-08-10 16:10:04 +02:00
|
|
|
})
|
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-16 22:56:18 +01:00
|
|
|
newtype_index! {
|
|
|
|
pub struct UserTypeAnnotationIndex {
|
2018-12-03 01:14:35 +01:00
|
|
|
derive [HashStable]
|
2019-01-06 16:01:45 +00:00
|
|
|
DEBUG_FORMAT = "UserType({})",
|
2018-11-16 22:56:18 +01:00
|
|
|
const START_INDEX = 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Mapping of type annotation indices to canonical user type annotations.
|
|
|
|
pub type CanonicalUserTypeAnnotations<'tcx> =
|
2019-01-06 17:10:53 +00:00
|
|
|
IndexVec<UserTypeAnnotationIndex, CanonicalUserTypeAnnotation<'tcx>>;
|
|
|
|
|
2018-12-03 01:14:35 +01:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)]
|
2019-01-06 17:10:53 +00:00
|
|
|
pub struct CanonicalUserTypeAnnotation<'tcx> {
|
|
|
|
pub user_ty: CanonicalUserType<'tcx>,
|
|
|
|
pub span: Span,
|
2019-01-12 14:55:23 +00:00
|
|
|
pub inferred_ty: Ty<'tcx>,
|
2019-01-06 17:10:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for CanonicalUserTypeAnnotation<'tcx> {
|
2019-01-12 14:55:23 +00:00
|
|
|
user_ty, span, inferred_ty
|
2019-01-06 17:10:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BraceStructLiftImpl! {
|
|
|
|
impl<'a, 'tcx> Lift<'tcx> for CanonicalUserTypeAnnotation<'a> {
|
|
|
|
type Lifted = CanonicalUserTypeAnnotation<'tcx>;
|
2019-01-12 14:55:23 +00:00
|
|
|
user_ty, span, inferred_ty
|
2019-01-06 17:10:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-16 22:56:18 +01:00
|
|
|
|
|
|
|
/// Canonicalized user type annotation.
|
2019-01-06 16:04:00 +00:00
|
|
|
pub type CanonicalUserType<'gcx> = Canonical<'gcx, UserType<'gcx>>;
|
2018-11-16 22:56:18 +01:00
|
|
|
|
2019-01-06 16:04:00 +00:00
|
|
|
impl CanonicalUserType<'gcx> {
|
2018-11-16 22:56:18 +01:00
|
|
|
/// Returns `true` if this represents a substitution of the form `[?0, ?1, ?2]`,
|
2019-02-08 14:53:55 +01:00
|
|
|
/// i.e., each thing is mapped to a canonical variable with the same index.
|
2018-11-16 22:56:18 +01:00
|
|
|
pub fn is_identity(&self) -> bool {
|
|
|
|
match self.value {
|
2019-01-06 16:01:45 +00:00
|
|
|
UserType::Ty(_) => false,
|
|
|
|
UserType::TypeOf(_, user_substs) => {
|
2018-11-16 22:56:18 +01:00
|
|
|
if user_substs.user_self_ty.is_some() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
user_substs.substs.iter().zip(BoundVar::new(0)..).all(|(kind, cvar)| {
|
|
|
|
match kind.unpack() {
|
|
|
|
UnpackedKind::Type(ty) => match ty.sty {
|
|
|
|
ty::Bound(debruijn, b) => {
|
|
|
|
// We only allow a `ty::INNERMOST` index in substitutions.
|
|
|
|
assert_eq!(debruijn, ty::INNERMOST);
|
|
|
|
cvar == b.var
|
|
|
|
}
|
|
|
|
_ => false,
|
|
|
|
},
|
|
|
|
|
|
|
|
UnpackedKind::Lifetime(r) => match r {
|
|
|
|
ty::ReLateBound(debruijn, br) => {
|
|
|
|
// We only allow a `ty::INNERMOST` index in substitutions.
|
|
|
|
assert_eq!(*debruijn, ty::INNERMOST);
|
|
|
|
cvar == br.assert_bound_var()
|
|
|
|
}
|
|
|
|
_ => false,
|
|
|
|
},
|
2019-02-20 01:14:56 +00:00
|
|
|
|
2019-03-14 10:19:31 +01:00
|
|
|
UnpackedKind::Const(ct) => match ct.val {
|
|
|
|
ConstValue::Infer(InferConst::Canonical(debruijn, b)) => {
|
2019-02-20 01:14:56 +00:00
|
|
|
// We only allow a `ty::INNERMOST` index in substitutions.
|
2019-03-14 10:19:31 +01:00
|
|
|
assert_eq!(debruijn, ty::INNERMOST);
|
|
|
|
cvar == b
|
2019-02-20 01:14:56 +00:00
|
|
|
}
|
|
|
|
_ => false,
|
|
|
|
},
|
2018-11-16 22:56:18 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// A user-given type annotation attached to a constant. These arise
|
2018-11-16 22:56:18 +01:00
|
|
|
/// from constants that are named via paths, like `Foo::<A>::new` and
|
|
|
|
/// so forth.
|
2018-12-03 01:14:35 +01:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)]
|
2019-01-06 16:01:45 +00:00
|
|
|
pub enum UserType<'tcx> {
|
2018-11-16 22:56:18 +01:00
|
|
|
Ty(Ty<'tcx>),
|
|
|
|
|
|
|
|
/// The canonical type is the result of `type_of(def_id)` with the
|
|
|
|
/// given substitutions applied.
|
|
|
|
TypeOf(DefId, UserSubsts<'tcx>),
|
|
|
|
}
|
|
|
|
|
|
|
|
EnumTypeFoldableImpl! {
|
2019-01-06 16:01:45 +00:00
|
|
|
impl<'tcx> TypeFoldable<'tcx> for UserType<'tcx> {
|
|
|
|
(UserType::Ty)(ty),
|
|
|
|
(UserType::TypeOf)(def, substs),
|
2018-11-16 22:56:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EnumLiftImpl! {
|
2019-01-06 16:01:45 +00:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for UserType<'a> {
|
|
|
|
type Lifted = UserType<'tcx>;
|
|
|
|
(UserType::Ty)(ty),
|
|
|
|
(UserType::TypeOf)(def, substs),
|
2018-11-16 22:56:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
impl<'tcx> CommonTypes<'tcx> {
|
2016-04-28 03:13:17 +03:00
|
|
|
fn new(interners: &CtxtInterners<'tcx>) -> CommonTypes<'tcx> {
|
2018-04-30 08:59:23 +02:00
|
|
|
let mk = |sty| CtxtInterners::intern_ty(interners, interners, sty);
|
2018-11-29 21:13:04 +01:00
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
CommonTypes {
|
2018-11-29 21:13:04 +01:00
|
|
|
unit: mk(Tuple(List::empty())),
|
2018-08-22 01:35:55 +01:00
|
|
|
bool: mk(Bool),
|
|
|
|
char: mk(Char),
|
2018-08-22 01:35:02 +01:00
|
|
|
never: mk(Never),
|
2019-05-01 23:09:53 +01:00
|
|
|
err: mk(Error),
|
2018-08-22 01:35:55 +01:00
|
|
|
isize: mk(Int(ast::IntTy::Isize)),
|
|
|
|
i8: mk(Int(ast::IntTy::I8)),
|
|
|
|
i16: mk(Int(ast::IntTy::I16)),
|
|
|
|
i32: mk(Int(ast::IntTy::I32)),
|
|
|
|
i64: mk(Int(ast::IntTy::I64)),
|
|
|
|
i128: mk(Int(ast::IntTy::I128)),
|
|
|
|
usize: mk(Uint(ast::UintTy::Usize)),
|
|
|
|
u8: mk(Uint(ast::UintTy::U8)),
|
|
|
|
u16: mk(Uint(ast::UintTy::U16)),
|
|
|
|
u32: mk(Uint(ast::UintTy::U32)),
|
|
|
|
u64: mk(Uint(ast::UintTy::U64)),
|
|
|
|
u128: mk(Uint(ast::UintTy::U128)),
|
|
|
|
f32: mk(Float(ast::FloatTy::F32)),
|
|
|
|
f64: mk(Float(ast::FloatTy::F64)),
|
2017-04-20 01:58:12 +03:00
|
|
|
|
2019-04-03 11:46:40 +02:00
|
|
|
trait_object_dummy_self: mk(Infer(ty::FreshTy(0))),
|
2019-04-25 22:04:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-03 11:46:40 +02:00
|
|
|
|
2019-04-25 22:04:51 +01:00
|
|
|
impl<'tcx> CommonLifetimes<'tcx> {
|
|
|
|
fn new(interners: &CtxtInterners<'tcx>) -> CommonLifetimes<'tcx> {
|
|
|
|
let mk = |r| {
|
|
|
|
interners.region.borrow_mut().intern(r, |r| {
|
|
|
|
Interned(interners.arena.alloc(r))
|
|
|
|
}).0
|
|
|
|
};
|
|
|
|
|
|
|
|
CommonLifetimes {
|
|
|
|
re_empty: mk(RegionKind::ReEmpty),
|
|
|
|
re_static: mk(RegionKind::ReStatic),
|
|
|
|
re_erased: mk(RegionKind::ReErased),
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-01 23:09:53 +01:00
|
|
|
impl<'tcx> CommonConsts<'tcx> {
|
|
|
|
fn new(interners: &CtxtInterners<'tcx>, types: &CommonTypes<'tcx>) -> CommonConsts<'tcx> {
|
|
|
|
let mk_const = |c| {
|
|
|
|
interners.const_.borrow_mut().intern(c, |c| {
|
|
|
|
Interned(interners.arena.alloc(c))
|
|
|
|
}).0
|
|
|
|
};
|
|
|
|
|
|
|
|
CommonConsts {
|
2019-04-03 15:29:31 +02:00
|
|
|
err: mk_const(ty::Const {
|
2019-05-25 10:59:09 +02:00
|
|
|
val: ConstValue::Scalar(Scalar::zst()),
|
2019-04-03 15:29:31 +02:00
|
|
|
ty: types.err,
|
|
|
|
}),
|
2019-05-01 23:09:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-02 00:42:51 +02:00
|
|
|
// This struct contains information regarding the `ReFree(FreeRegion)` corresponding to a lifetime
|
|
|
|
// conflict.
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct FreeRegionInfo {
|
|
|
|
// def id corresponding to FreeRegion
|
|
|
|
pub def_id: DefId,
|
|
|
|
// the bound region corresponding to FreeRegion
|
|
|
|
pub boundregion: ty::BoundRegion,
|
|
|
|
// checks if bound region is in Impl Item
|
|
|
|
pub is_impl_item: bool,
|
|
|
|
}
|
|
|
|
|
2017-09-15 16:19:44 -04:00
|
|
|
/// The central data structure of the compiler. It stores references
|
|
|
|
/// to the various **arenas** and also houses the results of the
|
2017-12-31 17:08:04 +01:00
|
|
|
/// various **compiler queries** that have been performed. See the
|
2018-02-25 15:24:14 -06:00
|
|
|
/// [rustc guide] for more details.
|
2017-12-31 17:08:04 +01:00
|
|
|
///
|
2018-11-26 15:03:13 -06:00
|
|
|
/// [rustc guide]: https://rust-lang.github.io/rustc-guide/ty.html
|
2016-05-03 04:56:42 +03:00
|
|
|
#[derive(Copy, Clone)]
|
2018-07-09 19:22:09 -03:00
|
|
|
pub struct TyCtxt<'a, 'gcx: 'tcx, 'tcx: 'a> {
|
2018-12-07 06:59:27 +01:00
|
|
|
gcx: &'gcx GlobalCtxt<'gcx>,
|
|
|
|
interners: &'tcx CtxtInterners<'tcx>,
|
|
|
|
dummy: PhantomData<&'a ()>,
|
2016-05-03 04:56:42 +03:00
|
|
|
}
|
|
|
|
|
2018-12-07 06:59:27 +01:00
|
|
|
impl<'gcx> Deref for TyCtxt<'_, 'gcx, '_> {
|
|
|
|
type Target = &'gcx GlobalCtxt<'gcx>;
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline(always)]
|
2016-05-03 05:23:22 +03:00
|
|
|
fn deref(&self) -> &Self::Target {
|
2016-05-03 04:56:42 +03:00
|
|
|
&self.gcx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct GlobalCtxt<'tcx> {
|
2019-03-29 17:49:11 +01:00
|
|
|
pub arena: WorkerLocal<Arena<'tcx>>,
|
2018-01-22 14:31:23 +01:00
|
|
|
global_arenas: &'tcx WorkerLocal<GlobalArenas<'tcx>>,
|
2016-04-28 03:13:17 +03:00
|
|
|
global_interners: CtxtInterners<'tcx>,
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2018-03-03 06:19:15 +01:00
|
|
|
cstore: &'tcx CrateStoreDyn,
|
2017-09-05 16:48:24 +02:00
|
|
|
|
2016-09-29 02:30:53 +03:00
|
|
|
pub sess: &'tcx Session,
|
|
|
|
|
2016-01-05 13:07:45 -05:00
|
|
|
pub dep_graph: DepGraph,
|
|
|
|
|
2018-12-01 18:13:27 +01:00
|
|
|
/// Common objects.
|
|
|
|
pub common: Common<'tcx>,
|
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
/// Common types, pre-interned for your convenience.
|
|
|
|
pub types: CommonTypes<'tcx>,
|
|
|
|
|
2019-04-25 22:04:51 +01:00
|
|
|
/// Common lifetimes, pre-interned for your convenience.
|
|
|
|
pub lifetimes: CommonLifetimes<'tcx>,
|
|
|
|
|
2019-05-01 23:09:53 +01:00
|
|
|
/// Common consts, pre-interned for your convenience.
|
|
|
|
pub consts: CommonConsts<'tcx>,
|
|
|
|
|
2016-07-27 17:26:55 -04:00
|
|
|
/// Map indicating what traits are in scope for places where this
|
|
|
|
/// is relevant; generated by resolve.
|
2017-09-14 17:40:37 +02:00
|
|
|
trait_map: FxHashMap<DefIndex,
|
2018-12-01 16:17:59 +01:00
|
|
|
FxHashMap<ItemLocalId,
|
|
|
|
StableVec<TraitCandidate>>>,
|
2016-07-27 17:26:55 -04:00
|
|
|
|
2017-03-23 14:18:25 -04:00
|
|
|
/// Export map produced by name resolution.
|
2018-12-01 16:23:32 +01:00
|
|
|
export_map: FxHashMap<DefId, Vec<Export<hir::HirId>>>,
|
2017-03-23 14:18:25 -04:00
|
|
|
|
2018-12-04 13:45:36 +01:00
|
|
|
hir_map: hir_map::Map<'tcx>,
|
2017-04-27 13:04:57 -04:00
|
|
|
|
2017-05-31 14:53:39 +02:00
|
|
|
/// A map from DefPathHash -> DefId. Includes DefIds from the local crate
|
|
|
|
/// as well as all upstream crates. Only populated in incremental mode.
|
|
|
|
pub def_path_hash_to_def_id: Option<FxHashMap<DefPathHash, DefId>>,
|
|
|
|
|
2018-12-24 06:18:39 +01:00
|
|
|
pub queries: query::Queries<'tcx>,
|
2016-10-28 13:55:49 +03:00
|
|
|
|
2019-05-04 03:57:46 +03:00
|
|
|
// Records the captured variables referenced by every closure
|
2015-12-22 16:39:33 -05:00
|
|
|
// expression. Do not track deps for this, just recompute it from
|
|
|
|
// scratch every time.
|
2018-12-01 16:23:32 +01:00
|
|
|
upvars: FxHashMap<DefId, Vec<hir::Upvar>>,
|
2015-12-22 16:39:33 -05:00
|
|
|
|
2017-09-08 13:51:57 -07:00
|
|
|
maybe_unused_trait_imports: FxHashSet<DefId>,
|
|
|
|
maybe_unused_extern_crates: Vec<(DefId, Span)>,
|
2019-01-07 11:46:44 +01:00
|
|
|
/// A map of glob use to a set of names it actually imports. Currently only
|
|
|
|
/// used in save-analysis.
|
|
|
|
glob_map: FxHashMap<DefId, FxHashSet<ast::Name>>,
|
2018-10-22 22:54:18 +03:00
|
|
|
/// Extern prelude entries. The value is `true` if the entry was introduced
|
|
|
|
/// via `extern crate` item and not `--extern` option or compiler built-in.
|
|
|
|
pub extern_prelude: FxHashMap<ast::Name, bool>,
|
2017-06-24 17:48:27 +09:00
|
|
|
|
2015-12-22 16:39:33 -05:00
|
|
|
// Internal cache for metadata decoding. No need to track deps on this.
|
2018-02-15 10:52:26 +01:00
|
|
|
pub rcache: Lock<FxHashMap<ty::CReaderCacheKey, Ty<'tcx>>>,
|
2015-12-22 16:39:33 -05:00
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
/// Caches the results of trait selection. This cache is used
|
|
|
|
/// for things that do not have to do with the parameters in scope.
|
|
|
|
pub selection_cache: traits::SelectionCache<'tcx>,
|
|
|
|
|
2015-10-21 14:50:38 +03:00
|
|
|
/// Caches the results of trait evaluation. This cache is used
|
|
|
|
/// for things that do not have to do with the parameters in scope.
|
|
|
|
/// Merge this with `selection_cache`?
|
|
|
|
pub evaluation_cache: traits::EvaluationCache<'tcx>,
|
|
|
|
|
2016-02-14 12:30:38 -05:00
|
|
|
/// The definite name of the current crate after taking into account
|
|
|
|
/// attributes, commandline parameters, etc.
|
2016-11-16 10:52:37 +00:00
|
|
|
pub crate_name: Symbol,
|
2016-04-18 16:03:16 +03:00
|
|
|
|
|
|
|
/// Data layout specification for the current target.
|
|
|
|
pub data_layout: TargetDataLayout,
|
2016-04-19 09:11:46 +03:00
|
|
|
|
2018-05-17 05:19:08 +02:00
|
|
|
stability_interner: Lock<FxHashMap<&'tcx attr::Stability, ()>>,
|
2016-12-23 20:48:21 -07:00
|
|
|
|
2018-05-02 06:03:02 +02:00
|
|
|
/// Stores the value of constants (and deduplicates the actual memory)
|
2018-05-17 05:19:08 +02:00
|
|
|
allocation_interner: Lock<FxHashMap<&'tcx Allocation, ()>>,
|
2018-05-02 06:03:02 +02:00
|
|
|
|
2018-12-03 14:54:58 +01:00
|
|
|
pub alloc_map: Lock<interpret::AllocMap<'tcx>>,
|
2017-12-06 09:25:29 +01:00
|
|
|
|
2018-05-17 05:19:08 +02:00
|
|
|
layout_interner: Lock<FxHashMap<&'tcx LayoutDetails, ()>>,
|
2016-10-04 02:19:40 +03:00
|
|
|
|
2017-09-13 16:03:24 -07:00
|
|
|
/// A general purpose channel to throw data out the back towards LLVM worker
|
|
|
|
/// threads.
|
|
|
|
///
|
2018-05-08 16:10:16 +03:00
|
|
|
/// This is intended to only get used during the codegen phase of the compiler
|
2017-09-13 16:03:24 -07:00
|
|
|
/// when satisfying the query for a particular codegen unit. Internally in
|
|
|
|
/// the query it'll send data along this channel to get processed later.
|
2018-03-26 21:31:45 +02:00
|
|
|
pub tx_to_llvm_workers: Lock<mpsc::Sender<Box<dyn Any + Send>>>,
|
2017-09-13 20:26:39 -07:00
|
|
|
|
|
|
|
output_filenames: Arc<OutputFilenames>,
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-03-15 10:01:17 +01:00
|
|
|
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Gets the global `TyCtxt`.
|
2018-03-15 10:01:17 +01:00
|
|
|
#[inline]
|
2018-12-07 06:59:27 +01:00
|
|
|
pub fn global_tcx(self) -> TyCtxt<'gcx, 'gcx, 'gcx> {
|
2016-04-28 03:13:17 +03:00
|
|
|
TyCtxt {
|
2018-03-15 10:01:17 +01:00
|
|
|
gcx: self.gcx,
|
|
|
|
interners: &self.gcx.global_interners,
|
2018-12-07 06:59:27 +01:00
|
|
|
dummy: PhantomData,
|
2016-04-28 03:13:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-04 13:45:36 +01:00
|
|
|
#[inline(always)]
|
|
|
|
pub fn hir(self) -> &'a hir_map::Map<'gcx> {
|
|
|
|
&self.hir_map
|
|
|
|
}
|
|
|
|
|
2017-01-25 22:01:11 +02:00
|
|
|
pub fn alloc_generics(self, generics: ty::Generics) -> &'gcx ty::Generics {
|
2016-12-23 20:48:21 -07:00
|
|
|
self.global_arenas.generics.alloc(generics)
|
2016-08-08 23:39:49 +03:00
|
|
|
}
|
|
|
|
|
2019-05-17 23:55:04 +02:00
|
|
|
pub fn alloc_steal_mir(self, mir: Body<'gcx>) -> &'gcx Steal<Body<'gcx>> {
|
2017-04-28 06:00:48 -04:00
|
|
|
self.global_arenas.steal_mir.alloc(Steal::new(mir))
|
|
|
|
}
|
|
|
|
|
2019-05-17 23:55:04 +02:00
|
|
|
pub fn alloc_mir(self, mir: Body<'gcx>) -> &'gcx Body<'gcx> {
|
2017-04-28 06:00:48 -04:00
|
|
|
self.global_arenas.mir.alloc(mir)
|
2016-10-28 13:55:49 +03:00
|
|
|
}
|
|
|
|
|
2017-01-25 16:24:00 -05:00
|
|
|
pub fn alloc_tables(self, tables: ty::TypeckTables<'gcx>) -> &'gcx ty::TypeckTables<'gcx> {
|
2017-01-04 04:01:58 +02:00
|
|
|
self.global_arenas.tables.alloc(tables)
|
|
|
|
}
|
|
|
|
|
2016-11-25 02:29:26 +02:00
|
|
|
pub fn alloc_trait_def(self, def: ty::TraitDef) -> &'gcx ty::TraitDef {
|
2016-12-23 20:48:21 -07:00
|
|
|
self.global_arenas.trait_def.alloc(def)
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2016-11-25 01:33:29 +02:00
|
|
|
pub fn alloc_adt_def(self,
|
|
|
|
did: DefId,
|
|
|
|
kind: AdtKind,
|
2018-11-01 16:01:24 +01:00
|
|
|
variants: IndexVec<VariantIdx, ty::VariantDef>,
|
2017-02-06 15:26:32 -05:00
|
|
|
repr: ReprOptions)
|
2016-11-25 01:33:29 +02:00
|
|
|
-> &'gcx ty::AdtDef {
|
2017-02-05 07:01:48 +02:00
|
|
|
let def = ty::AdtDef::new(self, did, kind, variants, repr);
|
2016-12-23 20:48:21 -07:00
|
|
|
self.global_arenas.adt_def.alloc(def)
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2019-02-06 11:57:11 +11:00
|
|
|
pub fn intern_const_alloc(self, alloc: Allocation) -> &'gcx Allocation {
|
2018-05-17 05:19:08 +02:00
|
|
|
self.allocation_interner.borrow_mut().intern(alloc, |alloc| {
|
|
|
|
self.global_arenas.const_allocs.alloc(alloc)
|
|
|
|
})
|
2017-12-06 09:25:29 +01:00
|
|
|
}
|
|
|
|
|
2018-08-23 19:04:33 +02:00
|
|
|
/// Allocates a byte or string literal for `mir::interpret`, read-only
|
2018-05-01 12:18:53 +02:00
|
|
|
pub fn allocate_bytes(self, bytes: &[u8]) -> interpret::AllocId {
|
2017-12-06 09:25:29 +01:00
|
|
|
// create an allocation that just contains these bytes
|
2018-11-14 16:00:52 +01:00
|
|
|
let alloc = interpret::Allocation::from_byte_aligned_bytes(bytes, ());
|
2017-12-06 09:25:29 +01:00
|
|
|
let alloc = self.intern_const_alloc(alloc);
|
2018-05-02 06:03:06 +02:00
|
|
|
self.alloc_map.lock().allocate(alloc)
|
2017-12-06 09:25:29 +01:00
|
|
|
}
|
|
|
|
|
2016-05-11 04:14:41 +03:00
|
|
|
pub fn intern_stability(self, stab: attr::Stability) -> &'gcx attr::Stability {
|
2018-05-17 05:19:08 +02:00
|
|
|
self.stability_interner.borrow_mut().intern(stab, |stab| {
|
|
|
|
self.global_interners.arena.alloc(stab)
|
|
|
|
})
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2017-10-28 16:52:41 +03:00
|
|
|
pub fn intern_layout(self, layout: LayoutDetails) -> &'gcx LayoutDetails {
|
2018-05-17 05:19:08 +02:00
|
|
|
self.layout_interner.borrow_mut().intern(layout, |layout| {
|
|
|
|
self.global_arenas.layout.alloc(layout)
|
|
|
|
})
|
2016-04-19 09:11:46 +03:00
|
|
|
}
|
|
|
|
|
2018-09-10 13:40:34 +02:00
|
|
|
/// Returns a range of the start/end indices specified with the
|
|
|
|
/// `rustc_layout_scalar_valid_range` attribute.
|
|
|
|
pub fn layout_scalar_valid_range(self, def_id: DefId) -> (Bound<u128>, Bound<u128>) {
|
2018-09-07 13:41:59 +02:00
|
|
|
let attrs = self.get_attrs(def_id);
|
2018-09-10 13:40:34 +02:00
|
|
|
let get = |name| {
|
|
|
|
let attr = match attrs.iter().find(|a| a.check_name(name)) {
|
|
|
|
Some(attr) => attr,
|
|
|
|
None => return Bound::Unbounded,
|
|
|
|
};
|
|
|
|
for meta in attr.meta_item_list().expect("rustc_layout_scalar_valid_range takes args") {
|
|
|
|
match meta.literal().expect("attribute takes lit").node {
|
|
|
|
ast::LitKind::Int(a, _) => return Bound::Included(a),
|
|
|
|
_ => span_bug!(attr.span, "rustc_layout_scalar_valid_range expects int arg"),
|
2018-09-07 13:41:59 +02:00
|
|
|
}
|
|
|
|
}
|
2018-09-10 13:40:34 +02:00
|
|
|
span_bug!(attr.span, "no arguments to `rustc_layout_scalar_valid_range` attribute");
|
2018-09-07 13:41:59 +02:00
|
|
|
};
|
2019-05-08 13:21:18 +10:00
|
|
|
(get(sym::rustc_layout_scalar_valid_range_start),
|
|
|
|
get(sym::rustc_layout_scalar_valid_range_end))
|
2018-09-07 13:41:59 +02:00
|
|
|
}
|
|
|
|
|
2016-05-03 04:56:42 +03:00
|
|
|
pub fn lift<T: ?Sized + Lift<'tcx>>(self, value: &T) -> Option<T::Lifted> {
|
2015-09-06 21:51:58 +03:00
|
|
|
value.lift_to_tcx(self)
|
|
|
|
}
|
|
|
|
|
2016-04-29 06:00:23 +03:00
|
|
|
/// Like lift, but only tries in the global tcx.
|
|
|
|
pub fn lift_to_global<T: ?Sized + Lift<'gcx>>(self, value: &T) -> Option<T::Lifted> {
|
|
|
|
value.lift_to_tcx(self.global_tcx())
|
|
|
|
}
|
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Returns `true` if self is the same as self.global_tcx().
|
2016-04-29 06:00:23 +03:00
|
|
|
fn is_global(self) -> bool {
|
2019-02-23 14:25:03 +00:00
|
|
|
ptr_eq(self.interners, &self.global_interners)
|
2016-04-29 06:00:23 +03:00
|
|
|
}
|
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Creates a type context and call the closure with a `TyCtxt` reference
|
2015-09-06 21:51:58 +03:00
|
|
|
/// to the context. The closure enforces that the type context and any interned
|
|
|
|
/// value (types, substs, etc.) can only be used while `ty::tls` has a valid
|
|
|
|
/// reference to the context, to allow formatting values that need it.
|
2018-12-08 20:30:23 +01:00
|
|
|
pub fn create_global_ctxt(
|
|
|
|
s: &'tcx Session,
|
|
|
|
cstore: &'tcx CrateStoreDyn,
|
|
|
|
local_providers: ty::query::Providers<'tcx>,
|
|
|
|
extern_providers: ty::query::Providers<'tcx>,
|
|
|
|
arenas: &'tcx AllArenas<'tcx>,
|
|
|
|
resolutions: ty::Resolutions,
|
|
|
|
hir: hir_map::Map<'tcx>,
|
|
|
|
on_disk_query_result_cache: query::OnDiskCache<'tcx>,
|
|
|
|
crate_name: &str,
|
|
|
|
tx: mpsc::Sender<Box<dyn Any + Send>>,
|
|
|
|
output_filenames: &OutputFilenames,
|
|
|
|
) -> GlobalCtxt<'tcx> {
|
2018-04-26 16:07:26 +03:00
|
|
|
let data_layout = TargetDataLayout::parse(&s.target.target).unwrap_or_else(|err| {
|
2017-12-18 16:18:36 +02:00
|
|
|
s.fatal(&err);
|
|
|
|
});
|
2017-12-03 13:57:25 +01:00
|
|
|
let interners = CtxtInterners::new(&arenas.interner);
|
2018-12-01 18:13:27 +01:00
|
|
|
let common = Common {
|
|
|
|
empty_predicates: ty::GenericPredicates {
|
|
|
|
parent: None,
|
|
|
|
predicates: vec![],
|
|
|
|
},
|
|
|
|
};
|
2016-04-28 03:13:17 +03:00
|
|
|
let common_types = CommonTypes::new(&interners);
|
2019-04-25 22:04:51 +01:00
|
|
|
let common_lifetimes = CommonLifetimes::new(&interners);
|
2019-05-01 23:09:53 +01:00
|
|
|
let common_consts = CommonConsts::new(&interners, &common_types);
|
2017-01-26 02:41:06 +02:00
|
|
|
let dep_graph = hir.dep_graph.clone();
|
2017-09-05 16:48:24 +02:00
|
|
|
let max_cnum = cstore.crates_untracked().iter().map(|c| c.as_usize()).max().unwrap_or(0);
|
2016-09-29 02:30:53 +03:00
|
|
|
let mut providers = IndexVec::from_elem_n(extern_providers, max_cnum + 1);
|
|
|
|
providers[LOCAL_CRATE] = local_providers;
|
2017-05-31 14:53:39 +02:00
|
|
|
|
|
|
|
let def_path_hash_to_def_id = if s.opts.build_dep_graph() {
|
2018-02-27 17:11:14 +01:00
|
|
|
let upstream_def_path_tables: Vec<(CrateNum, Lrc<_>)> = cstore
|
2017-09-07 08:13:41 -07:00
|
|
|
.crates_untracked()
|
2017-05-31 14:53:39 +02:00
|
|
|
.iter()
|
2017-09-05 16:48:24 +02:00
|
|
|
.map(|&cnum| (cnum, cstore.def_path_table(cnum)))
|
2017-05-31 14:53:39 +02:00
|
|
|
.collect();
|
|
|
|
|
|
|
|
let def_path_tables = || {
|
|
|
|
upstream_def_path_tables
|
|
|
|
.iter()
|
|
|
|
.map(|&(cnum, ref rc)| (cnum, &**rc))
|
|
|
|
.chain(iter::once((LOCAL_CRATE, hir.definitions().def_path_table())))
|
|
|
|
};
|
|
|
|
|
|
|
|
// Precompute the capacity of the hashmap so we don't have to
|
|
|
|
// re-allocate when populating it.
|
|
|
|
let capacity = def_path_tables().map(|(_, t)| t.size()).sum::<usize>();
|
|
|
|
|
|
|
|
let mut map: FxHashMap<_, _> = FxHashMap::with_capacity_and_hasher(
|
|
|
|
capacity,
|
|
|
|
::std::default::Default::default()
|
|
|
|
);
|
|
|
|
|
|
|
|
for (cnum, def_path_table) in def_path_tables() {
|
|
|
|
def_path_table.add_def_path_hashes_to(cnum, &mut map);
|
|
|
|
}
|
|
|
|
|
|
|
|
Some(map)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2018-12-01 16:17:59 +01:00
|
|
|
let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default();
|
2017-09-08 13:51:57 -07:00
|
|
|
for (k, v) in resolutions.trait_map {
|
|
|
|
let hir_id = hir.node_to_hir_id(k);
|
2018-07-21 22:43:31 +03:00
|
|
|
let map = trait_map.entry(hir_id.owner).or_default();
|
2018-12-01 16:17:59 +01:00
|
|
|
map.insert(hir_id.local_id, StableVec::new(v));
|
2017-09-08 13:51:57 -07:00
|
|
|
}
|
|
|
|
|
2018-12-08 20:30:23 +01:00
|
|
|
GlobalCtxt {
|
2016-09-29 02:30:53 +03:00
|
|
|
sess: s,
|
2017-09-05 16:48:24 +02:00
|
|
|
cstore,
|
2019-03-29 17:49:11 +01:00
|
|
|
arena: WorkerLocal::new(|_| Arena::default()),
|
2017-12-03 13:57:25 +01:00
|
|
|
global_arenas: &arenas.global,
|
2016-04-28 03:13:17 +03:00
|
|
|
global_interners: interners,
|
2018-10-26 03:11:11 +09:00
|
|
|
dep_graph,
|
2018-12-01 18:13:27 +01:00
|
|
|
common,
|
2015-09-06 21:51:58 +03:00
|
|
|
types: common_types,
|
2019-04-25 22:04:51 +01:00
|
|
|
lifetimes: common_lifetimes,
|
2019-05-01 23:09:53 +01:00
|
|
|
consts: common_consts,
|
2017-09-08 13:51:57 -07:00
|
|
|
trait_map,
|
2017-08-29 11:10:22 -07:00
|
|
|
export_map: resolutions.export_map.into_iter().map(|(k, v)| {
|
2019-04-03 09:07:45 +02:00
|
|
|
let exports: Vec<_> = v.into_iter().map(|e| {
|
|
|
|
e.map_id(|id| hir.node_to_hir_id(id))
|
|
|
|
}).collect();
|
2018-12-01 16:23:32 +01:00
|
|
|
(k, exports)
|
2017-08-29 11:10:22 -07:00
|
|
|
}).collect(),
|
2019-05-04 03:57:46 +03:00
|
|
|
upvars: resolutions.upvars.into_iter().map(|(k, v)| {
|
2019-04-03 09:07:45 +02:00
|
|
|
let vars: Vec<_> = v.into_iter().map(|e| {
|
|
|
|
e.map_id(|id| hir.node_to_hir_id(id))
|
|
|
|
}).collect();
|
2018-12-01 16:23:32 +01:00
|
|
|
(hir.local_def_id(k), vars)
|
2017-08-31 12:30:25 -07:00
|
|
|
}).collect(),
|
2017-08-31 13:19:33 -07:00
|
|
|
maybe_unused_trait_imports:
|
|
|
|
resolutions.maybe_unused_trait_imports
|
|
|
|
.into_iter()
|
2017-09-08 13:51:57 -07:00
|
|
|
.map(|id| hir.local_def_id(id))
|
2017-08-31 13:19:33 -07:00
|
|
|
.collect(),
|
|
|
|
maybe_unused_extern_crates:
|
|
|
|
resolutions.maybe_unused_extern_crates
|
|
|
|
.into_iter()
|
2017-09-08 13:51:57 -07:00
|
|
|
.map(|(id, sp)| (hir.local_def_id(id), sp))
|
2017-08-31 13:19:33 -07:00
|
|
|
.collect(),
|
2019-01-07 11:46:44 +01:00
|
|
|
glob_map: resolutions.glob_map.into_iter().map(|(id, names)| {
|
|
|
|
(hir.local_def_id(id), names)
|
|
|
|
}).collect(),
|
2018-10-13 21:21:08 +03:00
|
|
|
extern_prelude: resolutions.extern_prelude,
|
2018-12-04 13:45:36 +01:00
|
|
|
hir_map: hir,
|
2017-07-03 11:19:51 -07:00
|
|
|
def_path_hash_to_def_id,
|
2018-09-12 10:31:00 +03:00
|
|
|
queries: query::Queries::new(
|
|
|
|
providers,
|
|
|
|
extern_providers,
|
|
|
|
on_disk_query_result_cache,
|
|
|
|
),
|
2018-10-16 16:57:53 +02:00
|
|
|
rcache: Default::default(),
|
|
|
|
selection_cache: Default::default(),
|
|
|
|
evaluation_cache: Default::default(),
|
2016-11-16 10:52:37 +00:00
|
|
|
crate_name: Symbol::intern(crate_name),
|
2017-07-03 11:19:51 -07:00
|
|
|
data_layout,
|
2018-10-16 16:57:53 +02:00
|
|
|
layout_interner: Default::default(),
|
|
|
|
stability_interner: Default::default(),
|
|
|
|
allocation_interner: Default::default(),
|
2018-05-02 06:03:06 +02:00
|
|
|
alloc_map: Lock::new(interpret::AllocMap::new()),
|
2018-03-26 21:31:45 +02:00
|
|
|
tx_to_llvm_workers: Lock::new(tx),
|
2017-09-13 20:26:39 -07:00
|
|
|
output_filenames: Arc::new(output_filenames.clone()),
|
2018-12-08 20:30:23 +01:00
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
2017-03-08 16:28:47 -05:00
|
|
|
|
|
|
|
pub fn consider_optimizing<T: Fn() -> String>(&self, msg: T) -> bool {
|
|
|
|
let cname = self.crate_name(LOCAL_CRATE).as_str();
|
|
|
|
self.sess.consider_optimizing(&cname, msg)
|
|
|
|
}
|
2017-08-31 08:57:41 -07:00
|
|
|
|
2018-12-01 16:57:29 +01:00
|
|
|
pub fn lib_features(self) -> &'gcx middle::lib_features::LibFeatures {
|
2018-07-23 01:20:33 +01:00
|
|
|
self.get_lib_features(LOCAL_CRATE)
|
|
|
|
}
|
|
|
|
|
2018-12-01 16:57:29 +01:00
|
|
|
pub fn lang_items(self) -> &'gcx middle::lang_items::LanguageItems {
|
2017-09-12 17:07:09 +02:00
|
|
|
self.get_lang_items(LOCAL_CRATE)
|
2017-08-31 08:57:41 -07:00
|
|
|
}
|
2017-08-31 15:08:34 -07:00
|
|
|
|
2018-01-26 16:24:54 +01:00
|
|
|
/// Due to missing llvm support for lowering 128 bit math to software emulation
|
|
|
|
/// (on some targets), the lowering can be done in MIR.
|
|
|
|
///
|
|
|
|
/// This function only exists until said support is implemented.
|
2018-01-16 09:24:38 +01:00
|
|
|
pub fn is_binop_lang_item(&self, def_id: DefId) -> Option<(mir::BinOp, bool)> {
|
|
|
|
let items = self.lang_items();
|
|
|
|
let def_id = Some(def_id);
|
|
|
|
if items.i128_add_fn() == def_id { Some((mir::BinOp::Add, false)) }
|
|
|
|
else if items.u128_add_fn() == def_id { Some((mir::BinOp::Add, false)) }
|
|
|
|
else if items.i128_sub_fn() == def_id { Some((mir::BinOp::Sub, false)) }
|
|
|
|
else if items.u128_sub_fn() == def_id { Some((mir::BinOp::Sub, false)) }
|
|
|
|
else if items.i128_mul_fn() == def_id { Some((mir::BinOp::Mul, false)) }
|
|
|
|
else if items.u128_mul_fn() == def_id { Some((mir::BinOp::Mul, false)) }
|
|
|
|
else if items.i128_div_fn() == def_id { Some((mir::BinOp::Div, false)) }
|
|
|
|
else if items.u128_div_fn() == def_id { Some((mir::BinOp::Div, false)) }
|
|
|
|
else if items.i128_rem_fn() == def_id { Some((mir::BinOp::Rem, false)) }
|
|
|
|
else if items.u128_rem_fn() == def_id { Some((mir::BinOp::Rem, false)) }
|
|
|
|
else if items.i128_shl_fn() == def_id { Some((mir::BinOp::Shl, false)) }
|
|
|
|
else if items.u128_shl_fn() == def_id { Some((mir::BinOp::Shl, false)) }
|
|
|
|
else if items.i128_shr_fn() == def_id { Some((mir::BinOp::Shr, false)) }
|
|
|
|
else if items.u128_shr_fn() == def_id { Some((mir::BinOp::Shr, false)) }
|
|
|
|
else if items.i128_addo_fn() == def_id { Some((mir::BinOp::Add, true)) }
|
|
|
|
else if items.u128_addo_fn() == def_id { Some((mir::BinOp::Add, true)) }
|
|
|
|
else if items.i128_subo_fn() == def_id { Some((mir::BinOp::Sub, true)) }
|
|
|
|
else if items.u128_subo_fn() == def_id { Some((mir::BinOp::Sub, true)) }
|
|
|
|
else if items.i128_mulo_fn() == def_id { Some((mir::BinOp::Mul, true)) }
|
|
|
|
else if items.u128_mulo_fn() == def_id { Some((mir::BinOp::Mul, true)) }
|
|
|
|
else if items.i128_shlo_fn() == def_id { Some((mir::BinOp::Shl, true)) }
|
|
|
|
else if items.u128_shlo_fn() == def_id { Some((mir::BinOp::Shl, true)) }
|
|
|
|
else if items.i128_shro_fn() == def_id { Some((mir::BinOp::Shr, true)) }
|
|
|
|
else if items.u128_shro_fn() == def_id { Some((mir::BinOp::Shr, true)) }
|
|
|
|
else { None }
|
|
|
|
}
|
|
|
|
|
2018-11-30 22:45:46 +01:00
|
|
|
pub fn stability(self) -> &'gcx stability::Index<'gcx> {
|
2017-11-27 10:50:15 +01:00
|
|
|
self.stability_index(LOCAL_CRATE)
|
2017-08-31 15:08:34 -07:00
|
|
|
}
|
2017-09-07 08:13:41 -07:00
|
|
|
|
2018-11-30 22:45:46 +01:00
|
|
|
pub fn crates(self) -> &'gcx [CrateNum] {
|
2017-09-07 08:13:41 -07:00
|
|
|
self.all_crate_nums(LOCAL_CRATE)
|
|
|
|
}
|
2017-09-07 13:21:46 -07:00
|
|
|
|
2018-11-30 22:45:46 +01:00
|
|
|
pub fn features(self) -> &'gcx feature_gate::Features {
|
2018-02-14 16:11:02 +01:00
|
|
|
self.features_query(LOCAL_CRATE)
|
|
|
|
}
|
|
|
|
|
2017-09-07 13:21:46 -07:00
|
|
|
pub fn def_key(self, id: DefId) -> hir_map::DefKey {
|
|
|
|
if id.is_local() {
|
2018-12-04 13:45:36 +01:00
|
|
|
self.hir().def_key(id)
|
2017-09-07 13:21:46 -07:00
|
|
|
} else {
|
|
|
|
self.cstore.def_key(id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Converts a `DefId` into its fully expanded `DefPath` (every
|
2017-09-07 13:21:46 -07:00
|
|
|
/// `DefId` is really just an interned def-path).
|
|
|
|
///
|
|
|
|
/// Note that if `id` is not local to this crate, the result will
|
|
|
|
/// be a non-local `DefPath`.
|
|
|
|
pub fn def_path(self, id: DefId) -> hir_map::DefPath {
|
|
|
|
if id.is_local() {
|
2018-12-04 13:45:36 +01:00
|
|
|
self.hir().def_path(id)
|
2017-09-07 13:21:46 -07:00
|
|
|
} else {
|
|
|
|
self.cstore.def_path(id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-20 23:27:08 -04:00
|
|
|
/// Returns whether or not the crate with CrateNum 'cnum'
|
|
|
|
/// is marked as a private dependency
|
|
|
|
pub fn is_private_dep(self, cnum: CrateNum) -> bool {
|
|
|
|
if cnum == LOCAL_CRATE {
|
|
|
|
false
|
|
|
|
} else {
|
|
|
|
self.cstore.crate_is_private_dep_untracked(cnum)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-07 13:21:46 -07:00
|
|
|
#[inline]
|
|
|
|
pub fn def_path_hash(self, def_id: DefId) -> hir_map::DefPathHash {
|
|
|
|
if def_id.is_local() {
|
2018-12-04 13:45:36 +01:00
|
|
|
self.hir().definitions().def_path_hash(def_id.index)
|
2017-09-07 13:21:46 -07:00
|
|
|
} else {
|
|
|
|
self.cstore.def_path_hash(def_id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-04 14:57:14 +02:00
|
|
|
pub fn def_path_debug_str(self, def_id: DefId) -> String {
|
|
|
|
// We are explicitly not going through queries here in order to get
|
|
|
|
// crate name and disambiguator since this code is called from debug!()
|
|
|
|
// statements within the query system and we'd run into endless
|
|
|
|
// recursion otherwise.
|
|
|
|
let (crate_name, crate_disambiguator) = if def_id.is_local() {
|
|
|
|
(self.crate_name.clone(),
|
|
|
|
self.sess.local_crate_disambiguator())
|
|
|
|
} else {
|
|
|
|
(self.cstore.crate_name_untracked(def_id.krate),
|
|
|
|
self.cstore.crate_disambiguator_untracked(def_id.krate))
|
|
|
|
};
|
|
|
|
|
|
|
|
format!("{}[{}]{}",
|
|
|
|
crate_name,
|
|
|
|
// Don't print the whole crate disambiguator. That's just
|
|
|
|
// annoying in debug output.
|
2017-10-24 17:49:58 +02:00
|
|
|
&(crate_disambiguator.to_fingerprint().to_hex())[..4],
|
2017-10-04 14:57:14 +02:00
|
|
|
self.def_path(def_id).to_string_no_crate())
|
|
|
|
}
|
|
|
|
|
2017-09-07 13:21:46 -07:00
|
|
|
pub fn metadata_encoding_version(self) -> Vec<u8> {
|
|
|
|
self.cstore.metadata_encoding_version().to_vec()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that this is *untracked* and should only be used within the query
|
|
|
|
// system if the result is otherwise tracked through queries
|
2018-02-23 09:53:00 -08:00
|
|
|
pub fn crate_data_as_rc_any(self, cnum: CrateNum) -> Lrc<dyn Any> {
|
2017-09-07 13:21:46 -07:00
|
|
|
self.cstore.crate_data_as_rc_any(cnum)
|
|
|
|
}
|
2017-09-14 15:10:24 +02:00
|
|
|
|
2018-12-04 16:26:34 +01:00
|
|
|
#[inline(always)]
|
2018-01-16 10:16:38 +01:00
|
|
|
pub fn create_stable_hashing_context(self) -> StableHashingContext<'a> {
|
2018-12-04 16:26:34 +01:00
|
|
|
let krate = self.gcx.hir_map.forest.untracked_krate();
|
2017-09-14 15:10:24 +02:00
|
|
|
|
|
|
|
StableHashingContext::new(self.sess,
|
|
|
|
krate,
|
2018-12-04 13:45:36 +01:00
|
|
|
self.hir().definitions(),
|
2017-09-14 15:10:24 +02:00
|
|
|
self.cstore)
|
|
|
|
}
|
2017-09-14 17:43:03 +02:00
|
|
|
|
2017-09-22 13:03:15 +02:00
|
|
|
// This method makes sure that we have a DepNode and a Fingerprint for
|
|
|
|
// every upstream crate. It needs to be called once right after the tcx is
|
|
|
|
// created.
|
|
|
|
// With full-fledged red/green, the method will probably become unnecessary
|
|
|
|
// as this will be done on-demand.
|
|
|
|
pub fn allocate_metadata_dep_nodes(self) {
|
|
|
|
// We cannot use the query versions of crates() and crate_hash(), since
|
|
|
|
// those would need the DepNodes that we are allocating here.
|
|
|
|
for cnum in self.cstore.crates_untracked() {
|
|
|
|
let dep_node = DepNode::new(self, DepConstructor::CrateMetadata(cnum));
|
|
|
|
let crate_hash = self.cstore.crate_hash_untracked(cnum);
|
|
|
|
self.dep_graph.with_task(dep_node,
|
|
|
|
self,
|
|
|
|
crate_hash,
|
2019-01-20 05:44:02 +01:00
|
|
|
|_, x| x, // No transformation needed
|
|
|
|
dep_graph::hash_result,
|
2017-09-22 13:03:15 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-19 14:32:39 +02:00
|
|
|
pub fn serialize_query_result_cache<E>(self,
|
|
|
|
encoder: &mut E)
|
|
|
|
-> Result<(), E::Error>
|
2017-11-13 16:35:51 +01:00
|
|
|
where E: ty::codec::TyEncoder
|
2017-10-19 14:32:39 +02:00
|
|
|
{
|
2018-06-13 16:44:43 +03:00
|
|
|
self.queries.on_disk_cache.serialize(self.global_tcx(), encoder)
|
2017-10-19 14:32:39 +02:00
|
|
|
}
|
|
|
|
|
2018-07-05 15:14:34 -03:00
|
|
|
/// If true, we should use the AST-based borrowck (we may *also* use
|
|
|
|
/// the MIR-based borrowck).
|
|
|
|
pub fn use_ast_borrowck(self) -> bool {
|
|
|
|
self.borrowck_mode().use_ast()
|
|
|
|
}
|
|
|
|
|
2018-07-20 17:29:29 +02:00
|
|
|
/// If true, we should use the MIR-based borrow check, but also
|
|
|
|
/// fall back on the AST borrow check if the MIR-based one errors.
|
|
|
|
pub fn migrate_borrowck(self) -> bool {
|
|
|
|
self.borrowck_mode().migrate()
|
|
|
|
}
|
|
|
|
|
2018-05-04 12:05:10 +02:00
|
|
|
/// If true, make MIR codegen for `match` emit a temp that holds a
|
|
|
|
/// borrow of the input to the match expression.
|
|
|
|
pub fn generate_borrow_of_any_match_input(&self) -> bool {
|
|
|
|
self.emit_read_for_match()
|
|
|
|
}
|
|
|
|
|
2018-09-14 21:05:31 +02:00
|
|
|
/// If true, make MIR codegen for `match` emit FakeRead
|
2018-05-04 12:05:10 +02:00
|
|
|
/// statements (which simulate the maximal effect of executing the
|
|
|
|
/// patterns in a match arm).
|
|
|
|
pub fn emit_read_for_match(&self) -> bool {
|
2019-01-26 17:25:37 +00:00
|
|
|
!self.sess.opts.debugging_opts.nll_dont_emit_read_for_match
|
2018-02-14 16:11:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// What mode(s) of borrowck should we run? AST? MIR? both?
|
|
|
|
/// (Also considers the `#![feature(nll)]` setting.)
|
|
|
|
pub fn borrowck_mode(&self) -> BorrowckMode {
|
2018-07-26 13:17:33 +02:00
|
|
|
// Here are the main constraints we need to deal with:
|
|
|
|
//
|
2019-01-26 17:25:37 +00:00
|
|
|
// 1. An opts.borrowck_mode of `BorrowckMode::Migrate` is
|
2018-07-26 13:17:33 +02:00
|
|
|
// synonymous with no `-Z borrowck=...` flag at all.
|
|
|
|
//
|
2019-01-26 17:25:37 +00:00
|
|
|
// 2. We want to allow developers on the Nightly channel
|
2018-07-26 13:17:33 +02:00
|
|
|
// to opt back into the "hard error" mode for NLL,
|
|
|
|
// (which they can do via specifying `#![feature(nll)]`
|
|
|
|
// explicitly in their crate).
|
|
|
|
//
|
|
|
|
// So, this precedence list is how pnkfelix chose to work with
|
|
|
|
// the above constraints:
|
|
|
|
//
|
|
|
|
// * `#![feature(nll)]` *always* means use NLL with hard
|
|
|
|
// errors. (To simplify the code here, it now even overrides
|
|
|
|
// a user's attempt to specify `-Z borrowck=compare`, which
|
|
|
|
// we arguably do not need anymore and should remove.)
|
|
|
|
//
|
2019-01-26 17:25:37 +00:00
|
|
|
// * Otherwise, if no `-Z borrowck=...` then use migrate mode
|
2018-07-26 13:17:33 +02:00
|
|
|
//
|
|
|
|
// * Otherwise, use the behavior requested via `-Z borrowck=...`
|
|
|
|
|
|
|
|
if self.features().nll { return BorrowckMode::Mir; }
|
|
|
|
|
2019-01-26 17:25:37 +00:00
|
|
|
self.sess.opts.borrowck_mode
|
2018-02-14 16:11:02 +01:00
|
|
|
}
|
|
|
|
|
2018-03-06 14:44:14 +01:00
|
|
|
#[inline]
|
|
|
|
pub fn local_crate_exports_generics(self) -> bool {
|
2018-07-26 13:20:47 -06:00
|
|
|
debug_assert!(self.sess.opts.share_generics());
|
2018-03-21 12:23:57 +01:00
|
|
|
|
2018-03-06 14:44:14 +01:00
|
|
|
self.sess.crate_types.borrow().iter().any(|crate_type| {
|
|
|
|
match crate_type {
|
2018-07-26 11:13:11 -06:00
|
|
|
CrateType::Executable |
|
|
|
|
CrateType::Staticlib |
|
|
|
|
CrateType::ProcMacro |
|
|
|
|
CrateType::Cdylib => false,
|
|
|
|
CrateType::Rlib |
|
|
|
|
CrateType::Dylib => true,
|
2018-03-06 14:44:14 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2018-09-02 00:42:51 +02:00
|
|
|
|
|
|
|
// This method returns the DefId and the BoundRegion corresponding to the given region.
|
|
|
|
pub fn is_suitable_region(&self, region: Region<'tcx>) -> Option<FreeRegionInfo> {
|
|
|
|
let (suitable_region_binding_scope, bound_region) = match *region {
|
|
|
|
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
|
|
|
|
ty::ReEarlyBound(ref ebr) => (
|
2018-12-19 12:20:59 +02:00
|
|
|
self.parent(ebr.def_id).unwrap(),
|
2018-09-02 00:42:51 +02:00
|
|
|
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
|
|
|
|
),
|
|
|
|
_ => return None, // not a free region
|
|
|
|
};
|
|
|
|
|
2019-03-04 09:00:30 +01:00
|
|
|
let hir_id = self.hir()
|
|
|
|
.as_local_hir_id(suitable_region_binding_scope)
|
2018-09-02 00:42:51 +02:00
|
|
|
.unwrap();
|
2019-03-04 09:00:30 +01:00
|
|
|
let is_impl_item = match self.hir().find_by_hir_id(hir_id) {
|
2018-09-02 00:42:51 +02:00
|
|
|
Some(Node::Item(..)) | Some(Node::TraitItem(..)) => false,
|
|
|
|
Some(Node::ImplItem(..)) => {
|
|
|
|
self.is_bound_region_in_impl_item(suitable_region_binding_scope)
|
|
|
|
}
|
|
|
|
_ => return None,
|
|
|
|
};
|
|
|
|
|
|
|
|
return Some(FreeRegionInfo {
|
|
|
|
def_id: suitable_region_binding_scope,
|
|
|
|
boundregion: bound_region,
|
|
|
|
is_impl_item: is_impl_item,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-02 11:10:51 +02:00
|
|
|
pub fn return_type_impl_trait(
|
2018-09-02 00:42:51 +02:00
|
|
|
&self,
|
|
|
|
scope_def_id: DefId,
|
2018-09-04 18:56:14 +02:00
|
|
|
) -> Option<Ty<'tcx>> {
|
2018-11-08 15:18:55 -08:00
|
|
|
// HACK: `type_of_def_id()` will fail on these (#55796), so return None
|
2019-03-04 09:00:30 +01:00
|
|
|
let hir_id = self.hir().as_local_hir_id(scope_def_id).unwrap();
|
|
|
|
match self.hir().get_by_hir_id(hir_id) {
|
2018-11-08 15:18:55 -08:00
|
|
|
Node::Item(item) => {
|
|
|
|
match item.node {
|
2018-11-09 10:16:07 -08:00
|
|
|
ItemKind::Fn(..) => { /* type_of_def_id() will work */ }
|
|
|
|
_ => {
|
2018-11-08 15:18:55 -08:00
|
|
|
return None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => { /* type_of_def_id() will work or panic */ }
|
|
|
|
}
|
|
|
|
|
2018-09-02 00:42:51 +02:00
|
|
|
let ret_ty = self.type_of(scope_def_id);
|
|
|
|
match ret_ty.sty {
|
|
|
|
ty::FnDef(_, _) => {
|
|
|
|
let sig = ret_ty.fn_sig(*self);
|
|
|
|
let output = self.erase_late_bound_regions(&sig.output());
|
2018-09-02 11:10:51 +02:00
|
|
|
if output.is_impl_trait() {
|
|
|
|
Some(output)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2018-09-02 00:42:51 +02:00
|
|
|
}
|
2018-09-02 11:10:51 +02:00
|
|
|
_ => None
|
2018-09-02 00:42:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Here we check if the bound region is in Impl Item.
|
|
|
|
pub fn is_bound_region_in_impl_item(
|
|
|
|
&self,
|
|
|
|
suitable_region_binding_scope: DefId,
|
|
|
|
) -> bool {
|
|
|
|
let container_id = self.associated_item(suitable_region_binding_scope)
|
|
|
|
.container
|
|
|
|
.id();
|
|
|
|
if self.impl_trait_ref(container_id).is_some() {
|
|
|
|
// For now, we do not try to target impls of traits. This is
|
|
|
|
// because this message is going to suggest that the user
|
|
|
|
// change the fn signature, but they may not be free to do so,
|
|
|
|
// since the signature must match the trait.
|
|
|
|
//
|
|
|
|
// FIXME(#42706) -- in some cases, we could do better here.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
false
|
|
|
|
}
|
2019-01-19 21:59:34 +01:00
|
|
|
|
|
|
|
/// Determine whether identifiers in the assembly have strict naming rules.
|
|
|
|
/// Currently, only NVPTX* targets need it.
|
|
|
|
pub fn has_strict_asm_symbol_naming(&self) -> bool {
|
|
|
|
self.gcx.sess.target.target.arch.contains("nvptx")
|
|
|
|
}
|
2017-09-07 13:21:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
2018-08-18 12:08:06 +02:00
|
|
|
pub fn encode_metadata(self)
|
2017-11-29 16:28:25 +01:00
|
|
|
-> EncodedMetadata
|
2017-09-07 13:21:46 -07:00
|
|
|
{
|
2018-08-18 12:08:06 +02:00
|
|
|
self.cstore.encode_metadata(self)
|
2017-09-07 13:21:46 -07:00
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-12-07 06:59:27 +01:00
|
|
|
impl<'gcx> GlobalCtxt<'gcx> {
|
2016-12-23 20:48:21 -07:00
|
|
|
/// Call the closure with a local `TyCtxt` using the given arena.
|
2018-12-13 03:32:44 +01:00
|
|
|
/// `interners` is a slot passed so we can create a CtxtInterners
|
|
|
|
/// with the same lifetime as `arena`.
|
2018-12-07 06:59:27 +01:00
|
|
|
pub fn enter_local<'tcx, F, R>(
|
|
|
|
&'gcx self,
|
2018-04-15 16:01:38 +02:00
|
|
|
arena: &'tcx SyncDroplessArena,
|
2018-12-07 06:59:27 +01:00
|
|
|
interners: &'tcx mut Option<CtxtInterners<'tcx>>,
|
2018-03-24 06:19:20 +01:00
|
|
|
f: F
|
|
|
|
) -> R
|
|
|
|
where
|
2018-12-07 06:59:27 +01:00
|
|
|
F: FnOnce(TyCtxt<'tcx, 'gcx, 'tcx>) -> R,
|
|
|
|
'gcx: 'tcx,
|
2016-05-11 04:14:41 +03:00
|
|
|
{
|
2018-12-07 06:59:27 +01:00
|
|
|
*interners = Some(CtxtInterners::new(&arena));
|
2018-03-15 10:03:36 +01:00
|
|
|
let tcx = TyCtxt {
|
|
|
|
gcx: self,
|
2018-12-07 06:59:27 +01:00
|
|
|
interners: interners.as_ref().unwrap(),
|
|
|
|
dummy: PhantomData,
|
2018-03-15 10:03:36 +01:00
|
|
|
};
|
|
|
|
ty::tls::with_related_context(tcx.global_tcx(), |icx| {
|
|
|
|
let new_icx = ty::tls::ImplicitCtxt {
|
|
|
|
tcx,
|
|
|
|
query: icx.query.clone(),
|
2018-12-07 03:04:23 +01:00
|
|
|
diagnostics: icx.diagnostics,
|
2018-04-06 14:53:11 +02:00
|
|
|
layout_depth: icx.layout_depth,
|
2018-12-25 04:36:17 +01:00
|
|
|
task_deps: icx.task_deps,
|
2018-03-15 10:03:36 +01:00
|
|
|
};
|
2018-12-07 06:59:27 +01:00
|
|
|
ty::tls::enter_context(&new_icx, |_| {
|
|
|
|
f(tcx)
|
2018-03-15 10:03:36 +01:00
|
|
|
})
|
|
|
|
})
|
2016-05-11 04:14:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
/// A trait implemented for all X<'a> types which can be safely and
|
|
|
|
/// efficiently converted to X<'tcx> as long as they are part of the
|
2016-02-29 23:36:51 +00:00
|
|
|
/// provided TyCtxt<'tcx>.
|
2019-02-09 22:11:53 +08:00
|
|
|
/// This can be done, for example, for Ty<'tcx> or SubstsRef<'tcx>
|
2015-09-06 21:51:58 +03:00
|
|
|
/// by looking them up in their respective interners.
|
2016-05-11 04:14:41 +03:00
|
|
|
///
|
|
|
|
/// However, this is still not the best implementation as it does
|
|
|
|
/// need to compare the components, even for interned values.
|
|
|
|
/// It would be more efficient if TypedArena provided a way to
|
|
|
|
/// determine whether the address is in the allocated range.
|
|
|
|
///
|
2015-09-06 21:51:58 +03:00
|
|
|
/// None is returned if the value or one of the components is not part
|
|
|
|
/// of the provided context.
|
|
|
|
/// For Ty, None can be returned if either the type interner doesn't
|
2018-08-22 01:34:12 +01:00
|
|
|
/// contain the TyKind key or if the address of the interned
|
2015-09-06 21:51:58 +03:00
|
|
|
/// pointer differs. The latter case is possible if a primitive type,
|
2018-11-27 02:59:49 +00:00
|
|
|
/// e.g., `()` or `u8`, was interned in a different context.
|
2018-06-27 06:01:19 -04:00
|
|
|
pub trait Lift<'tcx>: fmt::Debug {
|
|
|
|
type Lifted: fmt::Debug + 'tcx;
|
2016-04-29 06:00:23 +03:00
|
|
|
fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted>;
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-05-08 18:15:48 -03:00
|
|
|
|
2018-12-28 20:30:06 +01:00
|
|
|
macro_rules! nop_lift {
|
|
|
|
($ty:ty => $lifted:ty) => {
|
|
|
|
impl<'a, 'tcx> Lift<'tcx> for $ty {
|
|
|
|
type Lifted = $lifted;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
if tcx.interners.arena.in_arena(*self as *const _) {
|
|
|
|
return Some(unsafe { mem::transmute(*self) });
|
|
|
|
}
|
|
|
|
// Also try in the global tcx if we're not that.
|
|
|
|
if !tcx.is_global() {
|
|
|
|
self.lift_to_tcx(tcx.global_tcx())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
2018-05-08 18:15:48 -03:00
|
|
|
}
|
2018-12-28 20:30:06 +01:00
|
|
|
};
|
2018-05-08 18:15:48 -03:00
|
|
|
}
|
|
|
|
|
2018-12-28 20:30:06 +01:00
|
|
|
macro_rules! nop_list_lift {
|
|
|
|
($ty:ty => $lifted:ty) => {
|
|
|
|
impl<'a, 'tcx> Lift<'tcx> for &'a List<$ty> {
|
|
|
|
type Lifted = &'tcx List<$lifted>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
2019-01-08 09:25:06 +01:00
|
|
|
if self.is_empty() {
|
2018-12-28 20:30:06 +01:00
|
|
|
return Some(List::empty());
|
|
|
|
}
|
|
|
|
if tcx.interners.arena.in_arena(*self as *const _) {
|
|
|
|
return Some(unsafe { mem::transmute(*self) });
|
|
|
|
}
|
|
|
|
// Also try in the global tcx if we're not that.
|
|
|
|
if !tcx.is_global() {
|
|
|
|
self.lift_to_tcx(tcx.global_tcx())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
2018-05-08 18:15:48 -03:00
|
|
|
}
|
2018-12-28 20:30:06 +01:00
|
|
|
};
|
2018-05-08 18:15:48 -03:00
|
|
|
}
|
|
|
|
|
2018-12-28 20:30:06 +01:00
|
|
|
nop_lift!{Ty<'a> => Ty<'tcx>}
|
|
|
|
nop_lift!{Region<'a> => Region<'tcx>}
|
|
|
|
nop_lift!{Goal<'a> => Goal<'tcx>}
|
2019-03-14 10:19:31 +01:00
|
|
|
nop_lift!{&'a Const<'a> => &'tcx Const<'tcx>}
|
2018-11-23 19:47:22 +01:00
|
|
|
|
2018-12-28 20:30:06 +01:00
|
|
|
nop_list_lift!{Goal<'a> => Goal<'tcx>}
|
|
|
|
nop_list_lift!{Clause<'a> => Clause<'tcx>}
|
|
|
|
nop_list_lift!{Ty<'a> => Ty<'tcx>}
|
|
|
|
nop_list_lift!{ExistentialPredicate<'a> => ExistentialPredicate<'tcx>}
|
|
|
|
nop_list_lift!{Predicate<'a> => Predicate<'tcx>}
|
|
|
|
nop_list_lift!{CanonicalVarInfo => CanonicalVarInfo}
|
2019-03-28 18:00:17 -07:00
|
|
|
nop_list_lift!{ProjectionKind => ProjectionKind}
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2019-02-26 09:30:34 +08:00
|
|
|
// this is the impl for `&'a InternalSubsts<'a>`
|
2018-12-28 20:30:06 +01:00
|
|
|
nop_list_lift!{Kind<'a> => Kind<'tcx>}
|
2018-12-11 19:56:59 +01:00
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
pub mod tls {
|
2019-02-23 14:25:03 +00:00
|
|
|
use super::{GlobalCtxt, TyCtxt, ptr_eq};
|
2015-09-06 21:51:58 +03:00
|
|
|
|
|
|
|
use std::fmt;
|
2018-03-15 10:03:36 +01:00
|
|
|
use std::mem;
|
2018-12-07 06:59:27 +01:00
|
|
|
use std::marker::PhantomData;
|
2016-06-21 18:08:13 -04:00
|
|
|
use syntax_pos;
|
2019-02-05 11:20:45 -06:00
|
|
|
use crate::ty::query;
|
2019-02-08 00:56:05 +09:00
|
|
|
use errors::{Diagnostic, TRACK_DIAGNOSTICS};
|
2018-03-15 10:03:36 +01:00
|
|
|
use rustc_data_structures::OnDrop;
|
2018-04-06 12:56:59 +02:00
|
|
|
use rustc_data_structures::sync::{self, Lrc, Lock};
|
2018-12-07 03:04:23 +01:00
|
|
|
use rustc_data_structures::thin_vec::ThinVec;
|
2019-02-05 11:20:45 -06:00
|
|
|
use crate::dep_graph::TaskDeps;
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2019-01-28 15:51:47 +01:00
|
|
|
#[cfg(not(parallel_compiler))]
|
2018-04-06 12:56:59 +02:00
|
|
|
use std::cell::Cell;
|
|
|
|
|
2019-01-28 15:51:47 +01:00
|
|
|
#[cfg(parallel_compiler)]
|
2019-02-05 11:20:45 -06:00
|
|
|
use rustc_rayon_core as rayon_core;
|
2018-04-06 12:56:59 +02:00
|
|
|
|
2018-03-24 06:19:20 +01:00
|
|
|
/// This is the implicit state of rustc. It contains the current
|
|
|
|
/// TyCtxt and query. It is updated when creating a local interner or
|
|
|
|
/// executing a new query. Whenever there's a TyCtxt value available
|
|
|
|
/// you should also have access to an ImplicitCtxt through the functions
|
|
|
|
/// in this module.
|
2018-03-15 10:03:36 +01:00
|
|
|
#[derive(Clone)]
|
2018-12-07 06:59:27 +01:00
|
|
|
pub struct ImplicitCtxt<'a, 'gcx: 'tcx, 'tcx> {
|
2018-03-24 06:19:20 +01:00
|
|
|
/// The current TyCtxt. Initially created by `enter_global` and updated
|
|
|
|
/// by `enter_local` with a new local interner
|
2018-12-07 06:59:27 +01:00
|
|
|
pub tcx: TyCtxt<'tcx, 'gcx, 'tcx>,
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2018-12-07 03:04:23 +01:00
|
|
|
/// The current query job, if any. This is updated by JobOwner::start in
|
2018-06-13 16:44:43 +03:00
|
|
|
/// ty::query::plumbing when executing a query
|
|
|
|
pub query: Option<Lrc<query::QueryJob<'gcx>>>,
|
2018-04-06 14:53:11 +02:00
|
|
|
|
2018-12-07 03:04:23 +01:00
|
|
|
/// Where to store diagnostics for the current query job, if any.
|
|
|
|
/// This is updated by JobOwner::start in ty::query::plumbing when executing a query
|
|
|
|
pub diagnostics: Option<&'a Lock<ThinVec<Diagnostic>>>,
|
|
|
|
|
2018-04-06 14:53:11 +02:00
|
|
|
/// Used to prevent layout from recursing too deeply.
|
|
|
|
pub layout_depth: usize,
|
2018-04-06 14:52:36 +02:00
|
|
|
|
|
|
|
/// The current dep graph task. This is used to add dependencies to queries
|
|
|
|
/// when executing them
|
2018-12-25 04:36:17 +01:00
|
|
|
pub task_deps: Option<&'a Lock<TaskDeps>>,
|
std: Stabilize APIs for the 1.8 release
This commit is the result of the FCPs ending for the 1.8 release cycle for both
the libs and the lang suteams. The full list of changes are:
Stabilized
* `braced_empty_structs`
* `augmented_assignments`
* `str::encode_utf16` - renamed from `utf16_units`
* `str::EncodeUtf16` - renamed from `Utf16Units`
* `Ref::map`
* `RefMut::map`
* `ptr::drop_in_place`
* `time::Instant`
* `time::SystemTime`
* `{Instant,SystemTime}::now`
* `{Instant,SystemTime}::duration_since` - renamed from `duration_from_earlier`
* `{Instant,SystemTime}::elapsed`
* Various `Add`/`Sub` impls for `Time` and `SystemTime`
* `SystemTimeError`
* `SystemTimeError::duration`
* Various impls for `SystemTimeError`
* `UNIX_EPOCH`
* `ops::{Add,Sub,Mul,Div,Rem,BitAnd,BitOr,BitXor,Shl,Shr}Assign`
Deprecated
* Scoped TLS (the `scoped_thread_local!` macro)
* `Ref::filter_map`
* `RefMut::filter_map`
* `RwLockReadGuard::map`
* `RwLockWriteGuard::map`
* `Condvar::wait_timeout_with`
Closes #27714
Closes #27715
Closes #27746
Closes #27748
Closes #27908
Closes #29866
2016-02-25 15:52:29 -08:00
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2018-05-31 23:04:21 +02:00
|
|
|
/// Sets Rayon's thread local variable which is preserved for Rayon jobs
|
|
|
|
/// to `value` during the call to `f`. It is restored to its previous value after.
|
|
|
|
/// This is used to set the pointer to the new ImplicitCtxt.
|
2019-01-28 15:51:47 +01:00
|
|
|
#[cfg(parallel_compiler)]
|
2018-12-05 18:59:48 +01:00
|
|
|
#[inline]
|
2018-04-06 12:56:59 +02:00
|
|
|
fn set_tlv<F: FnOnce() -> R, R>(value: usize, f: F) -> R {
|
|
|
|
rayon_core::tlv::with(value, f)
|
|
|
|
}
|
|
|
|
|
2018-05-31 23:04:21 +02:00
|
|
|
/// Gets Rayon's thread local variable which is preserved for Rayon jobs.
|
|
|
|
/// This is used to get the pointer to the current ImplicitCtxt.
|
2019-01-28 15:51:47 +01:00
|
|
|
#[cfg(parallel_compiler)]
|
2018-12-05 18:59:48 +01:00
|
|
|
#[inline]
|
2018-04-06 12:56:59 +02:00
|
|
|
fn get_tlv() -> usize {
|
|
|
|
rayon_core::tlv::get()
|
|
|
|
}
|
|
|
|
|
2019-01-28 15:51:47 +01:00
|
|
|
#[cfg(not(parallel_compiler))]
|
2019-01-24 15:49:03 -05:00
|
|
|
thread_local! {
|
|
|
|
/// A thread local variable which stores a pointer to the current ImplicitCtxt.
|
|
|
|
static TLV: Cell<usize> = Cell::new(0);
|
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2018-05-31 23:04:21 +02:00
|
|
|
/// Sets TLV to `value` during the call to `f`.
|
|
|
|
/// It is restored to its previous value after.
|
|
|
|
/// This is used to set the pointer to the new ImplicitCtxt.
|
2019-01-28 15:51:47 +01:00
|
|
|
#[cfg(not(parallel_compiler))]
|
2018-12-05 18:59:48 +01:00
|
|
|
#[inline]
|
2018-03-15 10:03:36 +01:00
|
|
|
fn set_tlv<F: FnOnce() -> R, R>(value: usize, f: F) -> R {
|
|
|
|
let old = get_tlv();
|
|
|
|
let _reset = OnDrop(move || TLV.with(|tlv| tlv.set(old)));
|
|
|
|
TLV.with(|tlv| tlv.set(value));
|
|
|
|
f()
|
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2018-05-31 23:04:21 +02:00
|
|
|
/// This is used to get the pointer to the current ImplicitCtxt.
|
2019-01-28 15:51:47 +01:00
|
|
|
#[cfg(not(parallel_compiler))]
|
2018-03-15 10:03:36 +01:00
|
|
|
fn get_tlv() -> usize {
|
|
|
|
TLV.with(|tlv| tlv.get())
|
std: Stabilize APIs for the 1.8 release
This commit is the result of the FCPs ending for the 1.8 release cycle for both
the libs and the lang suteams. The full list of changes are:
Stabilized
* `braced_empty_structs`
* `augmented_assignments`
* `str::encode_utf16` - renamed from `utf16_units`
* `str::EncodeUtf16` - renamed from `Utf16Units`
* `Ref::map`
* `RefMut::map`
* `ptr::drop_in_place`
* `time::Instant`
* `time::SystemTime`
* `{Instant,SystemTime}::now`
* `{Instant,SystemTime}::duration_since` - renamed from `duration_from_earlier`
* `{Instant,SystemTime}::elapsed`
* Various `Add`/`Sub` impls for `Time` and `SystemTime`
* `SystemTimeError`
* `SystemTimeError::duration`
* Various impls for `SystemTimeError`
* `UNIX_EPOCH`
* `ops::{Add,Sub,Mul,Div,Rem,BitAnd,BitOr,BitXor,Shl,Shr}Assign`
Deprecated
* Scoped TLS (the `scoped_thread_local!` macro)
* `Ref::filter_map`
* `RefMut::filter_map`
* `RwLockReadGuard::map`
* `RwLockWriteGuard::map`
* `Condvar::wait_timeout_with`
Closes #27714
Closes #27715
Closes #27746
Closes #27748
Closes #27908
Closes #29866
2016-02-25 15:52:29 -08:00
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2018-03-24 06:19:20 +01:00
|
|
|
/// This is a callback from libsyntax as it cannot access the implicit state
|
|
|
|
/// in librustc otherwise
|
2018-08-29 22:02:42 -07:00
|
|
|
fn span_debug(span: syntax_pos::Span, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2018-12-03 19:45:06 +01:00
|
|
|
with_opt(|tcx| {
|
|
|
|
if let Some(tcx) = tcx {
|
|
|
|
write!(f, "{}", tcx.sess.source_map().span_to_string(span))
|
|
|
|
} else {
|
|
|
|
syntax_pos::default_span_debug(span, f)
|
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-03-24 06:19:20 +01:00
|
|
|
/// This is a callback from libsyntax as it cannot access the implicit state
|
|
|
|
/// in librustc otherwise. It is used to when diagnostic messages are
|
|
|
|
/// emitted and stores them in the current query, if there is one.
|
2018-03-15 10:03:36 +01:00
|
|
|
fn track_diagnostic(diagnostic: &Diagnostic) {
|
2018-04-26 00:49:52 +02:00
|
|
|
with_context_opt(|icx| {
|
|
|
|
if let Some(icx) = icx {
|
2018-12-07 03:04:23 +01:00
|
|
|
if let Some(ref diagnostics) = icx.diagnostics {
|
|
|
|
let mut diagnostics = diagnostics.lock();
|
|
|
|
diagnostics.extend(Some(diagnostic.clone()));
|
2018-04-26 00:49:52 +02:00
|
|
|
}
|
2018-03-15 10:03:36 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-03-24 06:19:20 +01:00
|
|
|
/// Sets up the callbacks from libsyntax on the current thread
|
2018-03-15 10:03:36 +01:00
|
|
|
pub fn with_thread_locals<F, R>(f: F) -> R
|
|
|
|
where F: FnOnce() -> R
|
2016-04-28 03:13:17 +03:00
|
|
|
{
|
2016-06-21 18:08:13 -04:00
|
|
|
syntax_pos::SPAN_DEBUG.with(|span_dbg| {
|
2015-09-06 21:51:58 +03:00
|
|
|
let original_span_debug = span_dbg.get();
|
|
|
|
span_dbg.set(span_debug);
|
2018-03-15 10:03:36 +01:00
|
|
|
|
|
|
|
let _on_drop = OnDrop(move || {
|
|
|
|
span_dbg.set(original_span_debug);
|
|
|
|
});
|
|
|
|
|
|
|
|
TRACK_DIAGNOSTICS.with(|current| {
|
|
|
|
let original = current.get();
|
|
|
|
current.set(track_diagnostic);
|
|
|
|
|
|
|
|
let _on_drop = OnDrop(move || {
|
|
|
|
current.set(original);
|
|
|
|
});
|
|
|
|
|
|
|
|
f()
|
|
|
|
})
|
2015-09-28 15:00:15 +13:00
|
|
|
})
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-03-24 06:19:20 +01:00
|
|
|
/// Sets `context` as the new current ImplicitCtxt for the duration of the function `f`
|
2018-12-05 18:59:48 +01:00
|
|
|
#[inline]
|
2018-03-24 06:19:20 +01:00
|
|
|
pub fn enter_context<'a, 'gcx: 'tcx, 'tcx, F, R>(context: &ImplicitCtxt<'a, 'gcx, 'tcx>,
|
|
|
|
f: F) -> R
|
|
|
|
where F: FnOnce(&ImplicitCtxt<'a, 'gcx, 'tcx>) -> R
|
2016-05-11 04:14:41 +03:00
|
|
|
{
|
2018-03-24 06:19:20 +01:00
|
|
|
set_tlv(context as *const _ as usize, || {
|
|
|
|
f(&context)
|
2016-05-11 04:14:41 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-03-24 06:19:20 +01:00
|
|
|
/// Enters GlobalCtxt by setting up libsyntax callbacks and
|
|
|
|
/// creating a initial TyCtxt and ImplicitCtxt.
|
|
|
|
/// This happens once per rustc session and TyCtxts only exists
|
|
|
|
/// inside the `f` function.
|
2018-12-07 06:59:27 +01:00
|
|
|
pub fn enter_global<'gcx, F, R>(gcx: &'gcx GlobalCtxt<'gcx>, f: F) -> R
|
2018-12-13 03:32:44 +01:00
|
|
|
where F: FnOnce(TyCtxt<'gcx, 'gcx, 'gcx>) -> R
|
2016-05-03 05:23:22 +03:00
|
|
|
{
|
2018-12-08 20:30:23 +01:00
|
|
|
// Update GCX_PTR to indicate there's a GlobalCtxt available
|
|
|
|
GCX_PTR.with(|lock| {
|
|
|
|
*lock.lock() = gcx as *const _ as usize;
|
|
|
|
});
|
|
|
|
// Set GCX_PTR back to 0 when we exit
|
|
|
|
let _on_drop = OnDrop(move || {
|
|
|
|
GCX_PTR.with(|lock| *lock.lock() = 0);
|
|
|
|
});
|
2018-04-06 12:56:59 +02:00
|
|
|
|
2018-12-08 20:30:23 +01:00
|
|
|
let tcx = TyCtxt {
|
|
|
|
gcx,
|
|
|
|
interners: &gcx.global_interners,
|
|
|
|
dummy: PhantomData,
|
|
|
|
};
|
|
|
|
let icx = ImplicitCtxt {
|
|
|
|
tcx,
|
|
|
|
query: None,
|
|
|
|
diagnostics: None,
|
|
|
|
layout_depth: 0,
|
|
|
|
task_deps: None,
|
|
|
|
};
|
|
|
|
enter_context(&icx, |_| {
|
|
|
|
f(tcx)
|
std: Stabilize APIs for the 1.8 release
This commit is the result of the FCPs ending for the 1.8 release cycle for both
the libs and the lang suteams. The full list of changes are:
Stabilized
* `braced_empty_structs`
* `augmented_assignments`
* `str::encode_utf16` - renamed from `utf16_units`
* `str::EncodeUtf16` - renamed from `Utf16Units`
* `Ref::map`
* `RefMut::map`
* `ptr::drop_in_place`
* `time::Instant`
* `time::SystemTime`
* `{Instant,SystemTime}::now`
* `{Instant,SystemTime}::duration_since` - renamed from `duration_from_earlier`
* `{Instant,SystemTime}::elapsed`
* Various `Add`/`Sub` impls for `Time` and `SystemTime`
* `SystemTimeError`
* `SystemTimeError::duration`
* Various impls for `SystemTimeError`
* `UNIX_EPOCH`
* `ops::{Add,Sub,Mul,Div,Rem,BitAnd,BitOr,BitXor,Shl,Shr}Assign`
Deprecated
* Scoped TLS (the `scoped_thread_local!` macro)
* `Ref::filter_map`
* `RefMut::filter_map`
* `RwLockReadGuard::map`
* `RwLockWriteGuard::map`
* `Condvar::wait_timeout_with`
Closes #27714
Closes #27715
Closes #27746
Closes #27748
Closes #27908
Closes #29866
2016-02-25 15:52:29 -08:00
|
|
|
})
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2019-01-24 15:49:03 -05:00
|
|
|
scoped_thread_local! {
|
|
|
|
/// Stores a pointer to the GlobalCtxt if one is available.
|
|
|
|
/// This is used to access the GlobalCtxt in the deadlock handler given to Rayon.
|
|
|
|
pub static GCX_PTR: Lock<usize>
|
|
|
|
}
|
2018-04-06 12:56:59 +02:00
|
|
|
|
2018-05-31 23:04:21 +02:00
|
|
|
/// Creates a TyCtxt and ImplicitCtxt based on the GCX_PTR thread local.
|
|
|
|
/// This is used in the deadlock handler.
|
2018-04-06 12:56:59 +02:00
|
|
|
pub unsafe fn with_global<F, R>(f: F) -> R
|
|
|
|
where F: for<'a, 'gcx, 'tcx> FnOnce(TyCtxt<'a, 'gcx, 'tcx>) -> R
|
|
|
|
{
|
|
|
|
let gcx = GCX_PTR.with(|lock| *lock.lock());
|
|
|
|
assert!(gcx != 0);
|
|
|
|
let gcx = &*(gcx as *const GlobalCtxt<'_>);
|
|
|
|
let tcx = TyCtxt {
|
|
|
|
gcx,
|
|
|
|
interners: &gcx.global_interners,
|
2018-12-07 06:59:27 +01:00
|
|
|
dummy: PhantomData,
|
2018-04-06 12:56:59 +02:00
|
|
|
};
|
|
|
|
let icx = ImplicitCtxt {
|
|
|
|
query: None,
|
2018-12-07 03:04:23 +01:00
|
|
|
diagnostics: None,
|
2018-04-06 12:56:59 +02:00
|
|
|
tcx,
|
|
|
|
layout_depth: 0,
|
2018-12-25 04:36:17 +01:00
|
|
|
task_deps: None,
|
2018-04-06 12:56:59 +02:00
|
|
|
};
|
|
|
|
enter_context(&icx, |_| f(tcx))
|
|
|
|
}
|
|
|
|
|
2018-03-24 06:19:20 +01:00
|
|
|
/// Allows access to the current ImplicitCtxt in a closure if one is available
|
2018-12-05 18:59:48 +01:00
|
|
|
#[inline]
|
2018-03-15 10:03:36 +01:00
|
|
|
pub fn with_context_opt<F, R>(f: F) -> R
|
|
|
|
where F: for<'a, 'gcx, 'tcx> FnOnce(Option<&ImplicitCtxt<'a, 'gcx, 'tcx>>) -> R
|
2016-05-03 05:23:22 +03:00
|
|
|
{
|
2018-03-15 10:03:36 +01:00
|
|
|
let context = get_tlv();
|
|
|
|
if context == 0 {
|
2015-09-06 21:51:58 +03:00
|
|
|
f(None)
|
2018-03-15 10:03:36 +01:00
|
|
|
} else {
|
2018-04-26 01:03:54 +02:00
|
|
|
// We could get a ImplicitCtxt pointer from another thread.
|
|
|
|
// Ensure that ImplicitCtxt is Sync
|
2018-08-29 22:02:42 -07:00
|
|
|
sync::assert_sync::<ImplicitCtxt<'_, '_, '_>>();
|
2018-04-26 01:03:54 +02:00
|
|
|
|
2018-08-29 22:02:42 -07:00
|
|
|
unsafe { f(Some(&*(context as *const ImplicitCtxt<'_, '_, '_>))) }
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
}
|
2018-03-15 10:03:36 +01:00
|
|
|
|
2018-03-24 06:19:20 +01:00
|
|
|
/// Allows access to the current ImplicitCtxt.
|
|
|
|
/// Panics if there is no ImplicitCtxt available
|
2018-12-05 18:59:48 +01:00
|
|
|
#[inline]
|
2018-03-24 06:19:20 +01:00
|
|
|
pub fn with_context<F, R>(f: F) -> R
|
|
|
|
where F: for<'a, 'gcx, 'tcx> FnOnce(&ImplicitCtxt<'a, 'gcx, 'tcx>) -> R
|
|
|
|
{
|
|
|
|
with_context_opt(|opt_context| f(opt_context.expect("no ImplicitCtxt stored in tls")))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Allows access to the current ImplicitCtxt whose tcx field has the same global
|
|
|
|
/// interner as the tcx argument passed in. This means the closure is given an ImplicitCtxt
|
|
|
|
/// with the same 'gcx lifetime as the TyCtxt passed in.
|
|
|
|
/// This will panic if you pass it a TyCtxt which has a different global interner from
|
|
|
|
/// the current ImplicitCtxt's tcx field.
|
2018-12-05 18:59:48 +01:00
|
|
|
#[inline]
|
2018-03-24 06:19:20 +01:00
|
|
|
pub fn with_related_context<'a, 'gcx, 'tcx1, F, R>(tcx: TyCtxt<'a, 'gcx, 'tcx1>, f: F) -> R
|
|
|
|
where F: for<'b, 'tcx2> FnOnce(&ImplicitCtxt<'b, 'gcx, 'tcx2>) -> R
|
2018-03-15 10:03:36 +01:00
|
|
|
{
|
|
|
|
with_context(|context| {
|
|
|
|
unsafe {
|
2019-02-23 14:25:03 +00:00
|
|
|
assert!(ptr_eq(context.tcx.gcx, tcx.gcx));
|
2018-08-29 22:02:42 -07:00
|
|
|
let context: &ImplicitCtxt<'_, '_, '_> = mem::transmute(context);
|
2018-03-15 10:03:36 +01:00
|
|
|
f(context)
|
|
|
|
}
|
2016-05-11 04:14:41 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-03-24 06:19:20 +01:00
|
|
|
/// Allows access to the current ImplicitCtxt whose tcx field has the same global
|
|
|
|
/// interner and local interner as the tcx argument passed in. This means the closure
|
|
|
|
/// is given an ImplicitCtxt with the same 'tcx and 'gcx lifetimes as the TyCtxt passed in.
|
|
|
|
/// This will panic if you pass it a TyCtxt which has a different global interner or
|
|
|
|
/// a different local interner from the current ImplicitCtxt's tcx field.
|
2018-12-05 18:59:48 +01:00
|
|
|
#[inline]
|
2018-03-24 06:19:20 +01:00
|
|
|
pub fn with_fully_related_context<'a, 'gcx, 'tcx, F, R>(tcx: TyCtxt<'a, 'gcx, 'tcx>, f: F) -> R
|
|
|
|
where F: for<'b> FnOnce(&ImplicitCtxt<'b, 'gcx, 'tcx>) -> R
|
2018-03-15 10:03:36 +01:00
|
|
|
{
|
|
|
|
with_context(|context| {
|
|
|
|
unsafe {
|
2019-02-23 14:25:03 +00:00
|
|
|
assert!(ptr_eq(context.tcx.gcx, tcx.gcx));
|
|
|
|
assert!(ptr_eq(context.tcx.interners, tcx.interners));
|
2018-08-29 22:02:42 -07:00
|
|
|
let context: &ImplicitCtxt<'_, '_, '_> = mem::transmute(context);
|
2018-03-15 10:03:36 +01:00
|
|
|
f(context)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-03-24 06:19:20 +01:00
|
|
|
/// Allows access to the TyCtxt in the current ImplicitCtxt.
|
|
|
|
/// Panics if there is no ImplicitCtxt available
|
2018-12-05 18:59:48 +01:00
|
|
|
#[inline]
|
2016-05-03 05:23:22 +03:00
|
|
|
pub fn with<F, R>(f: F) -> R
|
2016-05-11 04:14:41 +03:00
|
|
|
where F: for<'a, 'gcx, 'tcx> FnOnce(TyCtxt<'a, 'gcx, 'tcx>) -> R
|
2016-05-03 05:23:22 +03:00
|
|
|
{
|
2018-03-15 10:03:36 +01:00
|
|
|
with_context(|context| f(context.tcx))
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-03-24 06:19:20 +01:00
|
|
|
/// Allows access to the TyCtxt in the current ImplicitCtxt.
|
|
|
|
/// The closure is passed None if there is no ImplicitCtxt available
|
2018-12-05 18:59:48 +01:00
|
|
|
#[inline]
|
2016-05-03 05:23:22 +03:00
|
|
|
pub fn with_opt<F, R>(f: F) -> R
|
2016-05-11 04:14:41 +03:00
|
|
|
where F: for<'a, 'gcx, 'tcx> FnOnce(Option<TyCtxt<'a, 'gcx, 'tcx>>) -> R
|
2016-05-03 05:23:22 +03:00
|
|
|
{
|
2018-03-15 10:03:36 +01:00
|
|
|
with_context_opt(|opt_context| f(opt_context.map(|context| context.tcx)))
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! sty_debug_print {
|
|
|
|
($ctxt: expr, $($variant: ident),*) => {{
|
|
|
|
// curious inner module to allow variant names to be used as
|
|
|
|
// variable names.
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
mod inner {
|
2019-02-05 11:20:45 -06:00
|
|
|
use crate::ty::{self, TyCtxt};
|
|
|
|
use crate::ty::context::Interned;
|
2016-03-23 04:56:49 +02:00
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
struct DebugStat {
|
|
|
|
total: usize,
|
2019-02-20 01:14:56 +00:00
|
|
|
lt_infer: usize,
|
2015-09-06 21:51:58 +03:00
|
|
|
ty_infer: usize,
|
2019-02-20 01:14:56 +00:00
|
|
|
ct_infer: usize,
|
|
|
|
all_infer: usize,
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-08-29 22:02:42 -07:00
|
|
|
pub fn go(tcx: TyCtxt<'_, '_, '_>) {
|
2015-09-06 21:51:58 +03:00
|
|
|
let mut total = DebugStat {
|
|
|
|
total: 0,
|
2019-02-20 01:14:56 +00:00
|
|
|
lt_infer: 0,
|
|
|
|
ty_infer: 0,
|
|
|
|
ct_infer: 0,
|
|
|
|
all_infer: 0,
|
2015-09-06 21:51:58 +03:00
|
|
|
};
|
|
|
|
$(let mut $variant = total;)*
|
|
|
|
|
2018-05-17 05:19:08 +02:00
|
|
|
for &Interned(t) in tcx.interners.type_.borrow().keys() {
|
2015-09-06 21:51:58 +03:00
|
|
|
let variant = match t.sty {
|
2018-08-22 01:35:55 +01:00
|
|
|
ty::Bool | ty::Char | ty::Int(..) | ty::Uint(..) |
|
|
|
|
ty::Float(..) | ty::Str | ty::Never => continue,
|
2018-08-22 01:35:02 +01:00
|
|
|
ty::Error => /* unimportant */ continue,
|
2015-09-06 21:51:58 +03:00
|
|
|
$(ty::$variant(..) => &mut $variant,)*
|
|
|
|
};
|
2019-02-20 01:14:56 +00:00
|
|
|
let lt = t.flags.intersects(ty::TypeFlags::HAS_RE_INFER);
|
2017-05-12 12:01:43 -04:00
|
|
|
let ty = t.flags.intersects(ty::TypeFlags::HAS_TY_INFER);
|
2019-02-20 01:14:56 +00:00
|
|
|
let ct = t.flags.intersects(ty::TypeFlags::HAS_CT_INFER);
|
2015-09-06 21:51:58 +03:00
|
|
|
|
|
|
|
variant.total += 1;
|
|
|
|
total.total += 1;
|
2019-02-20 01:14:56 +00:00
|
|
|
if lt { total.lt_infer += 1; variant.lt_infer += 1 }
|
2015-09-06 21:51:58 +03:00
|
|
|
if ty { total.ty_infer += 1; variant.ty_infer += 1 }
|
2019-02-20 01:14:56 +00:00
|
|
|
if ct { total.ct_infer += 1; variant.ct_infer += 1 }
|
|
|
|
if lt && ty && ct { total.all_infer += 1; variant.all_infer += 1 }
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
2019-02-20 01:14:56 +00:00
|
|
|
println!("Ty interner total ty lt ct all");
|
2015-09-06 21:51:58 +03:00
|
|
|
$(println!(" {:18}: {uses:6} {usespc:4.1}%, \
|
2019-02-20 01:14:56 +00:00
|
|
|
{ty:4.1}% {lt:5.1}% {ct:4.1}% {all:4.1}%",
|
|
|
|
stringify!($variant),
|
|
|
|
uses = $variant.total,
|
|
|
|
usespc = $variant.total as f64 * 100.0 / total.total as f64,
|
|
|
|
ty = $variant.ty_infer as f64 * 100.0 / total.total as f64,
|
|
|
|
lt = $variant.lt_infer as f64 * 100.0 / total.total as f64,
|
|
|
|
ct = $variant.ct_infer as f64 * 100.0 / total.total as f64,
|
|
|
|
all = $variant.all_infer as f64 * 100.0 / total.total as f64);
|
|
|
|
)*
|
2015-09-06 21:51:58 +03:00
|
|
|
println!(" total {uses:6} \
|
2019-02-20 01:14:56 +00:00
|
|
|
{ty:4.1}% {lt:5.1}% {ct:4.1}% {all:4.1}%",
|
|
|
|
uses = total.total,
|
|
|
|
ty = total.ty_infer as f64 * 100.0 / total.total as f64,
|
|
|
|
lt = total.lt_infer as f64 * 100.0 / total.total as f64,
|
|
|
|
ct = total.ct_infer as f64 * 100.0 / total.total as f64,
|
|
|
|
all = total.all_infer as f64 * 100.0 / total.total as f64)
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inner::go($ctxt)
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2016-05-03 05:23:22 +03:00
|
|
|
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
2016-05-03 04:56:42 +03:00
|
|
|
pub fn print_debug_stats(self) {
|
2015-09-06 21:51:58 +03:00
|
|
|
sty_debug_print!(
|
|
|
|
self,
|
2018-11-02 18:48:24 +01:00
|
|
|
Adt, Array, Slice, RawPtr, Ref, FnDef, FnPtr, Placeholder,
|
2018-10-22 20:37:56 +02:00
|
|
|
Generator, GeneratorWitness, Dynamic, Closure, Tuple, Bound,
|
2018-10-03 17:06:28 +02:00
|
|
|
Param, Infer, UnnormalizedProjection, Projection, Opaque, Foreign);
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2019-02-26 09:30:34 +08:00
|
|
|
println!("InternalSubsts interner: #{}", self.interners.substs.borrow().len());
|
2016-04-28 03:13:17 +03:00
|
|
|
println!("Region interner: #{}", self.interners.region.borrow().len());
|
2016-12-23 20:48:21 -07:00
|
|
|
println!("Stability interner: #{}", self.stability_interner.borrow().len());
|
2018-05-02 06:03:02 +02:00
|
|
|
println!("Allocation interner: #{}", self.allocation_interner.borrow().len());
|
2016-12-23 20:48:21 -07:00
|
|
|
println!("Layout interner: #{}", self.layout_interner.borrow().len());
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-11 04:14:41 +03:00
|
|
|
/// An entry in an interner.
|
|
|
|
struct Interned<'tcx, T: 'tcx+?Sized>(&'tcx T);
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2018-05-17 05:19:08 +02:00
|
|
|
impl<'tcx, T: 'tcx+?Sized> Clone for Interned<'tcx, T> {
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
Interned(self.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl<'tcx, T: 'tcx+?Sized> Copy for Interned<'tcx, T> {}
|
|
|
|
|
2018-11-27 02:59:49 +00:00
|
|
|
// N.B., an `Interned<Ty>` compares and hashes as a sty.
|
2016-05-11 04:14:41 +03:00
|
|
|
impl<'tcx> PartialEq for Interned<'tcx, TyS<'tcx>> {
|
|
|
|
fn eq(&self, other: &Interned<'tcx, TyS<'tcx>>) -> bool {
|
|
|
|
self.0.sty == other.0.sty
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 04:14:41 +03:00
|
|
|
impl<'tcx> Eq for Interned<'tcx, TyS<'tcx>> {}
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2016-05-11 04:14:41 +03:00
|
|
|
impl<'tcx> Hash for Interned<'tcx, TyS<'tcx>> {
|
2015-09-06 21:51:58 +03:00
|
|
|
fn hash<H: Hasher>(&self, s: &mut H) {
|
2016-05-11 04:14:41 +03:00
|
|
|
self.0.sty.hash(s)
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-22 01:34:12 +01:00
|
|
|
impl<'tcx: 'lcx, 'lcx> Borrow<TyKind<'lcx>> for Interned<'tcx, TyS<'tcx>> {
|
|
|
|
fn borrow<'a>(&'a self) -> &'a TyKind<'lcx> {
|
2016-05-11 04:14:41 +03:00
|
|
|
&self.0.sty
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-27 02:59:49 +00:00
|
|
|
// N.B., an `Interned<List<T>>` compares and hashes as its elements.
|
2018-08-22 00:35:01 +01:00
|
|
|
impl<'tcx, T: PartialEq> PartialEq for Interned<'tcx, List<T>> {
|
|
|
|
fn eq(&self, other: &Interned<'tcx, List<T>>) -> bool {
|
2016-09-02 11:08:16 +03:00
|
|
|
self.0[..] == other.0[..]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-22 00:35:01 +01:00
|
|
|
impl<'tcx, T: Eq> Eq for Interned<'tcx, List<T>> {}
|
2016-09-02 11:08:16 +03:00
|
|
|
|
2018-08-22 00:35:01 +01:00
|
|
|
impl<'tcx, T: Hash> Hash for Interned<'tcx, List<T>> {
|
2016-09-02 11:08:16 +03:00
|
|
|
fn hash<H: Hasher>(&self, s: &mut H) {
|
|
|
|
self.0[..].hash(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-22 00:35:01 +01:00
|
|
|
impl<'tcx: 'lcx, 'lcx> Borrow<[Ty<'lcx>]> for Interned<'tcx, List<Ty<'tcx>>> {
|
2016-04-29 08:30:54 +03:00
|
|
|
fn borrow<'a>(&'a self) -> &'a [Ty<'lcx>] {
|
2016-09-02 11:08:16 +03:00
|
|
|
&self.0[..]
|
2016-04-29 08:30:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-22 00:35:01 +01:00
|
|
|
impl<'tcx: 'lcx, 'lcx> Borrow<[CanonicalVarInfo]> for Interned<'tcx, List<CanonicalVarInfo>> {
|
2018-02-09 10:39:36 -05:00
|
|
|
fn borrow<'a>(&'a self) -> &'a [CanonicalVarInfo] {
|
|
|
|
&self.0[..]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 09:30:34 +08:00
|
|
|
impl<'tcx: 'lcx, 'lcx> Borrow<[Kind<'lcx>]> for Interned<'tcx, InternalSubsts<'tcx>> {
|
2016-10-09 11:36:12 -07:00
|
|
|
fn borrow<'a>(&'a self) -> &'a [Kind<'lcx>] {
|
|
|
|
&self.0[..]
|
2016-03-23 04:56:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-28 18:00:17 -07:00
|
|
|
impl<'tcx> Borrow<[ProjectionKind]>
|
|
|
|
for Interned<'tcx, List<ProjectionKind>> {
|
|
|
|
fn borrow<'a>(&'a self) -> &'a [ProjectionKind] {
|
2018-10-26 11:28:40 +02:00
|
|
|
&self.0[..]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-11 16:10:47 +03:00
|
|
|
impl<'tcx> Borrow<RegionKind> for Interned<'tcx, RegionKind> {
|
|
|
|
fn borrow<'a>(&'a self) -> &'a RegionKind {
|
2017-04-20 04:45:53 -04:00
|
|
|
&self.0
|
2016-05-02 18:07:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-06 13:51:02 +02:00
|
|
|
impl<'tcx: 'lcx, 'lcx> Borrow<GoalKind<'lcx>> for Interned<'tcx, GoalKind<'tcx>> {
|
|
|
|
fn borrow<'a>(&'a self) -> &'a GoalKind<'lcx> {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 09:21:49 -07:00
|
|
|
impl<'tcx: 'lcx, 'lcx> Borrow<[ExistentialPredicate<'lcx>]>
|
2018-08-22 00:35:01 +01:00
|
|
|
for Interned<'tcx, List<ExistentialPredicate<'tcx>>> {
|
2016-11-16 09:21:49 -07:00
|
|
|
fn borrow<'a>(&'a self) -> &'a [ExistentialPredicate<'lcx>] {
|
|
|
|
&self.0[..]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-02 14:37:00 -04:00
|
|
|
impl<'tcx: 'lcx, 'lcx> Borrow<[Predicate<'lcx>]>
|
2018-08-22 00:35:01 +01:00
|
|
|
for Interned<'tcx, List<Predicate<'tcx>>> {
|
2017-05-02 14:37:00 -04:00
|
|
|
fn borrow<'a>(&'a self) -> &'a [Predicate<'lcx>] {
|
|
|
|
&self.0[..]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-04 11:25:13 +03:00
|
|
|
impl<'tcx: 'lcx, 'lcx> Borrow<Const<'lcx>> for Interned<'tcx, Const<'tcx>> {
|
|
|
|
fn borrow<'a>(&'a self) -> &'a Const<'lcx> {
|
2017-08-04 00:41:44 +03:00
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-09 16:38:00 +09:00
|
|
|
impl<'tcx: 'lcx, 'lcx> Borrow<[Clause<'lcx>]>
|
2018-08-22 00:35:01 +01:00
|
|
|
for Interned<'tcx, List<Clause<'tcx>>> {
|
2018-04-09 16:38:00 +09:00
|
|
|
fn borrow<'a>(&'a self) -> &'a [Clause<'lcx>] {
|
|
|
|
&self.0[..]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx: 'lcx, 'lcx> Borrow<[Goal<'lcx>]>
|
2018-08-22 00:35:01 +01:00
|
|
|
for Interned<'tcx, List<Goal<'tcx>>> {
|
2018-04-09 16:38:00 +09:00
|
|
|
fn borrow<'a>(&'a self) -> &'a [Goal<'lcx>] {
|
|
|
|
&self.0[..]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-02 11:08:16 +03:00
|
|
|
macro_rules! intern_method {
|
|
|
|
($lt_tcx:tt, $name:ident: $method:ident($alloc:ty,
|
2018-05-02 08:02:57 +02:00
|
|
|
$alloc_method:expr,
|
2016-09-02 11:08:16 +03:00
|
|
|
$alloc_to_key:expr,
|
2018-04-04 17:21:50 -04:00
|
|
|
$keep_in_local_tcx:expr) -> $ty:ty) => {
|
2016-05-11 04:14:41 +03:00
|
|
|
impl<'a, 'gcx, $lt_tcx> TyCtxt<'a, 'gcx, $lt_tcx> {
|
|
|
|
pub fn $method(self, v: $alloc) -> &$lt_tcx $ty {
|
2018-04-30 08:59:23 +02:00
|
|
|
let key = ($alloc_to_key)(&v);
|
2016-05-11 04:14:41 +03:00
|
|
|
|
|
|
|
// HACK(eddyb) Depend on flags being accurate to
|
|
|
|
// determine that all contents are in the global tcx.
|
|
|
|
// See comments on Lift for why we can't use that.
|
2018-04-30 08:59:23 +02:00
|
|
|
if ($keep_in_local_tcx)(&v) {
|
2018-05-17 05:19:08 +02:00
|
|
|
self.interners.$name.borrow_mut().intern_ref(key, || {
|
|
|
|
// Make sure we don't end up with inference
|
|
|
|
// types/regions in the global tcx.
|
|
|
|
if self.is_global() {
|
|
|
|
bug!("Attempted to intern `{:?}` which contains \
|
|
|
|
inference types/regions in the global type context",
|
|
|
|
v);
|
|
|
|
}
|
|
|
|
|
|
|
|
Interned($alloc_method(&self.interners.arena, v))
|
|
|
|
}).0
|
2018-04-30 08:59:23 +02:00
|
|
|
} else {
|
2018-05-17 05:19:08 +02:00
|
|
|
self.global_interners.$name.borrow_mut().intern_ref(key, || {
|
|
|
|
// This transmutes $alloc<'tcx> to $alloc<'gcx>
|
|
|
|
let v = unsafe {
|
|
|
|
mem::transmute(v)
|
|
|
|
};
|
|
|
|
let i: &$lt_tcx $ty = $alloc_method(&self.global_interners.arena, v);
|
|
|
|
// Cast to 'gcx
|
|
|
|
let i = unsafe { mem::transmute(i) };
|
|
|
|
Interned(i)
|
|
|
|
}).0
|
2018-04-30 08:59:23 +02:00
|
|
|
}
|
2016-05-11 04:14:41 +03:00
|
|
|
}
|
2016-09-02 11:08:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! direct_interners {
|
2018-04-04 17:21:50 -04:00
|
|
|
($lt_tcx:tt, $($name:ident: $method:ident($keep_in_local_tcx:expr) -> $ty:ty),+) => {
|
2016-09-02 11:08:16 +03:00
|
|
|
$(impl<$lt_tcx> PartialEq for Interned<$lt_tcx, $ty> {
|
|
|
|
fn eq(&self, other: &Self) -> bool {
|
|
|
|
self.0 == other.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<$lt_tcx> Eq for Interned<$lt_tcx, $ty> {}
|
|
|
|
|
|
|
|
impl<$lt_tcx> Hash for Interned<$lt_tcx, $ty> {
|
|
|
|
fn hash<H: Hasher>(&self, s: &mut H) {
|
|
|
|
self.0.hash(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-04 17:21:50 -04:00
|
|
|
intern_method!(
|
|
|
|
$lt_tcx,
|
2018-05-02 08:02:57 +02:00
|
|
|
$name: $method($ty,
|
|
|
|
|a: &$lt_tcx SyncDroplessArena, v| -> &$lt_tcx $ty { a.alloc(v) },
|
|
|
|
|x| x,
|
|
|
|
$keep_in_local_tcx) -> $ty);)+
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
2016-05-11 04:14:41 +03:00
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2017-08-14 13:23:56 +03:00
|
|
|
pub fn keep_local<'tcx, T: ty::TypeFoldable<'tcx>>(x: &T) -> bool {
|
2016-05-11 04:14:41 +03:00
|
|
|
x.has_type_flags(ty::TypeFlags::KEEP_IN_LOCAL_TCX)
|
|
|
|
}
|
|
|
|
|
2016-09-02 11:08:16 +03:00
|
|
|
direct_interners!('tcx,
|
2018-04-04 18:24:17 -04:00
|
|
|
region: mk_region(|r: &RegionKind| r.keep_in_local_tcx()) -> RegionKind,
|
2019-02-06 11:57:11 +11:00
|
|
|
goal: mk_goal(|c: &GoalKind<'_>| keep_local(c)) -> GoalKind<'tcx>,
|
2019-03-14 10:19:31 +01:00
|
|
|
const_: mk_const(|c: &Const<'_>| keep_local(&c)) -> Const<'tcx>
|
2016-05-11 04:14:41 +03:00
|
|
|
);
|
|
|
|
|
2016-10-16 21:21:25 -06:00
|
|
|
macro_rules! slice_interners {
|
2019-03-28 18:00:17 -07:00
|
|
|
($($field:ident: $method:ident($ty:ty)),+) => (
|
2018-05-02 08:02:57 +02:00
|
|
|
$(intern_method!( 'tcx, $field: $method(
|
2019-03-28 18:00:17 -07:00
|
|
|
&[$ty],
|
2018-08-22 00:35:01 +01:00
|
|
|
|a, v| List::from_arena(a, v),
|
2018-05-02 08:02:57 +02:00
|
|
|
Deref::deref,
|
2019-03-28 18:00:17 -07:00
|
|
|
|xs: &[$ty]| xs.iter().any(keep_local)) -> List<$ty>);)+
|
|
|
|
);
|
2016-10-16 21:21:25 -06:00
|
|
|
}
|
2016-09-02 11:08:16 +03:00
|
|
|
|
2016-10-16 21:21:25 -06:00
|
|
|
slice_interners!(
|
2019-03-28 18:00:17 -07:00
|
|
|
existential_predicates: _intern_existential_predicates(ExistentialPredicate<'tcx>),
|
|
|
|
predicates: _intern_predicates(Predicate<'tcx>),
|
|
|
|
type_list: _intern_type_list(Ty<'tcx>),
|
|
|
|
substs: _intern_substs(Kind<'tcx>),
|
|
|
|
clauses: _intern_clauses(Clause<'tcx>),
|
|
|
|
goal_list: _intern_goals(Goal<'tcx>),
|
2018-10-26 11:28:40 +02:00
|
|
|
projs: _intern_projs(ProjectionKind)
|
2016-10-09 11:36:12 -07:00
|
|
|
);
|
|
|
|
|
2018-02-09 10:39:36 -05:00
|
|
|
// This isn't a perfect fit: CanonicalVarInfo slices are always
|
|
|
|
// allocated in the global arena, so this `intern_method!` macro is
|
|
|
|
// overly general. But we just return false for the code that checks
|
|
|
|
// whether they belong in the thread-local arena, so no harm done, and
|
|
|
|
// seems better than open-coding the rest.
|
|
|
|
intern_method! {
|
|
|
|
'tcx,
|
|
|
|
canonical_var_infos: _intern_canonical_var_infos(
|
|
|
|
&[CanonicalVarInfo],
|
2018-08-22 00:35:01 +01:00
|
|
|
|a, v| List::from_arena(a, v),
|
2018-02-09 10:39:36 -05:00
|
|
|
Deref::deref,
|
|
|
|
|_xs: &[CanonicalVarInfo]| -> bool { false }
|
2018-08-22 00:35:01 +01:00
|
|
|
) -> List<CanonicalVarInfo>
|
2018-02-09 10:39:36 -05:00
|
|
|
}
|
|
|
|
|
2016-05-11 04:14:41 +03:00
|
|
|
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
2017-12-12 14:21:10 -05:00
|
|
|
/// Given a `fn` type, returns an equivalent `unsafe fn` type;
|
|
|
|
/// that is, a `fn` type that is equivalent in every way for being
|
|
|
|
/// unsafe.
|
2017-02-13 10:51:06 +02:00
|
|
|
pub fn safe_to_unsafe_fn_ty(self, sig: PolyFnSig<'tcx>) -> Ty<'tcx> {
|
|
|
|
assert_eq!(sig.unsafety(), hir::Unsafety::Normal);
|
|
|
|
self.mk_fn_ptr(sig.map_bound(|sig| ty::FnSig {
|
2015-09-06 21:51:58 +03:00
|
|
|
unsafety: hir::Unsafety::Unsafe,
|
2017-02-13 10:51:06 +02:00
|
|
|
..sig
|
2016-04-29 08:30:54 +03:00
|
|
|
}))
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2017-12-12 14:21:10 -05:00
|
|
|
/// Given a closure signature `sig`, returns an equivalent `fn`
|
|
|
|
/// type with the same signature. Detuples and so forth -- so
|
2018-11-27 02:59:49 +00:00
|
|
|
/// e.g., if we have a sig with `Fn<(u32, i32)>` then you would get
|
2017-12-12 14:21:10 -05:00
|
|
|
/// a `fn(u32, i32)`.
|
2019-04-01 00:00:43 +09:00
|
|
|
/// `unsafety` determines the unsafety of the `fn` type. If you pass
|
|
|
|
/// `hir::Unsafety::Unsafe` in the previous example, then you would get
|
|
|
|
/// an `unsafe fn (u32, i32)`.
|
|
|
|
/// It cannot convert a closure that requires unsafe.
|
|
|
|
pub fn coerce_closure_fn_ty(self, sig: PolyFnSig<'tcx>, unsafety: hir::Unsafety) -> Ty<'tcx> {
|
2017-11-30 12:22:11 -03:00
|
|
|
let converted_sig = sig.map_bound(|s| {
|
|
|
|
let params_iter = match s.inputs()[0].sty {
|
2018-08-22 01:35:02 +01:00
|
|
|
ty::Tuple(params) => {
|
2019-04-26 00:27:33 +01:00
|
|
|
params.into_iter().map(|k| k.expect_ty())
|
2017-11-30 12:22:11 -03:00
|
|
|
}
|
|
|
|
_ => bug!(),
|
|
|
|
};
|
|
|
|
self.mk_fn_sig(
|
|
|
|
params_iter,
|
|
|
|
s.output(),
|
2019-02-08 17:30:42 +00:00
|
|
|
s.c_variadic,
|
2019-04-01 00:00:43 +09:00
|
|
|
unsafety,
|
2017-12-12 14:21:10 -05:00
|
|
|
abi::Abi::Rust,
|
|
|
|
)
|
2017-11-30 12:22:11 -03:00
|
|
|
});
|
|
|
|
|
|
|
|
self.mk_fn_ptr(converted_sig)
|
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2018-08-22 01:34:12 +01:00
|
|
|
pub fn mk_ty(&self, st: TyKind<'tcx>) -> Ty<'tcx> {
|
2018-04-30 08:59:23 +02:00
|
|
|
CtxtInterners::intern_ty(&self.interners, &self.global_interners, st)
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2016-05-03 04:56:42 +03:00
|
|
|
pub fn mk_mach_int(self, tm: ast::IntTy) -> Ty<'tcx> {
|
2015-09-06 21:51:58 +03:00
|
|
|
match tm {
|
2018-01-04 03:12:04 +02:00
|
|
|
ast::IntTy::Isize => self.types.isize,
|
2016-02-08 16:20:57 +01:00
|
|
|
ast::IntTy::I8 => self.types.i8,
|
|
|
|
ast::IntTy::I16 => self.types.i16,
|
|
|
|
ast::IntTy::I32 => self.types.i32,
|
|
|
|
ast::IntTy::I64 => self.types.i64,
|
2016-08-23 03:56:52 +03:00
|
|
|
ast::IntTy::I128 => self.types.i128,
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-03 04:56:42 +03:00
|
|
|
pub fn mk_mach_uint(self, tm: ast::UintTy) -> Ty<'tcx> {
|
2015-09-06 21:51:58 +03:00
|
|
|
match tm {
|
2018-01-04 03:12:04 +02:00
|
|
|
ast::UintTy::Usize => self.types.usize,
|
2016-02-08 16:20:57 +01:00
|
|
|
ast::UintTy::U8 => self.types.u8,
|
|
|
|
ast::UintTy::U16 => self.types.u16,
|
|
|
|
ast::UintTy::U32 => self.types.u32,
|
|
|
|
ast::UintTy::U64 => self.types.u64,
|
2016-08-23 03:56:52 +03:00
|
|
|
ast::UintTy::U128 => self.types.u128,
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-03 04:56:42 +03:00
|
|
|
pub fn mk_mach_float(self, tm: ast::FloatTy) -> Ty<'tcx> {
|
2015-09-06 21:51:58 +03:00
|
|
|
match tm {
|
2016-02-08 16:09:01 +01:00
|
|
|
ast::FloatTy::F32 => self.types.f32,
|
|
|
|
ast::FloatTy::F64 => self.types.f64,
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2016-05-03 04:56:42 +03:00
|
|
|
pub fn mk_str(self) -> Ty<'tcx> {
|
2018-08-22 01:35:55 +01:00
|
|
|
self.mk_ty(Str)
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2016-05-03 04:56:42 +03:00
|
|
|
pub fn mk_static_str(self) -> Ty<'tcx> {
|
2019-04-25 22:04:51 +01:00
|
|
|
self.mk_imm_ref(self.lifetimes.re_static, self.mk_str())
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2019-02-09 22:11:53 +08:00
|
|
|
pub fn mk_adt(self, def: &'tcx AdtDef, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
|
2015-09-06 21:51:58 +03:00
|
|
|
// take a copy of substs so that we own the vectors inside
|
2018-08-22 01:35:02 +01:00
|
|
|
self.mk_ty(Adt(def, substs))
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2017-09-03 19:53:58 +01:00
|
|
|
pub fn mk_foreign(self, def_id: DefId) -> Ty<'tcx> {
|
2018-08-22 01:35:29 +01:00
|
|
|
self.mk_ty(Foreign(def_id))
|
2017-09-03 19:53:58 +01:00
|
|
|
}
|
|
|
|
|
2016-05-03 04:56:42 +03:00
|
|
|
pub fn mk_box(self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
2017-01-21 17:40:31 +03:00
|
|
|
let def_id = self.require_lang_item(lang_items::OwnedBoxLangItem);
|
2017-04-24 15:20:46 +03:00
|
|
|
let adt_def = self.adt_def(def_id);
|
2019-02-26 09:30:34 +08:00
|
|
|
let substs = InternalSubsts::for_item(self, def_id, |param, substs| {
|
2018-05-14 18:27:13 +01:00
|
|
|
match param.kind {
|
2019-02-20 01:14:56 +00:00
|
|
|
GenericParamDefKind::Lifetime |
|
|
|
|
GenericParamDefKind::Const => {
|
|
|
|
bug!()
|
|
|
|
}
|
2018-05-16 13:03:04 +03:00
|
|
|
GenericParamDefKind::Type { has_default, .. } => {
|
2018-05-14 18:27:13 +01:00
|
|
|
if param.index == 0 {
|
2018-05-15 13:15:49 +01:00
|
|
|
ty.into()
|
2018-05-14 18:27:13 +01:00
|
|
|
} else {
|
2018-05-16 13:03:04 +03:00
|
|
|
assert!(has_default);
|
2018-05-15 13:15:49 +01:00
|
|
|
self.type_of(param.def_id).subst(self, substs).into()
|
2018-05-10 23:02:41 +01:00
|
|
|
}
|
|
|
|
}
|
2018-04-27 23:44:25 +01:00
|
|
|
}
|
2018-05-10 23:02:41 +01:00
|
|
|
});
|
2018-08-22 01:35:02 +01:00
|
|
|
self.mk_ty(Adt(adt_def, substs))
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2016-05-03 04:56:42 +03:00
|
|
|
pub fn mk_ptr(self, tm: TypeAndMut<'tcx>) -> Ty<'tcx> {
|
2018-08-22 01:35:02 +01:00
|
|
|
self.mk_ty(RawPtr(tm))
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2017-04-20 04:45:53 -04:00
|
|
|
pub fn mk_ref(self, r: Region<'tcx>, tm: TypeAndMut<'tcx>) -> Ty<'tcx> {
|
2018-08-22 01:35:02 +01:00
|
|
|
self.mk_ty(Ref(r, tm.ty, tm.mutbl))
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2017-04-20 04:45:53 -04:00
|
|
|
pub fn mk_mut_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
|
2015-09-06 21:51:58 +03:00
|
|
|
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::MutMutable})
|
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2017-04-20 04:45:53 -04:00
|
|
|
pub fn mk_imm_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
|
2015-09-06 21:51:58 +03:00
|
|
|
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::MutImmutable})
|
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2016-05-03 04:56:42 +03:00
|
|
|
pub fn mk_mut_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
2015-09-06 21:51:58 +03:00
|
|
|
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::MutMutable})
|
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2016-05-03 04:56:42 +03:00
|
|
|
pub fn mk_imm_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
2015-09-06 21:51:58 +03:00
|
|
|
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::MutImmutable})
|
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2018-09-11 22:17:43 +09:00
|
|
|
pub fn mk_nil_ptr(self) -> Ty<'tcx> {
|
2018-09-10 11:07:13 +09:00
|
|
|
self.mk_imm_ptr(self.mk_unit())
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2017-08-05 12:27:28 +03:00
|
|
|
pub fn mk_array(self, ty: Ty<'tcx>, n: u64) -> Ty<'tcx> {
|
2019-04-03 15:29:31 +02:00
|
|
|
self.mk_ty(Array(ty, ty::Const::from_usize(self.global_tcx(), n)))
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2016-05-03 04:56:42 +03:00
|
|
|
pub fn mk_slice(self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
2018-08-22 01:35:02 +01:00
|
|
|
self.mk_ty(Slice(ty))
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2018-01-21 13:33:21 +08:00
|
|
|
pub fn intern_tup(self, ts: &[Ty<'tcx>]) -> Ty<'tcx> {
|
2019-04-26 00:27:33 +01:00
|
|
|
let kinds: Vec<_> = ts.into_iter().map(|&t| Kind::from(t)).collect();
|
|
|
|
self.mk_ty(Tuple(self.intern_substs(&kinds)))
|
2016-10-24 18:23:29 -06:00
|
|
|
}
|
|
|
|
|
2018-01-21 13:33:21 +08:00
|
|
|
pub fn mk_tup<I: InternAs<[Ty<'tcx>], Ty<'tcx>>>(self, iter: I) -> I::Output {
|
2019-04-26 00:27:33 +01:00
|
|
|
iter.intern_with(|ts| {
|
|
|
|
let kinds: Vec<_> = ts.into_iter().map(|&t| Kind::from(t)).collect();
|
|
|
|
self.mk_ty(Tuple(self.intern_substs(&kinds)))
|
|
|
|
})
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2018-09-10 11:07:13 +09:00
|
|
|
pub fn mk_unit(self) -> Ty<'tcx> {
|
2018-11-29 21:13:04 +01:00
|
|
|
self.types.unit
|
2016-08-02 19:56:33 +08:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2018-04-20 17:11:28 +02:00
|
|
|
pub fn mk_diverging_default(self) -> Ty<'tcx> {
|
|
|
|
if self.features().never_type {
|
|
|
|
self.types.never
|
|
|
|
} else {
|
|
|
|
self.intern_tup(&[])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2016-05-03 04:56:42 +03:00
|
|
|
pub fn mk_bool(self) -> Ty<'tcx> {
|
2018-08-22 01:35:55 +01:00
|
|
|
self.mk_ty(Bool)
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2016-05-03 04:56:42 +03:00
|
|
|
pub fn mk_fn_def(self, def_id: DefId,
|
2019-02-09 22:11:53 +08:00
|
|
|
substs: SubstsRef<'tcx>) -> Ty<'tcx> {
|
2018-08-22 01:35:02 +01:00
|
|
|
self.mk_ty(FnDef(def_id, substs))
|
2015-06-13 13:15:03 -07:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2017-02-13 10:51:06 +02:00
|
|
|
pub fn mk_fn_ptr(self, fty: PolyFnSig<'tcx>) -> Ty<'tcx> {
|
2018-08-22 01:35:02 +01:00
|
|
|
self.mk_ty(FnPtr(fty))
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2016-11-16 09:21:49 -07:00
|
|
|
pub fn mk_dynamic(
|
|
|
|
self,
|
2018-08-22 00:35:01 +01:00
|
|
|
obj: ty::Binder<&'tcx List<ExistentialPredicate<'tcx>>>,
|
2017-04-20 04:45:53 -04:00
|
|
|
reg: ty::Region<'tcx>
|
2016-11-16 09:21:49 -07:00
|
|
|
) -> Ty<'tcx> {
|
2018-08-22 01:35:02 +01:00
|
|
|
self.mk_ty(Dynamic(obj, reg))
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2016-05-03 04:56:42 +03:00
|
|
|
pub fn mk_projection(self,
|
2017-07-11 10:33:09 -04:00
|
|
|
item_def_id: DefId,
|
2019-02-09 22:11:53 +08:00
|
|
|
substs: SubstsRef<'tcx>)
|
2016-11-16 09:21:49 -07:00
|
|
|
-> Ty<'tcx> {
|
2018-08-22 01:35:02 +01:00
|
|
|
self.mk_ty(Projection(ProjectionTy {
|
2017-08-06 22:54:09 -07:00
|
|
|
item_def_id,
|
|
|
|
substs,
|
2017-07-11 10:33:09 -04:00
|
|
|
}))
|
2016-11-16 09:21:49 -07:00
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2018-05-02 13:14:30 +02:00
|
|
|
pub fn mk_closure(self, closure_id: DefId, closure_substs: ClosureSubsts<'tcx>)
|
2018-10-01 15:26:53 +02:00
|
|
|
-> Ty<'tcx> {
|
2018-08-22 01:35:02 +01:00
|
|
|
self.mk_ty(Closure(closure_id, closure_substs))
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2017-07-05 14:57:26 -07:00
|
|
|
pub fn mk_generator(self,
|
2016-12-26 14:34:03 +01:00
|
|
|
id: DefId,
|
2018-05-02 13:14:30 +02:00
|
|
|
generator_substs: GeneratorSubsts<'tcx>,
|
2018-05-02 10:17:12 +02:00
|
|
|
movability: hir::GeneratorMovability)
|
2016-12-26 14:34:03 +01:00
|
|
|
-> Ty<'tcx> {
|
2018-08-22 01:35:02 +01:00
|
|
|
self.mk_ty(Generator(id, generator_substs, movability))
|
2016-12-26 14:34:03 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2018-08-22 00:35:01 +01:00
|
|
|
pub fn mk_generator_witness(self, types: ty::Binder<&'tcx List<Ty<'tcx>>>) -> Ty<'tcx> {
|
2018-08-22 01:35:02 +01:00
|
|
|
self.mk_ty(GeneratorWitness(types))
|
2017-10-07 16:36:28 +02:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2019-02-20 01:14:56 +00:00
|
|
|
pub fn mk_ty_var(self, v: TyVid) -> Ty<'tcx> {
|
2019-02-28 23:02:32 -05:00
|
|
|
self.mk_ty_infer(TyVar(v))
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2019-02-20 01:14:56 +00:00
|
|
|
#[inline]
|
2019-03-14 10:19:31 +01:00
|
|
|
pub fn mk_const_var(self, v: ConstVid<'tcx>, ty: Ty<'tcx>) -> &'tcx Const<'tcx> {
|
|
|
|
self.mk_const(ty::Const {
|
2019-02-20 01:14:56 +00:00
|
|
|
val: ConstValue::Infer(InferConst::Var(v)),
|
|
|
|
ty,
|
2019-03-14 10:19:31 +01:00
|
|
|
})
|
2019-02-20 01:14:56 +00:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2016-05-03 04:56:42 +03:00
|
|
|
pub fn mk_int_var(self, v: IntVid) -> Ty<'tcx> {
|
2019-02-28 23:02:32 -05:00
|
|
|
self.mk_ty_infer(IntVar(v))
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2016-05-03 04:56:42 +03:00
|
|
|
pub fn mk_float_var(self, v: FloatVid) -> Ty<'tcx> {
|
2019-02-28 23:02:32 -05:00
|
|
|
self.mk_ty_infer(FloatVar(v))
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2019-02-28 23:02:32 -05:00
|
|
|
pub fn mk_ty_infer(self, it: InferTy) -> Ty<'tcx> {
|
2018-08-22 01:35:02 +01:00
|
|
|
self.mk_ty(Infer(it))
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2019-02-28 23:03:37 -05:00
|
|
|
#[inline]
|
|
|
|
pub fn mk_const_infer(
|
|
|
|
self,
|
|
|
|
ic: InferConst<'tcx>,
|
|
|
|
ty: Ty<'tcx>,
|
2019-03-18 20:55:19 +00:00
|
|
|
) -> &'tcx ty::Const<'tcx> {
|
|
|
|
self.mk_const(ty::Const {
|
2019-02-28 23:03:37 -05:00
|
|
|
val: ConstValue::Infer(ic),
|
|
|
|
ty,
|
2019-03-18 20:55:19 +00:00
|
|
|
})
|
2019-02-28 23:03:37 -05:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2019-05-06 13:12:04 +01:00
|
|
|
pub fn mk_ty_param(self, index: u32, name: InternedString) -> Ty<'tcx> {
|
|
|
|
self.mk_ty(Param(ParamTy { index, name: name }))
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2019-02-20 01:14:56 +00:00
|
|
|
#[inline]
|
|
|
|
pub fn mk_const_param(
|
|
|
|
self,
|
|
|
|
index: u32,
|
|
|
|
name: InternedString,
|
|
|
|
ty: Ty<'tcx>
|
2019-03-14 10:19:31 +01:00
|
|
|
) -> &'tcx Const<'tcx> {
|
|
|
|
self.mk_const(ty::Const {
|
2019-02-20 01:14:56 +00:00
|
|
|
val: ConstValue::Param(ParamConst { index, name }),
|
|
|
|
ty,
|
2019-03-14 10:19:31 +01:00
|
|
|
})
|
2019-02-20 01:14:56 +00:00
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2016-05-03 04:56:42 +03:00
|
|
|
pub fn mk_self_type(self) -> Ty<'tcx> {
|
2019-05-11 17:41:37 +03:00
|
|
|
self.mk_ty_param(0, kw::SelfUpper.as_interned_str())
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-05-15 13:35:53 +01:00
|
|
|
pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> Kind<'tcx> {
|
|
|
|
match param.kind {
|
|
|
|
GenericParamDefKind::Lifetime => {
|
|
|
|
self.mk_region(ty::ReEarlyBound(param.to_early_bound_region_data())).into()
|
|
|
|
}
|
2019-02-20 01:14:56 +00:00
|
|
|
GenericParamDefKind::Type { .. } => self.mk_ty_param(param.index, param.name).into(),
|
|
|
|
GenericParamDefKind::Const => {
|
|
|
|
self.mk_const_param(param.index, param.name, self.type_of(param.def_id)).into()
|
|
|
|
}
|
2018-05-15 13:35:53 +01:00
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
2015-12-22 16:39:33 -05:00
|
|
|
|
2018-11-29 21:13:04 +01:00
|
|
|
#[inline]
|
2019-02-09 22:11:53 +08:00
|
|
|
pub fn mk_opaque(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
|
2018-08-23 13:51:32 -06:00
|
|
|
self.mk_ty(Opaque(def_id, substs))
|
2016-07-22 18:56:22 +03:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:21:49 -07:00
|
|
|
pub fn intern_existential_predicates(self, eps: &[ExistentialPredicate<'tcx>])
|
2018-08-22 00:35:01 +01:00
|
|
|
-> &'tcx List<ExistentialPredicate<'tcx>> {
|
2016-11-16 09:21:49 -07:00
|
|
|
assert!(!eps.is_empty());
|
2018-06-09 15:09:07 -07:00
|
|
|
assert!(eps.windows(2).all(|w| w[0].stable_cmp(self, &w[1]) != Ordering::Greater));
|
2016-11-16 09:21:49 -07:00
|
|
|
self._intern_existential_predicates(eps)
|
|
|
|
}
|
|
|
|
|
2017-05-02 14:37:00 -04:00
|
|
|
pub fn intern_predicates(self, preds: &[Predicate<'tcx>])
|
2018-08-22 00:35:01 +01:00
|
|
|
-> &'tcx List<Predicate<'tcx>> {
|
2017-05-02 14:37:00 -04:00
|
|
|
// FIXME consider asking the input slice to be sorted to avoid
|
|
|
|
// re-interning permutations, in which case that would be asserted
|
|
|
|
// here.
|
|
|
|
if preds.len() == 0 {
|
|
|
|
// The macro-generated method below asserts we don't intern an empty slice.
|
2018-08-22 00:35:01 +01:00
|
|
|
List::empty()
|
2017-05-02 14:37:00 -04:00
|
|
|
} else {
|
|
|
|
self._intern_predicates(preds)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-22 00:35:01 +01:00
|
|
|
pub fn intern_type_list(self, ts: &[Ty<'tcx>]) -> &'tcx List<Ty<'tcx>> {
|
2016-10-24 18:23:29 -06:00
|
|
|
if ts.len() == 0 {
|
2018-08-22 00:35:01 +01:00
|
|
|
List::empty()
|
2016-10-24 18:23:29 -06:00
|
|
|
} else {
|
|
|
|
self._intern_type_list(ts)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-22 00:35:01 +01:00
|
|
|
pub fn intern_substs(self, ts: &[Kind<'tcx>]) -> &'tcx List<Kind<'tcx>> {
|
2016-10-24 18:23:29 -06:00
|
|
|
if ts.len() == 0 {
|
2018-08-22 00:35:01 +01:00
|
|
|
List::empty()
|
2016-10-24 18:23:29 -06:00
|
|
|
} else {
|
|
|
|
self._intern_substs(ts)
|
2018-02-09 10:39:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-28 18:00:17 -07:00
|
|
|
pub fn intern_projs(self, ps: &[ProjectionKind]) -> &'tcx List<ProjectionKind> {
|
2018-10-26 11:28:40 +02:00
|
|
|
if ps.len() == 0 {
|
|
|
|
List::empty()
|
|
|
|
} else {
|
|
|
|
self._intern_projs(ps)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-09 10:39:36 -05:00
|
|
|
pub fn intern_canonical_var_infos(self, ts: &[CanonicalVarInfo]) -> CanonicalVarInfos<'gcx> {
|
|
|
|
if ts.len() == 0 {
|
2018-08-22 00:35:01 +01:00
|
|
|
List::empty()
|
2018-02-09 10:39:36 -05:00
|
|
|
} else {
|
|
|
|
self.global_tcx()._intern_canonical_var_infos(ts)
|
2016-10-24 18:23:29 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-23 13:12:00 -04:00
|
|
|
pub fn intern_clauses(self, ts: &[Clause<'tcx>]) -> Clauses<'tcx> {
|
2018-04-09 16:38:00 +09:00
|
|
|
if ts.len() == 0 {
|
2018-08-22 00:35:01 +01:00
|
|
|
List::empty()
|
2018-04-09 16:38:00 +09:00
|
|
|
} else {
|
|
|
|
self._intern_clauses(ts)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-23 13:12:00 -04:00
|
|
|
pub fn intern_goals(self, ts: &[Goal<'tcx>]) -> Goals<'tcx> {
|
2018-04-09 16:38:00 +09:00
|
|
|
if ts.len() == 0 {
|
2018-08-22 00:35:01 +01:00
|
|
|
List::empty()
|
2018-04-09 16:38:00 +09:00
|
|
|
} else {
|
|
|
|
self._intern_goals(ts)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-13 10:51:06 +02:00
|
|
|
pub fn mk_fn_sig<I>(self,
|
|
|
|
inputs: I,
|
|
|
|
output: I::Item,
|
2019-02-08 17:30:42 +00:00
|
|
|
c_variadic: bool,
|
2017-02-13 10:51:06 +02:00
|
|
|
unsafety: hir::Unsafety,
|
|
|
|
abi: abi::Abi)
|
2016-11-28 20:25:33 -07:00
|
|
|
-> <I::Item as InternIteratorElement<Ty<'tcx>, ty::FnSig<'tcx>>>::Output
|
|
|
|
where I: Iterator,
|
|
|
|
I::Item: InternIteratorElement<Ty<'tcx>, ty::FnSig<'tcx>>
|
|
|
|
{
|
|
|
|
inputs.chain(iter::once(output)).intern_with(|xs| ty::FnSig {
|
|
|
|
inputs_and_output: self.intern_type_list(xs),
|
2019-02-08 17:30:42 +00:00
|
|
|
c_variadic, unsafety, abi
|
2016-11-28 20:25:33 -07:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-11-16 09:21:49 -07:00
|
|
|
pub fn mk_existential_predicates<I: InternAs<[ExistentialPredicate<'tcx>],
|
2018-08-22 00:35:01 +01:00
|
|
|
&'tcx List<ExistentialPredicate<'tcx>>>>(self, iter: I)
|
2016-11-16 09:21:49 -07:00
|
|
|
-> I::Output {
|
|
|
|
iter.intern_with(|xs| self.intern_existential_predicates(xs))
|
|
|
|
}
|
|
|
|
|
2017-05-02 14:37:00 -04:00
|
|
|
pub fn mk_predicates<I: InternAs<[Predicate<'tcx>],
|
2018-08-22 00:35:01 +01:00
|
|
|
&'tcx List<Predicate<'tcx>>>>(self, iter: I)
|
2017-05-02 14:37:00 -04:00
|
|
|
-> I::Output {
|
|
|
|
iter.intern_with(|xs| self.intern_predicates(xs))
|
|
|
|
}
|
|
|
|
|
2016-10-24 18:23:29 -06:00
|
|
|
pub fn mk_type_list<I: InternAs<[Ty<'tcx>],
|
2018-08-22 00:35:01 +01:00
|
|
|
&'tcx List<Ty<'tcx>>>>(self, iter: I) -> I::Output {
|
2016-10-24 18:23:29 -06:00
|
|
|
iter.intern_with(|xs| self.intern_type_list(xs))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn mk_substs<I: InternAs<[Kind<'tcx>],
|
2018-08-22 00:35:01 +01:00
|
|
|
&'tcx List<Kind<'tcx>>>>(self, iter: I) -> I::Output {
|
2016-10-24 18:23:29 -06:00
|
|
|
iter.intern_with(|xs| self.intern_substs(xs))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn mk_substs_trait(self,
|
2018-05-16 09:34:09 +03:00
|
|
|
self_ty: Ty<'tcx>,
|
|
|
|
rest: &[Kind<'tcx>])
|
2019-02-09 22:11:53 +08:00
|
|
|
-> SubstsRef<'tcx>
|
2016-10-24 18:23:29 -06:00
|
|
|
{
|
2018-05-16 09:34:09 +03:00
|
|
|
self.mk_substs(iter::once(self_ty.into()).chain(rest.iter().cloned()))
|
2016-10-24 18:23:29 -06:00
|
|
|
}
|
2017-07-26 21:51:09 -07:00
|
|
|
|
2018-04-23 13:12:00 -04:00
|
|
|
pub fn mk_clauses<I: InternAs<[Clause<'tcx>], Clauses<'tcx>>>(self, iter: I) -> I::Output {
|
2018-04-09 16:38:00 +09:00
|
|
|
iter.intern_with(|xs| self.intern_clauses(xs))
|
|
|
|
}
|
|
|
|
|
2018-04-23 13:12:00 -04:00
|
|
|
pub fn mk_goals<I: InternAs<[Goal<'tcx>], Goals<'tcx>>>(self, iter: I) -> I::Output {
|
2018-04-09 16:38:00 +09:00
|
|
|
iter.intern_with(|xs| self.intern_goals(xs))
|
|
|
|
}
|
|
|
|
|
2018-05-20 20:19:34 -07:00
|
|
|
pub fn lint_hir<S: Into<MultiSpan>>(self,
|
|
|
|
lint: &'static Lint,
|
|
|
|
hir_id: HirId,
|
|
|
|
span: S,
|
|
|
|
msg: &str) {
|
|
|
|
self.struct_span_lint_hir(lint, hir_id, span.into(), msg).emit()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn lint_hir_note<S: Into<MultiSpan>>(self,
|
2018-11-27 02:59:49 +00:00
|
|
|
lint: &'static Lint,
|
|
|
|
hir_id: HirId,
|
|
|
|
span: S,
|
|
|
|
msg: &str,
|
|
|
|
note: &str) {
|
2018-05-20 20:19:34 -07:00
|
|
|
let mut err = self.struct_span_lint_hir(lint, hir_id, span.into(), msg);
|
|
|
|
err.note(note);
|
|
|
|
err.emit()
|
|
|
|
}
|
|
|
|
|
2017-08-13 20:07:09 +02:00
|
|
|
pub fn lint_node_note<S: Into<MultiSpan>>(self,
|
|
|
|
lint: &'static Lint,
|
2019-02-22 15:48:14 +01:00
|
|
|
id: hir::HirId,
|
2017-08-13 20:07:09 +02:00
|
|
|
span: S,
|
|
|
|
msg: &str,
|
|
|
|
note: &str) {
|
2019-02-22 15:48:14 +01:00
|
|
|
let mut err = self.struct_span_lint_hir(lint, id, span.into(), msg);
|
2017-08-13 20:07:09 +02:00
|
|
|
err.note(note);
|
|
|
|
err.emit()
|
|
|
|
}
|
|
|
|
|
2019-01-31 23:11:29 +01:00
|
|
|
/// Walks upwards from `id` to find a node which might change lint levels with attributes.
|
|
|
|
/// It stops at `bound` and just returns it if reached.
|
|
|
|
pub fn maybe_lint_level_root_bounded(
|
|
|
|
self,
|
|
|
|
mut id: hir::HirId,
|
|
|
|
bound: hir::HirId,
|
|
|
|
) -> hir::HirId {
|
|
|
|
loop {
|
|
|
|
if id == bound {
|
|
|
|
return bound;
|
2017-07-26 21:51:09 -07:00
|
|
|
}
|
2019-01-31 23:11:29 +01:00
|
|
|
if lint::maybe_lint_level_root(self, id) {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
let next = self.hir().get_parent_node_by_hir_id(id);
|
|
|
|
if next == id {
|
|
|
|
bug!("lint traversal reached the root of the crate");
|
|
|
|
}
|
|
|
|
id = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn lint_level_at_node(
|
|
|
|
self,
|
|
|
|
lint: &'static Lint,
|
|
|
|
mut id: hir::HirId
|
|
|
|
) -> (lint::Level, lint::LintSource) {
|
|
|
|
let sets = self.lint_levels(LOCAL_CRATE);
|
|
|
|
loop {
|
|
|
|
if let Some(pair) = sets.level_and_source(lint, id, self.sess) {
|
|
|
|
return pair
|
|
|
|
}
|
|
|
|
let next = self.hir().get_parent_node_by_hir_id(id);
|
|
|
|
if next == id {
|
|
|
|
bug!("lint traversal reached the root of the crate");
|
|
|
|
}
|
|
|
|
id = next;
|
|
|
|
}
|
2017-07-26 21:51:09 -07:00
|
|
|
}
|
|
|
|
|
2018-05-20 20:19:34 -07:00
|
|
|
pub fn struct_span_lint_hir<S: Into<MultiSpan>>(self,
|
|
|
|
lint: &'static Lint,
|
|
|
|
hir_id: HirId,
|
|
|
|
span: S,
|
|
|
|
msg: &str)
|
|
|
|
-> DiagnosticBuilder<'tcx>
|
|
|
|
{
|
2019-02-26 11:48:34 +01:00
|
|
|
let (level, src) = self.lint_level_at_node(lint, hir_id);
|
2017-07-26 21:51:09 -07:00
|
|
|
lint::struct_lint_level(self.sess, lint, level, src, Some(span.into()), msg)
|
|
|
|
}
|
|
|
|
|
2019-02-26 11:48:34 +01:00
|
|
|
pub fn struct_lint_node(self, lint: &'static Lint, id: HirId, msg: &str)
|
2017-07-26 21:51:09 -07:00
|
|
|
-> DiagnosticBuilder<'tcx>
|
|
|
|
{
|
|
|
|
let (level, src) = self.lint_level_at_node(lint, id);
|
|
|
|
lint::struct_lint_level(self.sess, lint, level, src, None, msg)
|
|
|
|
}
|
2017-09-08 13:51:57 -07:00
|
|
|
|
2018-12-01 16:17:59 +01:00
|
|
|
pub fn in_scope_traits(self, id: HirId) -> Option<&'gcx StableVec<TraitCandidate>> {
|
2017-09-08 13:51:57 -07:00
|
|
|
self.in_scope_traits_map(id.owner)
|
2018-12-01 16:17:59 +01:00
|
|
|
.and_then(|map| map.get(&id.local_id))
|
2017-09-08 13:51:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn named_region(self, id: HirId) -> Option<resolve_lifetime::Region> {
|
|
|
|
self.named_region_map(id.owner)
|
|
|
|
.and_then(|map| map.get(&id.local_id).cloned())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_late_bound(self, id: HirId) -> bool {
|
|
|
|
self.is_late_bound_map(id.owner)
|
|
|
|
.map(|set| set.contains(&id.local_id))
|
|
|
|
.unwrap_or(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn object_lifetime_defaults(self, id: HirId)
|
2018-11-30 22:26:57 +01:00
|
|
|
-> Option<&'gcx [ObjectLifetimeDefault]>
|
2017-09-08 13:51:57 -07:00
|
|
|
{
|
|
|
|
self.object_lifetime_defaults_map(id.owner)
|
2018-11-30 22:26:57 +01:00
|
|
|
.and_then(|map| map.get(&id.local_id).map(|v| &**v))
|
2017-09-08 13:51:57 -07:00
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
2016-10-24 18:23:29 -06:00
|
|
|
|
|
|
|
pub trait InternAs<T: ?Sized, R> {
|
|
|
|
type Output;
|
2017-05-02 05:55:20 +02:00
|
|
|
fn intern_with<F>(self, f: F) -> Self::Output
|
2016-10-24 18:23:29 -06:00
|
|
|
where F: FnOnce(&T) -> R;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<I, T, R, E> InternAs<[T], R> for I
|
|
|
|
where E: InternIteratorElement<T, R>,
|
|
|
|
I: Iterator<Item=E> {
|
|
|
|
type Output = E::Output;
|
|
|
|
fn intern_with<F>(self, f: F) -> Self::Output
|
|
|
|
where F: FnOnce(&[T]) -> R {
|
|
|
|
E::intern_with(self, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait InternIteratorElement<T, R>: Sized {
|
|
|
|
type Output;
|
|
|
|
fn intern_with<I: Iterator<Item=Self>, F: FnOnce(&[T]) -> R>(iter: I, f: F) -> Self::Output;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T, R> InternIteratorElement<T, R> for T {
|
|
|
|
type Output = R;
|
|
|
|
fn intern_with<I: Iterator<Item=Self>, F: FnOnce(&[T]) -> R>(iter: I, f: F) -> Self::Output {
|
2018-08-24 13:51:32 +10:00
|
|
|
f(&iter.collect::<SmallVec<[_; 8]>>())
|
2016-10-24 18:23:29 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-08 01:41:26 +02:00
|
|
|
impl<'a, T, R> InternIteratorElement<T, R> for &'a T
|
|
|
|
where T: Clone + 'a
|
|
|
|
{
|
|
|
|
type Output = R;
|
|
|
|
fn intern_with<I: Iterator<Item=Self>, F: FnOnce(&[T]) -> R>(iter: I, f: F) -> Self::Output {
|
2018-08-24 13:51:32 +10:00
|
|
|
f(&iter.cloned().collect::<SmallVec<[_; 8]>>())
|
2017-03-08 01:41:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-24 18:23:29 -06:00
|
|
|
impl<T, R, E> InternIteratorElement<T, R> for Result<T, E> {
|
|
|
|
type Output = Result<R, E>;
|
|
|
|
fn intern_with<I: Iterator<Item=Self>, F: FnOnce(&[T]) -> R>(iter: I, f: F) -> Self::Output {
|
2018-08-24 13:51:32 +10:00
|
|
|
Ok(f(&iter.collect::<Result<SmallVec<[_; 8]>, _>>()?))
|
2016-10-24 18:23:29 -06:00
|
|
|
}
|
|
|
|
}
|
2017-08-29 11:10:22 -07:00
|
|
|
|
2019-02-23 14:25:03 +00:00
|
|
|
// We are comparing types with different invariant lifetimes, so `ptr::eq`
|
|
|
|
// won't work for us.
|
|
|
|
fn ptr_eq<T, U>(t: *const T, u: *const U) -> bool {
|
|
|
|
t as *const () == u as *const ()
|
|
|
|
}
|
|
|
|
|
2018-08-29 22:02:42 -07:00
|
|
|
pub fn provide(providers: &mut ty::query::Providers<'_>) {
|
2018-12-01 16:17:59 +01:00
|
|
|
providers.in_scope_traits_map = |tcx, id| tcx.gcx.trait_map.get(&id);
|
2018-12-01 16:23:32 +01:00
|
|
|
providers.module_exports = |tcx, id| tcx.gcx.export_map.get(&id).map(|v| &v[..]);
|
2017-08-31 08:07:39 -07:00
|
|
|
providers.crate_name = |tcx, id| {
|
|
|
|
assert_eq!(id, LOCAL_CRATE);
|
|
|
|
tcx.crate_name
|
|
|
|
};
|
2018-07-23 01:20:33 +01:00
|
|
|
providers.get_lib_features = |tcx, id| {
|
|
|
|
assert_eq!(id, LOCAL_CRATE);
|
2018-12-01 16:57:29 +01:00
|
|
|
tcx.arena.alloc(middle::lib_features::collect(tcx))
|
2018-07-23 01:20:33 +01:00
|
|
|
};
|
2017-08-31 08:57:41 -07:00
|
|
|
providers.get_lang_items = |tcx, id| {
|
|
|
|
assert_eq!(id, LOCAL_CRATE);
|
2018-12-01 16:57:29 +01:00
|
|
|
tcx.arena.alloc(middle::lang_items::collect(tcx))
|
2017-08-31 08:57:41 -07:00
|
|
|
};
|
2018-12-01 16:23:32 +01:00
|
|
|
providers.upvars = |tcx, id| tcx.gcx.upvars.get(&id).map(|v| &v[..]);
|
2017-08-31 13:19:33 -07:00
|
|
|
providers.maybe_unused_trait_import = |tcx, id| {
|
|
|
|
tcx.maybe_unused_trait_imports.contains(&id)
|
|
|
|
};
|
|
|
|
providers.maybe_unused_extern_crates = |tcx, cnum| {
|
|
|
|
assert_eq!(cnum, LOCAL_CRATE);
|
2018-12-01 16:57:29 +01:00
|
|
|
&tcx.maybe_unused_extern_crates[..]
|
2017-08-31 13:19:33 -07:00
|
|
|
};
|
2019-01-07 11:46:44 +01:00
|
|
|
providers.names_imported_by_glob_use = |tcx, id| {
|
|
|
|
assert_eq!(id.krate, LOCAL_CRATE);
|
|
|
|
Lrc::new(tcx.glob_map.get(&id).cloned().unwrap_or_default())
|
|
|
|
};
|
2017-08-31 15:08:34 -07:00
|
|
|
|
|
|
|
providers.stability_index = |tcx, cnum| {
|
|
|
|
assert_eq!(cnum, LOCAL_CRATE);
|
2018-11-30 22:45:46 +01:00
|
|
|
tcx.arena.alloc(stability::Index::new(tcx))
|
2017-08-31 15:08:34 -07:00
|
|
|
};
|
|
|
|
providers.lookup_stability = |tcx, id| {
|
|
|
|
assert_eq!(id.krate, LOCAL_CRATE);
|
2018-12-04 13:45:36 +01:00
|
|
|
let id = tcx.hir().definitions().def_index_to_hir_id(id.index);
|
2017-08-31 15:08:34 -07:00
|
|
|
tcx.stability().local_stability(id)
|
|
|
|
};
|
|
|
|
providers.lookup_deprecation_entry = |tcx, id| {
|
|
|
|
assert_eq!(id.krate, LOCAL_CRATE);
|
2018-12-04 13:45:36 +01:00
|
|
|
let id = tcx.hir().definitions().def_index_to_hir_id(id.index);
|
2017-08-31 15:08:34 -07:00
|
|
|
tcx.stability().local_deprecation_entry(id)
|
|
|
|
};
|
2017-09-07 13:21:46 -07:00
|
|
|
providers.extern_mod_stmt_cnum = |tcx, id| {
|
2018-12-04 13:45:36 +01:00
|
|
|
let id = tcx.hir().as_local_node_id(id).unwrap();
|
2017-09-07 13:21:46 -07:00
|
|
|
tcx.cstore.extern_mod_stmt_cnum_untracked(id)
|
|
|
|
};
|
|
|
|
providers.all_crate_nums = |tcx, cnum| {
|
|
|
|
assert_eq!(cnum, LOCAL_CRATE);
|
2018-11-30 22:45:46 +01:00
|
|
|
tcx.arena.alloc_slice(&tcx.cstore.crates_untracked())
|
2017-09-07 13:21:46 -07:00
|
|
|
};
|
|
|
|
providers.postorder_cnums = |tcx, cnum| {
|
|
|
|
assert_eq!(cnum, LOCAL_CRATE);
|
2018-12-01 16:57:29 +01:00
|
|
|
tcx.arena.alloc_slice(&tcx.cstore.postorder_cnums_untracked())
|
2017-09-07 13:21:46 -07:00
|
|
|
};
|
2017-09-13 20:26:39 -07:00
|
|
|
providers.output_filenames = |tcx, cnum| {
|
|
|
|
assert_eq!(cnum, LOCAL_CRATE);
|
|
|
|
tcx.output_filenames.clone()
|
|
|
|
};
|
2018-02-14 16:11:02 +01:00
|
|
|
providers.features_query = |tcx, cnum| {
|
|
|
|
assert_eq!(cnum, LOCAL_CRATE);
|
2018-11-30 22:45:46 +01:00
|
|
|
tcx.arena.alloc(tcx.sess.features_untracked().clone())
|
2018-02-14 16:11:02 +01:00
|
|
|
};
|
2018-02-27 19:28:21 +01:00
|
|
|
providers.is_panic_runtime = |tcx, cnum| {
|
|
|
|
assert_eq!(cnum, LOCAL_CRATE);
|
2019-05-08 13:21:18 +10:00
|
|
|
attr::contains_name(tcx.hir().krate_attrs(), sym::panic_runtime)
|
2018-02-27 19:28:21 +01:00
|
|
|
};
|
|
|
|
providers.is_compiler_builtins = |tcx, cnum| {
|
|
|
|
assert_eq!(cnum, LOCAL_CRATE);
|
2019-05-08 13:21:18 +10:00
|
|
|
attr::contains_name(tcx.hir().krate_attrs(), sym::compiler_builtins)
|
2018-02-27 19:28:21 +01:00
|
|
|
};
|
2017-08-29 11:10:22 -07:00
|
|
|
}
|