-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
go/ast, go/token: additions to support type parameters #47781
Comments
Thanks for the proposal. Typo: "invalid or invalid" -> "valid or invalid"? I think the general representation of optional arguments/parameter is ok. Perhaps a better name can be found for MultiIndexExpr: BracketedExpr? (I do not think of type parameters or instantiations as "indices") But, I don't quite understand why suppositions about the completeness of a set of node types is a concern in the stdlib but the same is not a concern about token: The dev.typeparams commit 7c5d7a4 introduced token.TILDE. Why does the same concern not hold there? I think that one way to handle these issues is documentation: we could state that for go/* stdlib libraries, all exported sets of constants and types can be extended to facilitate language changes: do not assume switches handle all (possibly future) cases. Could you post a link to the issue for the type proposal here when you are ready? |
invalid or invalid -> valid or invalid, as pointed out in golang/go#47781 (comment) (thanks) Change-Id: I203a06a3280bb6a20ac87f78ddf49990b1812331 Reviewed-on: https://go-review.googlesource.com/c/proposal/+/343549 Reviewed-by: Robert Findley <rfindley@google.com>
@scott-cotton thank you for the feedback.
Fixed, thanks.
I think an advantage of MultiIndexExpr is similarity with IndexExpr. If we could start over these would be the same node, but since we can't it's important to keep them associated.
You're right that we should extend the same concern to TILDE. I was more concerned about node completeness because I was already aware of places in the x/tools codebase that would panic when encountering an unknown node. One additional argument for adding a new node is that the panic exists to be sure your type switch covers all syntax. In this context, it would actually be unhelpful to hide the change by packing the new syntax into existing nodes. Perhaps that's overly optimistic.
Yes, will do. |
@scott-cotton the go/types proposal is filed as #47916. |
What's the rationale for adding |
@mdempsky that is the rationale. If we put It wasn't an obvious choice though. |
This proposal has been added to the active column of the proposals project |
I'm slightly surprised by the choice of TParams as a name. TypeParams is just slightly longer, and much clearer. I also might mistake TParams for Params or vice versa when quickly reading or reviewing code.
I agree with the decision to go with
Continuing on the point above: this is how I write my type switches in general, including those using If the addition was made to an existing type, the strong and clear signal via a default case panic would not be there, and I might not notice that my tool actually needs changes to support new or changed node struct fields in existing types. |
Thanks for the feedback. I don't feel the same way, but I've been staring at this for a while. With TParams (and TArgs), I've grown accustomed to seeing 'T' as a modifier. With that said, we already have the TypeParam type in go/types, and you are right that TypeParams is not significantly more verbose. We can consider changing the naming convention, but of course if we decide to switch we should apply this change to go/types as well.
Yes, I was concerned at first but have come around to adding a new node as the clear best option. With something like #47783 I don't think it will be a large burden on tool authors to update their code to avoid the panic, especially since many tools will want to have explicit support for type parameters anyway. |
It might be nice to have MultiIndexExpr next to IndexExpr in the docs. Maybe IndexListExpr? |
It does seem a bit odd to have the type params in ast.FuncType and not ast.FuncDecl. |
@griesemer and I just discussed, and here is our current thinking:
|
Change https://golang.org/cl/348375 mentions this issue: |
As discussed in the ast proposal (#47781), there's not really a strong reason to avoid spelling out 'Type'. Change-Id: I0ba1bf03b112ea60509a78a89a050a302779d9d0 Reviewed-on: https://go-review.googlesource.com/c/go/+/348375 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
Based on the discussion above, this proposal seems like a likely accept. |
Change https://golang.org/cl/348609 mentions this issue: |
As discussed in #47781, IndexListExpr is one character shorter and has the advantage of being next to IndexExpr in documentation. Updates #47781 Change-Id: I709d5c1a79b4f9aebcd6445e4ab0cd6dae45bab7 Reviewed-on: https://go-review.googlesource.com/c/go/+/348609 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
Change https://golang.org/cl/348382 mentions this issue: |
Following discussion in golang/go#47781, MultiIndexExpr was renamed to IndexListExpr. Change-Id: Ib8b0d138265d34b5764f5684a12c560838718ae2 Reviewed-on: https://go-review.googlesource.com/c/proposal/+/348382 Reviewed-by: Robert Griesemer <gri@golang.org>
No change in consensus, so accepted. 🎉 |
Thanks for the feedback, all! Closing, as the accepted proposal matches the current implementation at tip. |
Change https://golang.org/cl/353882 mentions this issue: |
Allows cgo to work with generics. Updates #47781. Change-Id: Id1a5d1a0a8193c5b157e3e671b1490d687d10384 Reviewed-on: https://go-review.googlesource.com/c/go/+/353882 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This proposal formally introduces the changes we’ve made to support parameterized functions and types in the
go/ast
andgo/token
packages. See the full write-up here:https://go.googlesource.com/proposal/+/master/design/47781-parameterized-go-ast.md
There will be a separate issue for
go/types
, where type parameters add a much larger API surface.We’ve gotten some experience with these new APIs over the last few months by using them in
go/types
. The additionalMultiIndexExpr
IndexListExpr
node type is the most significant change, but felt cleanest of the alternatives we considered.Any feedback is appreciated.
CC @griesemer
Changelog:
TParams
fields were renamed toTypeParams
MultiIndexExpr
was renamed toIndexListExpr
The text was updated successfully, but these errors were encountered: