Skip to content

Commit b893d56

Browse files
borsehuss
authored andcommitted
Auto merge of rust-lang#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.
1 parent d2e10d5 commit b893d56

File tree

1 file changed

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

1 file changed

+16
-0
lines changed

compiler/rustc_trait_selection/src/traits/select/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
982982
param_env: ty::ParamEnv<'tcx>,
983983
trait_ref: ty::ConstnessAnd<ty::PolyTraitRef<'tcx>>,
984984
) -> Option<EvaluationResult> {
985+
// Neither the global nor local cache is aware of intercrate
986+
// mode, so don't do any caching. In particular, we might
987+
// re-use the same `InferCtxt` with both an intercrate
988+
// and non-intercrate `SelectionContext`
989+
if self.intercrate {
990+
return None;
991+
}
992+
985993
let tcx = self.tcx();
986994
if self.can_use_global_caches(param_env) {
987995
if let Some(res) = tcx.evaluation_cache.get(&param_env.and(trait_ref), tcx) {
@@ -1004,6 +1012,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10041012
return;
10051013
}
10061014

1015+
// Neither the global nor local cache is aware of intercrate
1016+
// mode, so don't do any caching. In particular, we might
1017+
// re-use the same `InferCtxt` with both an intercrate
1018+
// and non-intercrate `SelectionContext`
1019+
if self.intercrate {
1020+
return;
1021+
}
1022+
10071023
if self.can_use_global_caches(param_env) {
10081024
if !trait_ref.needs_infer() {
10091025
debug!(?trait_ref, ?result, "insert_evaluation_cache global");

0 commit comments

Comments
 (0)