Skip to content

Commit 0a02371

Browse files
Cuong Manh Lecuonglm
Cuong Manh Le
authored andcommitted
cmd/compile: set correct type for OpIData
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 <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 41d8e61 commit 0a02371

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

src/cmd/compile/internal/gc/ssa.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5925,7 +5925,7 @@ func (s *state) dottype(n *Node, commaok bool) (res, resok *ssa.Value) {
59255925
// Load type out of itab, build interface with existing idata.
59265926
off := s.newValue1I(ssa.OpOffPtr, byteptr, int64(Widthptr), itab)
59275927
typ := s.load(byteptr, off)
5928-
idata := s.newValue1(ssa.OpIData, n.Type, iface)
5928+
idata := s.newValue1(ssa.OpIData, byteptr, iface)
59295929
res = s.newValue2(ssa.OpIMake, n.Type, typ, idata)
59305930
return
59315931
}
@@ -5947,7 +5947,7 @@ func (s *state) dottype(n *Node, commaok bool) (res, resok *ssa.Value) {
59475947
bOk.AddEdgeTo(bEnd)
59485948
bFail.AddEdgeTo(bEnd)
59495949
s.startBlock(bEnd)
5950-
idata := s.newValue1(ssa.OpIData, n.Type, iface)
5950+
idata := s.newValue1(ssa.OpIData, byteptr, iface)
59515951
res = s.newValue2(ssa.OpIMake, n.Type, s.variable(&typVar, byteptr), idata)
59525952
resok = cond
59535953
delete(s.vars, &typVar)

src/cmd/compile/internal/ssa/expand_calls.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,6 @@ func expandCalls(f *Func) {
196196
}
197197
if leaf.Op == OpIData {
198198
leafType = removeTrivialWrapperTypes(leaf.Type)
199-
if leafType.IsEmptyInterface() {
200-
leafType = typ.BytePtr
201-
}
202199
}
203200
aux := selector.Aux
204201
auxInt := selector.AuxInt + offset
@@ -247,12 +244,9 @@ func expandCalls(f *Func) {
247244
// i.e., the struct select is generated and remains in because it is not applied to an actual structure.
248245
// The OpLoad was created to load the single field of the IData
249246
// This case removes that StructSelect.
250-
if leafType != selector.Type && !selector.Type.IsEmptyInterface() { // empty interface for #42727
247+
if leafType != selector.Type {
251248
f.Fatalf("Unexpected Load as selector, leaf=%s, selector=%s\n", leaf.LongString(), selector.LongString())
252249
}
253-
if selector.Type.IsEmptyInterface() {
254-
selector.Type = typ.BytePtr
255-
}
256250
leaf.copyOf(selector)
257251
for _, s := range namedSelects[selector] {
258252
locs = append(locs, f.Names[s.locIndex])

test/fixedbugs/issue43112.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// compile
2+
3+
// Copyright 2020 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package p
8+
9+
type Symbol interface{}
10+
11+
type Value interface {
12+
String() string
13+
}
14+
15+
type Object interface {
16+
String() string
17+
}
18+
19+
type Scope struct {
20+
outer *Scope
21+
elems map[string]Object
22+
}
23+
24+
func (s *Scope) findouter(name string) (*Scope, Object) {
25+
return s.outer.findouter(name)
26+
}
27+
28+
func (s *Scope) Resolve(name string) (sym Symbol) {
29+
if _, obj := s.findouter(name); obj != nil {
30+
sym = obj.(Symbol)
31+
}
32+
return
33+
}
34+
35+
type ScopeName struct {
36+
scope *Scope
37+
}
38+
39+
func (n *ScopeName) Get(name string) (Value, error) {
40+
return n.scope.Resolve(name).(Value), nil
41+
}

0 commit comments

Comments
 (0)