Skip to content

Commit 5673943

Browse files
committed
remove Canonicalization trait, which serves no purpose
1 parent e769912 commit 5673943

File tree

9 files changed

+32
-151
lines changed

9 files changed

+32
-151
lines changed

src/librustc/infer/canonical/canonicalizer.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
1818
use infer::canonical::{
1919
Canonical, CanonicalTyVarKind, CanonicalVarInfo, CanonicalVarKind, CanonicalVarValues,
20-
Canonicalize,
20+
Canonicalized,
2121
};
2222
use infer::InferCtxt;
2323
use std::sync::atomic::Ordering;
2424
use ty::fold::{TypeFoldable, TypeFolder};
2525
use ty::subst::Kind;
26-
use ty::{self, CanonicalVar, Slice, Ty, TyCtxt, TypeFlags};
26+
use ty::{self, CanonicalVar, Lift, Slice, Ty, TyCtxt, TypeFlags};
2727

2828
use rustc_data_structures::fx::FxHashMap;
2929
use rustc_data_structures::indexed_vec::IndexVec;
@@ -44,9 +44,12 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
4444
/// out the [chapter in the rustc guide][c].
4545
///
4646
/// [c]: https://rust-lang-nursery.github.io/rustc-guide/traits-canonicalization.html#canonicalizing-the-query
47-
pub fn canonicalize_query<V>(&self, value: &V) -> (V::Canonicalized, CanonicalVarValues<'tcx>)
47+
pub fn canonicalize_query<V>(
48+
&self,
49+
value: &V,
50+
) -> (Canonicalized<'gcx, V>, CanonicalVarValues<'tcx>)
4851
where
49-
V: Canonicalize<'gcx, 'tcx>,
52+
V: TypeFoldable<'tcx> + Lift<'gcx>,
5053
{
5154
self.tcx
5255
.sess
@@ -90,9 +93,9 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
9093
pub fn canonicalize_response<V>(
9194
&self,
9295
value: &V,
93-
) -> (V::Canonicalized, CanonicalVarValues<'tcx>)
96+
) -> (Canonicalized<'gcx, V>, CanonicalVarValues<'tcx>)
9497
where
95-
V: Canonicalize<'gcx, 'tcx>,
98+
V: TypeFoldable<'tcx> + Lift<'gcx>,
9699
{
97100
Canonicalizer::canonicalize(
98101
value,
@@ -233,9 +236,9 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
233236
infcx: Option<&'cx InferCtxt<'cx, 'gcx, 'tcx>>,
234237
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
235238
canonicalize_all_free_regions: CanonicalizeAllFreeRegions,
236-
) -> (V::Canonicalized, CanonicalVarValues<'tcx>)
239+
) -> (Canonicalized<'gcx, V>, CanonicalVarValues<'tcx>)
237240
where
238-
V: Canonicalize<'gcx, 'tcx>,
241+
V: TypeFoldable<'tcx> + Lift<'gcx>,
239242
{
240243
debug_assert!(
241244
!value.has_type_flags(TypeFlags::HAS_CANONICAL_VARS),
@@ -254,13 +257,10 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
254257
// Fast path: nothing that needs to be canonicalized.
255258
if !value.has_type_flags(needs_canonical_flags) {
256259
let out_value = gcx.lift(value).unwrap();
257-
let canon_value = V::intern(
258-
gcx,
259-
Canonical {
260-
variables: Slice::empty(),
261-
value: out_value,
262-
},
263-
);
260+
let canon_value = Canonical {
261+
variables: Slice::empty(),
262+
value: out_value,
263+
};
264264
let values = CanonicalVarValues {
265265
var_values: IndexVec::default(),
266266
};
@@ -291,13 +291,10 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
291291

292292
let canonical_variables = tcx.intern_canonical_var_infos(&canonicalizer.variables.raw);
293293

294-
let canonical_value = V::intern(
295-
gcx,
296-
Canonical {
297-
variables: canonical_variables,
298-
value: out_value,
299-
},
300-
);
294+
let canonical_value = Canonical {
295+
variables: canonical_variables,
296+
value: out_value,
297+
};
301298
let canonical_var_values = CanonicalVarValues {
302299
var_values: canonicalizer.var_values,
303300
};

src/librustc/infer/canonical/mod.rs

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin};
3535
use rustc_data_structures::indexed_vec::IndexVec;
3636
use rustc_data_structures::sync::Lrc;
3737
use serialize::UseSpecializedDecodable;
38-
use std::fmt::Debug;
3938
use std::ops::Index;
4039
use syntax::codemap::Span;
4140
use ty::fold::TypeFoldable;
@@ -124,6 +123,8 @@ pub struct QueryResult<'tcx, R> {
124123
pub value: R,
125124
}
126125

126+
pub type Canonicalized<'gcx, V> = Canonical<'gcx, <V as Lift<'gcx>>::Lifted>;
127+
127128
pub type CanonicalizedQueryResult<'gcx, T> =
128129
Lrc<Canonical<'gcx, QueryResult<'gcx, <T as Lift<'gcx>>::Lifted>>>;
129130

@@ -184,19 +185,6 @@ impl<'tcx, R> Canonical<'tcx, QueryResult<'tcx, R>> {
184185

185186
pub type QueryRegionConstraint<'tcx> = ty::Binder<ty::OutlivesPredicate<Kind<'tcx>, Region<'tcx>>>;
186187

187-
/// Trait implemented by values that can be canonicalized. It mainly
188-
/// serves to identify the interning table we will use.
189-
pub trait Canonicalize<'gcx: 'tcx, 'tcx>: TypeFoldable<'tcx> + Lift<'gcx> {
190-
type Canonicalized: 'gcx + Debug;
191-
192-
/// After a value has been fully canonicalized and lifted, this
193-
/// method will allocate it in a global arena.
194-
fn intern(
195-
gcx: TyCtxt<'_, 'gcx, 'gcx>,
196-
value: Canonical<'gcx, Self::Lifted>,
197-
) -> Self::Canonicalized;
198-
}
199-
200188
impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
201189
/// Creates a substitution S for the canonical value with fresh
202190
/// inference variables and applies it to the canonical value.
@@ -344,18 +332,3 @@ impl<'tcx> Index<CanonicalVar> for CanonicalVarValues<'tcx> {
344332
&self.var_values[value]
345333
}
346334
}
347-
348-
impl<'gcx: 'tcx, 'tcx, T> Canonicalize<'gcx, 'tcx> for QueryResult<'tcx, T>
349-
where
350-
T: TypeFoldable<'tcx> + Lift<'gcx>,
351-
{
352-
// we ought to intern this, but I'm too lazy just now
353-
type Canonicalized = Lrc<Canonical<'gcx, QueryResult<'gcx, T::Lifted>>>;
354-
355-
fn intern(
356-
_gcx: TyCtxt<'_, 'gcx, 'gcx>,
357-
value: Canonical<'gcx, Self::Lifted>,
358-
) -> Self::Canonicalized {
359-
Lrc::new(value)
360-
}
361-
}

src/librustc/infer/canonical/query_result.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
2020
use infer::canonical::substitute::substitute_value;
2121
use infer::canonical::{
22-
Canonical, CanonicalVarValues, Canonicalize, CanonicalizedQueryResult, Certainty,
22+
Canonical, CanonicalVarValues, CanonicalizedQueryResult, Certainty,
2323
QueryRegionConstraint, QueryResult,
2424
};
2525
use infer::region_constraints::{Constraint, RegionConstraintData};
2626
use infer::{InferCtxt, InferOk, InferResult, RegionObligation};
2727
use rustc_data_structures::indexed_vec::Idx;
2828
use rustc_data_structures::indexed_vec::IndexVec;
29+
use rustc_data_structures::sync::Lrc;
2930
use std::fmt::Debug;
3031
use syntax::ast;
3132
use traits::query::NoSolution;
@@ -72,7 +73,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
7273
canonical_result
7374
);
7475

75-
Ok(canonical_result)
76+
Ok(Lrc::new(canonical_result))
7677
}
7778

7879
/// Helper for `make_canonicalized_query_result` that does
@@ -84,8 +85,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
8485
fulfill_cx: &mut FulfillmentContext<'tcx>,
8586
) -> Result<QueryResult<'tcx, T>, NoSolution>
8687
where
87-
T: Debug,
88-
QueryResult<'tcx, T>: Canonicalize<'gcx, 'tcx>,
88+
T: Debug + TypeFoldable<'tcx> + Lift<'gcx>,
8989
{
9090
let tcx = self.tcx;
9191

src/librustc/traits/mod.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use ty::subst::Substs;
2727
use ty::{self, AdtKind, Slice, Ty, TyCtxt, GenericParamDefKind, ToPredicate};
2828
use ty::error::{ExpectedFound, TypeError};
2929
use ty::fold::{TypeFolder, TypeFoldable, TypeVisitor};
30-
use infer::canonical::{Canonical, Canonicalize};
3130
use infer::{InferCtxt};
3231

3332
use rustc_data_structures::sync::Lrc;
@@ -1015,18 +1014,6 @@ pub fn provide(providers: &mut ty::query::Providers) {
10151014
};
10161015
}
10171016

1018-
impl<'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for ty::ParamEnvAnd<'tcx, Goal<'tcx>> {
1019-
// we ought to intern this, but I'm too lazy just now
1020-
type Canonicalized = Canonical<'gcx, ty::ParamEnvAnd<'gcx, Goal<'gcx>>>;
1021-
1022-
fn intern(
1023-
_gcx: TyCtxt<'_, 'gcx, 'gcx>,
1024-
value: Canonical<'gcx, Self::Lifted>,
1025-
) -> Self::Canonicalized {
1026-
value
1027-
}
1028-
}
1029-
10301017
pub trait ExClauseFold<'tcx>
10311018
where
10321019
Self: chalk_engine::context::Context + Clone,
@@ -1053,20 +1040,3 @@ where
10531040
tcx: TyCtxt<'a, 'gcx, 'tcx>,
10541041
) -> Option<Self::LiftedExClause>;
10551042
}
1056-
1057-
impl<'gcx: 'tcx, 'tcx, C> Canonicalize<'gcx, 'tcx> for chalk_engine::ExClause<C>
1058-
where
1059-
C: chalk_engine::context::Context + Clone,
1060-
C: ExClauseLift<'gcx> + ExClauseFold<'tcx>,
1061-
C::Substitution: Clone,
1062-
C::RegionConstraint: Clone,
1063-
{
1064-
type Canonicalized = Canonical<'gcx, C::LiftedExClause>;
1065-
1066-
fn intern(
1067-
_gcx: TyCtxt<'_, 'gcx, 'gcx>,
1068-
value: Canonical<'gcx, Self::Lifted>,
1069-
) -> Self::Canonicalized {
1070-
value
1071-
}
1072-
}

src/librustc/traits/query/dropck_outlives.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@
99
// except according to those terms.
1010

1111
use infer::at::At;
12-
use infer::canonical::{Canonical, Canonicalize};
1312
use infer::InferOk;
1413
use std::iter::FromIterator;
15-
use traits::query::CanonicalTyGoal;
16-
use ty::{self, Ty, TyCtxt};
1714
use ty::subst::Kind;
15+
use ty::{self, Ty, TyCtxt};
1816

1917
impl<'cx, 'gcx, 'tcx> At<'cx, 'gcx, 'tcx> {
2018
/// Given a type `ty` of some value being dropped, computes a set
@@ -44,7 +42,10 @@ impl<'cx, 'gcx, 'tcx> At<'cx, 'gcx, 'tcx> {
4442
// any destructor.
4543
let tcx = self.infcx.tcx;
4644
if trivial_dropck_outlives(tcx, ty) {
47-
return InferOk { value: vec![], obligations: vec![] };
45+
return InferOk {
46+
value: vec![],
47+
obligations: vec![],
48+
};
4849
}
4950

5051
let gcx = tcx.global_tcx();
@@ -152,17 +153,6 @@ impl<'tcx> FromIterator<DtorckConstraint<'tcx>> for DtorckConstraint<'tcx> {
152153
result
153154
}
154155
}
155-
impl<'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for ty::ParamEnvAnd<'tcx, Ty<'tcx>> {
156-
type Canonicalized = CanonicalTyGoal<'gcx>;
157-
158-
fn intern(
159-
_gcx: TyCtxt<'_, 'gcx, 'gcx>,
160-
value: Canonical<'gcx, Self::Lifted>,
161-
) -> Self::Canonicalized {
162-
value
163-
}
164-
}
165-
166156
BraceStructTypeFoldableImpl! {
167157
impl<'tcx> TypeFoldable<'tcx> for DropckOutlivesResult<'tcx> {
168158
kinds, overflows

src/librustc/traits/query/evaluate_obligation.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99
// except according to those terms.
1010

1111
use infer::InferCtxt;
12-
use infer::canonical::{Canonical, Canonicalize};
1312
use traits::{EvaluationResult, PredicateObligation, SelectionContext,
1413
TraitQueryMode, OverflowError};
15-
use traits::query::CanonicalPredicateGoal;
16-
use ty::{ParamEnvAnd, Predicate, TyCtxt};
1714

1815
impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
1916
/// Evaluates whether the predicate can be satisfied (by any means)
@@ -57,14 +54,3 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
5754
}
5855
}
5956
}
60-
61-
impl<'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for ParamEnvAnd<'tcx, Predicate<'tcx>> {
62-
type Canonicalized = CanonicalPredicateGoal<'gcx>;
63-
64-
fn intern(
65-
_gcx: TyCtxt<'_, 'gcx, 'gcx>,
66-
value: Canonical<'gcx, Self::Lifted>,
67-
) -> Self::Canonicalized {
68-
value
69-
}
70-
}

