From 0110073d035530139835585a78c3a62db838a49e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sun, 26 Mar 2023 12:51:16 +0200 Subject: [PATCH] Fully erase query values --- compiler/rustc_middle/src/query/erase.rs | 150 ++++++++++++++++++++--- 1 file changed, 135 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs index 86532f4f264..5462ced16d6 100644 --- a/compiler/rustc_middle/src/query/erase.rs +++ b/compiler/rustc_middle/src/query/erase.rs @@ -1,4 +1,6 @@ -use crate::ty; +use crate::mir; +use crate::traits; +use crate::ty::{self, Ty}; use std::mem::{size_of, transmute_copy, MaybeUninit}; #[derive(Copy, Clone)] @@ -53,32 +55,128 @@ impl EraseType for &'_ ty::List { type Result = [u8; size_of::<*const ()>()]; } -impl EraseType for Result { - type Result = Self; +impl EraseType for Result<&'_ T, traits::query::NoSolution> { + type Result = [u8; size_of::>()]; } -impl EraseType for Option { - type Result = Self; +impl EraseType for Result<&'_ T, rustc_errors::ErrorGuaranteed> { + type Result = [u8; size_of::>()]; } -impl EraseType for rustc_hir::MaybeOwner { - type Result = Self; +impl EraseType for Result<&'_ T, traits::CodegenObligationError> { + type Result = [u8; size_of::>()]; } -impl EraseType for ty::Visibility { - type Result = Self; +impl EraseType for Result<&'_ T, ty::layout::FnAbiError<'_>> { + type Result = [u8; size_of::>>()]; } -impl EraseType for ty::Binder<'_, T> { - type Result = Self; +impl EraseType for Result<(&'_ T, rustc_middle::thir::ExprId), rustc_errors::ErrorGuaranteed> { + type Result = [u8; size_of::< + Result<(&'static (), rustc_middle::thir::ExprId), rustc_errors::ErrorGuaranteed>, + >()]; } -impl EraseType for ty::EarlyBinder { - type Result = Self; +impl EraseType for Result>, rustc_errors::ErrorGuaranteed> { + type Result = + [u8; size_of::>, rustc_errors::ErrorGuaranteed>>()]; } -impl EraseType for (T0, T1) { - type Result = Self; +impl EraseType for Result>, rustc_errors::ErrorGuaranteed> { + type Result = + [u8; size_of::>, rustc_errors::ErrorGuaranteed>>()]; +} + +impl EraseType for Result, traits::query::NoSolution> { + type Result = [u8; size_of::, traits::query::NoSolution>>()]; +} + +impl EraseType for Result> { + type Result = [u8; size_of::>>()]; +} + +impl EraseType for Result>, ty::layout::LayoutError<'_>> { + type Result = [u8; size_of::< + Result< + rustc_target::abi::TyAndLayout<'static, Ty<'static>>, + ty::layout::LayoutError<'static>, + >, + >()]; +} + +impl EraseType for Result, mir::interpret::LitToConstError> { + type Result = [u8; size_of::, mir::interpret::LitToConstError>>()]; +} + +impl EraseType for Result, mir::interpret::LitToConstError> { + type Result = + [u8; size_of::, mir::interpret::LitToConstError>>()]; +} + +impl EraseType for Result, mir::interpret::ErrorHandled> { + type Result = [u8; size_of::< + Result, mir::interpret::ErrorHandled>, + >()]; +} + +impl EraseType for Result, mir::interpret::ErrorHandled> { + type Result = [u8; size_of::< + Result, mir::interpret::ErrorHandled>, + >()]; +} + +impl EraseType for Result>, mir::interpret::ErrorHandled> { + type Result = + [u8; size_of::>, mir::interpret::ErrorHandled>>()]; +} + +impl EraseType for Result<&'_ ty::List>, ty::util::AlwaysRequiresDrop> { + type Result = + [u8; size_of::>, ty::util::AlwaysRequiresDrop>>()]; +} + +impl EraseType for Option<&'_ T> { + type Result = [u8; size_of::>()]; +} + +impl EraseType for Option<&'_ [T]> { + type Result = [u8; size_of::>()]; +} + +impl EraseType for Option> { + type Result = [u8; size_of::>>()]; +} + +impl EraseType for Option> { + type Result = [u8; size_of::>>()]; +} + +impl EraseType for Option>> { + type Result = [u8; size_of::>>>()]; +} + +impl EraseType for Option>> { + type Result = [u8; size_of::>>>()]; +} + +impl EraseType for rustc_hir::MaybeOwner<&'_ T> { + type Result = [u8; size_of::>()]; +} + +impl EraseType for ty::EarlyBinder { + type Result = T::Result; +} + +impl EraseType for ty::Binder<'_, ty::FnSig<'_>> { + type Result = [u8; size_of::>>()]; +} + +impl EraseType for (&'_ T0, &'_ T1) { + type Result = [u8; size_of::<(&'static (), &'static ())>()]; +} + +impl EraseType for (&'_ T0, &'_ [T1]) { + type Result = [u8; size_of::<(&'static (), &'static [()])>()]; } macro_rules! trivial { @@ -94,6 +192,27 @@ macro_rules! trivial { trivial! { (), bool, + Option<(rustc_span::def_id::DefId, rustc_session::config::EntryFnType)>, + Option, + Option, + Option, + Option, + Option, + Option, + Option, + Option, + Option, + Option, + Option, + Option, + Option, + Option, + Option, + Option, + Option, + Result<(), rustc_errors::ErrorGuaranteed>, + Result<(), rustc_middle::traits::query::NoSolution>, + Result, rustc_ast::expand::allocator::AllocatorKind, rustc_attr::ConstStability, rustc_attr::DefaultBodyStability, @@ -144,6 +263,7 @@ trivial! { rustc_middle::ty::ReprOptions, rustc_middle::ty::UnusedGenericParams, rustc_middle::ty::util::AlwaysRequiresDrop, + rustc_middle::ty::Visibility, rustc_session::config::CrateType, rustc_session::config::EntryFnType, rustc_session::config::OptLevel,