|
1 | 1 | use tracing::debug;
|
2 | 2 |
|
3 |
| -use crate::query::Providers; |
| 3 | +use crate::dep_graph::DepGraph; |
4 | 4 | use crate::ty::{
|
5 | 5 | self, Ty, TyCtxt, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
|
6 | 6 | };
|
7 | 7 |
|
8 |
| -pub(super) fn provide(providers: &mut Providers) { |
9 |
| - *providers = Providers { erase_regions_ty, ..*providers }; |
10 |
| -} |
| 8 | +impl<'tcx> TyCtxt<'tcx> { |
| 9 | + /// Erases regions from `ty` to yield a new type. |
| 10 | + pub fn erase_regions_ty(self, ty: Ty<'tcx>) -> Ty<'tcx> { |
| 11 | + if let Some(ty) = self.erased_region_cache.get(&ty) { |
| 12 | + return ty; |
| 13 | + } |
11 | 14 |
|
12 |
| -fn erase_regions_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { |
13 |
| - // N.B., use `super_fold_with` here. If we used `fold_with`, it |
14 |
| - // could invoke the `erase_regions_ty` query recursively. |
15 |
| - ty.super_fold_with(&mut RegionEraserVisitor { tcx }) |
16 |
| -} |
| 15 | + let result = DepGraph::debug_assert_no_deps(|| { |
| 16 | + // N.B., use `super_fold_with` here. If we used `fold_with`, it |
| 17 | + // could invoke the `erase_regions_ty` function recursively. |
| 18 | + ty.super_fold_with(&mut RegionEraserVisitor { tcx: self }) |
| 19 | + }); |
| 20 | + |
| 21 | + self.erased_region_cache.insert(ty, result); |
| 22 | + result |
| 23 | + } |
17 | 24 |
|
18 |
| -impl<'tcx> TyCtxt<'tcx> { |
19 | 25 | /// Returns an equivalent value with all free regions removed (note
|
20 | 26 | /// that late-bound regions remain, because they are important for
|
21 | 27 | /// subtyping, but they are anonymized and normalized as well)..
|
|
0 commit comments