Skip to content

Commit

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

- src/cmd/compile/internal/gc/main.go
- test/fixedbugs/issue15055.go

Merge List:

+ 2021-01-05 77365c5 [dev.regabi] cmd/compile: add Name.Canonical and move Byval
+ 2021-01-05 e09783c [dev.regabi] cmd/compile: make ir.StaticValue safer
+ 2021-01-05 9aa950c [dev.regabi] cmd/compile: make ir.OuterValue safer
+ 2021-01-05 eb62640 [dev.regabi] cmd/compile: simplify CaptureVars
+ 2021-01-05 c28ca67 [dev.regabi] cmd/compile: fix ir.Dump for []*CaseClause, etc
+ 2021-01-04 f24e40c [dev.regabi] cmd/compile: remove Name.Class_ accessors
+ 2021-01-04 d89705e [dev.regabi] cmd/compile: fix re-export of parameters
+ 2021-01-04 290b415 [dev.regabi] cmd/compile: fix ICE due to large uint64 constants
+ 2021-01-04 a30fd52 [dev.regabi] cmd/compile: use ir.NewNameAt in SubstArgTypes
+ 2021-01-03 8fc44cf [dev.regabi] cmd/compile: remove a couple CloneName calls
+ 2021-01-03 907a4bf [dev.regabi] cmd/compile: fix map assignment order
+ 2021-01-03 f2e6dab [dev.regabi] cmd/compile: remove walkReturn "common case" path
+ 2021-01-03 d36a6bf [dev.regabi] cmd/compile: improve walkReturn common case
+ 2021-01-03 a317067 [dev.regabi] cmd/compile: improve ascompatee
+ 2021-01-03 5d80a59 [dev.regabi] cmd/compile: simplify walkReturn
+ 2021-01-03 bb1b6c9 [dev.regabi] cmd/compile: remove Node.{,Set}Walkdef
+ 2021-01-03 57c426c [dev.regabi] cmd/compile: tighten typecheckdef to *ir.Name
+ 2021-01-03 b174775 [dev.regabi] cmd/compile: reorganize escape analysis somewhat
+ 2021-01-02 f253803 [dev.regabi] cmd/compile: remove Nodes.Set [generated]
+ 2021-01-02 2f2d4b4 [dev.regabi] cmd/compile: remove {Ptr,Set}Init from Node interface
+ 2021-01-01 1544a03 [dev.regabi] cmd/compile: refactor redundant type conversion [generated]
+ 2021-01-01 7958a23 [dev.regabi] cmd/compile: use *ir.Name where possible in inl.go
+ 2021-01-01 bfa97ba [dev.regabi] test: add another closure test case
+ 2021-01-01 67ad695 [dev.regabi] cmd/compile: split escape analysis state
+ 2021-01-01 fad9a8b [dev.regabi] cmd/compile: simplify inlining of closures
+ 2021-01-01 7d55669 [dev.regabi] cmd/compile: simplify dwarfgen.declPos
+ 2021-01-01 9ed1577 [dev.regabi] cmd/compile: remove Func.ClosureEnter
+ 2021-01-01 ece345a [dev.regabi] cmd/compile: expand documentation for Func.Closure{Vars,Enter}
+ 2021-01-01 6ddbc75 [dev.regabi] cmd/compile: earlier deadcode removal
+ 2021-01-01 68e6fa4 [dev.regabi] cmd/compile: fix package-initialization order
+ 2021-01-01 3a4474c [dev.regabi] cmd/compile: some more manual shuffling
+ 2021-01-01 0f1d212 [dev.regabi] cmd/compile: reshuffle type-checking code [generated]
+ 2021-01-01 b8fd344 [dev.regabi] cmd/compile: report unused variables during typecheck
+ 2021-01-01 fd22df9 [dev.regabi] cmd/compile: remove idempotent Name() calls [generated]
+ 2020-12-31 dfbcff8 [dev.regabi] cmd/compile: make copyExpr return *ir.Name directly
+ 2020-12-31 77fd81a [dev.regabi] cmd/compile: use names for keep alive variables in function call
+ 2020-12-31 8fe1197 [dev.regabi] cmd/compile: remove Name.orig
+ 2020-12-31 477b049 [dev.regabi] cmd/compile: fix printing of method expressions
+ 2020-12-30 178c667 [dev.regabi] cmd/compile: fix OSLICEARR comments
+ 2020-12-30 f0d99de [dev.regabi] cmd/compile: add newline to ir.Dump
+ 2020-12-30 451693a [dev.regabi] cmd/compile: simplify typecheckdef
+ 2020-12-30 0c1a899 [dev.regabi] cmd/compile: fix defined-pointer method call check
+ 2020-12-30 f9b67f7 [dev.regabi] cmd/compile: change ir.DoChildren to use bool result type
+ 2020-12-30 499851b [dev.regabi] cmd/compile: generalize ir/mknode.go
+ 2020-12-30 82ab3d1 [dev.regabi] cmd/compile: use *ir.Name for Decl.X
+ 2020-12-30 9958b7e [dev.regabi] cmd/compile: unexport ir.FmtNode
+ 2020-12-29 f581662 [dev.regabi] cmd/compile: change AddrExpr.Alloc to AddrExpr.Prealloc
+ 2020-12-29 850aa7c [dev.regabi] cmd/compile: use *ir.Name instead of ir.Node for CaseClause.Var
+ 2020-12-29 37babc9 [dev.regabi] cmd/compile: allow visitor visits *ir.Name
+ 2020-12-29 5cf3c87 [dev.regabi] cmd/compile: generate case/comm clause functions in mknode.go
+ 2020-12-29 b3e1ec9 [dev.regabi] cmd/compile: move new addrtaken bit back to the old name
+ 2020-12-29 0620c67 [dev.regabi] cmd/compile: remove original addrtaken bit
+ 2020-12-29 0523d52 [dev.regabi] cmd/compile: separate out address taken computation from typechecker
+ 2020-12-29 9ea272e [dev.regabi] cmd/compile: simplify ir.Func somewhat
+ 2020-12-29 e40cb4d [dev.regabi] cmd/compile: remove more unused code
+ 2020-12-29 6f30c95 [dev.regabi] cmd/compile: remove unneeded indirection
+ 2020-12-29 171fc6f [dev.regabi] cmd/compile: remove workarounds for go/constant issues
+ 2020-12-29 33801cd [dev.regabi] cmd/compile: use Ntype where possible
+ 2020-12-29 82ad308 [dev.regabi] cmd/compile: remove typ from AssignOpStmt
+ 2020-12-29 e34c44a [dev.regabi] cmd/compile: refactoring typecheck arith
+ 2020-12-29 a5ec920 [dev.regabi] cmd/compile: more Linksym cleanup
+ 2020-12-29 ec59b19 [dev.regabi] cmd/compile: rewrite to use linksym helpers [generated]
+ 2020-12-29 25c613c [dev.regabi] cmd/compile: add Linksym helpers
+ 2020-12-29 289da2b [dev.regabi] cmd/compile: move Node.Opt to Name
+ 2020-12-29 6acbae4 [dev.regabi] cmd/compile: address some ir TODOs
+ 2020-12-29 4629f6a [dev.regabi] cmd/compile: merge {Selector,CallPart,Method}Expr
+ 2020-12-29 e563715 [dev.regabi] cmd/compile: remove Sym.Importdef
+ 2020-12-29 3f370b7 [dev.regabi] cmd/compile: cleanup //go:generate directives

