Skip to content

Commit 618b01f

Browse files
committed
Auto merge of #66454 - cjgillot:lift, r=Zoxc
Derive Lift using a proc-macro Based on #66384 r? @Zoxc
2 parents 9d6ff15 + a65091f commit 618b01f

24 files changed

+87
-322
lines changed

src/librustc/infer/canonical/mod.rs

+5-33
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use std::ops::Index;
3232
use syntax::source_map::Span;
3333
use crate::ty::fold::TypeFoldable;
3434
use crate::ty::subst::GenericArg;
35-
use crate::ty::{self, BoundVar, Lift, List, Region, TyCtxt};
35+
use crate::ty::{self, BoundVar, List, Region, TyCtxt};
3636

3737
mod canonicalizer;
3838

@@ -44,7 +44,7 @@ mod substitute;
4444
/// variables have been rewritten to "canonical vars". These are
4545
/// numbered starting from 0 in order of first appearance.
4646
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable)]
47-
#[derive(HashStable, TypeFoldable)]
47+
#[derive(HashStable, TypeFoldable, Lift)]
4848
pub struct Canonical<'tcx, V> {
4949
pub max_universe: ty::UniverseIndex,
5050
pub variables: CanonicalVarInfos<'tcx>,
@@ -65,7 +65,7 @@ impl<'tcx> UseSpecializedDecodable for CanonicalVarInfos<'tcx> {}
6565
/// variables. You will need to supply it later to instantiate the
6666
/// canonicalized query response.
6767
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable)]
68-
#[derive(HashStable, TypeFoldable)]
68+
#[derive(HashStable, TypeFoldable, Lift)]
6969
pub struct CanonicalVarValues<'tcx> {
7070
pub var_values: IndexVec<BoundVar, GenericArg<'tcx>>,
7171
}
@@ -188,15 +188,15 @@ pub enum CanonicalTyVarKind {
188188
/// After we execute a query with a canonicalized key, we get back a
189189
/// `Canonical<QueryResponse<..>>`. You can use
190190
/// `instantiate_query_result` to access the data in this result.
191-
#[derive(Clone, Debug, HashStable, TypeFoldable)]
191+
#[derive(Clone, Debug, HashStable, TypeFoldable, Lift)]
192192
pub struct QueryResponse<'tcx, R> {
193193
pub var_values: CanonicalVarValues<'tcx>,
194194
pub region_constraints: QueryRegionConstraints<'tcx>,
195195
pub certainty: Certainty,
196196
pub value: R,
197197
}
198198

199-
#[derive(Clone, Debug, Default, HashStable, TypeFoldable)]
199+
#[derive(Clone, Debug, Default, HashStable, TypeFoldable, Lift)]
200200
pub struct QueryRegionConstraints<'tcx> {
201201
pub outlives: Vec<QueryOutlivesConstraint<'tcx>>,
202202
pub member_constraints: Vec<MemberConstraint<'tcx>>,
@@ -469,13 +469,6 @@ CloneTypeFoldableImpls! {
469469
}
470470
}
471471

