Skip to content

Go: Only output origin constraints for methods - #22399

Merged
jketema merged 2 commits into
github:mainfrom
jketema:jketema/go-follow
Sep 2, 2026
Merged

Go: Only output origin constraints for methods#22399
jketema merged 2 commits into
github:mainfrom
jketema:jketema/go-follow

Conversation

@jketema

@jketemajketema commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Addresses #22042 (comment) by only outputting the origins of constraints on generic method and not instantiated constraints. This matches the behavior in other places where we have both instantiations and origins.

@jketema
jketemaforce-pushed the jketema/go-follow branch 4 times, most recently from bb92ed7 to 2178247CompareAugust 20, 2026 14:34
@jketema
jketema marked this pull request as ready for review August 20, 2026 15:21
@jketema
jketema requested review from a team as code ownersAugust 20, 2026 15:21
CopilotAI balanced review requested due to automatic review settings August 20, 2026 15:21

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ensures instantiated generic Go methods emit their origin type-parameter constraints.

Changes:

  • Tracks origin type parameters for instantiated methods.
  • Adds dependent-bound generic method coverage.
  • Updates expected query results.
Show a summary per file
FileDescription
go/extractor/extractor.goMaps instantiated method parameters to origin constraints.
genericMethods.goAdds dependent-bound test cases.
TypeParamType.expectedUpdates type-parameter results.
getTypeParameter.expectedUpdates declaration results.
getParameter.expectedUpdates parameter results.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 5/5 changed files
  • Comments generated: 2
  • Review effort level: Balanced


var typeParamParent map[*types.TypeParam]typeParamParentEntry = make(map[*types.TypeParam]typeParamParentEntry)

var typeParamOrigin map[*types.TypeParam]*types.TypeParam = make(map[*types.TypeParam]*types.TypeParam)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. That also applies to the pre-existing typeParamParent

@jketemajketemaAug 20, 2026

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I convinced myself that we wouldn't have synchronization issues in the old behaviour. Each thread works independently. Even if they refer to the same type they make their own classes to represent that type. And we always populate an entry in the map before we try to read it. I don't understand the new behaviour well enough to tell if that's still true. I guess you might want add another test file which references GenericMethodWithDependentBound to double check that that works.

@jketemajketemaAug 21, 2026

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe that was a sufficient condition even before the introduction of generic methods. My understanding is that concurrent writes and concurrent read-writes are simply not safe, even if the elements read/written are different.

Comment threadgo/extractor/extractor.go Outdated
@jketema
jketemaforce-pushed the jketema/go-follow branch 2 times, most recently from b58033f to 293f687CompareAugust 21, 2026 09:27
Also mutex protect the two global maps. Go `map`s are not are not thread
safe in the case of write/writes and read/writes.

@owen-mcowen-mc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to fix a real problem.

| genericMethods.go:7:6:7:45 | type declaration specifier | TypeSpec | 0 | genericMethods.go:7:30:7:35 | type parameter declaration | 0 | genericMethods.go:7:30:7:31 | P2 | genericMethods.go:7:33:7:35 | any | interface { } |
| genericMethods.go:9:1:9:67 | function declaration | MethodDecl | 0 | genericMethods.go:9:52:9:57 | type parameter declaration | 0 | genericMethods.go:9:52:9:53 | P4 | genericMethods.go:9:55:9:57 | any | interface { } |
| genericMethods.go:21:6:21:46 | type declaration specifier | TypeSpec | 0 | genericMethods.go:21:31:21:36 | type parameter declaration | 0 | genericMethods.go:21:31:21:32 | P5 | genericMethods.go:21:34:21:36 | any | interface { } |
| genericMethods.go:23:1:23:87 | function declaration | MethodDecl | 0 | genericMethods.go:23:70:23:77 | type parameter declaration | 0 | genericMethods.go:23:70:23:71 | P7 | genericMethods.go:23:73:23:77 | type set literal | interface { ~[]P6 } |

@owen-mcowen-mcSep 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that there should be another line here for P6 on line 23. But I believe this is an existing bug that we don't properly extract everything about type parameters defined on the receiver, so it shouldn't affect this PR. I can't remember - maybe we don't extract the object, or the declaration? I tried to fix it years ago but it wasn't easy. Maybe the new map you've introduced will make it easy, as it allows you link a type parameter to the place where it was declared.

@jketema
jketema merged commit 327b8e9 into github:mainSep 2, 2026
13 checks passed
@jketema
jketema deleted the jketema/go-follow branch September 2, 2026 14:37
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@jketema@owen-mc