diff options
| author | Tyler Mandry <tmandry@gmail.com> | 2019-09-17 14:10:47 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-17 14:10:47 -0700 |
| commit | ec905cf9e5b8fea647ba49bf781366addef8f7e2 (patch) | |
| tree | 7121aea7bb73779b8fe45df522ca44e58d4a67ab /src | |
| parent | 20d43d03dd27568f609d621ce44673393e838892 (diff) | |
| parent | 7f0637da5144c7435e88ea3805021882f077d50c (diff) | |
| download | rust-ec905cf9e5b8fea647ba49bf781366addef8f7e2.tar.gz rust-ec905cf9e5b8fea647ba49bf781366addef8f7e2.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/infer/equate.rs | 2 | ||||
| -rw-r--r-- | src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs | 14 | ||||
| -rw-r--r-- | src/librustc/infer/error_reporting/note.rs | 4 | ||||
| -rw-r--r-- | src/librustc/infer/glb.rs | 2 | ||||
| -rw-r--r-- | src/librustc/infer/lub.rs | 2 | ||||
| -rw-r--r-- | src/librustc/infer/mod.rs | 6 | ||||
| -rw-r--r-- | src/librustc/infer/sub.rs | 2 |
7 files changed, 18 insertions, 14 deletions
diff --git a/src/librustc/infer/equate.rs b/src/librustc/infer/equate.rs index 5dfa0d29daf..96d40bc81ad 100644 --- a/src/librustc/infer/equate.rs +++ b/src/librustc/infer/equate.rs @@ -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) diff --git a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs index 19bd38b45b3..bfa8353ca34 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -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 }), }), diff --git a/src/librustc/infer/error_reporting/note.rs b/src/librustc/infer/error_reporting/note.rs index caed4288892..115ffea97bf 100644 --- a/src/librustc/infer/error_reporting/note.rs +++ b/src/librustc/infer/error_reporting/note.rs @@ -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) } diff --git a/src/librustc/infer/glb.rs b/src/librustc/infer/glb.rs index 2cef5211762..10e45321a6d 100644 --- a/src/librustc/infer/glb.rs +++ b/src/librustc/infer/glb.rs @@ -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)) } diff --git a/src/librustc/infer/lub.rs b/src/librustc/infer/lub.rs index e20372f1513..8b64cda7bd2 100644 --- a/src/librustc/infer/lub.rs +++ b/src/librustc/infer/lub.rs @@ -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)) } diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index 8638f42976f..a886c44a479 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -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 { diff --git a/src/librustc/infer/sub.rs b/src/librustc/infer/sub.rs index cd1d206b5fc..76db55ecfa8 100644 --- a/src/librustc/infer/sub.rs +++ b/src/librustc/infer/sub.rs @@ -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); |
