mirror of
https://github.com/golang/go.git
synced 2025-11-10 13:41:05 +00:00
cmd/compile/internal/ir: remove OrigNode
The OrigNode functionality used to be relevant to the typecheck frontend, because we wanted to report errors using the same syntax as the user originally wrote. However, now that types2 handles all spec-required error diagnostics, there's no need to preserve original nodes anymore. Change-Id: I64a0540b8952513913021e7b84d165beb1f9f801 Reviewed-on: https://go-review.googlesource.com/c/go/+/526397 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
0a49d4a778
commit
d2eab5ff19
5 changed files with 8 additions and 67 deletions
|
|
@ -5,71 +5,26 @@
|
||||||
package ir
|
package ir
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cmd/compile/internal/base"
|
|
||||||
"cmd/internal/src"
|
"cmd/internal/src"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Node may implement the Orig and SetOrig method to
|
// Orig returns n.
|
||||||
// maintain a pointer to the "unrewritten" form of a Node.
|
|
||||||
// If a Node does not implement OrigNode, it is its own Orig.
|
|
||||||
//
|
//
|
||||||
// Note that both SepCopy and Copy have definitions compatible
|
// TODO(mdempsky): Remove.
|
||||||
// with a Node that does not implement OrigNode: such a Node
|
|
||||||
// is its own Orig, and in that case, that's what both want to return
|
|
||||||
// anyway (SepCopy unconditionally, and Copy only when the input
|
|
||||||
// is its own Orig as well, but if the output does not implement
|
|
||||||
// OrigNode, then neither does the input, making the condition true).
|
|
||||||
type OrigNode interface {
|
|
||||||
Node
|
|
||||||
Orig() Node
|
|
||||||
SetOrig(Node)
|
|
||||||
}
|
|
||||||
|
|
||||||
// origNode may be embedded into a Node to make it implement OrigNode.
|
|
||||||
type origNode struct {
|
|
||||||
orig Node `mknode:"-"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *origNode) Orig() Node { return n.orig }
|
|
||||||
func (n *origNode) SetOrig(o Node) { n.orig = o }
|
|
||||||
|
|
||||||
// Orig returns the “original” node for n.
|
|
||||||
// If n implements OrigNode, Orig returns n.Orig().
|
|
||||||
// Otherwise Orig returns n itself.
|
|
||||||
func Orig(n Node) Node {
|
func Orig(n Node) Node {
|
||||||
if n, ok := n.(OrigNode); ok {
|
|
||||||
o := n.Orig()
|
|
||||||
if o == nil {
|
|
||||||
Dump("Orig nil", n)
|
|
||||||
base.Fatalf("Orig returned nil")
|
|
||||||
}
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
// SepCopy returns a separate shallow copy of n,
|
// SepCopy returns a shallow copy of n.
|
||||||
// breaking any Orig link to any other nodes.
|
//
|
||||||
|
// TODO(mdempsky): Replace with Copy.
|
||||||
func SepCopy(n Node) Node {
|
func SepCopy(n Node) Node {
|
||||||
n = n.copy()
|
return n.copy()
|
||||||
if n, ok := n.(OrigNode); ok {
|
|
||||||
n.SetOrig(n)
|
|
||||||
}
|
|
||||||
return n
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy returns a shallow copy of n.
|
// Copy returns a shallow copy of n.
|
||||||
// If Orig(n) == n, then Orig(Copy(n)) == the copy.
|
|
||||||
// Otherwise the Orig link is preserved as well.
|
|
||||||
//
|
|
||||||
// The specific semantics surrounding Orig are subtle but right for most uses.
|
|
||||||
// See issues #26855 and #27765 for pitfalls.
|
|
||||||
func Copy(n Node) Node {
|
func Copy(n Node) Node {
|
||||||
c := n.copy()
|
return n.copy()
|
||||||
if n, ok := n.(OrigNode); ok && n.Orig() == n {
|
|
||||||
c.(OrigNode).SetOrig(c)
|
|
||||||
}
|
|
||||||
return c
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy returns a “deep” copy of n, with its entire structure copied
|
// DeepCopy returns a “deep” copy of n, with its entire structure copied
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,6 @@ func (n *BinaryExpr) SetOp(op Op) {
|
||||||
// A CallExpr is a function call X(Args).
|
// A CallExpr is a function call X(Args).
|
||||||
type CallExpr struct {
|
type CallExpr struct {
|
||||||
miniExpr
|
miniExpr
|
||||||
origNode
|
|
||||||
X Node
|
X Node
|
||||||
Args Nodes
|
Args Nodes
|
||||||
RType Node `mknode:"-"` // see reflectdata/helpers.go
|
RType Node `mknode:"-"` // see reflectdata/helpers.go
|
||||||
|
|
@ -200,7 +199,6 @@ type CallExpr struct {
|
||||||
func NewCallExpr(pos src.XPos, op Op, fun Node, args []Node) *CallExpr {
|
func NewCallExpr(pos src.XPos, op Op, fun Node, args []Node) *CallExpr {
|
||||||
n := &CallExpr{X: fun}
|
n := &CallExpr{X: fun}
|
||||||
n.pos = pos
|
n.pos = pos
|
||||||
n.orig = n
|
|
||||||
n.SetOp(op)
|
n.SetOp(op)
|
||||||
n.Args = args
|
n.Args = args
|
||||||
return n
|
return n
|
||||||
|
|
@ -234,7 +232,6 @@ type ClosureExpr struct {
|
||||||
// Before type-checking, the type is Ntype.
|
// Before type-checking, the type is Ntype.
|
||||||
type CompLitExpr struct {
|
type CompLitExpr struct {
|
||||||
miniExpr
|
miniExpr
|
||||||
origNode
|
|
||||||
List Nodes // initialized values
|
List Nodes // initialized values
|
||||||
RType Node `mknode:"-"` // *runtime._type for OMAPLIT map types
|
RType Node `mknode:"-"` // *runtime._type for OMAPLIT map types
|
||||||
Prealloc *Name
|
Prealloc *Name
|
||||||
|
|
@ -251,7 +248,6 @@ func NewCompLitExpr(pos src.XPos, op Op, typ *types.Type, list []Node) *CompLitE
|
||||||
if typ != nil {
|
if typ != nil {
|
||||||
n.SetType(typ)
|
n.SetType(typ)
|
||||||
}
|
}
|
||||||
n.orig = n
|
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -373,15 +373,13 @@ func NewRangeStmt(pos src.XPos, key, value, x Node, body []Node, distinctVars bo
|
||||||
// A ReturnStmt is a return statement.
|
// A ReturnStmt is a return statement.
|
||||||
type ReturnStmt struct {
|
type ReturnStmt struct {
|
||||||
miniStmt
|
miniStmt
|
||||||
origNode // for typecheckargs rewrite
|
Results Nodes // return list
|
||||||
Results Nodes // return list
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewReturnStmt(pos src.XPos, results []Node) *ReturnStmt {
|
func NewReturnStmt(pos src.XPos, results []Node) *ReturnStmt {
|
||||||
n := &ReturnStmt{}
|
n := &ReturnStmt{}
|
||||||
n.pos = pos
|
n.pos = pos
|
||||||
n.op = ORETURN
|
n.op = ORETURN
|
||||||
n.orig = n
|
|
||||||
n.Results = results
|
n.Results = results
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -169,9 +169,6 @@ func tcCompLit(n *ir.CompLitExpr) (res ir.Node) {
|
||||||
base.Pos = lno
|
base.Pos = lno
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Save original node (including n.Right)
|
|
||||||
n.SetOrig(ir.Copy(n))
|
|
||||||
|
|
||||||
ir.SetPos(n)
|
ir.SetPos(n)
|
||||||
|
|
||||||
t := n.Type()
|
t := n.Type()
|
||||||
|
|
|
||||||
|
|
@ -624,11 +624,6 @@ func typecheckargs(n ir.InitNode) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save n as n.Orig for fmt.go.
|
|
||||||
if ir.Orig(n) == n {
|
|
||||||
n.(ir.OrigNode).SetOrig(ir.SepCopy(n))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rewrite f(g()) into t1, t2, ... = g(); f(t1, t2, ...).
|
// Rewrite f(g()) into t1, t2, ... = g(); f(t1, t2, ...).
|
||||||
RewriteMultiValueCall(n, list[0])
|
RewriteMultiValueCall(n, list[0])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue