Skip to content

Commit

Permalink
Remove shrink_to_tcx_lifetime
Browse files Browse the repository at this point in the history
There's no longer two distinct gcx and tcx lifetimes which made this
necessary (or, at least, the code compiles -- it's possible we got
better at normalizing, but that seems unlikely).
  • Loading branch information
Mark-Simulacrum committed Sep 25, 2019
1 parent 9f63a3a commit 4469bdd
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 98 deletions.
8 changes: 1 addition & 7 deletions src/librustc/traits/query/type_op/ascribe_user_type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
use crate::traits::query::Fallible;
use crate::hir::def_id::DefId;
use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
Expand Down Expand Up @@ -37,12 +37,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for AscribeUserType<'tcx> {
) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> {
tcx.type_op_ascribe_user_type(canonicalized)
}

fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, ()>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, ()>> {
v
}
}

BraceStructTypeFoldableImpl! {
Expand Down
8 changes: 1 addition & 7 deletions src/librustc/traits/query/type_op/eq.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
use crate::traits::query::Fallible;
use crate::ty::{ParamEnvAnd, Ty, TyCtxt};

Expand Down Expand Up @@ -34,12 +34,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for Eq<'tcx> {
) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> {
tcx.type_op_eq(canonicalized)
}

fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, ()>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, ()>> {
v
}
}

BraceStructTypeFoldableImpl! {
Expand Down
8 changes: 1 addition & 7 deletions src/librustc/traits/query/type_op/implied_outlives_bounds.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
use crate::traits::query::outlives_bounds::OutlivesBound;
use crate::traits::query::Fallible;
use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
Expand Down Expand Up @@ -38,12 +38,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ImpliedOutlivesBounds<'tcx> {

tcx.implied_outlives_bounds(canonicalized)
}

fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, Self::QueryResponse>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self::QueryResponse>> {
v
}
}

BraceStructTypeFoldableImpl! {
Expand Down
21 changes: 2 additions & 19 deletions src/librustc/traits/query/type_op/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::infer::canonical::{
Canonical, Canonicalized, CanonicalizedQueryResponse, OriginalQueryValues,
QueryRegionConstraints, QueryResponse,
Canonicalized, CanonicalizedQueryResponse, OriginalQueryValues,
QueryRegionConstraints,
};
use crate::infer::{InferCtxt, InferOk};
use std::fmt;
Expand Down Expand Up @@ -66,22 +66,6 @@ pub trait QueryTypeOp<'tcx>: fmt::Debug + Sized + TypeFoldable<'tcx> + 'tcx {
canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
) -> Fallible<CanonicalizedQueryResponse<'tcx, Self::QueryResponse>>;

/// Casts a lifted query result (which is in the tcx lifetime)
/// into the tcx lifetime. This is always just an identity cast,
/// but the generic code doesn't realize it -- put another way, in
/// the generic code, we have a `Lifted<'tcx, Self::QueryResponse>`
/// and we want to convert that to a `Self::QueryResponse`. This is
/// not a priori valid, so we can't do it -- but in practice, it
/// is always a no-op (e.g., the lifted form of a type,
/// `Ty<'tcx>`, is a subtype of `Ty<'tcx>`). So we have to push
/// the operation into the impls that know more specifically what
/// `QueryResponse` is. This operation would (maybe) be nicer with
/// something like HKTs or GATs, since then we could make
/// `QueryResponse` parametric and `'tcx` and `'tcx` etc.
fn shrink_to_tcx_lifetime(
lifted_query_result: &'a CanonicalizedQueryResponse<'tcx, Self::QueryResponse>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self::QueryResponse>>;

fn fully_perform_into(
query_key: ParamEnvAnd<'tcx, Self>,
infcx: &InferCtxt<'_, 'tcx>,
Expand All @@ -99,7 +83,6 @@ pub trait QueryTypeOp<'tcx>: fmt::Debug + Sized + TypeFoldable<'tcx> + 'tcx {
let canonical_self =
infcx.canonicalize_hr_query_hack(&query_key, &mut canonical_var_values);
let canonical_result = Self::perform_query(infcx.tcx, canonical_self)?;
let canonical_result = Self::shrink_to_tcx_lifetime(&canonical_result);

let param_env = query_key.param_env;

Expand Down
38 changes: 1 addition & 37 deletions src/librustc/traits/query/type_op/normalize.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
use std::fmt;
use crate::traits::query::Fallible;
use crate::ty::fold::TypeFoldable;
Expand Down Expand Up @@ -38,25 +38,13 @@ where
) -> Fallible<CanonicalizedQueryResponse<'tcx, Self::QueryResponse>> {
T::type_op_method(tcx, canonicalized)
}

fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, T>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, T>> {
T::shrink_to_tcx_lifetime(v)
}
}

pub trait Normalizable<'tcx>: fmt::Debug + TypeFoldable<'tcx> + Lift<'tcx> + Copy {
fn type_op_method(
tcx: TyCtxt<'tcx>,
canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>>;

/// Converts from the `'tcx` (lifted) form of `Self` into the `tcx`
/// form of `Self`.
fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, Self>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>>;
}

impl Normalizable<'tcx> for Ty<'tcx> {
Expand All @@ -66,12 +54,6 @@ impl Normalizable<'tcx> for Ty<'tcx> {
) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> {
tcx.type_op_normalize_ty(canonicalized)
}

fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, Self>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>> {
v
}
}

impl Normalizable<'tcx> for ty::Predicate<'tcx> {
Expand All @@ -81,12 +63,6 @@ impl Normalizable<'tcx> for ty::Predicate<'tcx> {
) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> {
tcx.type_op_normalize_predicate(canonicalized)
}

fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, Self>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>> {
v
}
}

impl Normalizable<'tcx> for ty::PolyFnSig<'tcx> {
Expand All @@ -96,12 +72,6 @@ impl Normalizable<'tcx> for ty::PolyFnSig<'tcx> {
) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> {
tcx.type_op_normalize_poly_fn_sig(canonicalized)
}

fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, Self>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>> {
v
}
}

impl Normalizable<'tcx> for ty::FnSig<'tcx> {
Expand All @@ -111,12 +81,6 @@ impl Normalizable<'tcx> for ty::FnSig<'tcx> {
) -> Fallible<CanonicalizedQueryResponse<'tcx, Self>> {
tcx.type_op_normalize_fn_sig(canonicalized)
}

fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, Self>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>> {
v
}
}

BraceStructTypeFoldableImpl! {
Expand Down
8 changes: 1 addition & 7 deletions src/librustc/traits/query/type_op/outlives.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
use crate::traits::query::dropck_outlives::trivial_dropck_outlives;
use crate::traits::query::dropck_outlives::DropckOutlivesResult;
use crate::traits::query::Fallible;
Expand Down Expand Up @@ -53,12 +53,6 @@ impl super::QueryTypeOp<'tcx> for DropckOutlives<'tcx> {

tcx.dropck_outlives(canonicalized)
}

fn shrink_to_tcx_lifetime(
lifted_query_result: &'a CanonicalizedQueryResponse<'tcx, Self::QueryResponse>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self::QueryResponse>> {
lifted_query_result
}
}

BraceStructTypeFoldableImpl! {
Expand Down
8 changes: 1 addition & 7 deletions src/librustc/traits/query/type_op/prove_predicate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
use crate::traits::query::Fallible;
use crate::ty::{ParamEnvAnd, Predicate, TyCtxt};

Expand Down Expand Up @@ -43,12 +43,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> {
tcx.type_op_prove_predicate(canonicalized)
}

fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, ()>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, ()>> {
v
}
}

BraceStructTypeFoldableImpl! {
Expand Down
8 changes: 1 addition & 7 deletions src/librustc/traits/query/type_op/subtype.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
use crate::traits::query::Fallible;
use crate::ty::{ParamEnvAnd, Ty, TyCtxt};

Expand Down Expand Up @@ -34,12 +34,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for Subtype<'tcx> {
) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> {
tcx.type_op_subtype(canonicalized)
}

fn shrink_to_tcx_lifetime(
v: &'a CanonicalizedQueryResponse<'tcx, ()>,
) -> &'a Canonical<'tcx, QueryResponse<'tcx, ()>> {
v
}
}

BraceStructTypeFoldableImpl! {
Expand Down

0 comments on commit 4469bdd

Please sign in to comment.