-
Notifications
You must be signed in to change notification settings - Fork 797
Conversation
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.
I like this a lot,
this also makes very easy to add new nodes that share a lot of things instead of writing serde(flatten)
containers
and customizing them is still possible
Yep concept ack |
It may be worthwhile to explore https://github.com/ConsenSys/solc-typed-ast to compare OZs implementation against |
I'm already comparing against a typed implementation as described in the PR |
The repo i linked provides an ast with "xpath" support, its used in scribble to help provide instrumentation coverage, should have mentioned that too sorry. |
I think xpath support is out of scope for this PR since it is a bigger feature and the most immediate need here is supporting some coverage features |
Just added some test fixtures from Solmate, will try to slim it down lmfao |
@mattsse any preference on how we safeguard against breaking stuff in solc? rn if the AST won't deserialize everything breaks, but it is used by ethers-solc in at least one place, so either we find a way to replace that, or we try to deserialize to a smaller ast on failure? |
As a note here, I gave up on supporting the legacy AST layout. At first I thought it was just some properties that were lifted into a nested
where left and right expression in the legacy AST would be in |
Yeah I think for coverage-related stuff we can afford to say "this is for after solidity version XXX" what's the next step after this PR? integrate in coverage? |
Yes, integrate into coverage to get library coverage |
perhaps upcoming generics will break some things here, how we handled semver incompatible |
bump @onbjerg |
@onbjerg @mattsse what should we do here? do we want this to get over the line and we are just not allocated on it (in which case I'll find someone else to cover) or do we not think this is going to be a material improvement? this also ended up going deep in the AST so maybe helpful too? https://github.com/0xKitsune/solstat |
Imo, it makes sense to have this, if someone is going to use this, they can improve this where necessary |
The ast was very well done with the macros it makes totally sense. I have fixed some bugs because of needing it, I can add them to the branch |
@iFrostizz yes that would be great. keen to get this over the line, so if you want to submit a new branch (or something that forks off this PR) that works! thank you |
I've opened the PR. |
sgtm! lets do that. unsure about foundry impact, most likely coverage. |
Fixing bugs in the onbjerg ast
superseded by #1943 |
Motivation
Working with the Solc AST right now is not super ergonomic and it's making it hard to provide support for library coverage in Foundry, since for that feature we would need to walk out to each call expression node and parse the type name. It's doable currently, but a lot of the nice information in the AST is rolled into
other
, so it's not super easy or maintanable.Solution
Replace the AST abstraction with more strict types. Each node gets its own type loosely based on https://github.com/OpenZeppelin/solidity-ast which claims to have a wide Solidity version support. I'll also add a
Visitor
trait with somewalk_*
helper functions for easier traversal.I've opened up this PR because I am currently at an impasse: I've started implementing macros to generate some of the common fields in the different nodes, but we could also use struct composition instead.
The downside of struct composition is that you have to "reach" and I am having some struggle coming up with nice names. For example, the two most common fields are
id
andsrc
... we could call these "meta", but then what about the expression meta-fields? If we called them "node", then it's a bit awkward since you'd probably have a lot of code doing things likenode.node.id
.If we called these fields "meta", and the common expression fields "expression", then you'd instead have a lot of code doing
expr.expression
.The downside of macros is that it might be slow to compile, too opaque or too inflexible.
Thoughts @mattsse @gakonst?
(Docs + doc comments and so on coming later, this is very much a WIP)
PR Checklist