]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: set correct type for OpIData
authorCuong Manh Le <cuong@orijtech.com>
Mon, 14 Dec 2020 02:45:44 +0000 (09:45 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 14 Dec 2020 03:21:35 +0000 (03:21 +0000)
Since CL 270057, there're many attempts to fix the expand_calls pass
with interface{}-typed. But all of them did not fix the root cause. The
main issue is during SSA conversion in gc/ssa.go, for empty interface
case, we make its type as n.Type, instead of BytePtr.

To fix these, we can just use BytePtr for now, since when itab fields
are treated as scalar.

No significal changes on compiler speed, size.

cmd/compile/internal/ssa
expandCalls.func6 9488 -> 9232  (-2.70%)

file                       before   after    Δ       %
cmd/compile/internal/ssa.s 3992893  3992637  -256    -0.006%
total                      20500447 20500191 -256    -0.001%

Fixes #43112
Updates #42784
Updates #42727
Updates #42568

Change-Id: I0b15d9434e0be5448453e61f98ef9c2d6cd93792
Reviewed-on: https://go-review.googlesource.com/c/go/+/276952
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/ssa/expand_calls.go
test/fixedbugs/issue43112.go [new file with mode: 0644]

index 65b9291b764d0237bc1f33fe6cd4ac76dd1c8406..5b74754b53291211f486cca9d28017ed1ce60f23 100644 (file)
@@ -5925,7 +5925,7 @@ func (s *state) dottype(n *Node, commaok bool) (res, resok *ssa.Value) {
                                // Load type out of itab, build interface with existing idata.
                                off := s.newValue1I(ssa.OpOffPtr, byteptr, int64(Widthptr), itab)
                                typ := s.load(byteptr, off)
-                               idata := s.newValue1(ssa.OpIData, n.Type, iface)
+                               idata := s.newValue1(ssa.OpIData, byteptr, iface)
                                res = s.newValue2(ssa.OpIMake, n.Type, typ, idata)
                                return
                        }
@@ -5947,7 +5947,7 @@ func (s *state) dottype(n *Node, commaok bool) (res, resok *ssa.Value) {
                        bOk.AddEdgeTo(bEnd)
                        bFail.AddEdgeTo(bEnd)
                        s.startBlock(bEnd)
-                       idata := s.newValue1(ssa.OpIData, n.Type, iface)
+                       idata := s.newValue1(ssa.OpIData, byteptr, iface)
                        res = s.newValue2(ssa.OpIMake, n.Type, s.variable(&typVar, byteptr), idata)
                        resok = cond
                        delete(s.vars, &typVar)
index f266e49327eee56a1bb9d4ce94ab3ca0d0beb3a2..fbde19d94c29927a2a50a0d396ced550fed31dcb 100644 (file)
@@ -196,9 +196,6 @@ func expandCalls(f *Func) {
                        }
                        if leaf.Op == OpIData {
                                leafType = removeTrivialWrapperTypes(leaf.Type)
-                               if leafType.IsEmptyInterface() {
-                                       leafType = typ.BytePtr
-                               }
                        }
                        aux := selector.Aux
                        auxInt := selector.AuxInt + offset
@@ -247,12 +244,9 @@ func expandCalls(f *Func) {
                        // i.e., the struct select is generated and remains in because it is not applied to an actual structure.
                        // The OpLoad was created to load the single field of the IData
                        // This case removes that StructSelect.
-                       if leafType != selector.Type && !selector.Type.IsEmptyInterface() { // empty interface for #42727
+                       if leafType != selector.Type {
                                f.Fatalf("Unexpected Load as selector, leaf=%s, selector=%s\n", leaf.LongString(), selector.LongString())
                        }
-                       if selector.Type.IsEmptyInterface() {
-                               selector.Type = typ.BytePtr
-                       }
                        leaf.copyOf(selector)
                        for _, s := range namedSelects[selector] {
                                locs = append(locs, f.Names[s.locIndex])
diff --git a/test/fixedbugs/issue43112.go b/test/fixedbugs/issue43112.go
new file mode 100644 (file)
index 0000000..e36627a
--- /dev/null
@@ -0,0 +1,41 @@
+// compile
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+type Symbol interface{}
+
+type Value interface {
+       String() string
+}
+
+type Object interface {
+       String() string
+}
+
+type Scope struct {
+       outer *Scope
+       elems map[string]Object
+}
+
+func (s *Scope) findouter(name string) (*Scope, Object) {
+       return s.outer.findouter(name)
+}
+
+func (s *Scope) Resolve(name string) (sym Symbol) {
+       if _, obj := s.findouter(name); obj != nil {
+               sym = obj.(Symbol)
+       }
+       return
+}
+
+type ScopeName struct {
+       scope *Scope
+}
+
+func (n *ScopeName) Get(name string) (Value, error) {
+       return n.scope.Resolve(name).(Value), nil
+}