-
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/types: add Object.Origin [freeze exception] #51682
Comments
Does it make sense to have |
We'd need it for |
Do we want more experience with the existing alternatives available before making a decision? |
It's fine to wait if we think we'll get more signal, but I do think we should add something for 1.19. This feels like a philosophical oversight: the canonical nature of Objects was broken without an API to easily 'canonicalize'. |
This proposal has been added to the active column of the proposals project |
I think it would be fine to simply add Origin to the objects that could possibly be instantiated: |
Based on the discussion above, this proposal seems like a likely accept. |
@findleyr The more conservative approach seems fine. Can you please send out a CL soon so we can see the implications in detail? |
Change https://go.dev/cl/395535 mentions this issue: |
https://go.dev/cl/395535 contains a prototype of the new API, which is added only to A notably questionable decision: I opted to have the new methods return |
I'm leaning towards returning |
Moving back to active to resolve the discussion about the result type. |
Discussed this with @griesemer, and it seems like the arguments for concrete result types are compelling:
On the other hand, we wouldn't be able to pass around By way of analogy, we document that |
@findleyr, thanks for updating the top comment with the proposed API. Does anyone object to this change? |
Based on the discussion above, this proposal seems like a likely accept. |
CC @adonovan :) |
No change in consensus, so accepted. 🎉 |
CC @golang/release This issue was filed early in the dev cycle, but due to ongoing discussion and the abbreviated cycle, was not accepted until a few days before the freeze. With other priorities in go/types (particularly the urgent https://go.dev/issue/52715), I didn't get to the implementation of this feature before the freeze. I'd like to request a freeze exception to land this proposal for 1.19, as it allows us to redefine a 'canonical' invariant that was broken with generics. Certain types of static analysis (such as dominikh/go-tools#1215 or some Google-internal analyses) would be facilitated by these new APIs. Please let me know if you'd like me to file a new issue for the freeze exception request, or if you need any other information to help make a determination. |
This freeze exemption has been approved. Nothing else is required for the exemption request. |
Thanks all! |
I propose to add the following methods to
types.Var
andtypes.Func
:While instantiating types, we necessarily have to create instantiated copies of their methods/fields/parameters/etc. However, as we work on updating tools for generics, an emerging theme is that is useful to be able to answer the following two questions:
Right now, these are not easy questions to answer. For methods, these can be answered by a lookup on the receiver base origin type. For fields / parameters / etc., it is more difficult and may require finding the relevant
*ast.Ident
and looking inInfo.Defs
.Adding an
Origin
method to these types answers both of these questions trivially, at the cost of a pointer per object. If the added memory is a concern, there are several internal fields ontypes.object
used during type-checking that may be externalized to free memory.CC @griesemer @dominikh @timothy-king @mdempsky
The text was updated successfully, but these errors were encountered: