golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.16k stars 17.56k forks source link

x/tools/go/ssa/builder.go: panic("nil underlyin") while executing *ssa.Program.Build() #68195

Closed guox33 closed 3 months ago

guox33 commented 3 months ago

Go version

go version go1.20.5 darwin/amd64

Output of go env in your module/workspace:

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/bytedance/Library/Caches/go-build"
GOENV="/Users/bytedance/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/bytedance/go/pkg/mod"
GONOPROXY="*.byted.org,*.everphoto.cn,git.smartisan.com"
GONOSUMDB="*.byted.org,*.everphoto.cn,git.smartisan.com"
GOOS="darwin"
GOPATH="/Users/bytedance/go"
GOPRIVATE="*.byted.org,*.everphoto.cn,git.smartisan.com"
GOPROXY="https://go-mod-proxy.byted.org|https://goproxy.cn|https://proxy.golang.org|direct"
GOROOT="/usr/local/opt/go/libexec"
GOSUMDB="sum.golang.google.cn"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.20.5"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="cc"
CXX="c++"
CGO_ENABLED="1"
GOMOD="/Users/bytedance/go/src/code.byted.org/test_infra/mocka/go.mod"
GOWORK="/Users/bytedance/go/src/code.byted.org/test_infra/mocka/go.work"
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/7j/9grcncv57rl_x3zgwzy1djsw0000gp/T/go-build510662253=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

here is my code `

cfg := &packages.Config{
    Mode: packages.NeedSyntax | packages.NeedTypesInfo |
        packages.NeedTypesSizes | packages.NeedTypes | packages.NeedImports |
        packages.NeedName | packages.NeedFiles | packages.NeedCompiledGoFiles,
    Dir: path.Dir(fp),
}
ps, err := packages.Load(cfg, "")
if err != nil {
    return
}
if en := packages.PrintErrors(ps); en > 0 {
    for _, tp := range ps {
        for _, e := range tp.Errors {
            err = e
            break
        }
        if err != nil {
            break
        }
    }
    return
}
prog, sps := ssautil.AllPackages(ps, ssa.InstantiateGenerics)
p.ssaFs = prog.Fset
if conf.needAst {
    for _, sp := range sps {
        sp.SetDebugMode(true)
    }
}
prog.Build()`

I load the packages of my project and about to build an ssa program for further analyzing

What did you see happen?

it panics when executing prog.Build(), the panic msg is "nil underlying", and below is the stack panic: nil underlying

