go101/golds

Panic with Go 1.20.3

Marakai opened this issue · 13 comments

First time user of golds and wanted to check it out, trying to find a way to create docs then publish them to a separate web server.

Sadly, just running the basics is not working when merely throwing it at our source tree:

$ go version                                                                                                                                                                                                                                                               go version go1.20.3 darwin/arm64
$ go install go101.org/golds@latest
go: downloading go101.org/golds v0.6.4
go: downloading golang.org/x/net v0.7.0
go: downloading golang.org/x/text v0.7.0
go: downloading golang.org/x/tools v0.6.0
go: downloading golang.org/x/mod v0.8.0
go: downloading golang.org/x/sys v0.5.0
$ golds ./...                                                                                                                                                                                                                                                              2 ↵
[Analyzing] Start analyzing ...
[Analyzing] Preparation done: 796.631166ms
[Analyzing] 2 files parsed: 222.25µs
[Analyzing] 4 files parsed: 302.292µs
[Analyzing] 8 files parsed: 583.084µs
[Analyzing] 16 files parsed: 1.30475ms
[Analyzing] 32 files parsed: 2.727459ms
[Analyzing] 64 files parsed: 3.980084ms
[Analyzing] 128 files parsed: 8.191792ms
[Analyzing] 256 files parsed: 19.165959ms
[Analyzing] 512 files parsed: 152.815792ms
[Analyzing] 1024 files parsed: 252.670084ms
[Analyzing] 2048 files parsed: 563.152209ms
[Analyzing] All 2400 files are parsed: 993.025042ms
[Analyzing] Collected 423 packages: 487.663375ms
[Analyzing] Collected 57 modules: 515.903417ms
[Analyzing] Sorted packages by dependency relations: 295.583µs
[Analyzing] Collected Source Files: 580µs
[Analyzing] Collected declarations: 36.28525ms
panic: unnamed interface should have collected direct selectors now. &code.TypeInfo{TT:(*types.Interface)(0x14021a4b810), Exprs:[]ast.Expr(nil), Underlying:(*code.TypeInfo)(0x14021b122c0), TypeName:(*code.TypeName)(nil), Instantiated:(*code.InstantiatedInfo)(nil), Implements:[]code.Implementation(nil), ImplementedBys:[]*code.TypeInfo(nil), Aliases:[]*code.TypeName(nil), Underlieds:[]*code.TypeName(nil), DirectSelectors:[]*code.Selector(nil), EmbeddingFields:0, AllMethods:[]*code.Selector(nil), AllFields:[]*code.Selector(nil), AllSelectors:map[string]*code.Selector(nil), AsTypesOf:[]code.ValueResource(nil), AsInputsOf:[]code.ValueResource(nil), AsOutputsOf:[]code.ValueResource(nil), attributes:0x20000000, index:0x8948, counter:0x8949}

goroutine 38 [running]:
go101.org/golds/code.(*CodeAnalyzer).collectSelectorsForInterfaceType(0x14014a61c18?, 0x14021b122c0, 0x0, 0x8949, 0x14014a61c20)
	/Users/myuser/go/pkg/mod/go101.org/golds@v0.6.4/code/code-analyse.go:1118 +0x7dc
go101.org/golds/code.(*CodeAnalyzer).collectSelectors(0x14000156000)
	/Users/myuser/go/pkg/mod/go101.org/golds@v0.6.4/code/code-analyse.go:937 +0xbc
go101.org/golds/code.(*CodeAnalyzer).AnalyzePackages(0x14000156000, 0x14014a61dd0)
	/Users/myuser/go/pkg/mod/go101.org/golds@v0.6.4/code/code-analyse.go:59 +0x1c8
go101.org/golds/internal/server.(*docServer).analyze(0x140041a2000, {0x140000b8010, 0x1, 0x1}, {{0x104c1a3d7, 0x6}, {0x14000028025, 0xb}, 0x0, 0x0, ...}, ...)
	/Users/myuser/go/pkg/mod/go101.org/golds@v0.6.4/internal/server/server.go:348 +0x43c
