Repository navigation
Conversation
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| // Utility functions for macro expansion of function contract clauses. | ||
| use proc_macro2::TokenStream as TokenStream2; |
There was a problem hiding this comment.
Because TokenStream exists in both proc_macro and proc_macro2 crate. I've redefined the type to TokenStream2 when it comes from proc_macro2. Most other crates that use proc_macro2 do something similar - they refer to the types from proc_macro2 using the suffix 2.
| .collect() | ||
| } | ||
|
|
||
| /// Returns the list of function arguments from the function signature. |
There was a problem hiding this comment.
Comment that you are ignoring self.
Comment explaining why
There was a problem hiding this comment.
Added a comment. The function is returning a list of arguments for use in a function or method call.
If we have a function fn foo(self, x: i32, y:i32) -> ..., it extracts vec![x, y] for use in the foo(x, y) method call.
| .filter_map(|a| { | ||
| let name = a.path.segments.last().unwrap().ident.to_string(); | ||
| match name.as_str() { | ||
| "ensures" | "requires" => None, |
There was a problem hiding this comment.
will this only match kani::ensures
There was a problem hiding this comment.
Good point. I've changed it to match exactly.
| use proc_macro::TokenStream; | ||
| use proc_macro2::TokenStream as TokenStream2; |
There was a problem hiding this comment.
Two different proc macro crates?
There was a problem hiding this comment.
Both syn and quote use the proc_macro2 crate.
proc_macro2 is a wrapper around proc_macro, except it allows you to use the defined types outside a procedural macro.
I need proc_macro2::TokenStream because quote::quote!(...) expects inputs to be of that type.
| attributes | ||
| .iter() | ||
| .filter_map(|a| { | ||
| let name = a.path.segments.last().unwrap().ident.to_string(); |
There was a problem hiding this comment.
If you only look at the last part, wuoldn't that match whatever::ensures too?
There was a problem hiding this comment.
Thanks for pointing it out. I've added a helper function to deal with this now.
|
I'm merging this for future reference since it's being kept in a feature branch. |
Co-authored-by: Monal Narasimhamurthy <[email protected]>
Description of changes:
Add macros for
requires,ensures, andmodifiesclause for function contracts.Resolved issues:
Resolves #1503
Call-outs:
Testing:
How is this change tested?
The change is tested locally for now. Will add test cases before merging into main.
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.