diff options
| author | Matthew Dempsky <mdempsky@google.com> | 2022-06-21 00:57:18 -0700 |
|---|---|---|
| committer | Matthew Dempsky <mdempsky@google.com> | 2022-06-23 21:52:45 +0000 |
| commit | 7368647ac6eecd57a476616ff1f3ac1aa7f445b6 (patch) | |
| tree | 5a61c96f3727a9d71481579bc33dbc575409d38d /src/cmd/compile/internal/noder/reader.go | |
| parent | 5960f4ec10e175714145d5ffa1b37d282b7a2157 (diff) | |
| download | go-7368647ac6eecd57a476616ff1f3ac1aa7f445b6.tar.xz | |
[dev.unified] cmd/compile: start setting RType fields for Unified IR
This CL switches the GOEXPERIMENT=unified frontend to set RType fields
in the simpler cases, and to make it fatal if they're missing.
Subsequent CLs will handle the remaining more complex cases (e.g.,
expressions from later desugaring, and implicit conversions to
interface type).
Change-Id: If6257dcb3916905afd9b8371ea64b85f108ebbfb
Reviewed-on: https://go-review.googlesource.com/c/go/+/413359
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/cmd/compile/internal/noder/reader.go')
| -rw-r--r-- | src/cmd/compile/internal/noder/reader.go | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index 5ebc776605..7588e52d96 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -1390,6 +1390,9 @@ func (r *reader) forStmt(label *types.Sym) ir.Node { r.closeAnotherScope() rang := ir.NewRangeStmt(pos, nil, nil, x, body) + if x.Type().IsMap() { + rang.RType = reflectdata.TypePtrAt(pos, x.Type()) + } if len(lhs) >= 1 { rang.Key = lhs[0] if len(lhs) >= 2 { @@ -1632,7 +1635,13 @@ func (r *reader) expr() (res ir.Node) { x := r.expr() pos := r.pos() index := r.expr() - return typecheck.Expr(ir.NewIndexExpr(pos, x, index)) + n := typecheck.Expr(ir.NewIndexExpr(pos, x, index)) + switch n.Op() { + case ir.OINDEXMAP: + n := n.(*ir.IndexExpr) + n.RType = reflectdata.TypePtrAt(pos, x.Type()) + } + return n case exprSlice: x := r.expr() @@ -1654,6 +1663,7 @@ func (r *reader) expr() (res ir.Node) { if typ, ok := typ.(*ir.DynamicType); ok && typ.Op() == ir.ODYNAMICTYPE { assert := ir.NewDynamicTypeAssertExpr(pos, ir.ODYNAMICDOTTYPE, x, typ.RType) + assert.SrcRType = reflectdata.TypePtrAt(pos, x.Type()) assert.ITab = typ.ITab return typed(typ.Type(), assert) } @@ -1682,7 +1692,19 @@ func (r *reader) expr() (res ir.Node) { case ir.OANDAND, ir.OOROR: return typecheck.Expr(ir.NewLogicalExpr(pos, op, x, y)) } - return typecheck.Expr(ir.NewBinaryExpr(pos, op, x, y)) + n := typecheck.Expr(ir.NewBinaryExpr(pos, op, x, y)) + switch n.Op() { + case ir.OEQ, ir.ONE: + n := n.(*ir.BinaryExpr) + if n.X.Type().IsInterface() != n.Y.Type().IsInterface() { + typ := n.X.Type() + if typ.IsInterface() { + typ = n.Y.Type() + } + n.RType = reflectdata.TypePtrAt(pos, typ) + } + } + return n case exprCall: fun := r.expr() @@ -1694,13 +1716,37 @@ func (r *reader) expr() (res ir.Node) { pos := r.pos() args := r.exprs() dots := r.Bool() - return typecheck.Call(pos, fun, args, dots) + n := typecheck.Call(pos, fun, args, dots) + switch n.Op() { + case ir.OAPPEND: + n := n.(*ir.CallExpr) + n.RType = reflectdata.TypePtrAt(pos, n.Type().Elem()) + case ir.OCOPY: + n := n.(*ir.BinaryExpr) + n.RType = reflectdata.TypePtrAt(pos, n.X.Type().Elem()) + case ir.ODELETE: + n := n.(*ir.CallExpr) + n.RType = reflectdata.TypePtrAt(pos, n.Args[0].Type()) + case ir.OUNSAFESLICE: + n := n.(*ir.BinaryExpr) + n.RType = reflectdata.TypePtrAt(pos, n.Type().Elem()) + } + return n case exprMake: pos := r.pos() typ := r.exprType(false) extra := r.exprs() - return typecheck.Expr(ir.NewCallExpr(pos, ir.OMAKE, nil, append([]ir.Node{typ}, extra...))) + n := typecheck.Expr(ir.NewCallExpr(pos, ir.OMAKE, nil, append([]ir.Node{typ}, extra...))).(*ir.MakeExpr) + switch n.Op() { + case ir.OMAKECHAN: + n.RType = reflectdata.TypePtrAt(pos, typ.Type()) + case ir.OMAKEMAP: + n.RType = reflectdata.TypePtrAt(pos, typ.Type()) + case ir.OMAKESLICE: + n.RType = reflectdata.TypePtrAt(pos, typ.Type().Elem()) + } + return n case exprNew: pos := r.pos() |
