-
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: nil pointer dereference in the 1.18 compiler when dealing with generic types #50423
Comments
A reproducer (even if not minimized, assuming it's not 100k lines of code) could be useful. cc @danscales @randall77 in the meantime. |
I am fully aware that something to reproduce this bug would be useful, and I'm working on it. ;) Some more information: The nil dereference is triggered in line 758 of stencil.go. I have added a fmt.Println(nameNode) before line 756. The output that corresponds with the nil dereference looks like this: LibraryB.nofunc.(*computedObject[bool,bool,int]).getElement None of the other outputs until that point mention "nofunc" in their names. From elsewhere in the compiler sources, "nofunc" seems to suggest that it has something to do with "shape types." Could you tell me what a "shape type" is? Maybe this will give me a clue what I need to pay attention to to be able to create something to reproduce the bug. Thanks, |
More information: I have a method that looks as follows. func (m *comp[D]) asMask() (result structure, ok bool) { m.initialized.Wait() switch m := any(m).(type) { case *comp[bool]: return m.resultStructure.construct(func(i int) bool { result, ok := m.getElement(i) return ok && result }), true default: return } } The bug seems to be triggered by m.getElement(i). When I change this as follows, the problem disappears: func (m *comp[D]) asMask() (result structure, ok bool) { m.initialized.Wait() switch any(m).(type) { case *comp[bool]: return m.resultStructure.construct(func(i int) bool { result, ok := m.getElement(i) return ok && any(result).(bool) }), true default: return } } |
Thanks for the issue report! A simple example of your above code (a type switch on the receiver, where each case is instantiated types) seems to work fine. If there are no confidentiality issues and you are able to package things up reasonable, feel free to point to the entire large failure case, via a github tree, a gzipped archive, etc. Of course, a smaller repro is also welcome. For info on shape types, see here. Basically, we group types into gcshape groups, and only create one instantiation of a specific generic function/type for all types in a group. (Our gcshape groups in Go 1.18 are finer-grain than the ones described in the proposal.) This is to reduce the number of instantiations we create and avoid possible code explosion. A shape type is the representative type in a gcshape group that we use when compiling an instantiation. I'm not sure if knowledge of shape types will necessarily help you create a smaller reproduction. |
It also looks like noder has not been placed under the usual panic handler (which hides panics when there are type errors in the program, and otherwise prints a nice 'internal error' report). It should be. The compiler should never just dump a Go panic like in the report. |
I see what happened. In the C version of the compiler the fault handler was subtly different from hidePanic. In the case where there were no errors printed, it called what amounts today to base.Fatalf("fault"), so that the compiler would print the 'Please file a bug report' text. That's what's missing. And Fatalf already has the right logic (half duplicating hidePanic), so I think hidePanic can be simplfied to
And probably at that point should be renamed to handlePanic. |
Change https://golang.org/cl/376057 mentions this issue: |
… panics Change hidePanic (now renamed handlePanic) to print out the "internal compiler error" message for all panics and runtime exceptions, similar to what we already do for the SSA backend in ssa.Compile(). Previously, hidePanic would not catch panics/exceptions unless it wanted to completely hide the panic because there had already been some compiler errors. Tested by manually inserting a seg fault in the compiler, and verifying that the seg fault is cause and "internal compiler error" message (with stack trace) is displayed proeprly. Updates #50423 Change-Id: Ibe846012e147fcdcc63ac147aae4bdfc47bf5a58 Reviewed-on: https://go-review.googlesource.com/c/go/+/376057 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
I downloaded the newest version of gotip today, and now the issue doesn't occur anymore. Thanks a lot! |
OK, great, not sure what change fixed it. Still happy to have some version of your code as a test case if you're willing, but I realize that may be infeasible. Closing the issue. |
The code where this issue occurred is finally open sourced. You can find the libraries depending on each other at:
Alas, the code has also changed considerably since the bug report above, and what triggered the bug isn't even in the repositories anymore. But maybe you still find this interesting... |
… panics Change hidePanic (now renamed handlePanic) to print out the "internal compiler error" message for all panics and runtime exceptions, similar to what we already do for the SSA backend in ssa.Compile(). Previously, hidePanic would not catch panics/exceptions unless it wanted to completely hide the panic because there had already been some compiler errors. Tested by manually inserting a seg fault in the compiler, and verifying that the seg fault is cause and "internal compiler error" message (with stack trace) is displayed proeprly. Updates golang#50423 Change-Id: Ibe846012e147fcdcc63ac147aae4bdfc47bf5a58 Reviewed-on: https://go-review.googlesource.com/c/go/+/376057 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
What version of Go are you using (
go version
)?and
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
It is very difficult to reproduce the issue. I am currently developing a set of three libraries depending on each other, using generic types in current go 1.18 beta / development versions. (library A depends on B, library B depends on C) The bug occurs when I try to build library A, and it seems to be triggered by an instantiation of a generic function from library B.
The error message I get is the following in go1.18beta1
I get the following with the gotip version:
I have tried several times to create a small example that triggers the same bug, but I haven't yet managed to do so.
What did you expect to see?
I believe the source code to be correct. go1.18beta1 vet *.go and gotip vet *.go don't report any issues.
What did you see instead?
See above.
The text was updated successfully, but these errors were encountered: