From 24017148ca8a669debbddba56d69769dc47d5c71 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sat, 25 Feb 2023 18:31:13 +0800 Subject: [PATCH] cmd/compile: clarify a few redundant deletions of internal/ssagen.state.vars 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 TryBot-Result: Gopher Robot Auto-Submit: Keith Randall Reviewed-by: Keith Randall Reviewed-by: Matthew Dempsky Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssagen/ssa.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cmd/compile/internal/ssagen/ssa.go b/src/cmd/compile/internal/ssagen/ssa.go index 48d5e34f46..b4a55c00af 100644 --- a/src/cmd/compile/internal/ssagen/ssa.go +++ b/src/cmd/compile/internal/ssagen/ssa.go @@ -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 }