- Notifications
You must be signed in to change notification settings - Fork 18.5k
Description
Similar problem to #32595.
Found this bug while investigating avoiding to create algs for array types that are only used as backing array for slices.
It seems this is the reason our initial attempts at introducing that optimisation in https://go-review.googlesource.com/c/go/+/151497 failed with test errors.
Arrays marked noalg are created by the compiler to hold keys and values
to initialize map literals. The ssa backend creates a pointer type for the
array type when creating an OpAddr while processing the loop that
initializes the map from the arrays. The pointer type does not inherit
the noalg property but points to the noalg array type.
This leads to strange problems were the same values of a type dont compare equal anymore if created through reflect:
package a func A() { var m map[int]int = map[int]int{ 0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0, 10: 0, 11: 0, 12: 0, 13: 0, 14: 0, 15: 0, 16: 0, 17: 0, 18: 0, 19: 0, 20: 0, 21: 0, 22: 0, 23: 0, 24: 0, 25: 0, 26: 0, 27: 0, 28: 0, 29: 0} if len(m) != 30 { panic("unepexted map length") } } package b import "reflect" func B() { t1 := reflect.TypeOf([30]int{}) t2 := reflect.TypeOf(new([30]int)).Elem() if t1 != t2 { panic("[30]int types do not match") } } package main import ( "a" "b" ) func main() { a.A() b.B() }