summaryrefslogtreecommitdiff
path: root/compiler/rustc_middle
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-05-11 08:43:38 +0000
committerbors <bors@rust-lang.org>2023-05-11 08:43:38 +0000
commitf8d8ffa2eba53928662dc57bc3a6c5608beb26f1 (patch)
treed2e0560b842c3eb735263ad6d797effa42614ec3 /compiler/rustc_middle
parent4d941cd9812891af3b83dd4de64aa7d8ee99641a (diff)
parente8ab6489027098dbf4a407ddd0cedd0fbe40e3a4 (diff)
downloadrust-f8d8ffa2eba53928662dc57bc3a6c5608beb26f1.tar.gz
Auto merge of #111029 - Nilstrieb:when-the-errs-are-too-big, r=petrochenkov
Shrink `SelectionError` a lot `SelectionError` used to be 80 bytes (on 64 bit). That's quite big. Especially because the selection cache contained `Result<_, SelectionError>. The Ok type is only 32 bytes, so the 80 bytes significantly inflate the size of the cache. Most variants of the `SelectionError` seem to be hard errors, only `Unimplemented` shows up in practice (for cranelift-codegen, it occupies 23.4% of all cache entries). We can just box away the biggest variant, `OutputTypeParameterMismatch`, to get the size down to 16 bytes, well within the size of the Ok type inside the cache.
Diffstat (limited to 'compiler/rustc_middle')
-rw-r--r--compiler/rustc_middle/src/traits/mod.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs
index 8366567c2c3..449c453555e 100644
--- a/compiler/rustc_middle/src/traits/mod.rs
+++ b/compiler/rustc_middle/src/traits/mod.rs
@@ -580,11 +580,7 @@ pub enum SelectionError<'tcx> {
/// After a closure impl has selected, its "outputs" were evaluated
/// (which for closures includes the "input" type params) and they
/// didn't resolve. See `confirm_poly_trait_refs` for more.
- OutputTypeParameterMismatch(
- ty::PolyTraitRef<'tcx>,
- ty::PolyTraitRef<'tcx>,
- ty::error::TypeError<'tcx>,
- ),
+ OutputTypeParameterMismatch(Box<SelectionOutputTypeParameterMismatch<'tcx>>),
/// The trait pointed by `DefId` is not object safe.
TraitNotObjectSafe(DefId),
/// A given constant couldn't be evaluated.
@@ -596,6 +592,13 @@ pub enum SelectionError<'tcx> {
ErrorReporting,
}
+#[derive(Clone, Debug, TypeVisitable, Lift)]
+pub struct SelectionOutputTypeParameterMismatch<'tcx> {
+ pub found_trait_ref: ty::PolyTraitRef<'tcx>,
+ pub expected_trait_ref: ty::PolyTraitRef<'tcx>,
+ pub terr: ty::error::TypeError<'tcx>,
+}
+
/// When performing resolution, it is typically the case that there
/// can be one of three outcomes:
///