Skip to content

Commit

Permalink
feat: support go1.24
Browse files Browse the repository at this point in the history
  • Loading branch information
liuq19 committed Feb 26, 2025
1 parent c5a58f9 commit 6918f90
Show file tree
Hide file tree
Showing 63 changed files with 436 additions and 585 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/compatibility_test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ jobs:
- name: main
run: |
set GOMAXPROCS=4
go test -v -race github.com/bytedance/sonic
go test -v -race ./
- name: ast
run: |
set GOMAXPROCS=4
go test -v -race github.com/bytedance/sonic/ast
go test -v -race ./ast
- name: external
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/compatibility_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ jobs:
${{ runner.os }}-go-
- name: main
run: go test -race -v -gcflags="all=-l" github.com/bytedance/sonic
run: go test -race -v -gcflags="all=-l" ./

- name: decoder
run: go test -race -v -gcflags="all=-l" github.com/bytedance/sonic/decoder
run: go test -race -v -gcflags="all=-l" ./decoder

- name: encoder
run: go test -race -v -gcflags="all=-l" github.com/bytedance/sonic/encoder
run: go test -race -v -gcflags="all=-l" ./encoder

- name: ast
run: go test -race -v -gcflags="all=-l" github.com/bytedance/sonic/ast
run: go test -race -v -gcflags="all=-l" ./ast
47 changes: 47 additions & 0 deletions .github/workflows/test-arm64-1.24.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

name: Unit Test

on: pull_request

jobs:
build:
strategy:
matrix:
go-version: [1.24.x]
runner_arch: [ubuntu-24.04-arm]

runs-on: ${{ matrix.runner_arch }}

steps:
- name: Clear repository
run: sudo rm -fr $GITHUB_WORKSPACE && mkdir $GITHUB_WORKSPACE
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
cache: true

- uses: actions/checkout@v4

- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
${{ github.workspace }}/go.sum
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}

- name: Unit Test
run: |
GOMAXPROCS=4 go test -ldflags=-checklinkname=0 -race -covermode=atomic -coverprofile=coverage.txt $(go list ./... | grep -v -E 'loader|jit|avx|x86|sse|examples')
- name: Data Race
run: |
./scripts/test_race.sh
- name: Generic Test
if: ${{ !startsWith(matrix.go-version, '1.17.') }}
run: GOMAXPROCS=4 go test -ldflags=-checklinkname=0 -v -race ./generic_test

- name: Codecov
run: bash <(curl -s https://codecov.io/bash)
1 change: 0 additions & 1 deletion .github/workflows/test-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on: pull_request
jobs:
build:
strategy:
max-parallel: 4
matrix:
go-version: [1.20.x, 1.21.x, 1.22.x, 1.23.x]
runner_arch: [ubuntu-24.04-arm]
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/test-x86-go1.24.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

name: Unit Test

on: pull_request

jobs:
build:
strategy:
matrix:
go-version: [1.24.x]
runner_arch: [ubuntu-latest]

runs-on: ${{ matrix.runner_arch }}

steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
cache: true

- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
${{ github.workspace }}/go.sum
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}

- name: Unit Test JIT
run: |
GOMAXPROCS=4 go test -ldflags=-checklinkname=0 -race -covermode=atomic -coverprofile=coverage.txt ./...
- name: Unit Test VM
run: |
SONIC_USE_OPTDEC=1 SONIC_USE_FASTMAP=1 SONIC_ENCODER_USE_VM=1 GOMAXPROCS=4 go test -ldflags=-checklinkname=0 -race -covermode=atomic -coverprofile=coverage.txt ./...
- name: Loader Test
run: |
cd ./loader
go test -ldflags=-checklinkname=0 -v -race ./...
- name: Data Race
run: |
./scripts/test_race.sh
- name: PCSP Test
env:
GOVERSION: ${{ matrix.go-version }}
run: python3 ./scripts/test_pcsp.py

- name: Generic Test JIT
if: ${{ !startsWith(matrix.go-version, '1.17.') }}
run: GOMAXPROCS=4 go test -ldflags=-checklinkname=0 -v -race ./generic_test

