Go: Track whether a type parameter type was declared as part of a receiver#22178
Open
jketema wants to merge 5 commits into
Open
Go: Track whether a type parameter type was declared as part of a receiver#22178jketema wants to merge 5 commits into
jketema wants to merge 5 commits into
Conversation
Contributor
There was a problem hiding this comment.
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
typeparamrelation keyset with a new booleanis_from_recvcolumn 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 on lines
+2024
to
2026
| for tparam := range typeparams.TypeParams() { | ||
| setTypeParamParent(tparam, parent, isFromReceiver) | ||
| } |
Contributor
Author
There was a problem hiding this comment.
The VSCode Go extension begs to differ.
Comment on lines
+398
to
+399
| /** Holds if this type parameter type is declared as part of a receiver */ | ||
| boolean isFromReceiver() { typeparam(this, _, _, _, _, result) } |
Contributor
Author
There was a problem hiding this comment.
Update to predicate instead of boolean, which is what I intended to do.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
mainand not the upgrade branch.