Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ rustc_queries! {
/// Return the live symbols in the crate for dead code check.
///
/// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone).
query live_symbols_and_ignored_derived_traits(_: ()) -> &'tcx Result<(
query live_symbols_and_ignored_derived_traits(_: ()) -> Result<&'tcx (
LocalDefIdSet,
LocalDefIdMap<FxIndexSet<DefId>>,
), ErrorGuaranteed> {
Expand Down Expand Up @@ -1292,7 +1292,7 @@ rustc_queries! {

/// Return the set of (transitive) callees that may result in a recursive call to `key`,
/// if we were able to walk all callees.
query mir_callgraph_cyclic(key: LocalDefId) -> &'tcx Option<UnordSet<LocalDefId>> {
query mir_callgraph_cyclic(key: LocalDefId) -> Option<&'tcx UnordSet<LocalDefId>> {
arena_cache
desc {
"computing (transitive) callees of `{}` that may recurse",
Expand Down
16 changes: 16 additions & 0 deletions compiler/rustc_middle/src/query/arena_cached.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::mem;

use rustc_arena::TypedArena;
use rustc_span::ErrorGuaranteed;

use crate::ty::TyCtxt;

Expand Down Expand Up @@ -51,6 +52,21 @@ impl<'tcx, T> ArenaCached<'tcx> for Option<&'tcx T> {
}
}

impl<'tcx, T> ArenaCached<'tcx> for Result<&'tcx T, ErrorGuaranteed> {
type Provided = Result<T, ErrorGuaranteed>;
/// The provide value is `Result<T, ErrorGuaranteed>`, but we only store `T` in the arena.
type Allocated = T;

fn alloc_in_arena(
tcx: TyCtxt<'tcx>,
typed_arena: &'tcx TypedArena<T>,
value: Result<T, ErrorGuaranteed>,
) -> Self {
// Don't store Err(ErrorGuaranteed) in the arena, and wrap the allocated reference in Ok.
try { do_alloc(tcx, typed_arena, value?) }
}
}

/// Allocates a value in either its dedicated arena, or in the common dropless
/// arena, depending on whether it needs to be dropped.
fn do_alloc<'tcx, T>(tcx: TyCtxt<'tcx>, typed_arena: &'tcx TypedArena<T>, value: T) -> &'tcx T {
Expand Down
Loading