src/librustc/traits/query/normalize.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
1515
use infer::{InferCtxt, InferOk};
1616
use infer::at::At;
17-
use infer::canonical::{Canonical, Canonicalize};
1817
use middle::const_val::ConstVal;
1918
use mir::interpret::GlobalId;
2019
use traits::{Obligation, ObligationCause, PredicateObligation, Reveal};
21-
use traits::query::CanonicalProjectionGoal;
2220
use traits::project::Normalized;
2321
use ty::{self, Ty, TyCtxt};
2422
use ty::fold::{TypeFoldable, TypeFolder};
@@ -250,17 +248,6 @@ BraceStructLiftImpl! {
250248
}
251249
}
252250

253-
impl<'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for ty::ParamEnvAnd<'tcx, ty::ProjectionTy<'tcx>> {
254-
type Canonicalized = CanonicalProjectionGoal<'gcx>;
255-
256-
fn intern(
257-
_gcx: TyCtxt<'_, 'gcx, 'gcx>,
258-
value: Canonical<'gcx, Self::Lifted>,
259-
) -> Self::Canonicalized {
260-
value
261-
}
262-
}
263-
264251
impl_stable_hash_for!(struct NormalizationResult<'tcx> {
265252
normalized_ty
266253
});

src/librustc/ty/mod.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use hir::map::DefPathData;
2121
use hir::svh::Svh;
2222
use ich::Fingerprint;
2323
use ich::StableHashingContext;
24-
use infer::canonical::{Canonical, Canonicalize};
24+
use infer::canonical::Canonical;
2525
use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};
2626
use middle::privacy::AccessLevels;
2727
use middle::resolve_lifetime::ObjectLifetimeDefault;
@@ -591,15 +591,6 @@ impl<'tcx> serialize::UseSpecializedDecodable for Ty<'tcx> {}
591591

592592
pub type CanonicalTy<'gcx> = Canonical<'gcx, Ty<'gcx>>;
593593

594-
impl <'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for Ty<'tcx> {
595-
type Canonicalized = CanonicalTy<'gcx>;
596-
597-
fn intern(_gcx: TyCtxt<'_, 'gcx, 'gcx>,
598-
value: Canonical<'gcx, Self::Lifted>) -> Self::Canonicalized {
599-
value
600-
}
601-
}
602-
603594
extern {
604595
/// A dummy type used to force Slice to by unsized without requiring fat pointers
605596
type OpaqueSliceContents;

src/librustc_traits/chalk_context.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
use chalk_engine::fallible::Fallible as ChalkEngineFallible;
1212
use chalk_engine::{context, hh::HhGoal, DelayedLiteral, ExClause};
13-
use rustc::infer::canonical::{
14-
Canonical, CanonicalVarValues, Canonicalize, QueryRegionConstraint, QueryResult,
15-
};
13+
use rustc::infer::canonical::{Canonical, CanonicalVarValues, QueryRegionConstraint, QueryResult};
1614
use rustc::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime};
1715
use rustc::traits::{
1816
WellFormed,
@@ -519,14 +517,3 @@ BraceStructLiftImpl! {
519517
subst, constraints
520518
}
521519
}
522-
523-
impl<'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for ConstrainedSubst<'tcx> {
524-
type Canonicalized = Canonical<'gcx, ConstrainedSubst<'gcx>>;
525-
526-
fn intern(
527-
_gcx: TyCtxt<'_, 'gcx, 'gcx>,
528-
value: Canonical<'gcx, ConstrainedSubst<'gcx>>,
529-
) -> Self::Canonicalized {
530-
value
531-
}
532-
}

0 commit comments

Comments
 (0)