Skip to content

Commit 223a2ee

Browse files
committed
Add fast path to eq_opaque_type_and_type
1 parent 6d9e270 commit 223a2ee

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

src/librustc/ty/flags.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl FlagComputation {
138138
}
139139

140140
&ty::Opaque(_, substs) => {
141-
self.add_flags(TypeFlags::HAS_PROJECTION);
141+
self.add_flags(TypeFlags::HAS_PROJECTION | TypeFlags::HAS_TY_OPAQUE);
142142
self.add_substs(substs);
143143
}
144144

src/librustc/ty/fold.rs

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
7878
fn has_projections(&self) -> bool {
7979
self.has_type_flags(TypeFlags::HAS_PROJECTION)
8080
}
81+
fn has_opaque_types(&self) -> bool {
82+
self.has_type_flags(TypeFlags::HAS_TY_OPAQUE)
83+
}
8184
fn references_error(&self) -> bool {
8285
self.has_type_flags(TypeFlags::HAS_TY_ERR)
8386
}

src/librustc/ty/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,8 @@ bitflags! {
481481

482482
const HAS_CT_INFER = 1 << 14;
483483
const HAS_CT_PLACEHOLDER = 1 << 15;
484+
/// Does this have any [Opaque] types.
485+
const HAS_TY_OPAQUE = 1 << 16;
484486

485487
const NEEDS_SUBST = TypeFlags::HAS_PARAMS.bits |
486488
TypeFlags::HAS_RE_EARLY_BOUND.bits;
@@ -503,7 +505,8 @@ bitflags! {
503505
TypeFlags::HAS_RE_ERASED.bits |
504506
TypeFlags::HAS_TY_PLACEHOLDER.bits |
505507
TypeFlags::HAS_CT_INFER.bits |
506-
TypeFlags::HAS_CT_PLACEHOLDER.bits;
508+
TypeFlags::HAS_CT_PLACEHOLDER.bits |
509+
TypeFlags::HAS_TY_OPAQUE.bits;
507510
}
508511
}
509512

src/librustc/ty/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ impl<'tcx> TyCtxt<'tcx> {
615615
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
616616
if let ty::Opaque(def_id, substs) = t.kind {
617617
self.expand_opaque_ty(def_id, substs).unwrap_or(t)
618-
} else if t.has_projections() {
618+
} else if t.has_opaque_types() {
619619
t.super_fold_with(self)
620620
} else {
621621
t

src/librustc_mir/borrow_check/type_check/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,22 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
11961196
anon_ty={:?})",
11971197
revealed_ty, anon_ty
11981198
);
1199+
1200+
// Fast path for the common case.
1201+
if !anon_ty.has_opaque_types() {
1202+
if let Err(terr) = self.eq_types(anon_ty, revealed_ty, locations, category) {
1203+
span_mirbug!(
1204+
self,
1205+
locations,
1206+
"eq_opaque_type_and_type: `{:?}=={:?}` failed with `{:?}`",
1207+
revealed_ty,
1208+
anon_ty,
1209+
terr
1210+
);
1211+
}
1212+
return Ok(());
1213+
}
1214+
11991215
let infcx = self.infcx;
12001216
let tcx = infcx.tcx;
12011217
let param_env = self.param_env;

0 commit comments

Comments
 (0)