- name: Generic Test VM
if: ${{ !startsWith(matrix.go-version, '1.17.') }}
run: GOMAXPROCS=4 SONIC_USE_OPTDEC=1 SONIC_USE_FASTMAP=1 SONIC_ENCODER_USE_VM=1 go test -ldflags=-checklinkname=0 -v -race ./generic_test

- name: Codecov
run: bash <(curl -s https://codecov.io/bash)
4 changes: 2 additions & 2 deletions ast/api.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build (amd64 && go1.17 && !go1.24) || (arm64 && go1.20 && !go1.24)
// +build amd64,go1.17,!go1.24 arm64,go1.20,!go1.24
//go:build (amd64 && go1.17 && !go1.25) || (arm64 && go1.20 && !go1.25)
// +build amd64,go1.17,!go1.25 arm64,go1.20,!go1.25

/*
* Copyright 2022 ByteDance Inc.
Expand Down
2 changes: 1 addition & 1 deletion ast/api_compat.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !amd64,!arm64 go1.24 !go1.17 arm64,!go1.20
// +build !amd64,!arm64 go1.25 !go1.17 arm64,!go1.20

/*
* Copyright 2022 ByteDance Inc.
Expand Down
4 changes: 2 additions & 2 deletions ast/api_native_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build (amd64 && go1.17 && !go1.24) || (arm64 && go1.20 && !go1.24)
// +build amd64,go1.17,!go1.24 arm64,go1.20,!go1.24
//go:build (amd64 && go1.17 && !go1.25) || (arm64 && go1.20 && !go1.25)
// +build amd64,go1.17,!go1.25 arm64,go1.20,!go1.25

/*
* Copyright 2022 ByteDance Inc.
Expand Down
2 changes: 1 addition & 1 deletion ast/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,7 @@ func NewBytes(src []byte) Node {
if len(src) == 0 {
panic("empty src bytes")
}
out := rt.EncodeBase64(src)
out := rt.EncodeBase64ToString(src)
return NewString(out)
}

Expand Down
111 changes: 0 additions & 111 deletions ast/stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,126 +17,15 @@
package ast

import (
"unicode/utf8"
"unsafe"

"github.com/bytedance/sonic/internal/rt"
)

//go:noescape
//go:linkname memmove runtime.memmove
//goland:noinspection GoUnusedParameter
func memmove(to unsafe.Pointer, from unsafe.Pointer, n uintptr)

//go:linkname unsafe_NewArray reflect.unsafe_NewArray
//goland:noinspection GoUnusedParameter
func unsafe_NewArray(typ *rt.GoType, n int) unsafe.Pointer

//go:nosplit
func mem2ptr(s []byte) unsafe.Pointer {
return (*rt.GoSlice)(unsafe.Pointer(&s)).Ptr
}

var safeSet = [utf8.RuneSelf]bool{
' ': true,
'!': true,
'"': false,
'#': true,
'$': true,
'%': true,
'&': true,
'\'': true,
'(': true,
')': true,
'*': true,
'+': true,
',': true,
'-': true,
'.': true,
'/': true,
'0': true,
'1': true,
'2': true,
'3': true,
'4': true,
'5': true,
'6': true,
'7': true,
'8': true,
'9': true,
':': true,
';': true,
'<': true,
'=': true,
'>': true,
'?': true,
'@': true,
'A': true,
'B': true,
'C': true,
'D': true,
'E': true,
'F': true,
'G': true,
'H': true,
'I': true,
'J': true,
'K': true,
'L': true,
'M': true,
'N': true,
'O': true,
'P': true,
'Q': true,
'R': true,
'S': true,
'T': true,
'U': true,
'V': true,
'W': true,
'X': true,
'Y': true,
'Z': true,
'[': true,
'\\': false,
']': true,
'^': true,
'_': true,
'`': true,
'a': true,
'b': true,
'c': true,
'd': true,
'e': true,
'f': true,
'g': true,
'h': true,
'i': true,
'j': true,
'k': true,
'l': true,
'm': true,
'n': true,
'o': true,
'p': true,
'q': true,
'r': true,
's': true,
't': true,
'u': true,
'v': true,
'w': true,
'x': true,
'y': true,
'z': true,
'{': true,
'|': true,
'}': true,
'~': true,
'\u007f': true,
}

var hex = "0123456789abcdef"

//go:linkname unquoteBytes encoding/json.unquoteBytes
func unquoteBytes(s []byte) (t []byte, ok bool)
2 changes: 1 addition & 1 deletion compat.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !amd64,!arm64 go1.24 !go1.17 arm64,!go1.20
// +build !amd64,!arm64 go1.25 !go1.17 arm64,!go1.20

/*
* Copyright 2021 ByteDance Inc.
Expand Down
4 changes: 2 additions & 2 deletions decode_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build (amd64 && go1.17 && !go1.24) || (arm64 && go1.20 && !go1.24)
// +build amd64,go1.17,!go1.24 arm64,go1.20,!go1.24
//go:build (amd64 && go1.17 && !go1.25) || (arm64 && go1.20 && !go1.25)
// +build amd64,go1.17,!go1.25 arm64,go1.20,!go1.25

/*
* Copyright 2021 ByteDance Inc.
Expand Down
4 changes: 2 additions & 2 deletions decoder/decoder_compat.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build (!amd64 && !arm64) || go1.24 || !go1.17 || (arm64 && !go1.20)
// +build !amd64,!arm64 go1.24 !go1.17 arm64,!go1.20
//go:build (!amd64 && !arm64) || go1.25 || !go1.17 || (arm64 && !go1.20)
// +build !amd64,!arm64 go1.25 !go1.17 arm64,!go1.20

/*
* Copyright 2023 ByteDance Inc.
Expand Down
4 changes: 2 additions & 2 deletions decoder/decoder_native.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build (amd64 && go1.17 && !go1.24) || (arm64 && go1.20 && !go1.24)
// +build amd64,go1.17,!go1.24 arm64,go1.20,!go1.24
//go:build (amd64 && go1.17 && !go1.25) || (arm64 && go1.20 && !go1.25)
// +build amd64,go1.17,!go1.25 arm64,go1.20,!go1.25


/*
Expand Down
4 changes: 2 additions & 2 deletions decoder/decoder_native_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build (amd64 && go1.17 && !go1.24) || (arm64 && go1.20 && !go1.24)
// +build amd64,go1.17,!go1.24 arm64,go1.20,!go1.24
//go:build (amd64 && go1.17 && !go1.25) || (arm64 && go1.20 && !go1.25)
// +build amd64,go1.17,!go1.25 arm64,go1.20,!go1.25

/*
* Copyright 2021 ByteDance Inc.
Expand Down
4 changes: 2 additions & 2 deletions encode_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build (amd64 && go1.17 && !go1.24) || (arm64 && go1.20 && !go1.24)
// +build amd64,go1.17,!go1.24 arm64,go1.20,!go1.24
//go:build (amd64 && go1.17 && !go1.25) || (arm64 && go1.20 && !go1.25)
// +build amd64,go1.17,!go1.25 arm64,go1.20,!go1.25

/*
* Copyright 2021 ByteDance Inc.
Expand Down
2 changes: 1 addition & 1 deletion encoder/encoder_compat.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !amd64,!arm64 go1.24 !go1.17 arm64,!go1.20
// +build !amd64,!arm64 go1.25 !go1.17 arm64,!go1.20

/*
* Copyright 2023 ByteDance Inc.
Expand Down
2 changes: 1 addition & 1 deletion encoder/encoder_native.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build amd64,go1.17,!go1.24 arm64,go1.20,!go1.24
// +build amd64,go1.17,!go1.25 arm64,go1.20,!go1.25

/*
* Copyright 2023 ByteDance Inc.
Expand Down
2 changes: 1 addition & 1 deletion encoder/encoder_native_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build amd64,go1.17,!go1.24 arm64,go1.20,!go1.24
// +build amd64,go1.17,!go1.25 arm64,go1.20,!go1.25

/*
* Copyright 2021 ByteDance Inc.
Expand Down
2 changes: 2 additions & 0 deletions examples/example_stream_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !go1.24

package example

import (
Expand Down
Loading

0 comments on commit 6918f90

Please sign in to comment.