You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 3688434
Browse filesBrowse the repository at this point in the historyBrowse files
feat(scanner): load and type-check packages without a Go toolchain
packages.Load resolves a package graph by running `go list`. That binds a scan
to an installed toolchain and rules out any environment without one.
internal/packages does the same job in pure Go: patterns to directories,
build-constraint selection through go/build, parse, type-check. Both ways of
resolving a graph live behind one Loader and are chosen by a Strategy, so the
options mean the same thing under either and a caller swaps by asking, not by
rewriting. Across codescan's fixture corpus the two produce identical specs.
Experimental, and opt-in: ToolchainFreeLoader selects it, Options.FS implies it,
and saying nothing keeps the go/packages path exactly as it was.
New options:
- ToolchainFreeLoader — scan without the go command.
- GOOS/GOARCH/GOFLAGS/GOWORK/GOEXPERIMENT — the go environment that decides
what is built, stated rather than inherited so a scan is reproducible.
Honoured by both strategies; the go command reads them from the environment
and nowhere else, so a pinned value is pushed there.
- FS — read source through an io/fs, which is what lets a scan cover a tree
that was never written to disk.
- StubStdlib — synthesize the standard library instead of reading GOROOT.
Trades fidelity for reach: a synthesized type has no fields and no method
set. Every fabricated import raises scan.synthesized-import.
- ExportData — serve dependencies from pre-computed export data instead.
Resolution follows the go command rather than approximating it. `...` stops at
a module boundary and is a wildcard anywhere in a pattern; import paths come
from the module that contains the directory; go.work places a sibling module at
its working copy rather than at a stale cached one; vendoring is decided by
vendor/modules.txt as `go mod vendor` writes it; a bare pattern is an import
path. A malformed directory is reported on its package and the rest of the tree
still loads, as `go list -e` does.
Two differences are kept on purpose, both in the direction of documenting code
that compiles for its author: a tree with no module still scans, and another
module's internal packages are readable.
The pattern matcher itself is copied from the Go distribution under its own
licence rather than re-derived — the vendor rules are subtle enough that our
own version failed three of the cases upstream tests for. See NOTICE.
What the copy costs is drift, so hack/go-loader is the answer to both halves of
that: `sync` reports when an upstream declaration has moved, and `corpus`
replays the go command's own test trees through both strategies and records
each verdict in ledger.md, which is committed so a newer Go shows up as a diff.
It needs a golang/go checkout and does not run in CI.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
|`scan_context.go`|`ScanCtx` / `NewScanCtx` — loads Go packages via `golang.org/x/tools/go/packages`|
37
+
|`scan_context.go`|`ScanCtx` / `NewScanCtx`; `loadPackages` picks a loader from `Options.FS` (see `README.md#loader`) |
38
+
|`load_golist.go` / `load_wasm.go`| the `golang.org/x/tools/go/packages` (`go list`) loader; excluded from `wasm` builds, which have no process model |
|`declaration.go`|`EntityDecl` — wraps a type/value declaration with its enclosing file/package |
40
41
|`enum_value.go`|`enumBasicLitValue` — converts a `const Foo Kind = "bar"` RHS into its runtime value (enum discovery) |
41
42
|`provenance.go`|`Provenance` — ties a spec JSON pointer to the source position of the Go construct that produced it; emitted via `Options.OnProvenance` (cross-ref linker, source side) |
42
43
|`classify/`| Classification predicates usable from both scanner and builders (e.g. `IsAllowedExtension`) |
0 commit comments