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

Expose import graph in output json #11716

Closed
d-xo opened this issue Jul 28, 2021 · 4 comments
Closed

Expose import graph in output json #11716

d-xo opened this issue Jul 28, 2021 · 4 comments

Comments

@d-xo
Copy link
Contributor

d-xo commented Jul 28, 2021

Abstract

Exposing the import graph as part of the compiler output would make implementing incremental compilation workflows in frameworks a lot easier.

Motivation

One very common feature request for dapptools is support for incremental compilation, especially for larger projects or monorepos. In order to do this we would need to parse the solidity files in the project, and build some tree or graph like structure showing which contracts are imported and where.

Once we have this graph we can pretty easily determine the set of changed contracts, and then use the graph to determine which contracts should be recompiled.

Presumably solidity already builds such a structure as part of the compilation process, it would be very helpful if this could be exposed as part of the build artifacts.

@chriseth
Copy link
Contributor

You can construct an import graph from the AST. For features like incremental compilation, we also recently implemented the --stop-after parsing feature, which essentially only parses the input files and does not auto-load imported dependencies that were not given as input, but can still export an AST.

The ImportDirective has the following attributes:

  • file (just the string in the source code)
  • sourceUnit the AST ID of the referenced file
  • absolutePath the resolved absolute path as seen by the compiler inside its internal virtual file system (this is the unique name that characterizes the referenced source unit)

How to go from absolutePath to a file on the local filesystem depends on the way you invoke the compiler.

Can you work with this information or do you need anything else?

@d-xo
Copy link
Contributor Author

d-xo commented Jul 28, 2021

Ah interesting. Yes I think we can work with this. Thanks!

@cameel
Copy link
Member

cameel commented Sep 19, 2021

@d-xo Is #11756 a blocker for you regarding incremental compilation? The bug is that --stop-after parsing does not currently provide absolutePath. Perhaps we should prioritize it a bit more?

@d-xo
Copy link
Contributor Author

d-xo commented Sep 21, 2021

Hmmmm yes I think it probably is. Otherwise we would have to maintain a copy of the file resolution stages ourselves in dapp.

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

No branches or pull requests

3 participants