Skip to content

Commit 194d4bc

Browse files
committed
make parameter-environment a query
1 parent 1b7acb6 commit 194d4bc

File tree

3 files changed

+35
-32
lines changed

3 files changed

+35
-32
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ pub enum DepNode<D: Clone + Debug> {
162162
// not a hotspot.
163163
ProjectionCache { def_ids: Vec<D> },
164164

165+
ParameterEnvironment(D),
165166
DescribeDef(D),
166167
DefSpan(D),
167168
Stability(D),
@@ -290,6 +291,7 @@ impl<D: Clone + Debug> DepNode<D> {
290291
let def_ids: Option<Vec<E>> = def_ids.iter().map(op).collect();
291292
def_ids.map(|d| ProjectionCache { def_ids: d })
292293
}
294+
ParameterEnvironment(ref d) => op(d).map(ParameterEnvironment),
293295
DescribeDef(ref d) => op(d).map(DescribeDef),
294296
DefSpan(ref d) => op(d).map(DefSpan),
295297
Stability(ref d) => op(d).map(Stability),

src/librustc/ty/maps.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,8 @@ define_maps! { <'tcx>
884884
[] specialization_graph_of: SpecializationGraph(DefId) -> Rc<specialization_graph::Graph>,
885885
[] is_object_safe: ObjectSafety(DefId) -> bool,
886886

887+
[] parameter_environment: ParameterEnvironment(DefId) -> ty::ParameterEnvironment<'tcx>,
888+
887889
// Trait selection queries. These are best used by invoking `ty.moves_by_default()`,
888890
// `ty.is_copy()`, etc, since that will prune the environment where possible.
889891
[] is_copy_raw: is_copy_dep_node(ty::ParameterEnvironmentAnd<'tcx, Ty<'tcx>>) -> bool,

src/librustc/ty/mod.rs

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,38 +2344,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
23442344
}
23452345
}
23462346

2347-
/// See `ParameterEnvironment` struct def'n for details.
2348-
pub fn parameter_environment(self, def_id: DefId) -> ParameterEnvironment<'gcx> {
2349-
//
2350-
// Compute the bounds on Self and the type parameters.
2351-
//
2352-
2353-
let tcx = self.global_tcx();
2354-
let bounds = tcx.predicates_of(def_id).instantiate_identity(tcx);
2355-
let predicates = bounds.predicates;
2356-
2357-
// Finally, we have to normalize the bounds in the environment, in
2358-
// case they contain any associated type projections. This process
2359-
// can yield errors if the put in illegal associated types, like
2360-
// `<i32 as Foo>::Bar` where `i32` does not implement `Foo`. We
2361-
// report these errors right here; this doesn't actually feel
2362-
// right to me, because constructing the environment feels like a
2363-
// kind of a "idempotent" action, but I'm not sure where would be
2364-
// a better place. In practice, we construct environments for
2365-
// every fn once during type checking, and we'll abort if there
2366-
// are any errors at that point, so after type checking you can be
2367-
// sure that this will succeed without errors anyway.
2368-
//
2369-
2370-
let unnormalized_env = ty::ParameterEnvironment::new(tcx.intern_predicates(&predicates));
2371-
2372-
let body_id = self.hir.as_local_node_id(def_id).map_or(DUMMY_NODE_ID, |id| {
2373-
self.hir.maybe_body_owned_by(id).map_or(id, |body| body.node_id)
2374-
});
2375-
let cause = traits::ObligationCause::misc(tcx.def_span(def_id), body_id);
2376-
traits::normalize_param_env_or_error(tcx, def_id, unnormalized_env, cause)
2377-
}
2378-
23792347
pub fn node_scope_region(self, id: NodeId) -> Region<'tcx> {
23802348
self.mk_region(ty::ReScope(CodeExtent::Misc(id)))
23812349
}
@@ -2535,6 +2503,35 @@ fn trait_of_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Option
25352503
})
25362504
}
25372505

2506+
/// See `ParameterEnvironment` struct def'n for details.
2507+
fn parameter_environment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
2508+
def_id: DefId)
2509+
-> ParameterEnvironment<'tcx> {
2510+
// Compute the bounds on Self and the type parameters.
2511+
2512+
let bounds = tcx.predicates_of(def_id).instantiate_identity(tcx);
2513+
let predicates = bounds.predicates;
2514+
2515+
// Finally, we have to normalize the bounds in the environment, in
2516+
// case they contain any associated type projections. This process
2517+
// can yield errors if the put in illegal associated types, like
2518+
// `<i32 as Foo>::Bar` where `i32` does not implement `Foo`. We
2519+
// report these errors right here; this doesn't actually feel
2520+
// right to me, because constructing the environment feels like a
2521+
// kind of a "idempotent" action, but I'm not sure where would be
2522+
// a better place. In practice, we construct environments for
2523+
// every fn once during type checking, and we'll abort if there
2524+
// are any errors at that point, so after type checking you can be
2525+
// sure that this will succeed without errors anyway.
2526+
2527+
let unnormalized_env = ty::ParameterEnvironment::new(tcx.intern_predicates(&predicates));
2528+
2529+
let body_id = tcx.hir.as_local_node_id(def_id).map_or(DUMMY_NODE_ID, |id| {
2530+
tcx.hir.maybe_body_owned_by(id).map_or(id, |body| body.node_id)
2531+
});
2532+
let cause = traits::ObligationCause::misc(tcx.def_span(def_id), body_id);
2533+
traits::normalize_param_env_or_error(tcx, def_id, unnormalized_env, cause)
2534+
}
25382535

25392536
pub fn provide(providers: &mut ty::maps::Providers) {
25402537
util::provide(providers);
@@ -2544,6 +2541,7 @@ pub fn provide(providers: &mut ty::maps::Providers) {
25442541
adt_sized_constraint,
25452542
adt_dtorck_constraint,
25462543
def_span,
2544+
parameter_environment,
25472545
trait_of_item,
25482546
trait_impls_of: trait_def::trait_impls_of_provider,
25492547
relevant_trait_impls_for: trait_def::relevant_trait_impls_provider,
@@ -2557,6 +2555,7 @@ pub fn provide_extern(providers: &mut ty::maps::Providers) {
25572555
adt_dtorck_constraint,
25582556
trait_impls_of: trait_def::trait_impls_of_provider,
25592557
relevant_trait_impls_for: trait_def::relevant_trait_impls_provider,
2558+
parameter_environment,
25602559
..*providers
25612560
};
25622561
}

0 commit comments

Comments
 (0)