Skip to content
Closed
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
14 changes: 0 additions & 14 deletions compiler/rustc_middle/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,20 +752,6 @@ rustc_queries! {
separate_provide_extern
}

/// Erases regions from `ty` to yield a new type.
/// Normally you would just use `tcx.erase_and_anonymize_regions(value)`,
/// however, which uses this query as a kind of cache.
query erase_and_anonymize_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
// This query is not expected to have input -- as a result, it
// is not a good candidates for "replay" because it is essentially a
// pure function of its input (and hence the expectation is that
// no caller would be green **apart** from just these
// queries). Making it anonymous avoids hashing the result, which
// may save a bit of time.
anon
desc { "erasing regions from `{}`", ty }
}

query wasm_import_module_map(_: CrateNum) -> &'tcx DefIdMap<String> {
arena_cache
desc { "getting wasm import module map" }
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,9 @@ pub struct GlobalCtxt<'tcx> {
pub clauses_cache:
Lock<FxHashMap<(ty::Clauses<'tcx>, &'tcx [ty::GenericArg<'tcx>]), ty::Clauses<'tcx>>>,

/// Internal cache of erased types, used by [`TyCtxt::erase_and_anonymize_regions`].
pub(crate) erase_and_anonymize_regions_ty_cache: ShardedHashMap<Ty<'tcx>, Ty<'tcx>>,

/// Data layout specification for the current target.
pub data_layout: TargetDataLayout,

Expand Down Expand Up @@ -1058,6 +1061,7 @@ impl<'tcx> TyCtxt<'tcx> {
canonical_param_env_cache: Default::default(),
highest_var_in_clauses_cache: Default::default(),
clauses_cache: Default::default(),
erase_and_anonymize_regions_ty_cache: Default::default(),
data_layout,
alloc_map: interpret::AllocMap::new(),
current_gcx,
Expand Down
20 changes: 12 additions & 8 deletions compiler/rustc_middle/src/ty/erase_regions.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
use tracing::debug;

use crate::query::Providers;
use crate::ty::{
self, Ty, TyCtxt, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
};

pub(super) fn provide(providers: &mut Providers) {
*providers = Providers { erase_and_anonymize_regions_ty, ..*providers };
}

/// Erases regions from `ty` to yield a new type.
fn erase_and_anonymize_regions_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
if let Some(erased_ty) = tcx.erase_and_anonymize_regions_ty_cache.get(&ty) {
return erased_ty;
}

// N.B., use `super_fold_with` here. If we used `fold_with`, it
// could invoke the `erase_and_anonymize_regions_ty` query recursively.
ty.super_fold_with(&mut RegionEraserAndAnonymizerVisitor { tcx })
// could invoke `erase_and_anonymize_regions_ty` recursively.
let erased_ty = ty.super_fold_with(&mut RegionEraserAndAnonymizerVisitor { tcx });
let old_ty = tcx.erase_and_anonymize_regions_ty_cache.insert(ty, erased_ty);
// If two threads raced to erase the same type, they should agree.
try { debug_assert_eq!(old_ty?, erased_ty) };
erased_ty
}

impl<'tcx> TyCtxt<'tcx> {
Expand Down Expand Up @@ -49,7 +53,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RegionEraserAndAnonymizerVisitor<'tcx> {
} else if ty.has_infer() {
ty.super_fold_with(self)
} else {
self.tcx.erase_and_anonymize_regions_ty(ty)
erase_and_anonymize_regions_ty(self.tcx, ty)
}
}

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2202,7 +2202,6 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn provide(providers: &mut Providers) {
closure::provide(providers);
context::provide(providers);
erase_regions::provide(providers);
inhabitedness::provide(providers);
util::provide(providers);
print::provide(providers);
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_query_impl/src/from_cycle_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ pub(crate) fn specialize_query_vtables<'tcx>(vtables: &mut QueryVTables<'tcx>) {
erase_val(ty::EarlyBinder::bind(Ty::new_error(tcx, guar)))
};

vtables.erase_and_anonymize_regions_ty.value_from_cycle_error = |tcx, _, _, err| {
let guar = err.emit();
erase_val(Ty::new_error(tcx, guar))
};

vtables.fn_sig.value_from_cycle_error = |tcx, key, _, err| {
let guar = err.delay_as_bug();
erase_val(fn_sig(tcx, key, guar))
Expand Down
Loading