goroutine 10022 [running]: go/types.(*Named).under(0xc0077472d0) /usr/local/opt/go/libexec/src/go/types/named.go:494 +0x6e5 go/types.under({0x101742568, 0xc0077472d0}) /usr/local/opt/go/libexec/src/go/types/type.go:23 +0x8c go/types.computeInterfaceTypeSet(0x0, 0x0, 0xc007701220) /usr/local/opt/go/libexec/src/go/types/typeset.go:273 +0x7f3 go/types.(*Interface).typeSet(0xc007701220) /usr/local/opt/go/libexec/src/go/types/interface.go:29 +0x3d go/types.(*Interface).Complete(0xc007701220) /usr/local/opt/go/libexec/src/go/types/interface.go:143 +0x4c golang.org/x/tools/go/ssa.(*subster).interface_(0xc0072878f0, 0xc000b4c2d0) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:304 +0x5ec golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742518, 0xc000b4c2d0}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:138 +0x1012 golang.org/x/tools/go/ssa.(*subster).named(0xc0072878f0, 0xc000349a40) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:344 +0x2c5 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742568, 0xc000349a40}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:141 +0x10c5 golang.org/x/tools/go/ssa.(*subster).var_(0xc0072878f0, 0xc000b74f00) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:213 +0x92 golang.org/x/tools/go/ssa.(*subster).varlist(0xc0072878f0, {0x101742658, 0xc0001a7de8}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:197 +0xcf golang.org/x/tools/go/ssa.(*subster).tuple(0xc0072878f0, 0xc0001a7de8) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:159 +0x4b golang.org/x/tools/go/ssa.(*subster).signature(0xc0072878f0, 0xc007762140) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:399 +0x105 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x1017425b8, 0xc007762140}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:132 +0xea8 golang.org/x/tools/go/ssa.(*subster).interface_(0xc0072878f0, 0xc000b4c7d0) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:268 +0x18e golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742518, 0xc000b4c7d0}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:138 +0x1012 golang.org/x/tools/go/ssa.(*subster).named(0xc0072878f0, 0xc000349960) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:344 +0x2c5 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742568, 0xc000349960}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:141 +0x10c5 golang.org/x/tools/go/ssa.(*subster).var_(0xc0072878f0, 0xc000b7f860) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:213 +0x92 golang.org/x/tools/go/ssa.(*subster).varlist(0xc0072878f0, {0x101742658, 0xc000410b28}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:197 +0xcf golang.org/x/tools/go/ssa.(*subster).tuple(0xc0072878f0, 0xc000410b28) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:159 +0x4b golang.org/x/tools/go/ssa.(*subster).signature(0xc0072878f0, 0xc007762000) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:398 +0xd2 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x1017425b8, 0xc007762000}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:132 +0xea8 golang.org/x/tools/go/ssa.(*subster).interface_(0xc0072878f0, 0xc000b4cbe0) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:268 +0x18e golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742518, 0xc000b4cbe0}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:138 +0x1012 golang.org/x/tools/go/ssa.(*subster).named(0xc0072878f0, 0xc0003498f0) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:344 +0x2c5 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742568, 0xc0003498f0}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:141 +0x10c5 golang.org/x/tools/go/ssa.(*subster).var_(0xc0072878f0, 0xc000a98240) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:213 +0x92 golang.org/x/tools/go/ssa.(*subster).varlist(0xc0072878f0, {0x101742658, 0xc000411740}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:197 +0xcf golang.org/x/tools/go/ssa.(*subster).tuple(0xc0072878f0, 0xc000411740) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:159 +0x4b golang.org/x/tools/go/ssa.(*subster).signature(0xc0072878f0, 0xc007741fc0) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:399 +0x105 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x1017425b8, 0xc007741fc0}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:132 +0xea8 golang.org/x/tools/go/ssa.(*subster).interface_(0xc0072878f0, 0xc000b4cc80) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:268 +0x18e golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742518, 0xc000b4cc80}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:138 +0x1012 golang.org/x/tools/go/ssa.(*subster).named(0xc0072878f0, 0xc000349880) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:344 +0x2c5 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742568, 0xc000349880}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:141 +0x10c5 golang.org/x/tools/go/ssa.(*subster).var_(0xc0072878f0, 0xc000a98420) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:213 +0x92 golang.org/x/tools/go/ssa.(*subster).varlist(0xc0072878f0, {0x101742658, 0xc000411788}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:197 +0xcf golang.org/x/tools/go/ssa.(*subster).tuple(0xc0072878f0, 0xc000411788) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:159 +0x4b golang.org/x/tools/go/ssa.(*subster).signature(0xc0072878f0, 0xc007741f80) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:399 +0x105 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x1017425b8, 0xc007741f80}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:132 +0xea8 golang.org/x/tools/go/ssa.(*subster).interface_(0xc0072878f0, 0xc000b4da40) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:268 +0x18e golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742518, 0xc000b4da40}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:138 +0x1012 golang.org/x/tools/go/ssa.(*subster).named(0xc0072878f0, 0xc0003497a0) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:344 +0x2c5 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742568, 0xc0003497a0}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:141 +0x10c5 golang.org/x/tools/go/ssa.(*subster).interface_(0xc0072878f0, 0xc000b4dbd0) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:286 +0x414 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742518, 0xc000b4dbd0}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:138 +0x1012 golang.org/x/tools/go/ssa.(*subster).named(0xc0072878f0, 0xc000349730) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:344 +0x2c5 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742568, 0xc000349730}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:141 +0x10c5 golang.org/x/tools/go/ssa.(*subster).var_(0xc0072878f0, 0xc000cdc6c0) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:213 +0x92 golang.org/x/tools/go/ssa.(*subster).varlist(0xc0072878f0, {0x101742658, 0xc0006ae948}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:197 +0xcf golang.org/x/tools/go/ssa.(*subster).tuple(0xc0072878f0, 0xc0006ae948) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:159 +0x4b golang.org/x/tools/go/ssa.(*subster).signature(0xc0072878f0, 0xc007741d00) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:399 +0x105 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x1017425b8, 0xc007741d00}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:132 +0xea8 golang.org/x/tools/go/ssa.(*subster).interface_(0xc0072878f0, 0xc000b4dc70) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:268 +0x18e golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742518, 0xc000b4dc70}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:138 +0x1012 golang.org/x/tools/go/ssa.(*subster).named(0xc0072878f0, 0xc0003496c0) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:344 +0x2c5 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742568, 0xc0003496c0}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:141 +0x10c5 golang.org/x/tools/go/ssa.(*subster).var_(0xc0072878f0, 0xc000cdcf00) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:213 +0x92 golang.org/x/tools/go/ssa.(*subster).varlist(0xc0072878f0, {0x101742658, 0xc0006aea08}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:197 +0xcf golang.org/x/tools/go/ssa.(*subster).tuple(0xc0072878f0, 0xc0006aea08) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:159 +0x4b golang.org/x/tools/go/ssa.(*subster).signature(0xc0072878f0, 0xc007741cc0) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:399 +0x105 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x1017425b8, 0xc007741cc0}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:132 +0xea8 golang.org/x/tools/go/ssa.(*subster).interface_(0xc0072878f0, 0xc000b4de00) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:268 +0x18e golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742518, 0xc000b4de00}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:138 +0x1012 golang.org/x/tools/go/ssa.(*subster).named(0xc0072878f0, 0xc000349260) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:344 +0x2c5 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742568, 0xc000349260}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:141 +0x10c5 golang.org/x/tools/go/ssa.(*subster).var_(0xc0072878f0, 0xc000cdd920) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:213 +0x92 golang.org/x/tools/go/ssa.(*subster).varlist(0xc0072878f0, {0x101742658, 0xc0006aeab0}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:197 +0xcf golang.org/x/tools/go/ssa.(*subster).tuple(0xc0072878f0, 0xc0006aeab0) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:159 +0x4b golang.org/x/tools/go/ssa.(*subster).signature(0xc0072878f0, 0xc007741680) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:399 +0x105 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x1017425b8, 0xc007741680}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:132 +0xea8 golang.org/x/tools/go/ssa.(*subster).interface_(0xc0072878f0, 0xc000b4dea0) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:268 +0x18e golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742518, 0xc000b4dea0}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:138 +0x1012 golang.org/x/tools/go/ssa.(*subster).named(0xc0072878f0, 0xc000349110) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:344 +0x2c5 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742568, 0xc000349110}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:141 +0x10c5 golang.org/x/tools/go/ssa.(*subster).var_(0xc0072878f0, 0xc000cddf20) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:213 +0x92 golang.org/x/tools/go/ssa.(*subster).varlist(0xc0072878f0, {0x101742658, 0xc0006aeb58}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:197 +0xcf golang.org/x/tools/go/ssa.(*subster).tuple(0xc0072878f0, 0xc0006aeb58) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:159 +0x4b golang.org/x/tools/go/ssa.(*subster).signature(0xc0072878f0, 0xc007741640) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:399 +0x105 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x1017425b8, 0xc007741640}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:132 +0xea8 golang.org/x/tools/go/ssa.(*subster).interface_(0xc0072878f0, 0xc000cee320) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:268 +0x18e golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742518, 0xc000cee320}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:138 +0x1012 golang.org/x/tools/go/ssa.(*subster).named(0xc0072878f0, 0xc0003490a0) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:344 +0x2c5 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742568, 0xc0003490a0}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:141 +0x10c5 golang.org/x/tools/go/ssa.(*subster).var_(0xc0072878f0, 0xc000d05320) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:213 +0x92 golang.org/x/tools/go/ssa.(*subster).varlist(0xc0072878f0, {0x1017433a0, 0xc0000c4750}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:197 +0xcf golang.org/x/tools/go/ssa.(*subster).struct_(0xc0072878f0, 0xc0000c4750) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:181 +0x79 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742608, 0xc0000c4750}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:115 +0x9eb golang.org/x/tools/go/ssa.(*subster).named(0xc0072878f0, 0xc000349030) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:344 +0x2c5 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742568, 0xc000349030}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:141 +0x10c5 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742590, 0xc000f5c750}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:106 +0x7c5 golang.org/x/tools/go/ssa.(*subster).var_(0xc0072878f0, 0xc000f98a20) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:213 +0x92 golang.org/x/tools/go/ssa.(*subster).varlist(0xc0072878f0, {0x1017433a0, 0xc0000c4840}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:197 +0xcf golang.org/x/tools/go/ssa.(*subster).struct_(0xc0072878f0, 0xc0000c4840) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:181 +0x79 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742608, 0xc0000c4840}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:115 +0x9eb golang.org/x/tools/go/ssa.(*subster).named(0xc0072878f0, 0xc000348e70) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:344 +0x2c5 golang.org/x/tools/go/ssa.(*subster).typ(0xc0072878f0, {0x101742568, 0xc000348e70}) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:141 +0x10c5 golang.org/x/tools/go/ssa.(*subster).var_(0xc0072878f0, 0xc000f98a80) /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/subst.go:213 +0x92 created by golang.org/x/tools/go/ssa.(*Program).Build /Users/bytedance/go/pkg/mod/golang.org/x/tools@v0.11.0/go/ssa/builder.go:2439 +0x1c5

