Skip to content

Commit 992f4c2

Browse files
committed
Write down the rules
1 parent a889ecd commit 992f4c2

File tree

4 files changed

+74
-1
lines changed

4 files changed

+74
-1
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,25 @@ judgment_fn! {
316316
}
317317
}
318318

319+
judgment_fn! {
320+
fn is_int(
321+
_decls: Decls,
322+
env: Env,
323+
assumptions: Wcs,
324+
goal: Parameter,
325+
) => Constraints {
326+
debug(goal, assumptions, env)
327+
328+
(
329+
(if id.is_int())
330+
------- ("is int")
331+
(is_int(_decls, env, _assumptions, RigidTy {name: RigidName::ScalarId(id), parameters: _}) => Constraints::none(env))
332+
)
333+
334+
}
335+
336+
}
337+
319338
fn is_fundamental(_decls: &Decls, name: &RigidName) -> bool {
320339
// From https://rust-lang.github.io/rfcs/2451-re-rebalancing-coherence.html:
321340
//

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ use crate::{
1616
};
1717

1818
use super::constraints::Constraints;
19-
use formality_types::grammar::Parameter::Ty;
19+
use formality_types::grammar::Parameter::{self, Ty};
20+
use formality_types::grammar::RigidName;
21+
use formality_types::grammar::RigidTy;
2022

2123
judgment_fn! {
2224
/// The "heart" of the trait system -- prove that a where-clause holds given a set of declarations, variable environment, and set of assumptions.
@@ -145,5 +147,30 @@ judgment_fn! {
145147
----------------------------- ("const has ty")
146148
(prove_wc(decls, env, assumptions, Predicate::ConstHasType(ct, ty)) => c)
147149
)
150+
151+
(
152+
(is_int(decl, env, assumptions, ty) => c)
153+
----------------------------- ("ty is int")
154+
(prove_wc(decl, env, assumptions, Relation::IsInt(ty)) => c)
155+
)
148156
}
149157
}
158+
159+
judgment_fn! {
160+
pub fn is_int(
161+
_decls: Decls,
162+
env: Env,
163+
assumptions: Wcs,
164+
goal: Parameter,
165+
) => Constraints {
166+
debug(goal, assumptions, env)
167+
168+
(
169+
(if id.is_int())
170+
------- ("is int")
171+
(is_int(_decls, env, _assumptions, RigidTy {name: RigidName::ScalarId(id), parameters: _}) => Constraints::none(env))
172+
)
173+
174+
}
175+
176+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ impl Ty {
7272
pub fn well_formed(&self) -> Relation {
7373
Relation::WellFormed(self.upcast())
7474
}
75+
76+
pub fn is_int(&self) -> Relation {
77+
Relation::IsInt(self.clone())
78+
}
7579
}
7680

7781
impl Parameter {
@@ -101,6 +105,7 @@ pub enum Skeleton {
101105
Equals,
102106
Sub,
103107
Outlives,
108+
IsInt,
104109
}
105110

106111
impl Predicate {
@@ -177,6 +182,9 @@ pub enum Relation {
177182

178183
#[grammar(@wf($v0))]
179184
WellFormed(Parameter),
185+
186+
#[grammar(@is_int($v0))]
187+
IsInt(Ty),
180188
}
181189

182190
impl Relation {
@@ -187,6 +195,7 @@ impl Relation {
187195
Relation::Sub(a, b) => (Skeleton::Sub, vec![a.clone(), b.clone()]),
188196
Relation::Outlives(a, b) => (Skeleton::Outlives, vec![a.clone(), b.clone()]),
189197
Relation::WellFormed(p) => (Skeleton::WellFormed, vec![p.clone()]),
198+
Relation::IsInt(ty) => (Skeleton::IsInt, vec![ty.to_parameter()]),
190199
}
191200
}
192201
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,24 @@ pub enum ScalarId {
189189
Isize,
190190
}
191191

192+
impl ScalarId {
193+
pub fn is_int(&self) -> bool {
194+
match self {
195+
ScalarId::U8
196+
| ScalarId::U16
197+
| ScalarId::U32
198+
| ScalarId::U64
199+
| ScalarId::I8
200+
| ScalarId::I16
201+
| ScalarId::I32
202+
| ScalarId::I64
203+
| ScalarId::Usize
204+
| ScalarId::Isize => true,
205+
ScalarId::Bool => false,
206+
}
207+
}
208+
}
209+
192210
#[term((alias $name $*parameters))]
193211
#[customize(parse, debug)]
194212
pub struct AliasTy {

0 commit comments

Comments
 (0)