Skip to content

Commit 91daf70

Browse files
committed
Make TypeFoldable::is_global() false when fresh tys/consts are present
This ensures that `ParamEnv::and` preserves the original `caller_bounds` when we have a value containing fresh tys/consts. This ensures that when we cache a `SelectionCandidate`, the cache key (a `ParamEnvAnd`) contains all of the information that influenced the computation of our result (e.g. we may end up choosing a `ParamCandidate`)
1 parent 5f304a5 commit 91daf70

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

Diff for: compiler/rustc_middle/src/ty/flags.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ impl FlagComputation {
141141
&ty::Infer(infer) => {
142142
self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
143143
match infer {
144-
ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => {}
144+
ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => {
145+
self.add_flags(TypeFlags::HAS_TY_FRESH)
146+
}
145147

146148
ty::TyVar(_) | ty::IntVar(_) | ty::FloatVar(_) => {
147149
self.add_flags(TypeFlags::HAS_TY_INFER)
@@ -278,7 +280,7 @@ impl FlagComputation {
278280
ty::ConstKind::Infer(infer) => {
279281
self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
280282
match infer {
281-
InferConst::Fresh(_) => {}
283+
InferConst::Fresh(_) => self.add_flags(TypeFlags::HAS_CT_FRESH),
282284
InferConst::Var(_) => self.add_flags(TypeFlags::HAS_CT_INFER),
283285
}
284286
}

Diff for: compiler/rustc_type_ir/src/lib.rs

+15
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ bitflags! {
5959
| TypeFlags::HAS_CT_INFER.bits
6060
| TypeFlags::HAS_TY_PLACEHOLDER.bits
6161
| TypeFlags::HAS_CT_PLACEHOLDER.bits
62+
// We consider 'freshened' types and constants
63+
// to depend on a particular fn.
64+
// The freshening process throws away information,
65+
// which can make things unsuitable for use in a global
66+
// cache. Note that there is no 'fresh lifetime' flag -
67+
// freshening replaces all lifetimes with `ReErased`,
68+
// which is different from how types/const are freshened.
69+
| TypeFlags::HAS_TY_FRESH.bits
70+
| TypeFlags::HAS_CT_FRESH.bits
6271
| TypeFlags::HAS_FREE_LOCAL_REGIONS.bits;
6372

6473
/// Does this have `Projection`?
@@ -90,6 +99,12 @@ bitflags! {
9099
/// Does this value have parameters/placeholders/inference variables which could be
91100
/// replaced later, in a way that would change the results of `impl` specialization?
92101
const STILL_FURTHER_SPECIALIZABLE = 1 << 17;
102+
103+
/// Does this value have `InferTy::FreshTy/FreshIntTy/FreshFloatTy`?
104+
const HAS_TY_FRESH = 1 << 18;
105+
106+
/// Does this value have `InferConst::Fresh`?
107+
const HAS_CT_FRESH = 1 << 19;
93108
}
94109
}
95110

0 commit comments

Comments
 (0)