Rebase and use ena 0.14
This commit is contained in:
parent
fba241fc66
commit
b61a28b2a1
@ -223,7 +223,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
|
||||
&self.region_obligations
|
||||
}
|
||||
|
||||
pub(crate) fn projection_cache(&mut self) -> traits::ProjectionCache<'tcx, '_> {
|
||||
pub fn projection_cache(&mut self) -> traits::ProjectionCache<'tcx, '_> {
|
||||
self.projection_cache.with_log(&mut self.undo_log)
|
||||
}
|
||||
|
||||
@ -1308,19 +1308,21 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
outlives_env: &OutlivesEnvironment<'tcx>,
|
||||
mode: RegionckMode,
|
||||
) {
|
||||
let (var_infos, data) = {
|
||||
let mut inner = self.inner.borrow_mut();
|
||||
let inner = &mut *inner;
|
||||
assert!(
|
||||
self.is_tainted_by_errors() || self.inner.borrow().region_obligations.is_empty(),
|
||||
self.is_tainted_by_errors() || inner.region_obligations.is_empty(),
|
||||
"region_obligations not empty: {:#?}",
|
||||
self.inner.borrow().region_obligations
|
||||
inner.region_obligations
|
||||
);
|
||||
let (var_infos, data) = self
|
||||
.inner
|
||||
.borrow_mut()
|
||||
inner
|
||||
.region_constraints
|
||||
.take()
|
||||
.expect("regions already resolved")
|
||||
.with_log(&mut inner.undo_log)
|
||||
.into_infos_and_data();
|
||||
.into_infos_and_data()
|
||||
};
|
||||
|
||||
let region_rels = &RegionRelations::new(
|
||||
self.tcx,
|
||||
@ -1686,13 +1688,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
/// having to resort to storing full `GenericArg`s in `stalled_on`.
|
||||
#[inline(always)]
|
||||
pub fn ty_or_const_infer_var_changed(&self, infer_var: TyOrConstInferVar<'tcx>) -> bool {
|
||||
let mut inner = self.inner.borrow_mut();
|
||||
match infer_var {
|
||||
TyOrConstInferVar::Ty(v) => {
|
||||
use self::type_variable::TypeVariableValue;
|
||||
|
||||
// If `inlined_probe` returns a `Known` value, it never equals
|
||||
// `ty::Infer(ty::TyVar(v))`.
|
||||
match self.inner.borrow_mut().type_variables().inlined_probe(v) {
|
||||
match inner.type_variables().inlined_probe(v) {
|
||||
TypeVariableValue::Unknown { .. } => false,
|
||||
TypeVariableValue::Known { .. } => true,
|
||||
}
|
||||
@ -1702,7 +1705,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
// If `inlined_probe_value` returns a value it's always a
|
||||
// `ty::Int(_)` or `ty::UInt(_)`, which never matches a
|
||||
// `ty::Infer(_)`.
|
||||
self.inner.borrow_mut().int_unification_table().inlined_probe_value(v).is_some()
|
||||
inner.int_unification_table().inlined_probe_value(v).is_some()
|
||||
}
|
||||
|
||||
TyOrConstInferVar::TyFloat(v) => {
|
||||
@ -1710,7 +1713,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
// `ty::Float(_)`, which never matches a `ty::Infer(_)`.
|
||||
//
|
||||
// Not `inlined_probe_value(v)` because this call site is colder.
|
||||
self.inner.borrow_mut().float_unification_table().probe_value(v).is_some()
|
||||
inner.float_unification_table().probe_value(v).is_some()
|
||||
}
|
||||
|
||||
TyOrConstInferVar::Const(v) => {
|
||||
@ -1718,7 +1721,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
// `ty::ConstKind::Infer(ty::InferConst::Var(v))`.
|
||||
//
|
||||
// Not `inlined_probe_value(v)` because this call site is colder.
|
||||
match self.inner.borrow_mut().const_unification_table.probe_value(v).val {
|
||||
match inner.const_unification_table().probe_value(v).val {
|
||||
ConstVariableValue::Unknown { .. } => false,
|
||||
ConstVariableValue::Known { .. } => true,
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use rustc::ty;
|
||||
use rustc_data_structures::snapshot_vec as sv;
|
||||
use rustc_data_structures::undo_log::{Rollback, Snapshots, UndoLogs};
|
||||
use rustc_data_structures::unify as ut;
|
||||
use rustc_hir as hir;
|
||||
use rustc_middle::ty;
|
||||
|
||||
use crate::{
|
||||
infer::{
|
||||
|
@ -23,7 +23,7 @@ pub use self::project::MismatchedProjectionTypes;
|
||||
pub(crate) use self::project::UndoLog;
|
||||
pub use self::project::{
|
||||
Normalized, NormalizedTy, ProjectionCache, ProjectionCacheEntry, ProjectionCacheKey,
|
||||
ProjectionCacheSnapshot, Reveal,
|
||||
ProjectionCacheStorage, Reveal,
|
||||
};
|
||||
crate use self::util::elaborate_predicates;
|
||||
|
||||
|
@ -2,8 +2,12 @@
|
||||
|
||||
use super::PredicateObligation;
|
||||
|
||||
use rustc_data_structures::snapshot_map::{self, SnapshotMapRef, SnapshotMapStorage};
|
||||
use rustc_middle::ty::fold::TypeFoldable;
|
||||
use crate::infer::InferCtxtUndoLogs;
|
||||
|
||||
use rustc_data_structures::{
|
||||
snapshot_map::{self, SnapshotMapRef, SnapshotMapStorage},
|
||||
undo_log::Rollback,
|
||||
};
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
|
||||
pub use rustc_middle::traits::Reveal;
|
||||
|
@ -311,16 +311,19 @@ impl<'hir> Map<'hir> {
|
||||
}
|
||||
|
||||
fn find_entry(&self, id: HirId) -> Option<Entry<'hir>> {
|
||||
if id.local_id == ItemLocalId::from_u32_const(0) {
|
||||
let owner = self.tcx.hir_owner(id.owner_def_id());
|
||||
if id.local_id == ItemLocalId::from_u32(0) {
|
||||
let owner = self.tcx.hir_owner(id.owner);
|
||||
owner.map(|owner| Entry { parent: owner.parent, node: owner.node })
|
||||
} else {
|
||||
let owner = self.tcx.hir_owner_items(id.owner_def_id());
|
||||
let owner = self.tcx.hir_owner_nodes(id.owner);
|
||||
owner.and_then(|owner| {
|
||||
let item = owner.items[id.local_id].as_ref();
|
||||
item.map(|item| Entry {
|
||||
parent: HirId { owner: id.owner, local_id: item.parent },
|
||||
node: item.node,
|
||||
let node = owner.nodes[id.local_id].as_ref();
|
||||
// FIXME(eddyb) use a single generic type insted of having both
|
||||
// `Entry` and `ParentedNode`, which are effectively the same.
|
||||
// Alternatively, rewrite code using `Entry` to use `ParentedNode`.
|
||||
node.map(|node| Entry {
|
||||
parent: HirId { owner: id.owner, local_id: node.parent },
|
||||
node: node.node,
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -352,12 +355,7 @@ impl<'hir> Map<'hir> {
|
||||
}
|
||||
|
||||
pub fn body(&self, id: BodyId) -> &'hir Body<'hir> {
|
||||
self.tcx
|
||||
.hir_owner_items(DefId::local(id.hir_id.owner))
|
||||
.unwrap()
|
||||
.bodies
|
||||
.get(&id.hir_id.local_id)
|
||||
.unwrap()
|
||||
self.tcx.hir_owner_nodes(id.hir_id.owner).unwrap().bodies.get(&id.hir_id.local_id).unwrap()
|
||||
}
|
||||
|
||||
pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
|
||||
|
@ -77,8 +77,8 @@ pub fn provide(providers: &mut Providers<'_>) {
|
||||
let module = hir.as_local_hir_id(id);
|
||||
&tcx.untracked_crate.modules[&module]
|
||||
};
|
||||
providers.hir_owner = |tcx, id| tcx.index_hir(id.krate).map[id.index].signature;
|
||||
providers.hir_owner_items =
|
||||
|tcx, id| tcx.index_hir(id.krate).map[id.index].with_bodies.as_ref().map(|items| &**items);
|
||||
providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature;
|
||||
providers.hir_owner_nodes =
|
||||
|tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_ref().map(|nodes| &**nodes);
|
||||
map::provide(providers);
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ rustc_queries! {
|
||||
//
|
||||
// This can be conveniently accessed by methods on `tcx.hir()`.
|
||||
// Avoid calling this query directly.
|
||||
query hir_owner(key: DefId) -> Option<&'tcx HirOwner<'tcx>> {
|
||||
query hir_owner(key: LocalDefId) -> Option<&'tcx crate::hir::Owner<'tcx>> {
|
||||
eval_always
|
||||
desc { |tcx| "HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
|
||||
}
|
||||
@ -84,7 +84,7 @@ rustc_queries! {
|
||||
//
|
||||
// This can be conveniently accessed by methods on `tcx.hir()`.
|
||||
// Avoid calling this query directly.
|
||||
query hir_owner_items(key: DefId) -> Option<&'tcx HirOwnerItems<'tcx>> {
|
||||
query hir_owner_nodes(key: LocalDefId) -> Option<&'tcx crate::hir::OwnerNodes<'tcx>> {
|
||||
eval_always
|
||||
desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
|
||||
}
|
||||
|
@ -240,9 +240,15 @@ struct FulfillProcessor<'a, 'b, 'tcx> {
|
||||
register_region_obligations: bool,
|
||||
}
|
||||
|
||||
fn mk_pending(os: Vec<PredicateObligation<'tcx>>) -> Vec<PendingPredicateObligation<'tcx>> {
|
||||
fn mk_pending(
|
||||
infcx: &InferCtxt<'_, 'tcx>,
|
||||
os: Vec<PredicateObligation<'tcx>>,
|
||||
) -> Vec<PendingPredicateObligation<'tcx>> {
|
||||
os.into_iter()
|
||||
.map(|o| PendingPredicateObligation { obligation: o, stalled_on: vec![] })
|
||||
.map(|mut o| {
|
||||
o.predicate = infcx.resolve_vars_if_possible(&o.predicate);
|
||||
PendingPredicateObligation { obligation: o, stalled_on: vec![] }
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@ -312,6 +318,8 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
|
||||
|
||||
debug!("process_obligation: obligation = {:?} cause = {:?}", obligation, obligation.cause);
|
||||
|
||||
let infcx = self.selcx.infcx();
|
||||
|
||||
match obligation.predicate {
|
||||
ty::Predicate::Trait(ref data, _) => {
|
||||
let trait_obligation = obligation.with(*data);
|
||||
@ -319,7 +327,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
|
||||
if data.is_global() {
|
||||
// no type variables present, can use evaluation for better caching.
|
||||
// FIXME: consider caching errors too.
|
||||
if self.selcx.infcx().predicate_must_hold_considering_regions(&obligation) {
|
||||
if infcx.predicate_must_hold_considering_regions(&obligation) {
|
||||
debug!(
|
||||
"selecting trait `{:?}` at depth {} evaluated to holds",
|
||||
data, obligation.recursion_depth
|
||||
@ -334,7 +342,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
|
||||
"selecting trait `{:?}` at depth {} yielded Ok(Some)",
|
||||
data, obligation.recursion_depth
|
||||
);
|
||||
ProcessResult::Changed(mk_pending(vtable.nested_obligations()))
|
||||
ProcessResult::Changed(mk_pending(infcx, vtable.nested_obligations()))
|
||||
}
|
||||
Ok(None) => {
|
||||
debug!(
|
||||
@ -351,7 +359,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
|
||||
|
||||
debug!(
|
||||
"process_predicate: pending obligation {:?} now stalled on {:?}",
|
||||
self.selcx.infcx().resolve_vars_if_possible(obligation),
|
||||
infcx.resolve_vars_if_possible(obligation),
|
||||
pending_obligation.stalled_on
|
||||
);
|
||||
|
||||
@ -369,7 +377,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
|
||||
}
|
||||
|
||||
ty::Predicate::RegionOutlives(ref binder) => {
|
||||
match self.selcx.infcx().region_outlives_predicate(&obligation.cause, binder) {
|
||||
match infcx.region_outlives_predicate(&obligation.cause, binder) {
|
||||
Ok(()) => ProcessResult::Changed(vec![]),
|
||||
Err(_) => ProcessResult::Error(CodeSelectionError(Unimplemented)),
|
||||
}
|
||||
@ -428,7 +436,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
|
||||
trait_ref_type_vars(self.selcx, data.to_poly_trait_ref(tcx));
|
||||
ProcessResult::Unchanged
|
||||
}
|
||||
Ok(Some(os)) => ProcessResult::Changed(mk_pending(os)),
|
||||
Ok(Some(os)) => ProcessResult::Changed(mk_pending(infcx, os)),
|
||||
Err(e) => ProcessResult::Error(CodeProjectionError(e)),
|
||||
}
|
||||
}
|
||||
@ -467,7 +475,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
|
||||
vec![TyOrConstInferVar::maybe_from_ty(ty).unwrap()];
|
||||
ProcessResult::Unchanged
|
||||
}
|
||||
Some(os) => ProcessResult::Changed(mk_pending(os)),
|
||||
Some(os) => ProcessResult::Changed(mk_pending(infcx, os)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -485,7 +493,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
|
||||
];
|
||||
ProcessResult::Unchanged
|
||||
}
|
||||
Some(Ok(ok)) => ProcessResult::Changed(mk_pending(ok.obligations)),
|
||||
Some(Ok(ok)) => ProcessResult::Changed(mk_pending(infcx, ok.obligations)),
|
||||
Some(Err(err)) => {
|
||||
let expected_found = ExpectedFound::new(
|
||||
subtype.skip_binder().a_is_expected,
|
||||
|
@ -471,7 +471,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
|
||||
// bounds. It might be the case that we want two distinct caches,
|
||||
// or else another kind of cache entry.
|
||||
|
||||
let cache_result = infcx.inner.borrow_mut().projection_cache.try_start(cache_key);
|
||||
let cache_result = infcx.inner.borrow_mut().projection_cache().try_start(cache_key);
|
||||
match cache_result {
|
||||
Ok(()) => {}
|
||||
Err(ProjectionCacheEntry::Ambiguous) => {
|
||||
@ -537,7 +537,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
|
||||
// Once we have inferred everything we need to know, we
|
||||
// can ignore the `obligations` from that point on.
|
||||
if infcx.unresolved_type_vars(&ty.value).is_none() {
|
||||
infcx.inner.borrow_mut().projection_cache.complete_normalized(cache_key, &ty);
|
||||
infcx.inner.borrow_mut().projection_cache().complete_normalized(cache_key, &ty);
|
||||
// No need to extend `obligations`.
|
||||
} else {
|
||||
obligations.extend(ty.obligations);
|
||||
@ -604,7 +604,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
|
||||
};
|
||||
|
||||
let cache_value = prune_cache_value_obligations(infcx, &result);
|
||||
infcx.inner.borrow_mut().projection_cache.insert_ty(cache_key, cache_value);
|
||||
infcx.inner.borrow_mut().projection_cache().insert_ty(cache_key, cache_value);
|
||||
obligations.extend(result.obligations);
|
||||
Some(result.value)
|
||||
}
|
||||
@ -615,7 +615,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
|
||||
projected_ty
|
||||
);
|
||||
let result = Normalized { value: projected_ty, obligations: vec![] };
|
||||
infcx.inner.borrow_mut().projection_cache.insert_ty(cache_key, result.clone());
|
||||
infcx.inner.borrow_mut().projection_cache().insert_ty(cache_key, result.clone());
|
||||
// No need to extend `obligations`.
|
||||
Some(result.value)
|
||||
}
|
||||
@ -624,7 +624,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
|
||||
"opt_normalize_projection_type: \
|
||||
too many candidates"
|
||||
);
|
||||
infcx.inner.borrow_mut().projection_cache.ambiguous(cache_key);
|
||||
infcx.inner.borrow_mut().projection_cache().ambiguous(cache_key);
|
||||
None
|
||||
}
|
||||
Err(ProjectionTyError::TraitSelectionError(_)) => {
|
||||
@ -634,7 +634,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
|
||||
// Trait`, which when processed will cause the error to be
|
||||
// reported later
|
||||
|
||||
infcx.inner.borrow_mut().projection_cache.error(cache_key);
|
||||
infcx.inner.borrow_mut().projection_cache().error(cache_key);
|
||||
let result = normalize_to_error(selcx, param_env, projection_ty, cause, depth);
|
||||
obligations.extend(result.obligations);
|
||||
Some(result.value)
|
||||
|
@ -2,10 +2,12 @@
|
||||
// run-pass
|
||||
|
||||
macro_rules! regex {
|
||||
//~^ WARN unused macro definition
|
||||
() => {};
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
use regex;
|
||||
//~^ WARN unused import
|
||||
|
||||
fn main() {}
|
||||
|
Loading…
Reference in New Issue
Block a user