aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2023-08-16 17:23:52 -0700
committerGopher Robot <gobot@golang.org>2023-08-17 19:36:24 +0000
commite45397100584e0ca55901f203d16c2acadbb4447 (patch)
tree488380de82eeadfb2d5f8b6ea722e028c4b0c7e9 /src/cmd/compile/internal/noder
parentd63652b7c69d106a6bab787fbdf7726d39e42406 (diff)
downloadgo-e45397100584e0ca55901f203d16c2acadbb4447.tar.xz
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>
Diffstat (limited to 'src/cmd/compile/internal/noder')
-rw-r--r--src/cmd/compile/internal/noder/reader.go48
-rw-r--r--src/cmd/compile/internal/noder/unified.go2
2 files changed, 18 insertions, 32 deletions
diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go
index 42794da042..c51963e1c2 100644
--- a/src/cmd/compile/internal/noder/reader.go
+++ b/src/cmd/compile/internal/noder/reader.go
@@ -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)
}
}
diff --git a/src/cmd/compile/internal/noder/unified.go b/src/cmd/compile/internal/noder/unified.go
index 3e5ab2ec39..25c7b77831 100644
--- a/src/cmd/compile/internal/noder/unified.go
+++ b/src/cmd/compile/internal/noder/unified.go
@@ -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
}