introduce QueryKey separation

This commit is contained in:
Niko Matsakis 2018-06-19 15:00:55 -04:00
parent f24e90ec25
commit 977f3fc940
5 changed files with 27 additions and 3 deletions

View file

@ -26,6 +26,7 @@ impl<'tcx> Eq<'tcx> {
}
impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for Eq<'tcx> {
type QueryKey = Self;
type QueryResult = ();
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> {
}
}
fn into_query_key(self) -> Self {
self
}
fn param_env(&self) -> ty::ParamEnv<'tcx> {
self.param_env
}

View file

@ -103,18 +103,21 @@ pub trait TypeOp<'gcx, 'tcx>: Sized + fmt::Debug {
}
}
pub trait QueryTypeOp<'gcx: 'tcx, 'tcx>: TypeFoldable<'tcx> + Lift<'gcx> {
pub trait QueryTypeOp<'gcx: 'tcx, 'tcx>: fmt::Debug + Sized {
type QueryKey: TypeFoldable<'tcx> + Lift<'gcx>;
type QueryResult: TypeFoldable<'tcx> + Lift<'gcx>;
/// Micro-optimization: returns `Ok(x)` if we can trivially
/// produce the output, else returns `Err(self)` back.
fn trivial_noop(self, tcx: TyCtxt<'_, 'gcx, 'tcx>) -> Result<Self::QueryResult, Self>;
fn into_query_key(self) -> Self::QueryKey;
fn param_env(&self) -> ParamEnv<'tcx>;
fn perform_query(
tcx: TyCtxt<'_, 'gcx, 'tcx>,
canonicalized: Canonicalized<'gcx, Self>,
canonicalized: Canonicalized<'gcx, Self::QueryKey>,
) -> Fallible<CanonicalizedQueryResult<'gcx, Self::QueryResult>>;
/// "Upcasts" a lifted query result (which is in the gcx lifetime)
@ -149,7 +152,8 @@ where
// `canonicalize_hr_query_hack` here because of things like
// the subtype query, which go awry around `'static`
// otherwise.
let (canonical_self, canonical_var_values) = infcx.canonicalize_hr_query_hack(&self);
let query_key = self.into_query_key();
let (canonical_self, canonical_var_values) = infcx.canonicalize_hr_query_hack(&query_key);
let canonical_result = Q::perform_query(infcx.tcx, canonical_self)?;
// FIXME: This is not the most efficient setup. The

View file

@ -33,6 +33,7 @@ impl<'gcx: 'tcx, 'tcx, T> super::QueryTypeOp<'gcx, 'tcx> for Normalize<'tcx, T>
where
T: Normalizable<'gcx, 'tcx>,
{
type QueryKey = Self;
type QueryResult = T;
fn trivial_noop(self, _tcx: TyCtxt<'_, 'gcx, 'tcx>) -> Result<T, Self> {
@ -43,6 +44,10 @@ where
}
}
fn into_query_key(self) -> Self {
self
}
fn param_env(&self) -> ParamEnv<'tcx> {
self.param_env
}

View file

@ -28,12 +28,17 @@ impl<'tcx> ProvePredicate<'tcx> {
}
impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for ProvePredicate<'tcx> {
type QueryKey = Self;
type QueryResult = ();
fn trivial_noop(self, _tcx: TyCtxt<'_, 'gcx, 'tcx>) -> Result<Self::QueryResult, Self> {
Err(self)
}
fn into_query_key(self) -> Self {
self
}
fn param_env(&self) -> ParamEnv<'tcx> {
self.param_env
}

View file

@ -30,6 +30,7 @@ impl<'tcx> Subtype<'tcx> {
}
impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for Subtype<'tcx> {
type QueryKey = Self;
type QueryResult = ();
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> {
}
}
fn into_query_key(self) -> Self {
self
}
fn param_env(&self) -> ParamEnv<'tcx> {
self.param_env
}