-
Notifications
You must be signed in to change notification settings - Fork 18k
go/types: go vet fails with illegal cycle for github.com/yuin/gopher-lua #26124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Definitively a type-checker failure. The new cycle detection code is overly aggressive. |
Independent reproducer: $ cat x.go
package p
const preloadLimit LNumber = 128
type LNumber float64
func (LNumber) assertFunction() *LFunction
type LFunction struct {
GFunction LGFunction
}
type LGFunction func(*LState)
type LState struct {
reg *registry
}
type registry struct {
alloc *allocator
}
type allocator struct {
_ [int(preloadLimit)]int
} Running gotype in it yields:
This is awfully wrong. Will fix in the next few days. |
A trivial fix is to set
in go/types/decl.go:57. This will disable the new code and the bug disappears (but it will also undo some other fixes, and the test suite will need to disable some tests). |
Shorter (go/types says C -> T -> M -> C):
It seems to me that the "C -> T" link is spurious. For cycle detection it seems like a constant shouldn't care about its own type or initializer, so this should be cycle-free too:
But maybe I am missing some subtlety around constants. It's been a while. |
Also the cycle via the method (assertFunction) is odd. I think it shouldn't be very hard to fix, probably tomorrow. Thanks for the shorter reproducer. (I kept the longer one so I have a test case for the original problem.) |
@rsc I'm using elsewhere a slightly different algorithm that breaks this cycle after C->T. The difference is in that methods are typechecked separately, after non-methods. Snippet of actual code cs := &cstack{p: p}
for _, sf := range p.SourceFiles {
for _, d := range sf.TopLevelDecls {
if x, ok := d.(*MethodDecl); ok {
cs.reset().check(x, nil)
}
}
}
for _, sf := range p.SourceFiles {
for _, d := range sf.TopLevelDecls {
if _, ok := d.(*MethodDecl); !ok {
cs.reset().check(d, nil)
}
}
}
p.checkEnqueued(cs)
for _, sf := range p.SourceFiles {
for _, d := range sf.InitFunctions {
d.(*FuncDecl).checkBody(cs)
}
}
p.checkEnqueued(cs)
for _, sf := range p.SourceFiles {
for _, d := range sf.TopLevelDecls {
switch x := d.(type) {
case *FuncDecl:
x.checkBody(cs)
case *MethodDecl:
x.checkBody(cs)
}
}
}
p.checkEnqueued(cs)
I think that would not be correct. |
Change https://golang.org/cl/121755 mentions this issue: |
Change https://golang.org/cl/121757 mentions this issue: |
The CL https://go-review.googlesource.com/c/go/+/121757 fixes this issue. Running go/vet on the repo now produces:
all of which look correct to me. |
The existing algorithm assumed that the length of a cycle was simply the number of elements in the cycle slice starting at the start object. However, we use a special "indir" indirection object to indicate pointer and other indirections that break the inline placement of types in composite types. These indirection objects don't exist as true named type objects, so don't count them anymore. This removes an unnecessary cycle error in one of the existing tests (testdata/issues.src:100). Also: - added more tracing support (only active if tracing is enabled) - better documentation in parts - r/check.typ/check.typExpr/ in a few of places where we don't need to record a type indirection Found while investigating #26124. Change-Id: I45341743225d979a72af3fbecfa05012b32fab67 Reviewed-on: https://go-review.googlesource.com/121755 Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
Change https://golang.org/cl/139899 mentions this issue: |
This work-around is not needed anymore now that method signatures are type-checked separately from their receiver base types: no artificial cycles are introduced anymore and so there is no need to artificially cut them. Updates #26124. Change-Id: I9d50171f12dd8977116a5d3f63ac39a06b1cd492 Reviewed-on: https://go-review.googlesource.com/c/139899 Reviewed-by: Alan Donovan <adonovan@google.com>
To reproduce:
reports
The text was updated successfully, but these errors were encountered: