Skip to content

Commit a3c427a

Browse files
committed
s/inference/existential/
1 parent d8bf37e commit a3c427a

File tree

10 files changed

+59
-58
lines changed

10 files changed

+59
-58
lines changed

crates/formality-prove/src/prove/constraints.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use formality_types::{
22
cast::{Downcast, Upcast},
33
cast_impl,
44
derive_links::UpcastFrom,
5-
grammar::{InferenceVar, Parameter, Substitution, Variable},
5+
grammar::{ExistentialVar, Parameter, Substitution, Variable},
66
visit::Visit,
77
};
88

@@ -183,7 +183,7 @@ impl Visit for Constraints {
183183
// Each variable `x` is only bound to a term of strictly lower universe.
184184
// This implies that `x` does not appear in `p`.
185185
for (x, p) in substitution.iter() {
186-
assert!(x.is_a::<InferenceVar>());
186+
assert!(x.is_a::<ExistentialVar>());
187187

188188
assert!(!occurs_in(x, &p));
189189

crates/formality-prove/src/prove/env.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use formality_types::{
55
collections::Set,
66
fold::Fold,
77
grammar::{
8-
Binder, InferenceVar, ParameterKind, UniversalVar, VarIndex, VarSubstitution, Variable,
8+
Binder, ExistentialVar, ParameterKind, UniversalVar, VarIndex, VarSubstitution, Variable,
99
},
1010
visit::Visit,
1111
};
@@ -60,7 +60,7 @@ impl Env {
6060
.iter()
6161
.map(|v| match v {
6262
Variable::UniversalVar(pv) => pv.var_index.index,
63-
Variable::InferenceVar(iv) => iv.var_index.index,
63+
Variable::ExistentialVar(iv) => iv.var_index.index,
6464
Variable::BoundVar(_) => panic!(),
6565
})
6666
.max()
@@ -71,16 +71,16 @@ impl Env {
7171
}
7272
}
7373

74-
pub fn fresh_existential(&mut self, kind: ParameterKind) -> InferenceVar {
74+
pub fn fresh_existential(&mut self, kind: ParameterKind) -> ExistentialVar {
7575
let var_index = self.fresh_index();
76-
let v = InferenceVar { kind, var_index };
76+
let v = ExistentialVar { kind, var_index };
7777
self.variables.push(v.upcast());
7878
v
7979
}
8080

81-
pub fn insert_fresh_before(&mut self, kind: ParameterKind, rank: Universe) -> InferenceVar {
81+
pub fn insert_fresh_before(&mut self, kind: ParameterKind, rank: Universe) -> ExistentialVar {
8282
let var_index = self.fresh_index();
83-
let v = InferenceVar { kind, var_index };
83+
let v = ExistentialVar { kind, var_index };
8484
self.variables.insert(rank.index, v.upcast());
8585
v
8686
}
@@ -160,12 +160,12 @@ impl Env {
160160
b.instantiate_with(&subst).unwrap()
161161
}
162162

163-
pub fn existential_substitution<T>(&self, b: &Binder<T>) -> (Env, Vec<InferenceVar>)
163+
pub fn existential_substitution<T>(&self, b: &Binder<T>) -> (Env, Vec<ExistentialVar>)
164164
where
165165
T: Fold,
166166
{
167167
let mut env = self.clone();
168-
let subst = env.fresh_substituion(b.kinds(), |kind, var_index| InferenceVar {
168+
let subst = env.fresh_substituion(b.kinds(), |kind, var_index| ExistentialVar {
169169
kind,
170170
var_index,
171171
});

crates/formality-prove/src/prove/is_local.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ judgment_fn! {
115115
)
116116

117117
(
118-
// Inference variables *could* be inferred to downstream types; depends on the substitution
118+
// existential variables *could* be inferred to downstream types; depends on the substitution
119119
// we ultimately have.
120120
--- ("type variable")
121-
(not_downstream(_decls, env, _assumptions, TyData::Variable(Variable::InferenceVar(_))) => Constraints::none(env).ambiguous())
121+
(not_downstream(_decls, env, _assumptions, TyData::Variable(Variable::ExistentialVar(_))) => Constraints::none(env).ambiguous())
122122
)
123123
}
124124
}
@@ -159,10 +159,10 @@ judgment_fn! {
159159
(is_local_parameter(decls, env, _assumptions, RigidTy { name: RigidName::AdtId(a), parameters: _ }) => Constraints::none(env))
160160
)
161161

162-
// Inference variables might or might not be local, depending on how they are instantiated.
162+
// existential variables might or might not be local, depending on how they are instantiated.
163163
(
164164
--- ("existential variable")
165-
(is_local_parameter(_decls, env, _assumptions, TyData::Variable(Variable::InferenceVar(_))) => Constraints::none(env).ambiguous())
165+
(is_local_parameter(_decls, env, _assumptions, TyData::Variable(Variable::ExistentialVar(_))) => Constraints::none(env).ambiguous())
166166
)
167167
}
168168
}

crates/formality-prove/src/prove/minimize.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use formality_types::{
22
cast::{Downcast, Upcast},
33
collections::Deduplicate,
44
grammar::{
5-
InferenceVar, Parameter, Substitution, UniversalVar, VarIndex, VarSubstitution, Variable,
5+
ExistentialVar, Parameter, Substitution, UniversalVar, VarIndex, VarSubstitution, Variable,
66
},
77
term::Term,
88
};
@@ -29,7 +29,7 @@ pub fn minimize<T: Term>(env_max: Env, term: T) -> (Env, T, Minimization) {
2929
var_index: VarIndex { index },
3030
}
3131
.upcast(),
32-
Variable::InferenceVar(InferenceVar { kind, var_index: _ }) => InferenceVar {
32+
Variable::ExistentialVar(ExistentialVar { kind, var_index: _ }) => ExistentialVar {
3333
kind,
3434
var_index: VarIndex { index },
3535
}
@@ -83,7 +83,7 @@ impl Minimization {
8383

8484
let mut env_out = self.env_max.clone();
8585

86-
let mut fresh_vars: Vec<InferenceVar> = vec![];
86+
let mut fresh_vars: Vec<ExistentialVar> = vec![];
8787
let mut env2out_subst = self.min2max_subst.clone();
8888
for &var in constraints.env().variables() {
8989
if let Some(var_out) = env2out_subst.map_var(var) {
@@ -98,7 +98,7 @@ impl Minimization {
9898
}
9999
} else {
100100
// e.g., Z in the example above
101-
let var: InferenceVar = var.downcast().unwrap(); // we only ever insert fresh existential variables
101+
let var: ExistentialVar = var.downcast().unwrap(); // we only ever insert fresh existential variables
102102
fresh_vars.push(var);
103103
}
104104
}

crates/formality-prove/src/prove/prove_eq.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use formality_types::{
22
cast::{Downcast, Upcast, Upcasted},
33
collections::{Deduplicate, Set},
44
grammar::{
5-
AliasTy, InferenceVar, Parameter, Relation, RigidTy, Substitution, TyData, UniversalVar,
5+
AliasTy, ExistentialVar, Parameter, Relation, RigidTy, Substitution, TyData, UniversalVar,
66
Variable, Wcs,
77
},
88
judgment_fn, set,
@@ -64,7 +64,7 @@ judgment_fn! {
6464
(
6565
(prove_existential_var_eq(decls, env, assumptions, v, r) => c)
6666
----------------------------- ("existential-nonvar")
67-
(prove_eq(decls, env, assumptions, Variable::InferenceVar(v), r) => c)
67+
(prove_eq(decls, env, assumptions, Variable::ExistentialVar(v), r) => c)
6868
)
6969

7070
(
@@ -81,7 +81,7 @@ judgment_fn! {
8181
decls: Decls,
8282
env: Env,
8383
assumptions: Wcs,
84-
v: InferenceVar,
84+
v: ExistentialVar,
8585
b: Parameter,
8686
) => Constraints {
8787
debug(v, b, assumptions, env, decls)
@@ -97,7 +97,7 @@ judgment_fn! {
9797
// Map the higher rank variable to the lower rank one.
9898
(let (a, b) = env.order_by_universe(l, r))
9999
----------------------------- ("existential-existential")
100-
(prove_existential_var_eq(_decls, env, _assumptions, l, Variable::InferenceVar(r)) => (env, (b, a)))
100+
(prove_existential_var_eq(_decls, env, _assumptions, l, Variable::ExistentialVar(r)) => (env, (b, a)))
101101
)
102102

103103
(
@@ -112,7 +112,7 @@ fn equate_variable(
112112
decls: Decls,
113113
mut env: Env,
114114
assumptions: Wcs,
115-
x: InferenceVar,
115+
x: ExistentialVar,
116116
p: impl Upcast<Parameter>,
117117
) -> Set<Constraints> {
118118
let p: Parameter = p.upcast();
@@ -161,11 +161,11 @@ fn equate_variable(
161161
env,
162162
universe_subst
163163
.iter()
164-
.filter(|(v, _)| v.is_a::<InferenceVar>())
164+
.filter(|(v, _)| v.is_a::<ExistentialVar>())
165165
.chain(Some((x, universe_subst.apply(&p)).upcast())),
166166
);
167167

168-
// For each universal variable that we replaced with an inference variable
168+
// For each universal variable that we replaced with an existential variable
169169
// above, we now have to prove that goal. e.g., if we had `X = Vec<!Y>`, we would replace `!Y` with `?Z`
170170
// (where `?Z` is in a lower universe than `X`), but now we must prove that `!Y = ?Z`
171171
// (this may be posible due to assumptions).

crates/formality-prove/src/prove/prove_normalize.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
use formality_types::{
22
cast::Downcast,
33
grammar::{
4-
AliasTy, InferenceVar, Parameter, Relation, RigidTy, TyData, Variable, Wc, WcData, Wcs,
4+
AliasTy, ExistentialVar, Parameter, Relation, RigidTy, TyData, Variable, Wc, WcData, Wcs,
55
},
66
judgment_fn,
77
};
88

99
use crate::{
1010
decls::{AliasEqDeclBoundData, Decls},
1111
prove::{
12-
env::Env, prove, prove_after::prove_after, prove_eq::prove_existential_var_eq, combinators::zip,
12+
combinators::zip, env::Env, prove, prove_after::prove_after,
13+
prove_eq::prove_existential_var_eq,
1314
},
1415
};
1516

@@ -58,36 +59,36 @@ judgment_fn! {
5859
) => (Constraints, Parameter) {
5960
debug(goal, via, assumptions, env, decls)
6061

61-
// The following 2 rules handle normalization of inference variables. We look specifically for
62+
// The following 2 rules handle normalization of existential variables. We look specifically for
6263
// the case of a assumption `?X = Y`, which lets us normalize `?X` to `Y`, and ignore
6364
// everything else. In principle, we could allow the more general normalization rules
6465
// below handle this case too, but that generates a LOT of false paths, and I *believe*
6566
// it is unnecessary (FIXME: prove this).
6667

6768
(
68-
(if let Some(Variable::InferenceVar(v_a)) = a.downcast())
69+
(if let Some(Variable::ExistentialVar(v_a)) = a.downcast())
6970
(if v_goal == v_a)
7071
----------------------------- ("var-axiom-l")
71-
(prove_normalize_via(_decls, env, _assumptions, Relation::Equals(a, b), Variable::InferenceVar(v_goal)) => (Constraints::none(env), b))
72+
(prove_normalize_via(_decls, env, _assumptions, Relation::Equals(a, b), Variable::ExistentialVar(v_goal)) => (Constraints::none(env), b))
7273
)
7374

7475
(
75-
(if let Some(Variable::InferenceVar(v_a)) = a.downcast())
76+
(if let Some(Variable::ExistentialVar(v_a)) = a.downcast())
7677
(if v_goal == v_a)
7778
----------------------------- ("var-axiom-r")
78-
(prove_normalize_via(_decls, env, _assumptions, Relation::Equals(b, a), Variable::InferenceVar(v_goal)) => (Constraints::none(env), b))
79+
(prove_normalize_via(_decls, env, _assumptions, Relation::Equals(b, a), Variable::ExistentialVar(v_goal)) => (Constraints::none(env), b))
7980
)
8081

8182
// The following 2 rules handle normalization of a type `X` given an assumption `X = Y`.
82-
// We can't just check for `goal == a` though because we sometimes need to bind inference
83+
// We can't just check for `goal == a` though because we sometimes need to bind existential
8384
// variables. Consider normalizing `R<?X>` given an assumption `R<u32> = Y`: this can be
8485
// normalized to `Y` given the constraint `?X = u32`.
8586
//
86-
// We don't use these rules to normalize an inference variable `?X` because such a goal
87+
// We don't use these rules to normalize an existential variable `?X` because such a goal
8788
// could be equated to everything, and thus generates a ton of spurious paths.
8889

8990
(
90-
(if let None = goal.downcast::<InferenceVar>())
91+
(if let None = goal.downcast::<ExistentialVar>())
9192
(if goal != b)
9293
(prove_syntactically_eq(decls, env, assumptions, a, goal) => c)
9394
(let b = c.substitution().apply(&b))
@@ -96,7 +97,7 @@ judgment_fn! {
9697
)
9798

9899
(
99-
(if let None = goal.downcast::<InferenceVar>())
100+
(if let None = goal.downcast::<ExistentialVar>())
100101
(if goal != b)
101102
(prove_syntactically_eq(decls, env, assumptions, a, goal) => c)
102103
(let b = c.substitution().apply(&b))
@@ -165,7 +166,7 @@ judgment_fn! {
165166
(
166167
(prove_existential_var_eq(decls, env, assumptions, v, t) => c)
167168
----------------------------- ("existential-nonvar")
168-
(prove_syntactically_eq(decls, env, assumptions, Variable::InferenceVar(v), t) => c)
169+
(prove_syntactically_eq(decls, env, assumptions, Variable::ExistentialVar(v), t) => c)
169170
)
170171
}
171172
}

crates/formality-prove/src/test/eq_assumptions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn test_normalize_assoc_ty() {
7676
}
7777

7878
#[test]
79-
fn test_normalize_assoc_ty_inference0() {
79+
fn test_normalize_assoc_ty_existential0() {
8080
let constraints = test_prove(
8181
Decls::empty(),
8282
term("exists<ty A> {} => {for<ty T> if { <T as Iterator>::Item = u32 } <A as Iterator>::Item = u32}"),
@@ -88,7 +88,7 @@ fn test_normalize_assoc_ty_inference0() {
8888
}
8989

9090
#[test]
91-
fn test_normalize_assoc_ty_inference1() {
91+
fn test_normalize_assoc_ty_existential1() {
9292
let constraints = test_prove(
9393
Decls::empty(),
9494
term(

crates/formality-types/src/grammar/ty.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ impl UpcastFrom<Ty> for TyData {
114114
}
115115

116116
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
117-
pub struct InferenceVar {
117+
pub struct ExistentialVar {
118118
pub kind: ParameterKind,
119119
pub var_index: VarIndex,
120120
}
121121

122-
cast_impl!(InferenceVar);
122+
cast_impl!(ExistentialVar);
123123

124-
impl Visit for InferenceVar {
124+
impl Visit for ExistentialVar {
125125
fn free_variables(&self) -> Vec<Variable> {
126126
vec![self.upcast()]
127127
}
@@ -407,7 +407,7 @@ impl Visit for LtData {
407407
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
408408
pub enum Variable {
409409
UniversalVar(UniversalVar),
410-
InferenceVar(InferenceVar),
410+
ExistentialVar(ExistentialVar),
411411
BoundVar(BoundVar),
412412
}
413413

@@ -417,7 +417,7 @@ impl Variable {
417417
pub fn kind(&self) -> ParameterKind {
418418
match self {
419419
Variable::UniversalVar(v) => v.kind,
420-
Variable::InferenceVar(v) => v.kind,
420+
Variable::ExistentialVar(v) => v.kind,
421421
Variable::BoundVar(v) => v.kind,
422422
}
423423
}
@@ -466,13 +466,13 @@ impl Variable {
466466
}
467467

468468
/// A variable is *free* (i.e., not bound by any internal binder)
469-
/// if it is an inference variable, a universal, or has a debruijn
469+
/// if it is an existential variable, a universal, or has a debruijn
470470
/// index of `None`. The latter occurs when you `open` a binder (and before
471471
/// you close it back up again).
472472
pub fn is_free(&self) -> bool {
473473
match self {
474474
Variable::UniversalVar(_)
475-
| Variable::InferenceVar(_)
475+
| Variable::ExistentialVar(_)
476476
| Variable::BoundVar(BoundVar {
477477
debruijn: None,
478478
var_index: _,
@@ -490,7 +490,7 @@ impl Variable {
490490
pub fn is_universal(&self) -> bool {
491491
match self {
492492
Variable::UniversalVar(_) => true,
493-
Variable::InferenceVar(_) => false,
493+
Variable::ExistentialVar(_) => false,
494494
Variable::BoundVar(_) => false,
495495
}
496496
}
@@ -528,7 +528,7 @@ impl DowncastTo<Variable> for Parameter {
528528
}
529529

530530
cast_impl!(BoundVar);
531-
cast_impl!((InferenceVar) <: (Variable) <: (Parameter));
531+
cast_impl!((ExistentialVar) <: (Variable) <: (Parameter));
532532
cast_impl!((BoundVar) <: (Variable) <: (Parameter));
533533
cast_impl!((UniversalVar) <: (Variable) <: (Parameter));
534534

@@ -825,20 +825,20 @@ cast_impl!(TyData::PredicateTy(PredicateTy));
825825
cast_impl!(TyData::Variable(Variable));
826826
cast_impl!((Variable) <: (TyData) <: (Ty));
827827
cast_impl!((UniversalVar) <: (Variable) <: (TyData));
828-
cast_impl!((InferenceVar) <: (Variable) <: (TyData));
828+
cast_impl!((ExistentialVar) <: (Variable) <: (TyData));
829829
cast_impl!((BoundVar) <: (Variable) <: (TyData));
830830
cast_impl!((ScalarId) <: (RigidTy) <: (TyData));
831831
cast_impl!((UniversalVar) <: (Variable) <: (Ty));
832-
cast_impl!((InferenceVar) <: (Variable) <: (Ty));
832+
cast_impl!((ExistentialVar) <: (Variable) <: (Ty));
833833
cast_impl!((BoundVar) <: (Variable) <: (Ty));
834834
cast_impl!(Lt);
835835
cast_impl!(LtData::Variable(Variable));
836-
cast_impl!((InferenceVar) <: (Variable) <: (LtData));
836+
cast_impl!((ExistentialVar) <: (Variable) <: (LtData));
837837
cast_impl!((UniversalVar) <: (Variable) <: (LtData));
838838
cast_impl!((BoundVar) <: (Variable) <: (LtData));
839839
cast_impl!((UniversalVar) <: (LtData) <: (Lt));
840-
cast_impl!((InferenceVar) <: (LtData) <: (Lt));
840+
cast_impl!((ExistentialVar) <: (LtData) <: (Lt));
841841
cast_impl!((BoundVar) <: (LtData) <: (Lt));
842842
cast_impl!(Variable::UniversalVar(UniversalVar));
843-
cast_impl!(Variable::InferenceVar(InferenceVar));
843+
cast_impl!(Variable::ExistentialVar(ExistentialVar));
844844
cast_impl!(Variable::BoundVar(BoundVar));

0 commit comments

Comments
 (0)