-
Notifications
You must be signed in to change notification settings - Fork 83
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
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThe recent update introduces a significant enhancement to the Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
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.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
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 settingdefer_compilation=True
and then explicitly callingcrytic_compile_instance.compile()
. This aligns with the PR objectives and demonstrates the intended use of the new feature. However, ensure that thecompile
method ofCryticCompile
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 ofCryticCompile
are aware of this new behavior and correctly pass thedefer_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.
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
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
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
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
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
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
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.
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": |
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.
Could this be a boolean instead of a magic string?
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", |
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.
crytic_defer_compilation="true", | |
crytic_defer_compilation=True, |
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.
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.
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 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. |
We just need to get the linters passing @iliastsa |
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