-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: tricky map key causes internal compiler error #14988
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
Comments
Sounds like we should run the new SSA backend against https://github.com/dvyukov/gosmith / go-fuzz. |
This error isn't from the SSA backend. It has existed since 1.5. |
I did a little bit of investigating. Consider the following two programs: P_1:
OUT_1: The first line creates a forward declaration for k. The next line sets the value of m to a map with key 'k' and runs checkMapKeyType. It fails properly because [1]map[anything]anything is not a comparison type. Now consider the same program with the two lines swapped: P_2:
OUT_2: The difference is subtle. The first line creates a forward type for m. The second line creates a forward type for k, and checkMapKeyType([1]m) is called. The entire key [1]m is treated as a forward type instead of as array with an element that's a forward type. Instead of erroring out, checkMapKeyType does nothing and waits for the type [1]m to be fully resolved, which I don't believe will ever happen because of the mutually recursive type definitions. This is eventually caught here: https://github.com/golang/go/blob/master/src/cmd/compile/internal/gc/reflect.go#L1006 |
I took at stab at a fix: https://go-review.googlesource.com/#/c/21830/ New results: P_1 (original bug):
OUT_1: P_2:
OUT_2:
|
CL https://golang.org/cl/21830 mentions this issue. |
Yields:
The code is invalid anyway, but we should be detecting that during type checking. It shouldn't be triggering an ICE.
The text was updated successfully, but these errors were encountered: