[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/ir"
|
|
|
|
|
"cmd/compile/internal/syntax"
|
|
|
|
|
"cmd/compile/internal/typecheck"
|
|
|
|
|
"cmd/compile/internal/types"
|
|
|
|
|
"cmd/internal/src"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (g *irgen) stmts(stmts []syntax.Stmt) []ir.Node {
|
|
|
|
|
var nodes []ir.Node
|
|
|
|
|
for _, stmt := range stmts {
|
|
|
|
|
switch s := g.stmt(stmt).(type) {
|
|
|
|
|
case nil: // EmptyStmt
|
|
|
|
|
case *ir.BlockStmt:
|
|
|
|
|
nodes = append(nodes, s.List...)
|
|
|
|
|
default:
|
|
|
|
|
nodes = append(nodes, s)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nodes
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *irgen) stmt(stmt syntax.Stmt) ir.Node {
|
|
|
|
|
switch stmt := stmt.(type) {
|
|
|
|
|
case nil, *syntax.EmptyStmt:
|
|
|
|
|
return nil
|
|
|
|
|
case *syntax.LabeledStmt:
|
|
|
|
|
return g.labeledStmt(stmt)
|
|
|
|
|
case *syntax.BlockStmt:
|
|
|
|
|
return ir.NewBlockStmt(g.pos(stmt), g.blockStmt(stmt))
|
|
|
|
|
case *syntax.ExprStmt:
|
2021-07-03 05:27:54 -07:00
|
|
|
return g.expr(stmt.X)
|
[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.SendStmt:
|
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
|
|
|
n := ir.NewSendStmt(g.pos(stmt), g.expr(stmt.Chan), g.expr(stmt.Value))
|
2021-03-29 08:28:01 -07:00
|
|
|
if n.Chan.Type().HasTParam() || n.Value.Type().HasTParam() {
|
|
|
|
|
// Delay transforming the send if the channel or value
|
|
|
|
|
// have a type param.
|
|
|
|
|
n.SetTypecheck(3)
|
|
|
|
|
return n
|
|
|
|
|
}
|
2021-03-23 10:19:11 -07:00
|
|
|
transformSend(n)
|
|
|
|
|
n.SetTypecheck(1)
|
|
|
|
|
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.DeclStmt:
|
|
|
|
|
return ir.NewBlockStmt(g.pos(stmt), g.decls(stmt.DeclList))
|
|
|
|
|
|
|
|
|
|
case *syntax.AssignStmt:
|
|
|
|
|
if stmt.Op != 0 && stmt.Op != syntax.Def {
|
|
|
|
|
op := g.op(stmt.Op, binOps[:])
|
2021-03-23 10:19:11 -07:00
|
|
|
var n *ir.AssignOpStmt
|
2021-01-20 17:03:36 -08:00
|
|
|
if stmt.Rhs == nil {
|
2021-03-23 10:19:11 -07:00
|
|
|
n = IncDec(g.pos(stmt), op, g.expr(stmt.Lhs))
|
|
|
|
|
} else {
|
|
|
|
|
n = ir.NewAssignOpStmt(g.pos(stmt), op, g.expr(stmt.Lhs), g.expr(stmt.Rhs))
|
[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-03-23 10:19:11 -07:00
|
|
|
if n.X.Typecheck() == 3 {
|
|
|
|
|
n.SetTypecheck(3)
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
transformAsOp(n)
|
|
|
|
|
n.SetTypecheck(1)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2021-01-22 01:46:42 -08:00
|
|
|
names, lhs := g.assignList(stmt.Lhs, stmt.Op == syntax.Def)
|
[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
|
|
|
rhs := g.exprList(stmt.Rhs)
|
2021-01-22 01:46:42 -08:00
|
|
|
|
2021-03-23 10:19:11 -07:00
|
|
|
// We must delay transforming the assign statement if any of the
|
|
|
|
|
// lhs or rhs nodes are also delayed, since transformAssign needs
|
|
|
|
|
// to know the types of the left and right sides in various cases.
|
|
|
|
|
delay := false
|
|
|
|
|
for _, e := range lhs {
|
|
|
|
|
if e.Typecheck() == 3 {
|
|
|
|
|
delay = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for _, e := range rhs {
|
|
|
|
|
if e.Typecheck() == 3 {
|
|
|
|
|
delay = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-22 01:46:42 -08:00
|
|
|
if len(lhs) == 1 && len(rhs) == 1 {
|
|
|
|
|
n := ir.NewAssignStmt(g.pos(stmt), lhs[0], rhs[0])
|
|
|
|
|
n.Def = initDefn(n, names)
|
2021-03-23 10:19:11 -07:00
|
|
|
|
|
|
|
|
if delay {
|
|
|
|
|
n.SetTypecheck(3)
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lhs, rhs := []ir.Node{n.X}, []ir.Node{n.Y}
|
|
|
|
|
transformAssign(n, lhs, rhs)
|
|
|
|
|
n.X, n.Y = lhs[0], rhs[0]
|
|
|
|
|
n.SetTypecheck(1)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2021-01-22 01:46:42 -08:00
|
|
|
n := ir.NewAssignListStmt(g.pos(stmt), ir.OAS2, lhs, rhs)
|
|
|
|
|
n.Def = initDefn(n, names)
|
2021-03-23 10:19:11 -07:00
|
|
|
if delay {
|
|
|
|
|
n.SetTypecheck(3)
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
transformAssign(n, n.Lhs, n.Rhs)
|
|
|
|
|
n.SetTypecheck(1)
|
|
|
|
|
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.BranchStmt:
|
|
|
|
|
return ir.NewBranchStmt(g.pos(stmt), g.tokOp(int(stmt.Tok), branchOps[:]), g.name(stmt.Label))
|
|
|
|
|
case *syntax.CallStmt:
|
|
|
|
|
return ir.NewGoDeferStmt(g.pos(stmt), g.tokOp(int(stmt.Tok), callOps[:]), g.expr(stmt.Call))
|
|
|
|
|
case *syntax.ReturnStmt:
|
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
|
|
|
n := ir.NewReturnStmt(g.pos(stmt), g.exprList(stmt.Results))
|
2021-03-29 08:28:01 -07:00
|
|
|
for _, e := range n.Results {
|
|
|
|
|
if e.Type().HasTParam() {
|
|
|
|
|
// Delay transforming the return statement if any of the
|
|
|
|
|
// return values have a type param.
|
|
|
|
|
n.SetTypecheck(3)
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-23 10:19:11 -07:00
|
|
|
transformReturn(n)
|
|
|
|
|
n.SetTypecheck(1)
|
|
|
|
|
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.IfStmt:
|
|
|
|
|
return g.ifStmt(stmt)
|
|
|
|
|
case *syntax.ForStmt:
|
|
|
|
|
return g.forStmt(stmt)
|
|
|
|
|
case *syntax.SelectStmt:
|
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
|
|
|
n := g.selectStmt(stmt)
|
2021-03-23 10:19:11 -07:00
|
|
|
transformSelect(n.(*ir.SelectStmt))
|
|
|
|
|
n.SetTypecheck(1)
|
|
|
|
|
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.SwitchStmt:
|
|
|
|
|
return g.switchStmt(stmt)
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
g.unhandled("statement", stmt)
|
|
|
|
|
panic("unreachable")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO(mdempsky): Investigate replacing with switch statements or dense arrays.
|
|
|
|
|
|
|
|
|
|
var branchOps = [...]ir.Op{
|
|
|
|
|
syntax.Break: ir.OBREAK,
|
|
|
|
|
syntax.Continue: ir.OCONTINUE,
|
|
|
|
|
syntax.Fallthrough: ir.OFALL,
|
|
|
|
|
syntax.Goto: ir.OGOTO,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var callOps = [...]ir.Op{
|
|
|
|
|
syntax.Defer: ir.ODEFER,
|
|
|
|
|
syntax.Go: ir.OGO,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *irgen) tokOp(tok int, ops []ir.Op) ir.Op {
|
|
|
|
|
// TODO(mdempsky): Validate.
|
|
|
|
|
return ops[tok]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *irgen) op(op syntax.Operator, ops []ir.Op) ir.Op {
|
|
|
|
|
// TODO(mdempsky): Validate.
|
|
|
|
|
return ops[op]
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-22 01:46:42 -08:00
|
|
|
func (g *irgen) assignList(expr syntax.Expr, def bool) ([]*ir.Name, []ir.Node) {
|
|
|
|
|
if !def {
|
|
|
|
|
return nil, g.exprList(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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var exprs []syntax.Expr
|
|
|
|
|
if list, ok := expr.(*syntax.ListExpr); ok {
|
|
|
|
|
exprs = list.ElemList
|
|
|
|
|
} else {
|
|
|
|
|
exprs = []syntax.Expr{expr}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-22 01:46:42 -08:00
|
|
|
var names []*ir.Name
|
[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
|
|
|
res := make([]ir.Node, len(exprs))
|
|
|
|
|
for i, expr := range exprs {
|
|
|
|
|
expr := expr.(*syntax.Name)
|
|
|
|
|
if expr.Value == "_" {
|
|
|
|
|
res[i] = ir.BlankNode
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if obj, ok := g.info.Uses[expr]; ok {
|
|
|
|
|
res[i] = g.obj(obj)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
name, _ := g.def(expr)
|
2021-01-22 01:46:42 -08:00
|
|
|
names = append(names, name)
|
[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
|
|
|
res[i] = name
|
|
|
|
|
}
|
2021-01-22 01:46:42 -08:00
|
|
|
|
|
|
|
|
return names, res
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// initDefn marks the given names as declared by defn and populates
|
|
|
|
|
// its Init field with ODCL nodes. It then reports whether any names
|
|
|
|
|
// were so declared, which can be used to initialize defn.Def.
|
|
|
|
|
func initDefn(defn ir.InitNode, names []*ir.Name) bool {
|
|
|
|
|
if len(names) == 0 {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init := make([]ir.Node, len(names))
|
|
|
|
|
for i, name := range names {
|
|
|
|
|
name.Defn = defn
|
|
|
|
|
init[i] = ir.NewDecl(name.Pos(), ir.ODCL, name)
|
|
|
|
|
}
|
|
|
|
|
defn.SetInit(init)
|
|
|
|
|
return true
|
[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) blockStmt(stmt *syntax.BlockStmt) []ir.Node {
|
|
|
|
|
return g.stmts(stmt.List)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *irgen) ifStmt(stmt *syntax.IfStmt) ir.Node {
|
|
|
|
|
init := g.stmt(stmt.Init)
|
|
|
|
|
n := ir.NewIfStmt(g.pos(stmt), g.expr(stmt.Cond), g.blockStmt(stmt.Then), nil)
|
|
|
|
|
if stmt.Else != nil {
|
|
|
|
|
e := g.stmt(stmt.Else)
|
|
|
|
|
if e.Op() == ir.OBLOCK {
|
|
|
|
|
e := e.(*ir.BlockStmt)
|
|
|
|
|
n.Else = e.List
|
|
|
|
|
} else {
|
|
|
|
|
n.Else = []ir.Node{e}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return g.init(init, n)
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-22 01:46:42 -08:00
|
|
|
// unpackTwo returns the first two nodes in list. If list has fewer
|
|
|
|
|
// than 2 nodes, then the missing nodes are replaced with nils.
|
|
|
|
|
func unpackTwo(list []ir.Node) (fst, snd ir.Node) {
|
|
|
|
|
switch len(list) {
|
|
|
|
|
case 0:
|
|
|
|
|
return nil, nil
|
|
|
|
|
case 1:
|
|
|
|
|
return list[0], nil
|
|
|
|
|
default:
|
|
|
|
|
return list[0], list[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
|
|
|
func (g *irgen) forStmt(stmt *syntax.ForStmt) ir.Node {
|
|
|
|
|
if r, ok := stmt.Init.(*syntax.RangeClause); ok {
|
2021-01-22 01:46:42 -08:00
|
|
|
names, lhs := g.assignList(r.Lhs, r.Def)
|
|
|
|
|
key, value := unpackTwo(lhs)
|
|
|
|
|
n := ir.NewRangeStmt(g.pos(r), key, value, g.expr(r.X), g.blockStmt(stmt.Body))
|
|
|
|
|
n.Def = initDefn(n, names)
|
[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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ir.NewForStmt(g.pos(stmt), g.stmt(stmt.Init), g.expr(stmt.Cond), g.stmt(stmt.Post), g.blockStmt(stmt.Body))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *irgen) selectStmt(stmt *syntax.SelectStmt) ir.Node {
|
|
|
|
|
body := make([]*ir.CommClause, len(stmt.Body))
|
|
|
|
|
for i, clause := range stmt.Body {
|
|
|
|
|
body[i] = ir.NewCommStmt(g.pos(clause), g.stmt(clause.Comm), g.stmts(clause.Body))
|
|
|
|
|
}
|
|
|
|
|
return ir.NewSelectStmt(g.pos(stmt), body)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *irgen) switchStmt(stmt *syntax.SwitchStmt) ir.Node {
|
|
|
|
|
pos := g.pos(stmt)
|
|
|
|
|
init := g.stmt(stmt.Init)
|
|
|
|
|
|
|
|
|
|
var expr ir.Node
|
|
|
|
|
switch tag := stmt.Tag.(type) {
|
|
|
|
|
case *syntax.TypeSwitchGuard:
|
|
|
|
|
var ident *ir.Ident
|
|
|
|
|
if tag.Lhs != nil {
|
|
|
|
|
ident = ir.NewIdent(g.pos(tag.Lhs), g.name(tag.Lhs))
|
|
|
|
|
}
|
|
|
|
|
expr = ir.NewTypeSwitchGuard(pos, ident, g.expr(tag.X))
|
|
|
|
|
default:
|
|
|
|
|
expr = g.expr(tag)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
body := make([]*ir.CaseClause, len(stmt.Body))
|
|
|
|
|
for i, clause := range stmt.Body {
|
|
|
|
|
// Check for an implicit clause variable before
|
|
|
|
|
// visiting body, because it may contain function
|
|
|
|
|
// literals that reference it, and then it'll be
|
|
|
|
|
// associated to the wrong function.
|
|
|
|
|
//
|
|
|
|
|
// Also, override its position to the clause's colon, so that
|
|
|
|
|
// dwarfgen can find the right scope for it later.
|
|
|
|
|
// TODO(mdempsky): We should probably just store the scope
|
|
|
|
|
// directly in the ir.Name.
|
|
|
|
|
var cv *ir.Name
|
|
|
|
|
if obj, ok := g.info.Implicits[clause]; ok {
|
|
|
|
|
cv = g.obj(obj)
|
|
|
|
|
cv.SetPos(g.makeXPos(clause.Colon))
|
|
|
|
|
}
|
|
|
|
|
body[i] = ir.NewCaseStmt(g.pos(clause), g.exprList(clause.Cases), g.stmts(clause.Body))
|
|
|
|
|
body[i].Var = cv
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return g.init(init, ir.NewSwitchStmt(pos, expr, body))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *irgen) labeledStmt(label *syntax.LabeledStmt) ir.Node {
|
|
|
|
|
sym := g.name(label.Label)
|
|
|
|
|
lhs := ir.NewLabelStmt(g.pos(label), sym)
|
|
|
|
|
ls := g.stmt(label.Stmt)
|
|
|
|
|
|
|
|
|
|
// Attach label directly to control statement too.
|
|
|
|
|
switch ls := ls.(type) {
|
|
|
|
|
case *ir.ForStmt:
|
|
|
|
|
ls.Label = sym
|
|
|
|
|
case *ir.RangeStmt:
|
|
|
|
|
ls.Label = sym
|
|
|
|
|
case *ir.SelectStmt:
|
|
|
|
|
ls.Label = sym
|
|
|
|
|
case *ir.SwitchStmt:
|
|
|
|
|
ls.Label = sym
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
l := []ir.Node{lhs}
|
|
|
|
|
if ls != nil {
|
|
|
|
|
if ls.Op() == ir.OBLOCK {
|
|
|
|
|
ls := ls.(*ir.BlockStmt)
|
|
|
|
|
l = append(l, ls.List...)
|
|
|
|
|
} else {
|
|
|
|
|
l = append(l, ls)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ir.NewBlockStmt(src.NoXPos, l)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *irgen) init(init ir.Node, stmt ir.InitNode) ir.InitNode {
|
|
|
|
|
if init != nil {
|
|
|
|
|
stmt.SetInit([]ir.Node{init})
|
|
|
|
|
}
|
|
|
|
|
return stmt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *irgen) name(name *syntax.Name) *types.Sym {
|
|
|
|
|
if name == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return typecheck.Lookup(name.Value)
|
|
|
|
|
}
|