]> Cypherpunks.ru repositories - gostls13.git/commitdiff
[dev.regabi] strconv: add to bootstrap packages
authorMatthew Dempsky <mdempsky@google.com>
Tue, 24 Nov 2020 05:48:38 +0000 (21:48 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 24 Nov 2020 19:42:42 +0000 (19:42 +0000)
go/constant relies on strconv for parsing Go literals, while older
versions of strconv either lack recent Go language features (e.g., Go
1.13's new numeric literals) or have errors (e.g., mishandling of
carriage returns in raw string literals prior to Go 1.8).

This requires two changes:

1. Splitting out the internal/bytealg dependency into a separate file,
which can be easily substituted with a simple loop for bootstrap
builds.

2. Updating eisel_lemire.go to not utilize Go 1.13 functionality
(underscores in numeric literals and signed shift counts).

Change-Id: Ib48a858a03b155eebdcd08d577aec2254337e70e
Reviewed-on: https://go-review.googlesource.com/c/go/+/272749
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>

src/cmd/compile/internal/gc/dep_test.go
src/cmd/dist/buildtool.go
src/strconv/bytealg.go [new file with mode: 0644]
src/strconv/bytealg_bootstrap.go [new file with mode: 0644]
src/strconv/eisel_lemire.go
src/strconv/quote.go

index c1dac9338652bf186ac42d7d0eb6d6cdd5dff132..a185bc9f547c5261b4c81b0abad34aea62570819 100644 (file)
@@ -18,7 +18,7 @@ func TestDeps(t *testing.T) {
        }
        for _, dep := range strings.Fields(strings.Trim(string(out), "[]")) {
                switch dep {
-               case "go/build", "go/token":
+               case "go/build", "go/scanner":
                        t.Errorf("undesired dependency on %q", dep)
                }
        }
index 37b3d45977a888746a3bd16eae132ec228612431..e39f284db566d70a4a9a094009990006a24ae236 100644 (file)
@@ -96,6 +96,7 @@ var bootstrapDirs = []string{
        "debug/elf",
        "debug/macho",
        "debug/pe",
+       "go/constant",
        "internal/goversion",
        "internal/race",
        "internal/unsafeheader",
@@ -103,6 +104,7 @@ var bootstrapDirs = []string{
        "math/big",
        "math/bits",
        "sort",
+       "strconv",
 }
 
 // File prefixes that are ignored by go/build anyway, and cause
diff --git a/src/strconv/bytealg.go b/src/strconv/bytealg.go
new file mode 100644 (file)
index 0000000..7f66f2a
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2009 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.
+
+// +build !compiler_bootstrap
+
+package strconv
+
+import "internal/bytealg"
+
+// contains reports whether the string contains the byte c.
+func contains(s string, c byte) bool {
+       return bytealg.IndexByteString(s, c) != -1
+}
diff --git a/src/strconv/bytealg_bootstrap.go b/src/strconv/bytealg_bootstrap.go
new file mode 100644 (file)
index 0000000..a3a547d
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2020 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.
+
+// +build compiler_bootstrap
+
+package strconv
+
+// contains reports whether the string contains the byte c.
+func contains(s string, c byte) bool {
+       for i := 0; i < len(s); i++ {
+               if s[i] == c {
+                       return true
+               }
+       }
+       return false
+}
index 6c7f852eba8061efb18e83aa2741816279ca8064..fecd1b93451d0794af39198efc42462aa41bece1 100644 (file)
@@ -29,7 +29,7 @@ func eiselLemire64(man uint64, exp10 int, neg bool) (f float64, ok bool) {
        // Exp10 Range.
        if man == 0 {
                if neg {
-                       f = math.Float64frombits(0x80000000_00000000) // Negative zero.
+                       f = math.Float64frombits(0x8000000000000000) // Negative zero.
                }
                return f, true
        }
@@ -39,7 +39,7 @@ func eiselLemire64(man uint64, exp10 int, neg bool) (f float64, ok bool) {
 
        // Normalization.
        clz := bits.LeadingZeros64(man)
-       man <<= clz
+       man <<= uint(clz)
        const float64ExponentBias = 1023
        retExp2 := uint64(217706*exp10>>16+64+float64ExponentBias) - uint64(clz)
 
@@ -84,9 +84,9 @@ func eiselLemire64(man uint64, exp10 int, neg bool) (f float64, ok bool) {
        if retExp2-1 >= 0x7FF-1 {
                return 0, false
        }
-       retBits := retExp2<<52 | retMantissa&0x000FFFFF_FFFFFFFF
+       retBits := retExp2<<52 | retMantissa&0x000FFFFFFFFFFFFF
        if neg {
-               retBits |= 0x80000000_00000000
+               retBits |= 0x8000000000000000
        }
        return math.Float64frombits(retBits), true
 }
@@ -114,7 +114,7 @@ func eiselLemire32(man uint64, exp10 int, neg bool) (f float32, ok bool) {
 
        // Normalization.
        clz := bits.LeadingZeros64(man)
-       man <<= clz
+       man <<= uint(clz)
        const float32ExponentBias = 127
        retExp2 := uint64(217706*exp10>>16+64+float32ExponentBias) - uint64(clz)
 
@@ -122,13 +122,13 @@ func eiselLemire32(man uint64, exp10 int, neg bool) (f float32, ok bool) {
        xHi, xLo := bits.Mul64(man, detailedPowersOfTen[exp10-detailedPowersOfTenMinExp10][1])
 
        // Wider Approximation.
-       if xHi&0x3F_FFFFFFFF == 0x3F_FFFFFFFF && xLo+man < man {
+       if xHi&0x3FFFFFFFFF == 0x3FFFFFFFFF && xLo+man < man {
                yHi, yLo := bits.Mul64(man, detailedPowersOfTen[exp10-detailedPowersOfTenMinExp10][0])
                mergedHi, mergedLo := xHi, xLo+yHi
                if mergedLo < xLo {
                        mergedHi++
                }
-               if mergedHi&0x3F_FFFFFFFF == 0x3F_FFFFFFFF && mergedLo+1 == 0 && yLo+man < man {
+               if mergedHi&0x3FFFFFFFFF == 0x3FFFFFFFFF && mergedLo+1 == 0 && yLo+man < man {
                        return 0, false
                }
                xHi, xLo = mergedHi, mergedLo
@@ -140,7 +140,7 @@ func eiselLemire32(man uint64, exp10 int, neg bool) (f float32, ok bool) {
        retExp2 -= 1 ^ msb
 
        // Half-way Ambiguity.
-       if xLo == 0 && xHi&0x3F_FFFFFFFF == 0 && retMantissa&3 == 1 {
+       if xLo == 0 && xHi&0x3FFFFFFFFF == 0 && retMantissa&3 == 1 {
                return 0, false
        }
 
index bcbdbc514d21a8b72f8f83fecd5cc8cb5b9d4c49..4ffa10b72efc9d163640401c76092f47a16c125b 100644 (file)
@@ -7,7 +7,6 @@
 package strconv
 
 import (
-       "internal/bytealg"
        "unicode/utf8"
 )
 
@@ -436,11 +435,6 @@ func Unquote(s string) (string, error) {
        return string(buf), nil
 }
 
-// contains reports whether the string contains the byte c.
-func contains(s string, c byte) bool {
-       return bytealg.IndexByteString(s, c) != -1
-}
-
 // bsearch16 returns the smallest i such that a[i] >= x.
 // If there is no such i, bsearch16 returns len(a).
 func bsearch16(a []uint16, x uint16) int {