Skip to content

Commit 4d399f3

Browse files
committed
introduce QueryKey separation
1 parent 2b634bd commit 4d399f3

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

src/librustc/traits/query/type_op/eq.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ impl<'tcx> Eq<'tcx> {
2626
}
2727

2828
impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for Eq<'tcx> {
29+
type QueryKey = Self;
2930
type QueryResult = ();
3031

3132
fn trivial_noop(self, _tcx: TyCtxt<'_, 'gcx, 'tcx>) -> Result<Self::QueryResult, Self> {
@@ -36,6 +37,10 @@ impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for Eq<'tcx> {
3637
}
3738
}
3839

40+
fn into_query_key(self) -> Self {
41+
self
42+
}
43+
3944
fn param_env(&self) -> ty::ParamEnv<'tcx> {
4045
self.param_env
4146
}

src/librustc/traits/query/type_op/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,21 @@ pub trait TypeOp<'gcx, 'tcx>: Sized + fmt::Debug {
103103
}
104104
}
105105

106-
pub trait QueryTypeOp<'gcx: 'tcx, 'tcx>: TypeFoldable<'tcx> + Lift<'gcx> {
106+
pub trait QueryTypeOp<'gcx: 'tcx, 'tcx>: fmt::Debug + Sized {
107+
type QueryKey: TypeFoldable<'tcx> + Lift<'gcx>;
107108
type QueryResult: TypeFoldable<'tcx> + Lift<'gcx>;
108109

109110
/// Micro-optimization: returns `Ok(x)` if we can trivially
110111
/// produce the output, else returns `Err(self)` back.
111112
fn trivial_noop(self, tcx: TyCtxt<'_, 'gcx, 'tcx>) -> Result<Self::QueryResult, Self>;
112113

114+
fn into_query_key(self) -> Self::QueryKey;
115+
113116
fn param_env(&self) -> ParamEnv<'tcx>;
114117

115118
fn perform_query(
116119
tcx: TyCtxt<'_, 'gcx, 'tcx>,
117-
canonicalized: Canonicalized<'gcx, Self>,
120+
canonicalized: Canonicalized<'gcx, Self::QueryKey>,
118121
) -> Fallible<CanonicalizedQueryResult<'gcx, Self::QueryResult>>;
119122

120123
/// "Upcasts" a lifted query result (which is in the gcx lifetime)
@@ -149,7 +152,8 @@ where
149152
// `canonicalize_hr_query_hack` here because of things like
150153
// the subtype query, which go awry around `'static`
151154
// otherwise.
152-
let (canonical_self, canonical_var_values) = infcx.canonicalize_hr_query_hack(&self);
155+
let query_key = self.into_query_key();
156+
let (canonical_self, canonical_var_values) = infcx.canonicalize_hr_query_hack(&query_key);
153157
let canonical_result = Q::perform_query(infcx.tcx, canonical_self)?;
154158

155159
// FIXME: This is not the most efficient setup. The

src/librustc/traits/query/type_op/normalize.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ impl<'gcx: 'tcx, 'tcx, T> super::QueryTypeOp<'gcx, 'tcx> for Normalize<'tcx, T>
3333
where
3434
T: Normalizable<'gcx, 'tcx>,
3535
{
36+
type QueryKey = Self;
3637
type QueryResult = T;
3738

3839
fn trivial_noop(self, _tcx: TyCtxt<'_, 'gcx, 'tcx>) -> Result<T, Self> {
@@ -43,6 +44,10 @@ where
4344
}
4445
}
4546

47+
fn into_query_key(self) -> Self {
48+
self
49+
}
50+
4651
fn param_env(&self) -> ParamEnv<'tcx> {
4752
self.param_env
4853
}

src/librustc/traits/query/type_op/prove_predicate.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ impl<'tcx> ProvePredicate<'tcx> {
2828
}
2929

3030
impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for ProvePredicate<'tcx> {
31+
type QueryKey = Self;
3132
type QueryResult = ();
3233

3334
fn trivial_noop(self, _tcx: TyCtxt<'_, 'gcx, 'tcx>) -> Result<Self::QueryResult, Self> {
3435
Err(self)
3536
}
3637

38+
fn into_query_key(self) -> Self {
39+
self
40+
}
41+
3742
fn param_env(&self) -> ParamEnv<'tcx> {
3843
self.param_env
3944
}

src/librustc/traits/query/type_op/subtype.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ impl<'tcx> Subtype<'tcx> {
3030
}
3131

3232
impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for Subtype<'tcx> {
33+
type QueryKey = Self;
3334
type QueryResult = ();
3435

3536
fn trivial_noop(self, _tcx: TyCtxt<'_, 'gcx, 'tcx>) -> Result<(), Self> {
@@ -40,6 +41,10 @@ impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for Subtype<'tcx> {
4041
}
4142
}
4243

44+
fn into_query_key(self) -> Self {
45+
self
46+
}
47+
4348
fn param_env(&self) -> ParamEnv<'tcx> {
4449
self.param_env
4550
}

0 commit comments

Comments
 (0)