Change-Id: Ibb254630924ac5873ebda6762ceb066f54a82649
  • Loading branch information
mdempsky committed Jan 5, 2021
2 parents a800aca + 77365c5 commit a8fe098
Show file tree
Hide file tree
Showing 88 changed files with 3,389 additions and 2,754 deletions.
152 changes: 152 additions & 0 deletions src/cmd/compile/internal/deadcode/deadcode.go
@@ -0,0 +1,152 @@
// Copyright 2009 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 deadcode

import (
"go/constant"

"cmd/compile/internal/base"
"cmd/compile/internal/ir"
)

func Func(fn *ir.Func) {
stmts(&fn.Body)

if len(fn.Body) == 0 {
return
}

for _, n := range fn.Body {
if len(n.Init()) > 0 {
return
}
switch n.Op() {
case ir.OIF:
n := n.(*ir.IfStmt)
if !ir.IsConst(n.Cond, constant.Bool) || len(n.Body) > 0 || len(n.Else) > 0 {
return
}
case ir.OFOR:
n := n.(*ir.ForStmt)
if !ir.IsConst(n.Cond, constant.Bool) || ir.BoolVal(n.Cond) {
return
}
default:
return
}
}

fn.Body = []ir.Node{ir.NewBlockStmt(base.Pos, nil)}
}

func stmts(nn *ir.Nodes) {
var lastLabel = -1
for i, n := range *nn {
if n != nil && n.Op() == ir.OLABEL {
lastLabel = i
}
}
for i, n := range *nn {
// Cut is set to true when all nodes after i'th position
// should be removed.
// In other words, it marks whole slice "tail" as dead.
cut := false
if n == nil {
continue
}
if n.Op() == ir.OIF {
n := n.(*ir.IfStmt)
n.Cond = expr(n.Cond)
if ir.IsConst(n.Cond, constant.Bool) {
var body ir.Nodes
if ir.BoolVal(n.Cond) {
n.Else = ir.Nodes{}
body = n.Body
} else {
n.Body = ir.Nodes{}
body = n.Else
}
// If "then" or "else" branch ends with panic or return statement,
// it is safe to remove all statements after this node.
// isterminating is not used to avoid goto-related complications.
// We must be careful not to deadcode-remove labels, as they
// might be the target of a goto. See issue 28616.
if body := body; len(body) != 0 {
switch body[(len(body) - 1)].Op() {
case ir.ORETURN, ir.ORETJMP, ir.OPANIC:
if i > lastLabel {
cut = true
}
}
}
}
}

if len(n.Init()) != 0 {
stmts(n.(ir.InitNode).PtrInit())
}
switch n.Op() {
case ir.OBLOCK:
n := n.(*ir.BlockStmt)
stmts(&n.List)
case ir.OFOR:
n := n.(*ir.ForStmt)
stmts(&n.Body)
case ir.OIF:
n := n.(*ir.IfStmt)
stmts(&n.Body)
stmts(&n.Else)
case ir.ORANGE:
n := n.(*ir.RangeStmt)
stmts(&n.Body)
case ir.OSELECT:
n := n.(*ir.SelectStmt)
for _, cas := range n.Cases {
stmts(&cas.Body)
}
case ir.OSWITCH:
n := n.(*ir.SwitchStmt)
for _, cas := range n.Cases {
stmts(&cas.Body)
}
}

if cut {
*nn = (*nn)[:i+1]
break
}
}
}

func expr(n ir.Node) ir.Node {
// Perform dead-code elimination on short-circuited boolean
// expressions involving constants with the intent of
// producing a constant 'if' condition.
switch n.Op() {
case ir.OANDAND:
n := n.(*ir.LogicalExpr)
n.X = expr(n.X)
n.Y = expr(n.Y)
if ir.IsConst(n.X, constant.Bool) {
if ir.BoolVal(n.X) {
return n.Y // true && x => x
} else {
return n.X // false && x => false
}
}
case ir.OOROR:
n := n.(*ir.LogicalExpr)
n.X = expr(n.X)
n.Y = expr(n.Y)
if ir.IsConst(n.X, constant.Bool) {
if ir.BoolVal(n.X) {
return n.X // true || x => true
} else {
return n.Y // false || x => x
}
}
}
return n
}
71 changes: 27 additions & 44 deletions src/cmd/compile/internal/dwarfgen/dwarf.go
Expand Up @@ -26,7 +26,7 @@ func Info(fnsym *obj.LSym, infosym *obj.LSym, curfn interface{}) ([]dwarf.Scope,
fn := curfn.(*ir.Func)

if fn.Nname != nil {
expect := fn.Sym().Linksym()
expect := fn.Linksym()
if fnsym.ABI() == obj.ABI0 {
expect = fn.Sym().LinksymABI0()
}
Expand Down Expand Up @@ -76,7 +76,7 @@ func Info(fnsym *obj.LSym, infosym *obj.LSym, curfn interface{}) ([]dwarf.Scope,
if n.Op() != ir.ONAME { // might be OTYPE or OLITERAL
continue
}
switch n.Class_ {
switch n.Class {
case ir.PAUTO:
if !n.Used() {
// Text == nil -> generating abstract function
Expand All @@ -90,7 +90,7 @@ func Info(fnsym *obj.LSym, infosym *obj.LSym, curfn interface{}) ([]dwarf.Scope,
continue
}
apdecls = append(apdecls, n)
fnsym.Func().RecordAutoType(reflectdata.TypeSym(n.Type()).Linksym())
fnsym.Func().RecordAutoType(reflectdata.TypeLinksym(n.Type()))
}
}

Expand Down Expand Up @@ -127,24 +127,7 @@ func Info(fnsym *obj.LSym, infosym *obj.LSym, curfn interface{}) ([]dwarf.Scope,
}

func declPos(decl *ir.Name) src.XPos {
if decl.Name().Defn != nil && (decl.Name().Captured() || decl.Name().Byval()) {
// It's not clear which position is correct for captured variables here:
// * decl.Pos is the wrong position for captured variables, in the inner
// function, but it is the right position in the outer function.
// * decl.Name.Defn is nil for captured variables that were arguments
// on the outer function, however the decl.Pos for those seems to be
// correct.
// * decl.Name.Defn is the "wrong" thing for variables declared in the
// header of a type switch, it's their position in the header, rather
// than the position of the case statement. In principle this is the
// right thing, but here we prefer the latter because it makes each
// instance of the header variable local to the lexical block of its
// case statement.
// This code is probably wrong for type switch variables that are also
// captured.
return decl.Name().Defn.Pos()
}
return decl.Pos()
return decl.Canonical().Pos()
}

// createDwarfVars process fn, returning a list of DWARF variables and the
Expand Down Expand Up @@ -185,7 +168,7 @@ func createDwarfVars(fnsym *obj.LSym, complexOK bool, fn *ir.Func, apDecls []*ir
if c == '.' || n.Type().IsUntyped() {
continue
}
if n.Class_ == ir.PPARAM && !ssagen.TypeOK(n.Type()) {
if n.Class == ir.PPARAM && !ssagen.TypeOK(n.Type()) {
// SSA-able args get location lists, and may move in and
// out of registers, so those are handled elsewhere.
// Autos and named output params seem to get handled
Expand All @@ -200,28 +183,28 @@ func createDwarfVars(fnsym *obj.LSym, complexOK bool, fn *ir.Func, apDecls []*ir
typename := dwarf.InfoPrefix + types.TypeSymName(n.Type())
decls = append(decls, n)
abbrev := dwarf.DW_ABRV_AUTO_LOCLIST
isReturnValue := (n.Class_ == ir.PPARAMOUT)
if n.Class_ == ir.PPARAM || n.Class_ == ir.PPARAMOUT {
isReturnValue := (n.Class == ir.PPARAMOUT)
if n.Class == ir.PPARAM || n.Class == ir.PPARAMOUT {
abbrev = dwarf.DW_ABRV_PARAM_LOCLIST
} else if n.Class_ == ir.PAUTOHEAP {
} else if n.Class == ir.PAUTOHEAP {
// If dcl in question has been promoted to heap, do a bit
// of extra work to recover original class (auto or param);
// see issue 30908. This insures that we get the proper
// signature in the abstract function DIE, but leaves a
// misleading location for the param (we want pointer-to-heap
// and not stack).
// TODO(thanm): generate a better location expression
stackcopy := n.Name().Stackcopy
if stackcopy != nil && (stackcopy.Class_ == ir.PPARAM || stackcopy.Class_ == ir.PPARAMOUT) {
stackcopy := n.Stackcopy
if stackcopy != nil && (stackcopy.Class == ir.PPARAM || stackcopy.Class == ir.PPARAMOUT) {
abbrev = dwarf.DW_ABRV_PARAM_LOCLIST
isReturnValue = (stackcopy.Class_ == ir.PPARAMOUT)
isReturnValue = (stackcopy.Class == ir.PPARAMOUT)
}
}
inlIndex := 0
if base.Flag.GenDwarfInl > 1 {
if n.Name().InlFormal() || n.Name().InlLocal() {
if n.InlFormal() || n.InlLocal() {
inlIndex = posInlIndex(n.Pos()) + 1
if n.Name().InlFormal() {
if n.InlFormal() {
abbrev = dwarf.DW_ABRV_PARAM_LOCLIST
}
}
Expand All @@ -240,7 +223,7 @@ func createDwarfVars(fnsym *obj.LSym, complexOK bool, fn *ir.Func, apDecls []*ir
ChildIndex: -1,
})
// Record go type of to insure that it gets emitted by the linker.
fnsym.Func().RecordAutoType(reflectdata.TypeSym(n.Type()).Linksym())
fnsym.Func().RecordAutoType(reflectdata.TypeLinksym(n.Type()))
}

return decls, vars
Expand Down Expand Up @@ -289,7 +272,7 @@ func createSimpleVar(fnsym *obj.LSym, n *ir.Name) *dwarf.Var {
var abbrev int
var offs int64

switch n.Class_ {
switch n.Class {
case ir.PAUTO:
offs = n.FrameOffset()
abbrev = dwarf.DW_ABRV_AUTO
Expand All @@ -305,25 +288,25 @@ func createSimpleVar(fnsym *obj.LSym, n *ir.Name) *dwarf.Var {
abbrev = dwarf.DW_ABRV_PARAM
offs = n.FrameOffset() + base.Ctxt.FixedFrameSize()
default:
base.Fatalf("createSimpleVar unexpected class %v for node %v", n.Class_, n)
base.Fatalf("createSimpleVar unexpected class %v for node %v", n.Class, n)
}

typename := dwarf.InfoPrefix + types.TypeSymName(n.Type())
delete(fnsym.Func().Autot, reflectdata.TypeSym(n.Type()).Linksym())
delete(fnsym.Func().Autot, reflectdata.TypeLinksym(n.Type()))
inlIndex := 0
if base.Flag.GenDwarfInl > 1 {
if n.Name().InlFormal() || n.Name().InlLocal() {
if n.InlFormal() || n.InlLocal() {
inlIndex = posInlIndex(n.Pos()) + 1
if n.Name().InlFormal() {
if n.InlFormal() {
abbrev = dwarf.DW_ABRV_PARAM
}
}
}
declpos := base.Ctxt.InnermostPos(declPos(n))
return &dwarf.Var{
Name: n.Sym().Name,
IsReturnValue: n.Class_ == ir.PPARAMOUT,
IsInlFormal: n.Name().InlFormal(),
IsReturnValue: n.Class == ir.PPARAMOUT,
IsInlFormal: n.InlFormal(),
Abbrev: abbrev,
StackOffset: int32(offs),
Type: base.Ctxt.Lookup(typename),
Expand Down Expand Up @@ -367,7 +350,7 @@ func createComplexVar(fnsym *obj.LSym, fn *ir.Func, varID ssa.VarID) *dwarf.Var
n := debug.Vars[varID]

var abbrev int
switch n.Class_ {
switch n.Class {
case ir.PAUTO:
abbrev = dwarf.DW_ABRV_AUTO_LOCLIST
case ir.PPARAM, ir.PPARAMOUT:
Expand All @@ -376,23 +359,23 @@ func createComplexVar(fnsym *obj.LSym, fn *ir.Func, varID ssa.VarID) *dwarf.Var
return nil
}

gotype := reflectdata.TypeSym(n.Type()).Linksym()
gotype := reflectdata.TypeLinksym(n.Type())
delete(fnsym.Func().Autot, gotype)
typename := dwarf.InfoPrefix + gotype.Name[len("type."):]
inlIndex := 0
if base.Flag.GenDwarfInl > 1 {
if n.Name().InlFormal() || n.Name().InlLocal() {
if n.InlFormal() || n.InlLocal() {
inlIndex = posInlIndex(n.Pos()) + 1
if n.Name().InlFormal() {
if n.InlFormal() {
abbrev = dwarf.DW_ABRV_PARAM_LOCLIST
}
}
}
declpos := base.Ctxt.InnermostPos(n.Pos())
dvar := &dwarf.Var{
Name: n.Sym().Name,
IsReturnValue: n.Class_ == ir.PPARAMOUT,
IsInlFormal: n.Name().InlFormal(),
IsReturnValue: n.Class == ir.PPARAMOUT,
IsInlFormal: n.InlFormal(),
Abbrev: abbrev,
Type: base.Ctxt.Lookup(typename),
// The stack offset is used as a sorting key, so for decomposed
Expand Down

0 comments on commit a8fe098

Please sign in to comment.