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

x/tools/go/cfg: add CFG.Dot method #65754

Closed
adonovan opened this issue Feb 16, 2024 · 7 comments
Closed

x/tools/go/cfg: add CFG.Dot method #65754

adonovan opened this issue Feb 16, 2024 · 7 comments

Comments

@adonovan
Copy link
Member

Proposal Details

The golang.org/x/tools/go/cfg.CFG type, which represents a syntactic control-flow graph, has an unexported method that renders the graph in AT&T graphviz format, which I have found useful for debugging.

I propose to export it:

// Graphviz returns the control-flow graph in AT&T GraphViz form.
// Use a command such as 'dot -Tsvg' to render it in a form viewable in a browser.
// This method is provided as a debugging aid; the details of the
// output are unspecified and may change. 
func (g *CFG) Graphviz(fset *token.FileSet) string
@gopherbot gopherbot added this to the Proposal milestone Feb 16, 2024
@timothy-king
Copy link
Contributor

It may be more flexible to have a cfg.Format function that takes an enum where Graphviz and the [default] (*CFG).Format are the initial options. This is also debatably overkill.

@adonovan
Copy link
Member Author

It may be more flexible to have a cfg.Format function that takes an enum where Graphviz and the [default] (*CFG).Format are the initial options.

CFG already has a Format method that doesn't take an enum.

@rsc
Copy link
Contributor

rsc commented Feb 28, 2024

Let's call it dot to match pprof's -dot flag. Otherwise seems fine.

@rsc rsc changed the title proposal: x/tools/go/cfg: publish 'CFG.Graphviz(*token.FileSet) string' method proposal: x/tools/go/cfg: add CFG.Dot method Mar 1, 2024
@rsc
Copy link
Contributor

rsc commented Mar 1, 2024

This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group

@adonovan adonovan self-assigned this Mar 2, 2024
@rsc
Copy link
Contributor

rsc commented Mar 8, 2024

Based on the discussion above, this proposal seems like a likely accept.
— rsc for the proposal review group

The proposal is to add:

// Dot returns the control-flow graph in the [Dot graph description language].
// Use a command such as 'dot -Tsvg' to render it in a form viewable in a browser.
// This method is provided as a debugging aid; the details of the
// output are unspecified and may change. 
//
// [Dot graph description language]: ​​https://en.wikipedia.org/wiki/DOT_(graph_description_language)
func (g *CFG) Dot(fset *token.FileSet) string

@rsc
Copy link
Contributor

rsc commented Mar 15, 2024

No change in consensus, so accepted. 🎉
This issue now tracks the work of implementing the proposal.
— rsc for the proposal review group

The proposal is to add:

// Dot returns the control-flow graph in the [Dot graph description language].
// Use a command such as 'dot -Tsvg' to render it in a form viewable in a browser.
// This method is provided as a debugging aid; the details of the
// output are unspecified and may change. 
//
// [Dot graph description language]: ​​https://en.wikipedia.org/wiki/DOT_(graph_description_language)
func (g *CFG) Dot(fset *token.FileSet) string

@rsc rsc changed the title proposal: x/tools/go/cfg: add CFG.Dot method x/tools/go/cfg: add CFG.Dot method Mar 15, 2024
@rsc rsc modified the milestones: Proposal, Backlog Mar 15, 2024
@gopherbot
Copy link

Change https://go.dev/cl/572016 mentions this issue: go/cfg: publish (*CFG).Dot method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Accepted
Development

No branches or pull requests

4 participants