-
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: Value live at entry. It shouldn't be. #44355
Comments
I forgot to describe the setup to reproduce the issue. package repro
type A struct{}
func (*A) F() (_ *B) { return }
type B struct{} and then in the package repro_test
import (
"testing"
"github.com/tonyghita/repro"
)
func TestF(t *testing.T) {
var a *repro.A
if a.F() != nil {
t.Fail()
}
} |
Thanks for the minimized test case, @tonyghita . I'm able to reproduce the issue locally. |
The issue is due to inlining an imported function with a blank result parameter and only one |
@tonyghita Can I ask what the original function looks like and why it was written that way? It's definitely a compiler issue that it's mishandling this case that I expect to have a fix for shortly, but I'm surprised there's real world code that exhibits this behavior, so I'm curious. FWIW, if you're in need of a workaround until Go 1.16.1 is available, you can should be able to either change the bare |
Aside: From all my years working on the compiler, there is no internal compiler error I hate more. (Of course, that means I also love it in a way, because it is catching bugs.) |
Change https://golang.org/cl/293293 mentions this issue: |
@gopherbot please backport to Go 1.16 |
Backport issue(s) opened: #44358 (for 1.16). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases. |
@mdempsky the original function is not very different from the reproducer code. It's pretty silly/useless and can/will be removed. To give a bit more context, the codebase is an API where the fields of the API map to method sets via type Query {
user(id: ID): User
}
type User {
name: String
nickname: String
} we would have equivalent structs type Query struct {
// hidden fields
}
func (q *Query) User(ctx context.Context, args struct{ ID string }) *User {
return q.load.UserByID(ctx, args.ID) // pretend this function loads a user by their ID.
}
type User struct {
// hidden fields
}
func (u *User) Name() *string {
return u.name
}
// Deprecated: use Name instead.
func (*User) Nickname() (_ *string) { return } Sometimes, we want to remove the implementation of a field without breaking the API, so the method is reduced to the bare minimum implementation until it is safe to remove the field from the API without breaking clients.. Sometimes we really flub the design of an API and so we remove the implementation for many fields that return many different types, and it is convenient to avoid having to specify the zero value for each type (although maybe too clever). func (*User) Nickname() (_ *string) { return }
func (*User) CreatedAt() (_ int) { return }
func (*User) BestFriend() (_ *User) { return }
func (*User) LicensePlate() (_ string) { return } The implementation is removed but the schema/interface can still be satisfied when we This bug was triggered by one of these "gutted" methods getting called in a forgotten unit test. As a workaround, we might be able to remove the useless test... |
@tonyghita Thanks for the context. That seems reasonable. Glad to know it's nothing performance sensitive, so just turning off the new, failing optimization in that case should be fine. |
There is another possibly related case that appeared at #44415 |
Is https://go-review.googlesource.com/c/go/+/293293/ okay to submit now? I'm thinking since it's a 1.16 regression that needs to be backported, it makes sense to commit now and get the backport fix CL ready. |
Please go ahead and submit. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes. I've
git bisect
the error to commit f2c0c2bWhat operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I made a small reproducer repository to demonstrate the issue https://github.com/tonyghita/repro and run
go test
against it.What did you expect to see?
Test pass without issue, as in Go 1.15.
What did you see instead?
The text was updated successfully, but these errors were encountered: