Skip to content

Conversation

@joshlf
Copy link
Member

@joshlf joshlf commented Feb 12, 2026


This PR is on branch hermes.

⬇️ Download this PR

Branch

git fetch origin refs/heads/G3j7gcwkk2kr2uix4cyeyxid6egsuoa4e && git checkout -b pr-G3j7gcwkk2kr2uix4cyeyxid6egsuoa4e FETCH_HEAD

Checkout

git fetch origin refs/heads/G3j7gcwkk2kr2uix4cyeyxid6egsuoa4e && git checkout FETCH_HEAD

Cherry Pick

git fetch origin refs/heads/G3j7gcwkk2kr2uix4cyeyxid6egsuoa4e && git cherry-pick FETCH_HEAD

Pull

git pull origin refs/heads/G3j7gcwkk2kr2uix4cyeyxid6egsuoa4e

Stacked PRs enabled by GHerrit.

gherrit-pr-id: G3j7gcwkk2kr2uix4cyeyxid6egsuoa4e
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 significantly improves the robustness and correctness of the Hermes tool by addressing how it handles Rust items defined within blocks and complex module structures. It introduces a mechanism to explicitly reject annotated items that are not reliably nameable within Rust's module system, preventing potential issues with verification. Furthermore, it enhances the module scanning process to correctly handle and detect cyclic module dependencies, avoiding infinite loops, and refines the way entry points are passed to Charon, ensuring that all relevant annotated items are considered for verification, even if they require falling back to their parent module.

Highlights

  • Rejection of Annotated Items in Blocks: Implemented logic to reject Hermes annotations on items defined within Rust blocks (e.g., const blocks, function bodies), preventing verification of unnameable items.
  • Improved Module Path Handling and Cycle Detection: Enhanced module scanning to detect and prevent infinite recursion caused by cyclic module declarations (e.g., #[path = "lib.rs"] mod self_loop;), improving the robustness of the module graph traversal.
  • Refined Charon start-from Argument Generation: Refined the generation of --start-from arguments for Charon, falling back to the parent module for items that cannot be reliably named (like impl blocks, impl functions, and trait functions) while still targeting specific items when possible.
  • Deduplication of start-from Entry Points: Added deduplication for start_from entry points to optimize Charon calls, especially when multiple unnameable items in the same module lead to redundant module-level entries.
  • New Test Fixtures: Introduced new test fixtures to cover scenarios like annotated items in const blocks, cyclic module paths, double-mounted modules, and impl fallback behavior, ensuring comprehensive testing of the new logic.

🧠 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
  • tools/hermes/src/charon.rs
    • Added dedup() call to start_from list to remove duplicate entrypoints.
  • tools/hermes/src/parse.rs
    • Removed unused quote::quote import.
    • Extended ParsedItem enum to include TraitItemFn.
    • Updated ParsedItem::name() and ParsedItem::attrs() methods to support TraitItemFn.
    • Added inside_block field to UnloadedModule struct to track if a module is declared within a block.
    • Modified scan_compilation_unit and read_file_and_scan_compilation_unit functions to accept and propagate the inside_block parameter.
    • Removed an unused variable _x.
    • Initialized HermesVisitor.inside_block with the new parameter.
    • Renamed check_and_add method to process_item in HermesVisitor.
    • Updated visit_item_mod to set the inside_block flag for UnloadedModule.
    • Replaced calls to check_and_add with process_item for various item types.
    • Simplified visit_item_impl by removing path manipulation logic.
    • Added visit_trait_item_fn to HermesVisitor.
    • Updated test calls to scan_compilation_unit_internal to include the inside_block parameter.
  • tools/hermes/src/resolve.rs
    • Added kind: HermesTargetKind field to HermesTargetName struct.
    • Initialized the kind field when creating HermesTargetName.
  • tools/hermes/src/scanner.rs
    • Removed unused dashmap::DashSet import.
    • Modified llbc_file_name generation to include target_kind in the hash, preventing naming collisions for different target types.
    • Removed visited_paths (DashSet) from scan_workspace and process_file_recursive arguments.
    • Introduced inside_block: bool and ancestors: Vec<PathBuf> parameters to process_file_recursive for improved module tracking and cycle detection.
    • Implemented cycle detection using the ancestors path list.
    • Updated item processing logic to fall back to the parent module for Impl, ImplItemFn, and TraitItemFn when sending start_from paths.
    • Passed module.inside_block and ancestors to recursive calls of process_file_recursive.
    • Added a new test case test_llbc_file_name_collision.
  • tools/hermes/src/ui_test_shim.rs
    • Updated read_file_and_scan_compilation_unit call to pass false for the new inside_block parameter.
  • tools/hermes/tests/fixtures/complex_impl/expected_config.toml
    • Updated the --start-from argument to target the entire crate instead of specific impl paths.
  • tools/hermes/tests/fixtures/complex_impl/expected_status.txt
    • Changed expected test status from failure to success.
  • tools/hermes/tests/fixtures/const_block_blind_spot/expected_status.txt
    • Added expected test status for a new fixture.
  • tools/hermes/tests/fixtures/const_block_blind_spot/expected_stderr.txt
    • Added expected stderr output for a new fixture.
  • tools/hermes/tests/fixtures/const_block_blind_spot/source/Cargo.toml
    • Added new Cargo.toml for a test fixture.
  • tools/hermes/tests/fixtures/const_block_blind_spot/source/src/lib.rs
    • Added new test source code with an annotated function inside a const block.
  • tools/hermes/tests/fixtures/cyclic_paths/expected_stderr.txt
    • Added expected stderr output for a new fixture.
  • tools/hermes/tests/fixtures/cyclic_paths/source/Cargo.toml
    • Removed unused dependencies section.
  • tools/hermes/tests/fixtures/cyclic_paths/source/src/lib.rs
    • Removed explanatory comments from the test source.
  • tools/hermes/tests/fixtures/double_mounted_mod/expected_config.toml
    • Added expected start-from arguments for a new fixture.
  • tools/hermes/tests/fixtures/double_mounted_mod/expected_status.txt
    • Added expected test status for a new fixture.
  • tools/hermes/tests/fixtures/double_mounted_mod/source/Cargo.toml
    • Added new Cargo.toml for a test fixture.
  • tools/hermes/tests/fixtures/double_mounted_mod/source/src/lib.rs
    • Added new test source code demonstrating double-mounted modules.
  • tools/hermes/tests/fixtures/double_mounted_mod/source/src/shared.rs
    • Added new shared source file for a test fixture.
  • tools/hermes/tests/fixtures/impl_fallback_dedup/expected_config.toml
    • Added expected start-from arguments for a new fixture, demonstrating deduplication.
  • tools/hermes/tests/fixtures/impl_fallback_dedup/expected_status.txt
    • Added expected test status for a new fixture.
  • tools/hermes/tests/fixtures/impl_fallback_dedup/source/Cargo.toml
    • Added new Cargo.toml for a test fixture.
  • tools/hermes/tests/fixtures/impl_fallback_dedup/source/src/lib.rs
    • Added new test source code demonstrating impl fallback and deduplication.
  • tools/hermes/tests/fixtures/impl_path/expected_config.toml
    • Modified expected start-from argument to be more general.
  • tools/hermes/tests/fixtures/macro_blind_spot/expected_status.txt
    • Added expected test status for a new fixture.
  • tools/hermes/tests/fixtures/macro_blind_spot/expected_stderr.txt
    • Added expected stderr output for a new fixture.
  • tools/hermes/tests/fixtures/macro_blind_spot/source/Cargo.toml
    • Added new Cargo.toml for a test fixture.
  • tools/hermes/tests/fixtures/macro_blind_spot/source/src/lib.rs
    • Added new test source code with an annotated item generated by a macro.
  • tools/hermes/tests/fixtures/nested_item_error/expected_stderr.txt
    • Updated expected stderr output for nested item errors to be more detailed.
  • tools/hermes/tests/fixtures/nested_out_of_line_mod/expected_status.txt
    • Added expected test status for a new fixture.
  • tools/hermes/tests/fixtures/nested_out_of_line_mod/expected_stderr.txt
    • Added expected stderr output for a new fixture.
  • tools/hermes/tests/fixtures/nested_out_of_line_mod/source/Cargo.toml
    • Added new Cargo.toml for a test fixture.
  • tools/hermes/tests/fixtures/nested_out_of_line_mod/source/src/hidden.rs
    • Added new source file for a test fixture.
  • tools/hermes/tests/fixtures/nested_out_of_line_mod/source/src/lib.rs
    • Added new test source code with an out-of-line module in a function.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 introduces a significant change to reject Hermes annotations on items defined within blocks (like function bodies), which is an important correctness fix to avoid unsound verification. The implementation correctly uses the syn visitor to track whether it's inside a block and raises an error for annotated items.

The PR also includes several valuable refactorings and improvements:

  • A new fallback strategy for items in impl blocks, which are hard to name reliably. Instead of complex path construction, it now uses the parent module path, with deduplication to keep the argument list clean.
  • Improved module processing logic, replacing a global visited set with per-path ancestor tracking. This correctly handles files included as modules in multiple places while still preventing infinite recursion from cyclic module declarations.
  • Better differentiation of compilation targets by including the target kind in HermesTargetName and the generated .llbc filename hash.

The changes are well-supported by a comprehensive set of new and updated tests that cover the new error conditions, the fallback strategy, and edge cases in module resolution.

I have a couple of minor suggestions for improving panic robustness in channel communication.

// back to naming the parent module.
Impl(_) | ImplItemFn(_) | TraitItemFn(_) => {
let start_from = full_path.join("::");
path_tx.send((name.clone(), start_from)).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using .unwrap() here could cause a panic if the receiving end of the channel is dropped, for example, if another part of the program panics. It would be more robust to handle the Result of send, for instance by ignoring the error, similar to how err_tx.send is handled. This prevents a double panic.

Suggested change
path_tx.send((name.clone(), start_from)).unwrap();
let _ = path_tx.send((name.clone(), start_from));

full_path.push(item_name);
let start_from = full_path.join("::");
log::debug!("Found entry point: {}", start_from);
path_tx.send((name.clone(), start_from)).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the comment above, using .unwrap() here could cause a panic. It's safer to ignore the result of the send operation.

Suggested change
path_tx.send((name.clone(), start_from)).unwrap();
let _ = path_tx.send((name.clone(), start_from));

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (Gegf4fywvkwtqzwzektqc5lett4skoxvx@4aaf99d). Learn more about missing BASE report.

Additional details and impacted files
@@                         Coverage Diff                          @@
##             Gegf4fywvkwtqzwzektqc5lett4skoxvx    #3046   +/-   ##
====================================================================
  Coverage                                     ?   91.87%           
====================================================================
  Files                                        ?       20           
  Lines                                        ?     6057           
  Branches                                     ?        0           
====================================================================
  Hits                                         ?     5565           
  Misses                                       ?      492           
  Partials                                     ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants