Skip to content
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

Request to Merge #4

Open
wants to merge 1 commit into
base: parent2b9a2
Choose a base branch
from
Open

Request to Merge #4

wants to merge 1 commit into from

Conversation

maorethians
Copy link
Owner

@maorethians maorethians commented Nov 4, 2024

User description

Note

I'm currently writing a description for your pull request. I should be done shortly (<1 minute). Please don't edit the description field until I'm finished, or we may overwrite each other. If I find nothing to write about, I'll delete this message.


PR Type

Bug fix, Tests


Description

  • Refactored the logic in Package.java to correctly handle the creation of implicit input files when using symbolic macros.
  • Introduced new methods createAssumedInputFiles and maybeCreateAssumedInputFile to streamline and document the process.
  • Enhanced test coverage in SymbolicMacroTest.java and PackageFactoryTest.java to verify the new behavior and ensure no implicit input files are created within symbolic macros.
  • Added detailed comments and documentation to clarify the logic and expected behavior.

Changes walkthrough 📝

Relevant files
Bug fix
Package.java
Refactor and fix implicit input file creation logic           

src/main/java/com/google/devtools/build/lib/packages/Package.java

  • Refactored logic for creating assumed input files.
  • Introduced createAssumedInputFiles and maybeCreateAssumedInputFile
    methods.
  • Improved handling of implicit input file creation for symbolic macros.
  • Added detailed documentation for new methods.
  • +103/-46
    Tests
    SymbolicMacroTest.java
    Enhance tests for symbolic macro input file behavior         

    src/test/java/com/google/devtools/build/lib/analysis/SymbolicMacroTest.java

  • Added comments to clarify macro behavior regarding input files.
  • Expanded test cases to cover new behavior.
  • Verified non-creation of implicit input files within symbolic macros.
  • +24/-5   
    PackageFactoryTest.java
    Add comprehensive tests for input file creation in macros

    src/test/java/com/google/devtools/build/lib/packages/PackageFactoryTest.java

  • Added new test cases for implicit input file creation.
  • Tested macro instantiation effects on input file creation.
  • Verified behavior when input files clash with macro targets.
  • +111/-6 

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Previously we weren't creating input files for labels used in the attribute of a top-level symbolic macro. This meant that if you wrote
    
    ```
    my_macro(
        name = "foo",
        srcs = ["input.txt"],
    )
    ```
    
    you'd get an error message claiming that input.txt is not declared and requires an `exports_files()`. (The usages of input.txt by targets declared inside of foo don't count, because implicit input file creation only works for usages of labels outside of symbolic macro bodies.)
    
    This CL fixes this behavior, refactors the relevant logic in Package.java, and adds more test coverage.
    
    Package.java:
    - Factor the big for loop from `beforeBuild()` to `createAssumedInputFiles()`. Leave the original for loop in place for test suite accumulation, and pull the `if (discover...)` out of the new call.
    - Factor the meat of the logic into a helper, `maybeCreateAssumedInputFile()`, so we can reuse it for both rules and macros (previously there was no loop over references in macros).
    - Add tedious javadoc to this tedious logic.
    
    SymbolicMacroTest.java
    - Add explanatory comment to `macroCanReferToInputFile()`.
    - Expand `macroCannotForceCreationOfImplicitInputFileOnItsOwn()` to check that the target is still not created when the inner usage is in an attr of a MacroInstance rather than a Rule.
    
    PackageFactoryTest.java
    - Expand comment in `testSymbolicMacro_macroPreventsImplicitCreationOfInputFilesUnderItsNamespace()`, include coverage for when the reference comes from within a target or submacro inside the symbolic macro itself.
    - New test case for the behavior of this CL, `..._macroInstantiationCanForceImplicitCreationOfInputFile()`.
    - Drive-by: Add a test case for when a badly named target in a symbolic macro clashes with an implicitly created input file. This behavior may be affected by lazy macro evaluation in the future.
    
    Confirmed that this CL works for the case I originally discovered it on while writing examples documentation.
    
    Fixes bazelbuild#24007.
    
    PiperOrigin-RevId: 686919555
    Change-Id: I6313070f76456c0b0b5d5458ca35c89d1d6da33b
    Copy link

    coderabbitai bot commented Nov 4, 2024

    Important

    Review skipped

    Auto reviews are disabled on base/target branches other than the default branch.

    Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

    You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


    Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

    ❤️ Share
    🪧 Tips

    Chat

    There are 3 ways to chat with CodeRabbit:

    • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
      • I pushed a fix in commit <commit_id>, please review it.
      • Generate unit testing code for this file.
      • Open a follow-up GitHub issue for this discussion.
    • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
      • @coderabbitai generate unit testing code for this file.
      • @coderabbitai modularize this function.
    • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
      • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
      • @coderabbitai read src/utils.ts and generate unit testing code.
      • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
      • @coderabbitai help me debug CodeRabbit configuration file.

    Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

    CodeRabbit Commands (Invoked using PR comments)

    • @coderabbitai pause to pause the reviews on a PR.
    • @coderabbitai resume to resume the paused reviews.
    • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
    • @coderabbitai full review to do a full review from scratch and review all the files again.
    • @coderabbitai summary to regenerate the summary of the PR.
    • @coderabbitai resolve resolve all the CodeRabbit review comments.
    • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
    • @coderabbitai help to get help.

    Other keywords and placeholders

    • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
    • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
    • Add @coderabbitai anywhere in the PR title to generate the title automatically.

    CodeRabbit Configuration File (.coderabbit.yaml)

    • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
    • Please see the configuration documentation for more information.
    • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

    Documentation and Community

    • Visit our Documentation for detailed information on how to use CodeRabbit.
    • Join our Discord Community to get help, request features, and share feedback.
    • Follow us on X/Twitter for updates and announcements.

    Copy link

    qodo-merge-pro bot commented Nov 4, 2024

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Performance Concern
    The conflict check in maybeCreateAssumedInputFile method has quadratic complexity. This could potentially lead to performance issues for large packages with many macros.

    Code Complexity
    The createAssumedInputFiles method is quite long and complex. Consider breaking it down into smaller, more focused methods to improve readability and maintainability.

    Incomplete Test
    The test case for lazy macro evaluation is currently commented out (TODO: bazelbuild#23852). Ensure this test is implemented when lazy macro evaluation is added to verify the expected behavior.

    Copy link

    qodo-merge-pro bot commented Nov 4, 2024

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Performance
    Use a more efficient data structure for checking macro namespace conflicts

    Consider using a more efficient data structure, such as a trie, to check for
    conflicts with macro namespaces. This can improve performance, especially for
    packages with many macros.

    src/main/java/com/google/devtools/build/lib/packages/Package.java [1612-1616]

    -for (MacroInstance macro : recorder.getMacroMap().values()) {
    -  if (TargetRecorder.nameIsWithinMacroNamespace(name, macro.getName())) {
    -    return;
    -  }
    +if (macroNamespaceTrie.hasConflict(name)) {
    +  return;
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: The suggestion proposes using a trie data structure instead of iterating through all macros, which could significantly improve performance for packages with many macros. This aligns with the TODO comment in the code about optimizing this quadratic complexity check.

    7
    Use stream processing for more efficient handling of assumed input file creation

    Consider using a stream or parallel processing to handle the creation of assumed
    input files for better performance, especially for packages with many rules and
    labels.

    src/main/java/com/google/devtools/build/lib/packages/Package.java [1553-1565]

    -for (Rule rule : recorder.getRules()) {
    -  if (!recorder.isRuleCreatedInMacro(rule)) {
    -    for (Label label : recorder.getRuleLabels(rule)) {
    -      maybeCreateAssumedInputFile(
    -          implicitlyCreatedInputFiles,
    -          pkg,
    -          recorder,
    -          noImplicitFileExport,
    -          label,
    -          rule.getLocation());
    -    }
    -  }
    -}
    +recorder.getRules().stream()
    +    .filter(rule -> !recorder.isRuleCreatedInMacro(rule))
    +    .flatMap(rule -> recorder.getRuleLabels(rule).stream())
    +    .forEach(label -> maybeCreateAssumedInputFile(
    +        implicitlyCreatedInputFiles,
    +        pkg,
    +        recorder,
    +        noImplicitFileExport,
    +        label,
    +        rule.getLocation()));
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: The suggestion to use stream processing could potentially improve performance for packages with many rules and labels. However, the impact may vary depending on the specific use case and the number of rules typically processed.

    6
    Best practice
    Use a factory method for creating InputFile instances to improve code structure

    Consider using a builder pattern or a separate factory method for creating InputFile
    instances to improve code readability and maintainability.

    src/main/java/com/google/devtools/build/lib/packages/Package.java [1618-1623]

     implicitlyCreatedInputFiles.put(
         name,
    -    noImplicitFileExport
    -        ? new PrivateVisibilityInputFile(pkg, label, loc)
    -        : new InputFile(pkg, label, loc));
    +    InputFileFactory.create(pkg, label, loc, noImplicitFileExport));
    • Apply this suggestion
    Suggestion importance[1-10]: 4

    Why: The suggestion to use a factory method for creating InputFile instances could improve code readability and maintainability. However, it's a relatively minor change that doesn't significantly impact the core functionality introduced in this PR.

    4
    Enhancement
    Use a more specific exception type for better error handling

    Consider using a more specific exception type instead of NoSuchPackageException in
    the beforeBuild method signature to provide more precise error handling.

    src/main/java/com/google/devtools/build/lib/packages/Package.java [1626]

    -private Builder beforeBuild(boolean discoverAssumedInputFiles) throws NoSuchPackageException {
    +private Builder beforeBuild(boolean discoverAssumedInputFiles) throws PackageCreationException {
    • Apply this suggestion
    Suggestion importance[1-10]: 3

    Why: While using a more specific exception type could improve error handling, the suggestion is not directly related to the main changes in the PR. The impact on the overall functionality is limited.

    3

    💡 Need additional feedback ? start a PR chat

    Copy link

    @korbit-ai korbit-ai bot left a comment

    Choose a reason for hiding this comment

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

    I've completed my review and didn't find any issues... but I did find this squirrel.

             _.-"""-,
           .'  ..::. `\
          /  .::' `'` /
         / .::' .--.=;
         | ::' /  C ..\
         | :: |   \  _.)
          \ ':|   /  \
           '-, \./ \)\)
              `-|   );/
                '--'-'
    
    Files scanned
    File Path Reviewed
    src/main/java/com/google/devtools/build/lib/packages/Package.java

    Explore our documentation to understand the languages and file types we support and the files we ignore.

    Need a new review? Comment /korbit-review on this PR and I'll review your latest changes.

    Korbit Guide: Usage and Customization

    Interacting with Korbit

    • You can manually ask Korbit to review your PR using the /korbit-review command in a comment at the root of your PR.
    • You can ask Korbit to generate a new PR description using the /korbit-generate-pr-description command in any comment on your PR.
    • Too many Korbit comments? I can resolve all my comment threads if you use the /korbit-resolve command in any comment on your PR.
    • Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
    • Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.

    Customizing Korbit

    • Check out our docs on how you can make Korbit work best for you and your team.
    • Customize Korbit for your organization through the Korbit Console.

    Current Korbit Configuration

    General Settings
    Setting Value
    Review Schedule Automatic excluding drafts
    Max Issue Count 10
    Automatic PR Descriptions
    Issue Categories
    Category Enabled
    Naming
    Database Operations
    Documentation
    Logging
    Error Handling
    Systems and Environment
    Objects and Data Structures
    Readability and Maintainability
    Asynchronous Processing
    Design Patterns
    Third-Party Libraries
    Performance
    Security
    Functionality

    Feedback and Support

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

    Successfully merging this pull request may close these issues.

    2 participants