-
Notifications
You must be signed in to change notification settings - Fork 137
[hermes] Finish shadow crate creation #3009
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
base: G93b59d9ea956b7e2e06b2e91c45dea803a391801
Are you sure you want to change the base?
[hermes] Finish shadow crate creation #3009
Conversation
Summary of ChangesHello @joshlf, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request finalizes the shadow crate creation feature for the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request completes the implementation of the shadow crate creation feature. It introduces a parallel file processing pipeline using rayon to traverse the module graph, transform source files, and write them to a shadow directory. Error handling is managed across threads using an mpsc channel, which is a robust approach. The overall architecture is a significant improvement over the previous implementation. I have one suggestion to enhance robustness by handling a potential panic.
| .context(format!("Failed to write shadow file {:?}", dest_path))?; | ||
|
|
||
| // Resolve and queue child modules for processing. | ||
| let base_dir = src_path.parent().unwrap(); |
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.
The use of .unwrap() could lead to a panic if src_path does not have a parent directory. While this might be unlikely for source files within a crate, it's more robust to handle this case gracefully.
Using anyhow::Context here would propagate the error through the existing Result-based error handling mechanism, which is more idiomatic than panicking.
| let base_dir = src_path.parent().unwrap(); | |
| let base_dir = src_path.parent().with_context(|| format!("path {:?} has no parent", src_path))?; |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## G93b59d9ea956b7e2e06b2e91c45dea803a391801 #3009 +/- ##
==========================================================================
Coverage 91.87% 91.87%
==========================================================================
Files 20 20
Lines 6057 6057
==========================================================================
Hits 5565 5565
Misses 492 492 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
2788a93 to
6f377df
Compare
|
/gemini review |
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.
Code Review
This pull request completes the implementation for creating shadow crates by introducing concurrent file processing using rayon. The overall structure is a significant improvement, with cleaner code in main.rs and well-factored logic in the shadow module. The use of a dedicated thread for error monitoring is a good pattern for handling concurrent operations.
I've identified a bug in the module path resolution for #[path] attributes that could lead to incorrect behavior, and a potential panic due to an unhandled unwrap(). Addressing these points will improve the tool's robustness.
| // 1. Handle explicit #[path = "..."] | ||
| if let Some(custom_path) = path_attr { | ||
| let p = base_dir.join(custom_path); | ||
| if p.exists() { | ||
| return Some(p); | ||
| } | ||
| return None; | ||
| } | ||
|
|
||
| // 2. Standard lookup: `foo.rs` | ||
| let inline = base_dir.join(format!("{}.rs", mod_name)); | ||
| if inline.exists() { | ||
| return Some(inline); | ||
| } | ||
|
|
||
| // 3. Standard lookup: `foo/mod.rs` | ||
| let nested = base_dir.join(mod_name).join("mod.rs"); | ||
| if nested.exists() { | ||
| return Some(nested); | ||
| } | ||
|
|
||
| None | ||
| } |
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.
The current module path resolution logic has a few issues that could lead to incorrect behavior or silent failures:
- The
#[path]attribute handling is incorrect. It usesp.exists(), which can be true for directories. If a directory path is returned,read_file_and_scan_compilation_unitwill fail later. According to the Rust reference, if the path is a directory, it should resolve todir/mod.rs. - The logic doesn't account for
#[path]attributes that omit the.rsextension (e.g.,#[path = "foo"]forfoo.rs). - Using
exists()for standard lookups is less precise thanis_file(). It's better to ensure we're dealing with files.
I've suggested a more robust implementation that correctly handles these cases, aligning better with Rust's module resolution rules.
// 1. Handle explicit #[path = "..."]
if let Some(custom_path) = path_attr {
let p = base_dir.join(custom_path);
if p.is_file() {
return Some(p);
}
if p.is_dir() {
let mod_path = p.join("mod.rs");
if mod_path.is_file() {
return Some(mod_path);
}
}
// The path attribute may omit the `.rs` extension.
let mut p_with_ext = p.into_os_string();
p_with_ext.push(".rs");
let p_with_ext = PathBuf::from(p_with_ext);
if p_with_ext.is_file() {
return Some(p_with_ext);
}
return None;
}
// 2. Standard lookup: `foo.rs`
let inline = base_dir.join(format!("{}.rs", mod_name));
if inline.is_file() {
return Some(inline);
}
// 3. Standard lookup: `foo/mod.rs`
let nested = base_dir.join(mod_name).join("mod.rs");
if nested.is_file() {
return Some(nested);
}
None| .context(format!("Failed to write shadow file {:?}", dest_path))?; | ||
|
|
||
| // Resolve and queue child modules for processing. | ||
| let base_dir = src_path.parent().unwrap(); |
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.
Using .unwrap() here could cause a panic if src_path does not have a parent directory (e.g., if it's a root path like /). While it's unlikely for a source file, it's more robust to handle this case gracefully by sending an error through the err_tx channel, consistent with other error handling in this function.
let base_dir = match src_path.parent() {
Some(p) => p,
None => {
let _ = err_tx.send(anyhow::anyhow!("Source file {:?} has no parent directory", src_path));
return;
}
};6f377df to
4ae812e
Compare
ab89fe4 to
176be07
Compare
gherrit-pr-id: G2f234da34d5c9cd516c08526882baaee631fe7d2
4ae812e to
1355228
Compare
176be07 to
030bb4e
Compare
mod foo;declarations #3008Latest Update: v32 — Compare vs v31
📚 Full Patch History
Links show the diff between the row version and the column version.
⬇️ Download this PR
Branch
git fetch origin refs/heads/G2f234da34d5c9cd516c08526882baaee631fe7d2 && git checkout -b pr-G2f234da34d5c9cd516c08526882baaee631fe7d2 FETCH_HEADCheckout
git fetch origin refs/heads/G2f234da34d5c9cd516c08526882baaee631fe7d2 && git checkout FETCH_HEADCherry Pick
git fetch origin refs/heads/G2f234da34d5c9cd516c08526882baaee631fe7d2 && git cherry-pick FETCH_HEADPull
Stacked PRs enabled by GHerrit.