]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: clarify a few redundant deletions of internal/ssagen.state.vars
authorAndy Pan <panjf2000@gmail.com>
Sat, 25 Feb 2023 10:31:13 +0000 (18:31 +0800)
committerGopher Robot <gobot@golang.org>
Thu, 9 Mar 2023 19:25:20 +0000 (19:25 +0000)
Fixes #58729

The reason why these deletions exist is that the old state.variable method
will assign the new value to the given key of map when the key doesn't exist,
but after this commit: https://github.com/golang/go/commit/5a6e511c614a158cb58150fb62bfbc207a33922d#diff-e754f9fc8eaf878714250cfc03844eb3b58185ac806a8c1c4f9fbabd86cda921L3972
the state.variable doesn't do that anymore, thus these deletions became redundant.

Change-Id: Ie6e2471ca445f907a2bb1607c293f9301f0d73e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/471355
Run-TryBot: Andy Pan <panjf2000@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssagen/ssa.go

index 48d5e34f46bb86554275dabe4d3a5327df337388..b4a55c00af0ca2528eca62d1f6ade05d2ef0b8ef 100644 (file)
@@ -7,7 +7,6 @@ package ssagen
 import (
        "bufio"
        "bytes"
-       "cmd/compile/internal/abi"
        "fmt"
        "go/constant"
        "html"
@@ -17,6 +16,7 @@ import (
        "sort"
        "strings"
 
+       "cmd/compile/internal/abi"
        "cmd/compile/internal/base"
        "cmd/compile/internal/ir"
        "cmd/compile/internal/liveness"
@@ -3521,6 +3521,10 @@ func (s *state) append(n *ir.CallExpr, inplace bool) *ssa.Value {
                }
        }
 
+       // The following deletions have no practical effect at this time
+       // because state.vars has been reset by the preceding state.startBlock.
+       // They only enforce the fact that these variables are no longer need in
+       // the current scope.
        delete(s.vars, ptrVar)
        delete(s.vars, lenVar)
        if !inplace {
@@ -6379,7 +6383,7 @@ func (s *state) dottype1(pos src.XPos, src, dst *types.Type, iface, source, targ
                        idata := s.newValue1(ssa.OpIData, byteptr, iface)
                        res = s.newValue2(ssa.OpIMake, dst, s.variable(typVar, byteptr), idata)
                        resok = cond
-                       delete(s.vars, typVar)
+                       delete(s.vars, typVar) // no practical effect, just to indicate typVar is no longer live.
                        return
                }
                // converting to a nonempty interface needs a runtime call.
@@ -6504,12 +6508,12 @@ func (s *state) dottype1(pos src.XPos, src, dst *types.Type, iface, source, targ
        s.startBlock(bEnd)
        if tmp == nil {
                res = s.variable(valVar, dst)
-               delete(s.vars, valVar)
+               delete(s.vars, valVar) // no practical effect, just to indicate typVar is no longer live.
        } else {
                res = s.load(dst, addr)
        }
        resok = s.variable(okVar, types.Types[types.TBOOL])
-       delete(s.vars, okVar)
+       delete(s.vars, okVar) // ditto
        return res, resok
 }