Skip to content

Commit

Permalink
cmd/compile: move Node.Typecheck to flags
Browse files Browse the repository at this point in the history
Change-Id: Id5aa4a1499068bf2d3497b21d794f970b7e47fdf
Reviewed-on: https://go-review.googlesource.com/41795
Run-TryBot: Josh Bleecher Snyder <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
josharian committed Apr 26, 2017
1 parent e2560ac commit 502a03f
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 64 deletions.
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/gc/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,8 @@ func (n *Node) jconv(s fmt.State, flag FmtFlag) {
fmt.Fprintf(s, " ld(%d)", e.Loopdepth)
}

if c == 0 && n.Typecheck != 0 {
fmt.Fprintf(s, " tc(%d)", n.Typecheck)
if c == 0 && n.Typecheck() != 0 {
fmt.Fprintf(s, " tc(%d)", n.Typecheck())
}

if n.Isddd() {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/gc/gsubr.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func nodarg(t interface{}, fp int) *Node {
}
}

n.Typecheck = 1
n.SetTypecheck(1)
n.SetAddrtaken(true) // keep optimizers at bay
return n
}
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/compile/internal/gc/inl.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func caninl(fn *Node) {
return
}

if fn.Typecheck == 0 {
if fn.Typecheck() == 0 {
Fatalf("caninl on non-typechecked function %v", fn)
}

Expand Down Expand Up @@ -478,7 +478,7 @@ func inlnode(n *Node) *Node {
if n.Op == OAS2FUNC && n.Rlist.First().Op == OINLCALL {
n.Rlist.Set(inlconv2list(n.Rlist.First()))
n.Op = OAS2
n.Typecheck = 0
n.SetTypecheck(0)
n = typecheck(n, Etop)
} else {
s := n.Rlist.Slice()
Expand Down Expand Up @@ -757,7 +757,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
call.Nbody.Set(body)
call.Rlist.Set(retvars)
call.Type = n.Type
call.Typecheck = 1
call.SetTypecheck(1)

// Hide the args from setPos -- the parameters to the inlined
// call already have good line numbers that should be preserved.
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/gc/racewalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ func appendinit(np **Node, init Nodes) {
n = nod(OCONVNOP, n, nil)

n.Type = n.Left.Type
n.Typecheck = 1
n.SetTypecheck(1)
*np = n
}

Expand Down
12 changes: 6 additions & 6 deletions src/cmd/compile/internal/gc/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ func typecheckrange(n *Node) {

// second half of dance
out:
n.Typecheck = 1
n.SetTypecheck(1)
ls = n.List.Slice()
for i1, n1 := range ls {
if n1.Typecheck == 0 {
if n1.Typecheck() == 0 {
ls[i1] = typecheck(ls[i1], Erv|Easgn)
}
}
Expand Down Expand Up @@ -231,9 +231,9 @@ func walkrange(n *Node) *Node {
tmp := nod(OADD, hp, nodintconst(t.Elem().Width))

tmp.Type = hp.Type
tmp.Typecheck = 1
tmp.SetTypecheck(1)
tmp.Right.Type = types.Types[types.Tptr]
tmp.Right.Typecheck = 1
tmp.Right.SetTypecheck(1)
a = nod(OAS, hp, tmp)
a = typecheck(a, Etop)
n.Right.Ninit.Set1(a)
Expand Down Expand Up @@ -283,15 +283,15 @@ func walkrange(n *Node) *Node {
n.Left = nil

hv1 := temp(t.Elem())
hv1.Typecheck = 1
hv1.SetTypecheck(1)
if types.Haspointers(t.Elem()) {
init = append(init, nod(OAS, hv1, nil))
}
hb := temp(types.Types[TBOOL])

n.Left = nod(ONE, hb, nodbool(false))
a := nod(OAS2RECV, nil, nil)
a.Typecheck = 1
a.SetTypecheck(1)
a.List.Set2(hv1, hb)
a.Rlist.Set1(nod(ORECV, ha, nil))
n.Left.Ninit.Set1(a)
Expand Down
12 changes: 6 additions & 6 deletions src/cmd/compile/internal/gc/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,14 +945,14 @@ func typename(t *types.Type) *Node {
n := newnamel(src.NoXPos, s)
n.Type = types.Types[TUINT8]
n.Class = PEXTERN
n.Typecheck = 1
n.SetTypecheck(1)
s.Def = asTypesNode(n)
}

n := nod(OADDR, asNode(s.Def), nil)
n.Type = types.NewPtr(asNode(s.Def).Type)
n.SetAddable(true)
n.Typecheck = 1
n.SetTypecheck(1)
return n
}

Expand All @@ -965,15 +965,15 @@ func itabname(t, itype *types.Type) *Node {
n := newname(s)
n.Type = types.Types[TUINT8]
n.Class = PEXTERN
n.Typecheck = 1
n.SetTypecheck(1)
s.Def = asTypesNode(n)
itabs = append(itabs, itabEntry{t: t, itype: itype, lsym: s.Linksym()})
}

n := nod(OADDR, asNode(s.Def), nil)
n.Type = types.NewPtr(asNode(s.Def).Type)
n.SetAddable(true)
n.Typecheck = 1
n.SetTypecheck(1)
return n
}

Expand Down Expand Up @@ -1822,12 +1822,12 @@ func zeroaddr(size int64) *Node {
x := newname(s)
x.Type = types.Types[TUINT8]
x.Class = PEXTERN
x.Typecheck = 1
x.SetTypecheck(1)
s.Def = asTypesNode(x)
}
z := nod(OADDR, asNode(s.Def), nil)
z.Type = types.NewPtr(types.Types[TUINT8])
z.SetAddable(true)
z.Typecheck = 1
z.SetTypecheck(1)
return z
}
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/gc/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func typecheckselect(sel *Node) {
case ORECV:
n = nod(OSELRECV, nil, n)

n.Typecheck = 1
n.SetTypecheck(1)
ncase.Left = n

case OSEND:
Expand Down Expand Up @@ -150,7 +150,7 @@ func walkselect(sel *Node) {
n.Rlist.Set1(n.Right)
n.Right = nil
n.Left = nil
n.Typecheck = 0
n.SetTypecheck(0)
n = typecheck(n, Etop)
}

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/gc/sinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ func anylit(n *Node, var_ *Node, init *Nodes) {
r = typecheck(r, Erv)
} else {
r = nod(ONEW, nil, nil)
r.Typecheck = 1
r.SetTypecheck(1)
r.Type = t
r.Esc = n.Esc
}
Expand Down
16 changes: 8 additions & 8 deletions src/cmd/compile/internal/gc/subr.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ func assignconvfn(n *Node, t *types.Type, context func() string) *Node {
if n.Op == ONAME || n.Op == OLITERAL {
r := nod(OCONVNOP, n, nil)
r.Type = types.Types[TBOOL]
r.Typecheck = 1
r.SetTypecheck(1)
r.SetImplicit(true)
n = r
}
Expand All @@ -986,7 +986,7 @@ func assignconvfn(n *Node, t *types.Type, context func() string) *Node {

r := nod(op, n, nil)
r.Type = t
r.Typecheck = 1
r.SetTypecheck(1)
r.SetImplicit(true)
r.Orig = n.Orig
return r
Expand Down Expand Up @@ -1965,7 +1965,7 @@ func addinit(n *Node, init []*Node) *Node {
// Introduce OCONVNOP to hold init list.
n = nod(OCONVNOP, n, nil)
n.Type = n.Left.Type
n.Typecheck = 1
n.SetTypecheck(1)
}

n.Ninit.Prepend(init...)
Expand Down Expand Up @@ -2029,7 +2029,7 @@ func checknil(x *Node, init *Nodes) {
}

n := nod(OCHECKNIL, x, nil)
n.Typecheck = 1
n.SetTypecheck(1)
init.Append(n)
}

Expand Down Expand Up @@ -2061,7 +2061,7 @@ func isdirectiface(t *types.Type) bool {
func itabType(itab *Node) *Node {
typ := nodSym(ODOTPTR, itab, nil)
typ.Type = types.NewPtr(types.Types[TUINT8])
typ.Typecheck = 1
typ.SetTypecheck(1)
typ.Xoffset = int64(Widthptr) // offset of _type in runtime.itab
typ.SetBounded(true) // guaranteed not to fault
return typ
Expand All @@ -2074,14 +2074,14 @@ func ifaceData(n *Node, t *types.Type) *Node {
ptr := nodSym(OIDATA, n, nil)
if isdirectiface(t) {
ptr.Type = t
ptr.Typecheck = 1
ptr.SetTypecheck(1)
return ptr
}
ptr.Type = types.NewPtr(t)
ptr.SetBounded(true)
ptr.Typecheck = 1
ptr.SetTypecheck(1)
ind := nod(OIND, ptr, nil)
ind.Type = t
ind.Typecheck = 1
ind.SetTypecheck(1)
return ind
}
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/gc/swt.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ func (s *typeSwitch) walk(sw *Node) {
// Load hash from type or itab.
h := nodSym(ODOTPTR, itab, nil)
h.Type = types.Types[TUINT32]
h.Typecheck = 1
h.SetTypecheck(1)
if cond.Right.Type.IsEmptyInterface() {
h.Xoffset = int64(2 * Widthptr) // offset of hash in runtime._type
} else {
Expand Down
11 changes: 7 additions & 4 deletions src/cmd/compile/internal/gc/syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ type Node struct {

Esc uint16 // EscXXX

Op Op
Etype types.EType // op for OASOP, etype for OTYPE, exclam for export, 6g saved reg, ChanDir for OTCHAN, for OINDEXMAP 1=LHS,0=RHS
Class Class // PPARAM, PAUTO, PEXTERN, etc
Typecheck uint8 // tracks state during typechecking; 2 == loop detected
Op Op
Etype types.EType // op for OASOP, etype for OTYPE, exclam for export, 6g saved reg, ChanDir for OTCHAN, for OINDEXMAP 1=LHS,0=RHS
Class Class // PPARAM, PAUTO, PEXTERN, etc
}

// IsAutoTmp indicates if n was created by the compiler as a temporary,
Expand All @@ -73,6 +72,8 @@ func (n *Node) IsAutoTmp() bool {
const (
nodeWalkdef, _ = iota, 1 << iota // tracks state during typecheckdef; 2 == loop detected; two bits
_, _ // second nodeWalkdef bit
nodeTypecheck, _ // tracks state during typechecking; 2 == loop detected; two bits
_, _ // second nodeTypecheck bit
nodeInitorder, _ // tracks state during init1; two bits
_, _ // second nodeInitorder bit
_, nodeHasBreak
Expand All @@ -99,6 +100,7 @@ const (
)

func (n *Node) Walkdef() uint8 { return n.flags.get2(nodeWalkdef) }
func (n *Node) Typecheck() uint8 { return n.flags.get2(nodeTypecheck) }
func (n *Node) Initorder() uint8 { return n.flags.get2(nodeInitorder) }

func (n *Node) HasBreak() bool { return n.flags&nodeHasBreak != 0 }
Expand All @@ -124,6 +126,7 @@ func (n *Node) HasOpt() bool { return n.flags&nodeHasOpt != 0 }
func (n *Node) Embedded() bool { return n.flags&nodeEmbedded != 0 }

func (n *Node) SetWalkdef(b uint8) { n.flags.set2(nodeWalkdef, b) }
func (n *Node) SetTypecheck(b uint8) { n.flags.set2(nodeTypecheck, b) }
func (n *Node) SetInitorder(b uint8) { n.flags.set2(nodeInitorder, b) }

func (n *Node) SetHasBreak(b bool) { n.flags.set(nodeHasBreak, b) }
Expand Down
26 changes: 13 additions & 13 deletions src/cmd/compile/internal/gc/typecheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func typecheck(n *Node, top int) *Node {

// Skip typecheck if already done.
// But re-typecheck ONAME/OTYPE/OLITERAL/OPACK node in case context has changed.
if n.Typecheck == 1 {
if n.Typecheck() == 1 {
switch n.Op {
case ONAME, OTYPE, OLITERAL, OPACK:
break
Expand All @@ -155,7 +155,7 @@ func typecheck(n *Node, top int) *Node {
}
}

if n.Typecheck == 2 {
if n.Typecheck() == 2 {
// Typechecking loop. Trying printing a meaningful message,
// otherwise a stack trace of typechecking.
switch n.Op {
Expand Down Expand Up @@ -195,12 +195,12 @@ func typecheck(n *Node, top int) *Node {
return n
}

n.Typecheck = 2
n.SetTypecheck(2)

typecheck_tcstack = append(typecheck_tcstack, n)
n = typecheck1(n, top)

n.Typecheck = 1
n.SetTypecheck(1)

last := len(typecheck_tcstack) - 1
typecheck_tcstack[last] = nil
Expand Down Expand Up @@ -633,7 +633,7 @@ OpSwitch:
if r.Type.IsInterface() == l.Type.IsInterface() || l.Type.Width >= 1<<16 {
l = nod(aop, l, nil)
l.Type = r.Type
l.Typecheck = 1
l.SetTypecheck(1)
n.Left = l
}

Expand All @@ -655,7 +655,7 @@ OpSwitch:
if r.Type.IsInterface() == l.Type.IsInterface() || r.Type.Width >= 1<<16 {
r = nod(aop, r, nil)
r.Type = l.Type
r.Typecheck = 1
r.SetTypecheck(1)
n.Right = r
}

Expand Down Expand Up @@ -3149,10 +3149,10 @@ func typecheckcomplit(n *Node) *Node {
n.Orig = norig
if n.Type.IsPtr() {
n = nod(OPTRLIT, n, nil)
n.Typecheck = 1
n.SetTypecheck(1)
n.Type = n.Left.Type
n.Left.Type = t
n.Left.Typecheck = 1
n.Left.SetTypecheck(1)
}

n.Orig = norig
Expand Down Expand Up @@ -3302,9 +3302,9 @@ func typecheckas(n *Node) {
// second half of dance.
// now that right is done, typecheck the left
// just to get it over with. see dance above.
n.Typecheck = 1
n.SetTypecheck(1)

if n.Left.Typecheck == 0 {
if n.Left.Typecheck() == 0 {
n.Left = typecheck(n.Left, Erv|Easgn)
}
}
Expand Down Expand Up @@ -3431,10 +3431,10 @@ mismatch:

// second half of dance
out:
n.Typecheck = 1
n.SetTypecheck(1)
ls = n.List.Slice()
for i1, n1 := range ls {
if n1.Typecheck == 0 {
if n1.Typecheck() == 0 {
ls[i1] = typecheck(ls[i1], Erv|Easgn)
}
}
Expand Down Expand Up @@ -3571,7 +3571,7 @@ func typecheckdeftype(n *Node) {
lno := lineno
setlineno(n)
n.Type.Sym = n.Sym
n.Typecheck = 1
n.SetTypecheck(1)
n.Name.Param.Ntype = typecheck(n.Name.Param.Ntype, Etype)
t := n.Name.Param.Ntype.Type
if t == nil {
Expand Down
Loading

0 comments on commit 502a03f

Please sign in to comment.