Skip to content

Commit

Permalink
Rollup merge of rust-lang#64394 - nnethercote:shrink-SubregionOrigin,…
Browse files Browse the repository at this point in the history
… r=Mark-Simulacrum

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.
  • Loading branch information
tmandry committed Sep 17, 2019
2 parents 20d43d0 + 7f0637d commit ec905cf
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/librustc/infer/equate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl TypeRelation<'tcx> for Equate<'combine, 'infcx, 'tcx> {
self.tag(),
a,
b);
let origin = Subtype(self.fields.trace.clone());
let origin = Subtype(box self.fields.trace.clone());
self.fields.infcx.borrow_region_constraints()
.make_eqregion(origin, a, b);
Ok(a)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl NiceRegionError<'me, 'tcx> {
Some(RegionResolutionError::SubSupConflict(
vid,
_,
SubregionOrigin::Subtype(TypeTrace {
SubregionOrigin::Subtype(box TypeTrace {
cause,
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
}),
Expand All @@ -50,7 +50,7 @@ impl NiceRegionError<'me, 'tcx> {
Some(RegionResolutionError::SubSupConflict(
vid,
_,
SubregionOrigin::Subtype(TypeTrace {
SubregionOrigin::Subtype(box TypeTrace {
cause,
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
}),
Expand All @@ -70,7 +70,7 @@ impl NiceRegionError<'me, 'tcx> {
Some(RegionResolutionError::SubSupConflict(
vid,
_,
SubregionOrigin::Subtype(TypeTrace {
SubregionOrigin::Subtype(box TypeTrace {
cause,
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
}),
Expand All @@ -92,7 +92,7 @@ impl NiceRegionError<'me, 'tcx> {
_,
_,
_,
SubregionOrigin::Subtype(TypeTrace {
SubregionOrigin::Subtype(box TypeTrace {
cause,
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
}),
Expand All @@ -108,7 +108,7 @@ impl NiceRegionError<'me, 'tcx> {
)),

Some(RegionResolutionError::ConcreteFailure(
SubregionOrigin::Subtype(TypeTrace {
SubregionOrigin::Subtype(box TypeTrace {
cause,
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
}),
Expand All @@ -125,7 +125,7 @@ impl NiceRegionError<'me, 'tcx> {
)),

Some(RegionResolutionError::ConcreteFailure(
SubregionOrigin::Subtype(TypeTrace {
SubregionOrigin::Subtype(box TypeTrace {
cause,
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
}),
Expand All @@ -142,7 +142,7 @@ impl NiceRegionError<'me, 'tcx> {
)),

Some(RegionResolutionError::ConcreteFailure(
SubregionOrigin::Subtype(TypeTrace {
SubregionOrigin::Subtype(box TypeTrace {
cause,
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
}),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/error_reporting/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
sup: Region<'tcx>)
-> DiagnosticBuilder<'tcx> {
match origin {
infer::Subtype(trace) => {
infer::Subtype(box trace) => {
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
let mut err = self.report_and_explain_type_error(trace, &terr);
self.tcx.note_and_explain_region(region_scope_tree, &mut err, "", sup, "...");
Expand Down Expand Up @@ -450,7 +450,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
) -> DiagnosticBuilder<'tcx> {
// I can't think how to do better than this right now. -nikomatsakis
match placeholder_origin {
infer::Subtype(trace) => {
infer::Subtype(box trace) => {
let terr = TypeError::RegionsPlaceholderMismatch;
self.report_and_explain_type_error(trace, &terr)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/glb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl TypeRelation<'tcx> for Glb<'combine, 'infcx, 'tcx> {
a,
b);

let origin = Subtype(self.fields.trace.clone());
let origin = Subtype(box self.fields.trace.clone());
Ok(self.fields.infcx.borrow_region_constraints().glb_regions(self.tcx(), origin, a, b))
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/lub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl TypeRelation<'tcx> for Lub<'combine, 'infcx, 'tcx> {
a,
b);

let origin = Subtype(self.fields.trace.clone());
let origin = Subtype(box self.fields.trace.clone());
Ok(self.fields.infcx.borrow_region_constraints().lub_regions(self.tcx(), origin, a, b))
}

Expand Down
6 changes: 5 additions & 1 deletion src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ pub struct TypeTrace<'tcx> {
#[derive(Clone, Debug)]
pub enum SubregionOrigin<'tcx> {
/// Arose from a subtyping relation
Subtype(TypeTrace<'tcx>),
Subtype(Box<TypeTrace<'tcx>>),

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

// `SubregionOrigin` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(target_arch = "x86_64")]
static_assert_size!(SubregionOrigin<'_>, 32);

/// Places that type/region parameters can appear.
#[derive(Clone, Copy, Debug)]
pub enum ParameterOrigin {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
// FIXME -- we have more fine-grained information available
// from the "cause" field, we could perhaps give more tailored
// error messages.
let origin = SubregionOrigin::Subtype(self.fields.trace.clone());
let origin = SubregionOrigin::Subtype(box self.fields.trace.clone());
self.fields.infcx.borrow_region_constraints()
.make_subregion(origin, a, b);

Expand Down

0 comments on commit ec905cf

Please sign in to comment.