Skip to content

feat: support Go 1.27#957

Open
liuq19 wants to merge 6 commits into
bytedance:mainfrom
liuq19:fix/go124tags
Open

feat: support Go 1.27#957
liuq19 wants to merge 6 commits into
bytedance:mainfrom
liuq19:fix/go124tags

Conversation

@liuq19

@liuq19 liuq19 commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • extend native/JIT build guards so amd64 and arm64 fast paths cover Go 1.27
  • add the Go 1.27 loader moduledata layout and keep the legacy map iterator compatibility tail field
  • document encoding/json jsonv2-backend parity differences and gate only the affected issue_test parity assertions
  • make the PCSP helper accept release-candidate Go version strings used by actions/setup-go

Validation

  • env -u GOROOT GOTOOLCHAIN=local /data02/home/liuq/sdk/go1.27rc1/bin/go test -count=1 ./...
  • env -u GOROOT GOTOOLCHAIN=local SONIC_USE_OPTDEC=1 SONIC_USE_FASTMAP=1 SONIC_ENCODER_USE_VM=1 /data02/home/liuq/sdk/go1.27rc1/bin/go test -count=1 ./...
  • env -u GOROOT GOTOOLCHAIN=local /data02/home/liuq/sdk/go1.27rc1/bin/go test -count=1 ./loader/...
  • env -u GOROOT GOTOOLCHAIN=local /data02/home/liuq/sdk/go1.27rc1/bin/go test -count=1 ./issue_test
  • env -u GOROOT GOEXPERIMENT=nojsonv2 GOTOOLCHAIN=local /data02/home/liuq/sdk/go1.27rc1/bin/go test -count=1 ./issue_test
  • env -u GOROOT GOTOOLCHAIN=local GOVERSION=1.27.0-rc.1 PATH=/data02/home/liuq/sdk/go1.27rc1/bin:$PATH python3 ./scripts/test_pcsp.py
  • python3 -m py_compile scripts/test_pcsp.py
  • git diff --check

@codecov-commenter

codecov-commenter commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 53.36%. Comparing base (59be92f) to head (5ef43eb).
⚠️ Report is 83 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #957      +/-   ##
==========================================
+ Coverage   51.86%   53.36%   +1.49%     
==========================================
  Files         127      171      +44     
  Lines       10893    14146    +3253     
==========================================
+ Hits         5650     7549    +1899     
- Misses       4920     6502    +1582     
+ Partials      323       95     -228     
Flag Coverage Δ
arm 45.40% <ø> (?)
macos-latest 47.00% <ø> (?)
ubuntu-24.04-arm 45.40% <ø> (?)
ubuntu-latest 52.08% <ø> (?)
x86 52.08% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

liuq19 added 2 commits June 24, 2026 16:03
Bump the native JIT version guards from `!go1.27` to `!go1.28` so the
amd64/arm64 fast paths cover Go 1.27, and mirror the Go 1.27 runtime
changes:

- loader: add funcdata_go127.go mirroring the new runtime.moduledata
  layout (typedesclen between types/etypes, itaboffset/itabsize after
  etypes, dropped typelinks/itablinks, typemap retyped to
  map[*_type]*_type); _func is unchanged from 1.26. funcdata_go126.go
  keeps its !go1.27 ceiling.
- compat: extend the fallback warning range to go1.17~1.27 /
  go1.20~1.27.
- json v2: Go 1.27 defaults encoding/json to the json v2 backend
  (GOEXPERIMENT=jsonv2). Add a stdUsesJSONV2 const gated on the
  goexperiment.jsonv2 build tag (jsonv2_compat_test.go /
  jsonv1_compat_test.go) and skip the ~10 issue_test cases that assert
  byte-for-byte parity against the live encoding/json, since sonic keeps
  v1 semantics. See docs/json-v2-alignment.md.
- README: bump supported range to Go 1.18~1.27.

