mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: use more range fors in gc
Slightly simplifies the code. Made sure to exclude the cases that would change behavior, such as when the iterated value is a string, when the index is modified within the body, or when the slice is modified. Also checked that all the elements are of pointer type, to avoid the corner case where non-pointer types could be copied by mistake. Change-Id: Iea64feb2a9a6a4c94ada9ff3ace40ee173505849 Reviewed-on: https://go-review.googlesource.com/100557 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
48f990b4a5
commit
02798ed936
4 changed files with 22 additions and 24 deletions
|
|
@ -100,8 +100,8 @@ func assembleInlines(fnsym *obj.LSym, dwVars []*dwarf.Var) dwarf.InlCalls {
|
||||||
var m map[varPos]int
|
var m map[varPos]int
|
||||||
if ii == 0 {
|
if ii == 0 {
|
||||||
if !fnsym.WasInlined() {
|
if !fnsym.WasInlined() {
|
||||||
for j := 0; j < len(sl); j++ {
|
for j, v := range sl {
|
||||||
sl[j].ChildIndex = int32(j)
|
v.ChildIndex = int32(j)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -121,19 +121,19 @@ func assembleInlines(fnsym *obj.LSym, dwVars []*dwarf.Var) dwarf.InlCalls {
|
||||||
// parented by the inlined routine and not the top-level
|
// parented by the inlined routine and not the top-level
|
||||||
// caller.
|
// caller.
|
||||||
synthCount := len(m)
|
synthCount := len(m)
|
||||||
for j := 0; j < len(sl); j++ {
|
for _, v := range sl {
|
||||||
canonName := unversion(sl[j].Name)
|
canonName := unversion(v.Name)
|
||||||
vp := varPos{
|
vp := varPos{
|
||||||
DeclName: canonName,
|
DeclName: canonName,
|
||||||
DeclFile: sl[j].DeclFile,
|
DeclFile: v.DeclFile,
|
||||||
DeclLine: sl[j].DeclLine,
|
DeclLine: v.DeclLine,
|
||||||
DeclCol: sl[j].DeclCol,
|
DeclCol: v.DeclCol,
|
||||||
}
|
}
|
||||||
synthesized := strings.HasPrefix(sl[j].Name, "~r") || canonName == "_"
|
synthesized := strings.HasPrefix(v.Name, "~r") || canonName == "_"
|
||||||
if idx, found := m[vp]; found {
|
if idx, found := m[vp]; found {
|
||||||
sl[j].ChildIndex = int32(idx)
|
v.ChildIndex = int32(idx)
|
||||||
sl[j].IsInAbstract = !synthesized
|
v.IsInAbstract = !synthesized
|
||||||
sl[j].Name = canonName
|
v.Name = canonName
|
||||||
} else {
|
} else {
|
||||||
// Variable can't be found in the pre-inline dcl list.
|
// Variable can't be found in the pre-inline dcl list.
|
||||||
// In the top-level case (ii=0) this can happen
|
// In the top-level case (ii=0) this can happen
|
||||||
|
|
@ -141,7 +141,7 @@ func assembleInlines(fnsym *obj.LSym, dwVars []*dwarf.Var) dwarf.InlCalls {
|
||||||
// and we're looking at a piece. We can also see
|
// and we're looking at a piece. We can also see
|
||||||
// return temps (~r%d) that were created during
|
// return temps (~r%d) that were created during
|
||||||
// lowering, or unnamed params ("_").
|
// lowering, or unnamed params ("_").
|
||||||
sl[j].ChildIndex = int32(synthCount)
|
v.ChildIndex = int32(synthCount)
|
||||||
synthCount += 1
|
synthCount += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -215,8 +215,7 @@ func unversion(name string) string {
|
||||||
func makePreinlineDclMap(fnsym *obj.LSym) map[varPos]int {
|
func makePreinlineDclMap(fnsym *obj.LSym) map[varPos]int {
|
||||||
dcl := preInliningDcls(fnsym)
|
dcl := preInliningDcls(fnsym)
|
||||||
m := make(map[varPos]int)
|
m := make(map[varPos]int)
|
||||||
for i := 0; i < len(dcl); i++ {
|
for i, n := range dcl {
|
||||||
n := dcl[i]
|
|
||||||
pos := Ctxt.InnermostPos(n.Pos)
|
pos := Ctxt.InnermostPos(n.Pos)
|
||||||
vp := varPos{
|
vp := varPos{
|
||||||
DeclName: unversion(n.Sym.Name),
|
DeclName: unversion(n.Sym.Name),
|
||||||
|
|
@ -338,7 +337,7 @@ func (s byClassThenName) Less(i, j int) bool { return cmpDwarfVar(s[i], s[j]) }
|
||||||
func (s byClassThenName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
func (s byClassThenName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||||
|
|
||||||
func dumpInlCall(inlcalls dwarf.InlCalls, idx, ilevel int) {
|
func dumpInlCall(inlcalls dwarf.InlCalls, idx, ilevel int) {
|
||||||
for i := 0; i < ilevel; i += 1 {
|
for i := 0; i < ilevel; i++ {
|
||||||
Ctxt.Logf(" ")
|
Ctxt.Logf(" ")
|
||||||
}
|
}
|
||||||
ic := inlcalls.Calls[idx]
|
ic := inlcalls.Calls[idx]
|
||||||
|
|
@ -363,9 +362,8 @@ func dumpInlCall(inlcalls dwarf.InlCalls, idx, ilevel int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpInlCalls(inlcalls dwarf.InlCalls) {
|
func dumpInlCalls(inlcalls dwarf.InlCalls) {
|
||||||
n := len(inlcalls.Calls)
|
for k, c := range inlcalls.Calls {
|
||||||
for k := 0; k < n; k += 1 {
|
if c.Root {
|
||||||
if inlcalls.Calls[k].Root {
|
|
||||||
dumpInlCall(inlcalls, k, 0)
|
dumpInlCall(inlcalls, k, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -241,7 +241,7 @@ func (s *phiState) insertVarPhis(n int, var_ *Node, defs []*ssa.Block, typ *type
|
||||||
v := c.NewValue0I(currentRoot.Pos, ssa.OpPhi, typ, int64(n)) // TODO: line number right?
|
v := c.NewValue0I(currentRoot.Pos, ssa.OpPhi, typ, int64(n)) // TODO: line number right?
|
||||||
// Note: we store the variable number in the phi's AuxInt field. Used temporarily by phi building.
|
// Note: we store the variable number in the phi's AuxInt field. Used temporarily by phi building.
|
||||||
s.s.addNamedValue(var_, v)
|
s.s.addNamedValue(var_, v)
|
||||||
for i := 0; i < len(c.Preds); i++ {
|
for range c.Preds {
|
||||||
v.AddArg(s.placeholder) // Actual args will be filled in by resolveFwdRefs.
|
v.AddArg(s.placeholder) // Actual args will be filled in by resolveFwdRefs.
|
||||||
}
|
}
|
||||||
if debugPhi {
|
if debugPhi {
|
||||||
|
|
|
||||||
|
|
@ -487,8 +487,8 @@ func (lv *Liveness) prologue() {
|
||||||
|
|
||||||
// Walk the block instructions forward to update avarinit bits.
|
// Walk the block instructions forward to update avarinit bits.
|
||||||
// avarinit describes the effect at the end of the block, not the beginning.
|
// avarinit describes the effect at the end of the block, not the beginning.
|
||||||
for j := 0; j < len(b.Values); j++ {
|
for _, val := range b.Values {
|
||||||
pos, e := lv.valueEffects(b.Values[j])
|
pos, e := lv.valueEffects(val)
|
||||||
if e&varkill != 0 {
|
if e&varkill != 0 {
|
||||||
be.avarinit.Unset(pos)
|
be.avarinit.Unset(pos)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,9 +73,9 @@ func flusherrors() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sort.Stable(byPos(errors))
|
sort.Stable(byPos(errors))
|
||||||
for i := 0; i < len(errors); i++ {
|
for i, err := range errors {
|
||||||
if i == 0 || errors[i].msg != errors[i-1].msg {
|
if i == 0 || err.msg != errors[i-1].msg {
|
||||||
fmt.Printf("%s", errors[i].msg)
|
fmt.Printf("%s", err.msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
errors = errors[:0]
|
errors = errors[:0]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue