]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile: simplify how irgen handles qualified idents
authorMatthew Dempsky <mdempsky@google.com>
Wed, 20 Jan 2021 21:54:53 +0000 (13:54 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 20 Jan 2021 22:50:16 +0000 (22:50 +0000)
This CL moves qualified identifier handling into expr0 with other
selector expressions, rather than as a completely separate special
case handled up front. This has a few benefits:

1. It's marginally simpler/cleaner.

2. It allows extra checking for imported objects that they have the
same type that types2 thought they had.

3. For imported, untyped constants, we now instead handle them with
the "tv.Value != nil" case. In particular, this ensures that they've
always already been coerced to the appropriate concrete type by
types2.

Change-Id: Ibf44ae6901db36aa5251f70934616e9fcbd1cbc5
Reviewed-on: https://go-review.googlesource.com/c/go/+/285053
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/noder/expr.go

index fba6ad2e4ba228f5f2c54743a2ff4aa9a2a5b3d9..d5177ead06fefce1c332422425f4b3745b37794a 100644 (file)
@@ -27,15 +27,6 @@ func (g *irgen) expr(expr syntax.Expr) ir.Node {
                return ir.BlankNode
        }
 
-       // TODO(mdempsky): Is there a better way to recognize and handle qualified identifiers?
-       if expr, ok := expr.(*syntax.SelectorExpr); ok {
-               if name, ok := expr.X.(*syntax.Name); ok {
-                       if _, ok := g.info.Uses[name].(*types2.PkgName); ok {
-                               return g.use(expr.Sel)
-                       }
-               }
-       }
-
        tv, ok := g.info.Types[expr]
        if !ok {
                base.FatalfAt(g.pos(expr), "missing type for %v (%T)", expr, expr)
@@ -89,6 +80,13 @@ func (g *irgen) expr0(typ types2.Type, expr syntax.Expr) ir.Node {
        case *syntax.ParenExpr:
                return g.expr(expr.X) // skip parens; unneeded after parse+typecheck
        case *syntax.SelectorExpr:
+               // Qualified identifier.
+               if name, ok := expr.X.(*syntax.Name); ok {
+                       if _, ok := g.info.Uses[name].(*types2.PkgName); ok {
+                               return g.use(expr.Sel)
+                       }
+               }
+
                // TODO(mdempsky/danscales): Use g.info.Selections[expr]
                // to resolve field/method selection. See CL 280633.
                return ir.NewSelectorExpr(pos, ir.OXDOT, g.expr(expr.X), g.name(expr.Sel))