[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2
to guide IR construction. Notably, it completely skips dealing with
constant and type expressions (aside from using ir.TypeNode to
interoperate with the types1 typechecker), because types2 already
handled those. It also omits any syntax checking, trusting that types2
already rejected any errors.
It currently still utilizes the types1 typechecker for the desugaring
operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting
implicit conversions, rewriting f(g()) functions, and so on). However,
the IR is constructed in a fully incremental fashion, so it should be
easy to now piecemeal replace those dependencies as needed.
Nearly all of "go test std cmd" passes with -G=3 enabled by
default. The main remaining blocker is the number of test/run.go
failures. There also appear to be cases where types2 does not provide
us with position information. These will be iterated upon.
Portions and ideas from Dan Scales's CL 276653.
Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281932
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-01-09 00:57:55 -08:00
|
|
|
// Copyright 2021 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package noder
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"cmd/compile/internal/base"
|
|
|
|
|
"cmd/compile/internal/ir"
|
|
|
|
|
"cmd/compile/internal/syntax"
|
|
|
|
|
"cmd/compile/internal/typecheck"
|
|
|
|
|
"cmd/compile/internal/types"
|
|
|
|
|
"cmd/compile/internal/types2"
|
2021-01-19 13:54:33 -08:00
|
|
|
"cmd/internal/src"
|
[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2
to guide IR construction. Notably, it completely skips dealing with
constant and type expressions (aside from using ir.TypeNode to
interoperate with the types1 typechecker), because types2 already
handled those. It also omits any syntax checking, trusting that types2
already rejected any errors.
It currently still utilizes the types1 typechecker for the desugaring
operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting
implicit conversions, rewriting f(g()) functions, and so on). However,
the IR is constructed in a fully incremental fashion, so it should be
easy to now piecemeal replace those dependencies as needed.
Nearly all of "go test std cmd" passes with -G=3 enabled by
default. The main remaining blocker is the number of test/run.go
failures. There also appear to be cases where types2 does not provide
us with position information. These will be iterated upon.
Portions and ideas from Dan Scales's CL 276653.
Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281932
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-01-09 00:57:55 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (g *irgen) expr(expr syntax.Expr) ir.Node {
|
|
|
|
|
// TODO(mdempsky): Change callers to not call on nil?
|
|
|
|
|
if expr == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if expr, ok := expr.(*syntax.Name); ok && expr.Value == "_" {
|
|
|
|
|
return ir.BlankNode
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tv, ok := g.info.Types[expr]
|
|
|
|
|
if !ok {
|
|
|
|
|
base.FatalfAt(g.pos(expr), "missing type for %v (%T)", expr, expr)
|
|
|
|
|
}
|
|
|
|
|
switch {
|
|
|
|
|
case tv.IsBuiltin():
|
|
|
|
|
return g.use(expr.(*syntax.Name))
|
|
|
|
|
case tv.IsType():
|
|
|
|
|
return ir.TypeNode(g.typ(tv.Type))
|
|
|
|
|
case tv.IsValue(), tv.IsVoid():
|
|
|
|
|
// ok
|
|
|
|
|
default:
|
|
|
|
|
base.FatalfAt(g.pos(expr), "unrecognized type-checker result")
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 12:54:23 -08:00
|
|
|
// The gc backend expects all expressions to have a concrete type, and
|
|
|
|
|
// types2 mostly satisfies this expectation already. But there are a few
|
|
|
|
|
// cases where the Go spec doesn't require converting to concrete type,
|
|
|
|
|
// and so types2 leaves them untyped. So we need to fix those up here.
|
|
|
|
|
typ := tv.Type
|
|
|
|
|
if basic, ok := typ.(*types2.Basic); ok && basic.Info()&types2.IsUntyped != 0 {
|
|
|
|
|
switch basic.Kind() {
|
|
|
|
|
case types2.UntypedNil:
|
|
|
|
|
// ok; can appear in type switch case clauses
|
|
|
|
|
// TODO(mdempsky): Handle as part of type switches instead?
|
|
|
|
|
case types2.UntypedBool:
|
|
|
|
|
typ = types2.Typ[types2.Bool] // expression in "if" or "for" condition
|
|
|
|
|
case types2.UntypedString:
|
|
|
|
|
typ = types2.Typ[types2.String] // argument to "append" or "copy" calls
|
|
|
|
|
default:
|
|
|
|
|
base.FatalfAt(g.pos(expr), "unexpected untyped type: %v", basic)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2
to guide IR construction. Notably, it completely skips dealing with
constant and type expressions (aside from using ir.TypeNode to
interoperate with the types1 typechecker), because types2 already
handled those. It also omits any syntax checking, trusting that types2
already rejected any errors.
It currently still utilizes the types1 typechecker for the desugaring
operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting
implicit conversions, rewriting f(g()) functions, and so on). However,
the IR is constructed in a fully incremental fashion, so it should be
easy to now piecemeal replace those dependencies as needed.
Nearly all of "go test std cmd" passes with -G=3 enabled by
default. The main remaining blocker is the number of test/run.go
failures. There also appear to be cases where types2 does not provide
us with position information. These will be iterated upon.
Portions and ideas from Dan Scales's CL 276653.
Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281932
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-01-09 00:57:55 -08:00
|
|
|
// Constant expression.
|
|
|
|
|
if tv.Value != nil {
|
2021-01-20 12:54:23 -08:00
|
|
|
return Const(g.pos(expr), g.typ(typ), tv.Value)
|
[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2
to guide IR construction. Notably, it completely skips dealing with
constant and type expressions (aside from using ir.TypeNode to
interoperate with the types1 typechecker), because types2 already
handled those. It also omits any syntax checking, trusting that types2
already rejected any errors.
It currently still utilizes the types1 typechecker for the desugaring
operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting
implicit conversions, rewriting f(g()) functions, and so on). However,
the IR is constructed in a fully incremental fashion, so it should be
easy to now piecemeal replace those dependencies as needed.
Nearly all of "go test std cmd" passes with -G=3 enabled by
default. The main remaining blocker is the number of test/run.go
failures. There also appear to be cases where types2 does not provide
us with position information. These will be iterated upon.
Portions and ideas from Dan Scales's CL 276653.
Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281932
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-01-09 00:57:55 -08:00
|
|
|
}
|
|
|
|
|
|
2021-01-20 12:54:23 -08:00
|
|
|
n := g.expr0(typ, expr)
|
|
|
|
|
if n.Typecheck() != 1 {
|
|
|
|
|
base.FatalfAt(g.pos(expr), "missed typecheck: %+v", n)
|
|
|
|
|
}
|
|
|
|
|
if !g.match(n.Type(), typ, tv.HasOk()) {
|
|
|
|
|
base.FatalfAt(g.pos(expr), "expected %L to have type %v", n, typ)
|
[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2
to guide IR construction. Notably, it completely skips dealing with
constant and type expressions (aside from using ir.TypeNode to
interoperate with the types1 typechecker), because types2 already
handled those. It also omits any syntax checking, trusting that types2
already rejected any errors.
It currently still utilizes the types1 typechecker for the desugaring
operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting
implicit conversions, rewriting f(g()) functions, and so on). However,
the IR is constructed in a fully incremental fashion, so it should be
easy to now piecemeal replace those dependencies as needed.
Nearly all of "go test std cmd" passes with -G=3 enabled by
default. The main remaining blocker is the number of test/run.go
failures. There also appear to be cases where types2 does not provide
us with position information. These will be iterated upon.
Portions and ideas from Dan Scales's CL 276653.
Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281932
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-01-09 00:57:55 -08:00
|
|
|
}
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *irgen) expr0(typ types2.Type, expr syntax.Expr) ir.Node {
|
|
|
|
|
pos := g.pos(expr)
|
|
|
|
|
|
|
|
|
|
switch expr := expr.(type) {
|
|
|
|
|
case *syntax.Name:
|
|
|
|
|
if _, isNil := g.info.Uses[expr].(*types2.Nil); isNil {
|
|
|
|
|
return Nil(pos, g.typ(typ))
|
|
|
|
|
}
|
2021-03-17 17:54:41 -07:00
|
|
|
return g.use(expr)
|
[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2
to guide IR construction. Notably, it completely skips dealing with
constant and type expressions (aside from using ir.TypeNode to
interoperate with the types1 typechecker), because types2 already
handled those. It also omits any syntax checking, trusting that types2
already rejected any errors.
It currently still utilizes the types1 typechecker for the desugaring
operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting
implicit conversions, rewriting f(g()) functions, and so on). However,
the IR is constructed in a fully incremental fashion, so it should be
easy to now piecemeal replace those dependencies as needed.
Nearly all of "go test std cmd" passes with -G=3 enabled by
default. The main remaining blocker is the number of test/run.go
failures. There also appear to be cases where types2 does not provide
us with position information. These will be iterated upon.
Portions and ideas from Dan Scales's CL 276653.
Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281932
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-01-09 00:57:55 -08:00
|
|
|
|
|
|
|
|
case *syntax.CompositeLit:
|
|
|
|
|
return g.compLit(typ, expr)
|
2021-02-08 14:33:51 -08:00
|
|
|
|
[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2
to guide IR construction. Notably, it completely skips dealing with
constant and type expressions (aside from using ir.TypeNode to
interoperate with the types1 typechecker), because types2 already
handled those. It also omits any syntax checking, trusting that types2
already rejected any errors.
It currently still utilizes the types1 typechecker for the desugaring
operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting
implicit conversions, rewriting f(g()) functions, and so on). However,
the IR is constructed in a fully incremental fashion, so it should be
easy to now piecemeal replace those dependencies as needed.
Nearly all of "go test std cmd" passes with -G=3 enabled by
default. The main remaining blocker is the number of test/run.go
failures. There also appear to be cases where types2 does not provide
us with position information. These will be iterated upon.
Portions and ideas from Dan Scales's CL 276653.
Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281932
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-01-09 00:57:55 -08:00
|
|
|
case *syntax.FuncLit:
|
|
|
|
|
return g.funcLit(typ, expr)
|
|
|
|
|
|
|
|
|
|
case *syntax.AssertExpr:
|
|
|
|
|
return Assert(pos, g.expr(expr.X), g.typeExpr(expr.Type))
|
2021-02-08 14:33:51 -08:00
|
|
|
|
[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2
to guide IR construction. Notably, it completely skips dealing with
constant and type expressions (aside from using ir.TypeNode to
interoperate with the types1 typechecker), because types2 already
handled those. It also omits any syntax checking, trusting that types2
already rejected any errors.
It currently still utilizes the types1 typechecker for the desugaring
operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting
implicit conversions, rewriting f(g()) functions, and so on). However,
the IR is constructed in a fully incremental fashion, so it should be
easy to now piecemeal replace those dependencies as needed.
Nearly all of "go test std cmd" passes with -G=3 enabled by
default. The main remaining blocker is the number of test/run.go
failures. There also appear to be cases where types2 does not provide
us with position information. These will be iterated upon.
Portions and ideas from Dan Scales's CL 276653.
Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281932
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-01-09 00:57:55 -08:00
|
|
|
case *syntax.CallExpr:
|
2021-02-02 13:04:16 -08:00
|
|
|
fun := g.expr(expr.Fun)
|
2021-03-09 18:24:51 -08:00
|
|
|
|
|
|
|
|
// The key for the Inferred map is usually the expr.
|
|
|
|
|
key := syntax.Expr(expr)
|
|
|
|
|
if _, ok := expr.Fun.(*syntax.IndexExpr); ok {
|
|
|
|
|
// If the Fun is an IndexExpr, then this may be a
|
|
|
|
|
// partial type inference case. In this case, we look up
|
|
|
|
|
// the IndexExpr in the Inferred map.
|
|
|
|
|
// TODO(gri): should types2 always record the callExpr as the key?
|
|
|
|
|
key = syntax.Expr(expr.Fun)
|
|
|
|
|
}
|
|
|
|
|
if inferred, ok := g.info.Inferred[key]; ok && len(inferred.Targs) > 0 {
|
2021-02-02 13:04:16 -08:00
|
|
|
targs := make([]ir.Node, len(inferred.Targs))
|
|
|
|
|
for i, targ := range inferred.Targs {
|
|
|
|
|
targs[i] = ir.TypeNode(g.typ(targ))
|
|
|
|
|
}
|
|
|
|
|
if fun.Op() == ir.OFUNCINST {
|
|
|
|
|
// Replace explicit type args with the full list that
|
|
|
|
|
// includes the additional inferred type args
|
|
|
|
|
fun.(*ir.InstExpr).Targs = targs
|
|
|
|
|
} else {
|
|
|
|
|
// Create a function instantiation here, given
|
|
|
|
|
// there are only inferred type args (e.g.
|
|
|
|
|
// min(5,6), where min is a generic function)
|
|
|
|
|
inst := ir.NewInstExpr(pos, ir.OFUNCINST, fun, targs)
|
|
|
|
|
typed(fun.Type(), inst)
|
|
|
|
|
fun = inst
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-30 08:43:58 -08:00
|
|
|
}
|
2021-02-02 13:04:16 -08:00
|
|
|
return Call(pos, g.typ(typ), fun, g.exprs(expr.ArgList), expr.HasDots)
|
2021-02-08 14:33:51 -08:00
|
|
|
|
[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2
to guide IR construction. Notably, it completely skips dealing with
constant and type expressions (aside from using ir.TypeNode to
interoperate with the types1 typechecker), because types2 already
handled those. It also omits any syntax checking, trusting that types2
already rejected any errors.
It currently still utilizes the types1 typechecker for the desugaring
operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting
implicit conversions, rewriting f(g()) functions, and so on). However,
the IR is constructed in a fully incremental fashion, so it should be
easy to now piecemeal replace those dependencies as needed.
Nearly all of "go test std cmd" passes with -G=3 enabled by
default. The main remaining blocker is the number of test/run.go
failures. There also appear to be cases where types2 does not provide
us with position information. These will be iterated upon.
Portions and ideas from Dan Scales's CL 276653.
Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281932
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-01-09 00:57:55 -08:00
|
|
|
case *syntax.IndexExpr:
|
2021-02-02 12:17:57 -08:00
|
|
|
var targs []ir.Node
|
2021-01-30 08:43:58 -08:00
|
|
|
if _, ok := expr.Index.(*syntax.ListExpr); ok {
|
2021-02-02 12:17:57 -08:00
|
|
|
targs = g.exprList(expr.Index)
|
2021-01-30 21:15:40 -08:00
|
|
|
} else {
|
2021-02-02 12:17:57 -08:00
|
|
|
index := g.expr(expr.Index)
|
|
|
|
|
if index.Op() != ir.OTYPE {
|
|
|
|
|
// This is just a normal index expression
|
cmd/compile: getting more built-ins to work with generics
For Builtin ops, we currently stay with using the old
typechecker to transform the call to a more specific expression
and possibly use more specific ops. However, for a bunch of the
ops, we delay calling the old typechecker if any of the args have
type params, for a variety of reasons.
In the near future, we will start creating separate functions that do
the same transformations as the old typechecker for calls, builtins,
indexing, comparisons, etc. These functions can then be called at noder
time for nodes with no type params, and at stenciling time for nodes
with type params.
Remove unnecessary calls to types1 typechecker for most kinds of
statements (still need it for SendStmt, AssignStmt, ReturnStmt, and
SelectStmt). In particular, we don't need it for RangeStmt, and this
avoids some complaints by the types1 typechecker on generic code.
Other small changes:
- Fix check on whether to delay calling types1-typechecker on type
conversions. Should check if HasTParam is true, rather than if the
type is directly a TYPEPARAM.
- Don't call types1-typechecker on an indexing operation if the left
operand has a typeparam in its type and is not obviously a TMAP,
TSLICE, or TARRAY. As above, we will eventually have to create a new
function that can do the required transformations (for complicated
cases) at noder time or stenciling time.
- Copy n.BuiltinOp in subster.node()
- The complex arithmetic example in absdiff.go now works.
- Added new tests double.go and append.go
- Added new example with a new() call in settable.go
Change-Id: I8f377afb6126cab1826bd3c2732aa8cdf1f7e0b4
Reviewed-on: https://go-review.googlesource.com/c/go/+/301951
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Dan Scales <danscales@google.com>
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-03-12 11:36:02 -08:00
|
|
|
return Index(pos, g.typ(typ), g.expr(expr.X), index)
|
2021-01-30 21:15:40 -08:00
|
|
|
}
|
2021-02-02 12:17:57 -08:00
|
|
|
// This is generic function instantiation with a single type
|
|
|
|
|
targs = []ir.Node{index}
|
|
|
|
|
}
|
2021-02-02 13:04:16 -08:00
|
|
|
// This is a generic function instantiation (e.g. min[int])
|
2021-02-02 12:17:57 -08:00
|
|
|
x := g.expr(expr.X)
|
|
|
|
|
if x.Op() != ir.ONAME || x.Type().Kind() != types.TFUNC {
|
|
|
|
|
panic("Incorrect argument for generic func instantiation")
|
2021-01-30 08:43:58 -08:00
|
|
|
}
|
2021-02-02 12:17:57 -08:00
|
|
|
// This could also be an OTYPEINST once we can handle those examples.
|
|
|
|
|
n := ir.NewInstExpr(pos, ir.OFUNCINST, x, targs)
|
|
|
|
|
typed(g.typ(typ), n)
|
|
|
|
|
return n
|
|
|
|
|
|
[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2
to guide IR construction. Notably, it completely skips dealing with
constant and type expressions (aside from using ir.TypeNode to
interoperate with the types1 typechecker), because types2 already
handled those. It also omits any syntax checking, trusting that types2
already rejected any errors.
It currently still utilizes the types1 typechecker for the desugaring
operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting
implicit conversions, rewriting f(g()) functions, and so on). However,
the IR is constructed in a fully incremental fashion, so it should be
easy to now piecemeal replace those dependencies as needed.
Nearly all of "go test std cmd" passes with -G=3 enabled by
default. The main remaining blocker is the number of test/run.go
failures. There also appear to be cases where types2 does not provide
us with position information. These will be iterated upon.
Portions and ideas from Dan Scales's CL 276653.
Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281932
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-01-09 00:57:55 -08:00
|
|
|
case *syntax.ParenExpr:
|
|
|
|
|
return g.expr(expr.X) // skip parens; unneeded after parse+typecheck
|
2021-02-08 14:33:51 -08:00
|
|
|
|
[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2
to guide IR construction. Notably, it completely skips dealing with
constant and type expressions (aside from using ir.TypeNode to
interoperate with the types1 typechecker), because types2 already
handled those. It also omits any syntax checking, trusting that types2
already rejected any errors.
It currently still utilizes the types1 typechecker for the desugaring
operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting
implicit conversions, rewriting f(g()) functions, and so on). However,
the IR is constructed in a fully incremental fashion, so it should be
easy to now piecemeal replace those dependencies as needed.
Nearly all of "go test std cmd" passes with -G=3 enabled by
default. The main remaining blocker is the number of test/run.go
failures. There also appear to be cases where types2 does not provide
us with position information. These will be iterated upon.
Portions and ideas from Dan Scales's CL 276653.
Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281932
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-01-09 00:57:55 -08:00
|
|
|
case *syntax.SelectorExpr:
|
2021-01-20 13:54:53 -08:00
|
|
|
// Qualified identifier.
|
|
|
|
|
if name, ok := expr.X.(*syntax.Name); ok {
|
|
|
|
|
if _, ok := g.info.Uses[name].(*types2.PkgName); ok {
|
2021-03-17 17:54:41 -07:00
|
|
|
return g.use(expr.Sel)
|
2021-01-20 13:54:53 -08:00
|
|
|
}
|
|
|
|
|
}
|
2021-02-08 14:33:51 -08:00
|
|
|
return g.selectorExpr(pos, typ, expr)
|
2021-01-20 13:54:53 -08:00
|
|
|
|
[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2
to guide IR construction. Notably, it completely skips dealing with
constant and type expressions (aside from using ir.TypeNode to
interoperate with the types1 typechecker), because types2 already
handled those. It also omits any syntax checking, trusting that types2
already rejected any errors.
It currently still utilizes the types1 typechecker for the desugaring
operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting
implicit conversions, rewriting f(g()) functions, and so on). However,
the IR is constructed in a fully incremental fashion, so it should be
easy to now piecemeal replace those dependencies as needed.
Nearly all of "go test std cmd" passes with -G=3 enabled by
default. The main remaining blocker is the number of test/run.go
failures. There also appear to be cases where types2 does not provide
us with position information. These will be iterated upon.
Portions and ideas from Dan Scales's CL 276653.
Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281932
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-01-09 00:57:55 -08:00
|
|
|
case *syntax.SliceExpr:
|
|
|
|
|
return Slice(pos, g.expr(expr.X), g.expr(expr.Index[0]), g.expr(expr.Index[1]), g.expr(expr.Index[2]))
|
|
|
|
|
|
|
|
|
|
case *syntax.Operation:
|
|
|
|
|
if expr.Y == nil {
|
|
|
|
|
return Unary(pos, g.op(expr.Op, unOps[:]), g.expr(expr.X))
|
|
|
|
|
}
|
|
|
|
|
switch op := g.op(expr.Op, binOps[:]); op {
|
|
|
|
|
case ir.OEQ, ir.ONE, ir.OLT, ir.OLE, ir.OGT, ir.OGE:
|
|
|
|
|
return Compare(pos, g.typ(typ), op, g.expr(expr.X), g.expr(expr.Y))
|
|
|
|
|
default:
|
|
|
|
|
return Binary(pos, op, g.expr(expr.X), g.expr(expr.Y))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
g.unhandled("expression", expr)
|
|
|
|
|
panic("unreachable")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-19 13:54:33 -08:00
|
|
|
// selectorExpr resolves the choice of ODOT, ODOTPTR, OCALLPART (eventually
|
|
|
|
|
// ODOTMETH & ODOTINTER), and OMETHEXPR and deals with embedded fields here rather
|
|
|
|
|
// than in typecheck.go.
|
2021-02-08 14:33:51 -08:00
|
|
|
func (g *irgen) selectorExpr(pos src.XPos, typ types2.Type, expr *syntax.SelectorExpr) ir.Node {
|
|
|
|
|
x := g.expr(expr.X)
|
2021-03-10 17:27:30 -08:00
|
|
|
if x.Type().HasTParam() {
|
2021-02-08 14:33:51 -08:00
|
|
|
// Leave a method call on a type param as an OXDOT, since it can
|
|
|
|
|
// only be fully transformed once it has an instantiated type.
|
|
|
|
|
n := ir.NewSelectorExpr(pos, ir.OXDOT, x, typecheck.Lookup(expr.Sel.Value))
|
|
|
|
|
typed(g.typ(typ), n)
|
|
|
|
|
return n
|
|
|
|
|
}
|
2021-01-22 13:29:59 -08:00
|
|
|
|
2021-02-08 14:33:51 -08:00
|
|
|
selinfo := g.info.Selections[expr]
|
2021-01-22 13:29:59 -08:00
|
|
|
// Everything up to the last selection is an implicit embedded field access,
|
|
|
|
|
// and the last selection is determined by selinfo.Kind().
|
|
|
|
|
index := selinfo.Index()
|
|
|
|
|
embeds, last := index[:len(index)-1], index[len(index)-1]
|
|
|
|
|
|
2021-01-24 09:59:20 -08:00
|
|
|
origx := x
|
2021-01-22 13:29:59 -08:00
|
|
|
for _, ix := range embeds {
|
|
|
|
|
x = Implicit(DotField(pos, x, ix))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kind := selinfo.Kind()
|
|
|
|
|
if kind == types2.FieldVal {
|
|
|
|
|
return DotField(pos, x, last)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO(danscales,mdempsky): Interface method sets are not sorted the
|
|
|
|
|
// same between types and types2. In particular, using "last" here
|
|
|
|
|
// without conversion will likely fail if an interface contains
|
|
|
|
|
// unexported methods from two different packages (due to cross-package
|
|
|
|
|
// interface embedding).
|
|
|
|
|
|
2021-01-24 09:59:20 -08:00
|
|
|
var n ir.Node
|
2021-02-11 10:50:20 -08:00
|
|
|
method2 := selinfo.Obj().(*types2.Func)
|
2021-01-22 13:29:59 -08:00
|
|
|
|
2021-01-24 09:59:20 -08:00
|
|
|
if kind == types2.MethodExpr {
|
|
|
|
|
// OMETHEXPR is unusual in using directly the node and type of the
|
|
|
|
|
// original OTYPE node (origx) before passing through embedded
|
|
|
|
|
// fields, even though the method is selected from the type
|
|
|
|
|
// (x.Type()) reached after following the embedded fields. We will
|
|
|
|
|
// actually drop any ODOT nodes we created due to the embedded
|
|
|
|
|
// fields.
|
|
|
|
|
n = MethodExpr(pos, origx, x.Type(), last)
|
|
|
|
|
} else {
|
|
|
|
|
// Add implicit addr/deref for method values, if needed.
|
2021-02-11 10:50:20 -08:00
|
|
|
if x.Type().IsInterface() {
|
|
|
|
|
n = DotMethod(pos, x, last)
|
|
|
|
|
} else {
|
|
|
|
|
recvType2 := method2.Type().(*types2.Signature).Recv().Type()
|
|
|
|
|
_, wantPtr := recvType2.(*types2.Pointer)
|
2021-01-24 09:59:20 -08:00
|
|
|
havePtr := x.Type().IsPtr()
|
|
|
|
|
|
|
|
|
|
if havePtr != wantPtr {
|
|
|
|
|
if havePtr {
|
|
|
|
|
x = Implicit(Deref(pos, x))
|
|
|
|
|
} else {
|
|
|
|
|
x = Implicit(Addr(pos, x))
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-11 10:50:20 -08:00
|
|
|
recvType2Base := recvType2
|
|
|
|
|
if wantPtr {
|
2021-02-18 15:09:38 -08:00
|
|
|
recvType2Base = types2.AsPointer(recvType2).Elem()
|
2021-02-11 10:50:20 -08:00
|
|
|
}
|
2021-02-18 15:09:38 -08:00
|
|
|
if len(types2.AsNamed(recvType2Base).TParams()) > 0 {
|
2021-02-11 10:50:20 -08:00
|
|
|
// recvType2 is the original generic type that is
|
|
|
|
|
// instantiated for this method call.
|
|
|
|
|
// selinfo.Recv() is the instantiated type
|
|
|
|
|
recvType2 = recvType2Base
|
|
|
|
|
// method is the generic method associated with the gen type
|
2021-02-18 15:09:38 -08:00
|
|
|
method := g.obj(types2.AsNamed(recvType2).Method(last))
|
2021-02-11 10:50:20 -08:00
|
|
|
n = ir.NewSelectorExpr(pos, ir.OCALLPART, x, method.Sym())
|
|
|
|
|
n.(*ir.SelectorExpr).Selection = types.NewField(pos, method.Sym(), method.Type())
|
|
|
|
|
n.(*ir.SelectorExpr).Selection.Nname = method
|
|
|
|
|
typed(method.Type(), n)
|
|
|
|
|
|
|
|
|
|
// selinfo.Targs() are the types used to
|
|
|
|
|
// instantiate the type of receiver
|
2021-03-04 12:09:04 -08:00
|
|
|
targs2 := getTargs(selinfo)
|
2021-02-11 10:50:20 -08:00
|
|
|
targs := make([]ir.Node, len(targs2))
|
|
|
|
|
for i, targ2 := range targs2 {
|
|
|
|
|
targs[i] = ir.TypeNode(g.typ(targ2))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create function instantiation with the type
|
|
|
|
|
// args for the receiver type for the method call.
|
|
|
|
|
n = ir.NewInstExpr(pos, ir.OFUNCINST, n, targs)
|
|
|
|
|
typed(g.typ(typ), n)
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !g.match(x.Type(), recvType2, false) {
|
|
|
|
|
base.FatalfAt(pos, "expected %L to have type %v", x, recvType2)
|
|
|
|
|
} else {
|
|
|
|
|
n = DotMethod(pos, x, last)
|
2021-01-19 13:54:33 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-11 10:50:20 -08:00
|
|
|
if have, want := n.Sym(), g.selector(method2); have != want {
|
2021-01-22 13:29:59 -08:00
|
|
|
base.FatalfAt(pos, "bad Sym: have %v, want %v", have, want)
|
|
|
|
|
}
|
|
|
|
|
return n
|
2021-01-19 13:54:33 -08:00
|
|
|
}
|
|
|
|
|
|
2021-03-04 12:09:04 -08:00
|
|
|
// getTargs gets the targs associated with the receiver of a selected method
|
|
|
|
|
func getTargs(selinfo *types2.Selection) []types2.Type {
|
|
|
|
|
r := selinfo.Recv()
|
|
|
|
|
if p := types2.AsPointer(r); p != nil {
|
|
|
|
|
r = p.Elem()
|
|
|
|
|
}
|
|
|
|
|
n := types2.AsNamed(r)
|
|
|
|
|
if n == nil {
|
|
|
|
|
base.Fatalf("Incorrect type for selinfo %v", selinfo)
|
|
|
|
|
}
|
|
|
|
|
return n.TArgs()
|
|
|
|
|
}
|
|
|
|
|
|
[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2
to guide IR construction. Notably, it completely skips dealing with
constant and type expressions (aside from using ir.TypeNode to
interoperate with the types1 typechecker), because types2 already
handled those. It also omits any syntax checking, trusting that types2
already rejected any errors.
It currently still utilizes the types1 typechecker for the desugaring
operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting
implicit conversions, rewriting f(g()) functions, and so on). However,
the IR is constructed in a fully incremental fashion, so it should be
easy to now piecemeal replace those dependencies as needed.
Nearly all of "go test std cmd" passes with -G=3 enabled by
default. The main remaining blocker is the number of test/run.go
failures. There also appear to be cases where types2 does not provide
us with position information. These will be iterated upon.
Portions and ideas from Dan Scales's CL 276653.
Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281932
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-01-09 00:57:55 -08:00
|
|
|
func (g *irgen) exprList(expr syntax.Expr) []ir.Node {
|
|
|
|
|
switch expr := expr.(type) {
|
|
|
|
|
case nil:
|
|
|
|
|
return nil
|
|
|
|
|
case *syntax.ListExpr:
|
|
|
|
|
return g.exprs(expr.ElemList)
|
|
|
|
|
default:
|
|
|
|
|
return []ir.Node{g.expr(expr)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *irgen) exprs(exprs []syntax.Expr) []ir.Node {
|
|
|
|
|
nodes := make([]ir.Node, len(exprs))
|
|
|
|
|
for i, expr := range exprs {
|
|
|
|
|
nodes[i] = g.expr(expr)
|
|
|
|
|
}
|
|
|
|
|
return nodes
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *irgen) compLit(typ types2.Type, lit *syntax.CompositeLit) ir.Node {
|
|
|
|
|
if ptr, ok := typ.Underlying().(*types2.Pointer); ok {
|
2021-01-20 12:54:23 -08:00
|
|
|
n := ir.NewAddrExpr(g.pos(lit), g.compLit(ptr.Elem(), lit))
|
|
|
|
|
n.SetOp(ir.OPTRLIT)
|
|
|
|
|
return typed(g.typ(typ), n)
|
[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2
to guide IR construction. Notably, it completely skips dealing with
constant and type expressions (aside from using ir.TypeNode to
interoperate with the types1 typechecker), because types2 already
handled those. It also omits any syntax checking, trusting that types2
already rejected any errors.
It currently still utilizes the types1 typechecker for the desugaring
operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting
implicit conversions, rewriting f(g()) functions, and so on). However,
the IR is constructed in a fully incremental fashion, so it should be
easy to now piecemeal replace those dependencies as needed.
Nearly all of "go test std cmd" passes with -G=3 enabled by
default. The main remaining blocker is the number of test/run.go
failures. There also appear to be cases where types2 does not provide
us with position information. These will be iterated upon.
Portions and ideas from Dan Scales's CL 276653.
Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281932
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-01-09 00:57:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, isStruct := typ.Underlying().(*types2.Struct)
|
|
|
|
|
|
|
|
|
|
exprs := make([]ir.Node, len(lit.ElemList))
|
|
|
|
|
for i, elem := range lit.ElemList {
|
|
|
|
|
switch elem := elem.(type) {
|
|
|
|
|
case *syntax.KeyValueExpr:
|
|
|
|
|
if isStruct {
|
|
|
|
|
exprs[i] = ir.NewStructKeyExpr(g.pos(elem), g.name(elem.Key.(*syntax.Name)), g.expr(elem.Value))
|
|
|
|
|
} else {
|
|
|
|
|
exprs[i] = ir.NewKeyExpr(g.pos(elem), g.expr(elem.Key), g.expr(elem.Value))
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
exprs[i] = g.expr(elem)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 12:54:23 -08:00
|
|
|
// TODO(mdempsky): Remove dependency on typecheck.Expr.
|
|
|
|
|
return typecheck.Expr(ir.NewCompLitExpr(g.pos(lit), ir.OCOMPLIT, ir.TypeNode(g.typ(typ)), exprs))
|
[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2
to guide IR construction. Notably, it completely skips dealing with
constant and type expressions (aside from using ir.TypeNode to
interoperate with the types1 typechecker), because types2 already
handled those. It also omits any syntax checking, trusting that types2
already rejected any errors.
It currently still utilizes the types1 typechecker for the desugaring
operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting
implicit conversions, rewriting f(g()) functions, and so on). However,
the IR is constructed in a fully incremental fashion, so it should be
easy to now piecemeal replace those dependencies as needed.
Nearly all of "go test std cmd" passes with -G=3 enabled by
default. The main remaining blocker is the number of test/run.go
failures. There also appear to be cases where types2 does not provide
us with position information. These will be iterated upon.
Portions and ideas from Dan Scales's CL 276653.
Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281932
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-01-09 00:57:55 -08:00
|
|
|
}
|
|
|
|
|
|
2021-02-21 10:54:38 -08:00
|
|
|
func (g *irgen) funcLit(typ2 types2.Type, expr *syntax.FuncLit) ir.Node {
|
[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2
to guide IR construction. Notably, it completely skips dealing with
constant and type expressions (aside from using ir.TypeNode to
interoperate with the types1 typechecker), because types2 already
handled those. It also omits any syntax checking, trusting that types2
already rejected any errors.
It currently still utilizes the types1 typechecker for the desugaring
operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting
implicit conversions, rewriting f(g()) functions, and so on). However,
the IR is constructed in a fully incremental fashion, so it should be
easy to now piecemeal replace those dependencies as needed.
Nearly all of "go test std cmd" passes with -G=3 enabled by
default. The main remaining blocker is the number of test/run.go
failures. There also appear to be cases where types2 does not provide
us with position information. These will be iterated upon.
Portions and ideas from Dan Scales's CL 276653.
Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281932
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-01-09 00:57:55 -08:00
|
|
|
fn := ir.NewFunc(g.pos(expr))
|
|
|
|
|
fn.SetIsHiddenClosure(ir.CurFunc != nil)
|
|
|
|
|
|
|
|
|
|
fn.Nname = ir.NewNameAt(g.pos(expr), typecheck.ClosureName(ir.CurFunc))
|
|
|
|
|
ir.MarkFunc(fn.Nname)
|
2021-02-21 10:54:38 -08:00
|
|
|
typ := g.typ(typ2)
|
[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2
to guide IR construction. Notably, it completely skips dealing with
constant and type expressions (aside from using ir.TypeNode to
interoperate with the types1 typechecker), because types2 already
handled those. It also omits any syntax checking, trusting that types2
already rejected any errors.
It currently still utilizes the types1 typechecker for the desugaring
operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting
implicit conversions, rewriting f(g()) functions, and so on). However,
the IR is constructed in a fully incremental fashion, so it should be
easy to now piecemeal replace those dependencies as needed.
Nearly all of "go test std cmd" passes with -G=3 enabled by
default. The main remaining blocker is the number of test/run.go
failures. There also appear to be cases where types2 does not provide
us with position information. These will be iterated upon.
Portions and ideas from Dan Scales's CL 276653.
Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281932
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-01-09 00:57:55 -08:00
|
|
|
fn.Nname.Func = fn
|
|
|
|
|
fn.Nname.Defn = fn
|
2021-02-21 10:54:38 -08:00
|
|
|
// Set Ntype for now to be compatible with later parts of compile, remove later.
|
|
|
|
|
fn.Nname.Ntype = ir.TypeNode(typ)
|
|
|
|
|
typed(typ, fn.Nname)
|
|
|
|
|
fn.SetTypecheck(1)
|
[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2
to guide IR construction. Notably, it completely skips dealing with
constant and type expressions (aside from using ir.TypeNode to
interoperate with the types1 typechecker), because types2 already
handled those. It also omits any syntax checking, trusting that types2
already rejected any errors.
It currently still utilizes the types1 typechecker for the desugaring
operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting
implicit conversions, rewriting f(g()) functions, and so on). However,
the IR is constructed in a fully incremental fashion, so it should be
easy to now piecemeal replace those dependencies as needed.
Nearly all of "go test std cmd" passes with -G=3 enabled by
default. The main remaining blocker is the number of test/run.go
failures. There also appear to be cases where types2 does not provide
us with position information. These will be iterated upon.
Portions and ideas from Dan Scales's CL 276653.
Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281932
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-01-09 00:57:55 -08:00
|
|
|
|
|
|
|
|
fn.OClosure = ir.NewClosureExpr(g.pos(expr), fn)
|
2021-02-21 10:54:38 -08:00
|
|
|
typed(typ, fn.OClosure)
|
[dev.typeparams] cmd/compile: add types2-based noder
This CL adds "irgen", a new noding implementation that utilizes types2
to guide IR construction. Notably, it completely skips dealing with
constant and type expressions (aside from using ir.TypeNode to
interoperate with the types1 typechecker), because types2 already
handled those. It also omits any syntax checking, trusting that types2
already rejected any errors.
It currently still utilizes the types1 typechecker for the desugaring
operations it handles (e.g., turning OAS2 into OAS2FUNC/etc, inserting
implicit conversions, rewriting f(g()) functions, and so on). However,
the IR is constructed in a fully incremental fashion, so it should be
easy to now piecemeal replace those dependencies as needed.
Nearly all of "go test std cmd" passes with -G=3 enabled by
default. The main remaining blocker is the number of test/run.go
failures. There also appear to be cases where types2 does not provide
us with position information. These will be iterated upon.
Portions and ideas from Dan Scales's CL 276653.
Change-Id: Ic99e8f2d0267b0312d30c10d5d043f5817a59c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281932
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-01-09 00:57:55 -08:00
|
|
|
|
|
|
|
|
g.funcBody(fn, nil, expr.Type, expr.Body)
|
|
|
|
|
|
|
|
|
|
ir.FinishCaptureNames(fn.Pos(), ir.CurFunc, fn)
|
|
|
|
|
|
|
|
|
|
// TODO(mdempsky): ir.CaptureName should probably handle
|
|
|
|
|
// copying these fields from the canonical variable.
|
|
|
|
|
for _, cv := range fn.ClosureVars {
|
|
|
|
|
cv.SetType(cv.Canonical().Type())
|
|
|
|
|
cv.SetTypecheck(1)
|
|
|
|
|
cv.SetWalkdef(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g.target.Decls = append(g.target.Decls, fn)
|
|
|
|
|
|
|
|
|
|
return fn.OClosure
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *irgen) typeExpr(typ syntax.Expr) *types.Type {
|
|
|
|
|
n := g.expr(typ)
|
|
|
|
|
if n.Op() != ir.OTYPE {
|
|
|
|
|
base.FatalfAt(g.pos(typ), "expected type: %L", n)
|
|
|
|
|
}
|
|
|
|
|
return n.Type()
|
|
|
|
|
}
|