go101.org/golds/internal/server.Run.func1()
	/Users/myuser/go/pkg/mod/go101.org/golds@v0.6.4/internal/server/server.go:135 +0x9c
created by go101.org/golds/internal/server.Run
	/Users/myuser/go/pkg/mod/go101.org/golds@v0.6.4/internal/server/server.go:134 +0x5d8

Any suggestions to further investigate this?

$ golds toolchain

works, for comparison. The code being analysed is working, compiling, testable and running.

@Marakai
Thanks for trying Golds and making this report.

If your project is open sourced, then it would be very helpful for me to investigate this problem. But I guess it is not.

Is your project using custom generics?

I will try to improve the panic messages to locate which type causes this problem in several days.

No custom generics. Yet... (trying to hold back my team members :-P)

And indeed, the project is sadly not OSS, it's company internal.

@Marakai
I just pushed a new commit which will output more info in the panic message.
It might be helpful to locate which type causes the problem (but I'm not 100% sure).
It you would like to help me investigate the problem, you can install golds with this
commit by cloning this repo and run go install, or run
go install go101.org/golds@develop.

Thanks, I will give this a go (haha!)

With the preview I get

peInfo(nil), Aliases:[]*code.TypeName(nil), Underlieds:[]*code.TypeName(nil), DirectSelectors:[]*code.Selector(nil), EmbeddingFields:0, AllMethods:[]*code.Selector(nil), AllFields:[]*code.Selector(nil), AllSelectors:map[string]*code.Selector(nil), AsTypesOf:[]code.ValueResource(nil), AsInputsOf:[]code.ValueResource(nil), AsOutputsOf:[]code.ValueResource(nil), attributes:0x20000000, index:0x88a6, counter:0x88a7}.
More info:
  IsMethodSet(): true
  IsImplicit(): false
  NumEmbeddeds(): 0
  NumMethods(): 1
    Method(0): func (github.com/jellydator/ttlcache/v3.Loader[K, V]).Load(c *github.com/jellydator/ttlcache/v3.Cache[K, V], key K) *github.com/jellydator/ttlcache/v3.Item[K, V]

Verifying that I'm running the preview:

 golds -version                                                                                                                                                                                                                                                           
Golds v0.6.5-preview

@Marakai
Thanks for your help.

The problem is caused by a dependency of your project.
Luckily, this dependency module is open sourced.
Now I have created a minimum piece of code to reproduce this problem:

package main

func main() {}

// Loader is an interface that handles missing data loading.
type Loader[K1 comparable, V1 any] interface {
	Load(key K1)
}

type Cache[K2 comparable, V2 any] struct {
	options options[K2, V2]
}

type options[K3 comparable, V3 any] struct {
	loader  Loader[K3, V3]
}

Go custom generics indeed have brought much trouble for me to maintain this project.

I will try to fix this problem in the next release.

Hi, I encountered this problem as well today. If there is any pointer you might have on where I could look to begin or untangle a bug fix for this, I would appreciate it.

@Marakai
I just submitted a new commit. I have checked that it is okay to analyze the github.com/jellydator/ttlcache/v3 module.
But I'm not sure if there are some other cases I haven't aware of.

@krashanoff
Does this commit fix the problem you encountered?


If it is okay to analyze both of your projects. I will create a new release.

@go101 Outstanding work! Was able to analyze my project (also closed source company-internal, unfortunately) without a hitch.

Unrelated, but if there's any small bug I could pick up sometime to begin contributing to golds, I'd be more than happy to.

@krashanoff
I'm not aware of any such non-fixed small bugs now.

Certainly. there should be many bugs in this project.
But the user base of this tool is still very small, so most of them haven't been found yet. :)

that fixed it, many thanks!

Okay. I just created a new release: v0.6.5