Skip to content

Commit

Permalink
[dev.typeparams] all: merge dev.regabi (07569da) into dev.typeparams
Browse files Browse the repository at this point in the history
Conflicts:

- test/fixedbugs/issue27595.go
- test/fixedbugs/issue30087.go
- test/used.go

Merge List:

+ 2020-12-28 07569da [dev.regabi] all: merge master (1d78139) into dev.regabi
+ 2020-12-28 76136be [dev.regabi] cmd/compile: check for recursive import in ImportBody
+ 2020-12-28 fda7ec3 [dev.regabi] cmd/compile: remove Name.IsDDD, etc
+ 2020-12-28 098a649 [dev.regabi] cmd/compile: remove Declare in makepartialcall
+ 2020-12-28 137f0d2 [dev.regabi] cmd/compile: remove unnecessary Name.Sym call
+ 2020-12-28 3383b5c [dev.regabi] cmd/compile: flatten dependency graph [generated]
+ 2020-12-28 f8afb82 [dev.regabi] cmd/compile: rename CommStmt and CaseStmt [generated]
+ 2020-12-28 5f3bd59 [dev.regabi] cmd/compile: remove some unneeded code in package ir
+ 2020-12-28 3bdafb0 [dev.regabi] cmd/compile: remove CommStmt.List
+ 2020-12-28 2ecf52b [dev.regabi] cmd/compile: separate CommStmt from CaseStmt
+ 2020-12-28 ed9772e [dev.regabi] cmd/compile: add explicit file name in types generation
+ 2020-12-28 a59d266 [dev.regabi] cmd/compile: use []*CaseStmt in {Select,Switch}Stmt
+ 2020-12-28 fbc4458 [dev.regabi] cmd/compile: simplify some tree traversal code
+ 2020-12-28 6c67677 [dev.regabi] cmd/compile: simplify FuncName and PkgFuncName
+ 2020-12-28 676d794 [dev.regabi] cmd/compile: remove refersToCommonName
+ 2020-12-28 c98548e [dev.regabi] cmd/compile: merge ascompatee, ascompatee1, and reorder3
+ 2020-12-28 4c215c4 [dev.regabi] cmd/compile: simplify and optimize reorder3
+ 2020-12-28 e6c9731 [dev.regabi] cmd/compile: stop mangling SelectorExpr.Sel for ODOTMETH
+ 2020-12-28 135ce1c [dev.regabi] cmd/compile: desugar OMETHEXPR into ONAME during walk
+ 2020-12-28 0f732f8 [dev.regabi] cmd/compile: minor walkExpr cleanups
+ 2020-12-28 0de8eaf [dev.regabi] cmd/compile: remove SelectorExpr.Offset field
+ 2020-12-28 a4f335f [dev.regabi] cmd/compile: always use a Field for ODOTPTR expressions
+ 2020-12-26 1d78139 runtime/cgo: fix Android build with NDK 22
+ 2020-12-25 2018b68 net/mail: don't use MDT in test
+ 2020-12-25 e4f293d [dev.regabi] cmd/compile: fix OCALLMETH desugaring
+ 2020-12-25 1d9a1f6 [dev.regabi] cmd/compile: don't emit reflect data for method types
+ 2020-12-25 396b6c2 [dev.regabi] cmd/compile: cleanup assignment typechecking
+ 2020-12-25 e24d2f3 [dev.regabi] cmd/compile: remove typ from RangeStmt
+ 2020-12-25 2785c69 [dev.regabi] cmd/compile: cleanup devirtualization docs
+ 2020-12-25 4b1d0fe [dev.regabi] cmd/compile: new devirtualization pkg [generated]
+ 2020-12-24 082cc8b [dev.regabi] cmd/compile: change ir.IsAssignable -> ir.IsAddressable
+ 2020-12-24 27b248b [dev.regabi] cmd/compile: separate range stmt Vars to Key, Value nodes
+ 2020-12-23 4081803 [dev.regabi] cmd/compile: change CaseStmt.Vars to Var
+ 2020-12-23 b116404 runtime: shift timeHistogram buckets and allow negative durations
+ 2020-12-23 8db7e2f runtime: fix allocs-by-size and frees-by-size buckets
+ 2020-12-23 fb96f07 runtime: fix nStackRoots comment about stack roots
+ 2020-12-23 d1502b3 lib/time, time/tzdata: update tzdata to 2020e
+ 2020-12-23 30c99cb cmd/go: add the Retract field to 'go help mod edit' definition of the GoMod struct
+ 2020-12-23 49d0b23 doc: fix a typo in contribute.html
+ 2020-12-23 9eeed29 [dev.regabi] cmd/compile: eliminate usage of ir.Node in liveness
+ 2020-12-23 d1d64e4 [dev.regabi] cmd/compile: split SliceExpr.List into separate fields
+ 2020-12-23 98a7303 cmd/go: in 'go get', promote named implicit dependencies to explicit
+ 2020-12-23 d19018e [dev.regabi] cmd/compile: split SliceHeaderExpr.LenCap into separate fields
+ 2020-12-23 53f082b [dev.regabi] cmd/compile: cleanup export code further
+ 2020-12-23 31267f8 [dev.regabi] cmd/compile: simplify function/interface/struct typechecking
+ 2020-12-23 addade2 [dev.regabi] cmd/compile: prefer types constructors over typecheck
+ 2020-12-23 18ebfb4 [dev.regabi] cmd/compile: cleanup noder
+ 2020-12-23 87a592b [dev.regabi] cmd/compile: cleanup import/export code
+ 2020-12-23 5898025 [dev.regabi] cmd/compile: update mkbuiltin.go to use new type constructors
+ 2020-12-23 63c96c2 [dev.regabi] cmd/compile: update mkbuiltin.go and re-enable TestBuiltin
+ 2020-12-23 fd6ba1c os/signal: fix a deadlock with syscall.AllThreadsSyscall() use
+ 2020-12-23 b0b0d98 runtime: linux iscgo support for not blocking nptl signals
+ 2020-12-22 223331f cmd/go/internal/modload: add hint for missing implicit dependency

Change-Id: Iecb8a7dfb401b6ab383e97101cd81bfc201683f6
  • Loading branch information
mdempsky committed Dec 28, 2020
2 parents dd40bbc + 07569da commit a800aca
Show file tree
Hide file tree
Showing 90 changed files with 8,495 additions and 8,665 deletions.
2 changes: 1 addition & 1 deletion doc/contribute.html
Expand Up @@ -1129,7 +1129,7 @@ <h3 id="quick_test">Quickly testing your changes</h3>
might require a newer version than the stable one you have installed).

<pre>
$ cd $GODIR/src/hash/sha1
$ cd $GODIR/src/crypto/sha1
$ [make changes...]
$ $GODIR/bin/go test .
</pre>
Expand Down
4 changes: 2 additions & 2 deletions lib/time/update.bash
Expand Up @@ -8,8 +8,8 @@
# Consult https://www.iana.org/time-zones for the latest versions.

# Versions to use.
CODE=2020d
DATA=2020d
CODE=2020e
DATA=2020e

set -e
rm -rf work
Expand Down
Binary file modified lib/time/zoneinfo.zip
Binary file not shown.
85 changes: 85 additions & 0 deletions src/cmd/compile/internal/devirtualize/devirtualize.go
@@ -0,0 +1,85 @@
// 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 devirtualize implements a simple "devirtualization"
// optimization pass, which replaces interface method calls with
// direct concrete-type method calls where possible.
package devirtualize

import (
"cmd/compile/internal/base"
"cmd/compile/internal/ir"
"cmd/compile/internal/typecheck"
"cmd/compile/internal/types"
)

// Func devirtualizes calls within fn where possible.
func Func(fn *ir.Func) {
ir.CurFunc = fn
ir.VisitList(fn.Body, func(n ir.Node) {
if call, ok := n.(*ir.CallExpr); ok {
Call(call)
}
})
}

