-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: expected struct { F uintptr; L *lua.Lua_State } value to have type struct { F uintptr; L *lua.Lua_State } #62498
Comments
Similar issue can happen when you are typedef-in the same struct from multiple places via headers. Does the problem persist when you move the code into a single file? In other words, you should have only one single definition for |
This problem is no longer present when I write function
|
So, yes, See https://pkg.go.dev/cmd/cgo#hdr-Go_references_to_C
There's a separate issue for having a nicer solution for this problem: #13467 |
Although, I don't think the compiler should ICE due to that. |
cc @golang/compiler |
I'll look into this tomorrow, but if you can simplify the test case to work with only standard C (or at least POSIX) types/includes that will simplify reproducing it for me. Thanks. |
This is the simplify code。 Hope this helps troubleshooting the issue. |
The problem seems to be a more agressive inlining of closures in go1.21 The closure generated for
can now be inlined, there's no generated Go type for It ends up making two closures with different capture vars: |
@raochq Thank you, I can reproduce the failure. |
Here's a standalone repro of the issue: https://go.dev/play/p/5eDYV-mzqg9 There's nothing wrong with this code, and it compiled in Go 1.20. So I think this is a regression that should be backported. @gopherbot Please backport to Go 1.21. This is a compilation failure of valid code that used to work in Go 1.20. |
Backport issue(s) opened: #62544 (for 1.20), #62545 (for 1.21). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases. |
Thanks, I concur. That's an issue: exported struct fields are supposed to always use ir.LocalPkg for their Sym. |
Oh wait, the field name is actually But Type.LinkString is rewriting this to just |
Change https://go.dev/cl/527135 mentions this issue: |
This is because the problem relates to closures capturing local variables with uppercase names. (There aren't closures in your code as written, but cgo introduces them as part of its rewriting.) I've uploaded a fix, and I hope to have it included in the next Go minor release. In the mean time, disabling inlining like you discovered should work. Alternatively, you could rename your variables to start with a lowercase letter. Sorry for the inconvenience. Thank you for the report and for preparing the standalone reproduction. |
Change https://go.dev/cl/534916 mentions this issue: |
…ield naming When creating the struct type to hold variables captured by a function literal, we currently reuse the captured variable names as fields. However, there's no particular reason to do this: these struct types aren't visible to users, and it adds extra complexity in making sure fields belong to the correct packages. Further, it turns out we were getting that subtly wrong. If two function literals from different packages capture variables with identical names starting with an uppercase letter (and in the same order and with corresponding identical types) end up in the same function (e.g., due to inlining), then we could end up creating closure struct types that are "different" (i.e., not types.Identical) yet end up with equal LinkString representations (which violates LinkString's contract). The easy fix is to just always use simple, exported, generated field names in the struct. This should allow further struct reuse across packages too, and shrink binary sizes slightly. For #62498. Fixes #62545. Change-Id: I9c973f5087bf228649a8f74f7dc1522d84a26b51 Reviewed-on: https://go-review.googlesource.com/c/go/+/527135 Auto-Submit: Matthew Dempsky <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]> Reviewed-by: Keith Randall <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> (cherry picked from commit e3ce312) Reviewed-on: https://go-review.googlesource.com/c/go/+/534916 Reviewed-by: Matthew Dempsky <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
This issue only occurs in go 1.21
It work well before go1.21;
It work well in go1.21 with '-gcflags "all=-l"';
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
go install battlesvr
What did you expect to see?
build success
What did you see instead?
code
The text was updated successfully, but these errors were encountered: