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

feat: Add ability to defer compilation #547

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

iliastsa
Copy link

@iliastsa iliastsa commented Feb 26, 2024

This PR adds the ability to defer compilation at a later stage, instead of doing it at the time of the CryticCompile object. This is useful when the client code wants to make use of some properties that are initialized before compilation is triggered.

Summary by CodeRabbit

  • New Features
    • Introduced a deferred compilation feature, enhancing flexibility in compilation management.
  • Refactor
    • Refactored metadata testing into two distinct functions for improved testing clarity.

Copy link

coderabbitai bot commented Feb 26, 2024

Walkthrough

The recent update introduces a significant enhancement to the CryticCompile class by adding a defer_compilation parameter, which offers the flexibility to defer the compilation process. A new method, compile, has been implemented to initiate compilation when required. Additionally, the testing suite has been refined by splitting a test function into two, focusing on standard and deferred compilation checks, streamlining the testing process for these new functionalities.

Changes

File Change Summary
crytic_compile/crytic_compile.py
tests/test_metadata.py
Added defer_compilation parameter and compile method to CryticCompile class for flexible compilation control.
Refactored test_metadata into metadata_checks and test_metadata_deferred to accommodate and test new deferred compilation feature.

🐰✨
In the realm of code, under digital skies,
A change was made, wise and sly.
Compilation deferred, flexibility gained,
With tests refactored, no clarity drained.
A hop, a skip, in binary meadows,
Celebrating the code, with shadows in echos.
🌟📚

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@CLAassistant
Copy link

CLAassistant commented Feb 26, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c0ad9f5 and 6e9e4e1.
Files selected for processing (2)
  • crytic_compile/crytic_compile.py (3 hunks)
  • tests/test_metadata.py (2 hunks)
Additional comments: 4
tests/test_metadata.py (1)
  • 46-55: The test_metadata_deferred function correctly tests the deferred compilation feature by setting defer_compilation=True and then explicitly calling crytic_compile_instance.compile(). This aligns with the PR objectives and demonstrates the intended use of the new feature. However, ensure that the compile method of CryticCompile is designed to handle being called in this manner, especially considering the initial state with no compilation units.
crytic_compile/crytic_compile.py (3)
  • 120-120: The addition of the defer_compilation parameter in the __init__ method introduces flexibility in managing the compilation process, allowing it to be deferred. This is a positive change that aligns with the PR objectives.
  • 209-210: The conditional check for defer_compilation to decide whether to compile immediately or defer is correctly implemented. However, ensure that all callers of CryticCompile are aware of this new behavior and correctly pass the defer_compilation flag based on their requirements.
  • 640-641: The new compile method enables deferred compilation by calling _compile with previously stored compilation arguments. This method is well-implemented and adheres to the DRY principle by reusing the _compile method. Ensure that this method is called appropriately wherever deferred compilation is needed.

tests/test_metadata.py Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6e9e4e1 and 275b036.
Files selected for processing (1)
  • tests/test_metadata.py (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/test_metadata.py

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 275b036 and c8d783d.
Files selected for processing (2)
  • crytic_compile/crytic_compile.py (2 hunks)
  • tests/test_metadata.py (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • crytic_compile/crytic_compile.py
  • tests/test_metadata.py

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c8d783d and 4a3acf4.
Files selected for processing (1)
  • crytic_compile/crytic_compile.py (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • crytic_compile/crytic_compile.py

Copy link
Member

@elopez elopez left a comment

Choose a reason for hiding this comment

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

Hi @iliastsa, thanks for the PR! Could you elaborate a bit more on the use case you see for this feature? I'm not sure what kind of information may be useful on an "uncompiled" CryticCompile object.

self._compile(**kwargs)
self.compilation_kwargs = kwargs

if not kwargs.get("crytic_defer_compilation") == "true":
Copy link
Member

Choose a reason for hiding this comment

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

Could this be a boolean instead of a magic string?

Suggested change
if not kwargs.get("crytic_defer_compilation") == "true":
if not kwargs.get("crytic_defer_compilation", False):

def test_metadata_deferred() -> None:
crytic_compile_instance = CryticCompile(
"0x6B175474E89094C44Da98b954EedeAC495271d0F", # solc 0.5.12
crytic_defer_compilation="true",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
crytic_defer_compilation="true",
crytic_defer_compilation=True,

Copy link
Author

Choose a reason for hiding this comment

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

That how I had it initially, but I was getting mypy errors due to the type of kwargs (only takes str right now). If we are ok with changing that to something like str | bool then I'm all for changing it.

@iliastsa
Copy link
Author

iliastsa commented Feb 29, 2024

Hi @iliastsa, thanks for the PR! Could you elaborate a bit more on the use case you see for this feature? I'm not sure what kind of information may be useful on an "uncompiled" CryticCompile object.

The idea is to be able to use various inferred facts from Crytic (config file paths, inferred build system etc). In our use-case we'd like to modify configuration files right before compilation.

One way to emulate this without adding additional flags is to subclass the CryticCompile class and override the _compile method, something like:

class MyCryticCompile(CryticCompile):
     def _compile(self, **kwargs):
         # My logic here before compilation
         ...
        super()._compile(kwargs)
        # My logic here after compilation
        ...

but I think offering this capability with out having to create a new class is a bit cleaner.

@0xalpharush
Copy link
Contributor

We just need to get the linters passing @iliastsa

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.

4 participants