-
Notifications
You must be signed in to change notification settings - Fork 98
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
Account for use
statements when resolving paths in kani::stub
attributes
#2003
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/cargo-kani/stubbing-do-not-resolve/other_crate1/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
fn mock() {} | ||
pub fn mock() {} |
2 changes: 1 addition & 1 deletion
2
tests/cargo-kani/stubbing-do-not-resolve/other_crate2/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
fn mock() {} | ||
pub fn mock() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/cargo-kani/stubbing-resolve-extern-crate-as/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
[package] | ||
name = "stubbing-do-not-resolve" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
other_crate = { path = "other_crate" } | ||
|
||
[package.metadata.kani] | ||
flags = { enable-unstable=true, enable-stubbing=true } |
1 change: 1 addition & 0 deletions
1
tests/cargo-kani/stubbing-resolve-extern-crate-as/harness.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VERIFICATION:- SUCCESSFUL |
10 changes: 10 additions & 0 deletions
10
tests/cargo-kani/stubbing-resolve-extern-crate-as/other_crate/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
[package] | ||
name = "other_crate" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
20 changes: 20 additions & 0 deletions
20
tests/cargo-kani/stubbing-resolve-extern-crate-as/other_crate/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
pub fn magic_number13() -> u32 { | ||
13 | ||
} | ||
|
||
pub mod inner_mod { | ||
pub fn magic_number42() -> u32 { | ||
42 | ||
} | ||
} | ||
|
||
pub struct MyType {} | ||
|
||
impl MyType { | ||
pub fn magic_number101() -> u32 { | ||
101 | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/cargo-kani/stubbing-resolve-extern-crate-as/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
//! This tests whether we take into account `extern crate XXX as YYY;` | ||
//! statements when resolving paths in `kani::stub` attributes. | ||
|
||
extern crate other_crate as foo; | ||
|
||
#[kani::proof] | ||
#[kani::stub(zero, foo::magic_number13)] | ||
#[kani::stub(one, foo::inner_mod::magic_number42)] | ||
#[kani::stub(two, foo::MyType::magic_number101)] | ||
fn harness() { | ||
assert_eq!(zero(), foo::magic_number13()); | ||
assert_eq!(one(), foo::inner_mod::magic_number42()); | ||
assert_eq!(two(), foo::MyType::magic_number101()); | ||
} | ||
|
||
fn zero() -> u32 { | ||
0 | ||
} | ||
|
||
fn one() -> u32 { | ||
1 | ||
} | ||
|
||
fn two() -> u32 { | ||
2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
[package] | ||
name = "stubbing-use-as-foreign" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
other_crate = { path = "other_crate" } | ||
|
||
[package.metadata.kani] | ||
flags = { enable-unstable=true, enable-stubbing=true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VERIFICATION:- SUCCESSFUL |
8 changes: 8 additions & 0 deletions
8
tests/cargo-kani/stubbing-use-as-foreign/other_crate/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
[package] | ||
name = "other_crate" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe change this to:
Also, do we have the span from the stub declaration? I think that would really help here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We currently don't have the span available anywhere in this module, and at this point in the code we don't even have the full name of the original function we're trying to resolve. We could potentially pass this information around all the different resolution functions so that we can produce helpful error messages here. However, I think it would be cleaner to change the resolution functions to return a
Result
and then leave it up to the client of this module to produce error messages.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could wrap these functions into a type that holds that information so you can generate more helpful error messages. Not on this PR though. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, sounds like we're holding off on making changes here until later. I think it probably makes most sense to go with the approach of returning a
Result
, so that thisresolve
module does not become specialized to stubbing, but can also be used in other parts of Kani.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, my suggestion is to keep it independent from stubbing. I'm OK with returning a result too, and letting the user to decide whether the failure to resolve is an error or not.
My main point is that the message should give more context on the exact path that we are trying to resolve and in which level it has failed.