472-
BraceStructLiftImpl! {
473-
impl<'a, 'tcx, T> Lift<'tcx> for Canonical<'a, T> {
474-
type Lifted = Canonical<'tcx, T::Lifted>;
475-
max_universe, variables, value
476-
} where T: Lift<'tcx>
477-
}
478-
479472
impl<'tcx> CanonicalVarValues<'tcx> {
480473
pub fn len(&self) -> usize {
481474
self.var_values.len()
@@ -521,27 +514,6 @@ impl<'a, 'tcx> IntoIterator for &'a CanonicalVarValues<'tcx> {
521514
}
522515
}
523516

524-
BraceStructLiftImpl! {
525-
impl<'a, 'tcx> Lift<'tcx> for CanonicalVarValues<'a> {
526-
type Lifted = CanonicalVarValues<'tcx>;
527-
var_values,
528-
}
529-
}
530-
531-
BraceStructLiftImpl! {
532-
impl<'a, 'tcx, R> Lift<'tcx> for QueryResponse<'a, R> {
533-
type Lifted = QueryResponse<'tcx, R::Lifted>;
534-
var_values, region_constraints, certainty, value
535-
} where R: Lift<'tcx>
536-
}
537-
538-
BraceStructLiftImpl! {
539-
impl<'a, 'tcx> Lift<'tcx> for QueryRegionConstraints<'a> {
540-
type Lifted = QueryRegionConstraints<'tcx>;
541-
outlives, member_constraints
542-
}
543-
}
544-
545517
impl<'tcx> Index<BoundVar> for CanonicalVarValues<'tcx> {
546518
type Output = GenericArg<'tcx>;
547519

src/librustc/infer/region_constraints/mod.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl Constraint<'_> {
151151
/// ```
152152
/// R0 member of [O1..On]
153153
/// ```
154-
#[derive(Debug, Clone, HashStable, TypeFoldable)]
154+
#[derive(Debug, Clone, HashStable, TypeFoldable, Lift)]
155155
pub struct MemberConstraint<'tcx> {
156156
/// The `DefId` of the opaque type causing this constraint: used for error reporting.
157157
pub opaque_type_def_id: DefId,
@@ -169,13 +169,6 @@ pub struct MemberConstraint<'tcx> {
169169
pub choice_regions: Lrc<Vec<Region<'tcx>>>,
170170
}
171171

172-
BraceStructLiftImpl! {
173-
impl<'a, 'tcx> Lift<'tcx> for MemberConstraint<'a> {
174-
type Lifted = MemberConstraint<'tcx>;
175-
opaque_type_def_id, definition_span, hidden_ty, member_region, choice_regions
176-
}
177-
}
178-
179172
/// `VerifyGenericBound(T, _, R, RS)`: the parameter type `T` (or
180173
/// associated type) must outlive the region `R`. `T` is known to
181174
/// outlive `RS`. Therefore, verify that `R <= RS[i]` for some

src/librustc/macros.rs

-71
Original file line numberDiff line numberDiff line change
@@ -253,77 +253,6 @@ macro_rules! CloneTypeFoldableAndLiftImpls {
253253
}
254254
}
255255

256-
#[macro_export]
257-
macro_rules! BraceStructLiftImpl {
258-
(impl<$($p:tt),*> Lift<$tcx:tt> for $s:path {
259-
type Lifted = $lifted:ty;
260-
$($field:ident),* $(,)?
261-
} $(where $($wc:tt)*)*) => {
262-
impl<$($p),*> $crate::ty::Lift<$tcx> for $s
263-
$(where $($wc)*)*
264-
{
265-
type Lifted = $lifted;
266-
267-
fn lift_to_tcx(&self, tcx: TyCtxt<$tcx>) -> Option<$lifted> {
268-
$(let $field = tcx.lift(&self.$field)?;)*
269-
Some(Self::Lifted { $($field),* })
270-
}
271-
}
272-
};
273-
}
274-
275-
#[macro_export]
276-
macro_rules! EnumLiftImpl {
277-
(impl<$($p:tt),*> Lift<$tcx:tt> for $s:path {
278-
type Lifted = $lifted:ty;
279-
$($variants:tt)*
280-
} $(where $($wc:tt)*)*) => {
281-
impl<$($p),*> $crate::ty::Lift<$tcx> for $s
282-
$(where $($wc)*)*
283-
{
284-
type Lifted = $lifted;
285-
286-
fn lift_to_tcx(&self, tcx: TyCtxt<$tcx>) -> Option<$lifted> {
287-
EnumLiftImpl!(@Variants(self, tcx) input($($variants)*) output())
288-
}
289-
}
290-
};
291-
292-
(@Variants($this:expr, $tcx:expr) input() output($($output:tt)*)) => {
293-
match $this {
294-
$($output)*
295-
}
296-
};
297-
298-
(@Variants($this:expr, $tcx:expr)
299-
input( ($variant:path) ( $($variant_arg:ident),* ) , $($input:tt)*)
300-
output( $($output:tt)*) ) => {
301-
EnumLiftImpl!(
302-
@Variants($this, $tcx)
303-
input($($input)*)
304-
output(
305-
$variant ( $($variant_arg),* ) => {
306-
Some($variant ( $($tcx.lift($variant_arg)?),* ))
307-
}
308-
$($output)*
309-
)
310-
)
311-
};
312-
313-
(@Variants($this:expr, $tcx:expr)
314-
input( ($variant:path), $($input:tt)*)
315-
output( $($output:tt)*) ) => {
316-
EnumLiftImpl!(
317-
@Variants($this, $tcx)
318-
input($($input)*)
319-
output(
320-
$variant => { Some($variant) }
321-
$($output)*
322-
)
323-
)
324-
};
325-
}
326-
327256
#[macro_export]
328257
macro_rules! EnumTypeFoldableImpl {
329258
(impl<$($p:tt),*> TypeFoldable<$tcx:tt> for $s:path {

src/librustc/mir/interpret/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ use rustc_macros::HashStable;
124124
use byteorder::{WriteBytesExt, ReadBytesExt, LittleEndian, BigEndian};
125125

126126
/// Uniquely identifies a specific constant or static.
127-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, RustcEncodable, RustcDecodable, HashStable)]
127+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, RustcEncodable, RustcDecodable)]
128+
#[derive(HashStable, Lift)]
128129
pub struct GlobalId<'tcx> {
129130
/// For a constant or static, the `Instance` of the item itself.
130131
/// For a promoted global, the `Instance` of the function they belong to.

