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

tools: track tools/tooling updates to support generics #50558

Open
findleyr opened this issue Jan 11, 2022 · 16 comments
Open

tools: track tools/tooling updates to support generics #50558

findleyr opened this issue Jan 11, 2022 · 16 comments
Labels
NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository. umbrella
Milestone

Comments

@findleyr
Copy link
Member

findleyr commented Jan 11, 2022

Many tools and libraries that operate on Go code need to be updated to support generics. In most cases, this requires handling of the new constructs introduced in go/ast and go/types.

This is a tracking issue for the status of this support. It is based on #24661, which did the same for modules, though I added several tools/packages, and removed any that have been archived or that don't work directly with Go code.

It is not the case that every tool listed here needs updates to support generics -- many will require no changes. However, any tool that interacts with Go code might need to be updated, and probably needs additional tests.

Issue #50447 tracks adding a transitional API + user guide that should make it easier to get started updating third-party tools.

How to Help

  • Suggest additions to the list below. This list is certainly incomplete. Any tool or library that operates on Go code is a candidate for updating.
  • Comment if you're aware of the status of generics support in any of the items below, and I'll update accordingly (or update this comment yourself if you can).
  • Try building any of the tools below with Go 1.18, and test them on generic Go code. Comment with your findings.
  • Send a PR to update any of the tools below to support generics (this will probably be easier once x/exp/typeparams: a new module with a transitional API for tools #50447 is resolved).

List of tools / packages

@mvdan
Copy link
Member

mvdan commented Jan 12, 2022

I think the gogrep entry is a bit confusing :) The link doesn't point to a Go analysis tool, and the linked issue is about support for modules. Also, note that the actual repo has been archived, so I think we can just omit it entirely, unless there's a healthy fork somewhere.

For gofumpt, I think it already supports type parameters (https://github.com/mvdan/gofumpt/blob/ba9bdf90c2757f830763edbfb9ab401a50012fa8/testdata/scripts/typeparams.txt), so we can probably mark it as done unless there's a specific bug or missing feature you can point me to.

@findleyr
Copy link
Member Author

I think the gogrep entry is a bit confusing :)

Whoops! I started with the list from #24661, and missed that link. I removed the gogrep item, and marked gofumpt as done. Thanks!

@findleyr findleyr added the Tools This label describes issues relating to any tools in the x/tools repository. label Jan 12, 2022
@mvdan
Copy link
Member

mvdan commented Jan 12, 2022

In terms of the other tools, you already mentioend #50447, and I think #48525 also deserves a mention as a blocker. Some static analysis tools, like unparam or staticcheck, depend on SSA.

@thepudds
Copy link
Contributor

thepudds commented Jan 12, 2022

Hi @findleyr One thing that might be helpful is a pointer to a body of generic Go code to test against?

For example, I've pitched in a bit on dvyukov/go-fuzz, and I've confirmed that a hello world generic target seems to work, but I suspect more complicated examples might have problems. A while ago, I pulled together a small set of generics examples, but probably not representative enough, and it might be helpful to have a pointer here to a good set of examples.

Also, in case you haven't already seen this, there is a list of ~80 utilities here in golangci/golangci-lint#2438 (comment) with some high-level status for generics support, including red X's for "known to panic on generic code".

@nevkontakte
Copy link
Contributor

gopherjs/gopherjs#1013 is the specific issue that tracks Generics support in GopherJS.

@zephyrtronium
Copy link
Contributor

@thepudds

Hi @findleyr One thing that might be helpful is a pointer to a body of generic Go code to test against?

The test cases in test/typeparam might be useful for that.

@heschi heschi added the NeedsFix The path to resolution is known, but the work has not been done. label Jan 20, 2022
@findleyr
Copy link
Member Author

@thepudds thank you! Sorry for the slow turnaround: I will incorporate that list along with what I know about x/tools analyzers.

Regarding a corpus of generic code: @zephyrtronium's suggestion of test/typeparam is good. I also sometimes use go/types/testdata/examples. But the point stands: I think we should perhaps consider including a small corpus in the soon-to-be-created x/exp/typeparams module.

@ipfans
Copy link

ipfans commented Mar 20, 2022

Due to golangci-lint v1.45.0 being released, I think its status is now supported.

@findleyr
Copy link
Member Author

Thanks @ipfans -- I updated to note that golangci-lint has partial generics support.

@mvdan
Copy link
Member

mvdan commented Apr 24, 2022

Regarding a corpus of generic code: @zephyrtronium's suggestion of test/typeparam is good. I also sometimes use go/types/testdata/examples. But the point stands: I think we should perhaps consider including a small corpus in the soon-to-be-created x/exp/typeparams module.

I was wondering what's the current status of this, if it has evolved :) I tried using go/types/testdata/examples, but it contains some /* ERROR ... */ lines, presumably failing to typecheck on purpose - so it's no good as-is as a generic code corpus for tools. I also found https://github.com/golang/exp/tree/master/typeparams/example, though it seems to be a collection of example tools, so it's not quite what I'm after either.

@mvdan
Copy link
Member

mvdan commented Apr 24, 2022

To give some more context: I'm after hundreds of lines of Go code, not thousands or tens of thousands, because that code will need to be copied to each of the modules for the tools which I need to ensure don't panic on e.g. unexpected go/ast nodes for generic code. I imagine that one wouldn't need that much code to represent most syntax and typechecking edge cases :)

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/402254 mentions this issue: go.mod: update to golang.org/x/text v0.1.10

@findleyr
Copy link
Member Author

@mvdan

I was wondering what's the current status of this, if it has evolved :)

No status change as far as I know, sorry. I think we'd welcome an addition to x/exp/typeparams. Perhaps the corpus should be available as an importable package within that module? Would that work for your purposes, or would you more likely make a copy?

I tried using go/types/testdata/examples, but it contains some /* ERROR ... */ lines, presumably failing to typecheck on purpose

Yes, those comments denote expected errors.

  • so it's no good as-is as a generic code corpus for tools.

That depends on whether you want to test your tool in the presence of errors, I suppose, but your point stands. I think a good starting point for a corpus may be to filter out those error cases.

gopherbot pushed a commit to golang/text that referenced this issue Apr 28, 2022
go get -u golang.org/x/tools
go mod tidy

For golang/go#50558
Fixes golang/go#52552

Change-Id: I233aa90922fc23800563fd05beb4be6f7e87cf5b
Reviewed-on: https://go-review.googlesource.com/c/text/+/402254
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
@zchee
Copy link
Contributor

zchee commented Apr 29, 2022

@findleyr very nits, but goa/goagen link url is now https://github.com/golang/go/issues/github.com/goadesign/goa/goagen.

@findleyr
Copy link
Member Author

@findleyr very nits, but goa/goagen link url is now https://github.com/golang/go/issues/github.com/goadesign/goa/goagen.

Thanks. That URL doesn't look right (it starts with github.com/golang...), but I updated the goagen URL based on a Google search. Please let me know if it's still not right.

@zchee
Copy link
Contributor

zchee commented Apr 30, 2022

@findleyr Thanks for fix.

But, I'm not familiar with goa, but goa seems to already released v3 using v3 default branch. Also gen move to subcommand.

So, I think correct URL is just:
https://github.com/goadesign/goa

@seankhliao seankhliao added this to the Backlog milestone Aug 20, 2022
xhit pushed a commit to xhit/text that referenced this issue Oct 10, 2022
go get -u golang.org/x/tools
go mod tidy

For golang/go#50558
Fixes golang/go#52552

Change-Id: I233aa90922fc23800563fd05beb4be6f7e87cf5b
Reviewed-on: https://go-review.googlesource.com/c/text/+/402254
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository. umbrella
Projects
None yet
Development

No branches or pull requests

10 participants