You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cmd/compile: internal compiler error: Value live at entry. It shouldn't be. #44355
# github.com/tonyghita/repro_test [github.com/tonyghita/repro.test]
./repro_test.go:10:13: internal compiler error: 'TestF.func1': Value live at entry. It shouldn't be. func TestF.func1, node ~R0, value v19
changed the title [-]internal compiler error: Value live at entry. It shouldn't be.[/-][+]cmd/compile: internal compiler error: Value live at entry. It shouldn't be.[/+]on Feb 18, 2021
The issue is due to inlining an imported function with a blank result parameter and only one return statement, which also doesn't have any result arguments.
@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 return statement to explicitly return zero values, or just add a second (unreachable) return statement. Either of these would suppress the optimization that's crashing here.
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.)
@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 reflect package. For example, given the API schema:
we would have equivalent structs type Query struct and type User struct in Go.
typeQuerystruct {
// hidden fields
}
func (q*Query) User(ctx context.Context, argsstruct{ IDstring }) *User {
returnq.load.UserByID(ctx, args.ID) // pretend this function loads a user by their ID.
}
typeUserstruct {
// hidden fields
}
func (u*User) Name() *string {
returnu.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).
The implementation is removed but the schema/interface can still be satisfied when we reflect type User's method set.
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...
although maybe the issue remains since reflect could still call one of these functions.
@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.
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.
Activity
[-]internal compiler error: Value live at entry. It shouldn't be.[/-][+]cmd/compile: internal compiler error: Value live at entry. It shouldn't be.[/+]ianlancetaylor commentedon Feb 18, 2021
CC @mdempsky @dr2chase
If this is a real bug it probably needs a backport to the 1.16 branch.
tonyghita commentedon Feb 18, 2021
I forgot to describe the setup to reproduce the issue.
and then in the
repro_testpackage (or some other package)mdempsky commentedon Feb 18, 2021
Thanks for the minimized test case, @tonyghita . I'm able to reproduce the issue locally.
mdempsky commentedon Feb 18, 2021
The issue is due to inlining an imported function with a blank result parameter and only one
returnstatement, which also doesn't have any result arguments.mdempsky commentedon Feb 18, 2021
@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
returnstatement to explicitly return zero values, or just add a second (unreachable)returnstatement. Either of these would suppress the optimization that's crashing here.josharian commentedon Feb 18, 2021
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.)
gopherbot commentedon Feb 18, 2021
Change https://golang.org/cl/293293 mentions this issue:
cmd/compile: declare inlined result params early for empty returnsmdempsky commentedon Feb 18, 2021
@gopherbot please backport to Go 1.16
gopherbot commentedon Feb 18, 2021
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.
tonyghita commentedon Feb 18, 2021
@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
reflectpackage. For example, given the API schema:we would have equivalent structs
type Query structandtype User structin Go.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).
The implementation is removed but the schema/interface can still be satisfied when we
reflecttypeUser's method set.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...
although maybe the issue remains since reflect could still call one of these functions.
mdempsky commentedon Feb 18, 2021
@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.
toothrot commentedon Feb 19, 2021
There is another possibly related case that appeared at #44415
mdempsky commentedon Feb 19, 2021
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.
cagedmantis commentedon Feb 25, 2021
Please go ahead and submit.
cmd/compile: declare inlined result params early for empty returns