Skip to content

Commit 8aeaaac

Browse files
author
Ariel Ben-Yehuda
committed
add a fast-path to resolve_type_vars_if_possible
this avoids needless substituting before: 577.76user 4.27system 7:36.13elapsed 127%CPU (0avgtext+0avgdata 1141608maxresident)k after: 573.01user 4.04system 7:33.86elapsed 127%CPU (0avgtext+0avgdata 1141656maxresident)k
1 parent 96e6b2f commit 8aeaaac

File tree

6 files changed

+48
-6
lines changed

6 files changed

+48
-6
lines changed

src/librustc/middle/infer/higher_ranked/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ pub fn plug_leaks<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
614614
snapshot: &CombinedSnapshot,
615615
value: &T)
616616
-> T
617-
where T : TypeFoldable<'tcx>
617+
where T : TypeFoldable<'tcx> + ty::HasTypeFlags
618618
{
619619
debug_assert!(leak_check(infcx, &skol_map, snapshot).is_ok());
620620

src/librustc/middle/infer/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
985985
snapshot: &CombinedSnapshot,
986986
value: &T)
987987
-> T
988-
where T : TypeFoldable<'tcx>
988+
where T : TypeFoldable<'tcx> + HasTypeFlags
989989
{
990990
/*! See `higher_ranked::plug_leaks` */
991991

@@ -1256,7 +1256,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
12561256
}
12571257
}
12581258

1259-
pub fn resolve_type_vars_if_possible<T:TypeFoldable<'tcx>>(&self, value: &T) -> T {
1259+
pub fn resolve_type_vars_if_possible<T>(&self, value: &T) -> T
1260+
where T: TypeFoldable<'tcx> + HasTypeFlags
1261+
{
12601262
/*!
12611263
* Where possible, replaces type/int/float variables in
12621264
* `value` with their final value. Note that region variables
@@ -1266,6 +1268,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
12661268
* at will.
12671269
*/
12681270

1271+
if !value.needs_infer() {
1272+
return value.clone(); // avoid duplicated subst-folding
1273+
}
12691274
let mut r = resolve::OpportunisticTypeResolver::new(self);
12701275
value.fold_with(&mut r)
12711276
}

src/librustc/middle/traits/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ fn report_on_unimplemented<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
160160
pub fn report_overflow_error<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>,
161161
obligation: &Obligation<'tcx, T>)
162162
-> !
163-
where T: fmt::Display + TypeFoldable<'tcx>
163+
where T: fmt::Display + TypeFoldable<'tcx> + HasTypeFlags
164164
{
165165
let predicate =
166166
infcx.resolve_type_vars_if_possible(&obligation.predicate);

src/librustc/middle/traits/project.rs

+7
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,13 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Normalized<'tcx, T> {
927927
}
928928
}
929929

930+
impl<'tcx, T: HasTypeFlags> HasTypeFlags for Normalized<'tcx, T> {
931+
fn has_type_flags(&self, flags: ty::TypeFlags) -> bool {
932+
self.value.has_type_flags(flags) ||
933+
self.obligations.has_type_flags(flags)
934+
}
935+
}
936+
930937
impl<'tcx, T:fmt::Debug> fmt::Debug for Normalized<'tcx, T> {
931938
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
932939
write!(f, "Normalized({:?},{:?})",

src/librustc/middle/ty.rs

+30
Original file line numberDiff line numberDiff line change
@@ -7280,6 +7280,24 @@ impl<'tcx,T:HasTypeFlags> HasTypeFlags for VecPerParamSpace<T> {
72807280
}
72817281
}
72827282

7283+
impl HasTypeFlags for abi::Abi {
7284+
fn has_type_flags(&self, _flags: TypeFlags) -> bool {
7285+
false
7286+
}
7287+
}
7288+
7289+
impl HasTypeFlags for ast::Unsafety {
7290+
fn has_type_flags(&self, _flags: TypeFlags) -> bool {
7291+
false
7292+
}
7293+
}
7294+
7295+
impl HasTypeFlags for BuiltinBounds {
7296+
fn has_type_flags(&self, _flags: TypeFlags) -> bool {
7297+
false
7298+
}
7299+
}
7300+
72837301
impl<'tcx> HasTypeFlags for ClosureTy<'tcx> {
72847302
fn has_type_flags(&self, flags: TypeFlags) -> bool {
72857303
self.sig.has_type_flags(flags)
@@ -7292,6 +7310,12 @@ impl<'tcx> HasTypeFlags for ClosureUpvar<'tcx> {
72927310
}
72937311
}
72947312

7313+
impl<'tcx> HasTypeFlags for ExistentialBounds<'tcx> {
7314+
fn has_type_flags(&self, flags: TypeFlags) -> bool {
7315+
self.projection_bounds.has_type_flags(flags)
7316+
}
7317+
}
7318+
72957319
impl<'tcx> HasTypeFlags for ty::InstantiatedPredicates<'tcx> {
72967320
fn has_type_flags(&self, flags: TypeFlags) -> bool {
72977321
self.predicates.has_type_flags(flags)
@@ -7367,6 +7391,12 @@ impl<'tcx> HasTypeFlags for Ty<'tcx> {
73677391
}
73687392
}
73697393

7394+
impl<'tcx> HasTypeFlags for TypeAndMut<'tcx> {
7395+
fn has_type_flags(&self, flags: TypeFlags) -> bool {
7396+
self.ty.has_type_flags(flags)
7397+
}
7398+
}
7399+
73707400
impl<'tcx> HasTypeFlags for TraitRef<'tcx> {
73717401
fn has_type_flags(&self, flags: TypeFlags) -> bool {
73727402
self.substs.has_type_flags(flags)

src/librustc/middle/ty_relate/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! type equality, etc.
1515
1616
use middle::subst::{ErasedRegions, NonerasedRegions, ParamSpace, Substs};
17-
use middle::ty::{self, Ty, TypeError};
17+
use middle::ty::{self, HasTypeFlags, Ty, TypeError};
1818
use middle::ty_fold::TypeFoldable;
1919
use std::rc::Rc;
2020
use syntax::abi;
@@ -78,7 +78,7 @@ pub trait TypeRelation<'a,'tcx> : Sized {
7878
where T: Relate<'a,'tcx>;
7979
}
8080

81-
pub trait Relate<'a,'tcx>: TypeFoldable<'tcx> {
81+
pub trait Relate<'a,'tcx>: TypeFoldable<'tcx> + HasTypeFlags {
8282
fn relate<R:TypeRelation<'a,'tcx>>(relation: &mut R,
8383
a: &Self,
8484
b: &Self)

0 commit comments

Comments
 (0)