Skip to content

Commit 58fd1a2

Browse files
authored
Merge pull request #17357 from smowton/smowton/feature/go-indistinguishable-types
Go: extract and expose struct tags, interface method IDs
2 parents f3cbf86 + 837387a commit 58fd1a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+10167
-4545
lines changed

go/downgrades/4bd57e093275e5e892dfb16b55ed4bd76ea662be/go.dbscheme

Lines changed: 546 additions & 0 deletions
Large diffs are not rendered by default.

go/downgrades/4bd57e093275e5e892dfb16b55ed4bd76ea662be/old.dbscheme

Lines changed: 552 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
description: Remove component-tags and interface-method-id tables
2+
compatibility: full
3+
4+
struct_tags.rel: delete
5+
interface_private_method_ids.rel: delete

go/extractor/dbscheme/dbscheme.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ func AddDefaultSnippet(snippet string) bool {
410410

411411
// PrintDbScheme prints the schema of this database to the writer `w`
412412
func PrintDbScheme(w io.Writer) {
413-
fmt.Fprintf(w, "/** Auto-generated dbscheme; do not edit. */\n\n")
413+
fmt.Fprintf(w, "/** Auto-generated dbscheme; do not edit. Run `make gen` in directory `go/` to regenerate. */\n\n")
414414
for _, snippet := range defaultSnippets {
415415
fmt.Fprintf(w, "%s\n", snippet)
416416
}

go/extractor/dbscheme/tables.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,20 @@ var ComponentTypesTable = NewTable("component_types",
11501150
EntityColumn(TypeType, "tp"),
11511151
).KeySet("parent", "index")
11521152

1153+
// StructTagsTable is the table associating struct types with their component types' tags
1154+
var StructTagsTable = NewTable("struct_tags",
1155+
EntityColumn(StructType, "parent"),
1156+
IntColumn("index"),
1157+
StringColumn("tag"),
1158+
).KeySet("parent", "index")
1159+
1160+
// InterfacePrivateMethodIdsTable is the table associating interface types with the indices and ids of their private methods.
1161+
var InterfacePrivateMethodIdsTable = NewTable("interface_private_method_ids",
1162+
EntityColumn(InterfaceType, "interface"),
1163+
IntColumn("index"),
1164+
StringColumn("id"),
1165+
).KeySet("interface", "index")
1166+
11531167
// ArrayLengthTable is the table associating array types with their length (represented as a string
11541168
// since Go array lengths are 64-bit and hence do not always fit into a QL integer)
11551169
var ArrayLengthTable = NewTable("array_length",

go/extractor/extractor.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,9 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
16241624
name = ""
16251625
}
16261626
extractComponentType(tw, lbl, i, name, field.Type())
1627+
if tp.Tag(i) != "" {
1628+
dbscheme.StructTagsTable.Emit(tw, lbl, i, tp.Tag(i))
1629+
}
16271630
}
16281631
case *types.Pointer:
16291632
kind = dbscheme.PointerType.Index()
@@ -1641,6 +1644,10 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
16411644
extractMethod(tw, meth)
16421645

16431646
extractComponentType(tw, lbl, i, meth.Name(), meth.Type())
1647+
1648+
if !meth.Exported() {
1649+
dbscheme.InterfacePrivateMethodIdsTable.Emit(tw, lbl, i, meth.Id())
1650+
}
16441651
}
16451652
for i := 0; i < tp.NumEmbeddeds(); i++ {
16461653
component := tp.EmbeddedType(i)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added member predicates `StructTag.hasOwnFieldWithTag` and `Field.getTag`, which enable CodeQL queries to examine struct field tags.
5+
* Added member predicate `InterfaceType.hasPrivateMethodWithQualifiedName`, which enables CodeQL queries to distinguish interfaces with matching non-exported method names that are declared in different packages, and are therefore incompatible.

go/ql/lib/go.dbscheme

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** Auto-generated dbscheme; do not edit. */
1+
/** Auto-generated dbscheme; do not edit. Run `make gen` in directory `go/` to regenerate. */
22

33

44
/** Duplicate code **/
@@ -207,6 +207,12 @@ underlying_type(unique int named: @namedtype ref, int tp: @type ref);
207207
#keyset[parent, index]
208208
component_types(int parent: @compositetype ref, int index: int ref, string name: string ref, int tp: @type ref);
209209

210+
#keyset[parent, index]
211+
struct_tags(int parent: @structtype ref, int index: int ref, string tag: string ref);
212+
213+
#keyset[interface, index]
214+
interface_private_method_ids(int interface: @interfacetype ref, int index: int ref, string id: string ref);
215+
210216
array_length(unique int tp: @arraytype ref, string len: string ref);
211217

212218
type_objects(unique int tp: @type ref, int object: @object ref);

0 commit comments

Comments
 (0)