Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add fast path to eq_opaque_type_and_type
  • Loading branch information
matthewjasper committed Feb 14, 2020
1 parent 6d9e270 commit 223a2ee
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/librustc/ty/flags.rs
Expand Up @@ -138,7 +138,7 @@ impl FlagComputation {
}

&ty::Opaque(_, substs) => {
self.add_flags(TypeFlags::HAS_PROJECTION);
self.add_flags(TypeFlags::HAS_PROJECTION | TypeFlags::HAS_TY_OPAQUE);
self.add_substs(substs);
}

Expand Down
3 changes: 3 additions & 0 deletions src/librustc/ty/fold.rs
Expand Up @@ -78,6 +78,9 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
fn has_projections(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_PROJECTION)
}
fn has_opaque_types(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_TY_OPAQUE)
}
fn references_error(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_TY_ERR)
}
Expand Down
5 changes: 4 additions & 1 deletion src/librustc/ty/mod.rs
Expand Up @@ -481,6 +481,8 @@ bitflags! {

const HAS_CT_INFER = 1 << 14;
const HAS_CT_PLACEHOLDER = 1 << 15;
/// Does this have any [Opaque] types.
const HAS_TY_OPAQUE = 1 << 16;

const NEEDS_SUBST = TypeFlags::HAS_PARAMS.bits |
TypeFlags::HAS_RE_EARLY_BOUND.bits;
Expand All @@ -503,7 +505,8 @@ bitflags! {
TypeFlags::HAS_RE_ERASED.bits |
TypeFlags::HAS_TY_PLACEHOLDER.bits |
TypeFlags::HAS_CT_INFER.bits |
TypeFlags::HAS_CT_PLACEHOLDER.bits;
TypeFlags::HAS_CT_PLACEHOLDER.bits |
TypeFlags::HAS_TY_OPAQUE.bits;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/util.rs
Expand Up @@ -615,7 +615,7 @@ impl<'tcx> TyCtxt<'tcx> {
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
if let ty::Opaque(def_id, substs) = t.kind {
self.expand_opaque_ty(def_id, substs).unwrap_or(t)
} else if t.has_projections() {
} else if t.has_opaque_types() {
t.super_fold_with(self)
} else {
t
Expand Down
16 changes: 16 additions & 0 deletions src/librustc_mir/borrow_check/type_check/mod.rs
Expand Up @@ -1196,6 +1196,22 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
anon_ty={:?})",
revealed_ty, anon_ty
);

// Fast path for the common case.
if !anon_ty.has_opaque_types() {
if let Err(terr) = self.eq_types(anon_ty, revealed_ty, locations, category) {
span_mirbug!(
self,
locations,
"eq_opaque_type_and_type: `{:?}=={:?}` failed with `{:?}`",
revealed_ty,
anon_ty,
terr
);
}
return Ok(());
}

let infcx = self.infcx;
let tcx = infcx.tcx;
let param_env = self.param_env;
Expand Down

0 comments on commit 223a2ee

Please sign in to comment.