mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 04:08:40 +00:00
Cache with consistent env and bound
This commit is contained in:
parent
87cd1ce6c1
commit
6b07cec05c
@ -230,6 +230,19 @@ pub enum BoundConstness {
|
|||||||
ConstIfConst,
|
ConstIfConst,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl BoundConstness {
|
||||||
|
/// Reduce `self` and `constness` to two possible combined states instead of four.
|
||||||
|
pub fn and(&mut self, constness: hir::Constness) -> hir::Constness {
|
||||||
|
match (constness, self) {
|
||||||
|
(hir::Constness::Const, BoundConstness::ConstIfConst) => hir::Constness::Const,
|
||||||
|
(_, this) => {
|
||||||
|
*this = BoundConstness::NotConst;
|
||||||
|
hir::Constness::NotConst
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Display for BoundConstness {
|
impl fmt::Display for BoundConstness {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
@ -1326,6 +1339,11 @@ impl<'tcx> ParamEnv<'tcx> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_constness(mut self, constness: hir::Constness) -> Self {
|
||||||
|
self.packed.set_tag(ParamTag { constness, ..self.packed.tag() });
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn with_const(mut self) -> Self {
|
pub fn with_const(mut self) -> Self {
|
||||||
self.packed.set_tag(ParamTag { constness: hir::Constness::Const, ..self.packed.tag() });
|
self.packed.set_tag(ParamTag { constness: hir::Constness::Const, ..self.packed.tag() });
|
||||||
self
|
self
|
||||||
|
@ -675,11 +675,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let stack = self.push_stack(previous_stack, &obligation);
|
let stack = self.push_stack(previous_stack, &obligation);
|
||||||
let fresh_trait_pred = stack.fresh_trait_pred;
|
let mut fresh_trait_pred = stack.fresh_trait_pred;
|
||||||
|
let mut param_env = obligation.param_env;
|
||||||
|
|
||||||
|
fresh_trait_pred = fresh_trait_pred.map_bound(|mut pred| {
|
||||||
|
param_env = param_env.with_constness(pred.constness.and(param_env.constness()));
|
||||||
|
pred
|
||||||
|
});
|
||||||
|
|
||||||
debug!(?fresh_trait_pred);
|
debug!(?fresh_trait_pred);
|
||||||
|
|
||||||
if let Some(result) = self.check_evaluation_cache(obligation.param_env, fresh_trait_pred) {
|
if let Some(result) = self.check_evaluation_cache(param_env, fresh_trait_pred) {
|
||||||
debug!(?result, "CACHE HIT");
|
debug!(?result, "CACHE HIT");
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
@ -709,11 +715,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||||||
let reached_depth = stack.reached_depth.get();
|
let reached_depth = stack.reached_depth.get();
|
||||||
if reached_depth >= stack.depth {
|
if reached_depth >= stack.depth {
|
||||||
debug!(?result, "CACHE MISS");
|
debug!(?result, "CACHE MISS");
|
||||||
self.insert_evaluation_cache(obligation.param_env, fresh_trait_pred, dep_node, result);
|
self.insert_evaluation_cache(param_env, fresh_trait_pred, dep_node, result);
|
||||||
|
|
||||||
stack.cache().on_completion(stack.dfn, |fresh_trait_pred, provisional_result| {
|
stack.cache().on_completion(stack.dfn, |fresh_trait_pred, provisional_result| {
|
||||||
self.insert_evaluation_cache(
|
self.insert_evaluation_cache(
|
||||||
obligation.param_env,
|
param_env,
|
||||||
fresh_trait_pred,
|
fresh_trait_pred,
|
||||||
dep_node,
|
dep_node,
|
||||||
provisional_result.max(result),
|
provisional_result.max(result),
|
||||||
@ -1200,7 +1206,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||||||
|
|
||||||
fn check_candidate_cache(
|
fn check_candidate_cache(
|
||||||
&mut self,
|
&mut self,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
mut param_env: ty::ParamEnv<'tcx>,
|
||||||
cache_fresh_trait_pred: ty::PolyTraitPredicate<'tcx>,
|
cache_fresh_trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
) -> Option<SelectionResult<'tcx, SelectionCandidate<'tcx>>> {
|
) -> Option<SelectionResult<'tcx, SelectionCandidate<'tcx>>> {
|
||||||
// Neither the global nor local cache is aware of intercrate
|
// Neither the global nor local cache is aware of intercrate
|
||||||
@ -1211,7 +1217,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
let pred = cache_fresh_trait_pred.skip_binder();
|
let mut pred = cache_fresh_trait_pred.skip_binder();
|
||||||
|
param_env = param_env.with_constness(pred.constness.and(param_env.constness()));
|
||||||
|
|
||||||
if self.can_use_global_caches(param_env) {
|
if self.can_use_global_caches(param_env) {
|
||||||
if let Some(res) = tcx.selection_cache.get(¶m_env.and(pred), tcx) {
|
if let Some(res) = tcx.selection_cache.get(¶m_env.and(pred), tcx) {
|
||||||
return Some(res);
|
return Some(res);
|
||||||
@ -1255,13 +1263,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||||||
|
|
||||||
fn insert_candidate_cache(
|
fn insert_candidate_cache(
|
||||||
&mut self,
|
&mut self,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
mut param_env: ty::ParamEnv<'tcx>,
|
||||||
cache_fresh_trait_pred: ty::PolyTraitPredicate<'tcx>,
|
cache_fresh_trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
dep_node: DepNodeIndex,
|
dep_node: DepNodeIndex,
|
||||||
candidate: SelectionResult<'tcx, SelectionCandidate<'tcx>>,
|
candidate: SelectionResult<'tcx, SelectionCandidate<'tcx>>,
|
||||||
) {
|
) {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
let pred = cache_fresh_trait_pred.skip_binder();
|
let mut pred = cache_fresh_trait_pred.skip_binder();
|
||||||
|
|
||||||
|
param_env = param_env.with_constness(pred.constness.and(param_env.constness()));
|
||||||
|
|
||||||
if !self.can_cache_candidate(&candidate) {
|
if !self.can_cache_candidate(&candidate) {
|
||||||
debug!(?pred, ?candidate, "insert_candidate_cache - candidate is not cacheable");
|
debug!(?pred, ?candidate, "insert_candidate_cache - candidate is not cacheable");
|
||||||
|
Loading…
Reference in New Issue
Block a user