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

add option to forge build to only get the AST without compiling to bytecode #7212

Open
0xalpharush opened this issue Feb 22, 2024 · 3 comments
Labels
T-feature Type: feature

Comments

@0xalpharush
Copy link
Contributor

0xalpharush commented Feb 22, 2024

Component

Forge

Describe the feature you would like

UPDATE see #7212 (comment)

I would like the forge build command to expose this, so one can pass --stop-after parsing solc and only get the AST without compiling to bytecode

As a potential optimization, foundry could look if the solidity files' content is unchanged and reuse the AST on disk for compilation by giving them to solc when forge build --stop-after parsing && forge build/test is run.

Additional context

from https://github.com/ethereum/solidity/blob/develop/docs/using-the-compiler.rst#compiler-input-and-output-json-description:

{
      // If language is set to "SolidityAST", an AST needs to be supplied under the "ast" key
      // and there can be only one source file present.
      // The format is the same as used by the `ast` output.
      // Note that importing ASTs is experimental and in particular that:
      // - importing invalid ASTs can produce undefined results and
      // - no proper error reporting is available on invalid ASTs.
      // Furthermore, note that the AST import only consumes the fields of the AST as
      // produced by the compiler in "stopAfter": "parsing" mode and then re-performs
      // analysis, so any analysis-based annotations of the AST are ignored upon import.
      "ast": { ... }
    },
@0xalpharush 0xalpharush added the T-feature Type: feature label Feb 22, 2024
@mds1
Copy link
Collaborator

mds1 commented Feb 26, 2024

@klkvr Related to #5041 where we'd want similar functionality to only get ABIs without compiling, so we know which contracts to compile

@0xalpharush
Copy link
Contributor Author

This is not strictly blocked by ethereum/solidity#15043 as additional stages would be trivial to add but it may be premature considering the original use case needs a semantic stage.

@0xalpharush
Copy link
Contributor Author

@klkvr Is there a way to not request bin and only request ast with Foundry. I think forge build --ast (not sure why this wasn't just added to --extra-output) still requests the bytecode. I would prefer the AST in the hardhat style artifact just with everything else missing (key is there but value is empty) because the foundry native artifact format has several latent bugs e.g. gakonst/ethers-rs#1995

@0xalpharush 0xalpharush changed the title add --stop-after parsing to pass to solc and only get the AST without compiling to bytecode add option to forge build to only get the AST without compiling to bytecode May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-feature Type: feature
Projects
None yet
Development

No branches or pull requests

2 participants