What did you expect to see?

the code runs successfully

gabyhelp commented 3 months ago

Similar Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

guox33 commented 3 months ago

the loaded package is "google.golang.org/protobuf/reflect/protoreflect" it starts with struct EnumValueDescriptor

timothy-king commented 3 months ago

The version of x/tools v0.11.0 (from the stack trace) is fairly out of date so you may want to try updating to see if this fixes the issue already.

I am not yet able to reproduce this with go1.20.5 (from the go env) with golang.org/x/tools v0.11.0 and google.golang.org/protobuf v1.34.2. What version of google.golang.org/protobuf/reflect/protoreflect are you analyzing?

Here is what I am doing to try to reproduce this:

# mkdir and cd into it
% cat go.mod 
module example.com/x

go 1.20

require (
        golang.org/x/tools v0.11.0
        google.golang.org/protobuf v1.34.2
)

require (
        golang.org/x/mod v0.12.0 // indirect
        golang.org/x/sys v0.10.0 // indirect
)
% cat m.go
package main

import (
        "log"

        "golang.org/x/tools/go/packages"
        "golang.org/x/tools/go/ssa"
        "golang.org/x/tools/go/ssa/ssautil"

        _ "google.golang.org/protobuf/reflect/protoreflect"
)

func main() {
        fp := "."
        cfg := &packages.Config{
                Mode: packages.NeedSyntax | packages.NeedTypesInfo |
                        packages.NeedTypesSizes | packages.NeedTypes | packages.NeedImports |
                        packages.NeedName | packages.NeedFiles | packages.NeedCompiledGoFiles,
                Dir: fp,
        }
        ps, err := packages.Load(cfg, "google.golang.org/protobuf/reflect/protoreflect")
        if err != nil {
                log.Fatal(err)
                return
        }
        if en := packages.PrintErrors(ps); en > 0 {
                for _, tp := range ps {
                        for _, e := range tp.Errors {
                                err = e
                                break
                        }
                        if err != nil {
                                log.Fatal(err)
                                break
                        }
                }
                return
        }
        prog, sps := ssautil.AllPackages(ps, ssa.InstantiateGenerics)
        // p.ssaFs = prog.Fset
        needAst := true /*conf.needAst*/
        if needAst {
                for _, sp := range sps {
                        sp.SetDebugMode(true)
                }
        }
        prog.Build()

        for _, pkg := range sps {
                for k, m := range pkg.Members {
                        log.Println(pkg.String(), k, ":", m.String())
                }
        }
}
% go1.20.5 build
% ./x # Prints many many members so it is loading and building.

Can you give more details for how to reproduce the crash?

guox33 commented 3 months ago

The version of x/tools v0.11.0 (from the stack trace) is fairly out of date so you may want to try updating to see if this fixes the issue already.

I am not yet able to reproduce this with go1.20.5 (from the go env) with golang.org/x/tools v0.11.0 and google.golang.org/protobuf v1.34.2. What version of google.golang.org/protobuf/reflect/protoreflect are you analyzing?

Here is what I am doing to try to reproduce this:

# mkdir and cd into it
% cat go.mod 
module example.com/x

go 1.20

require (
        golang.org/x/tools v0.11.0
        google.golang.org/protobuf v1.34.2
)

require (
        golang.org/x/mod v0.12.0 // indirect
        golang.org/x/sys v0.10.0 // indirect
)
% cat m.go
package main

import (
        "log"

        "golang.org/x/tools/go/packages"
        "golang.org/x/tools/go/ssa"
        "golang.org/x/tools/go/ssa/ssautil"

        _ "google.golang.org/protobuf/reflect/protoreflect"
)

func main() {
        fp := "."
        cfg := &packages.Config{
                Mode: packages.NeedSyntax | packages.NeedTypesInfo |
                        packages.NeedTypesSizes | packages.NeedTypes | packages.NeedImports |
                        packages.NeedName | packages.NeedFiles | packages.NeedCompiledGoFiles,
                Dir: fp,
        }
        ps, err := packages.Load(cfg, "google.golang.org/protobuf/reflect/protoreflect")
        if err != nil {
                log.Fatal(err)
                return
        }
        if en := packages.PrintErrors(ps); en > 0 {
                for _, tp := range ps {
                        for _, e := range tp.Errors {
                                err = e
                                break
                        }
                        if err != nil {
                                log.Fatal(err)
                                break
                        }
                }
                return
        }
        prog, sps := ssautil.AllPackages(ps, ssa.InstantiateGenerics)
        // p.ssaFs = prog.Fset
        needAst := true /*conf.needAst*/
        if needAst {
                for _, sp := range sps {
                        sp.SetDebugMode(true)
                }
        }
        prog.Build()

        for _, pkg := range sps {
                for k, m := range pkg.Members {
                        log.Println(pkg.String(), k, ":", m.String())
                }
        }
}
% go1.20.5 build
% ./x # Prints many many members so it is loading and building.

Can you give more details for how to reproduce the crash?

thanks for replying. the problem was solved after I updated x/tools to version v0.22.0 I can't neither reproduce this problem with your code, sorry that I can't provide you with the loaded repo, it's a company property. thanks again.

guox33 commented 3 months ago

solved by updating x/gools to the latest version