-
Notifications
You must be signed in to change notification settings - Fork 11.7k
[sui-pkg-alt] move-analyzer fixes #24493
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
stefan-mysten
wants to merge
8
commits into
MystenLabs:sui-pkg-alt
Choose a base branch
from
stefan-mysten:sui-pkg-alt-move-analyzer-fixes
base: sui-pkg-alt
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.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
207730e
A few fixes to move-analyzer and a small optimization to reuse a rege…
stefan-mysten 2e63435
WIP
stefan-mysten 836236c
Cleanup and add back the compile_with_driver_and_deps function
stefan-mysten af8cd8d
Cleanup
stefan-mysten c914813
Cleanup
stefan-mysten 5cb210d
Cleanup
stefan-mysten 2b461c0
Cleanup
stefan-mysten 94e37f0
Cleanup
stefan-mysten 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
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
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
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 |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ use std::path::{Path, PathBuf}; | |
|
|
||
| use anyhow::{Context, Result, bail}; | ||
| use move_core_types::account_address::{AccountAddress, AccountAddressParseError}; | ||
| use once_cell::sync::Lazy; | ||
| use regex::Regex; | ||
| use tracing::debug; | ||
|
|
||
|
|
@@ -34,6 +35,9 @@ pub enum LegacySubstOrRename { | |
| /// The regex to detect `module <name>::<module_name>` on its different forms. | ||
| const MODULE_REGEX: &str = r"\bmodule\s+([a-zA-Z_][\w]*)::([a-zA-Z_][\w]*)"; | ||
|
|
||
| // Compile regex once at program startup | ||
| static MODULE_REGEX_COMPILED: Lazy<Regex> = Lazy::new(|| Regex::new(MODULE_REGEX).unwrap()); | ||
|
|
||
| /// This is a naive way to detect all module names that are part of the source code | ||
| /// for a given package. | ||
| /// | ||
|
|
@@ -111,18 +115,15 @@ fn find_files(files: &mut Vec<PathBuf>, dir: &Path, extension: &str, max_depth: | |
| // Consider supporting the legacy `address { module {} }` format. | ||
| fn parse_module_names(contents: &str) -> Result<HashSet<String>> { | ||
| let clean = strip_comments(contents); | ||
| let mut set = HashSet::new(); | ||
|
|
||
| // This matches `module a::b {}`, and `module a::b;` cases. | ||
| // In both cases, the match is the 2nd group (so `match.get(1)`) | ||
| let regex = Regex::new(MODULE_REGEX).unwrap(); | ||
|
|
||
| for cap in regex.captures_iter(&clean) { | ||
| set.insert(cap[1].to_string()); | ||
| } | ||
|
|
||
| Ok(set | ||
| .into_iter() | ||
| .filter(|name| !is_address_like(name.as_str())) | ||
| Ok(MODULE_REGEX_COMPILED | ||
| .captures_iter(&clean) | ||
| .filter_map(|cap| { | ||
| let name = &cap[1]; | ||
| (!is_address_like(name)).then(|| name.to_string()) | ||
| }) | ||
|
Comment on lines
117
to
+126
Contributor
Author
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. I think this should be slightly more optimized, particularly that we're reusing the REGEX rather than creating a new one every time. |
||
| .collect()) | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
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.
moved it up a bit