]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile/internal/ir: add typ parameter to NewNameAt
authorMatthew Dempsky <mdempsky@google.com>
Thu, 17 Aug 2023 00:23:52 +0000 (17:23 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 17 Aug 2023 19:36:24 +0000 (19:36 +0000)
Start making progress towards constructing IR with proper types.

Change-Id: Iad32c1cf60f30ceb8e07c31c8871b115570ac3bd
Reviewed-on: https://go-review.googlesource.com/c/go/+/520263
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
20 files changed:
src/cmd/compile/internal/inline/inl.go
src/cmd/compile/internal/ir/expr.go
src/cmd/compile/internal/ir/func.go
src/cmd/compile/internal/ir/name.go
src/cmd/compile/internal/ir/node.go
src/cmd/compile/internal/noder/reader.go
src/cmd/compile/internal/noder/unified.go
src/cmd/compile/internal/pkginit/init.go
src/cmd/compile/internal/pkginit/initAsanGlobals.go
src/cmd/compile/internal/ssa/export_test.go
src/cmd/compile/internal/ssagen/ssa.go
src/cmd/compile/internal/staticdata/data.go
src/cmd/compile/internal/staticinit/sched.go
src/cmd/compile/internal/test/abiutilsaux_test.go
src/cmd/compile/internal/typecheck/dcl.go
src/cmd/compile/internal/typecheck/subr.go
src/cmd/compile/internal/typecheck/syms.go
src/cmd/compile/internal/typecheck/universe.go
src/cmd/compile/internal/walk/closure.go
src/cmd/compile/internal/walk/switch.go

index 078fba594dd0b3cd406dbec90646faea6c0e2413..908d6ca347ca84375d438770d6eabd31784d8f04 100644 (file)
@@ -820,9 +820,8 @@ func inlcopy(n ir.Node) ir.Node {
                        oldfn := x.Func
                        newfn := ir.NewFunc(oldfn.Pos())
                        m.(*ir.ClosureExpr).Func = newfn
-                       newfn.Nname = ir.NewNameAt(oldfn.Nname.Pos(), oldfn.Nname.Sym())
+                       newfn.Nname = ir.NewNameAt(oldfn.Nname.Pos(), oldfn.Nname.Sym(), oldfn.Nname.Type())
                        // XXX OK to share fn.Type() ??
-                       newfn.Nname.SetType(oldfn.Nname.Type())
                        newfn.Body = inlcopylist(oldfn.Body)
                        // Make shallow copy of the Dcl and ClosureVar slices
                        newfn.Dcl = append([]*ir.Name(nil), oldfn.Dcl...)
index 0f44bd8e2133599ba1944fa777befaec0091c56b..69edd1c3cf8d1b890c6c703e27660d3eef6bc90d 100644 (file)
@@ -557,9 +557,8 @@ func (n *SelectorExpr) FuncName() *Name {
        if n.Op() != OMETHEXPR {
                panic(n.no("FuncName"))
        }
-       fn := NewNameAt(n.Selection.Pos, MethodSym(n.X.Type(), n.Sel))
+       fn := NewNameAt(n.Selection.Pos, MethodSym(n.X.Type(), n.Sel), n.Type())
        fn.Class = PFUNC
-       fn.SetType(n.Type())
        if n.Selection.Nname != nil {
                // TODO(austin): Nname is nil for interface method
                // expressions (I.M), so we can't attach a Func to
index b0b4d52fa3f60f34494bc972b0fd09f3341a365b..fa45ccb2dfd19aaf3f08cf1f52b0121d1d98fa8f 100644 (file)
@@ -398,7 +398,7 @@ func NewClosureFunc(pos src.XPos, hidden bool) *Func {
        fn := NewFunc(pos)
        fn.SetIsHiddenClosure(hidden)
 
-       fn.Nname = NewNameAt(pos, BlankNode.Sym())
+       fn.Nname = NewNameAt(pos, BlankNode.Sym(), nil)
        fn.Nname.Func = fn
        fn.Nname.Defn = fn
 
index 0f565833d2e2ef64626d79381100bf097700b83f..4489e7cc1faf633ef62f491802bdf965c7cb5b05 100644 (file)
@@ -147,11 +147,42 @@ func (n *Name) RecordFrameOffset(offset int64) {
 
 // NewNameAt returns a new ONAME Node associated with symbol s at position pos.
 // The caller is responsible for setting Curfn.
-func NewNameAt(pos src.XPos, sym *types.Sym) *Name {
+func NewNameAt(pos src.XPos, sym *types.Sym, typ *types.Type) *Name {
        if sym == nil {
                base.Fatalf("NewNameAt nil")
        }
-       return newNameAt(pos, ONAME, sym)
+       n := newNameAt(pos, ONAME, sym)
+       if typ != nil {
+               n.SetType(typ)
+               n.SetTypecheck(1)
+       }
+       return n
+}
+
+// NewBuiltin returns a new Name representing a builtin function,
+// either predeclared or from package unsafe.
+func NewBuiltin(sym *types.Sym, op Op) *Name {
+       n := newNameAt(src.NoXPos, ONAME, sym)
+       n.BuiltinOp = op
+       n.SetTypecheck(1)
+       sym.Def = n
+       return n
+}
+
+// NewLocal returns a new function-local variable with the given name and type.
+func (fn *Func) NewLocal(pos src.XPos, sym *types.Sym, class Class, typ *types.Type) *Name {
+       switch class {
+       case PPARAM, PPARAMOUT, PAUTO:
+               // ok
+       default:
+               base.FatalfAt(pos, "NewLocal: unexpected class for %v: %v", sym, class)
+       }
+
+       n := NewNameAt(pos, sym, typ)
+       n.Class = class
+       n.Curfn = fn
+       fn.Dcl = append(fn.Dcl, n)
+       return n
 }
 
 // NewDeclNameAt returns a new Name associated with symbol s at position pos.
@@ -345,16 +376,13 @@ func NewClosureVar(pos src.XPos, fn *Func, n *Name) *Name {
                base.Fatalf("NewClosureVar: %+v", n)
        }
 
-       c := NewNameAt(pos, n.Sym())
+       c := NewNameAt(pos, n.Sym(), n.Type())
        c.Curfn = fn
        c.Class = PAUTOHEAP
        c.SetIsClosureVar(true)
        c.Defn = n.Canonical()
        c.Outer = n
 
-       c.SetType(n.Type())
-       c.SetTypecheck(n.Typecheck())
-
        fn.ClosureVars = append(fn.ClosureVars, c)
 
        return c
@@ -371,9 +399,8 @@ func NewHiddenParam(pos src.XPos, fn *Func, sym *types.Sym, typ *types.Type) *Na
 
        // Create a fake parameter, disassociated from any real function, to
        // pretend to capture.
-       fake := NewNameAt(pos, sym)
+       fake := NewNameAt(pos, sym, typ)
        fake.Class = PPARAM
-       fake.SetType(typ)
        fake.SetByval(true)
 
        return NewClosureVar(pos, fn, fake)
index a6a47663361baf7a80f32c06a93cc84d9aa5ab01..4ba560bba7b9aba9de45a0b5b77674e2b3569b3d 100644 (file)
@@ -470,7 +470,7 @@ func AsNode(n types.Object) Node {
        return n.(Node)
 }
 
-var BlankNode Node
+var BlankNode *Name
 
 func IsConst(n Node, ct constant.Kind) bool {
        return ConstType(n) == ct
index 42794da042a6a460cc66cf6f9b68f5ec6aaebe37..c51963e1c270f97ae4bb9147c6ea577d92c2a626 100644 (file)
@@ -995,8 +995,7 @@ func (r *reader) method(rext *reader) *types.Field {
        _, recv := r.param()
        typ := r.signature(recv)
 
-       name := ir.NewNameAt(pos, ir.MethodSym(recv.Type, sym))
-       setType(name, typ)
+       name := ir.NewNameAt(pos, ir.MethodSym(recv.Type, sym), typ)
 
        name.Func = ir.NewFunc(r.pos())
        name.Func.Nname = name
@@ -1386,7 +1385,7 @@ func (pr *pkgReader) dictNameOf(dict *readerDict) *ir.Name {
                return sym.Def.(*ir.Name)
        }
 
-       name := ir.NewNameAt(pos, sym)
+       name := ir.NewNameAt(pos, sym, dict.varType())
        name.Class = ir.PEXTERN
        sym.Def = name // break cycles with mutual subdictionaries
 
@@ -1453,9 +1452,6 @@ func (pr *pkgReader) dictNameOf(dict *readerDict) *ir.Name {
 
        objw.Global(lsym, int32(ot), obj.DUPOK|obj.RODATA)
 
-       name.SetType(dict.varType())
-       name.SetTypecheck(1)
-
        return name
 }
 
@@ -1530,9 +1526,7 @@ func (r *reader) funcarg(param *types.Field, sym *types.Sym, ctxt ir.Class) {
                return
        }
 
-       name := ir.NewNameAt(r.inlPos(param.Pos), sym)
-       setType(name, param.Type)
-       r.addLocal(name, ctxt)
+       name := r.addLocal(r.inlPos(param.Pos), sym, ctxt, param.Type)
 
        if r.inlCall == nil {
                if !r.funarghack {
@@ -1548,9 +1542,11 @@ func (r *reader) funcarg(param *types.Field, sym *types.Sym, ctxt ir.Class) {
        }
 }
 
-func (r *reader) addLocal(name *ir.Name, ctxt ir.Class) {
+func (r *reader) addLocal(pos src.XPos, sym *types.Sym, ctxt ir.Class, typ *types.Type) *ir.Name {
        assert(ctxt == ir.PAUTO || ctxt == ir.PPARAM || ctxt == ir.PPARAMOUT)
 
+       name := ir.NewNameAt(pos, sym, typ)
+
        if name.Sym().Name == dictParamName {
                r.dictParam = name
        } else {
@@ -1572,7 +1568,7 @@ func (r *reader) addLocal(name *ir.Name, ctxt ir.Class) {
 
        // TODO(mdempsky): Move earlier.
        if ir.IsBlank(name) {
-               return
+               return name
        }
 
        if r.inlCall != nil {
@@ -1592,6 +1588,8 @@ func (r *reader) addLocal(name *ir.Name, ctxt ir.Class) {
        if ctxt == ir.PAUTO {
                name.SetFrameOffset(0)
        }
+
+       return name
 }
 
 func (r *reader) useLocal() *ir.Name {
@@ -1836,9 +1834,7 @@ func (r *reader) assign() (ir.Node, bool) {
                _, sym := r.localIdent()
                typ := r.typ()
 
-               name := ir.NewNameAt(pos, sym)
-               setType(name, typ)
-               r.addLocal(name, ir.PAUTO)
+               name := r.addLocal(pos, sym, ir.PAUTO, typ)
                return name, true
 
        case assignExpr:
@@ -2064,9 +2060,7 @@ func (r *reader) switchStmt(label *types.Sym) ir.Node {
                        pos := r.pos()
                        typ := r.typ()
 
-                       name := ir.NewNameAt(pos, ident.Sym())
-                       setType(name, typ)
-                       r.addLocal(name, ir.PAUTO)
+                       name := r.addLocal(pos, ident.Sym(), ir.PAUTO, typ)
                        clause.Var = name
                        name.Defn = tag
                }
@@ -3468,11 +3462,10 @@ func unifiedInlineCall(call *ir.CallExpr, fn *ir.Func, inlIndex int) *ir.Inlined
 
        // TODO(mdempsky): This still feels clumsy. Can we do better?
        tmpfn := ir.NewFunc(fn.Pos())
-       tmpfn.Nname = ir.NewNameAt(fn.Nname.Pos(), callerfn.Sym())
+       tmpfn.Nname = ir.NewNameAt(fn.Nname.Pos(), callerfn.Sym(), fn.Type())
        tmpfn.Closgen = callerfn.Closgen
        defer func() { callerfn.Closgen = tmpfn.Closgen }()
 
-       setType(tmpfn.Nname, fn.Type())
        r.curfn = tmpfn
 
        r.inlCaller = callerfn
@@ -3644,12 +3637,11 @@ func expandInline(fn *ir.Func, pri pkgReaderIndex) {
        topdcls := len(typecheck.Target.Funcs)
 
        tmpfn := ir.NewFunc(fn.Pos())
-       tmpfn.Nname = ir.NewNameAt(fn.Nname.Pos(), fn.Sym())
+       tmpfn.Nname = ir.NewNameAt(fn.Nname.Pos(), fn.Sym(), fn.Type())
        tmpfn.ClosureVars = fn.ClosureVars
 
        {
                r := pri.asReader(pkgbits.RelocBody, pkgbits.SyncFuncBody)
-               setType(tmpfn.Nname, fn.Type())
 
                // Don't change parameter's Sym/Nname fields.
                r.funarghack = true
@@ -3879,29 +3871,23 @@ func wrapMethodValue(recvType *types.Type, method *types.Field, target *ir.Packa
 }
 
 func newWrapperFunc(pos src.XPos, sym *types.Sym, wrapper *types.Type, method *types.Field) *ir.Func {
+       sig := newWrapperType(wrapper, method)
+
        fn := ir.NewFunc(pos)
        fn.SetDupok(true) // TODO(mdempsky): Leave unset for local, non-generic wrappers?
 
-       name := ir.NewNameAt(pos, sym)
+       name := ir.NewNameAt(pos, sym, sig)
        ir.MarkFunc(name)
        name.Func = fn
        name.Defn = fn
        fn.Nname = name
 
-       sig := newWrapperType(wrapper, method)
        setType(name, sig)
 
        // TODO(mdempsky): De-duplicate with similar logic in funcargs.
        defParams := func(class ir.Class, params *types.Type) {
                for _, param := range params.FieldSlice() {
-                       name := ir.NewNameAt(param.Pos, param.Sym)
-                       name.Class = class
-                       setType(name, param.Type)
-
-                       name.Curfn = fn
-                       fn.Dcl = append(fn.Dcl, name)
-
-                       param.Nname = name
+                       param.Nname = fn.NewLocal(param.Pos, param.Sym, class, param.Type)
                }
        }
 
index 3e5ab2ec39664c1161e93c1b7163a49865440f6f..25c7b77831f08b7f0772cb603e4f109768ccec42 100644 (file)
@@ -319,7 +319,7 @@ func readPackage(pr *pkgReader, importpkg *types.Pkg, localStub bool) {
 
                if r.Bool() {
                        sym := importpkg.Lookup(".inittask")
-                       task := ir.NewNameAt(src.NoXPos, sym)
+                       task := ir.NewNameAt(src.NoXPos, sym, nil)
                        task.Class = ir.PEXTERN
                        sym.Def = task
                }
index 95e3b5cee3ffec5390f5b59b49103574a3713255..48c6b03527891400214f2623e15c917b2dcdde23 100644 (file)
@@ -132,12 +132,12 @@ func MakeTask() {
 
                        // Call runtime.asanregisterglobals function to poison redzones.
                        // runtime.asanregisterglobals(unsafe.Pointer(&globals[0]), ni)
-                       asanf := typecheck.NewName(ir.Pkgs.Runtime.Lookup("asanregisterglobals"))
+                       asanf := ir.NewNameAt(base.Pos, ir.Pkgs.Runtime.Lookup("asanregisterglobals"),
+                               types.NewSignature(nil, []*types.Field{
+                                       types.NewField(base.Pos, nil, types.Types[types.TUNSAFEPTR]),
+                                       types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
+                               }, nil))
                        ir.MarkFunc(asanf)
-                       asanf.SetType(types.NewSignature(nil, []*types.Field{
-                               types.NewField(base.Pos, nil, types.Types[types.TUNSAFEPTR]),
-                               types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
-                       }, nil))
                        asancall := ir.NewCallExpr(base.Pos, ir.OCALL, asanf, nil)
                        asancall.Args.Append(typecheck.ConvNop(typecheck.NodAddr(
                                ir.NewIndexExpr(base.Pos, globals, ir.NewInt(base.Pos, 0))), types.Types[types.TUNSAFEPTR]))
@@ -193,8 +193,7 @@ func MakeTask() {
 
        // Make an .inittask structure.
        sym := typecheck.Lookup(".inittask")
-       task := typecheck.NewName(sym)
-       task.SetType(types.Types[types.TUINT8]) // fake type
+       task := ir.NewNameAt(base.Pos, sym, types.Types[types.TUINT8]) // fake type
        task.Class = ir.PEXTERN
        sym.Def = task
        lsym := task.Linksym()
index ce26cbf1899152d2b08399c51ce55916f11de190..42db0eaf1bbd2abdab11aec6849e749823fbd62c 100644 (file)
@@ -23,8 +23,7 @@ func instrumentGlobals(fn *ir.Func) *ir.Name {
        // var asanglobals []asanGlobalStruct
        arraytype := types.NewArray(asanGlobalStruct, int64(len(InstrumentGlobalsMap)))
        symG := lname(".asanglobals")
-       globals := typecheck.NewName(symG)
-       globals.SetType(arraytype)
+       globals := ir.NewNameAt(base.Pos, symG, arraytype)
        globals.Class = ir.PEXTERN
        symG.Def = globals
        typecheck.Target.Externs = append(typecheck.Target.Externs, globals)
@@ -32,8 +31,7 @@ func instrumentGlobals(fn *ir.Func) *ir.Name {
        // var asanL []asanLocationStruct
        arraytype = types.NewArray(asanLocationStruct, int64(len(InstrumentGlobalsMap)))
        symL := lname(".asanL")
-       asanlocation := typecheck.NewName(symL)
-       asanlocation.SetType(arraytype)
+       asanlocation := ir.NewNameAt(base.Pos, symL, arraytype)
        asanlocation.Class = ir.PEXTERN
        symL.Def = asanlocation
        typecheck.Target.Externs = append(typecheck.Target.Externs, asanlocation)
@@ -43,22 +41,19 @@ func instrumentGlobals(fn *ir.Func) *ir.Name {
        // var asanModulename string
        // var asanFilename string
        symL = lname(".asanName")
-       asanName := typecheck.NewName(symL)
-       asanName.SetType(types.Types[types.TSTRING])
+       asanName := ir.NewNameAt(base.Pos, symL, types.Types[types.TSTRING])
        asanName.Class = ir.PEXTERN
        symL.Def = asanName
        typecheck.Target.Externs = append(typecheck.Target.Externs, asanName)
 
        symL = lname(".asanModulename")
-       asanModulename := typecheck.NewName(symL)
-       asanModulename.SetType(types.Types[types.TSTRING])
+       asanModulename := ir.NewNameAt(base.Pos, symL, types.Types[types.TSTRING])
        asanModulename.Class = ir.PEXTERN
        symL.Def = asanModulename
        typecheck.Target.Externs = append(typecheck.Target.Externs, asanModulename)
 
        symL = lname(".asanFilename")
-       asanFilename := typecheck.NewName(symL)
-       asanFilename.SetType(types.Types[types.TSTRING])
+       asanFilename := ir.NewNameAt(base.Pos, symL, types.Types[types.TSTRING])
        asanFilename.Class = ir.PEXTERN
        symL.Def = asanFilename
        typecheck.Target.Externs = append(typecheck.Target.Externs, asanFilename)
index 14f2474a111a3025b7155e2ee50f629de28e8f3f..53a5b3070bb99f4b1d58b850cab93d265823b8e9 100644 (file)
@@ -59,7 +59,7 @@ func (c *Conf) Frontend() Frontend {
                f.Nname = ir.NewNameAt(f.Pos(), &types.Sym{
                        Pkg:  types.NewPkg("my/import/path", "path"),
                        Name: "function",
-               })
+               }, nil)
                f.LSym = &obj.LSym{Name: "my/import/path.function"}
 
                c.fe = TestFrontend{
@@ -83,8 +83,7 @@ func (TestFrontend) StringData(s string) *obj.LSym {
        return nil
 }
 func (TestFrontend) Auto(pos src.XPos, t *types.Type) *ir.Name {
-       n := ir.NewNameAt(pos, &types.Sym{Name: "aFakeAuto"})
-       n.SetType(t)
+       n := ir.NewNameAt(pos, &types.Sym{Name: "aFakeAuto"}, t)
        n.Class = ir.PAUTO
        return n
 }
index 64101a28dc294987f06585cd2c33aac676e49e1b..25e93b531d55ebe649192633404fc57a2d13c758 100644 (file)
@@ -675,12 +675,9 @@ func (s *state) setHeapaddr(pos src.XPos, n *ir.Name, ptr *ssa.Value) {
        }
 
        // Declare variable to hold address.
-       addr := ir.NewNameAt(pos, &types.Sym{Name: "&" + n.Sym().Name, Pkg: types.LocalPkg})
-       addr.SetType(types.NewPtr(n.Type()))
-       addr.Class = ir.PAUTO
+       sym := &types.Sym{Name: "&" + n.Sym().Name, Pkg: types.LocalPkg}
+       addr := s.curfn.NewLocal(pos, sym, ir.PAUTO, types.NewPtr(n.Type()))
        addr.SetUsed(true)
-       addr.Curfn = s.curfn
-       s.curfn.Dcl = append(s.curfn.Dcl, addr)
        types.CalcSize(addr.Type())
 
        if n.Class == ir.PPARAMOUT {
@@ -939,7 +936,7 @@ func (s *state) Warnl(pos src.XPos, msg string, args ...interface{}) { s.f.Warnl
 func (s *state) Debug_checknil() bool                                { return s.f.Frontend().Debug_checknil() }
 
 func ssaMarker(name string) *ir.Name {
-       return typecheck.NewName(&types.Sym{Name: name})
+       return ir.NewNameAt(base.Pos, &types.Sym{Name: name}, nil)
 }
 
 var (
@@ -7976,15 +7973,10 @@ func (e *ssafn) SplitSlot(parent *ssa.LocalSlot, suffix string, offset int64, t
                return ssa.LocalSlot{N: node, Type: t, Off: parent.Off + offset}
        }
 
-       s := &types.Sym{Name: node.Sym().Name + suffix, Pkg: types.LocalPkg}
-       n := ir.NewNameAt(parent.N.Pos(), s)
-       s.Def = n
-       ir.AsNode(s.Def).Name().SetUsed(true)
-       n.SetType(t)
-       n.Class = ir.PAUTO
+       sym := &types.Sym{Name: node.Sym().Name + suffix, Pkg: types.LocalPkg}
+       n := e.curfn.NewLocal(parent.N.Pos(), sym, ir.PAUTO, t)
+       n.SetUsed(true)
        n.SetEsc(ir.EscNever)
-       n.Curfn = e.curfn
-       e.curfn.Dcl = append(e.curfn.Dcl, n)
        types.CalcSize(t)
        return ssa.LocalSlot{N: n, Type: t, Off: 0, SplitOf: parent, SplitOffset: offset}
 }
index e39d0ee6a5fcb063ff7002a2034c1335bb58e43b..14107057d4887adfe79d281af8d31f7857e13e9e 100644 (file)
@@ -17,7 +17,6 @@ import (
        "cmd/compile/internal/base"
        "cmd/compile/internal/ir"
        "cmd/compile/internal/objw"
-       "cmd/compile/internal/typecheck"
        "cmd/compile/internal/types"
        "cmd/internal/notsha256"
        "cmd/internal/obj"
@@ -56,7 +55,7 @@ func InitSliceBytes(nam *ir.Name, off int64, s string) {
        if nam.Op() != ir.ONAME {
                base.Fatalf("InitSliceBytes %v", nam)
        }
-       InitSlice(nam, off, slicedata(nam.Pos(), s).Linksym(), int64(len(s)))
+       InitSlice(nam, off, slicedata(nam.Pos(), s), int64(len(s)))
 }
 
 const (
@@ -134,7 +133,7 @@ func fileStringSym(pos src.XPos, file string, readonly bool, hash []byte) (*obj.
                if readonly {
                        sym = StringSym(pos, string(data))
                } else {
-                       sym = slicedata(pos, string(data)).Linksym()
+                       sym = slicedata(pos, string(data))
                }
                if len(hash) > 0 {
                        sum := notsha256.Sum256(data)
@@ -182,7 +181,7 @@ func fileStringSym(pos src.XPos, file string, readonly bool, hash []byte) (*obj.
        } else {
                // Emit a zero-length data symbol
                // and then fix up length and content to use file.
-               symdata = slicedata(pos, "").Linksym()
+               symdata = slicedata(pos, "")
                symdata.Size = size
                symdata.Type = objabi.SNOPTRDATA
                info := symdata.NewFileInfo()
@@ -195,18 +194,14 @@ func fileStringSym(pos src.XPos, file string, readonly bool, hash []byte) (*obj.
 
 var slicedataGen int
 
-func slicedata(pos src.XPos, s string) *ir.Name {
+func slicedata(pos src.XPos, s string) *obj.LSym {
        slicedataGen++
        symname := fmt.Sprintf(".gobytes.%d", slicedataGen)
-       sym := types.LocalPkg.Lookup(symname)
-       symnode := typecheck.NewName(sym)
-       sym.Def = symnode
-
-       lsym := symnode.Linksym()
+       lsym := types.LocalPkg.Lookup(symname).LinksymABI(obj.ABI0)
        off := dstringdata(lsym, 0, s, pos, "slice")
        objw.Global(lsym, int32(off), obj.NOPTR|obj.LOCAL)
 
-       return symnode
+       return lsym
 }
 
 func dstringdata(s *obj.LSym, off int, t string, pos src.XPos, what string) int {
index b1c91089b94631921f0b558e59d6f398ca7b41a1..016d0692ed5197abbde77861705f207cb96b526b 100644 (file)
@@ -684,13 +684,12 @@ func StaticName(t *types.Type) *ir.Name {
        sym := typecheck.Lookup(fmt.Sprintf("%s%d", obj.StaticNamePref, statuniqgen))
        statuniqgen++
 
-       n := typecheck.NewName(sym)
+       n := ir.NewNameAt(base.Pos, sym, t)
        sym.Def = n
 
        n.Class = ir.PEXTERN
        typecheck.Target.Externs = append(typecheck.Target.Externs, n)
 
-       n.SetType(t)
        n.Linksym().Set(obj.AttrStatic, true)
        return n
 }
index 07b8eb728982dcba26cca2fea50268128180c5e6..3316af6940024f1b598c41f45b93ab6abe8a10e5 100644 (file)
@@ -21,10 +21,9 @@ import (
 
 func mkParamResultField(t *types.Type, s *types.Sym, which ir.Class) *types.Field {
        field := types.NewField(src.NoXPos, s, t)
-       n := typecheck.NewName(s)
+       n := ir.NewNameAt(src.NoXPos, s, t)
        n.Class = which
        field.Nname = n
-       n.SetType(t)
        return field
 }
 
index 8bd1d03222d7d2903fb630b6b66d345d746185d8..c0b7c76176f4b6c6d30956b0cabebba3be61a84b 100644 (file)
@@ -19,7 +19,7 @@ var DeclContext ir.Class = ir.PEXTERN // PEXTERN/PAUTO
 
 func DeclFunc(sym *types.Sym, recv *ir.Field, params, results []*ir.Field) *ir.Func {
        fn := ir.NewFunc(base.Pos)
-       fn.Nname = ir.NewNameAt(base.Pos, sym)
+       fn.Nname = ir.NewNameAt(base.Pos, sym, nil)
        fn.Nname.Func = fn
        fn.Nname.Defn = fn
        ir.MarkFunc(fn.Nname)
@@ -119,15 +119,7 @@ func declareParam(fn *ir.Func, ctxt ir.Class, i int, param *ir.Field) *types.Fie
        }
 
        if sym != nil {
-               name := ir.NewNameAt(param.Pos, sym)
-               name.SetType(f.Type)
-               name.SetTypecheck(1)
-
-               name.Class = ctxt
-               fn.Dcl = append(fn.Dcl, name)
-               name.Curfn = fn
-
-               f.Nname = name
+               f.Nname = fn.NewLocal(param.Pos, sym, ctxt, f.Type)
        }
 
        return f
@@ -157,16 +149,11 @@ func TempAt(pos src.XPos, curfn *ir.Func, t *types.Type) *ir.Name {
                Name: autotmpname(len(curfn.Dcl)),
                Pkg:  types.LocalPkg,
        }
-       n := ir.NewNameAt(pos, s)
-       s.Def = n
-       n.SetType(t)
-       n.SetTypecheck(1)
-       n.Class = ir.PAUTO
+       n := curfn.NewLocal(pos, s, ir.PAUTO, t)
+       s.Def = n // TODO(mdempsky): Should be unnecessary.
        n.SetEsc(ir.EscNever)
-       n.Curfn = curfn
        n.SetUsed(true)
        n.SetAutoTemp(true)
-       curfn.Dcl = append(curfn.Dcl, n)
 
        types.CalcSize(t)
 
index 18b93ba0add3f857c15ac0387e59bba4eacd06e2..75b5d58feef15ad5613ffef15d273d0634e604da 100644 (file)
@@ -48,13 +48,6 @@ func NewFuncParams(tl *types.Type, mustname bool) []*ir.Field {
        return args
 }
 
-// NewName returns a new ONAME Node associated with symbol s.
-func NewName(s *types.Sym) *ir.Name {
-       n := ir.NewNameAt(base.Pos, s)
-       n.Curfn = ir.CurFunc
-       return n
-}
-
 // NodAddr returns a node representing &n at base.Pos.
 func NodAddr(n ir.Node) *ir.AddrExpr {
        return NodAddrAt(base.Pos, n)
index 7fe649faaa26656c22cec9adb358baa675296e67..55160e47f0d8ce4a7b2dff8abcd3324c1ac4d3e8 100644 (file)
@@ -30,9 +30,8 @@ func SubstArgTypes(old *ir.Name, types_ ...*types.Type) *ir.Name {
        for _, t := range types_ {
                types.CalcSize(t)
        }
-       n := ir.NewNameAt(old.Pos(), old.Sym())
+       n := ir.NewNameAt(old.Pos(), old.Sym(), types.SubstAny(old.Type(), &types_))
        n.Class = old.Class
-       n.SetType(types.SubstAny(old.Type(), &types_))
        n.Func = old.Func
        if len(types_) > 0 {
                base.Fatalf("SubstArgTypes: too many argument types")
index 076c9da0b15a5e6c489af25b4f9bb928dd1aa1bc..a5bfca2157bdc9f9c6590fe2dbffa9f77ff491e9 100644 (file)
@@ -75,17 +75,11 @@ func InitUniverse() {
        })
 
        for _, s := range &builtinFuncs {
-               s2 := types.BuiltinPkg.Lookup(s.name)
-               def := NewName(s2)
-               def.BuiltinOp = s.op
-               s2.Def = def
+               ir.NewBuiltin(types.BuiltinPkg.Lookup(s.name), s.op)
        }
 
        for _, s := range &unsafeFuncs {
-               s2 := types.UnsafePkg.Lookup(s.name)
-               def := NewName(s2)
-               def.BuiltinOp = s.op
-               s2.Def = def
+               ir.NewBuiltin(types.UnsafePkg.Lookup(s.name), s.op)
        }
 
        s := types.BuiltinPkg.Lookup("true")
@@ -96,14 +90,11 @@ func InitUniverse() {
 
        s = Lookup("_")
        types.BlankSym = s
-       s.Def = NewName(s)
-       ir.BlankNode = ir.AsNode(s.Def)
-       ir.BlankNode.SetType(types.Types[types.TBLANK])
-       ir.BlankNode.SetTypecheck(1)
+       ir.BlankNode = ir.NewNameAt(src.NoXPos, s, types.Types[types.TBLANK])
+       s.Def = ir.BlankNode
 
        s = types.BuiltinPkg.Lookup("_")
-       s.Def = NewName(s)
-       ir.AsNode(s.Def).SetType(types.Types[types.TBLANK])
+       s.Def = ir.NewNameAt(src.NoXPos, s, types.Types[types.TBLANK])
 
        s = types.BuiltinPkg.Lookup("nil")
        s.Def = NodNil()
index 1fa3ac0f18fc4f5dd35087452d4839dcedee4969..27eebf41440e8efccaab9924717bd6aca4bbe7f5 100644 (file)
@@ -47,9 +47,8 @@ func directClosureCall(n *ir.CallExpr) {
                        // and v remains PAUTOHEAP with &v heapaddr
                        // (accesses will implicitly deref &v).
 
-                       addr := ir.NewNameAt(clofn.Pos(), typecheck.Lookup("&"+v.Sym().Name))
+                       addr := ir.NewNameAt(clofn.Pos(), typecheck.Lookup("&"+v.Sym().Name), types.NewPtr(v.Type()))
                        addr.Curfn = clofn
-                       addr.SetType(types.NewPtr(v.Type()))
                        v.Heapaddr = addr
                        v = addr
                }
index 1a167d363ecc8a4086156ee44682569465c6549e..3af457b8c002e2badd391df8a928b970a12d2df5 100644 (file)
@@ -548,7 +548,7 @@ func (s *typeSwitch) Add(pos src.XPos, n1 ir.Node, caseVar *ir.Name, jmp ir.Node
                typecheck.Stmts(l)
                body.Append(l...)
        } else {
-               caseVar = ir.BlankNode.(*ir.Name)
+               caseVar = ir.BlankNode
        }
 
        // cv, ok = iface.(type)