Skip to content

Go: Track whether a type parameter type was declared as part of a receiver#22178

Open
jketema wants to merge 5 commits into
github:mainfrom
jketema:jketema/go-recv
Open

Go: Track whether a type parameter type was declared as part of a receiver#22178
jketema wants to merge 5 commits into
github:mainfrom
jketema:jketema/go-recv

Conversation

@jketema

@jketema jketema commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

This is needed for Go 1.27, as generic methods will have type parameter types that are both defined in receivers and on the methods themselves. Tracking this as part of the keyset avoids the dataset check errors that would otherwise occur.

All the needed data is there already in Go 1.26, so target main and not the upgrade branch.

@github-actions github-actions Bot added the Go label Jul 13, 2026
@jketema jketema marked this pull request as ready for review July 13, 2026 10:45
@jketema jketema requested a review from a team as a code owner July 13, 2026 10:45
Copilot AI review requested due to automatic review settings July 13, 2026 10:45
@jketema jketema requested a review from a team as a code owner July 13, 2026 10:45
@jketema jketema mentioned this pull request Jul 13, 2026
@jketema jketema added the no-change-note-required This PR does not need a change note label Jul 13, 2026

Copilot AI 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

This PR updates the Go extractor + schema to track whether a typeparam row originated from receiver type parameters, avoiding keyset collisions expected with Go 1.27’s generic methods (receiver + method type parameters).

Changes:

  • Extend the typeparam relation keyset with a new boolean is_from_recv column and plumb it through extractor emission and the QL library API (TypeParamType.isFromReceiver()).
  • Update the Go extractor’s type-parameter parent tracking to record whether a type parameter came from the receiver vs the method/type declaration.
  • Add corresponding upgrade/downgrade steps and update the regression test output to include the new column.
Show a summary per file
File Description
go/ql/test/library-tests/semmle/go/Function/TypeParamType.ql Test query updated to select isFromReceiver() output.
go/ql/test/library-tests/semmle/go/Function/TypeParamType.expected Expected results updated to include receiver-origin boolean.
go/ql/lib/upgrades/b1341734d6870b105e5c9d168ce7dec25d7f72d0/upgrade.properties Adds upgrade step for typeparam relation.
go/ql/lib/upgrades/b1341734d6870b105e5c9d168ce7dec25d7f72d0/typeparam.ql Upgrade query populates new boolean column (defaulting to false).
go/ql/lib/upgrades/b1341734d6870b105e5c9d168ce7dec25d7f72d0/old.dbscheme Upgrade metadata: old schema snapshot for this upgrade step.
go/ql/lib/upgrades/b1341734d6870b105e5c9d168ce7dec25d7f72d0/go.dbscheme Upgrade metadata: new schema snapshot for this upgrade step.
go/ql/lib/semmle/go/Types.qll QL API updated to expose isFromReceiver() from the underlying relation.
go/ql/lib/go.dbscheme.stats Schema stats updated for the new column.
go/ql/lib/go.dbscheme typeparam relation updated with is_from_recv and extended keyset.
go/extractor/trap/trapwriter.go Adds boolean emission support for TRAP tuples.
go/extractor/extractor.go Tracks receiver-origin for type parameters; includes it in label + emitted typeparam rows.
go/extractor/dbscheme/tables.go Adds boolean column + keyset change to TypeParamTable.
go/extractor/dbscheme/dbscheme.go Adds BooleanColumn helper to define boolean columns.
go/downgrades/5ff5325d274ae4f86defa195577bc7c1370b72fa/upgrade.properties Adds downgrade step for typeparam relation.
go/downgrades/5ff5325d274ae4f86defa195577bc7c1370b72fa/typeparam.ql Downgrade query drops the new boolean column.
go/downgrades/5ff5325d274ae4f86defa195577bc7c1370b72fa/old.dbscheme Downgrade metadata: old schema snapshot for this downgrade step.
go/downgrades/5ff5325d274ae4f86defa195577bc7c1370b72fa/go.dbscheme Downgrade metadata: new schema snapshot for this downgrade step.

Review details

  • Files reviewed: 17/17 changed files
  • Comments generated: 2
  • Review effort level: Low

Comment thread go/extractor/extractor.go
Comment on lines +2024 to 2026
for tparam := range typeparams.TypeParams() {
setTypeParamParent(tparam, parent, isFromReceiver)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The VSCode Go extension begs to differ.

Comment thread go/ql/lib/semmle/go/Types.qll Outdated
Comment on lines +398 to +399
/** Holds if this type parameter type is declared as part of a receiver */
boolean isFromReceiver() { typeparam(this, _, _, _, _, result) }

@jketema jketema Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Update to predicate instead of boolean, which is what I intended to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Go no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants