Skip to content

Commit 106fc3a

Browse files
committed
all: clean up some TODOs for old Go versions
Now that we require Go 1.20 or later, we can simplify some of our code. Signed-off-by: Daniel Martí <[email protected]> Change-Id: Iede54cc9b67806a5c4de8cffc88903e838106186 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1167670 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent fae9c82 commit 106fc3a

File tree

3 files changed

+11
-25
lines changed

3 files changed

+11
-25
lines changed

cue/ast/astutil/sanitize.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,8 @@ func (z *sanitizer) uniqueName(base string, hidden bool) string {
332332
}
333333
}
334334

335-
// TODO(go1.13): const mask = 0xff_ffff_ffff_ffff
336-
const mask = 0xffffffffffffff // max bits; stay clear of int64 overflow
337-
const shift = 4 // rate of growth
335+
const mask = 0xff_ffff_ffff_ffff // max bits; stay clear of int64 overflow
336+
const shift = 4 // rate of growth
338337
for n := int64(0x10); ; n = int64(mask&((n<<shift)-1)) + 1 {
339338
num := z.rand.Intn(int(n))
340339
name := fmt.Sprintf("%s_%01X", base, num)

encoding/gocode/templates.go

+2-13
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package gocode
1616

1717
import (
18-
"strings"
1918
"text/template"
2019
)
2120

@@ -36,14 +35,6 @@ import (
3635
3736
`))
3837

39-
// normalizeHex copes with differences between the Go string literal conventions
40-
// between go1.18 and go1.19. The byte 0x7f changed from \u007f to \x7f.
41-
// By normalizing here, we make the code generation independent of the Go
42-
// version that's used.
43-
func normalizeHex(s string) string {
44-
return strings.ReplaceAll(s, `\u007f`, `\x7f`)
45-
}
46-
4738
// Inputs:
4839
// .prefix prefix to all generated variable names
4940
// .cueName name of the top-level CUE value
@@ -75,9 +66,7 @@ func {{if .func}}{{.complete}}{{.cueName}}{{$sig}}
7566
// .prefix prefix to all generated variable names
7667
// .runtime the variable name of a user-supplied runtime, if any
7768
// .data bytes obtained from Instance.MarshalBinary
78-
var loadCode = template.Must(template.New("load").Funcs(template.FuncMap{
79-
"normalizeHex": normalizeHex,
80-
}).Parse(`
69+
var loadCode = template.Must(template.New("load").Parse(`
8170
var {{.prefix}}Codec, {{.prefix}}Instance_, {{.prefix}}Value = func() (*gocodec.Codec, *cue.Instance, cue.Value) {
8271
var r *cue.Runtime
8372
r = {{if .runtime}}{{.runtime}}{{else}}&cue.Runtime{}{{end}}
@@ -113,5 +102,5 @@ func {{.prefix}}Make(name string, x interface{}) cue.Value {
113102
}
114103
115104
// Data size: {{len .data}} bytes.
116-
var {{.prefix}}InstanceData = []byte({{printf "%+q" .data | normalizeHex }})
105+
var {{.prefix}}InstanceData = []byte({{printf "%+q" .data }})
117106
`))

pkg/time/time_test.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ func TestTimestamp(t *testing.T) {
3535

3636
// TODO: allow leap seconds? This is allowed by the RFC 3339 spec.
3737
// `"2019-06-30T23:59:60Z"`, // leap seconds
38+
39+
// NOTE: Go 1.17 rejected the extra digits,
40+
// and Go 1.18 started accepting them while discarding them.
41+
// We want CUE to be consistent across Go versions,
42+
// so we should probably fork Go's time package to behave exactly the
43+
// way we want and in a consistent way across Go versions.
44+
`"2019-01-02T15:04:05.01234567890-08:00"`,
3845
}
3946

4047
for _, tc := range validTimes {
@@ -71,15 +78,6 @@ func TestTimestamp(t *testing.T) {
7178
`"2019-13-15T23:00:00Z"`, // month out of range
7279
`"2019-01-02T15:04:05Z+08:00"`, // double time zone
7380
`"2019-01-02T15:04:05+08"`, // partial time zone
74-
75-
// TODO: Go 1.17 rejected the extra digits,
76-
// and Go 1.18 started accepting them while discarding them.
77-
// We want CUE to be consistent across Go versions,
78-
// so we should probably fork Go's time package to behave exactly the
79-
// way we want and in a consistent way across Go versions.
80-
// In the meantime, having newer Go versions accept more inputs is not a
81-
// terrible state of affairs, so for now we disable the test case.
82-
// `"2019-01-02T15:04:05.01234567890-08:00"`,
8381
}
8482

8583
for _, tc := range invalidTimes {

0 commit comments

Comments
 (0)