Skip to content

Commit d7ecc8c

Browse files
committed
query normalize_generic_arg_after_erasing_regions
1 parent bda976d commit d7ecc8c

File tree

8 files changed

+49
-21
lines changed

8 files changed

+49
-21
lines changed

src/librustc/dep_graph/dep_node.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use crate::traits::query::{
5959
CanonicalTypeOpAscribeUserTypeGoal, CanonicalTypeOpEqGoal, CanonicalTypeOpNormalizeGoal,
6060
CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpSubtypeGoal,
6161
};
62-
use crate::ty::subst::SubstsRef;
62+
use crate::ty::subst::{GenericArg, SubstsRef};
6363
use crate::ty::{self, ParamEnvAnd, Ty, TyCtxt};
6464

6565
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};

src/librustc/query/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::traits::query::{
99
};
1010
use crate::ty::query::queries;
1111
use crate::ty::query::QueryDescription;
12-
use crate::ty::subst::SubstsRef;
12+
use crate::ty::subst::{GenericArg, SubstsRef};
1313
use crate::ty::{self, ParamEnvAnd, Ty, TyCtxt};
1414
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
1515

@@ -1114,9 +1114,9 @@ rustc_queries! {
11141114
}
11151115

11161116
/// Do not call this query directly: invoke `normalize_erasing_regions` instead.
1117-
query normalize_ty_after_erasing_regions(
1118-
goal: ParamEnvAnd<'tcx, Ty<'tcx>>
1119-
) -> Ty<'tcx> {
1117+
query normalize_generic_arg_after_erasing_regions(
1118+
goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1119+
) -> GenericArg<'tcx> {
11201120
desc { "normalizing `{:?}`", goal }
11211121
}
11221122

src/librustc/ty/normalize_erasing_regions.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
//!
55
//! The methods in this file use a `TypeFolder` to recursively process
66
//! contents, invoking the underlying
7-
//! `normalize_ty_after_erasing_regions` query for each type found
8-
//! within. (This underlying query is what is cached.)
7+
//! `normalize_generic_arg_after_erasing_regions` query for each type
8+
//! or constant found within. (This underlying query is what is cached.)
99
1010
use crate::ty::fold::{TypeFoldable, TypeFolder};
1111
use crate::ty::subst::{Subst, SubstsRef};
@@ -94,6 +94,14 @@ impl TypeFolder<'tcx> for NormalizeAfterErasingRegionsFolder<'tcx> {
9494
}
9595

9696
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
97-
self.tcx.normalize_ty_after_erasing_regions(self.param_env.and(ty))
97+
self.tcx
98+
.normalize_generic_arg_after_erasing_regions(self.param_env.and(ty.into()))
99+
.expect_ty()
100+
}
101+
102+
fn fold_const(&mut self, c: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
103+
self.tcx
104+
.normalize_generic_arg_after_erasing_regions(self.param_env.and(c.into()))
105+
.expect_const()
98106
}
99107
}

src/librustc/ty/query/keys.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::mir;
55
use crate::traits;
66
use crate::ty::fast_reject::SimplifiedType;
77
use crate::ty::query::caches::DefaultCacheSelector;
8-
use crate::ty::subst::SubstsRef;
8+
use crate::ty::subst::{GenericArg, SubstsRef};
99
use crate::ty::{self, Ty, TyCtxt};
1010
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
1111
use rustc_span::symbol::Symbol;
@@ -194,6 +194,17 @@ impl<'tcx> Key for ty::PolyTraitRef<'tcx> {
194194
}
195195
}
196196

197+
impl<'tcx> Key for GenericArg<'tcx> {
198+
type CacheSelector = DefaultCacheSelector;
199+
200+
fn query_crate(&self) -> CrateNum {
201+
LOCAL_CRATE
202+
}
203+
fn default_span(&self, _: TyCtxt<'_>) -> Span {
204+
DUMMY_SP
205+
}
206+
}
207+
197208
impl<'tcx> Key for &'tcx ty::Const<'tcx> {
198209
type CacheSelector = DefaultCacheSelector;
199210

