-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support constant sorts that are not integers #932
Comments
@vrindisbacher -- see this PR #941 which should get you unblocked (?) in particular, it lets you write stuff like #![flux::defs(
fn is_start(x:bitvec<32>) -> bool { x == START }
)]
#[flux::opaque]
#[flux::refined_by(val: bitvec<32>)]
pub struct BV32(u32);
impl BV32 {
#[flux::trusted]
#[flux::sig(fn (x:u32) -> BV32[bv_int_to_bv32(x)])]
const fn new(val: u32) -> Self {
BV32(val)
}
}
#[flux_rs::constant(bv_int_to_bv32(0x4567))]
pub const START: BV32 = BV32::new(0x4567);
#[flux_rs::sig(fn () -> BV32[START])]
pub fn test1() -> BV32 {
BV32::new(0x4567)
}
#[flux_rs::sig(fn () -> BV32{v: is_start(v)})]
pub fn test2() -> BV32 {
BV32::new(0x4567)
} |
The missing bit is that right now the specification #[flux_rs::constant(bv_int_to_bv32(0x4567))]
pub const START: BV32 = BV32::new(0x4567); is completely trusted. i.e. not checked -- you can make up whatever random constant you like in the |
Yes I think that should do the trick. I will checkout that branch and give it a try now. btw, what happens if I have something like this: #[flux_rs::sig(fn (u32[@val]) -> BV32[bv_int_to_bv32(val)])]
const fn into_bv32(val: u32) -> BV32 {
BV32(val)
}
pub const START: BV32 = into_bv32(0xFFFF_FFFF); This is a way to circumvent the fact that the constant specification isn't checked right? Or do you have to use |
If you use a non-integral const like START in a spec but don’t give it a
const annotation then you get an error… is that what you mean?
- Ranjit.
…On Thu, Dec 12, 2024 at 8:06 AM Vivien Rindisbacher < ***@***.***> wrote:
Yes I think that should do the trick. I will checkout that branch and give
it a try now. btw, what happens if I have something like this:
#[flux_rs::sig(fn ***@***.***) -> BV32[bv_int_to_bv32(val)])]const fn into_bv32(val: u32) -> BV32 {
BV32(val)}
pub const START: BV32 = into_bv32(0xFFFF_FFFF);
This is a way to circumvent the fact that the constant specification isn't
checked right? Or do you have to use flux_rs::constant?
—
Reply to this email directly, view it on GitHub
<https://urldefense.com/v3/__https://github.com/flux-rs/flux/issues/932*issuecomment-2539381102__;Iw!!Mih3wA!Eb3Faa67CxgnAJPkUT2E_0hKU_NG9ObwF48RVlAVsyIZDGQBpPYR4BPoRWQWdq_L5uOWx2Cnec20FzBtUzvToAuG$>,
or unsubscribe
<https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AAMS4OBR45Q6KYMPMWN7BJL2FGX7HAVCNFSM6AAAAABTJZBZ4KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMZZGM4DCMJQGI__;!!Mih3wA!Eb3Faa67CxgnAJPkUT2E_0hKU_NG9ObwF48RVlAVsyIZDGQBpPYR4BPoRWQWdq_L5uOWx2Cnec20FzBtU_IbKW1d$>
.
You are receiving this because you were assigned.Message ID:
***@***.***>
|
Ya - I guess my question is would I get an error or is it ok to just rely on the function annotation that converts it to BV32? |
You would get an error. Relying on the annotation will happen in “step 3”
:-)
- Ranjit.
…On Thu, Dec 12, 2024 at 8:43 AM Vivien Rindisbacher < ***@***.***> wrote:
Ya - I guess my question is would I get an error or is it ok to just rely
on the function annotation that converts it to BV32?
—
Reply to this email directly, view it on GitHub
<https://urldefense.com/v3/__https://github.com/flux-rs/flux/issues/932*issuecomment-2539468132__;Iw!!Mih3wA!ARpQEtk8MXwIR8CavTucANzGBu-_iZlvp-mUxjRH3eWE7m-qvE1JX0WPAm2NIfiNno-YimQ9HihRRQuiEJdZjcD_$>,
or unsubscribe
<https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AAMS4OA7ZHQGKL3FABMS6HL2FG4KZAVCNFSM6AAAAABTJZBZ4KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMZZGQ3DQMJTGI__;!!Mih3wA!ARpQEtk8MXwIR8CavTucANzGBu-_iZlvp-mUxjRH3eWE7m-qvE1JX0WPAm2NIfiNno-YimQ9HihRRQuiENMo4tcp$>
.
You are receiving this because you were assigned.Message ID:
***@***.***>
|
Ok so I was able to convert all constants to This function's postcondition cannot be proved. Here's the definition of |
@ranjitjhala it's silly that we didn't anticipate this but if we write #[flux_rs::constant(bv_int_to_bv32(0x4567))]
pub const START: BV32 = BV32::new(0x4567); we need to make sure we give Right now we lower |
concretely, the following should work #[flux::opaque]
#[flux::refined_by(val: bitvec<32>)]
pub struct BV32(u32);
impl BV32 {
#[flux::trusted]
#[flux::sig(fn (x:u32) -> BV32[bv_int_to_bv32(x)])]
const fn new(val: u32) -> Self {
BV32(val)
}
}
#[flux_rs::constant(bv_int_to_bv32(0x4567))]
pub const START: BV32 = BV32::new(0x4567);
#[flux_rs::sig(fn () -> BV32[START])]
pub fn test1() -> BV32 {
START
} |
I'm having a bit of trouble with inequalities on constants. Here's a minimal example.... #[flux_rs::constant(bv_int_to_bv32(0xE000E200))]
pub const ISPR_START: BV32 = BV32::new(0xE000_E200);
#[flux_rs::constant(bv_int_to_bv32(0xE000_E23C))]
pub const ISPR_END: BV32 = BV32::new(0xE000_E23C);
flux_rs::defs! {
fn bv32(x: int) -> bitvec<32> { bv_int_to_bv32(x) }
fn mod_is_valid_nvic(x: BV32) -> bool {
x >= ISPR_START && x <= ISPR_END
}
}
#[flux_rs::sig(fn () -> bool[mod_is_valid_nvic(bv32(0xe000_e200))])]
fn trivial() -> bool {
true
} Is this currently expected? The fluxc constraint seems reasonable... ∀ . (true = (BV32 { bv_int_to_bv32(3758154240) } ≥ armv7m::mem::nvic::ISPR_START ∧ BV32 { bv_int_to_bv32(3758154240) } ≤ armv7m::mem::nvic::ISPR_END)) ~ Ret at 51:5: 51:9 So does the (qualif EqZero ((v int)) ((= v 0)))
(qualif GtZero ((v int)) ((> v 0)))
(qualif GeZero ((v int)) ((>= v 0)))
(qualif LtZero ((v int)) ((< v 0)))
(qualif LeZero ((v int)) ((<= v 0)))
(qualif Eq ((a int) (b int)) ((= a b)))
(qualif Gt ((a int) (b int)) ((> a b)))
(qualif Ge ((a int) (b int)) ((>= a b)))
(qualif Lt ((a int) (b int)) ((< a b)))
(qualif Le ((a int) (b int)) ((<= a b)))
(qualif Le1 ((a int) (b int)) ((<= a (- b 1))))
(constant c0 (BitVec Size32)) ;; rust const: armv7m::mem::nvic::ISPR_START Some(BV32 { bv_int_to_bv32(3758154240) })
(constant c1 (BitVec Size32)) ;; rust const: armv7m::mem::nvic::ISPR_END Some(BV32 { bv_int_to_bv32(3758154300) })
(constant gt (func 1 (@(0) @(0) ) bool))
(constant ge (func 1 (@(0) @(0) ) bool))
(constant lt (func 1 (@(0) @(0) ) bool))
(constant le (func 1 (@(0) @(0) ) bool))
(constraint
(forall ((_$ int) ((= c1 (int_to_bv32 3758154300))))
(forall ((_$ int) ((= c0 (int_to_bv32 3758154240))))
(tag ((= true (and (and (ge (int_to_bv32 3758154240) c0)) (and (le (int_to_bv32 3758154240) c1))))) "0")))) Not sure where things are going wrong here. |
An even simpler and pretty surprising example is: #[flux_rs::constant(bv_int_to_bv32(0xE000E200))]
pub const ISPR_START: BV32 = BV32::new(0xE000_E200);
#[flux_rs::sig(fn () -> bool[ISPR_START >= ISPR_START])]
fn trivial() -> bool {
true
} |
The issue here is what? That FLUX is rejecting it?
…On Tue, Dec 17, 2024 at 11:18 AM Vivien Rindisbacher < ***@***.***> wrote:
An even simpler and pretty surprising example is:
#[flux_rs::constant(bv_int_to_bv32(0xE000E200))]pub const ISPR_START: BV32 = BV32::new(0xE000_E200);
#[flux_rs::sig(fn () -> bool[ISPR_START >= ISPR_START])]fn trivial() -> bool {
true}
—
Reply to this email directly, view it on GitHub
<https://urldefense.com/v3/__https://github.com/flux-rs/flux/issues/932*issuecomment-2549402302__;Iw!!Mih3wA!Hnl16L4OIIvU6KbALavFgaM6xSgXSjjDo3ldBitBf1cqwVLugQ3dd2qi2iA6LEjKfoqg_68hjsjh2fB3WJTD6_QW$>,
or unsubscribe
<https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AAMS4OFC3S5OP5RQDJFTSVL2GB2GTAVCNFSM6AAAAABTJZBZ4KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNBZGQYDEMZQGI__;!!Mih3wA!Hnl16L4OIIvU6KbALavFgaM6xSgXSjjDo3ldBitBf1cqwVLugQ3dd2qi2iA6LEjKfoqg_68hjsjh2fB3WGH-TDB3$>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
- Ranjit.
|
Ya - postcondition cannot be proved error[E0999]: refinement type error
--> src/armv7m/mem/nvic.rs:44:5
|
44 | true
| ^^^^ a postcondition cannot be proved
|
note: this is the condition that cannot be proved
--> src/armv7m/mem/nvic.rs:42:30
|
42 | #[flux_rs::sig(fn () -> bool[ISPR_START >= ISPR_START])]
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: could not compile `veri-asm` (lib) due to 1 previous error |
binary relations behave differently depending on the sort. For integers binary relations are interpreted, meaning that if you write The encoding for integers and reals is easy because there's only one meaning for The symbol The confusion arises because flux doesn't complain about using (the same applies for edit: this is implemented here https://github.com/flux-rs/flux/blob/nico/move-checker-config-to-infer/crates/flux-infer/src/fixpoint_encoding.rs/#L1155 |
Ah ok. Looking at the SMT-LIB docs, they actually implement bv_ule via equality over integers: https://smt-lib.org/theories-FixedSizeBitVectors.shtml |
@nilehmann perhaps the simplest thing to do for now is add flux/crates/flux-middle/src/lib.rs Line 78 in 7073381
I can use those direclty instead of |
@vrindisbacher yes, that sound like the easiest (and in a sense the most correct) |
Looks like these are already in |
Yep openening a pr for it |
I have some constants that define the location of memory mapped registers.
I then use these constants in a flux definition:
I'd like to make all of these constants of type
BV32
, which looks like:Unfortunately, this is not possible atm because const sorts are restricted to
int
. It would be great if we could allow something like:The text was updated successfully, but these errors were encountered: