Commit Graph

60 Commits

Author SHA1 Message Date
Owen Mansel-Chan
c781f98bdc (unrelated tidy up) resolveTypeAlias not needed
`types.Unalias` already does the same thing
2025-05-06 05:45:06 -04:00
Owen Mansel-Chan
09c44616a0 Rename "named type" to "defined type" 2025-02-13 15:22:33 +00:00
Owen Mansel-Chan
7c83b0e213 Move comment and clarify 2025-02-11 22:09:19 +00:00
Owen Mansel-Chan
b8cad66287 Update test results 2025-02-11 22:04:17 +00:00
Owen Mansel-Chan
29f6d48162 Retain previous check for alias types 2025-01-24 12:30:27 +00:00
Owen Mansel-Chan
57fad4a837 Allow type parameters on alias types 2025-01-24 09:40:58 +00:00
Owen Mansel-Chan
38ee2d418a Fix bug by extracting more pointer types 2024-11-08 13:57:36 +00:00
Owen Mansel-Chan
9381dda4a9 Use un-specialized field when extracting struct types 2024-10-11 11:30:02 +01:00
Owen Mansel-Chan
6bf6ed6f48 Add check for object for specialized named type 2024-10-11 11:30:00 +01:00
Owen Mansel-Chan
a810309160 Add check for specialized objects 2024-10-11 11:29:58 +01:00
Owen Mansel-Chan
45710e23c6 Always use generic method object 2024-10-11 11:29:57 +01:00
Owen Mansel-Chan
d013c8940d Revert "Go: extractor/objecttypes consistency generics" 2024-10-10 21:37:44 +01:00
Owen Mansel-Chan
513efe222d Add check for object for specialized named type 2024-10-10 13:59:51 +01:00
Owen Mansel-Chan
6f6b4a0bfe Add check for specialized objects 2024-10-10 13:59:49 +01:00
Owen Mansel-Chan
d295cac697 Always use generic method object 2024-10-10 13:59:47 +01:00
Chris Smowton
288e0ec565 component_tags -> struct_tags 2024-10-08 19:23:20 +01:00
Chris Smowton
7a7ff4a91e Apply review comments 2024-10-08 19:23:11 +01:00
Chris Smowton
dcbb66d366 Go: extract and expose struct tags, interface method IDs
This enables us to distinguish all database types in QL. Previously structs with the same field names and types but differing tags, and interface types with matching method names and at least one non-exported method but declared in differing packages, were impossible or only sometimes possible to distinguish in QL. With this change these types can be distinguished, as well as permitting queries to examine struct field tags, e.g. to read JSON field name associations.
2024-10-08 19:23:06 +01:00
Chris Smowton
d689db23d8 Warn on use of old option 2024-10-01 10:43:28 +01:00
Chris Smowton
c9d6c80913 Log when vendor dir extraction is active 2024-09-30 18:44:20 +01:00
Chris Smowton
684aedf6aa Golang vendor dir extraction: add extractor option 2024-09-30 18:24:49 +01:00
Owen Mansel-Chan
796db77104 Add comments noting methods from embedded interfaces are already included 2024-09-27 15:03:09 +01:00
Chris Smowton
bb44a2fc8c Populate pkgInfoMapping for test packages if relevant 2024-09-21 13:38:41 +01:00
Chris Smowton
bcb84a84e1 Only skip test packages at the file-extraction phase 2024-09-20 12:48:08 +01:00
Chris Smowton
f5ff822681 Convert extract-tests option to an official extractor option 2024-09-20 10:03:54 +01:00
Chris Smowton
c3dffc955b Apply review comments 2024-09-20 09:56:29 +01:00
Chris Smowton
76e6942594 Go: support extracting test code
This implements support for test extraction by two mechanisms:

* In autobuild mode, setting `CODEQL_EXTRACTOR_GO_EXTRACT_TESTS` to `true`.
* In manual build mode, tracing a `go test` command (`go test -c` is to be recommended for efficiency).

Go deals with test compilation by creating several extra packages on top of those expected from inspection of the source code (see docs of `packages.Load` for more detail): packages whose IDs include a suffix like `mydomain.com/mypackage [mydomain.com/mypackage.test]`, and packages containing generated test driver code like `mydomain.com/mypackage.test`. There are also additional packages like `mydomain.com/mypackage_tests` which are explicitly present in source code, but not compiled by a normal `go build`.