// Call devirtualizes the given call if possible.
func Call(call *ir.CallExpr) {
if call.Op() != ir.OCALLINTER {
return
}
sel := call.X.(*ir.SelectorExpr)
r := ir.StaticValue(sel.X)
if r.Op() != ir.OCONVIFACE {
return
}
recv := r.(*ir.ConvExpr)

typ := recv.X.Type()
if typ.IsInterface() {
return
}

dt := ir.NewTypeAssertExpr(sel.Pos(), sel.X, nil)
dt.SetType(typ)
x := typecheck.Callee(ir.NewSelectorExpr(sel.Pos(), ir.OXDOT, dt, sel.Sel))
switch x.Op() {
case ir.ODOTMETH:
x := x.(*ir.SelectorExpr)
if base.Flag.LowerM != 0 {
base.WarnfAt(call.Pos(), "devirtualizing %v to %v", sel, typ)
}
call.SetOp(ir.OCALLMETH)
call.X = x
case ir.ODOTINTER:
// Promoted method from embedded interface-typed field (#42279).
x := x.(*ir.SelectorExpr)
if base.Flag.LowerM != 0 {
base.WarnfAt(call.Pos(), "partially devirtualizing %v to %v", sel, typ)
}
call.SetOp(ir.OCALLINTER)
call.X = x
default:
// TODO(mdempsky): Turn back into Fatalf after more testing.
if base.Flag.LowerM != 0 {
base.WarnfAt(call.Pos(), "failed to devirtualize %v (%v)", x, x.Op())
}
return
}

// Duplicated logic from typecheck for function call return
// value types.
//
// Receiver parameter size may have changed; need to update
// call.Type to get correct stack offsets for result
// parameters.
types.CheckSize(x.Type())
switch ft := x.Type(); ft.NumResults() {
case 0:
case 1:
call.SetType(ft.Results().Field(0).Type)
default:
call.SetType(ft.Results())
}
}
29 changes: 12 additions & 17 deletions src/cmd/compile/internal/escape/escape.go
Expand Up @@ -347,21 +347,19 @@ func (e *escape) stmt(n ir.Node) {
e.loopDepth--

case ir.ORANGE:
// for List = range Right { Nbody }
// for Key, Value = range X { Body }
n := n.(*ir.RangeStmt)
e.loopDepth++
ks := e.addrs(n.Vars)
e.addr(n.Key)
k := e.addr(n.Value)
e.block(n.Body)
e.loopDepth--

// Right is evaluated outside the loop.
k := e.discardHole()
if len(ks) >= 2 {
if n.X.Type().IsArray() {
k = ks[1].note(n, "range")
} else {
k = ks[1].deref(n, "range-deref")
}
// X is evaluated outside the loop.
if n.X.Type().IsArray() {
k = k.note(n, "range")
} else {
k = k.deref(n, "range-deref")
}
e.expr(e.later(k), n.X)

Expand All @@ -371,9 +369,8 @@ func (e *escape) stmt(n ir.Node) {

var ks []hole
for _, cas := range n.Cases { // cases
cas := cas.(*ir.CaseStmt)
if typesw && n.Tag.(*ir.TypeSwitchGuard).Tag != nil {
cv := cas.Vars[0]
cv := cas.Var
k := e.dcl(cv) // type switch variables have no ODCL.
if cv.Type().HasPointers() {
ks = append(ks, k.dotType(cv.Type(), cas, "switch case"))
Expand All @@ -393,7 +390,6 @@ func (e *escape) stmt(n ir.Node) {
case ir.OSELECT:
n := n.(*ir.SelectStmt)
for _, cas := range n.Cases {
cas := cas.(*ir.CaseStmt)
e.stmt(cas.Comm)
e.block(cas.Body)
}
Expand Down Expand Up @@ -559,10 +555,9 @@ func (e *escape) exprSkipInit(k hole, n ir.Node) {
case ir.OSLICE, ir.OSLICEARR, ir.OSLICE3, ir.OSLICE3ARR, ir.OSLICESTR:
n := n.(*ir.SliceExpr)
e.expr(k.note(n, "slice"), n.X)
low, high, max := n.SliceBounds()
e.discard(low)
e.discard(high)
e.discard(max)
e.discard(n.Low)
e.discard(n.High)
e.discard(n.Max)

case ir.OCONV, ir.OCONVNOP:
n := n.(*ir.ConvExpr)
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/compile/internal/gc/main.go
Expand Up @@ -10,6 +10,7 @@ import (
"bufio"
"bytes"
"cmd/compile/internal/base"
"cmd/compile/internal/devirtualize"
"cmd/compile/internal/dwarfgen"
"cmd/compile/internal/escape"
"cmd/compile/internal/inline"
Expand Down Expand Up @@ -243,7 +244,7 @@ func Main(archInit func(*ssagen.ArchInfo)) {
// Devirtualize.
for _, n := range typecheck.Target.Decls {
if n.Op() == ir.ODCLFUNC {
inline.Devirtualize(n.(*ir.Func))
devirtualize.Func(n.(*ir.Func))
}
}
ir.CurFunc = nil
Expand Down
91 changes: 11 additions & 80 deletions src/cmd/compile/internal/inline/inl.go
Expand Up @@ -324,19 +324,17 @@ func (v *hairyVisitor) doNode(n ir.Node) error {
if t == nil {
base.Fatalf("no function type for [%p] %+v\n", n.X, n.X)
}
if types.IsRuntimePkg(n.X.Sym().Pkg) {
fn := n.X.Sym().Name
if fn == "heapBits.nextArena" {
// Special case: explicitly allow
// mid-stack inlining of
// runtime.heapBits.next even though
// it calls slow-path
// runtime.heapBits.nextArena.
break
}
fn := ir.MethodExprName(n.X).Func
if types.IsRuntimePkg(fn.Sym().Pkg) && fn.Sym().Name == "heapBits.nextArena" {
// Special case: explicitly allow
// mid-stack inlining of
// runtime.heapBits.next even though
// it calls slow-path
// runtime.heapBits.nextArena.
break
}
if inlfn := ir.MethodExprName(n.X).Func; inlfn.Inl != nil {
v.budget -= inlfn.Inl.Cost
if fn.Inl != nil {
v.budget -= fn.Inl.Cost
break
}
// Call cost for non-leaf inlining.
Expand Down Expand Up @@ -531,7 +529,7 @@ func inlnode(n ir.Node, maxCost int32, inlMap map[*ir.Func]bool, edit func(ir.No
// Prevent inlining some reflect.Value methods when using checkptr,
// even when package reflect was compiled without it (#35073).
n := n.(*ir.CallExpr)
if s := n.X.Sym(); base.Debug.Checkptr != 0 && types.IsReflectPkg(s.Pkg) && (s.Name == "Value.UnsafeAddr" || s.Name == "Value.Pointer") {
if s := ir.MethodExprName(n.X).Sym(); base.Debug.Checkptr != 0 && types.IsReflectPkg(s.Pkg) && (s.Name == "Value.UnsafeAddr" || s.Name == "Value.Pointer") {
return n
}
}
Expand Down Expand Up @@ -1203,73 +1201,6 @@ func pruneUnusedAutos(ll []*ir.Name, vis *hairyVisitor) []*ir.Name {
return s
}

// Devirtualize replaces interface method calls within fn with direct
// concrete-type method calls where applicable.
func Devirtualize(fn *ir.Func) {
ir.CurFunc = fn
ir.VisitList(fn.Body, func(n ir.Node) {
if n.Op() == ir.OCALLINTER {
devirtualizeCall(n.(*ir.CallExpr))
}
})
}

func devirtualizeCall(call *ir.CallExpr) {
sel := call.X.(*ir.SelectorExpr)
r := ir.StaticValue(sel.X)
if r.Op() != ir.OCONVIFACE {
return
}
recv := r.(*ir.ConvExpr)

typ := recv.X.Type()
if typ.IsInterface() {
return
}

dt := ir.NewTypeAssertExpr(sel.Pos(), sel.X, nil)
dt.SetType(typ)
x := typecheck.Callee(ir.NewSelectorExpr(sel.Pos(), ir.OXDOT, dt, sel.Sel))
switch x.Op() {
case ir.ODOTMETH:
x := x.(*ir.SelectorExpr)
if base.Flag.LowerM != 0 {
base.WarnfAt(call.Pos(), "devirtualizing %v to %v", sel, typ)
}
call.SetOp(ir.OCALLMETH)
call.X = x
case ir.ODOTINTER:
// Promoted method from embedded interface-typed field (#42279).
x := x.(*ir.SelectorExpr)
if base.Flag.LowerM != 0 {
base.WarnfAt(call.Pos(), "partially devirtualizing %v to %v", sel, typ)
}
call.SetOp(ir.OCALLINTER)
call.X = x
default:
// TODO(mdempsky): Turn back into Fatalf after more testing.
if base.Flag.LowerM != 0 {
base.WarnfAt(call.Pos(), "failed to devirtualize %v (%v)", x, x.Op())
}
return
}

// Duplicated logic from typecheck for function call return
// value types.
//
// Receiver parameter size may have changed; need to update
// call.Type to get correct stack offsets for result
// parameters.
types.CheckSize(x.Type())
switch ft := x.Type(); ft.NumResults() {
case 0:
case 1:
call.SetType(ft.Results().Field(0).Type)
default:
call.SetType(ft.Results())
}
}

// numNonClosures returns the number of functions in list which are not closures.
func numNonClosures(list []*ir.Func) int {
count := 0
Expand Down

0 comments on commit a800aca

Please sign in to comment.