Skip to content

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

Open
@0xalpharush

Description

@0xalpharush

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": { ... }
    },

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions