mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
d63652b7c6
commit
e453971005
20 changed files with 96 additions and 138 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue