cmd/compile/internal/ir: add typ parameter to NewNameAt

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>
This commit is contained in:
Matthew Dempsky 2023-08-16 17:23:52 -07:00 committed by Gopher Robot
parent d63652b7c6
commit e453971005
20 changed files with 96 additions and 138 deletions

View file

@ -820,9 +820,8 @@ func inlcopy(n ir.Node) ir.Node {
oldfn := x.Func oldfn := x.Func
newfn := ir.NewFunc(oldfn.Pos()) newfn := ir.NewFunc(oldfn.Pos())
m.(*ir.ClosureExpr).Func = newfn 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() ?? // XXX OK to share fn.Type() ??
newfn.Nname.SetType(oldfn.Nname.Type())
newfn.Body = inlcopylist(oldfn.Body) newfn.Body = inlcopylist(oldfn.Body)
// Make shallow copy of the Dcl and ClosureVar slices // Make shallow copy of the Dcl and ClosureVar slices
newfn.Dcl = append([]*ir.Name(nil), oldfn.Dcl...) newfn.Dcl = append([]*ir.Name(nil), oldfn.Dcl...)

View file

@ -557,9 +557,8 @@ func (n *SelectorExpr) FuncName() *Name {
if n.Op() != OMETHEXPR { if n.Op() != OMETHEXPR {
panic(n.no("FuncName")) 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.Class = PFUNC
fn.SetType(n.Type())
if n.Selection.Nname != nil { if n.Selection.Nname != nil {
// TODO(austin): Nname is nil for interface method // TODO(austin): Nname is nil for interface method
// expressions (I.M), so we can't attach a Func to // expressions (I.M), so we can't attach a Func to

View file

@ -398,7 +398,7 @@ func NewClosureFunc(pos src.XPos, hidden bool) *Func {
fn := NewFunc(pos) fn := NewFunc(pos)
fn.SetIsHiddenClosure(hidden) fn.SetIsHiddenClosure(hidden)
fn.Nname = NewNameAt(pos, BlankNode.Sym()) fn.Nname = NewNameAt(pos, BlankNode.Sym(), nil)
fn.Nname.Func = fn fn.Nname.Func = fn
fn.Nname.Defn = fn fn.Nname.Defn = fn

View file

@ -147,11 +147,42 @@ func (n *Name) RecordFrameOffset(offset int64) {
// NewNameAt returns a new ONAME Node associated with symbol s at position pos. // NewNameAt returns a new ONAME Node associated with symbol s at position pos.
// The caller is responsible for setting Curfn. // 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 { if sym == nil {
base.Fatalf("NewNameAt 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. // 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) base.Fatalf("NewClosureVar: %+v", n)
} }
c := NewNameAt(pos, n.Sym()) c := NewNameAt(pos, n.Sym(), n.Type())
c.Curfn = fn c.Curfn = fn
c.Class = PAUTOHEAP c.Class = PAUTOHEAP
c.SetIsClosureVar(true) c.SetIsClosureVar(true)
c.Defn = n.Canonical() c.Defn = n.Canonical()
c.Outer = n c.Outer = n
c.SetType(n.Type())
c.SetTypecheck(n.Typecheck())
fn.ClosureVars = append(fn.ClosureVars, c) fn.ClosureVars = append(fn.ClosureVars, c)
return 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 // Create a fake parameter, disassociated from any real function, to
// pretend to capture. // pretend to capture.
fake := NewNameAt(pos, sym) fake := NewNameAt(pos, sym, typ)
fake.Class = PPARAM fake.Class = PPARAM
fake.SetType(typ)
fake.SetByval(true) fake.SetByval(true)
return NewClosureVar(pos, fn, fake) return NewClosureVar(pos, fn, fake)

View file

@ -470,7 +470,7 @@ func AsNode(n types.Object) Node {
return n.(Node) return n.(Node)
} }
var BlankNode Node var BlankNode *Name
func IsConst(n Node, ct constant.Kind) bool { func IsConst(n Node, ct constant.Kind) bool {
return ConstType(n) == ct return ConstType(n) == ct

View file

@ -995,8 +995,7 @@ func (r *reader) method(rext *reader) *types.Field {
_, recv := r.param() _, recv := r.param()
typ := r.signature(recv) typ := r.signature(recv)
name := ir.NewNameAt(pos, ir.MethodSym(recv.Type, sym)) name := ir.NewNameAt(pos, ir.MethodSym(recv.Type, sym), typ)
setType(name, typ)
name.Func = ir.NewFunc(r.pos()) name.Func = ir.NewFunc(r.pos())
name.Func.Nname = name name.Func.Nname = name
@ -1386,7 +1385,7 @@ func (pr *pkgReader) dictNameOf(dict *readerDict) *ir.Name {
return sym.Def.(*ir.Name) return sym.Def.(*ir.Name)
} }
name := ir.NewNameAt(pos, sym) name := ir.NewNameAt(pos, sym, dict.varType())
name.Class = ir.PEXTERN name.Class = ir.PEXTERN
sym.Def = name // break cycles with mutual subdictionaries 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) objw.Global(lsym, int32(ot), obj.DUPOK|obj.RODATA)
name.SetType(dict.varType())
name.SetTypecheck(1)
return name return name
} }
@ -1530,9 +1526,7 @@ func (r *reader) funcarg(param *types.Field, sym *types.Sym, ctxt ir.Class) {
return return
} }
name := ir.NewNameAt(r.inlPos(param.Pos), sym) name := r.addLocal(r.inlPos(param.Pos), sym, ctxt, param.Type)
setType(name, param.Type)
r.addLocal(name, ctxt)
if r.inlCall == nil { if r.inlCall == nil {
if !r.funarghack { 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) assert(ctxt == ir.PAUTO || ctxt == ir.PPARAM || ctxt == ir.PPARAMOUT)
name := ir.NewNameAt(pos, sym, typ)
if name.Sym().Name == dictParamName { if name.Sym().Name == dictParamName {
r.dictParam = name r.dictParam = name
} else { } else {
@ -1572,7 +1568,7 @@ func (r *reader) addLocal(name *ir.Name, ctxt ir.Class) {
// TODO(mdempsky): Move earlier. // TODO(mdempsky): Move earlier.
if ir.IsBlank(name) { if ir.IsBlank(name) {
return return name
} }
if r.inlCall != nil { if r.inlCall != nil {
@ -1592,6 +1588,8 @@ func (r *reader) addLocal(name *ir.Name, ctxt ir.Class) {
if ctxt == ir.PAUTO { if ctxt == ir.PAUTO {
name.SetFrameOffset(0) name.SetFrameOffset(0)
} }
return name
} }
func (r *reader) useLocal() *ir.Name { func (r *reader) useLocal() *ir.Name {
@ -1836,9 +1834,7 @@ func (r *reader) assign() (ir.Node, bool) {
_, sym := r.localIdent() _, sym := r.localIdent()
typ := r.typ() typ := r.typ()
name := ir.NewNameAt(pos, sym) name := r.addLocal(pos, sym, ir.PAUTO, typ)
setType(name, typ)
r.addLocal(name, ir.PAUTO)
return name, true return name, true
case assignExpr: case assignExpr:
@ -2064,9 +2060,7 @@ func (r *reader) switchStmt(label *types.Sym) ir.Node {
pos := r.pos() pos := r.pos()
typ := r.typ() typ := r.typ()
name := ir.NewNameAt(pos, ident.Sym()) name := r.addLocal(pos, ident.Sym(), ir.PAUTO, typ)
setType(name, typ)
r.addLocal(name, ir.PAUTO)
clause.Var = name clause.Var = name
name.Defn = tag 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? // TODO(mdempsky): This still feels clumsy. Can we do better?
tmpfn := ir.NewFunc(fn.Pos()) 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 tmpfn.Closgen = callerfn.Closgen
defer func() { callerfn.Closgen = tmpfn.Closgen }() defer func() { callerfn.Closgen = tmpfn.Closgen }()
setType(tmpfn.Nname, fn.Type())
r.curfn = tmpfn r.curfn = tmpfn
r.inlCaller = callerfn r.inlCaller = callerfn
@ -3644,12 +3637,11 @@ func expandInline(fn *ir.Func, pri pkgReaderIndex) {
topdcls := len(typecheck.Target.Funcs) topdcls := len(typecheck.Target.Funcs)
tmpfn := ir.NewFunc(fn.Pos()) 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 tmpfn.ClosureVars = fn.ClosureVars
{ {
r := pri.asReader(pkgbits.RelocBody, pkgbits.SyncFuncBody) r := pri.asReader(pkgbits.RelocBody, pkgbits.SyncFuncBody)
setType(tmpfn.Nname, fn.Type())
// Don't change parameter's Sym/Nname fields. // Don't change parameter's Sym/Nname fields.
r.funarghack = true 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 { 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 := ir.NewFunc(pos)
fn.SetDupok(true) // TODO(mdempsky): Leave unset for local, non-generic wrappers? 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) ir.MarkFunc(name)
name.Func = fn name.Func = fn
name.Defn = fn name.Defn = fn
fn.Nname = name fn.Nname = name
sig := newWrapperType(wrapper, method)
setType(name, sig) setType(name, sig)
// TODO(mdempsky): De-duplicate with similar logic in funcargs. // TODO(mdempsky): De-duplicate with similar logic in funcargs.
defParams := func(class ir.Class, params *types.Type) { defParams := func(class ir.Class, params *types.Type) {
for _, param := range params.FieldSlice() { for _, param := range params.FieldSlice() {
name := ir.NewNameAt(param.Pos, param.Sym) param.Nname = fn.NewLocal(param.Pos, param.Sym, class, param.Type)
name.Class = class
setType(name, param.Type)
name.Curfn = fn
fn.Dcl = append(fn.Dcl, name)
param.Nname = name
} }
} }

View file

@ -319,7 +319,7 @@ func readPackage(pr *pkgReader, importpkg *types.Pkg, localStub bool) {
if r.Bool() { if r.Bool() {
sym := importpkg.Lookup(".inittask") sym := importpkg.Lookup(".inittask")
task := ir.NewNameAt(src.NoXPos, sym) task := ir.NewNameAt(src.NoXPos, sym, nil)
task.Class = ir.PEXTERN task.Class = ir.PEXTERN
sym.Def = task sym.Def = task
} }

View file

@ -132,12 +132,12 @@ func MakeTask() {
// Call runtime.asanregisterglobals function to poison redzones. // Call runtime.asanregisterglobals function to poison redzones.
// runtime.asanregisterglobals(unsafe.Pointer(&globals[0]), ni) // 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"),
ir.MarkFunc(asanf) types.NewSignature(nil, []*types.Field{
asanf.SetType(types.NewSignature(nil, []*types.Field{
types.NewField(base.Pos, nil, types.Types[types.TUNSAFEPTR]), types.NewField(base.Pos, nil, types.Types[types.TUNSAFEPTR]),
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]), types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
}, nil)) }, nil))
ir.MarkFunc(asanf)
asancall := ir.NewCallExpr(base.Pos, ir.OCALL, asanf, nil) asancall := ir.NewCallExpr(base.Pos, ir.OCALL, asanf, nil)
asancall.Args.Append(typecheck.ConvNop(typecheck.NodAddr( asancall.Args.Append(typecheck.ConvNop(typecheck.NodAddr(
ir.NewIndexExpr(base.Pos, globals, ir.NewInt(base.Pos, 0))), types.Types[types.TUNSAFEPTR])) ir.NewIndexExpr(base.Pos, globals, ir.NewInt(base.Pos, 0))), types.Types[types.TUNSAFEPTR]))
@ -193,8 +193,7 @@ func MakeTask() {
// Make an .inittask structure. // Make an .inittask structure.
sym := typecheck.Lookup(".inittask") sym := typecheck.Lookup(".inittask")
task := typecheck.NewName(sym) task := ir.NewNameAt(base.Pos, sym, types.Types[types.TUINT8]) // fake type
task.SetType(types.Types[types.TUINT8]) // fake type
task.Class = ir.PEXTERN task.Class = ir.PEXTERN
sym.Def = task sym.Def = task
lsym := task.Linksym() lsym := task.Linksym()

View file

@ -23,8 +23,7 @@ func instrumentGlobals(fn *ir.Func) *ir.Name {
// var asanglobals []asanGlobalStruct // var asanglobals []asanGlobalStruct
arraytype := types.NewArray(asanGlobalStruct, int64(len(InstrumentGlobalsMap))) arraytype := types.NewArray(asanGlobalStruct, int64(len(InstrumentGlobalsMap)))
symG := lname(".asanglobals") symG := lname(".asanglobals")
globals := typecheck.NewName(symG) globals := ir.NewNameAt(base.Pos, symG, arraytype)
globals.SetType(arraytype)
globals.Class = ir.PEXTERN globals.Class = ir.PEXTERN
symG.Def = globals symG.Def = globals
typecheck.Target.Externs = append(typecheck.Target.Externs, globals) typecheck.Target.Externs = append(typecheck.Target.Externs, globals)
@ -32,8 +31,7 @@ func instrumentGlobals(fn *ir.Func) *ir.Name {
// var asanL []asanLocationStruct // var asanL []asanLocationStruct
arraytype = types.NewArray(asanLocationStruct, int64(len(InstrumentGlobalsMap))) arraytype = types.NewArray(asanLocationStruct, int64(len(InstrumentGlobalsMap)))
symL := lname(".asanL") symL := lname(".asanL")
asanlocation := typecheck.NewName(symL) asanlocation := ir.NewNameAt(base.Pos, symL, arraytype)
asanlocation.SetType(arraytype)
asanlocation.Class = ir.PEXTERN asanlocation.Class = ir.PEXTERN
symL.Def = asanlocation symL.Def = asanlocation
typecheck.Target.Externs = append(typecheck.Target.Externs, asanlocation) typecheck.Target.Externs = append(typecheck.Target.Externs, asanlocation)
@ -43,22 +41,19 @@ func instrumentGlobals(fn *ir.Func) *ir.Name {
// var asanModulename string // var asanModulename string
// var asanFilename string // var asanFilename string
symL = lname(".asanName") symL = lname(".asanName")
asanName := typecheck.NewName(symL) asanName := ir.NewNameAt(base.Pos, symL, types.Types[types.TSTRING])
asanName.SetType(types.Types[types.TSTRING])
asanName.Class = ir.PEXTERN asanName.Class = ir.PEXTERN
symL.Def = asanName symL.Def = asanName
typecheck.Target.Externs = append(typecheck.Target.Externs, asanName) typecheck.Target.Externs = append(typecheck.Target.Externs, asanName)
symL = lname(".asanModulename") symL = lname(".asanModulename")
asanModulename := typecheck.NewName(symL) asanModulename := ir.NewNameAt(base.Pos, symL, types.Types[types.TSTRING])
asanModulename.SetType(types.Types[types.TSTRING])
asanModulename.Class = ir.PEXTERN asanModulename.Class = ir.PEXTERN
symL.Def = asanModulename symL.Def = asanModulename
typecheck.Target.Externs = append(typecheck.Target.Externs, asanModulename) typecheck.Target.Externs = append(typecheck.Target.Externs, asanModulename)
symL = lname(".asanFilename") symL = lname(".asanFilename")
asanFilename := typecheck.NewName(symL) asanFilename := ir.NewNameAt(base.Pos, symL, types.Types[types.TSTRING])
asanFilename.SetType(types.Types[types.TSTRING])
asanFilename.Class = ir.PEXTERN asanFilename.Class = ir.PEXTERN
symL.Def = asanFilename symL.Def = asanFilename
typecheck.Target.Externs = append(typecheck.Target.Externs, asanFilename) typecheck.Target.Externs = append(typecheck.Target.Externs, asanFilename)

View file

@ -59,7 +59,7 @@ func (c *Conf) Frontend() Frontend {
f.Nname = ir.NewNameAt(f.Pos(), &types.Sym{ f.Nname = ir.NewNameAt(f.Pos(), &types.Sym{
Pkg: types.NewPkg("my/import/path", "path"), Pkg: types.NewPkg("my/import/path", "path"),
Name: "function", Name: "function",
}) }, nil)
f.LSym = &obj.LSym{Name: "my/import/path.function"} f.LSym = &obj.LSym{Name: "my/import/path.function"}
c.fe = TestFrontend{ c.fe = TestFrontend{
@ -83,8 +83,7 @@ func (TestFrontend) StringData(s string) *obj.LSym {
return nil return nil
} }
func (TestFrontend) Auto(pos src.XPos, t *types.Type) *ir.Name { func (TestFrontend) Auto(pos src.XPos, t *types.Type) *ir.Name {
n := ir.NewNameAt(pos, &types.Sym{Name: "aFakeAuto"}) n := ir.NewNameAt(pos, &types.Sym{Name: "aFakeAuto"}, t)
n.SetType(t)
n.Class = ir.PAUTO n.Class = ir.PAUTO
return n return n
} }

View file

@ -675,12 +675,9 @@ func (s *state) setHeapaddr(pos src.XPos, n *ir.Name, ptr *ssa.Value) {
} }
// Declare variable to hold address. // Declare variable to hold address.
addr := ir.NewNameAt(pos, &types.Sym{Name: "&" + n.Sym().Name, Pkg: types.LocalPkg}) sym := &types.Sym{Name: "&" + n.Sym().Name, Pkg: types.LocalPkg}
addr.SetType(types.NewPtr(n.Type())) addr := s.curfn.NewLocal(pos, sym, ir.PAUTO, types.NewPtr(n.Type()))
addr.Class = ir.PAUTO
addr.SetUsed(true) addr.SetUsed(true)
addr.Curfn = s.curfn
s.curfn.Dcl = append(s.curfn.Dcl, addr)
types.CalcSize(addr.Type()) types.CalcSize(addr.Type())
if n.Class == ir.PPARAMOUT { 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 (s *state) Debug_checknil() bool { return s.f.Frontend().Debug_checknil() }
func ssaMarker(name string) *ir.Name { func ssaMarker(name string) *ir.Name {
return typecheck.NewName(&types.Sym{Name: name}) return ir.NewNameAt(base.Pos, &types.Sym{Name: name}, nil)
} }
var ( 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} return ssa.LocalSlot{N: node, Type: t, Off: parent.Off + offset}
} }
s := &types.Sym{Name: node.Sym().Name + suffix, Pkg: types.LocalPkg} sym := &types.Sym{Name: node.Sym().Name + suffix, Pkg: types.LocalPkg}
n := ir.NewNameAt(parent.N.Pos(), s) n := e.curfn.NewLocal(parent.N.Pos(), sym, ir.PAUTO, t)
s.Def = n n.SetUsed(true)
ir.AsNode(s.Def).Name().SetUsed(true)
n.SetType(t)
n.Class = ir.PAUTO
n.SetEsc(ir.EscNever) n.SetEsc(ir.EscNever)
n.Curfn = e.curfn
e.curfn.Dcl = append(e.curfn.Dcl, n)
types.CalcSize(t) types.CalcSize(t)
return ssa.LocalSlot{N: n, Type: t, Off: 0, SplitOf: parent, SplitOffset: offset} return ssa.LocalSlot{N: n, Type: t, Off: 0, SplitOf: parent, SplitOffset: offset}
} }

View file

@ -17,7 +17,6 @@ import (
"cmd/compile/internal/base" "cmd/compile/internal/base"
"cmd/compile/internal/ir" "cmd/compile/internal/ir"
"cmd/compile/internal/objw" "cmd/compile/internal/objw"
"cmd/compile/internal/typecheck"
"cmd/compile/internal/types" "cmd/compile/internal/types"
"cmd/internal/notsha256" "cmd/internal/notsha256"
"cmd/internal/obj" "cmd/internal/obj"
@ -56,7 +55,7 @@ func InitSliceBytes(nam *ir.Name, off int64, s string) {
if nam.Op() != ir.ONAME { if nam.Op() != ir.ONAME {
base.Fatalf("InitSliceBytes %v", nam) 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 ( const (
@ -134,7 +133,7 @@ func fileStringSym(pos src.XPos, file string, readonly bool, hash []byte) (*obj.
if readonly { if readonly {
sym = StringSym(pos, string(data)) sym = StringSym(pos, string(data))
} else { } else {
sym = slicedata(pos, string(data)).Linksym() sym = slicedata(pos, string(data))
} }
if len(hash) > 0 { if len(hash) > 0 {
sum := notsha256.Sum256(data) sum := notsha256.Sum256(data)
@ -182,7 +181,7 @@ func fileStringSym(pos src.XPos, file string, readonly bool, hash []byte) (*obj.
} else { } else {
// Emit a zero-length data symbol // Emit a zero-length data symbol
// and then fix up length and content to use file. // and then fix up length and content to use file.
symdata = slicedata(pos, "").Linksym() symdata = slicedata(pos, "")
symdata.Size = size symdata.Size = size
symdata.Type = objabi.SNOPTRDATA symdata.Type = objabi.SNOPTRDATA
info := symdata.NewFileInfo() info := symdata.NewFileInfo()
@ -195,18 +194,14 @@ func fileStringSym(pos src.XPos, file string, readonly bool, hash []byte) (*obj.
var slicedataGen int var slicedataGen int
func slicedata(pos src.XPos, s string) *ir.Name { func slicedata(pos src.XPos, s string) *obj.LSym {
slicedataGen++ slicedataGen++
symname := fmt.Sprintf(".gobytes.%d", slicedataGen) symname := fmt.Sprintf(".gobytes.%d", slicedataGen)
sym := types.LocalPkg.Lookup(symname) lsym := types.LocalPkg.Lookup(symname).LinksymABI(obj.ABI0)
symnode := typecheck.NewName(sym)
sym.Def = symnode
lsym := symnode.Linksym()
off := dstringdata(lsym, 0, s, pos, "slice") off := dstringdata(lsym, 0, s, pos, "slice")
objw.Global(lsym, int32(off), obj.NOPTR|obj.LOCAL) 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 { func dstringdata(s *obj.LSym, off int, t string, pos src.XPos, what string) int {

View file

@ -684,13 +684,12 @@ func StaticName(t *types.Type) *ir.Name {
sym := typecheck.Lookup(fmt.Sprintf("%s%d", obj.StaticNamePref, statuniqgen)) sym := typecheck.Lookup(fmt.Sprintf("%s%d", obj.StaticNamePref, statuniqgen))
statuniqgen++ statuniqgen++
n := typecheck.NewName(sym) n := ir.NewNameAt(base.Pos, sym, t)
sym.Def = n sym.Def = n
n.Class = ir.PEXTERN n.Class = ir.PEXTERN
typecheck.Target.Externs = append(typecheck.Target.Externs, n) typecheck.Target.Externs = append(typecheck.Target.Externs, n)
n.SetType(t)
n.Linksym().Set(obj.AttrStatic, true) n.Linksym().Set(obj.AttrStatic, true)
return n return n
} }

View file

@ -21,10 +21,9 @@ import (
func mkParamResultField(t *types.Type, s *types.Sym, which ir.Class) *types.Field { func mkParamResultField(t *types.Type, s *types.Sym, which ir.Class) *types.Field {
field := types.NewField(src.NoXPos, s, t) field := types.NewField(src.NoXPos, s, t)
n := typecheck.NewName(s) n := ir.NewNameAt(src.NoXPos, s, t)
n.Class = which n.Class = which
field.Nname = n field.Nname = n
n.SetType(t)
return field return field
} }

View 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 { func DeclFunc(sym *types.Sym, recv *ir.Field, params, results []*ir.Field) *ir.Func {
fn := ir.NewFunc(base.Pos) 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.Func = fn
fn.Nname.Defn = fn fn.Nname.Defn = fn
ir.MarkFunc(fn.Nname) 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 { if sym != nil {
name := ir.NewNameAt(param.Pos, sym) f.Nname = fn.NewLocal(param.Pos, sym, ctxt, f.Type)
name.SetType(f.Type)
name.SetTypecheck(1)
name.Class = ctxt
fn.Dcl = append(fn.Dcl, name)
name.Curfn = fn
f.Nname = name
} }
return f return f
@ -157,16 +149,11 @@ func TempAt(pos src.XPos, curfn *ir.Func, t *types.Type) *ir.Name {
Name: autotmpname(len(curfn.Dcl)), Name: autotmpname(len(curfn.Dcl)),
Pkg: types.LocalPkg, Pkg: types.LocalPkg,
} }
n := ir.NewNameAt(pos, s) n := curfn.NewLocal(pos, s, ir.PAUTO, t)
s.Def = n s.Def = n // TODO(mdempsky): Should be unnecessary.
n.SetType(t)
n.SetTypecheck(1)
n.Class = ir.PAUTO
n.SetEsc(ir.EscNever) n.SetEsc(ir.EscNever)
n.Curfn = curfn
n.SetUsed(true) n.SetUsed(true)
n.SetAutoTemp(true) n.SetAutoTemp(true)
curfn.Dcl = append(curfn.Dcl, n)
types.CalcSize(t) types.CalcSize(t)

View file

@ -48,13 +48,6 @@ func NewFuncParams(tl *types.Type, mustname bool) []*ir.Field {
return args 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. // NodAddr returns a node representing &n at base.Pos.
func NodAddr(n ir.Node) *ir.AddrExpr { func NodAddr(n ir.Node) *ir.AddrExpr {
return NodAddrAt(base.Pos, n) return NodAddrAt(base.Pos, n)

View file

@ -30,9 +30,8 @@ func SubstArgTypes(old *ir.Name, types_ ...*types.Type) *ir.Name {
for _, t := range types_ { for _, t := range types_ {
types.CalcSize(t) 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.Class = old.Class
n.SetType(types.SubstAny(old.Type(), &types_))
n.Func = old.Func n.Func = old.Func
if len(types_) > 0 { if len(types_) > 0 {
base.Fatalf("SubstArgTypes: too many argument types") base.Fatalf("SubstArgTypes: too many argument types")

View file

@ -75,17 +75,11 @@ func InitUniverse() {
}) })
for _, s := range &builtinFuncs { for _, s := range &builtinFuncs {
s2 := types.BuiltinPkg.Lookup(s.name) ir.NewBuiltin(types.BuiltinPkg.Lookup(s.name), s.op)
def := NewName(s2)
def.BuiltinOp = s.op
s2.Def = def
} }
for _, s := range &unsafeFuncs { for _, s := range &unsafeFuncs {
s2 := types.UnsafePkg.Lookup(s.name) ir.NewBuiltin(types.UnsafePkg.Lookup(s.name), s.op)
def := NewName(s2)
def.BuiltinOp = s.op
s2.Def = def
} }
s := types.BuiltinPkg.Lookup("true") s := types.BuiltinPkg.Lookup("true")
@ -96,14 +90,11 @@ func InitUniverse() {
s = Lookup("_") s = Lookup("_")
types.BlankSym = s types.BlankSym = s
s.Def = NewName(s) ir.BlankNode = ir.NewNameAt(src.NoXPos, s, types.Types[types.TBLANK])
ir.BlankNode = ir.AsNode(s.Def) s.Def = ir.BlankNode
ir.BlankNode.SetType(types.Types[types.TBLANK])
ir.BlankNode.SetTypecheck(1)
s = types.BuiltinPkg.Lookup("_") s = types.BuiltinPkg.Lookup("_")
s.Def = NewName(s) s.Def = ir.NewNameAt(src.NoXPos, s, types.Types[types.TBLANK])
ir.AsNode(s.Def).SetType(types.Types[types.TBLANK])
s = types.BuiltinPkg.Lookup("nil") s = types.BuiltinPkg.Lookup("nil")
s.Def = NodNil() s.Def = NodNil()

View file

@ -47,9 +47,8 @@ func directClosureCall(n *ir.CallExpr) {
// and v remains PAUTOHEAP with &v heapaddr // and v remains PAUTOHEAP with &v heapaddr
// (accesses will implicitly deref &v). // (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.Curfn = clofn
addr.SetType(types.NewPtr(v.Type()))
v.Heapaddr = addr v.Heapaddr = addr
v = addr v = addr
} }

View file

@ -548,7 +548,7 @@ func (s *typeSwitch) Add(pos src.XPos, n1 ir.Node, caseVar *ir.Name, jmp ir.Node
typecheck.Stmts(l) typecheck.Stmts(l)
body.Append(l...) body.Append(l...)
} else { } else {
caseVar = ir.BlankNode.(*ir.Name) caseVar = ir.BlankNode
} }
// cv, ok = iface.(type) // cv, ok = iface.(type)