Rollup merge of #64394 - nnethercote:shrink-SubregionOrigin, 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.
This commit is contained in:
commit
ec905cf9e5
@ -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)
|
||||
|
@ -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 }),
|
||||
}),
|
||||
@ -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 }),
|
||||
}),
|
||||
@ -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 }),
|
||||
}),
|
||||
@ -92,7 +92,7 @@ impl NiceRegionError<'me, 'tcx> {
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
SubregionOrigin::Subtype(TypeTrace {
|
||||
SubregionOrigin::Subtype(box TypeTrace {
|
||||
cause,
|
||||
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
|
||||
}),
|
||||
@ -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 }),
|
||||
}),
|
||||
@ -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 }),
|
||||
}),
|
||||
@ -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 }),
|
||||
}),
|
||||
|
@ -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, "...");
|
||||
@ -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)
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
||||
|
@ -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))
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
@ -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 {
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user