Skip to content

Commit

Permalink
feat: support go1.22
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes committed Mar 4, 2024
1 parent 1990b96 commit ee3f46e
Show file tree
Hide file tree
Showing 517 changed files with 95,190 additions and 965 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go-cross.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

strategy:
matrix:
go-version: [ '1.20', '1.21' ]
go-version: [ '1.21', '1.22' ]
os: [ubuntu-latest, macos-latest, windows-latest]

include:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
pull_request:

env:
GO_VERSION: '1.21'
GO_VERSION: '1.22'
GOLANGCI_LINT_VERSION: v1.55.2

jobs:
Expand Down Expand Up @@ -45,7 +45,7 @@ jobs:
needs: linting
strategy:
matrix:
go-version: [ '1.20', '1.21' ]
go-version: [ '1.21', '1.22' ]
steps:
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
working-directory: ${{ github.workspace }}/go/src/github.com/traefik/yaegi
strategy:
matrix:
go-version: [ '1.20', '1.21' ]
go-version: [ '1.21', '1.22' ]

steps:
- name: Set up Go ${{ matrix.go-version }}
Expand Down
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,15 @@ tests:
install.sh: .goreleaser.yml
godownloader --repo=traefik/yaegi -o install.sh .goreleaser.yml

.PHONY: check gen_all_syscall gen_tests generate_downloader internal/cmd/extract/extract install
generic_list = cmp/cmp.go slices/slices.go slices/sort.go slices/zsortanyfunc.go maps/maps.go \
sync/oncefunc.go sync/atomic/type.go

