Skip to content

Commit d6d2ebb

Browse files
committed
cmd/compile/internal/ir: remove unused -G=0 node types
ir.PkgName was only used by the old -G=0 frontend for representing identifiers that refer to a package name. The new types2-based frontends directly resolve the qualified identifier to the respective object during IR construction. Similarly, most of the ir.*Type nodes were only needed for representing types in the IR prior to type checking. The new types2-based frontends directly construct the corresponding types.Type instead. Exception: The internal typecheck.DeclFunc API used for compiler-generated functions still depends on ir.FuncType, so that IR node type is retained for now. (Eventually, we should update typecheck.DeclFunc and callers to not depend on it, but it's not urgent.) Change-Id: I982f1bbd41eef5b42ce0f32676c7dc4a8ab6d0ee Reviewed-on: https://go-review.googlesource.com/c/go/+/388538 Run-TryBot: Matthew Dempsky <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Trust: Matthew Dempsky <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 0fcb948 commit d6d2ebb

File tree

14 files changed

+162
-667
lines changed

14 files changed

+162
-667
lines changed

src/cmd/compile/internal/ir/copy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func DeepCopy(pos src.XPos, n Node) Node {
7979
var edit func(Node) Node
8080
edit = func(x Node) Node {
8181
switch x.Op() {
82-
case OPACK, ONAME, ONONAME, OLITERAL, ONIL, OTYPE:
82+
case ONAME, ONONAME, OLITERAL, ONIL, OTYPE:
8383
return x
8484
}
8585
x = Copy(x)

src/cmd/compile/internal/ir/fmt.go

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ var OpPrec = []int{
202202
ONIL: 8,
203203
ONONAME: 8,
204204
OOFFSETOF: 8,
205-
OPACK: 8,
206205
OPANIC: 8,
207206
OPAREN: 8,
208207
OPRINTN: 8,
@@ -213,13 +212,7 @@ var OpPrec = []int{
213212
OSTR2BYTES: 8,
214213
OSTR2RUNES: 8,
215214
OSTRUCTLIT: 8,
216-
OTARRAY: 8,
217-
OTSLICE: 8,
218-
OTCHAN: 8,
219215
OTFUNC: 8,
220-
OTINTER: 8,
221-
OTMAP: 8,
222-
OTSTRUCT: 8,
223216
OTYPE: 8,
224217
OUNSAFEADD: 8,
225218
OUNSAFESLICE: 8,
@@ -640,7 +633,7 @@ func exprFmt(n Node, s fmt.State, prec int) {
640633
return
641634
}
642635
fallthrough
643-
case OPACK, ONONAME:
636+
case ONONAME:
644637
fmt.Fprint(s, n.Sym())
645638

646639
case OLINKSYMOFFSET:
@@ -654,49 +647,6 @@ func exprFmt(n Node, s fmt.State, prec int) {
654647
}
655648
fmt.Fprintf(s, "%v", n.Type())
656649

657-
case OTSLICE:
658-
n := n.(*SliceType)
659-
if n.DDD {
660-
fmt.Fprintf(s, "...%v", n.Elem)
661-
} else {
662-
fmt.Fprintf(s, "[]%v", n.Elem) // happens before typecheck
663-
}
664-
665-
case OTARRAY:
666-
n := n.(*ArrayType)
667-
if n.Len == nil {
668-
fmt.Fprintf(s, "[...]%v", n.Elem)
669-
} else {
670-
fmt.Fprintf(s, "[%v]%v", n.Len, n.Elem)
671-
}
672-
673-
case OTMAP:
674-
n := n.(*MapType)
675-
fmt.Fprintf(s, "map[%v]%v", n.Key, n.Elem)
676-
677-
case OTCHAN:
678-
n := n.(*ChanType)
679-
switch n.Dir {
680-
case types.Crecv:
681-
fmt.Fprintf(s, "<-chan %v", n.Elem)
682-
683-
case types.Csend:
684-
fmt.Fprintf(s, "chan<- %v", n.Elem)
685-
686-
default:
687-
if n.Elem != nil && n.Elem.Op() == OTCHAN && n.Elem.(*ChanType).Dir == types.Crecv {
688-
fmt.Fprintf(s, "chan (%v)", n.Elem)
689-
} else {
690-
fmt.Fprintf(s, "chan %v", n.Elem)
691-
}
692-
}
693-
694-
case OTSTRUCT:
695-
fmt.Fprint(s, "<struct>")
696-
697-
case OTINTER:
698-
fmt.Fprint(s, "<inter>")
699-
700650
case OTFUNC:
701651
fmt.Fprint(s, "<func>")
702652

src/cmd/compile/internal/ir/name.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ type Name struct {
4848
Opt interface{} // for use by escape analysis
4949
Embed *[]Embed // list of embedded files, for ONAME var
5050

51-
PkgName *PkgName // real package for import . names
5251
// For a local variable (not param) or extern, the initializing assignment (OAS or OAS2).
5352
// For a closure var, the ONAME node of the outer captured variable.
5453
// For the case-local variables of a type switch, the type switch guard (OTYPESW).
@@ -536,22 +535,3 @@ type Embed struct {
536535
Pos src.XPos
537536
Patterns []string
538537
}
539-
540-
// A Pack is an identifier referring to an imported package.
541-
type PkgName struct {
542-
miniNode
543-
sym *types.Sym
544-
Pkg *types.Pkg
545-
Used bool
546-
}
547-
548-
func (p *PkgName) Sym() *types.Sym { return p.sym }
549-
550-
func (*PkgName) CanBeNtype() {}
551-
552-
func NewPkgName(pos src.XPos, sym *types.Sym, pkg *types.Pkg) *PkgName {
553-
p := &PkgName{sym: sym, Pkg: pkg}
554-
p.op = OPACK
555-
p.pos = pos
556-
return p
557-
}

src/cmd/compile/internal/ir/node.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ const (
118118
// Also used for a qualified package identifier that hasn't been resolved yet.
119119
ONONAME
120120
OTYPE // type name
121-
OPACK // import
122121
OLITERAL // literal
123122
ONIL // nil
124123

@@ -291,15 +290,10 @@ const (
291290
OFUNCINST // instantiation of a generic function
292291

293292
// types
294-
OTCHAN // chan int
295-
OTMAP // map[string]int
296-
OTSTRUCT // struct{}
297-
OTINTER // interface{}
298293
// OTFUNC: func() - Recv is receiver field, Params is list of param fields, Results is
299294
// list of result fields.
295+
// TODO(mdempsky): Remove.
300296
OTFUNC
301-
OTARRAY // [8]int or [...]int
302-
OTSLICE // []int
303297

304298
// misc
305299
// intermediate representation of an inlined call. Uses Init (assignments
@@ -533,7 +527,7 @@ func HasNamedResults(fn *Func) bool {
533527
// their usage position.
534528
func HasUniquePos(n Node) bool {
535529
switch n.Op() {
536-
case ONAME, OPACK:
530+
case ONAME:
537531
return false
538532
case OLITERAL, ONIL, OTYPE:
539533
if n.Sym() != nil {

src/cmd/compile/internal/ir/node_gen.go

Lines changed: 0 additions & 123 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)