So far as I can tell, the purpose of the two variants of the package is to resolve dependency cycles (because the tests variant of the package can have more dependencies than the non-tests variant, and non-test code can compile against non-test package variants). Since the test package variants seems to be a superset of the non-tests variant, I employ the simple heuristic of ignoring the variant of each package with the shortest ID. I haven't seen a case where there are three or more variants of a package, so I expect this to always identify the tests variant as the preferred one. If several variants were extracted, and we were to attempt to match Golang's linkage strategy among the different variants, we would need to extend trap-file name and most top-level symbol trap IDs with the package variant they come from; I hope this won't prove necessary.

"Real" `_tests` packages, and wholly synthetic driver code packages, are extracted just like normal.
2024-09-20 09:56:28 +01:00
Dave Bartolomeo
485fc04029 Initial merge from main 2024-09-15 08:55:31 -04:00
Owen Mansel-Chan
84c41744c1 Include type parameter's index in its label 2024-09-10 16:52:44 +01:00
Michael B. Gale
1a9608a1f5 Go: Don't extract objects for type aliases 2024-09-05 21:12:42 +01:00
Michael B. Gale
97c3efccd1 Go: Factor out isAlias function 2024-09-05 21:12:42 +01:00
Michael B. Gale
c5b8163493 Go: Handle Alias types by extracting the underlying types 2024-09-05 21:12:41 +01:00
Chris Smowton
f1f6f9b580 Share vendor-dir extraction logic between extractor and configure-baseline script 2024-08-20 15:56:26 +01:00
Michael B. Gale
7ca57e114f Go: Add CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS env var
If set to `true`, this allows `vendor` directories to be extracted
2024-07-08 14:08:19 +01:00
Michael B. Gale
724d026238 Go: Move go list functions to toolchain package 2024-05-08 13:29:28 +01:00
Owen Mansel-Chan
5ec3934ac8 Merge branch 'main' into go/extractor/no-intermediate-string-values 2024-04-10 14:51:22 +01:00
Owen Mansel-Chan
b4829addf7 Add comments with link to online doc 2024-04-10 10:48:23 +01:00
Owen Mansel-Chan
32ea94e625 Merge pull request #16123 from owen-mc/go/misc-trivial-fixes
Go: miscellaneous trivial fixes
2024-04-04 21:09:15 +01:00
Owen Mansel-Chan
7fc5265168 Misc small tidy-ups mostly suggested by linter 2024-04-04 10:51:22 +01:00
Owen Mansel-Chan
68321dd9ec Use nil for optional argument to packages.Visit 2024-04-04 10:51:13 +01:00
Owen Mansel-Chan
d9fe39d5ae Extractor: add comment about tw.Package.TypesInfo.Defs 2024-04-04 10:37:31 +01:00
Owen Mansel-Chan
698debfa20 Extractor: explicitly deal with extracting x.(type) in type switches 2024-04-03 13:58:58 +01:00
Michael B. Gale
06134467e9 Go: Make CODEQL_EXTRACTOR_GO_FAST_PACKAGE_INFO true by default 2024-03-20 12:01:49 +00:00
Owen Mansel-Chan
da8cc13506 go extractor: avoid long string concatenations
When we see "a" + "b" + "c" + "d", do not add a
row to the constvalues table for the intermiediate
strings "ab" and "abc". We still have entries for
the string literals ("a", "b", "c", and "d") and
the whole string concatenation ("abcd").
2024-03-11 10:53:26 +00:00
Michael B. Gale
be521508c2 Go: Do not add dummy files to CompilationCompilingFilesTable 2024-02-13 14:21:07 +00:00
Michael B. Gale
5e08bf0dbf Go: Add missing call to extractFileInfo 2024-02-13 14:20:45 +00:00
Michael B. Gale
3b708993c7 Go: Add diagnostic for 1.21 toolchain error 2023-09-07 11:51:20 +01:00
Owen Mansel-Chan
a7469ce4f1 Use Origin() 2023-07-17 16:11:25 +01:00
Owen Mansel-Chan
a2a2e93cfd Fix printing when one obj is nil 2023-07-15 07:06:16 +01:00
Owen Mansel-Chan
cff09d28b8 Test if Origin() works (for Var and Func) 2023-07-14 13:52:50 +01:00