mirror of
https://github.com/golang/go
synced 2024-11-26 10:18:12 -07:00
cmd/compile: remove unneeded calls to typecheck in noder2
Remove unneeded calls to typecheck in noder2 associated with g.use() and g.obj(). These routines are already setting the types2-derived type correctly for ONAME nodes, and there is no typechecker1-related transformations related to ONAME nodes, other than making sure that newly created closure variables have their type set. Tested through normal -G=3 testing in all.bash (all of go/tests). Change-Id: I1b790ab9948959685fca3a768401458201833671 Reviewed-on: https://go-review.googlesource.com/c/go/+/303029 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Dan Scales <danscales@google.com>
This commit is contained in:
parent
eaa1ddee84
commit
f47fab938e
@ -30,7 +30,6 @@ func (g *irgen) expr(expr syntax.Expr) ir.Node {
|
|||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case tv.IsBuiltin():
|
case tv.IsBuiltin():
|
||||||
// TODO(mdempsky): Handle in CallExpr?
|
|
||||||
return g.use(expr.(*syntax.Name))
|
return g.use(expr.(*syntax.Name))
|
||||||
case tv.IsType():
|
case tv.IsType():
|
||||||
return ir.TypeNode(g.typ(tv.Type))
|
return ir.TypeNode(g.typ(tv.Type))
|
||||||
@ -82,8 +81,7 @@ func (g *irgen) expr0(typ types2.Type, expr syntax.Expr) ir.Node {
|
|||||||
if _, isNil := g.info.Uses[expr].(*types2.Nil); isNil {
|
if _, isNil := g.info.Uses[expr].(*types2.Nil); isNil {
|
||||||
return Nil(pos, g.typ(typ))
|
return Nil(pos, g.typ(typ))
|
||||||
}
|
}
|
||||||
// TODO(mdempsky): Remove dependency on typecheck.Expr.
|
return g.use(expr)
|
||||||
return typecheck.Expr(g.use(expr))
|
|
||||||
|
|
||||||
case *syntax.CompositeLit:
|
case *syntax.CompositeLit:
|
||||||
return g.compLit(typ, expr)
|
return g.compLit(typ, expr)
|
||||||
@ -157,8 +155,7 @@ func (g *irgen) expr0(typ types2.Type, expr syntax.Expr) ir.Node {
|
|||||||
// Qualified identifier.
|
// Qualified identifier.
|
||||||
if name, ok := expr.X.(*syntax.Name); ok {
|
if name, ok := expr.X.(*syntax.Name); ok {
|
||||||
if _, ok := g.info.Uses[name].(*types2.PkgName); ok {
|
if _, ok := g.info.Uses[name].(*types2.PkgName); ok {
|
||||||
// TODO(mdempsky): Remove dependency on typecheck.Expr.
|
return g.use(expr.Sel)
|
||||||
return typecheck.Expr(g.use(expr.Sel))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return g.selectorExpr(pos, typ, expr)
|
return g.selectorExpr(pos, typ, expr)
|
||||||
|
@ -22,16 +22,26 @@ func (g *irgen) def(name *syntax.Name) (*ir.Name, types2.Object) {
|
|||||||
return g.obj(obj), obj
|
return g.obj(obj), obj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use returns the Name node associated with the use of name. The returned node
|
||||||
|
// will have the correct type and be marked as typechecked.
|
||||||
func (g *irgen) use(name *syntax.Name) *ir.Name {
|
func (g *irgen) use(name *syntax.Name) *ir.Name {
|
||||||
obj, ok := g.info.Uses[name]
|
obj2, ok := g.info.Uses[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
base.FatalfAt(g.pos(name), "unknown name %v", name)
|
base.FatalfAt(g.pos(name), "unknown name %v", name)
|
||||||
}
|
}
|
||||||
return ir.CaptureName(g.pos(obj), ir.CurFunc, g.obj(obj))
|
obj := ir.CaptureName(g.pos(obj2), ir.CurFunc, g.obj(obj2))
|
||||||
|
if obj.Defn != nil && obj.Defn.Op() == ir.ONAME {
|
||||||
|
// If CaptureName created a closure variable, then transfer the
|
||||||
|
// type of the captured name to the new closure variable.
|
||||||
|
obj.SetTypecheck(1)
|
||||||
|
obj.SetType(obj.Defn.Type())
|
||||||
|
}
|
||||||
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
// obj returns the Name that represents the given object. If no such
|
// obj returns the Name that represents the given object. If no such Name exists
|
||||||
// Name exists yet, it will be implicitly created.
|
// yet, it will be implicitly created. The returned node will have the correct
|
||||||
|
// type and be marked as typechecked.
|
||||||
//
|
//
|
||||||
// For objects declared at function scope, ir.CurFunc must already be
|
// For objects declared at function scope, ir.CurFunc must already be
|
||||||
// set to the respective function when the Name is created.
|
// set to the respective function when the Name is created.
|
||||||
@ -45,6 +55,7 @@ func (g *irgen) obj(obj types2.Object) *ir.Name {
|
|||||||
}
|
}
|
||||||
n := typecheck.Resolve(ir.NewIdent(src.NoXPos, sym))
|
n := typecheck.Resolve(ir.NewIdent(src.NoXPos, sym))
|
||||||
if n, ok := n.(*ir.Name); ok {
|
if n, ok := n.(*ir.Name); ok {
|
||||||
|
n.SetTypecheck(1)
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
base.FatalfAt(g.pos(obj), "failed to resolve %v", obj)
|
base.FatalfAt(g.pos(obj), "failed to resolve %v", obj)
|
||||||
@ -117,6 +128,7 @@ func (g *irgen) obj(obj types2.Object) *ir.Name {
|
|||||||
}
|
}
|
||||||
|
|
||||||
g.objs[obj] = name
|
g.objs[obj] = name
|
||||||
|
name.SetTypecheck(1)
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user