src/librustc/ty/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::traits::specialization_graph;
3131
use crate::traits::Clauses;
3232
use crate::traits::{self, Vtable};
3333
use crate::ty::steal::Steal;
34-
use crate::ty::subst::SubstsRef;
34+
use crate::ty::subst::{GenericArg, SubstsRef};
3535
use crate::ty::util::AlwaysRequiresDrop;
3636
use crate::ty::{self, AdtSizedConstraint, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
3737
use crate::util::common::ErrorReported;

src/librustc/ty/subst.rs

+8
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ impl<'tcx> GenericArg<'tcx> {
128128
_ => bug!("expected a type, but found another kind"),
129129
}
130130
}
131+
132+
/// Unpack the `GenericArg` as a const when it is known certainly to be a const.
133+
pub fn expect_const(self) -> &'tcx ty::Const<'tcx> {
134+
match self.unpack() {
135+
GenericArgKind::Const(c) => c,
136+
_ => bug!("expected a const, but found another kind"),
137+
}
138+
}
131139
}
132140

133141
impl<'a, 'tcx> Lift<'tcx> for GenericArg<'a> {

src/librustc_session/session.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ pub struct PerfStats {
150150
/// Total number of values canonicalized queries constructed.
151151
pub queries_canonicalized: AtomicUsize,
152152
/// Number of times this query is invoked.
153-
pub normalize_ty_after_erasing_regions: AtomicUsize,
153+
pub normalize_generic_arg_after_erasing_regions: AtomicUsize,
154154
/// Number of times this query is invoked.
155155
pub normalize_projection_ty: AtomicUsize,
156156
}
@@ -707,8 +707,8 @@ impl Session {
707707
self.perf_stats.queries_canonicalized.load(Ordering::Relaxed)
708708
);
709709
println!(
710-
"normalize_ty_after_erasing_regions: {}",
711-
self.perf_stats.normalize_ty_after_erasing_regions.load(Ordering::Relaxed)
710+
"normalize_generic_arg_after_erasing_regions: {}",
711+
self.perf_stats.normalize_generic_arg_after_erasing_regions.load(Ordering::Relaxed)
712712
);
713713
println!(
714714
"normalize_projection_ty: {}",
@@ -1080,7 +1080,7 @@ fn build_session_(
10801080
symbol_hash_time: Lock::new(Duration::from_secs(0)),
10811081
decode_def_path_tables_time: Lock::new(Duration::from_secs(0)),
10821082
queries_canonicalized: AtomicUsize::new(0),
1083-
normalize_ty_after_erasing_regions: AtomicUsize::new(0),
1083+
normalize_generic_arg_after_erasing_regions: AtomicUsize::new(0),
10841084
normalize_projection_ty: AtomicUsize::new(0),
10851085
},
10861086
code_stats: Default::default(),

src/librustc_traits/normalize_erasing_regions.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
use rustc::traits::query::NoSolution;
22
use rustc::ty::query::Providers;
3-
use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt};
3+
use rustc::ty::subst::GenericArg;
4+
use rustc::ty::{self, ParamEnvAnd, TyCtxt};
45
use rustc_infer::infer::TyCtxtInferExt;
56
use rustc_trait_selection::traits::query::normalize::AtExt;
67
use rustc_trait_selection::traits::{Normalized, ObligationCause};
78
use std::sync::atomic::Ordering;
89

910
crate fn provide(p: &mut Providers<'_>) {
10-
*p = Providers { normalize_ty_after_erasing_regions, ..*p };
11+
*p = Providers { normalize_generic_arg_after_erasing_regions, ..*p };
1112
}
1213

13-
fn normalize_ty_after_erasing_regions<'tcx>(
14+
fn normalize_generic_arg_after_erasing_regions<'tcx>(
1415
tcx: TyCtxt<'tcx>,
15-
goal: ParamEnvAnd<'tcx, Ty<'tcx>>,
16-
) -> Ty<'tcx> {
17-
debug!("normalize_ty_after_erasing_regions(goal={:#?})", goal);
16+
goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>,
17+
) -> GenericArg<'tcx> {
18+
debug!("normalize_generic_arg_after_erasing_regions(goal={:#?})", goal);
1819

1920
let ParamEnvAnd { param_env, value } = goal;
20-
tcx.sess.perf_stats.normalize_ty_after_erasing_regions.fetch_add(1, Ordering::Relaxed);
21+
tcx.sess.perf_stats.normalize_generic_arg_after_erasing_regions.fetch_add(1, Ordering::Relaxed);
2122
tcx.infer_ctxt().enter(|infcx| {
2223
let cause = ObligationCause::dummy();
2324
match infcx.at(&cause, param_env).normalize(&value) {

0 commit comments

Comments
 (0)