Skip to content

Commit 35c8f26

Browse files
committed
Auto merge of #88994 - Aaron1011:intercrate-caching, r=jackh726
Disable the evaluation cache when in intercrate mode It's possible to use the same `InferCtxt` with both an intercrate and non-intercrate `SelectionContext`. However, the local (inferctxt) evaluation cache is not aware of this distinction, so this kind of `InferCtxt` re-use will pollute the cache wth bad results. This commit avoids the issue by disabling the evaluation cache entirely during intercrate mode.
2 parents d6cd2c6 + 6d1f4d2 commit 35c8f26

File tree

1 file changed

+16
-0
lines changed
  • compiler/rustc_trait_selection/src/traits/select

1 file changed

+16
-0
lines changed

Diff for: compiler/rustc_trait_selection/src/traits/select/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
974974
param_env: ty::ParamEnv<'tcx>,
975975
trait_ref: ty::ConstnessAnd<ty::PolyTraitRef<'tcx>>,
976976
) -> Option<EvaluationResult> {
977+
// Neither the global nor local cache is aware of intercrate
978+
// mode, so don't do any caching. In particular, we might
979+
// re-use the same `InferCtxt` with both an intercrate
980+
// and non-intercrate `SelectionContext`
981+
if self.intercrate {
982+
return None;
983+
}
984+
977985
let tcx = self.tcx();
978986
if self.can_use_global_caches(param_env) {
979987
if let Some(res) = tcx.evaluation_cache.get(&param_env.and(trait_ref), tcx) {
@@ -996,6 +1004,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
9961004
return;
9971005
}
9981006

1007+
// Neither the global nor local cache is aware of intercrate
1008+
// mode, so don't do any caching. In particular, we might
1009+
// re-use the same `InferCtxt` with both an intercrate
1010+
// and non-intercrate `SelectionContext`
1011+
if self.intercrate {
1012+
return;
1013+
}
1014+
9991015
if self.can_use_global_caches(param_env) {
10001016
if !trait_ref.needs_infer() {
10011017
debug!(?trait_ref, ?result, "insert_evaluation_cache global");

0 commit comments

Comments
 (0)