Unintuitive precondition for absence of overflow #1500
              
  
  Closed
              
          
                  
                    
                      jschneider-bensch
                    
                  
                
                  started this conversation in
                General
              
            Replies: 2 comments
-
| 
         Sorry for the late repply -- I think we spoke about it in chat though. But, for reference, here, you are indeed hitting the fact that preconditions should be panic-free, just like any other piece of code. So, the escape hatch here is  use hax_lib::int::*;
#[hax_lib::requires(a.to_int() + b.to_int() <= usize::MAX.to_int())]
fn f(a: usize, b: usize) {
    let c = a + b;
} | 
  
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            -
| 
         Indeed, that's how I solved it. Thanks for coming back and documenting this here!  | 
  
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
The below precondition leads to a type error in F*, since
a + bis translated to(a +! b <: usize)in the precondition, which could also overflow.Interestingly the alternative formulation using subtraction does not lead to an error, so is
-!saturating? Is there a way to write this as a sum without using F* directly?Open this code snippet in the playground
Beta Was this translation helpful? Give feedback.
All reactions