Skip to content

Commit 17692b5

Browse files
committed
Use TypeFoldable derive macro.
1 parent 9e28e9c commit 17692b5

27 files changed

+90
-688
lines changed

src/librustc/infer/canonical/mod.rs

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ mod substitute;
4444
/// A "canonicalized" type `V` is one where all free inference
4545
/// variables have been rewritten to "canonical vars". These are
4646
/// numbered starting from 0 in order of first appearance.
47-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable, HashStable)]
47+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable,
48+
HashStable, TypeFoldable)]
4849
pub struct Canonical<'tcx, V> {
4950
pub max_universe: ty::UniverseIndex,
5051
pub variables: CanonicalVarInfos<'tcx>,
@@ -64,7 +65,8 @@ impl<'tcx> UseSpecializedDecodable for CanonicalVarInfos<'tcx> {}
6465
/// vectors with the original values that were replaced by canonical
6566
/// variables. You will need to supply it later to instantiate the
6667
/// canonicalized query response.
67-
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable, HashStable)]
68+
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable,
69+
HashStable, TypeFoldable)]
6870
pub struct CanonicalVarValues<'tcx> {
6971
pub var_values: IndexVec<BoundVar, GenericArg<'tcx>>,
7072
}
@@ -187,15 +189,15 @@ pub enum CanonicalTyVarKind {
187189
/// After we execute a query with a canonicalized key, we get back a
188190
/// `Canonical<QueryResponse<..>>`. You can use
189191
/// `instantiate_query_result` to access the data in this result.
190-
#[derive(Clone, Debug, HashStable)]
192+
#[derive(Clone, Debug, HashStable, TypeFoldable)]
191193
pub struct QueryResponse<'tcx, R> {
192194
pub var_values: CanonicalVarValues<'tcx>,
193195
pub region_constraints: QueryRegionConstraints<'tcx>,
194196
pub certainty: Certainty,
195197
pub value: R,
196198
}
197199

198-
#[derive(Clone, Debug, Default, HashStable)]
200+
#[derive(Clone, Debug, Default, HashStable, TypeFoldable)]
199201
pub struct QueryRegionConstraints<'tcx> {
200202
pub outlives: Vec<QueryOutlivesConstraint<'tcx>>,
201203
pub member_constraints: Vec<MemberConstraint<'tcx>>,
@@ -468,14 +470,6 @@ CloneTypeFoldableImpls! {
468470
}
469471
}
470472

471-
BraceStructTypeFoldableImpl! {
472-
impl<'tcx, C> TypeFoldable<'tcx> for Canonical<'tcx, C> {
473-
max_universe,
474-
variables,
475-
value,
476-
} where C: TypeFoldable<'tcx>
477-
}
478-
479473
BraceStructLiftImpl! {
480474
impl<'a, 'tcx, T> Lift<'tcx> for Canonical<'a, T> {
481475
type Lifted = Canonical<'tcx, T::Lifted>;
@@ -535,31 +529,13 @@ BraceStructLiftImpl! {
535529
}
536530
}
537531

538-
BraceStructTypeFoldableImpl! {
539-
impl<'tcx> TypeFoldable<'tcx> for CanonicalVarValues<'tcx> {
540-
var_values,
541-
}
542-
}
543-
544-
BraceStructTypeFoldableImpl! {
545-
impl<'tcx, R> TypeFoldable<'tcx> for QueryResponse<'tcx, R> {
546-
var_values, region_constraints, certainty, value
547-
} where R: TypeFoldable<'tcx>,
548-
}
549-
550532
BraceStructLiftImpl! {
551533
impl<'a, 'tcx, R> Lift<'tcx> for QueryResponse<'a, R> {
552534
type Lifted = QueryResponse<'tcx, R::Lifted>;
553535
var_values, region_constraints, certainty, value
554536
} where R: Lift<'tcx>
555537
}
556538

