Skip to content

Commit 5aca3b9

Browse files
nikomatsakissgrif
authored andcommitted
move param-env from CombineFields into the individual operations
1 parent 367be87 commit 5aca3b9

File tree

8 files changed

+94
-52
lines changed

8 files changed

+94
-52
lines changed

src/librustc/infer/at.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ impl<'a, 'gcx, 'tcx> Trace<'a, 'gcx, 'tcx> {
209209
debug!("sub({:?} <: {:?})", a, b);
210210
let Trace { at, trace, a_is_expected } = self;
211211
at.infcx.commit_if_ok(|_| {
212-
let mut fields = at.infcx.combine_fields(trace, at.param_env);
213-
fields.sub(a_is_expected)
212+
let mut fields = at.infcx.combine_fields(trace);
213+
fields.sub(at.param_env, a_is_expected)
214214
.relate(a, b)
215215
.map(move |_| InferOk { value: (), obligations: fields.obligations })
216216
})
@@ -227,8 +227,8 @@ impl<'a, 'gcx, 'tcx> Trace<'a, 'gcx, 'tcx> {
227227
debug!("eq({:?} == {:?})", a, b);
228228
let Trace { at, trace, a_is_expected } = self;
229229
at.infcx.commit_if_ok(|_| {
230-
let mut fields = at.infcx.combine_fields(trace, at.param_env);
231-
fields.equate(a_is_expected)
230+
let mut fields = at.infcx.combine_fields(trace);
231+
fields.equate(at.param_env, a_is_expected)
232232
.relate(a, b)
233233
.map(move |_| InferOk { value: (), obligations: fields.obligations })
234234
})
@@ -243,8 +243,8 @@ impl<'a, 'gcx, 'tcx> Trace<'a, 'gcx, 'tcx> {
243243
debug!("lub({:?} \\/ {:?})", a, b);
244244
let Trace { at, trace, a_is_expected } = self;
245245
at.infcx.commit_if_ok(|_| {
246-
let mut fields = at.infcx.combine_fields(trace, at.param_env);
247-
fields.lub(a_is_expected)
246+
let mut fields = at.infcx.combine_fields(trace);
247+
fields.lub(at.param_env, a_is_expected)
248248
.relate(a, b)
249249
.map(move |t| InferOk { value: t, obligations: fields.obligations })
250250
})
@@ -259,8 +259,8 @@ impl<'a, 'gcx, 'tcx> Trace<'a, 'gcx, 'tcx> {
259259
debug!("glb({:?} /\\ {:?})", a, b);
260260
let Trace { at, trace, a_is_expected } = self;
261261
at.infcx.commit_if_ok(|_| {
262-
let mut fields = at.infcx.combine_fields(trace, at.param_env);
263-
fields.glb(a_is_expected)
262+
let mut fields = at.infcx.combine_fields(trace);
263+
fields.glb(at.param_env, a_is_expected)
264264
.relate(a, b)
265265
.map(move |t| InferOk { value: t, obligations: fields.obligations })
266266
})

src/librustc/infer/combine.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ pub struct CombineFields<'infcx, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
5555
pub infcx: &'infcx InferCtxt<'infcx, 'gcx, 'tcx>,
5656
pub trace: TypeTrace<'tcx>,
5757
pub cause: Option<ty::relate::Cause>,
58-
pub param_env: ty::ParamEnv<'tcx>,
5958
pub obligations: PredicateObligations<'tcx>,
6059
}
6160

@@ -159,20 +158,32 @@ impl<'infcx, 'gcx, 'tcx> CombineFields<'infcx, 'gcx, 'tcx> {
159158
self.infcx.tcx
160159
}
161160

162-
pub fn equate<'a>(&'a mut self, a_is_expected: bool) -> Equate<'a, 'infcx, 'gcx, 'tcx> {
163-
Equate::new(self, a_is_expected)
161+
pub fn equate<'a>(&'a mut self,
162+
param_env: ty::ParamEnv<'tcx>,
163+
a_is_expected: bool)
164+
-> Equate<'a, 'infcx, 'gcx, 'tcx> {
165+
Equate::new(self, param_env, a_is_expected)
164166
}
165167

166-
pub fn sub<'a>(&'a mut self, a_is_expected: bool) -> Sub<'a, 'infcx, 'gcx, 'tcx> {
167-
Sub::new(self, a_is_expected)
168+
pub fn sub<'a>(&'a mut self,
169+
param_env: ty::ParamEnv<'tcx>,
170+
a_is_expected: bool)
171+
-> Sub<'a, 'infcx, 'gcx, 'tcx> {
172+
Sub::new(self, param_env, a_is_expected)
168173
}
169174

170-
pub fn lub<'a>(&'a mut self, a_is_expected: bool) -> Lub<'a, 'infcx, 'gcx, 'tcx> {
171-
Lub::new(self, a_is_expected)
175+
pub fn lub<'a>(&'a mut self,
176+
param_env: ty::ParamEnv<'tcx>,
177+
a_is_expected: bool)
178+
-> Lub<'a, 'infcx, 'gcx, 'tcx> {
179+
Lub::new(self, param_env, a_is_expected)
172180
}
173181

174-
pub fn glb<'a>(&'a mut self, a_is_expected: bool) -> Glb<'a, 'infcx, 'gcx, 'tcx> {
175-
Glb::new(self, a_is_expected)
182+
pub fn glb<'a>(&'a mut self,
183+
param_env: ty::ParamEnv<'tcx>,
184+
a_is_expected: bool)
185+
-> Glb<'a, 'infcx, 'gcx, 'tcx> {
186+
Glb::new(self, param_env, a_is_expected)
176187
}
177188

178189
/// Here dir is either EqTo, SubtypeOf, or SupertypeOf. The
@@ -185,6 +196,7 @@ impl<'infcx, 'gcx, 'tcx> CombineFields<'infcx, 'gcx, 'tcx> {
185196
/// of `a_ty`. Generalization introduces other inference
186197
/// variables wherever subtyping could occur.
187198
pub fn instantiate(&mut self,
199+
param_env: ty::ParamEnv<'tcx>,
188200
a_ty: Ty<'tcx>,
189201
dir: RelationDir,
190202
b_vid: ty::TyVid,
@@ -216,7 +228,7 @@ impl<'infcx, 'gcx, 'tcx> CombineFields<'infcx, 'gcx, 'tcx> {
216228

217229
if needs_wf {
218230
self.obligations.push(Obligation::new(self.trace.cause.clone(),
219-
self.param_env,
231+
param_env,
220232
ty::Predicate::WellFormed(b_ty)));
221233
}
222234

@@ -227,9 +239,9 @@ impl<'infcx, 'gcx, 'tcx> CombineFields<'infcx, 'gcx, 'tcx> {
227239
// to associate causes/spans with each of the relations in
228240
// the stack to get this right.
229241
match dir {
230-
EqTo => self.equate(a_is_expected).relate(&a_ty, &b_ty),
231-
SubtypeOf => self.sub(a_is_expected).relate(&a_ty, &b_ty),
232-
SupertypeOf => self.sub(a_is_expected).relate_with_variance(
242+
EqTo => self.equate(param_env, a_is_expected).relate(&a_ty, &b_ty),
243+
SubtypeOf => self.sub(param_env, a_is_expected).relate(&a_ty, &b_ty),
244+
SupertypeOf => self.sub(param_env, a_is_expected).relate_with_variance(
233245
ty::Contravariant, &a_ty, &b_ty),
234246
}?;
235247

src/librustc/infer/equate.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ use ty::relate::{self, Relate, RelateResult, TypeRelation};
2222
pub struct Equate<'combine, 'infcx: 'combine, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
2323
fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>,
2424
a_is_expected: bool,
25+
param_env: ty::ParamEnv<'tcx>,
2526
}
2627

2728
impl<'combine, 'infcx, 'gcx, 'tcx> Equate<'combine, 'infcx, 'gcx, 'tcx> {
28-
pub fn new(fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>, a_is_expected: bool)
29+
pub fn new(fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>,
30+
param_env: ty::ParamEnv<'tcx>,
31+
a_is_expected: bool)
2932
-> Equate<'combine, 'infcx, 'gcx, 'tcx>
3033
{
31-
Equate { fields: fields, a_is_expected: a_is_expected }
34+
Equate { fields, a_is_expected, param_env }
3235
}
3336
}
3437

@@ -81,12 +84,20 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
8184
}
8285

8386
(&ty::TyInfer(TyVar(a_id)), _) => {
84-
self.fields.instantiate(b, RelationDir::EqTo, a_id, self.a_is_expected)?;
87+
self.fields.instantiate(self.param_env,
88+
b,
89+
RelationDir::EqTo,
90+
a_id,
91+
self.a_is_expected)?;
8592
Ok(a)
8693
}
8794

8895
(_, &ty::TyInfer(TyVar(b_id))) => {
89-
self.fields.instantiate(a, RelationDir::EqTo, b_id, self.a_is_expected)?;
96+
self.fields.instantiate(self.param_env,
97+
a,
98+
RelationDir::EqTo,
99+
b_id,
100+
self.a_is_expected)?;
90101
Ok(a)
91102
}
92103

@@ -113,7 +124,7 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
113124
-> RelateResult<'tcx, ty::Binder<T>>
114125
where T: Relate<'tcx>
115126
{
116-
self.fields.higher_ranked_sub(a, b, self.a_is_expected)?;
117-
self.fields.higher_ranked_sub(b, a, self.a_is_expected)
127+
self.fields.higher_ranked_sub(self.param_env, a, b, self.a_is_expected)?;
128+
self.fields.higher_ranked_sub(self.param_env, b, a, self.a_is_expected)
118129
}
119130
}

src/librustc/infer/glb.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ use ty::relate::{Relate, RelateResult, TypeRelation};
2121
pub struct Glb<'combine, 'infcx: 'combine, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
2222
fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>,
2323
a_is_expected: bool,
24+
param_env: ty::ParamEnv<'tcx>,
2425
}
2526

2627
impl<'combine, 'infcx, 'gcx, 'tcx> Glb<'combine, 'infcx, 'gcx, 'tcx> {
27-
pub fn new(fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>, a_is_expected: bool)
28-
-> Glb<'combine, 'infcx, 'gcx, 'tcx>
28+
pub fn new(fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>,
29+
param_env: ty::ParamEnv<'tcx>,
30+
a_is_expected: bool)
31+
-> Glb<'combine, 'infcx, 'gcx, 'tcx>
2932
{
30-
Glb { fields: fields, a_is_expected: a_is_expected }
33+
Glb { fields, a_is_expected, param_env }
3134
}
3235
}
3336

@@ -47,11 +50,11 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
4750
-> RelateResult<'tcx, T>
4851
{
4952
match variance {
50-
ty::Invariant => self.fields.equate(self.a_is_expected).relate(a, b),
53+
ty::Invariant => self.fields.equate(self.param_env, self.a_is_expected).relate(a, b),
5154
ty::Covariant => self.relate(a, b),
5255
// FIXME(#41044) -- not correct, need test
5356
ty::Bivariant => Ok(a.clone()),
54-
ty::Contravariant => self.fields.lub(self.a_is_expected).relate(a, b),
57+
ty::Contravariant => self.fields.lub(self.param_env, self.a_is_expected).relate(a, b),
5558
}
5659
}
5760

@@ -101,7 +104,7 @@ impl<'combine, 'infcx, 'gcx, 'tcx> LatticeDir<'infcx, 'gcx, 'tcx>
101104
}
102105

103106
fn relate_bound(&mut self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()> {
104-
let mut sub = self.fields.sub(self.a_is_expected);
107+
let mut sub = self.fields.sub(self.param_env, self.a_is_expected);
105108
sub.relate(&v, &a)?;
106109
sub.relate(&v, &b)?;
107110
Ok(())

src/librustc/infer/higher_ranked/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ use syntax_pos::Span;
2525
use util::nodemap::{FxHashMap, FxHashSet};
2626

2727
impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
28-
pub fn higher_ranked_sub<T>(&mut self, a: &Binder<T>, b: &Binder<T>, a_is_expected: bool)
28+
pub fn higher_ranked_sub<T>(&mut self,
29+
param_env: ty::ParamEnv<'tcx>,
30+
a: &Binder<T>,
31+
b: &Binder<T>,
32+
a_is_expected: bool)
2933
-> RelateResult<'tcx, Binder<T>>
3034
where T: Relate<'tcx>
3135
{
@@ -62,7 +66,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
6266
debug!("b_prime={:?}", b_prime);
6367

6468
// Compare types now that bound regions have been replaced.
65-
let result = self.sub(a_is_expected).relate(&a_prime, &b_prime)?;
69+
let result = self.sub(param_env, a_is_expected).relate(&a_prime, &b_prime)?;
6670

6771
// Presuming type comparison succeeds, we need to check
6872
// that the skolemized regions do not "leak".

src/librustc/infer/lub.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ use ty::relate::{Relate, RelateResult, TypeRelation};
2121
pub struct Lub<'combine, 'infcx: 'combine, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
2222
fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>,
2323
a_is_expected: bool,
24+
param_env: ty::ParamEnv<'tcx>,
2425
}
2526

2627
impl<'combine, 'infcx, 'gcx, 'tcx> Lub<'combine, 'infcx, 'gcx, 'tcx> {
27-
pub fn new(fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>, a_is_expected: bool)
28-
-> Lub<'combine, 'infcx, 'gcx, 'tcx>
28+
pub fn new(fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>,
29+
param_env: ty::ParamEnv<'tcx>,
30+
a_is_expected: bool)
31+
-> Lub<'combine, 'infcx, 'gcx, 'tcx>
2932
{
30-
Lub { fields: fields, a_is_expected: a_is_expected }
33+
Lub { fields, a_is_expected, param_env }
3134
}
3235
}
3336

@@ -47,11 +50,11 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
4750
-> RelateResult<'tcx, T>
4851
{
4952
match variance {
50-
ty::Invariant => self.fields.equate(self.a_is_expected).relate(a, b),
53+
ty::Invariant => self.fields.equate(self.param_env, self.a_is_expected).relate(a, b),
5154
ty::Covariant => self.relate(a, b),
5255
// FIXME(#41044) -- not correct, need test
5356
ty::Bivariant => Ok(a.clone()),
54-
ty::Contravariant => self.fields.glb(self.a_is_expected).relate(a, b),
57+
ty::Contravariant => self.fields.glb(self.param_env, self.a_is_expected).relate(a, b),
5558
}
5659
}
5760

@@ -101,7 +104,7 @@ impl<'combine, 'infcx, 'gcx, 'tcx> LatticeDir<'infcx, 'gcx, 'tcx>
101104
}
102105

103106
fn relate_bound(&mut self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()> {
104-
let mut sub = self.fields.sub(self.a_is_expected);
107+
let mut sub = self.fields.sub(self.param_env, self.a_is_expected);
105108
sub.relate(&a, &v)?;
106109
sub.relate(&b, &v)?;
107110
Ok(())

src/librustc/infer/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,13 +578,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
578578
return variables;
579579
}
580580

581-
fn combine_fields(&'a self, trace: TypeTrace<'tcx>, param_env: ty::ParamEnv<'tcx>)
581+
fn combine_fields(&'a self, trace: TypeTrace<'tcx>)
582582
-> CombineFields<'a, 'gcx, 'tcx> {
583583
CombineFields {
584584
infcx: self,
585585
trace,
586586
cause: None,
587-
param_env,
588587
obligations: PredicateObligations::new(),
589588
}
590589
}

src/librustc/infer/sub.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ use std::mem;
2222
pub struct Sub<'combine, 'infcx: 'combine, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
2323
fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>,
2424
a_is_expected: bool,
25+
param_env: ty::ParamEnv<'tcx>,
2526
}
2627

2728
impl<'combine, 'infcx, 'gcx, 'tcx> Sub<'combine, 'infcx, 'gcx, 'tcx> {
28-
pub fn new(f: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>, a_is_expected: bool)
29-
-> Sub<'combine, 'infcx, 'gcx, 'tcx>
29+
pub fn new(fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>,
30+
param_env: ty::ParamEnv<'tcx>,
31+
a_is_expected: bool)
32+
-> Sub<'combine, 'infcx, 'gcx, 'tcx>
3033
{
31-
Sub { fields: f, a_is_expected: a_is_expected }
34+
Sub { fields, a_is_expected, param_env }
3235
}
3336

3437
fn with_expected_switched<R, F: FnOnce(&mut Self) -> R>(&mut self, f: F) -> R {
@@ -64,7 +67,7 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
6467
-> RelateResult<'tcx, T>
6568
{
6669
match variance {
67-
ty::Invariant => self.fields.equate(self.a_is_expected).relate(a, b),
70+
ty::Invariant => self.fields.equate(self.param_env, self.a_is_expected).relate(a, b),
6871
ty::Covariant => self.relate(a, b),
6972
ty::Bivariant => Ok(a.clone()),
7073
ty::Contravariant => self.with_expected_switched(|this| { this.relate(b, a) }),
@@ -96,7 +99,7 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
9699
self.fields.obligations.push(
97100
Obligation::new(
98101
self.fields.trace.cause.clone(),
99-
self.fields.param_env,
102+
self.param_env,
100103
ty::Predicate::Subtype(
101104
ty::Binder(ty::SubtypePredicate {
102105
a_is_expected: self.a_is_expected,
@@ -107,12 +110,19 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
107110
Ok(a)
108111
}
109112
(&ty::TyInfer(TyVar(a_id)), _) => {
110-
self.fields
111-
.instantiate(b, RelationDir::SupertypeOf, a_id, !self.a_is_expected)?;
113+
self.fields.instantiate(self.param_env,
114+
b,
115+
RelationDir::SupertypeOf,
116+
a_id,
117+
!self.a_is_expected)?;
112118
Ok(a)
113119
}
114120
(_, &ty::TyInfer(TyVar(b_id))) => {
115-
self.fields.instantiate(a, RelationDir::SubtypeOf, b_id, self.a_is_expected)?;
121+
self.fields.instantiate(self.param_env,
122+
a,
123+
RelationDir::SubtypeOf,
124+
b_id,
125+
self.a_is_expected)?;
116126
Ok(a)
117127
}
118128

@@ -147,6 +157,6 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
147157
-> RelateResult<'tcx, ty::Binder<T>>
148158
where T: Relate<'tcx>
149159
{
150-
self.fields.higher_ranked_sub(a, b, self.a_is_expected)
160+
self.fields.higher_ranked_sub(self.param_env, a, b, self.a_is_expected)
151161
}
152162
}

0 commit comments

Comments
 (0)