Skip to content

Call graph as contract annotation #10990

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

Merged
merged 4 commits into from
Feb 23, 2021
Merged

Conversation

cameel
Copy link
Member

@cameel cameel commented Feb 23, 2021

Depends on #10973.

This is a refactor on top of #10973 that moves the call graph from CompilerStack to an annotation on contract definition. This makes it more convenient to access it.

The PR is already complete and ready for review but waiting for #10973 to get merged.

@cameel cameel self-assigned this Feb 23, 2021
@cameel cameel mentioned this pull request Feb 23, 2021
@cameel cameel force-pushed the call-graph-as-contract-annotation branch from f8dd04b to 781f007 Compare February 23, 2021 09:47
Comment on lines +167 to +170
/// A graph with edges representing calls between functions that may happen during contract construction.
SetOnce<std::shared_ptr<CallGraph const>> creationCallGraph;
/// A graph with edges representing calls between functions that may happen in a deployed contract.
SetOnce<std::shared_ptr<CallGraph const>> deployedCallGraph;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to use CallGraph as a value here but I had to use a pointer instead due to dependencies. CallGraph.h needs AST.h so including it here would create a dependency cycle. I had to use something that only requires a forward declaration.

And the reason that CallGraph.h can't just use ASTForward.h is that it uses ASTNode::CompareByID in member declarations.

Also, I wanted to at last have unique_ptr here but that does not work with an incomplete type so I had to use shared_ptr instead.

Comment on lines +254 to +257
/// @returns the parsed contract with the supplied name. Throws an exception if the contract
/// does not exist.
ContractDefinition const& contractDefinition(std::string const& _contractName) const;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any particular reason this was private? I made it public so that I can access the contract and its annotations without having to create special methods for that.

* Stores also extra information about contracts that can be created and events that can be emitted
* from any of the functions in it.
*/
struct CallGraph
Copy link
Member Author

@cameel cameel Feb 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have another class called CallGraph (in Yul optimizer). I'd prefer the name to be unique but any ideas that I have would make this pretty long (and it's used a lot as a prefix for Node and SpecialNode).

chriseth
chriseth previously approved these changes Feb 23, 2021
Copy link
Contributor

@chriseth chriseth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@cameel cameel marked this pull request as ready for review February 23, 2021 10:19
@cameel
Copy link
Member Author

cameel commented Feb 23, 2021

The graph PR has been accepted so I'm marking this as ready for review.

Base automatically changed from function-call-graph-v2 to develop February 23, 2021 10:42
@chriseth chriseth dismissed their stale review February 23, 2021 10:42

The base branch was changed.

@chriseth chriseth merged commit dd1ae5b into develop Feb 23, 2021
@chriseth chriseth deleted the call-graph-as-contract-annotation branch February 23, 2021 10:43
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

Successfully merging this pull request may close these issues.

2 participants