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

go/types: guarantee sorting of named type methods #61298

Open
findleyr opened this issue Jul 11, 2023 · 3 comments
Open

go/types: guarantee sorting of named type methods #61298

findleyr opened this issue Jul 11, 2023 · 3 comments
Labels
NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@findleyr
Copy link
Contributor

Certain libraries such as x/tools/go/types/objectpath rely on a well-defined sorting of methods on Named types. To enforce this definition, the objectpath package sorts, but as seen in #58668 (comment) that can be quite expensive.

We can fix that particular issue outside of go/types, but it would be nice to commit to a fixed ordering of methods in the go/types API. IIRC the ordering is currently deterministic and in source order (as defined by the input file slice), but this is not documented. We should document and preserve this behavior, or pick a different stable sort.

CC @griesemer @adonovan

@findleyr findleyr added this to the Go1.22 milestone Jul 11, 2023
@adonovan
Copy link
Member

Strictly speaking, all that objectpath needs is that the type checker uses a deterministic ordering of Named.Methods, and that the export/import process preserves that. So either of source order and Id order would be fine, but we should at a minimum commit to determinism (in go/types) and order preservation (in gcexportdata).

@dominikh
Copy link
Member

Related: #44195

@cherrymui cherrymui added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Jul 11, 2023
@griesemer
Copy link
Contributor

Maybe we need both, a "fast" version that doesn't guarantee an ordering, and a "stable" version that guarantees an ordering.

Right now we have sorting, but I don't think we rely on it in the type checker (and maybe we could use a map internally).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

5 participants