557-
BraceStructTypeFoldableImpl! {
558-
impl<'tcx> TypeFoldable<'tcx> for QueryRegionConstraints<'tcx> {
559-
outlives, member_constraints
560-
}
561-
}
562-
563539
BraceStructLiftImpl! {
564540
impl<'a, 'tcx> Lift<'tcx> for QueryRegionConstraints<'a> {
565541
type Lifted = QueryRegionConstraints<'tcx>;

src/librustc/infer/mod.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ pub struct InferCtxt<'a, 'tcx> {
233233
pub type PlaceholderMap<'tcx> = BTreeMap<ty::BoundRegion, ty::Region<'tcx>>;
234234

235235
/// See the `error_reporting` module for more details.
236-
#[derive(Clone, Debug, PartialEq, Eq)]
236+
#[derive(Clone, Debug, PartialEq, Eq, TypeFoldable)]
237237
pub enum ValuePairs<'tcx> {
238238
Types(ExpectedFound<Ty<'tcx>>),
239239
Regions(ExpectedFound<ty::Region<'tcx>>),
@@ -1782,16 +1782,6 @@ impl RegionVariableOrigin {
17821782
}
17831783
}
17841784

1785-
EnumTypeFoldableImpl! {
1786-
impl<'tcx> TypeFoldable<'tcx> for ValuePairs<'tcx> {
1787-
(ValuePairs::Types)(a),
1788-
(ValuePairs::Regions)(a),
1789-
(ValuePairs::Consts)(a),
1790-
(ValuePairs::TraitRefs)(a),
1791-
(ValuePairs::PolyTraitRefs)(a),
1792-
}
1793-
}
1794-
17951785
impl<'tcx> fmt::Debug for RegionObligation<'tcx> {
17961786
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17971787
write!(

src/librustc/infer/region_constraints/mod.rs

Lines changed: 2 additions & 15 deletions
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)]
154+
#[derive(Debug, Clone, HashStable, TypeFoldable)]
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,12 +169,6 @@ pub struct MemberConstraint<'tcx> {
169169
pub choice_regions: Lrc<Vec<Region<'tcx>>>,
170170
}
171171

172-
BraceStructTypeFoldableImpl! {
173-
impl<'tcx> TypeFoldable<'tcx> for MemberConstraint<'tcx> {
174-
opaque_type_def_id, definition_span, hidden_ty, member_region, choice_regions
175-
}
176-
}
177-
178172
BraceStructLiftImpl! {
179173
impl<'a, 'tcx> Lift<'tcx> for MemberConstraint<'a> {
180174
type Lifted = MemberConstraint<'tcx>;
@@ -195,19 +189,12 @@ pub struct Verify<'tcx> {
195189
pub bound: VerifyBound<'tcx>,
196190
}
197191

198-
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
192+
#[derive(Copy, Clone, PartialEq, Eq, Hash, TypeFoldable)]
199193
pub enum GenericKind<'tcx> {
200194
Param(ty::ParamTy),
201195
Projection(ty::ProjectionTy<'tcx>),
202196
}
203197

204-
EnumTypeFoldableImpl! {
205-
impl<'tcx> TypeFoldable<'tcx> for GenericKind<'tcx> {
206-
(GenericKind::Param)(a),
207-
(GenericKind::Projection)(a),
208-
}
209-
}
210-
211198
/// Describes the things that some `GenericKind` value `G` is known to
212199
/// outlive. Each variant of `VerifyBound` can be thought of as a
213200
/// function:

src/librustc/mir/mod.rs

Lines changed: 9 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl MirPhase {
8686
}
8787

8888
/// The lowered representation of a single function.
89-
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
89+
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, TypeFoldable)]
9090
pub struct Body<'tcx> {
9191
/// A list of basic blocks. References to basic block use a newtyped index type `BasicBlock`
9292
/// that indexes into this vector.
@@ -446,7 +446,7 @@ impl<'tcx> IndexMut<BasicBlock> for Body<'tcx> {
446446
}
447447
}
448448

