]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/ir: prune down possible Ntype nodes
authorMatthew Dempsky <mdempsky@google.com>
Tue, 3 May 2022 19:58:54 +0000 (12:58 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 5 May 2022 18:49:04 +0000 (18:49 +0000)
Ident, ParenExpr, SelectorExpr, and StarExpr used to need to be
allowed as Ntypes for the old -G=0 type checker to represent some type
expressions before type checking, but now they're only ever used to
represent value expressions.

Change-Id: Idd4901ae6149ecc81acf1c52de3bc914d9e73418
Reviewed-on: https://go-review.googlesource.com/c/go/+/403844
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/ir/expr.go
src/cmd/compile/internal/ir/name.go
src/cmd/compile/internal/typecheck/expr.go

index 986fb29e454329a030d3dc6822935047854925bf..ffbeb20053f9baf991a08984dda2592e078e0388 100644 (file)
@@ -439,16 +439,6 @@ func NewParenExpr(pos src.XPos, x Node) *ParenExpr {
 func (n *ParenExpr) Implicit() bool     { return n.flags&miniExprImplicit != 0 }
 func (n *ParenExpr) SetImplicit(b bool) { n.flags.set(miniExprImplicit, b) }
 
-func (*ParenExpr) CanBeNtype() {}
-
-// SetOTYPE changes n to be an OTYPE node returning t,
-// like all the type nodes in type.go.
-func (n *ParenExpr) SetOTYPE(t *types.Type) {
-       n.op = OTYPE
-       n.typ = t
-       t.SetNod(n)
-}
-
 // A RawOrigExpr represents an arbitrary Go expression as a string value.
 // When printed in diagnostics, the string value is written out exactly as-is.
 type RawOrigExpr struct {
@@ -558,10 +548,6 @@ func (n *SelectorExpr) FuncName() *Name {
        return fn
 }
 
-// Before type-checking, bytes.Buffer is a SelectorExpr.
-// After type-checking it becomes a Name.
-func (*SelectorExpr) CanBeNtype() {}
-
 // A SliceExpr is a slice expression X[Low:High] or X[Low:High:Max].
 type SliceExpr struct {
        miniExpr
@@ -633,17 +619,6 @@ func NewStarExpr(pos src.XPos, x Node) *StarExpr {
 func (n *StarExpr) Implicit() bool     { return n.flags&miniExprImplicit != 0 }
 func (n *StarExpr) SetImplicit(b bool) { n.flags.set(miniExprImplicit, b) }
 
-func (*StarExpr) CanBeNtype() {}
-
-// SetOTYPE changes n to be an OTYPE node returning t,
-// like all the type nodes in type.go.
-func (n *StarExpr) SetOTYPE(t *types.Type) {
-       n.op = OTYPE
-       n.X = nil
-       n.typ = t
-       t.SetNod(n)
-}
-
 // A TypeAssertionExpr is a selector expression X.(Type).
 // Before type-checking, the type is Ntype.
 type TypeAssertExpr struct {
index 925994fe96fcebb8aba574d43659c2d09fa8b896..59269ff271cdd9ea599216d0e1dd649ee156b295 100644 (file)
@@ -31,8 +31,6 @@ func NewIdent(pos src.XPos, sym *types.Sym) *Ident {
 
 func (n *Ident) Sym() *types.Sym { return n.sym }
 
-func (*Ident) CanBeNtype() {}
-
 // Name holds Node fields used only by named nodes (ONAME, OTYPE, some OLITERAL).
 type Name struct {
        miniExpr
index ccad9bf3b86831726312097d2e90f311d68da641..b69fc2d60da3995b2b450a379b679cbca2c2cff9 100644 (file)
@@ -821,11 +821,11 @@ func tcStar(n *ir.StarExpr, top int) ir.Node {
                n.SetType(nil)
                return n
        }
+
+       // TODO(mdempsky): Remove (along with ctxType above) once I'm
+       // confident this code path isn't needed any more.
        if l.Op() == ir.OTYPE {
-               n.SetOTYPE(types.NewPtr(l.Type()))
-               // Ensure l.Type gets CalcSize'd for the backend. Issue 20174.
-               types.CheckSize(l.Type())
-               return n
+               base.Fatalf("unexpected type in deref expression: %v", l)
        }
 
        if !t.IsPtr() {