Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 14f863c

Browse files
committedMay 4, 2021
Auto merge of #84472 - Aaron1011:conservative-paramenv-and, r=lcnr
Be more conservative about discarding caller_bound in `ParamEnv::and`
2 parents 716394d + 091b7dd commit 14f863c

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed
 

‎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
}

‎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

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// compile-flags: --crate-type lib
2+
// check-pass
3+
//
4+
// Regression test for issue #84399
5+
// Tests that we keep the full `ParamEnv` when
6+
// caching predicates with freshened types in the global cache
7+
8+
use std::marker::PhantomData;
9+
pub trait Allocator<R> {
10+
type Buffer;
11+
}
12+
pub struct DefaultAllocator;
13+
impl <R> Allocator<R> for DefaultAllocator {
14+
type Buffer = ();
15+
}
16+
pub type Owned<R> = <DefaultAllocator as Allocator<R>>::Buffer;
17+
pub type MatrixMN<R> = Matrix<R, Owned<R>>;
18+
pub type Matrix4<N> = Matrix<N, ()>;
19+
pub struct Matrix<R, S> {
20+
pub data: S,
21+
_phantoms: PhantomData<R>,
22+
}
23+
pub fn set_object_transform(matrix: &Matrix4<()>) {
24+
matrix.js_buffer_view();
25+
}
26+
pub trait Storable {
27+
type Cell;
28+
fn slice_to_items(_buffer: &()) -> &[Self::Cell] {
29+
unimplemented!()
30+
}
31+
}
32+
pub type Cell<T> = <T as Storable>::Cell;
33+
impl<R> Storable for MatrixMN<R>
34+
where
35+
DefaultAllocator: Allocator<R>,
36+
{
37+
type Cell = ();
38+
}
39+
pub trait JsBufferView {
40+
fn js_buffer_view(&self) -> usize {
41+
unimplemented!()
42+
}
43+
}
44+
impl<R> JsBufferView for [MatrixMN<R>]
45+
where
46+
DefaultAllocator: Allocator<R>,
47+
MatrixMN<R>: Storable,
48+
[Cell<MatrixMN<R>>]: JsBufferView,
49+
{
50+
fn js_buffer_view(&self) -> usize {
51+
<MatrixMN<R> as Storable>::slice_to_items(&()).js_buffer_view()
52+
}
53+
}
54+
impl JsBufferView for [()] {}
55+
impl<R> JsBufferView for MatrixMN<R> where DefaultAllocator: Allocator<R> {}

0 commit comments

Comments
 (0)