Skip to content

cmd/compile: 1.7 compiler does not compile program with large complex struct #18920

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

Closed
rdvorak opened this issue Feb 3, 2017 · 17 comments
Closed
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge
Milestone

Comments

@rdvorak
Copy link

rdvorak commented Feb 3, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.7.5 windows/amd64

What operating system and processor architecture are you using (go env)?

Windows Server, Intel

What did you do?

I want to compile a program with large complex struct.
Go 1.7.1, 1.7.5 does not compile the program but the version 1.6.4 does and
it works (Un/Marshalling) perfectly with 1.6.
I have created repo with single main.go file just for this bug report.
https://github.com/rdvorak/largeGoStruct/blob/master/main.go
I had to hash identifiers in the struct because the real structure should not be published.

What did you expect to see?

I want the main.go get compiled.

What did you see instead?

.\main.go:1: internal compiler error: name too long: *struct
.. follows the large struct ...
goroutine 1 [running]:
runtime/debug.Stack(0x0, 0x0, 0x0)
c:/go/src/runtime/debug/stack.go:24 +0x80
cmd/compile/internal/gc.Fatalf(0x911ba1, 0x11, 0xc044fecd20, 0x1, 0x1)
c:/go/src/cmd/compile/internal/gc/subr.go:165 +0x24f
cmd/compile/internal/gc.dnameData(0xc043f2c120, 0x0, 0xc044860000, 0x29331, 0x0, 0x0, 0x0, 0x0, 0x0)
c:/go/src/cmd/compile/internal/gc/reflect.go:515 +0x444
cmd/compile/internal/gc.dname(0xc044860000, 0x29331, 0x0, 0x0, 0x0, 0xc044860000, 0x29331)
c:/go/src/cmd/compile/internal/gc/reflect.go:583 +0x1c8
cmd/compile/internal/gc.dcommontype(0xc042b54000, 0x28, 0xc0426e6a50, 0x9043ff)
c:/go/src/cmd/compile/internal/gc/reflect.go:911 +0x4cb
cmd/compile/internal/gc.dtypesym(0xc0426e6a50, 0xc0426e6a50)
c:/go/src/cmd/compile/internal/gc/reflect.go:1300 +0xef1
cmd/compile/internal/gc.dtypesym(0xc0427306e0, 0xc0426c10a0)
c:/go/src/cmd/compile/internal/gc/reflect.go:1284 +0xd3e
cmd/compile/internal/gc.dtypesym(0xc0426e69b0, 0xc042732380)
c:/go/src/cmd/compile/internal/gc/reflect.go:1296 +0xe98
cmd/compile/internal/gc.dumptypestructs()
c:/go/src/cmd/compile/internal/gc/reflect.go:1369 +0xd3
cmd/compile/internal/gc.dumpobj1(0xc0420440c0, 0x3a, 0x3)
c:/go/src/cmd/compile/internal/gc/obj.go:133 +0x566
cmd/compile/internal/gc.dumpobj()
c:/go/src/cmd/compile/internal/gc/obj.go:45 +0x59
cmd/compile/internal/gc.Main()
c:/go/src/cmd/compile/internal/gc/main.go:490 +0x1aa6
cmd/compile/internal/amd64.Main()
c:/go/src/cmd/compile/internal/amd64/galign.go:93 +0x301
main.main()
c:/go/src/cmd/compile/main.go:33 +0x2aa

@ianlancetaylor ianlancetaylor changed the title 1.7 compiler does not compile program with large complex struct cmd/compile: 1.7 compiler does not compile program with large complex struct Feb 3, 2017
@ianlancetaylor ianlancetaylor added this to the Go1.9 milestone Feb 3, 2017
@ianlancetaylor
Copy link
Member

CC @crawshaw

@crawshaw
Copy link
Member

crawshaw commented Feb 3, 2017

if len(name) > 1<<16-1 {
        Fatalf("name too long: %s", name)
}

That's a big name!

@LionNatsu
Copy link
Contributor

I think we should call it 'type name' in error message rather than call it 'name' which makes me feel that was a variable name…?

@odeke-em
Copy link
Member

I don't think this bug only applies to Go1.7, I can reproduce the message on >Go1.8 ie +3a6842a

$ go version
go version devel +3a6842a Thu Feb 9 04:13:35 2017 +0000 darwin/amd64

so I'll just do a minor retitling of the bug.

@odeke-em odeke-em changed the title cmd/compile: 1.7 compiler does not compile program with large complex struct cmd/compile: improve type name error message on failing to compile very large complex struct Feb 11, 2017
@pborges
Copy link

pborges commented Feb 27, 2017

Ouch... this bug just bit me bad, I am writing a package to generate some structs from a very complicated XSD, is there a work round other then attempting to simplify my structs so they are not so large?

And just to clarify, the problem is not the actual Name of my struct right? My name is only 25 characters

@rdvorak rdvorak changed the title cmd/compile: improve type name error message on failing to compile very large complex struct cmd/compile: 1.7 compiler does not compile program with large complex struct Feb 28, 2017
@rdvorak
Copy link
Author

rdvorak commented Feb 28, 2017

the workaround is to use 1.6 compiler or if you have large nested structs you can define them separately

@crawshaw
Copy link
Member

Yes this is a real bug that should be fixed at some point. But I would also ask you to consider the readability of your generated code. Go code should be designed for reading, even when made by a machine. Are enormous nested types readable? Would intermediate naming help? (I suspect that almost always, it would.)

@rdvorak
Copy link
Author

rdvorak commented Feb 28, 2017

In my case the structure is a container for one record of related data and the schema, complexity is not my decision, as it is defined by external data provider- it is real world example.

@pborges
Copy link

pborges commented Feb 28, 2017

@crawshaw You are probably right however the code I've generated looks pretty good, it has a bunch of nested structs however they are all only a few fields each, I can probably break them up into structs, I just need to come up with some naming scheme to avoid duplicate struct names :( Is there any information as to why this became a problem in 1.7+ (just curious)

@ianlancetaylor
Copy link
Member

The problem appeared in 1.7 because the type descriptors generated by the compiler were changed to make them smaller (for issue #6853). One of the changes was to store the length of the result of reflect.Type.String in two bytes rather than eight, leading to this error. To fix this we'll need some sort of escape mechanism for longer strings.

@pborges
Copy link

pborges commented Feb 28, 2017

@ianlancetaylor Thank you for the information

@josharian
Copy link
Contributor

@crawshaw any plans to work on this for 1.9?

@apoggi-carecloud
Copy link

Is this issue being worked on for 1.13?

@randall77
Copy link
Contributor

I don't think anyone has anything for 1.13 here.

@mbrancato
Copy link

I hit this in 1.15.5. The compiler can't handle very long structs (~2000 lines). However, go fmt and other tools like my IDE handle it fine. Go playground returned a 500 error when I tried to get share URL of a breaking example.

@davecheney
Copy link
Contributor

@mbrancato this is a rather old issue referring to an ancient version of the compiler, I think it would be better to open a new issue, complete the template and include a code sample that someone else can use to reproduce the problem.

If there are duplicates we (waves generally in the direction of the issue gardening folks) will gladly take care of that.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
@seankhliao
Copy link
Member

Not an issue for current versions (1.18/1.19)

@golang golang locked and limited conversation to collaborators Jan 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge
Projects
None yet
Development

No branches or pull requests