Skip to content

Commit 1702b17

Browse files
committed
Auto merge of #64394 - nnethercote:shrink-SubregionOrigin, r=<try>
Shrink `SubregionOrigin`. It's currently 120 bytes on x86-64, due to one oversized variant (`Subtype`). This commit boxes `Subtype`'s contents, reducing the size of `SubregionOrigin` to 32 bytes. The change speeds things up by avoiding lots of `memcpy` calls, mostly relating to `RegionConstraintData::constraints`, which is a `BTreeMap` with `SubregionOrigin` values.
2 parents c9edc02 + 7f0637d commit 1702b17

File tree

7 files changed

+18
-14
lines changed

7 files changed

+18
-14
lines changed

src/librustc/infer/equate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl TypeRelation<'tcx> for Equate<'combine, 'infcx, 'tcx> {
9797
self.tag(),
9898
a,
9999
b);
100-
let origin = Subtype(self.fields.trace.clone());
100+
let origin = Subtype(box self.fields.trace.clone());
101101
self.fields.infcx.borrow_region_constraints()
102102
.make_eqregion(origin, a, b);
103103
Ok(a)

src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl NiceRegionError<'me, 'tcx> {
3030
Some(RegionResolutionError::SubSupConflict(
3131
vid,
3232
_,
33-
SubregionOrigin::Subtype(TypeTrace {
33+
SubregionOrigin::Subtype(box TypeTrace {
3434
cause,
3535
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
3636
}),
@@ -50,7 +50,7 @@ impl NiceRegionError<'me, 'tcx> {
5050
Some(RegionResolutionError::SubSupConflict(
5151
vid,
5252
_,
53-
SubregionOrigin::Subtype(TypeTrace {
53+
SubregionOrigin::Subtype(box TypeTrace {
5454
cause,
5555
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
5656
}),
@@ -70,7 +70,7 @@ impl NiceRegionError<'me, 'tcx> {
7070
Some(RegionResolutionError::SubSupConflict(
7171
vid,
7272
_,
73-
SubregionOrigin::Subtype(TypeTrace {
73+
SubregionOrigin::Subtype(box TypeTrace {
7474
cause,
7575
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
7676
}),
@@ -92,7 +92,7 @@ impl NiceRegionError<'me, 'tcx> {
9292
_,
9393
_,
9494
_,
95-
SubregionOrigin::Subtype(TypeTrace {
95+
SubregionOrigin::Subtype(box TypeTrace {
9696
cause,
9797
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
9898
}),
@@ -108,7 +108,7 @@ impl NiceRegionError<'me, 'tcx> {
108108
)),
109109

110110
Some(RegionResolutionError::ConcreteFailure(
111-
SubregionOrigin::Subtype(TypeTrace {
111+
SubregionOrigin::Subtype(box TypeTrace {
112112
cause,
113113
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
114114
}),
@@ -125,7 +125,7 @@ impl NiceRegionError<'me, 'tcx> {
125125
)),
126126

127127
Some(RegionResolutionError::ConcreteFailure(
128-
SubregionOrigin::Subtype(TypeTrace {
128+
SubregionOrigin::Subtype(box TypeTrace {
129129
cause,
130130
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
131131
}),
@@ -142,7 +142,7 @@ impl NiceRegionError<'me, 'tcx> {
142142
)),
143143

144144
Some(RegionResolutionError::ConcreteFailure(
145-
SubregionOrigin::Subtype(TypeTrace {
145+
SubregionOrigin::Subtype(box TypeTrace {
146146
cause,
147147
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
148148
}),

src/librustc/infer/error_reporting/note.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
138138
sup: Region<'tcx>)
139139
-> DiagnosticBuilder<'tcx> {
140140
match origin {
141-
infer::Subtype(trace) => {
141+
infer::Subtype(box trace) => {
142142
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
143143
let mut err = self.report_and_explain_type_error(trace, &terr);
144144
self.tcx.note_and_explain_region(region_scope_tree, &mut err, "", sup, "...");
@@ -450,7 +450,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
450450
) -> DiagnosticBuilder<'tcx> {
451451
// I can't think how to do better than this right now. -nikomatsakis
452452
match placeholder_origin {
453-
infer::Subtype(trace) => {
453+
infer::Subtype(box trace) => {
454454
let terr = TypeError::RegionsPlaceholderMismatch;
455455
self.report_and_explain_type_error(trace, &terr)
456456
}

src/librustc/infer/glb.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl TypeRelation<'tcx> for Glb<'combine, 'infcx, 'tcx> {
5757
a,
5858
b);
5959

60-
let origin = Subtype(self.fields.trace.clone());
60+
let origin = Subtype(box self.fields.trace.clone());
6161
Ok(self.fields.infcx.borrow_region_constraints().glb_regions(self.tcx(), origin, a, b))
6262
}
6363

src/librustc/infer/lub.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl TypeRelation<'tcx> for Lub<'combine, 'infcx, 'tcx> {
5757
a,
5858
b);
5959

60-
let origin = Subtype(self.fields.trace.clone());
60+
let origin = Subtype(box self.fields.trace.clone());
6161
Ok(self.fields.infcx.borrow_region_constraints().lub_regions(self.tcx(), origin, a, b))
6262
}
6363

src/librustc/infer/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ pub struct TypeTrace<'tcx> {
254254
#[derive(Clone, Debug)]
255255
pub enum SubregionOrigin<'tcx> {
256256
/// Arose from a subtyping relation
257-
Subtype(TypeTrace<'tcx>),
257+
Subtype(Box<TypeTrace<'tcx>>),
258258

259259
/// Stack-allocated closures cannot outlive innermost loop
260260
/// or function so as to ensure we only require finite stack
@@ -340,6 +340,10 @@ pub enum SubregionOrigin<'tcx> {
340340
},
341341
}
342342

343+
// `SubregionOrigin` is used a lot. Make sure it doesn't unintentionally get bigger.
344+
#[cfg(target_arch = "x86_64")]
345+
static_assert_size!(SubregionOrigin<'_>, 32);
346+
343347
/// Places that type/region parameters can appear.
344348
#[derive(Clone, Copy, Debug)]
345349
pub enum ParameterOrigin {

src/librustc/infer/sub.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
130130
// FIXME -- we have more fine-grained information available
131131
// from the "cause" field, we could perhaps give more tailored
132132
// error messages.
133-
let origin = SubregionOrigin::Subtype(self.fields.trace.clone());
133+
let origin = SubregionOrigin::Subtype(box self.fields.trace.clone());
134134
self.fields.infcx.borrow_region_constraints()
135135
.make_subregion(origin, a, b);
136136

0 commit comments

Comments
 (0)