src/librustc/traits/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -334,27 +334,27 @@ pub type TraitObligations<'tcx> = Vec<TraitObligation<'tcx>>;
334334
/// are used for representing the trait system in the form of
335335
/// logic programming clauses. They are part of the interface
336336
/// for the chalk SLG solver.
337-
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable)]
337+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable, Lift)]
338338
pub enum WhereClause<'tcx> {
339339
Implemented(ty::TraitPredicate<'tcx>),
340340
ProjectionEq(ty::ProjectionPredicate<'tcx>),
341341
RegionOutlives(ty::RegionOutlivesPredicate<'tcx>),
342342
TypeOutlives(ty::TypeOutlivesPredicate<'tcx>),
343343
}
344344

345-
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable)]
345+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable, Lift)]
346346
pub enum WellFormed<'tcx> {
347347
Trait(ty::TraitPredicate<'tcx>),
348348
Ty(Ty<'tcx>),
349349
}
350350

351-
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable)]
351+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable, Lift)]
352352
pub enum FromEnv<'tcx> {
353353
Trait(ty::TraitPredicate<'tcx>),
354354
Ty(Ty<'tcx>),
355355
}
356356

357-
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable)]
357+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable, Lift)]
358358
pub enum DomainGoal<'tcx> {
359359
Holds(WhereClause<'tcx>),
360360
WellFormed(WellFormed<'tcx>),
@@ -370,7 +370,7 @@ pub enum QuantifierKind {
370370
Existential,
371371
}
372372

373-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable)]
373+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable, Lift)]
374374
pub enum GoalKind<'tcx> {
375375
Implies(Clauses<'tcx>, Goal<'tcx>),
376376
And(Goal<'tcx>, Goal<'tcx>),

src/librustc/traits/query/dropck_outlives.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<'cx, 'tcx> At<'cx, 'tcx> {
7979
}
8080
}
8181

82-
#[derive(Clone, Debug, Default, TypeFoldable)]
82+
#[derive(Clone, Debug, Default, TypeFoldable, Lift)]
8383
pub struct DropckOutlivesResult<'tcx> {
8484
pub kinds: Vec<GenericArg<'tcx>>,
8585
pub overflows: Vec<Ty<'tcx>>,
@@ -152,13 +152,6 @@ impl<'tcx> FromIterator<DtorckConstraint<'tcx>> for DtorckConstraint<'tcx> {
152152
result
153153
}
154154
}
155-
BraceStructLiftImpl! {
156-
impl<'a, 'tcx> Lift<'tcx> for DropckOutlivesResult<'a> {
157-
type Lifted = DropckOutlivesResult<'tcx>;
158-
kinds, overflows
159-
}
160-
}
161-
162155
impl_stable_hash_for!(struct DropckOutlivesResult<'tcx> {
163156
kinds, overflows
164157
});

src/librustc/traits/query/normalize.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'cx, 'tcx> At<'cx, 'tcx> {
6666
}
6767

6868
/// Result from the `normalize_projection_ty` query.
69-
#[derive(Clone, Debug, TypeFoldable)]
69+
#[derive(Clone, Debug, TypeFoldable, Lift)]
7070
pub struct NormalizationResult<'tcx> {
7171
/// Result of normalization.
7272
pub normalized_ty: Ty<'tcx>,
@@ -194,13 +194,6 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
194194
}
195195
}
196196

197-
BraceStructLiftImpl! {
198-
impl<'a, 'tcx> Lift<'tcx> for NormalizationResult<'a> {
199-
type Lifted = NormalizationResult<'tcx>;
200-
normalized_ty
201-
}
202-
}
203-
204197
impl_stable_hash_for!(struct NormalizationResult<'tcx> {
205198
normalized_ty
206199
});

src/librustc/traits/query/outlives_bounds.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::hir;
44
use syntax::source_map::Span;
55
use crate::traits::{FulfillmentContext, ObligationCause, TraitEngine, TraitEngineExt};
66
use crate::traits::query::NoSolution;
7-
use crate::ty::{self, Ty, TyCtxt};
7+
use crate::ty::{self, Ty};
88

99
use crate::ich::StableHashingContext;
1010
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -17,22 +17,13 @@ use std::mem;
1717
/// case they are called implied bounds). They are fed to the
1818
/// `OutlivesEnv` which in turn is supplied to the region checker and
1919
/// other parts of the inference system.
20-
#[derive(Clone, Debug, TypeFoldable)]
20+
#[derive(Clone, Debug, TypeFoldable, Lift)]
2121
pub enum OutlivesBound<'tcx> {
2222
RegionSubRegion(ty::Region<'tcx>, ty::Region<'tcx>),
2323
RegionSubParam(ty::Region<'tcx>, ty::ParamTy),
2424
RegionSubProjection(ty::Region<'tcx>, ty::ProjectionTy<'tcx>),
2525
}
2626

27-
EnumLiftImpl! {
28-
impl<'a, 'tcx> Lift<'tcx> for self::OutlivesBound<'a> {
29-
type Lifted = self::OutlivesBound<'tcx>;
30-
(self::OutlivesBound::RegionSubRegion)(a, b),
31-
(self::OutlivesBound::RegionSubParam)(a, b),
32-
(self::OutlivesBound::RegionSubProjection)(a, b),
33-
}
34-
}
35-
3627
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for OutlivesBound<'tcx> {
3728
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
3829
mem::discriminant(self).hash_stable(hcx, hasher);

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

+1-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::hir::def_id::DefId;
44
use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
55
use crate::ty::subst::UserSubsts;
66

7-
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, TypeFoldable)]
7+
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, TypeFoldable, Lift)]
88
pub struct AscribeUserType<'tcx> {
99
pub mir_ty: Ty<'tcx>,
1010
pub def_id: DefId,
@@ -39,13 +39,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for AscribeUserType<'tcx> {
3939
}
4040
}
4141

42-
BraceStructLiftImpl! {
43-
impl<'a, 'tcx> Lift<'tcx> for AscribeUserType<'a> {
44-
type Lifted = AscribeUserType<'tcx>;
45-
mir_ty, def_id, user_substs
46-
}
47-
}
48-
4942
impl_stable_hash_for! {
5043
struct AscribeUserType<'tcx> {
5144
mir_ty, def_id, user_substs

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

+1-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
22
use crate::traits::query::Fallible;
33
use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
44

5-
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, TypeFoldable)]
5+
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, TypeFoldable, Lift)]
66
pub struct Eq<'tcx> {
77
pub a: Ty<'tcx>,
88
pub b: Ty<'tcx>,
@@ -36,14 +36,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for Eq<'tcx> {
3636
}
3737
}
3838

39-
BraceStructLiftImpl! {
40-
impl<'a, 'tcx> Lift<'tcx> for Eq<'a> {
41-
type Lifted = Eq<'tcx>;
42-
a,
43-
b,
44-
}
45-
}
46-
4739
impl_stable_hash_for! {
4840
struct Eq<'tcx> { a, b }
4941
}

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

+1-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::traits::query::outlives_bounds::OutlivesBound;
33
use crate::traits::query::Fallible;
44
use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
55

6-
#[derive(Clone, Debug, TypeFoldable)]
6+
#[derive(Clone, Debug, TypeFoldable, Lift)]
77
pub struct ImpliedOutlivesBounds<'tcx> {
88
pub ty: Ty<'tcx>,
99
}
@@ -40,13 +40,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ImpliedOutlivesBounds<'tcx> {
4040
}
4141
}
4242

43-
BraceStructLiftImpl! {
44-
impl<'a, 'tcx> Lift<'tcx> for ImpliedOutlivesBounds<'a> {
45-
type Lifted = ImpliedOutlivesBounds<'tcx>;
46-
ty,
47-
}
48-
}
49-
5043
impl_stable_hash_for! {
5144
struct ImpliedOutlivesBounds<'tcx> { ty }
5245
}

0 commit comments

Comments
 (0)