1
Fork 0

Rollup merge of #119869 - oli-obk:track_errors2, r=matthewjasper

replace `track_errors` usages with bubbling up `ErrorGuaranteed`

more of the same as https://github.com/rust-lang/rust/pull/117449 (removing `track_errors`)
This commit is contained in:
Matthias Krüger 2024-01-18 20:56:20 +01:00 committed by GitHub
commit fa52edaa51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 342 additions and 192 deletions

View file

@ -114,6 +114,7 @@ macro_rules! arena_types {
[] mod_child: rustc_middle::metadata::ModChild,
[] features: rustc_feature::Features,
[decode] specialization_graph: rustc_middle::traits::specialization_graph::Graph,
[] crate_inherent_impls: rustc_middle::ty::CrateInherentImpls,
]);
)
}

View file

@ -82,6 +82,10 @@ impl<T> EraseType for Result<&'_ T, rustc_errors::ErrorGuaranteed> {
type Result = [u8; size_of::<Result<&'static (), rustc_errors::ErrorGuaranteed>>()];
}
impl<T> EraseType for Result<&'_ [T], rustc_errors::ErrorGuaranteed> {
type Result = [u8; size_of::<Result<&'static [()], rustc_errors::ErrorGuaranteed>>()];
}
impl<T> EraseType for Result<&'_ T, traits::CodegenObligationError> {
type Result = [u8; size_of::<Result<&'static (), traits::CodegenObligationError>>()];
}

View file

@ -859,13 +859,13 @@ rustc_queries! {
/// Maps a `DefId` of a type to a list of its inherent impls.
/// Contains implementations of methods that are inherent to a type.
/// Methods in these implementations don't need to be exported.
query inherent_impls(key: DefId) -> &'tcx [DefId] {
query inherent_impls(key: DefId) -> Result<&'tcx [DefId], ErrorGuaranteed> {
desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
cache_on_disk_if { key.is_local() }
separate_provide_extern
}
query incoherent_impls(key: SimplifiedType) -> &'tcx [DefId] {
query incoherent_impls(key: SimplifiedType) -> Result<&'tcx [DefId], ErrorGuaranteed> {
desc { |tcx| "collecting all inherent impls for `{:?}`", key }
}
@ -961,8 +961,9 @@ rustc_queries! {
desc { |tcx| "checking deathness of variables in {}", describe_as_module(key, tcx) }
}
query check_mod_impl_wf(key: LocalModDefId) -> () {
query check_mod_impl_wf(key: LocalModDefId) -> Result<(), ErrorGuaranteed> {
desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
ensure_forwards_result_if_red
}
query check_mod_type_wf(key: LocalModDefId) -> Result<(), ErrorGuaranteed> {
@ -1011,15 +1012,16 @@ rustc_queries! {
/// Gets a complete map from all types to their inherent impls.
/// Not meant to be used directly outside of coherence.
query crate_inherent_impls(k: ()) -> &'tcx CrateInherentImpls {
arena_cache
query crate_inherent_impls(k: ()) -> Result<&'tcx CrateInherentImpls, ErrorGuaranteed> {
desc { "finding all inherent impls defined in crate" }
ensure_forwards_result_if_red
}
/// Checks all types in the crate for overlap in their inherent impls. Reports errors.
/// Not meant to be used directly outside of coherence.
query crate_inherent_impls_overlap_check(_: ()) -> () {
query crate_inherent_impls_overlap_check(_: ()) -> Result<(), ErrorGuaranteed> {
desc { "check for overlap between inherent impls defined in this crate" }
ensure_forwards_result_if_red
}
/// Checks whether all impls in the crate pass the overlap check, returning
@ -1645,7 +1647,7 @@ rustc_queries! {
///
/// Do not call this directly, but instead use the `incoherent_impls` query.
/// This query is only used to get the data necessary for that query.
query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> &'tcx [DefId] {
query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> Result<&'tcx [DefId], ErrorGuaranteed> {
desc { |tcx| "collecting all impls for a type in a crate" }
separate_provide_extern
}

View file

@ -174,7 +174,7 @@ pub fn query_ensure<'tcx, Cache>(
}
#[inline]
pub fn query_ensure_error_guaranteed<'tcx, Cache>(
pub fn query_ensure_error_guaranteed<'tcx, Cache, T>(
tcx: TyCtxt<'tcx>,
execute_query: fn(TyCtxt<'tcx>, Span, Cache::Key, QueryMode) -> Option<Cache::Value>,
query_cache: &Cache,
@ -182,14 +182,16 @@ pub fn query_ensure_error_guaranteed<'tcx, Cache>(
check_cache: bool,
) -> Result<(), ErrorGuaranteed>
where
Cache: QueryCache<Value = super::erase::Erase<Result<(), ErrorGuaranteed>>>,
Cache: QueryCache<Value = super::erase::Erase<Result<T, ErrorGuaranteed>>>,
Result<T, ErrorGuaranteed>: EraseType,
{
let key = key.into_query_param();
if let Some(res) = try_get_cached(tcx, query_cache, &key) {
super::erase::restore(res)
super::erase::restore(res).map(drop)
} else {
execute_query(tcx, DUMMY_SP, key, QueryMode::Ensure { check_cache })
.map(super::erase::restore)
.map(|res| res.map(drop))
// Either we actually executed the query, which means we got a full `Result`,
// or we can just assume the query succeeded, because it was green in the
// incremental cache. If it is green, that means that the previous compilation
@ -205,7 +207,7 @@ macro_rules! query_ensure {
query_ensure($($args)*)
};
([(ensure_forwards_result_if_red) $($rest:tt)*]$($args:tt)*) => {
query_ensure_error_guaranteed($($args)*)
query_ensure_error_guaranteed($($args)*).map(|_| ())
};
([$other:tt $($modifiers:tt)*]$($args:tt)*) => {
query_ensure!([$($modifiers)*]$($args)*)
@ -667,5 +669,7 @@ mod sealed {
pub use sealed::IntoQueryParam;
use super::erase::EraseType;
#[derive(Copy, Clone, Debug, HashStable)]
pub struct CyclePlaceholder(pub ErrorGuaranteed);

View file

@ -254,16 +254,28 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
}
/// Query provider for `incoherent_impls`.
pub(super) fn incoherent_impls_provider(tcx: TyCtxt<'_>, simp: SimplifiedType) -> &[DefId] {
pub(super) fn incoherent_impls_provider(
tcx: TyCtxt<'_>,
simp: SimplifiedType,
) -> Result<&[DefId], ErrorGuaranteed> {
let mut impls = Vec::new();
let mut res = Ok(());
for cnum in iter::once(LOCAL_CRATE).chain(tcx.crates(()).iter().copied()) {
for &impl_def_id in tcx.crate_incoherent_impls((cnum, simp)) {
let incoherent_impls = match tcx.crate_incoherent_impls((cnum, simp)) {
Ok(impls) => impls,
Err(e) => {
res = Err(e);
continue;
}
};
for &impl_def_id in incoherent_impls {
impls.push(impl_def_id)
}
}
debug!(?impls);
res?;
tcx.arena.alloc_slice(&impls)
Ok(tcx.arena.alloc_slice(&impls))
}