generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 128
fix: Make kani attribute nameres work with generic args having ::
#4427
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
Open
ShoyuVanilla
wants to merge
1
commit into
model-checking:main
Choose a base branch
from
ShoyuVanilla:segmented-param-res
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+87
−18
Open
Changes from all commits
Commits
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 hidden or 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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -125,21 +125,25 @@ fn resolve_path<'tcx>( | |||||||
| ) -> Result<DefId, ResolveError<'tcx>> { | ||||||||
| debug!(?path, "resolve_path"); | ||||||||
| let path = resolve_prefix(tcx, current_module, path)?; | ||||||||
| path.segments.into_iter().try_fold(path.base, |base, segment| { | ||||||||
| let name = segment.ident.to_string(); | ||||||||
| let def_kind = tcx.def_kind(base); | ||||||||
| match def_kind { | ||||||||
| DefKind::ForeignMod | DefKind::Mod => resolve_in_module(tcx, base, &name), | ||||||||
| DefKind::Struct | DefKind::Enum | DefKind::Union => { | ||||||||
| resolve_in_type_def(tcx, base, &path.base_path_args, &name) | ||||||||
| } | ||||||||
| DefKind::Trait => resolve_in_trait_def(tcx, base, &name), | ||||||||
| kind => { | ||||||||
| debug!(?base, ?kind, "resolve_path: unexpected item"); | ||||||||
| Err(ResolveError::UnexpectedType { tcx, item: base, expected: "module" }) | ||||||||
| } | ||||||||
| } | ||||||||
| }) | ||||||||
| path.segments | ||||||||
| .into_iter() | ||||||||
| .try_fold((path.base, path.base_path_args.clone()), |(base, base_path_args), segment| { | ||||||||
| let name = segment.ident.to_string(); | ||||||||
| let def_kind = tcx.def_kind(base); | ||||||||
| let base = match def_kind { | ||||||||
| DefKind::ForeignMod | DefKind::Mod => resolve_in_module(tcx, base, &name), | ||||||||
| DefKind::Struct | DefKind::Enum | DefKind::Union => { | ||||||||
| resolve_in_type_def(tcx, base, &base_path_args, &name) | ||||||||
| } | ||||||||
| DefKind::Trait => resolve_in_trait_def(tcx, base, &name), | ||||||||
| kind => { | ||||||||
| debug!(?base, ?kind, "resolve_path: unexpected item"); | ||||||||
| Err(ResolveError::UnexpectedType { tcx, item: base, expected: "module" }) | ||||||||
| } | ||||||||
| }; | ||||||||
| base.map(|base| (base, segment.arguments)) | ||||||||
| }) | ||||||||
| .map(|it| it.0) | ||||||||
| } | ||||||||
|
|
||||||||
| /// Provide information about where the resolution failed. | ||||||||
|
|
@@ -781,7 +785,31 @@ fn is_item_name_with_generic_args( | |||||||
| // This is just a helper function for is_item_name_with_generic_args. | ||||||||
| // It's in a separate function so we can unit-test it without a mock TyCtxt or DefIds. | ||||||||
| fn last_two_items_of_path_match(item_path: &str, generic_args: &str, name: &str) -> bool { | ||||||||
| let parts: Vec<&str> = item_path.split("::").collect(); | ||||||||
| let mut angle_bracket_depth = 0; | ||||||||
| let mut parts = Vec::new(); | ||||||||
| let mut part_start = 0; | ||||||||
|
|
||||||||
| for (i, c) in item_path.char_indices() { | ||||||||
| match c { | ||||||||
| '<' => { | ||||||||
| angle_bracket_depth += 1; | ||||||||
| } | ||||||||
| '>' => { | ||||||||
| angle_bracket_depth -= 1; | ||||||||
| } | ||||||||
| ':' if angle_bracket_depth == 0 | ||||||||
| && i > 0 | ||||||||
| && item_path.chars().nth(i - 1) == Some(':') => | ||||||||
| { | ||||||||
| if part_start < i { | ||||||||
| parts.push(&item_path[part_start..i - 1]); | ||||||||
| } | ||||||||
| part_start = i + 1; | ||||||||
| } | ||||||||
| _ => {} | ||||||||
| } | ||||||||
| } | ||||||||
| parts.push(&item_path[part_start..]); | ||||||||
|
|
||||||||
| if parts.len() < 2 { | ||||||||
| return false; | ||||||||
|
|
@@ -793,7 +821,7 @@ fn last_two_items_of_path_match(item_path: &str, generic_args: &str, name: &str) | |||||||
| let last_two = format!("{}{}{}", generic_args, "::", name); | ||||||||
|
|
||||||||
| // The last two components of the item_path should be the same as ::{generic_args}::{name} | ||||||||
| last_two == actual_last_two | ||||||||
| last_two.chars().eq(actual_last_two.chars().filter(|c| !c.is_whitespace())) | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We strip whitespaces from the generic args here: kani/kani-compiler/src/kani_middle/resolve.rs Lines 589 to 591 in e0316ff
So multiple args like |
||||||||
| } | ||||||||
|
|
||||||||
| #[cfg(test)] | ||||||||
|
|
@@ -824,5 +852,13 @@ mod tests { | |||||||
| let item_path = format!("core::num::NonZero{}::{}", "::<u32>", name); | ||||||||
| assert!(!last_two_items_of_path_match(&item_path, generic_args, name)) | ||||||||
| } | ||||||||
|
|
||||||||
| #[test] | ||||||||
| fn generic_args_with_segmented_params() { | ||||||||
| let generic_args = "::<core::mem::MaybeUninit<T>,A>"; | ||||||||
| let name = "assume_init"; | ||||||||
| let item_path = format!("rc::Rc{}::{}", "::<core::mem::MaybeUninit<T>, A>", name); | ||||||||
| assert!(last_two_items_of_path_match(&item_path, generic_args, name)) | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
This file contains hidden or 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
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.
This is to fix argument passings when it is prefixed with module paths like
foo::bar::Baz::<..>