mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: allow delaying of transformCompLit, new transformAddr
For this unusual case, where a constraint specifies exactly one type, we can have a COMPLIT expression with a type that is/has typeparams. Therefore, we add code to delay transformCompLit for generic functions. We also need to break out transformAddr (which corresponds to tcAddr), and added code for delaying it as well. Also, we now need to export generic functions containing untransformed OCOMPLIT and OKEY nodes, so added support for that in iexport.go/iimport.go. Untransformed OKEY nodes include an ir.Ident/ONONAME which we can now export. Had to adjust some code/asserts in transformCompLit(), since we may now be transforming an OCOMPLIT from an imported generic function (i.e. from a non-local package). Fixes #48537 Change-Id: I09e1b3bd08b4e013c0b098b8a25d082efa1fef51 Reviewed-on: https://go-review.googlesource.com/c/go/+/354354 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Dan Scales <danscales@google.com> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
99c1b249b1
commit
0d838ea5a2
7 changed files with 80 additions and 11 deletions
|
|
@ -154,7 +154,11 @@ func (g *irgen) expr0(typ types2.Type, expr syntax.Expr) ir.Node {
|
|||
|
||||
case *syntax.Operation:
|
||||
if expr.Y == nil {
|
||||
return Unary(pos, g.typ(typ), g.op(expr.Op, unOps[:]), g.expr(expr.X))
|
||||
n := Unary(pos, g.typ(typ), g.op(expr.Op, unOps[:]), g.expr(expr.X))
|
||||
if n.Op() == ir.OADDR && !g.delayTransform() {
|
||||
transformAddr(n.(*ir.AddrExpr))
|
||||
}
|
||||
return n
|
||||
}
|
||||
switch op := g.op(expr.Op, binOps[:]); op {
|
||||
case ir.OEQ, ir.ONE, ir.OLT, ir.OLE, ir.OGT, ir.OGE:
|
||||
|
|
@ -353,15 +357,27 @@ func (g *irgen) compLit(typ types2.Type, lit *syntax.CompositeLit) ir.Node {
|
|||
key = g.expr(elem.Key)
|
||||
}
|
||||
value := wrapname(g.pos(elem.Value), g.expr(elem.Value))
|
||||
if value.Op() == ir.OPAREN {
|
||||
// Make sure any PAREN node added by wrapper has a type
|
||||
typed(value.(*ir.ParenExpr).X.Type(), value)
|
||||
}
|
||||
exprs[i] = ir.NewKeyExpr(g.pos(elem), key, value)
|
||||
default:
|
||||
exprs[i] = wrapname(g.pos(elem), g.expr(elem))
|
||||
if exprs[i].Op() == ir.OPAREN {
|
||||
// Make sure any PAREN node added by wrapper has a type
|
||||
typed(exprs[i].(*ir.ParenExpr).X.Type(), exprs[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
n := ir.NewCompLitExpr(g.pos(lit), ir.OCOMPLIT, nil, exprs)
|
||||
typed(g.typ(typ), n)
|
||||
return transformCompLit(n)
|
||||
var r ir.Node = n
|
||||
if !g.delayTransform() {
|
||||
r = transformCompLit(n)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (g *irgen) funcLit(typ2 types2.Type, expr *syntax.FuncLit) ir.Node {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue