-
Notifications
You must be signed in to change notification settings - Fork 570
Use go/types in Go 1.5 standard library. #278
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
Conversation
This is fully functional and ready for review now. See commit messages for known issues/limitations. I welcome suggestions for alternate better implementations of "Restore behavior of setting importError in Compile." commit. I was considering trying to return a custom error that implements an interface and checking for that (instead of assigning a local variable). See http://dave.cheney.net/2014/12/24/inspecting-errors for inspiration source (/cc @davecheney). However, I'm not sure it'll work great here. |
dc8548f
to
abe91a0
Compare
CI test keps failing on
Can't reproduce it locally:
Edit: Yep, it's the same test failure as what happened recently on |
Hopefully I've fixed the stack size issue with 1f89545. Alan Donovan said here golang/go#11861 (comment) that he wants to switch over the whole |
Great! Feel free to rebase this branch and omit the last commit then. Otherwise I'll do it next day.
Sounds good to me. This PR can stay open until then, so hopefully no one else spends time on this. |
https://go-review.googlesource.com/#/c/18207/ has been merged, that means this PR can now be merged pending review. It'll need to be updated first. |
In fact, this needs to be done quickly, because latest version (what you get if you
|
For others experiencing this problem a temporary workaround is something along the lines of:
|
I'm working on making this PR merge-able right now. |
Package golang.org/x/tools/go/types has moved into Go 1.5 standard library as go/types. Package golang.org/x/tools/go/exact is moved/renamed to go/constant.
Updated the PR. I was working on removing the vendored/modified packages (e.g., see commit message of 5c4af73), however I learned that of the two packages that are kept in x/tools, only one was updated to use the new "go/types" import paths, but not the other. So I ended up having to keep vendoring/modifying one of those two packages. See 76e265b. This is needed to be able to compile without errors, until that package is fixed upstream. I've made a comment about it at https://go-review.googlesource.com/#/c/18207/ and awaiting response. |
After looking into it more, I'm less sure about the status and future of According to the current version of https://groups.google.com/forum/#!topic/golang-announce/qu_rAphYdxY, it says:
I'm not sure if something has changed since the last time I worked on it or not. But perhaps it's possible to use |
go/types defines some types just like golang.org/x/tools/go/types, but because they have different import paths, those types are not interchangeable. Not all packages have moved into Go standard library. Namely, golang.org/x/tools/go/importer and golang.org/x/tools/go/types/typeutil are still living in x/tools subrepo. While golang.org/x/tools/go/types/typeutil has been updated to import go/types in https://golang.org/cl/18207, it appears golang.org/x/tools/go/importer has not yet been updated in a similar way. So if we import it as is, we would have incompatible types defined in go/types and golang.org/x/tools/go/types. A temporary solution to have a working codebase is to vendor that package and modify it to import go/types. This can be undone as soon as the upstream package is modified to import go/types itself. I've asked about its status in the aforementioned CL, awaiting a reply in order to figure out the best plan forward.
The type of go/types.Importer has changed from a func to an interface. Make appropriate changes. Maintain behavior of setting importError in Compile. This is needed to maintain the fix for #119.
@shurcooL Thanks for digging into this topic and working on this contribution! Very much appreciated. As far as I can see, |
I've followed up about that by asking a question at https://go-review.googlesource.com/#/c/18382. |
Robert Griesemer has answered the question, please see: https://groups.google.com/d/msg/golang-codereviews/t0XvZyHIWz4/zkDrwuzHCgAJ /cc @neelance I highly recommend you read it since it mentions the future plans for new binary export format and import/export, and prompts for feedback, in case you have some thoughts/suggestions/use cases in mind. I replied here. Basically, as far as this PR is concerned, there is no follow up action that needs to be done. We will continue to vendor x/tools/go/importer for the time being because there are no plans to provide one upstream that is compatible with new go/types. |
The copied importer is an old package from Go 1.5 times. It was a copy of x/tools/go/importer package. It does not support type aliases added in Go 1.9. Encountering a type alias declaration caused a panic. Use the gcimporter15 package instead. It supports a more modern binary export format and includes support for type aliases. The gcimporter15 package is marked as deprecated and said to be deleted in October 2017. However, the replacement package does not expose the functionality suitable for GopherJS current needs. That means we'll need to find a resolution by the time it's deleted. It will either be a feature request to add the needed functionality, a rewrite of GopherJS code to use available functionality, or vendoring/copying the code. Updates #278.
Do not merge, this PR is a work in progress. It's created for initial review and to avoid potential duplicate work.
With the release of Go 1.5, go/types and some related packages have moved from golang.org/x/tools subrepo to standard library. We can start using them. This PR is about making that so.
There are currently 3 commits, first one is clean and ready, the other two are WIP and need some work.
We need to use golang.org/x/tools/go/importer and x/tools/go/types/typeutil, which continue to live in golang.org/x/tools but have not yet been updated to import the new go/types. Instead, they still import the old golang.org/x/tools/go/types. Despite being identical, those packages have different import paths, and as a result the types they define cannot be used interchangeably.
For now, vendor those packages and modify them to use the new go/types package. Hopefully that change will be done upstream soon (see golang/tools@12c48ce for a first similar change) and vendoring/modifying them will becoming unnecessary.
Update: This PR is now updated and needs to be merged soon in order to resolve #373.
Resolves #373.