449-
#[derive(Copy, Clone, Debug, HashStable)]
449+
#[derive(Copy, Clone, Debug, HashStable, TypeFoldable)]
450450
pub enum ClearCrossCrate<T> {
451451
Clear,
452452
Set(T),
@@ -723,7 +723,7 @@ impl_stable_hash_for!(struct BlockTailInfo { tail_result_is_ignored });
723723
///
724724
/// This can be a binding declared by the user, a temporary inserted by the compiler, a function
725725
/// argument, or the return place.
726-
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
726+
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable, TypeFoldable)]
727727
pub struct LocalDecl<'tcx> {
728728
/// Whether this is a mutable minding (i.e., `let x` or `let mut x`).
729729
///
@@ -1012,7 +1012,7 @@ impl BasicBlock {
10121012
///////////////////////////////////////////////////////////////////////////
10131013
// BasicBlockData and Terminator
10141014

1015-
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
1015+
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable, TypeFoldable)]
10161016
pub struct BasicBlockData<'tcx> {
10171017
/// List of statements in this block.
10181018
pub statements: Vec<Statement<'tcx>>,
@@ -1542,7 +1542,7 @@ impl<'tcx> TerminatorKind<'tcx> {
15421542
///////////////////////////////////////////////////////////////////////////
15431543
// Statements
15441544

1545-
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
1545+
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable, TypeFoldable)]
15461546
pub struct Statement<'tcx> {
15471547
pub source_info: SourceInfo,
15481548
pub kind: StatementKind<'tcx>,
@@ -1568,7 +1568,7 @@ impl Statement<'_> {
15681568
}
15691569
}
15701570

1571-
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
1571+
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable, TypeFoldable)]
15721572
pub enum StatementKind<'tcx> {
15731573
/// Write the RHS Rvalue to the LHS Place.
15741574
Assign(Box<(Place<'tcx>, Rvalue<'tcx>)>),
@@ -1676,7 +1676,7 @@ pub enum FakeReadCause {
16761676
ForIndex,
16771677
}
16781678

1679-
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
1679+
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable, TypeFoldable)]
16801680
pub struct InlineAsm<'tcx> {
16811681
pub asm: HirInlineAsm,
16821682
pub outputs: Box<[Place<'tcx>]>,
@@ -2418,17 +2418,11 @@ pub struct Constant<'tcx> {
24182418
/// The first will lead to the constraint `w: &'1 str` (for some
24192419
/// inferred region `'1`). The second will lead to the constraint `w:
24202420
/// &'static str`.
2421-
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
2421+
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable, TypeFoldable)]
24222422
pub struct UserTypeProjections {
24232423
pub(crate) contents: Vec<(UserTypeProjection, Span)>,
24242424
}
24252425

2426-
BraceStructTypeFoldableImpl! {
2427-
impl<'tcx> TypeFoldable<'tcx> for UserTypeProjections {
2428-
contents
2429-
}
2430-
}
2431-
24322426
impl<'tcx> UserTypeProjections {
24332427
pub fn none() -> Self {
24342428
UserTypeProjections { contents: vec![] }
@@ -2737,7 +2731,7 @@ rustc_index::newtype_index! {
27372731
}
27382732

27392733
/// The layout of generator state.
2740-
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
2734+
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable, TypeFoldable)]
27412735
pub struct GeneratorLayout<'tcx> {
27422736
/// The type of every local stored inside the generator.
27432737
pub field_tys: IndexVec<GeneratorSavedLocal, Ty<'tcx>>,
@@ -2936,92 +2930,6 @@ CloneTypeFoldableAndLiftImpls! {
29362930
UserTypeAnnotationIndex,
29372931
}
29382932

2939-
BraceStructTypeFoldableImpl! {
2940-
impl<'tcx> TypeFoldable<'tcx> for Body<'tcx> {
2941-
phase,
2942-
basic_blocks,
2943-
source_scopes,
2944-
source_scope_local_data,
2945-
yield_ty,
2946-
generator_drop,
2947-
generator_layout,
2948-
local_decls,
2949-
user_type_annotations,
2950-
arg_count,
2951-
__upvar_debuginfo_codegen_only_do_not_use,
2952-
spread_arg,
2953-
control_flow_destroyed,
2954-
span,
2955-
cache,
2956-
}
2957-
}
2958-
2959-
BraceStructTypeFoldableImpl! {
2960-
impl<'tcx> TypeFoldable<'tcx> for GeneratorLayout<'tcx> {
2961-
field_tys,
2962-
variant_fields,
2963-
storage_conflicts,
2964-
__local_debuginfo_codegen_only_do_not_use,
2965-
}
2966-
}
2967-
2968-
BraceStructTypeFoldableImpl! {
2969-
impl<'tcx> TypeFoldable<'tcx> for LocalDecl<'tcx> {
2970-
mutability,
2971-
is_user_variable,
2972-
internal,
2973-
ty,
2974-
user_ty,
2975-
name,
2976-
source_info,
2977-
is_block_tail,
2978-
visibility_scope,
2979-
}
2980-
}
2981-
2982-
BraceStructTypeFoldableImpl! {
2983-
impl<'tcx> TypeFoldable<'tcx> for BasicBlockData<'tcx> {
2984-
statements,
2985-
terminator,
2986-
is_cleanup,
2987-
}
2988-
}
2989-
2990-
BraceStructTypeFoldableImpl! {
2991-
impl<'tcx> TypeFoldable<'tcx> for Statement<'tcx> {
2992-
source_info, kind
2993-
}
2994-
}
2995-
2996-
EnumTypeFoldableImpl! {
2997-
impl<'tcx> TypeFoldable<'tcx> for StatementKind<'tcx> {
2998-
(StatementKind::Assign)(a),
2999-
(StatementKind::FakeRead)(cause, place),
3000-
(StatementKind::SetDiscriminant) { place, variant_index },
3001-
(StatementKind::StorageLive)(a),
3002-
(StatementKind::StorageDead)(a),
3003-
(StatementKind::InlineAsm)(a),
3004-
(StatementKind::Retag)(kind, place),
3005-
(StatementKind::AscribeUserType)(a, v),
3006-
(StatementKind::Nop),
3007-
}
3008-
}
3009-
3010-
BraceStructTypeFoldableImpl! {
3011-
impl<'tcx> TypeFoldable<'tcx> for InlineAsm<'tcx> {
3012-
asm,
3013-
outputs,
3014-
inputs,
3015-
}
3016-
}
3017-
3018-
EnumTypeFoldableImpl! {
3019-
impl<'tcx, T> TypeFoldable<'tcx> for ClearCrossCrate<T> {
3020-
(ClearCrossCrate::Clear),
3021-
(ClearCrossCrate::Set)(a),
3022-
} where T: TypeFoldable<'tcx>
3023-
}
3024-
30252933
impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
30262934
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
30272935
use crate::mir::TerminatorKind::*;

src/librustc/mir/tcx.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::ty::layout::VariantIdx;
1010
use crate::hir;
1111
use crate::ty::util::IntTypeExt;
1212

13-
#[derive(Copy, Clone, Debug)]
13+
#[derive(Copy, Clone, Debug, TypeFoldable)]
1414
pub struct PlaceTy<'tcx> {
1515
pub ty: Ty<'tcx>,
1616
/// Downcast to a particular variant of an enum, if included.
@@ -111,13 +111,6 @@ impl<'tcx> PlaceTy<'tcx> {
111111
}
112112
}
113113

114-
BraceStructTypeFoldableImpl! {
115-
impl<'tcx> TypeFoldable<'tcx> for PlaceTy<'tcx> {
116-
ty,
117-
variant_index,
118-
}
119-
}
120-
121114
impl<'tcx> Place<'tcx> {
122115
pub fn ty_from<D>(
123116
base: &PlaceBase<'tcx>,

0 commit comments

Comments
 (0)