The Go bootstrap toolchain requirement is now Go 1.17.
We can finally delete all these pre-Go 1.17 workarounds.
For #44505.
Change-Id: I59d4dff1cde23da022892b5b6a116eb3dbad9ce4
Reviewed-on: https://go-review.googlesource.com/c/go/+/420903
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
+++ /dev/null
-// Copyright 2017 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.
-
-//go:build !go1.8
-// +build !go1.8
-
-package gc
-
-import (
-       "cmd/compile/internal/base"
-       "runtime"
-)
-
-func startMutexProfiling() {
-       base.Fatalf("mutex profiling unavailable in version %v", runtime.Version())
-}
 
+++ /dev/null
-// Copyright 2017 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.
-
-//go:build go1.8
-// +build go1.8
-
-package gc
-
-import "runtime"
-
-func startMutexProfiling() {
-       runtime.SetMutexProfileFraction(1)
-}
 
+++ /dev/null
-// Copyright 2016 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.
-
-//go:build go1.7
-// +build go1.7
-
-package gc
-
-import (
-       "os"
-       tracepkg "runtime/trace"
-
-       "cmd/compile/internal/base"
-)
-
-func init() {
-       traceHandler = traceHandlerGo17
-}
-
-func traceHandlerGo17(traceprofile string) {
-       f, err := os.Create(traceprofile)
-       if err != nil {
-               base.Fatalf("%v", err)
-       }
-       if err := tracepkg.Start(f); err != nil {
-               base.Fatalf("%v", err)
-       }
-       base.AtExit(tracepkg.Stop)
-}
 
        "os"
        "runtime"
        "runtime/pprof"
+       tracepkg "runtime/trace"
 
        "cmd/compile/internal/base"
 )
 
-var traceHandler func(string)
-
 func startProfile() {
        if base.Flag.CPUProfile != "" {
                f, err := os.Create(base.Flag.CPUProfile)
                if err != nil {
                        base.Fatalf("%v", err)
                }
-               startMutexProfiling()
+               runtime.SetMutexProfileFraction(1)
                base.AtExit(func() {
                        pprof.Lookup("mutex").WriteTo(f, 0)
                        f.Close()
                })
        }
-       if base.Flag.TraceProfile != "" && traceHandler != nil {
-               traceHandler(base.Flag.TraceProfile)
+       if base.Flag.TraceProfile != "" {
+               f, err := os.Create(base.Flag.TraceProfile)
+               if err != nil {
+                       base.Fatalf("%v", err)
+               }
+               if err := tracepkg.Start(f); err != nil {
+                       base.Fatalf("%v", err)
+               }
+               base.AtExit(tracepkg.Stop)
        }
 }
 
+++ /dev/null
-// Copyright 2019 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.
-
-//go:build go1.8
-// +build go1.8
-
-package logopt
-
-import "net/url"
-
-func pathEscape(s string) string {
-       return url.PathEscape(s)
-}
 
+++ /dev/null
-// Copyright 2019 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.
-
-//go:build !go1.8
-// +build !go1.8
-
-package logopt
-
-// For bootstrapping with an early version of Go
-func pathEscape(s string) string {
-       panic("This should never be called; the compiler is not fully bootstrapped if it is.")
-}
 
        if lastdot != -1 {
                basename = basename[:lastdot]
        }
-       basename = pathEscape(basename)
+       basename = url.PathEscape(basename)
 
        // Assume a directory, make a file
        p := filepath.Join(subdirpath, basename+".json")
                if slashPkgPath == "" {
                        slashPkgPath = "\000"
                }
-               subdirpath := filepath.Join(dest, pathEscape(slashPkgPath))
+               subdirpath := filepath.Join(dest, url.PathEscape(slashPkgPath))
                err := os.MkdirAll(subdirpath, 0755)
                if err != nil {
                        log.Fatalf("Could not create directory %s for logging optimizer actions, %v", subdirpath, err)
 
+++ /dev/null
-// 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.
-
-//go:build !go1.7
-// +build !go1.7
-
-// TODO(mdempsky): Remove after #44505 is resolved
-
-package pkgbits
-
-import "runtime"
-
-func walkFrames(pcs []uintptr, visit frameVisitor) {
-       for _, pc := range pcs {
-               fn := runtime.FuncForPC(pc)
-               file, line := fn.FileLine(pc)
-
-               visit(file, line, fn.Name(), pc-fn.Entry())
-       }
-}
 
+++ /dev/null
-// 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.
-
-//go:build go1.7
-// +build go1.7
-
-package pkgbits
-
-import "runtime"
-
-// walkFrames calls visit for each call frame represented by pcs.
-//
-// pcs should be a slice of PCs, as returned by runtime.Callers.
-func walkFrames(pcs []uintptr, visit frameVisitor) {
-       if len(pcs) == 0 {
-               return
-       }
-
-       frames := runtime.CallersFrames(pcs)
-       for {
-               frame, more := frames.Next()
-               visit(frame.File, frame.Line, frame.Function, frame.PC-frame.Entry)
-               if !more {
-                       return
-               }
-       }
-}
 
 
 import (
        "fmt"
+       "runtime"
        "strings"
 )
 
 
 type frameVisitor func(file string, line int, name string, offset uintptr)
 
+// walkFrames calls visit for each call frame represented by pcs.
+//
+// pcs should be a slice of PCs, as returned by runtime.Callers.
+func walkFrames(pcs []uintptr, visit frameVisitor) {
+       if len(pcs) == 0 {
+               return
+       }
+
+       frames := runtime.CallersFrames(pcs)
+       for {
+               frame, more := frames.Next()
+               visit(frame.File, frame.Line, frame.Function, frame.PC-frame.Entry)
+               if !more {
+                       return
+               }
+       }
+}
+
 // SyncMarker is an enum type that represents markers that may be
 // written to export data to ensure the reader and writer stay
 // synchronized.
 
 
 package sort
 
-import "math/bits"
+import (
+       "internal/reflectlite"
+       "math/bits"
+)
 
 // Slice sorts the slice x given the provided less function.
 // It panics if x is not a slice.
 // The less function must satisfy the same requirements as
 // the Interface type's Less method.
 func Slice(x any, less func(i, j int) bool) {
-       rv := reflectValueOf(x)
-       swap := reflectSwapper(x)
+       rv := reflectlite.ValueOf(x)
+       swap := reflectlite.Swapper(x)
        length := rv.Len()
        limit := bits.Len(uint(length))
        pdqsort_func(lessSwap{less, swap}, 0, length, limit)
 // The less function must satisfy the same requirements as
 // the Interface type's Less method.
 func SliceStable(x any, less func(i, j int) bool) {
-       rv := reflectValueOf(x)
-       swap := reflectSwapper(x)
+       rv := reflectlite.ValueOf(x)
+       swap := reflectlite.Swapper(x)
        stable_func(lessSwap{less, swap}, rv.Len())
 }
 
 // SliceIsSorted reports whether the slice x is sorted according to the provided less function.
 // It panics if x is not a slice.
 func SliceIsSorted(x any, less func(i, j int) bool) bool {
-       rv := reflectValueOf(x)
+       rv := reflectlite.ValueOf(x)
        n := rv.Len()
        for i := n - 1; i > 0; i-- {
                if less(i, i-1) {
 
+++ /dev/null
-// Copyright 2017 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.
-
-//go:build go1.13
-// +build go1.13
-
-package sort
-
-import "internal/reflectlite"
-
-var reflectValueOf = reflectlite.ValueOf
-var reflectSwapper = reflectlite.Swapper
 
+++ /dev/null
-// Copyright 2017 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.
-
-//go:build !go1.8
-// +build !go1.8
-
-package sort
-
-import "reflect"
-
-var reflectValueOf = reflect.ValueOf
-
-func reflectSwapper(x any) func(int, int) {
-       v := reflectValueOf(x)
-       tmp := reflect.New(v.Type().Elem()).Elem()
-       return func(i, j int) {
-               a, b := v.Index(i), v.Index(j)
-               tmp.Set(a)
-               a.Set(b)
-               b.Set(tmp)
-       }
-}
 
+++ /dev/null
-// Copyright 2017 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.
-
-//go:build go1.8 && !go1.13
-// +build go1.8,!go1.13
-
-package sort
-
-import "reflect"
-
-var reflectValueOf = reflect.ValueOf
-var reflectSwapper = reflect.Swapper