# get_generic_src imports stdlib files containing generic symbols definitions
get_generic_src:
eval "`go env`"; echo $$GOROOT; gov=$${GOVERSION#*.}; gov=$${gov%.*}; \
for f in ${generic_list}; do \
nf=stdlib/generic/go1_$${gov}_`echo $$f | tr / _`.txt; echo "nf: $$nf"; \
cat "$$GOROOT/src/$$f" > "$$nf"; \
done

.PHONY: check gen_all_syscall internal/cmd/extract/extract get_generic_src install
9 changes: 4 additions & 5 deletions _test/addr0.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ func main() {
r := extendedRequest{}
req := &r.Request


fmt.Println(r)
fmt.Println(req)
fmt.Printf("%T\n", r.Request)
fmt.Printf("%T\n", req)
}

// Output:
// {{ <nil> 0 0 map[] <nil> <nil> 0 [] false map[] map[] <nil> map[] <nil> <nil> <nil> <nil>} }
// &{ <nil> 0 0 map[] <nil> <nil> 0 [] false map[] map[] <nil> map[] <nil> <nil> <nil> <nil>}
// http.Request
// *http.Request
2 changes: 1 addition & 1 deletion extract/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func GetMinor(part string) string {
return minor
}

const defaultMinorVersion = 21
const defaultMinorVersion = 22

func genBuildTags() (string, error) {
version := runtime.Version()
Expand Down
4 changes: 2 additions & 2 deletions stdlib/generic/go1_21_generic.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build go1.21
// +build go1.21
//go:build go1.21 && !go1.22
// +build go1.21,!go1.22

package generic

Expand Down
71 changes: 71 additions & 0 deletions stdlib/generic/go1_22_cmp_cmp.go.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2023 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.

// Package cmp provides types and functions related to comparing
// ordered values.
package cmp

// Ordered is a constraint that permits any ordered type: any type
// that supports the operators < <= >= >.
// If future releases of Go add new ordered types,
// this constraint will be modified to include them.
//
// Note that floating-point types may contain NaN ("not-a-number") values.
// An operator such as == or < will always report false when
// comparing a NaN value with any other value, NaN or not.
// See the [Compare] function for a consistent way to compare NaN values.
type Ordered interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
~float32 | ~float64 |
~string
}

// Less reports whether x is less than y.
// For floating-point types, a NaN is considered less than any non-NaN,
// and -0.0 is not less than (is equal to) 0.0.
func Less[T Ordered](x, y T) bool {
return (isNaN(x) && !isNaN(y)) || x < y
}

// Compare returns
//
// -1 if x is less than y,
// 0 if x equals y,
// +1 if x is greater than y.
//
// For floating-point types, a NaN is considered less than any non-NaN,
// a NaN is considered equal to a NaN, and -0.0 is equal to 0.0.
func Compare[T Ordered](x, y T) int {
xNaN := isNaN(x)
yNaN := isNaN(y)
if xNaN && yNaN {
return 0
}
if xNaN || x < y {
return -1
}
if yNaN || x > y {
return +1
}
return 0
}

// isNaN reports whether x is a NaN without requiring the math package.
// This will always return false if T is not floating-point.
func isNaN[T Ordered](x T) bool {
return x != x
}

// Or returns the first of its arguments that is not equal to the zero value.
// If no argument is non-zero, it returns the zero value.
func Or[T comparable](vals ...T) T {
var zero T
for _, val := range vals {
if val != zero {
return val
}
}
return zero
}
41 changes: 41 additions & 0 deletions stdlib/generic/go1_22_generic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//go:build go1.22
// +build go1.22

package generic

import _ "embed"

//go:embed go1_22_cmp_cmp.go.txt
var cmpSource string

//go:embed go1_22_maps_maps.go.txt
var mapsSource string

//go:embed go1_22_slices_slices.go.txt
var slicesSource string

/*
//go:embed go1_22_slices_sort.go.txt
var slicesSource1 string
//go:embed go1_22_slices_zsortanyfunc.go.txt
var slicesSource2 string
//go:embed go1_22_sync_oncefunc.go.txt
var syncSource string
//go:embed go1_22_sync_atomic_type.go.txt
var syncAtomicSource string
*/

// Sources contains the list of generic packages source strings.
var Sources = [...]string{
cmpSource,
mapsSource,
slicesSource,
// FIXME(marc): support the following.
// slicesSource1,
// slicesSource2,
// syncAtomicSource,
// syncSource,
}
68 changes: 68 additions & 0 deletions stdlib/generic/go1_22_maps_maps.go.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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.

// Package maps defines various functions useful with maps of any type.
package maps

// Equal reports whether two maps contain the same key/value pairs.
// Values are compared using ==.
func Equal[M1, M2 ~map[K]V, K, V comparable](m1 M1, m2 M2) bool {
if len(m1) != len(m2) {
return false
}
for k, v1 := range m1 {
if v2, ok := m2[k]; !ok || v1 != v2 {
return false
}
}
return true
}

// EqualFunc is like Equal, but compares values using eq.
// Keys are still compared with ==.
func EqualFunc[M1 ~map[K]V1, M2 ~map[K]V2, K comparable, V1, V2 any](m1 M1, m2 M2, eq func(V1, V2) bool) bool {
if len(m1) != len(m2) {
return false
}
for k, v1 := range m1 {
if v2, ok := m2[k]; !ok || !eq(v1, v2) {
return false
}
}
return true
}

// clone is implemented in the runtime package.
func clone(m any) any {
return m
}

// Clone returns a copy of m. This is a shallow clone:
// the new keys and values are set using ordinary assignment.
func Clone[M ~map[K]V, K comparable, V any](m M) M {
// Preserve nil in case it matters.
if m == nil {
return nil
}
return clone(m).(M)
}

// Copy copies all key/value pairs in src adding them to dst.
// When a key in src is already present in dst,
// the value in dst will be overwritten by the value associated
// with the key in src.
func Copy[M1 ~map[K]V, M2 ~map[K]V, K comparable, V any](dst M1, src M2) {
for k, v := range src {
dst[k] = v
}
}

// DeleteFunc deletes any key/value pairs from m for which del returns true.
func DeleteFunc[M ~map[K]V, K comparable, V any](m M, del func(K, V) bool) {
for k, v := range m {
if del(k, v) {
delete(m, k)
}
}
}
Loading

0 comments on commit ee3f46e

Please sign in to comment.