]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: desugar ORECOVER during typecheck
authorMatthew Dempsky <mdempsky@google.com>
Sat, 12 Aug 2023 00:29:08 +0000 (17:29 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 14 Aug 2023 18:44:07 +0000 (18:44 +0000)
This never belonged in escape analysis, but the non-unified generics
frontend didn't use typecheck. That frontend is gone, so now we can
desugar it earlier.

Change-Id: I70f34a851f27fce1133777c5eeca0f549fc60ede
Reviewed-on: https://go-review.googlesource.com/c/go/+/518958
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>

src/cmd/compile/internal/escape/call.go
src/cmd/compile/internal/escape/desugar.go [deleted file]
src/cmd/compile/internal/escape/expr.go
src/cmd/compile/internal/escape/stmt.go
src/cmd/compile/internal/inline/inl.go
src/cmd/compile/internal/typecheck/const.go
src/cmd/compile/internal/typecheck/func.go
src/cmd/compile/internal/typecheck/stmt.go
src/cmd/compile/internal/typecheck/typecheck.go

index c69eca1998778ad88a60b80ce11e870e04861434..704b2e9dd10c8d7b8c5ca916bf9fb457f2703b1f 100644 (file)
@@ -55,7 +55,7 @@ func (e *escape) callCommon(ks []hole, call ir.Node, init *ir.Nodes, wrapper *ir
                ir.Dump("esc", call)
                base.Fatalf("unexpected call op: %v", call.Op())
 
-       case ir.OCALLFUNC, ir.OCALLMETH, ir.OCALLINTER:
+       case ir.OCALLFUNC, ir.OCALLINTER:
                call := call.(*ir.CallExpr)
                typecheck.AssertFixedCall(call)
 
@@ -186,9 +186,8 @@ func (e *escape) callCommon(ks []hole, call ir.Node, init *ir.Nodes, wrapper *ir
                argument(e.discardHole(), &call.X)
                argument(e.discardHole(), &call.Y)
 
-       case ir.ODELETE, ir.OMAX, ir.OMIN, ir.OPRINT, ir.OPRINTN, ir.ORECOVER:
+       case ir.ODELETE, ir.OMAX, ir.OMIN, ir.OPRINT, ir.OPRINTN, ir.ORECOVERFP:
                call := call.(*ir.CallExpr)
-               fixRecoverCall(call)
                for i := range call.Args {
                        argument(e.discardHole(), &call.Args[i])
                }
diff --git a/src/cmd/compile/internal/escape/desugar.go b/src/cmd/compile/internal/escape/desugar.go
deleted file mode 100644 (file)
index b2c4294..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-// 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 escape
-
-import (
-       "cmd/compile/internal/base"
-       "cmd/compile/internal/ir"
-       "cmd/compile/internal/typecheck"
-       "cmd/compile/internal/types"
-)
-
-// TODO(mdempsky): Desugaring doesn't belong during escape analysis,
-// but for now it's the most convenient place for some rewrites.
-
-// fixRecoverCall rewrites an ORECOVER call into ORECOVERFP,
-// adding an explicit frame pointer argument.
-// If call is not an ORECOVER call, it's left unmodified.
-func fixRecoverCall(call *ir.CallExpr) {
-       if call.Op() != ir.ORECOVER {
-               return
-       }
-
-       pos := call.Pos()
-
-       // FP is equal to caller's SP plus FixedFrameSize.
-       var fp ir.Node = ir.NewCallExpr(pos, ir.OGETCALLERSP, nil, nil)
-       if off := base.Ctxt.Arch.FixedFrameSize; off != 0 {
-               fp = ir.NewBinaryExpr(fp.Pos(), ir.OADD, fp, ir.NewInt(base.Pos, off))
-       }
-       // TODO(mdempsky): Replace *int32 with unsafe.Pointer, without upsetting checkptr.
-       fp = ir.NewConvExpr(pos, ir.OCONVNOP, types.NewPtr(types.Types[types.TINT32]), fp)
-
-       call.SetOp(ir.ORECOVERFP)
-       call.Args = []ir.Node{typecheck.Expr(fp)}
-}
index e5f590ddcb8b0803a007d207be8da98f2e7b6f6b..d3f963d40a65d41db77c86047b0192521a4642ec 100644 (file)
@@ -139,7 +139,7 @@ func (e *escape) exprSkipInit(k hole, n ir.Node) {
                e.discard(n.X)
 
        case ir.OCALLMETH, ir.OCALLFUNC, ir.OCALLINTER, ir.OINLCALL,
-               ir.OLEN, ir.OCAP, ir.OMIN, ir.OMAX, ir.OCOMPLEX, ir.OREAL, ir.OIMAG, ir.OAPPEND, ir.OCOPY, ir.ORECOVER,
+               ir.OLEN, ir.OCAP, ir.OMIN, ir.OMAX, ir.OCOMPLEX, ir.OREAL, ir.OIMAG, ir.OAPPEND, ir.OCOPY, ir.ORECOVERFP,
                ir.OUNSAFEADD, ir.OUNSAFESLICE, ir.OUNSAFESTRING, ir.OUNSAFESTRINGDATA, ir.OUNSAFESLICEDATA:
                e.call([]hole{k}, n)
 
index 5ae78e35fc3b4de037edfa25d4b4e8a84ff82797..4752e561e257711ce29bb4ad59200981c417a79c 100644 (file)
@@ -182,7 +182,7 @@ func (e *escape) stmt(n ir.Node) {
                        dsts[i] = res.Nname.(*ir.Name)
                }
                e.assignList(dsts, n.Results, "return", n)
-       case ir.OCALLFUNC, ir.OCALLMETH, ir.OCALLINTER, ir.OINLCALL, ir.OCLEAR, ir.OCLOSE, ir.OCOPY, ir.ODELETE, ir.OPANIC, ir.OPRINT, ir.OPRINTN, ir.ORECOVER:
+       case ir.OCALLFUNC, ir.OCALLMETH, ir.OCALLINTER, ir.OINLCALL, ir.OCLEAR, ir.OCLOSE, ir.OCOPY, ir.ODELETE, ir.OPANIC, ir.OPRINT, ir.OPRINTN, ir.ORECOVERFP:
                e.call(nil, n)
        case ir.OGO, ir.ODEFER:
                n := n.(*ir.GoDeferStmt)
index dfafd50dad5d70b183746b95afa84919839cb972..9003cbab7023f25e9d77b6bebf58aaf16ebd8904 100644 (file)
@@ -626,6 +626,8 @@ func (v *hairyVisitor) doNode(n ir.Node) bool {
                v.budget -= inlineExtraPanicCost
 
        case ir.ORECOVER:
+               base.FatalfAt(n.Pos(), "ORECOVER missed typecheck")
+       case ir.ORECOVERFP:
                // recover matches the argument frame pointer to find
                // the right panic value, so it needs an argument frame.
                v.reason = "call to recover"
index f56d330e7fc693dd39f64946bea2e740934e6d0e..7ef913236e5f8bbd0c67bcf53b2ba9b0426db3d7 100644 (file)
@@ -518,6 +518,7 @@ func callOrChan(n ir.Node) bool {
                ir.OPRINTN,
                ir.OREAL,
                ir.ORECOVER,
+               ir.ORECOVERFP,
                ir.ORECV,
                ir.OUNSAFEADD,
                ir.OUNSAFESLICE,
index 0bcb319291a0d5a7802037a76a0d1ebe79479ed7..eb17e63d9a0114623ce97d7fc04d2061675129d2 100644 (file)
@@ -830,22 +830,17 @@ func tcRecover(n *ir.CallExpr) ir.Node {
                return n
        }
 
-       n.SetType(types.Types[types.TINTER])
-       return n
-}
-
-// tcRecoverFP typechecks an ORECOVERFP node.
-func tcRecoverFP(n *ir.CallExpr) ir.Node {
-       if len(n.Args) != 1 {
-               base.FatalfAt(n.Pos(), "wrong number of arguments: %v", n)
-       }
-
-       n.Args[0] = Expr(n.Args[0])
-       if !n.Args[0].Type().IsPtrShaped() {
-               base.FatalfAt(n.Pos(), "%L is not pointer shaped", n.Args[0])
+       // FP is equal to caller's SP plus FixedFrameSize.
+       var fp ir.Node = ir.NewCallExpr(n.Pos(), ir.OGETCALLERSP, nil, nil)
+       if off := base.Ctxt.Arch.FixedFrameSize; off != 0 {
+               fp = ir.NewBinaryExpr(n.Pos(), ir.OADD, fp, ir.NewInt(base.Pos, off))
        }
+       // TODO(mdempsky): Replace *int32 with unsafe.Pointer, without upsetting checkptr.
+       fp = ir.NewConvExpr(n.Pos(), ir.OCONVNOP, types.NewPtr(types.Types[types.TINT32]), fp)
 
+       n.SetOp(ir.ORECOVERFP)
        n.SetType(types.Types[types.TINTER])
+       n.Args = []ir.Node{Expr(fp)}
        return n
 }
 
index 9dea261bb9acd16d3984f8cb6d538cb3eb5c8dd9..91ef184f9fb95d25b6cd2a31bf326def84666436 100644 (file)
@@ -283,7 +283,8 @@ func tcGoDefer(n *ir.GoDeferStmt) {
                ir.OPANIC,
                ir.OPRINT,
                ir.OPRINTN,
-               ir.ORECOVER:
+               ir.ORECOVER,
+               ir.ORECOVERFP:
                return
 
        case ir.OAPPEND,
index 6e4feeccd9ecfb87564aa1797ef7c206f6131312..5dac366b10fa35d02226478acbaacff89670574b 100644 (file)
@@ -661,10 +661,6 @@ func typecheck1(n ir.Node, top int) ir.Node {
                n := n.(*ir.CallExpr)
                return tcRecover(n)
 
-       case ir.ORECOVERFP:
-               n := n.(*ir.CallExpr)
-               return tcRecoverFP(n)
-
        case ir.OUNSAFEADD:
                n := n.(*ir.BinaryExpr)
                return tcUnsafeAdd(n)