Skip to content

Commit

Permalink
refactor: deprecated go1.17 (#62)
Browse files Browse the repository at this point in the history
* go fix -fix=buildtag ./...
* added build tag for debug pkg which uses JIT code
* reflect: removed go1.17 code, removed mapiter linkname
* ci: removed go1.17, added 1.23
* fuzz: removed kitex dep
  • Loading branch information
xiaost authored Sep 24, 2024
1 parent 9336b09 commit a1e494c
Show file tree
Hide file tree
Showing 31 changed files with 336 additions and 1,546 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
compatibility-test-amd64:
strategy:
matrix:
go: [ "1.17", "1.18", "1.19", "1.20", "1.21", "1.22" ]
go: [ "1.18", "1.19", "1.20", "1.21", "1.22", "1.23" ]
os: [ X64 ]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -26,7 +26,7 @@ jobs:
compatibility-test-arm64:
strategy:
matrix:
go: [ "1.17", "1.18", "1.19", "1.20", "1.21", "1.22" ]
go: [ "1.18", "1.19", "1.20", "1.21", "1.22", "1.23" ]
os: [ ARM64 ]
runs-on: ${{ matrix.os }}
steps:
Expand Down
27 changes: 3 additions & 24 deletions debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@
* limitations under the License.
*/

// Package debug is only for JIT encoder/decoder.
//
// It's deprecated.
package debug

import (
"github.com/cloudwego/frugal/internal/jit/decoder"
"github.com/cloudwego/frugal/internal/jit/encoder"
"github.com/cloudwego/frugal/internal/jit/loader"
)

// A Stats records statistics about the JIT compiler.
type Stats struct {
Memory MemStats
Expand All @@ -41,21 +38,3 @@ type CacheStats struct {
Miss int
Size int
}

// GetStats returns statistics of the JIT compiler.
func GetStats() Stats {
return Stats{
Memory: MemStats{
Count: int(loader.FnCount),
Alloc: int(loader.LoadSize),
},
Encoder: CacheStats{
Miss: int(encoder.MissCount),
Size: int(encoder.TypeCount),
},
Decoder: CacheStats{
Miss: int(decoder.MissCount),
Size: int(decoder.TypeCount),
},
}
}
22 changes: 4 additions & 18 deletions internal/reflect/hack_go1.18.go → debug/debug_go124.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build go1.18
//go:build go1.24 || !amd64 || windows

/*
* Copyright 2024 CloudWeGo Authors
Expand All @@ -16,21 +16,7 @@
* limitations under the License.
*/

package reflect
package debug

import (
"reflect"
"unsafe"
)

type hackMapIter struct {
m reflect.Value
hitter hitter // it's a pointer before go1.18
}

func (iter *hackMapIter) initialized() bool { return iter.hitter.k != nil }

func (iter *hackMapIter) Next() (unsafe.Pointer, unsafe.Pointer) {
mapiternext(unsafe.Pointer(&iter.hitter))
return iter.hitter.k, iter.hitter.v
}
// GetStats returns statistics of the JIT compiler.
func GetStats() Stats { return Stats{} } // only for JIT
43 changes: 43 additions & 0 deletions debug/debug_jit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//go:build !go1.24 && amd64 && !windows

/*
* Copyright 2022 CloudWeGo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package debug

import (
"github.com/cloudwego/frugal/internal/jit/decoder"
"github.com/cloudwego/frugal/internal/jit/encoder"
"github.com/cloudwego/frugal/internal/jit/loader"
)

// GetStats returns statistics of the JIT compiler.
func GetStats() Stats {
return Stats{
Memory: MemStats{
Count: int(loader.FnCount),
Alloc: int(loader.LoadSize),
},
Encoder: CacheStats{
Miss: int(encoder.MissCount),
Size: int(encoder.TypeCount),
},
Decoder: CacheStats{
Miss: int(decoder.MissCount),
Size: int(decoder.TypeCount),
},
}
}
2 changes: 1 addition & 1 deletion fuzz/builder/dynamic_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"log"
"reflect"

"github.com/apache/thrift/lib/go/thrift"
"github.com/cloudwego/frugal/fuzz"
"github.com/cloudwego/gopkg/protocol/thrift"
"github.com/cloudwego/thriftgo/parser"
"github.com/cloudwego/thriftgo/semantic"
)
Expand Down
56 changes: 12 additions & 44 deletions fuzz/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import (
"sort"
"strings"

"github.com/apache/thrift/lib/go/thrift"
"github.com/cloudwego/kitex/pkg/protocol/bthrift"
"github.com/cloudwego/gopkg/protocol/thrift"
)

var TypeSize = map[thrift.TType]int{
Expand Down Expand Up @@ -57,42 +56,37 @@ func Check(buf []byte, fieldTypeID thrift.TType) (typ *Type, length int, err err
typ = &Type{TypeID: fieldTypeID}
switch fieldTypeID {
case thrift.BOOL:
_, l, err = bthrift.Binary.ReadBool(buf)
_, l, err = thrift.Binary.ReadBool(buf)
length += l
return
case thrift.BYTE:
_, l, err = bthrift.Binary.ReadByte(buf)
_, l, err = thrift.Binary.ReadByte(buf)
length += l
return
case thrift.I16:
_, l, err = bthrift.Binary.ReadI16(buf)
_, l, err = thrift.Binary.ReadI16(buf)
length += l
return
case thrift.I32:
_, l, err = bthrift.Binary.ReadI32(buf)
_, l, err = thrift.Binary.ReadI32(buf)
length += l
return
case thrift.I64:
_, l, err = bthrift.Binary.ReadI64(buf)
_, l, err = thrift.Binary.ReadI64(buf)
length += l
return
case thrift.DOUBLE:
_, l, err = bthrift.Binary.ReadDouble(buf)
_, l, err = thrift.Binary.ReadDouble(buf)
length += l
return
case thrift.STRING:
_, l, err = bthrift.Binary.ReadString(buf)
_, l, err = thrift.Binary.ReadString(buf)
length += l
return
case thrift.STRUCT:
_, l, err = bthrift.Binary.ReadStructBegin(buf)
length += l
if err != nil {
return
}
fields := make(map[int16]*Type)
for {
_, typeID, id, l, e := bthrift.Binary.ReadFieldBegin(buf[length:])
typeID, id, l, e := thrift.Binary.ReadFieldBegin(buf[length:])
length += l
if e != nil {
err = e
Expand All @@ -112,22 +106,11 @@ func Check(buf []byte, fieldTypeID thrift.TType) (typ *Type, length int, err err
return
}
fields[id] = fType
l, e = bthrift.Binary.ReadFieldEnd(buf[length:])
length += l
if e != nil {
err = e
return
}
}
l, e := bthrift.Binary.ReadStructEnd(buf[length:])
length += l
if e != nil {
err = e
}
typ.Fields = fields
return
case thrift.MAP:
keyTypeID, valTypeID, size, l, e := bthrift.Binary.ReadMapBegin(buf)
keyTypeID, valTypeID, size, l, e := thrift.Binary.ReadMapBegin(buf)
length += l
if e != nil {
err = e
Expand Down Expand Up @@ -172,17 +155,12 @@ func Check(buf []byte, fieldTypeID thrift.TType) (typ *Type, length int, err err
if valTypes.Conflict() {
return nil, 0, fmt.Errorf("map value type conflict")
}
l, e = bthrift.Binary.ReadMapEnd(buf[length:])
length += l
if e != nil {
err = e
}
// NOTE: considering combine types to one complete type
typ.KeyType = keyTypes[0]
typ.ValType = valTypes[0]
return
case thrift.SET:
elemTypeID, size, l, e := bthrift.Binary.ReadSetBegin(buf)
elemTypeID, size, l, e := thrift.Binary.ReadSetBegin(buf)
length += l
if e != nil {
err = e
Expand Down Expand Up @@ -232,16 +210,11 @@ func Check(buf []byte, fieldTypeID thrift.TType) (typ *Type, length int, err err
if elemTypes.Conflict() {
return nil, 0, fmt.Errorf("set element type conflict")
}
l, e = bthrift.Binary.ReadSetEnd(buf[length:])
length += l
if e != nil {
err = e
}
// NOTE: considering combine types to one complete type
typ.ValType = elemTypes[0]
return
case thrift.LIST:
elemTypeID, size, l, e := bthrift.Binary.ReadListBegin(buf)
elemTypeID, size, l, e := thrift.Binary.ReadListBegin(buf)
length += l
if e != nil {
err = e
Expand Down Expand Up @@ -269,11 +242,6 @@ func Check(buf []byte, fieldTypeID thrift.TType) (typ *Type, length int, err err
if elemTypes.Conflict() {
return nil, 0, fmt.Errorf("list element type conflict")
}
l, e = bthrift.Binary.ReadListEnd(buf[length:])
length += l
if e != nil {
err = e
}
// NOTE: considering combine types to one complete type
typ.ValType = elemTypes[0]
return
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (

_ "net/http/pprof"

"github.com/apache/thrift/lib/go/thrift"
"github.com/bytedance/gopkg/util/gctuner"
"github.com/cloudwego/frugal"
"github.com/cloudwego/gopkg/protocol/thrift"
)

const (
Expand Down
9 changes: 3 additions & 6 deletions fuzz/go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
module github.com/cloudwego/frugal/fuzz

go 1.15
go 1.18

require (
github.com/apache/thrift v0.13.0
github.com/brianvoe/gofakeit/v6 v6.19.0
github.com/bytedance/gopkg v0.0.0-20220824043955-beb90005fda6
github.com/choleraehyq/pid v0.0.18 // indirect
github.com/bytedance/gopkg v0.1.1
github.com/cloudwego/frugal v0.1.7
github.com/cloudwego/kitex v0.4.4
github.com/cloudwego/gopkg v0.1.2
github.com/cloudwego/thriftgo v0.2.4
google.golang.org/genproto v0.0.0-20230216225411-c8e22ba71e44 // indirect
)

replace github.com/cloudwego/frugal => ../
Loading

0 comments on commit a1e494c

Please sign in to comment.