Verified on go1.27rc1: build, loader (moduledataverify1), issue_test
(both default v2 and GOEXPERIMENT=nojsonv2), and core
ast/decoder/encoder/rt packages all pass; go1.26.3 still green.
@liuq19 liuq19 marked this pull request as ready for review June 24, 2026 09:04
Copilot AI review requested due to automatic review settings June 24, 2026 09:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Sonic’s build constraints and runtime/loader shims to run the native/JIT fast paths on Go 1.27, and adjusts issue_test parity assertions to account for Go 1.27’s encoding/json jsonv2 backend divergences.

Changes:

  • Extend amd64/arm64 optimized build tags to include Go 1.27 (by shifting the “fallback at” guard to Go 1.28).
  • Add Go 1.27-specific loader moduledata layout support and keep map iterator compatibility aligned.
  • Document jsonv2 parity differences and gate only the affected issue_test parity checks via stdUsesJSONV2.

Reviewed changes

Copilot reviewed 55 out of 55 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
utf8/utf8.go Extend native utf8 build guard through Go 1.27.
utf8/utf8_native_test.go Align native utf8 tests with updated Go version guards.
utf8/utf8_fallback.go Shift fallback selection to Go 1.28+.
unquote/unquote.go Extend unquote native build guard through Go 1.27.
unquote/unquote_fallback.go Shift unquote fallback selection to Go 1.28+.
sonic.go Extend top-level native build guard through Go 1.27.
search_test.go Extend native test build guard through Go 1.27.
rfc_test.go Extend native test build guard through Go 1.27.
README.md Update documented supported Go range to 1.27.
README_ZH_CN.md Update documented supported Go range to 1.27 (ZH-CN).
loader/moduledata.go Adjust loader build constraints for Go 1.27 selection.
loader/funcdata_go127.go Add Go 1.27-specific moduledata/_func layout definitions.
loader/funcdata_compat.go Shift “compat” loader selection to Go 1.28+.
issue_test/jsonv2_compat_test.go Define stdUsesJSONV2=true under jsonv2 experiment.
issue_test/jsonv1_compat_test.go Define stdUsesJSONV2=false when jsonv2 is not active.
issue_test/issue827_test.go Gate std-parity assertions for jsonv2; keep Sonic internal consistency checks.
issue_test/issue824_test.go Gate float-map parity behavior under jsonv2.
issue_test/issue772_test.go Skip legacy parity case under jsonv2.
issue_test/issue758_test.go Skip stack-overflowing std jsonv2 behavior under jsonv2.
issue_test/issue747_test.go Gate legacy encoding/json comparison under jsonv2.
issue_test/issue670_test.go Skip legacy parity under jsonv2 for affected case(s).
issue_test/issue491_test.go Skip legacy parity under jsonv2 for affected case(s).
issue_test/issue460_test.go Skip legacy parity under jsonv2; reformat test.
issue_test/issue379_test.go Skip legacy parity under jsonv2; reformat test.
issue_test/issue144_test.go Skip legacy parity under jsonv2; reformat test.
internal/rt/map.go Extend map iterator layout to match newer runtime expectations.
internal/rt/gcwb.go Extend gc write-barrier fast path build guard through Go 1.27.
internal/rt/base64_compat.go Shift base64 compat selection to Go 1.28+.
internal/rt/base64_amd64.go Extend amd64 base64 fast path build guard through Go 1.27.
internal/encoder/x86/debug_go117.go Extend x86 debug build guard through Go 1.27.
internal/encoder/x86/assembler_regabi_amd64.go Extend regabi assembler build guard through Go 1.27.
internal/encoder/x86/assembler_export_amd64.go Extend export assembler build guard through Go 1.27.
internal/encoder/x86/asm_stubs_amd64_go121.go Extend asm stubs build guard through Go 1.27.
internal/encoder/alg/spec.go Extend alg spec build guard through Go 1.27.
internal/encoder/alg/spec_compat.go Shift alg spec compat selection to Go 1.28+.
internal/decoder/jitdec/generic_regabi_amd64.go Extend jit decoder regabi build guard through Go 1.27.
internal/decoder/jitdec/assembler_regabi_amd64.go Extend jit decoder assembler build guard through Go 1.27.
internal/decoder/jitdec/asm_stubs_amd64_go121.go Extend jit decoder asm stubs build guard through Go 1.27.
internal/decoder/api/decoder_arm64.go Extend arm64 decoder native build guard through Go 1.27.
internal/decoder/api/decoder_amd64.go Extend amd64 decoder native build guard through Go 1.27.
internal/compat/warn.go Update fallback warning text and build constraints for Go 1.27 support.
encoder/encoder_native.go Extend encoder native build guard through Go 1.27.
encoder/encoder_native_test.go Align encoder native tests with updated Go version guards.
encoder/encoder_compat.go Shift encoder compat selection to Go 1.28+.
encode_test.go Extend encode tests build guard through Go 1.27.
docs/json-v2-alignment.md Add documentation describing jsonv2 parity divergences and test gating.
decoder/decoder_native.go Extend decoder native build guard through Go 1.27.
decoder/decoder_native_test.go Align decoder native tests with updated Go version guards.
decoder/decoder_compat.go Shift decoder compat selection to Go 1.28+.
decode_test.go Extend decode tests build guard through Go 1.27.
compat.go Shift top-level compat selection to Go 1.28+.
ast/api.go Extend AST native build guard through Go 1.27.
ast/api_native_test.go Align AST native tests with updated Go version guards.
ast/api_compat.go Shift AST compat selection to Go 1.28+.
.github/workflows/compatibility_test.yml Adjust CI runner OS set (macOS) for compatibility testing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread loader/moduledata.go Outdated
Comment on lines +1 to +2
// go:build go1.18 && !go1.28
// +build go1.18,!go1.28
Comment on lines 18 to 23
import (
`encoding/json`
`testing`
`github.com/bytedance/sonic`
`github.com/stretchr/testify/require`
"encoding/json"
"github.com/bytedance/sonic"
"github.com/stretchr/testify/require"
"testing"
)
Comment thread docs/json-v2-alignment.md
Comment on lines +50 to +53
| Issue758 | self-referential `interface{}` (`v = &v`) | sonic handles it | **v2 std recurses to stack overflow** (sonic is fine) |
| Issue772 | skipping iface-typed fields (non-ptr / nil) | v1 skip behavior | v2 skip behavior differs |
| Issue824 (`TestFloatMap`) | marshal `map[float64]string` | v1 float-key formatting | v2 float-key formatting differs |
| Issue827 | `TextMarshaler` types (e.g. `string3`) | v1 TextMarshaler handling | v2 TextMarshaler handling differs |
Comment on lines 8 to +10
matrix:
go-version: [1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x, 1.23.x, 1.24.x, 1.25.x]
os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest]
os: [ubuntu-latest, ubuntu-24.04-arm, macos-15]
liuq19 and others added 2 commits June 26, 2026 12:18
Resolve the four Copilot review comments on PR bytedance#957:

- loader/moduledata.go: fix the build-constraint comment `// go:build`
  (with a space, silently ignored by the toolchain) to the canonical
  `//go:build` form; the file no longer relies solely on the legacy
  `// +build` line.
- issue_test/issue460_test.go: group stdlib imports separately from
  third-party imports, matching the other reformatted issue tests.
- docs/json-v2-alignment.md: correct the Issue824 row — std v1 errors on
  `map[float64]string` (`unsupported type`), while v2 marshals it to
  `{"1":""}`; also clarify the Issue491 marshal/unmarshal row.
- CI: add go1.27.0-rc.1 to the x86 / arm64 / compatibility matrices so
  the newly-supported version is exercised; gate the new
  TestIssue491_UnmarshalUnsupported parity case behind stdUsesJSONV2.

Verified on go1.27rc1: build, loader, and the affected issue_test cases
pass under both the default jsonv2 backend and GOEXPERIMENT=nojsonv2.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants