Skip to content

Commit 1f601cf

Browse files
committed
Refactor ty_is_int
1 parent 582560e commit 1f601cf

File tree

4 files changed

+44
-35
lines changed

4 files changed

+44
-35
lines changed

crates/formality-prove/src/prove.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod combinators;
22
mod constraints;
33
mod env;
4+
mod is_int;
45
mod is_local;
56
mod minimize;
67
mod negation;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use crate::prove::prove_normalize::prove_normalize;
2+
use crate::Constraints;
3+
use crate::Decls;
4+
use crate::Env;
5+
use formality_core::judgment_fn;
6+
use formality_types::grammar::Parameter::{self};
7+
use formality_types::grammar::RigidName;
8+
use formality_types::grammar::RigidTy;
9+
use formality_types::grammar::Wcs;
10+
11+
judgment_fn! {
12+
pub fn ty_is_int(
13+
_decls: Decls,
14+
env: Env,
15+
assumptions: Wcs,
16+
ty: Parameter,
17+
) => Constraints {
18+
debug(assumptions, ty, env)
19+
// If the type that we are currently checking is rigid, check if it is an int.
20+
// If the type can be normalized, normalize until rigid then check if it is an int.
21+
// For the rest of the case, it should fail.
22+
23+
(
24+
(prove_normalize(&decl, &env, &assumptions, ty) => (c1, p))
25+
(let assumptions = c1.substitution().apply(&assumptions))
26+
(ty_is_int(&decl, &env, assumptions, p) => c2)
27+
----------------------------- ("alias_ty is int")
28+
(ty_is_int(decl, env, assumptions, ty) => c2)
29+
)
30+
31+
(
32+
(if id.is_int())
33+
----------------------------- ("rigid_ty is int")
34+
(ty_is_int(_decls, _env, _assumptions, RigidTy {name: RigidName::ScalarId(id), parameters: _}) => Constraints::none(env))
35+
)
36+
37+
}
38+
}

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

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,18 @@ use crate::{
66
prove::{
77
combinators::for_all,
88
env::{Bias, Env},
9+
is_int::ty_is_int,
910
is_local::{is_local_trait_ref, may_be_remote},
1011
prove,
1112
prove_after::prove_after,
1213
prove_eq::prove_eq,
13-
prove_normalize::prove_normalize,
1414
prove_via::prove_via,
1515
prove_wf::prove_wf,
1616
},
1717
};
1818

1919
use super::constraints::Constraints;
20-
use formality_types::grammar::Parameter::{self, Ty};
21-
use formality_types::grammar::RigidName;
22-
use formality_types::grammar::RigidTy;
20+
use formality_types::grammar::Parameter::Ty;
2321

2422
judgment_fn! {
2523
/// The "heart" of the trait system -- prove that a where-clause holds given a set of declarations, variable environment, and set of assumptions.
@@ -150,37 +148,9 @@ judgment_fn! {
150148
)
151149

152150
(
153-
(is_int(&decl, &env, assumptions, ty) => c)
151+
(ty_is_int(&decl, env, assumptions, ty) => c)
154152
----------------------------- ("ty is int")
155153
(prove_wc(decl, env, assumptions, Relation::IsInt(ty)) => c)
156154
)
157-
158-
(
159-
(if ty.is_alias())!
160-
(prove_normalize(&decl, &env, &assumptions, ty) => (c1, p))
161-
(let assumptions = c1.substitution().apply(&assumptions))
162-
(is_int(&decl, &env, assumptions, p) => c2)
163-
----------------------------- ("aliasty is int")
164-
(prove_wc(decl, env, assumptions, Relation::IsInt(ty)) => c2)
165-
)
166155
}
167156
}
168-
169-
judgment_fn! {
170-
pub fn is_int(
171-
_decls: Decls,
172-
env: Env,
173-
assumptions: Wcs,
174-
goal: Parameter,
175-
) => Constraints {
176-
debug(goal, assumptions, env)
177-
178-
(
179-
(if id.is_int())
180-
------- ("is int")
181-
(is_int(_decls, env, _assumptions, RigidTy {name: RigidName::ScalarId(id), parameters: _}) => Constraints::none(env))
182-
)
183-
184-
}
185-
186-
}

src/test/mir_fn_bodies.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,8 @@ fn test_invalid_value_in_switch_terminator() {
664664
the rule "some" failed at step #0 (src/file.rs:LL:CC) because
665665
judgment `prove_wc { goal: @ is_int(bool), assumptions: {}, env: Env { variables: [], bias: Soundness, pending: [] } }` failed at the following rule(s):
666666
the rule "ty is int" failed at step #0 (src/file.rs:LL:CC) because
667-
judgment `is_int { goal: bool, assumptions: {}, env: Env { variables: [], bias: Soundness, pending: [] } }` failed at the following rule(s):
668-
the rule "is int" failed at step #0 (src/file.rs:LL:CC) because
667+
judgment `ty_is_int { assumptions: {}, ty: bool, env: Env { variables: [], bias: Soundness, pending: [] } }` failed at the following rule(s):
668+
the rule "rigid_ty is int" failed at step #0 (src/file.rs:LL:CC) because
669669
condition evaluted to false: `id.is_int()`
670670
id = bool"#]]
671671
)

0 commit comments

Comments
 (0)