Skip to content
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

cmd/compile: internal compiler error: methods are too far away #16037

Closed
dsnet opened this issue Jun 10, 2016 · 4 comments
Closed

cmd/compile: internal compiler error: methods are too far away #16037

dsnet opened this issue Jun 10, 2016 · 4 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dsnet
Copy link
Member

dsnet commented Jun 10, 2016

Using go1.7beta1

Consider this generator code:

package main

import (
    "fmt"
    "html/template"
    "os"
)

var tmpl = template.Must(template.New("main").Parse(`
package main

type T struct {
{{range .Names}}
    {{.Name}} *string
{{end}}
}

{{range .Names}}
func (t *T) Get{{.Name}}() string {
    if t.{{.Name}} == nil {
        return ""
    }
    return *t.{{.Name}}
}
{{end}}

func main() {}
`))

func main() {
    const n = 5000

    type Name struct{ Name string }
    var t struct{ Names []Name }
    for i := 0; i < n; i++ {
        t.Names = append(t.Names, Name{Name: fmt.Sprintf("H%06X", i)})
    }
    tmpl.Execute(os.Stdout, t)
}

This program produces a giant struct with n fields, and n accessor methods to get at those fields and is similar to whats generated by large protobuf files.

Compiling the program produced by this generator crashes the compiler:

$ go run gen.go > main.go
$ go run main.go
# command-line-arguments
main.go:45011: internal compiler error: methods are too far away on T: 120008

goroutine 1 [running]:
runtime/debug.Stack(0x0, 0x0, 0x0)
    /go/src/runtime/debug/stack.go:24 +0x79
cmd/compile/internal/gc.Fatalf(0x4fffff, 0x22, 0xc420c6b340, 0x2, 0x2)
    /go/src/cmd/compile/internal/gc/subr.go:165 +0x248
cmd/compile/internal/gc.dextratype(0xc420e693b0, 0x54, 0xc420c40af0, 0x1d4c8, 0x50)
    /go/src/cmd/compile/internal/gc/reflect.go:613 +0x2db
cmd/compile/internal/gc.dtypesym(0xc420c40af0, 0xc420c40af0)
    /go/src/cmd/compile/internal/gc/reflect.go:1305 +0x103b
cmd/compile/internal/gc.dtypesym(0xc420c40c30, 0xc420c6ba20)
    /go/src/cmd/compile/internal/gc/reflect.go:1278 +0xd37
cmd/compile/internal/gc.dumptypestructs()
    /go/src/cmd/compile/internal/gc/reflect.go:1363 +0xcc
cmd/compile/internal/gc.dumpobj1(0x7fff5fbff451, 0x5b, 0x3)
    /go/src/cmd/compile/internal/gc/obj.go:133 +0x553
cmd/compile/internal/gc.dumpobj()
    /go/src/cmd/compile/internal/gc/obj.go:45 +0x52
cmd/compile/internal/gc.Main()
    /go/src/cmd/compile/internal/gc/main.go:488 +0x1a5d
cmd/compile/internal/amd64.Main()
    /go/src/cmd/compile/internal/amd64/galign.go:93 +0x2fa
main.main()
    /go/src/cmd/compile/main.go:33 +0x2a3

This did not fail with the Go1.6 compiler.

/cc @crawshaw @griesemer @ianlancetaylor @randall77

@dsnet dsnet added the NeedsFix The path to resolution is known, but the work has not been done. label Jun 10, 2016
@dsnet dsnet added this to the Go1.7 milestone Jun 10, 2016
@dsnet
Copy link
Member Author

dsnet commented Jun 10, 2016

The error was introduced in 7d46917

@ianlancetaylor
Copy link
Contributor

Hmmm, this does seem to be a problem. The overhaul of the reflection data structures assumed that all types are small. That appears not to be the case.

@crawshaw
Copy link
Member

Even when the offset CL series is complete in 1.8 the space needed for each struct field on amd64 will be 16-bytes, so several thousand fields will overflow a uint16. So it looks like the moff field of uncommonType needs to be 4-bytes. For alignment, mcount should probably be pushed up to 4-bytes.

I'll do this tomorrow when I'm back from vacation.

@gopherbot
Copy link

CL https://golang.org/cl/24070 mentions this issue.

@golang golang locked and limited conversation to collaborators Jun 14, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants