Repository navigation
Override the print macros with a version suitable for verification - #825
Conversation
celinval
left a comment
There was a problem hiding this comment.
This is amazing! Thanks for doing it. I just have a few minor change request, but no blocker.
| #[macro_export] | ||
| macro_rules! evaluate_print_args { | ||
| () => { /* do nothing */ }; | ||
| ($x:expr $(, $arg:expr)* $(,)?) => { |
There was a problem hiding this comment.
nit: I'm assuming x is the message itself. Can you please rename it to make this easier to read?
There was a problem hiding this comment.
Fixed and added a comment to clarify.
| } | ||
|
|
||
| // Override the print macros to skip all the formatting functionality (which | ||
| /// is not relevant for verification) |
There was a problem hiding this comment.
nit: There's a mix of // and /// in these comments.
adpaco
left a comment
There was a problem hiding this comment.
Really excited about this, thank you @zhassan-aws !!
My only concern about this is the lack of user-facing documentation. What do you think about keeping a list or table of the macros/functions we override that describes the behavior or limitations for each one (e.g., the message formatting call-out in these print macros).
| println!("calling function with side-effect from println!: {}", subtract_two(&mut x)); | ||
| assert!(x == 10); | ||
|
|
||
| eprintln!("calling function with side-effect from eprintln!: {}", subtract_two(&mut x)); | ||
| assert!(x == 15); |
There was a problem hiding this comment.
Why not test the "no newline" variants here as well?
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| // This test checks that println! and eprintln! do not result in verification |
There was a problem hiding this comment.
| // This test checks that println! and eprintln! do not result in verification | |
| // This test checks that `print!`, `println!`, `eprint!` and `eprintln!` do not result in verification |
or just use "print macros" to refer to these
Yes, this makes sense. Should I put this under Limitations section of the docs? |
|
Yes, I would either add it to that section or create a subsection under limitations for overrides specifically. Both options are fine with me for now, we can define a better structure once we review the documentation. |
Done. |
Description of changes:
Currently any programs containing (reachable) print macros (e.g.
println) result in verification failure (see #824). This PR overrides std's print macros by providing versions that are suitable for verification.Resolved issues:
Resolves #194 and #824
Call-outs:
The overriden versions of the macros do not properly parse the arguments, so Kani may accept programs that are rejected by rustc, e.g.
Testing:
How is this change tested? Added two new tests.
Is this a refactor change? No
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.