Skip to content

Commit

Permalink
Release v1.27.0 (#479)
Browse files Browse the repository at this point in the history
This releases v1.27.0 with the following changes:

- Support parsing Thrift files that contain a `cpp_include` headers
- Support double constants without decimal components
- Handle escaped quotes inside string literals

Thanks to @jparise for these fixes.

I'm considering this a minor release, even though we could make a case for all
of these changes being bugfixes, largely because it contains changes to the
parser which is ever so slightly riskier than a usual bugfix.
  • Loading branch information
abhinav authored May 20, 2021
2 parents dc51c30 + 60ef33b commit 39f2ce9
Show file tree
Hide file tree
Showing 35 changed files with 5,854 additions and 4,985 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: build

on:
push:
branches: ['*']
tags: ['v*']
pull_request:
branches: ['*']

jobs:

build:
runs-on: ubuntu-latest
strategy:
matrix:
go: ["1.15.x", "1.16.x"]
include:
- go: 1.16.x
latest: true

steps:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}

- name: Checkout code
uses: actions/checkout@v2

- name: Load cached dependencies
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download Dependencies
run: go mod download

- name: Lint
if: matrix.latest
run: make lint

- name: Test
run: make cover

- name: Upload coverage to codecov.io
uses: codecov/codecov-action@v1
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.27.0] - 2021-05-20
### Added
- ThriftRW is now able to parse Thrift files with `cpp_include` statements.

### Fixed
- `double` constants with exponents but without decimal components are now supported.
- Fix handling of escaped quotes inside string literals.

## [1.26.0] - 2021-02-18
### Changed
- Codegeneration for typedefs now uses use generated `MarshalLog...` functions
Expand Down Expand Up @@ -357,6 +365,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- Initial release.

[1.27.0]: https://github.com/thriftrw/thriftrw-go/compare/v1.26.0...v1.27.0
[1.26.0]: https://github.com/thriftrw/thriftrw-go/compare/v1.25.1...v1.26.0
[1.25.1]: https://github.com/thriftrw/thriftrw-go/compare/v1.25.0...v1.25.1
[1.25.0]: https://github.com/thriftrw/thriftrw-go/compare/v1.24.0...v1.25.0
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ lint: $(GOLINT) $(STATICCHECK)
@$(STATICCHECK) ./... 2>&1 | $(LINT_FILTER) | tee -a lint.log
@[ ! -s lint.log ]

$(GOLINT): go.mod
go install golang.org/x/lint/golint

$(STATICCHECK): go.mod
go install honnef.co/go/tools/cmd/staticcheck

.PHONY: verifyversion
verifyversion:
$(eval CHANGELOG_VERSION := $(shell perl -ne '/^## \[(\S+?)\]/ && print "v$$1\n"' CHANGELOG.md | head -n1))
Expand Down Expand Up @@ -121,7 +127,7 @@ space +=

.PHONY: cover
cover:
go test -v -covermode=atomic -coverprofile cover.full.out -coverpkg=./... ./...
go test -v -race -covermode=atomic -coverprofile cover.full.out -coverpkg=./... ./...
grep -v "$(subst $(space),\|,$(COVER_IGNORE_FILES))" cover.full.out > cover.out
go tool cover -html=cover.out -o cover.html

Expand Down
25 changes: 23 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,19 @@ To release new versions of ThriftRW Go, follow these instructions.

9. Land the pull request after approval as a **merge commit**. To do this,
select **Create a merge commit** from the pull-down next to the merge
button and click **Merge pull request**. Make sure you delete that branch
after it has been merged with **Delete Branch**.
button and click **Merge pull request**.

Please update the subject to be the release. For example, v1.2.3 (#PR).
The body of the merge commit should be a short description of the
changes to be merged into master.

Please note that the pull request title and comment are NOT the contents
of the merge commit subject and body. The merge commit message is set
in the form that appears after you click **Merge pull request** and before
you confirm the merge.

Make sure you delete that branch after it has been merged with
**Delete Branch**.

10. Once the change has been landed, pull it locally.

Expand Down Expand Up @@ -127,3 +138,13 @@ To release new versions of ThriftRW Go, follow these instructions.

git commit -am "Back to development"
hub pull-request -b dev --push

19. Merge this pull request once approved as a merge commit.

Please update the subject of the the merge commit as 'Back to
development (#PR)', message body contents are not required.

Please note that the pull request title and comment are NOT the contents
of the merge commit subject and body. The merge commit message is set
in the form that appears after you click **Merge pull request** and before
you confirm the merge.
20 changes: 20 additions & 0 deletions ast/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ func (i *Include) Info() HeaderInfo {
return HeaderInfo{Line: i.Line}
}

// CppInclude is a request to include a C++-specific header file.
//
// cpp_include "<unordered_map>"
type CppInclude struct {
Path string
Line int
}

func (*CppInclude) node() {}
func (*CppInclude) header() {}

func (i *CppInclude) lineNumber() int { return i.Line }

func (*CppInclude) visitChildren(nodeStack, visitor) {}

// Info for CppInclude.
func (i *CppInclude) Info() HeaderInfo {
return HeaderInfo{Line: i.Line}
}

// Namespace statements allow users to choose the package name used by the
// generated code in certain languages.
//
Expand Down
7 changes: 7 additions & 0 deletions ast/walk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,13 @@ func TestWalk(t *testing.T) {
{node: &ast.Include{Path: "foo.thrift"}},
},
},
{
desc: "cpp_include",
node: &ast.CppInclude{Path: "<unordered_map>"},
visits: []visit{
{node: &ast.CppInclude{Path: "<unordered_map>"}},
},
},
func() (tt test) {
tt.desc = "list type"

Expand Down
191 changes: 191 additions & 0 deletions gen/benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
package gen_test

import (
"bytes"
"math"
"testing"

"github.com/stretchr/testify/require"
tc "go.uber.org/thriftrw/gen/internal/tests/containers"
ts "go.uber.org/thriftrw/gen/internal/tests/structs"
"go.uber.org/thriftrw/protocol"
"go.uber.org/thriftrw/ptr"
"go.uber.org/thriftrw/wire"
)

type thriftType interface {
ToWire() (wire.Value, error)
FromWire(wire.Value) error
}

func BenchmarkRoundTrip(b *testing.B) {
type benchCase struct {
name string
give thriftType
}

benchmarks := []benchCase{
{
name: "PrimitiveOptionalStruct",
give: &ts.PrimitiveOptionalStruct{
BoolField: ptr.Bool(true),
ByteField: ptr.Int8(42),
Int16Field: ptr.Int16(123),
Int32Field: ptr.Int32(1234),
Int64Field: ptr.Int64(123456),
DoubleField: ptr.Float64(math.Pi),
StringField: ptr.String("foo"),
BinaryField: []byte("bar"),
},
},
{
name: "Graph",
give: &ts.Graph{
Edges: []*ts.Edge{
{
StartPoint: &ts.Point{X: 1.0, Y: 2.0},
EndPoint: &ts.Point{X: 3.0, Y: 4.0},
},
{
StartPoint: &ts.Point{X: 5.0, Y: 6.0},
EndPoint: &ts.Point{X: 7.0, Y: 8.0},
},
{
StartPoint: &ts.Point{X: 9.0, Y: 10.0},
EndPoint: &ts.Point{X: 11.0, Y: 12.0},
},
},
},
},
{
name: "ContainersOfContainers",
give: &tc.ContainersOfContainers{
ListOfLists: [][]int32{
int32range(1, 10),
int32range(2, 20),
int32range(3, 30),
int32range(4, 40),
int32range(5, 50),
},
ListOfSets: []map[int32]struct{}{
int32set(int32range(6, 60)...),
int32set(int32range(7, 70)...),
int32set(int32range(8, 80)...),
int32set(int32range(9, 90)...),
int32set(int32range(10, 100)...),
},
ListOfMaps: []map[int32]int32{
int32multiply(42, int32range(5, 10)...),
int32multiply(43, int32range(6, 20)...),
int32multiply(44, int32range(7, 30)...),
},
SetOfSets: []map[string]struct{}{
stringset("foo", "bar", "baz", "qux", "quux"),
stringset("bar", "baz", "qux", "quux"),
stringset("baz", "qux", "quux"),
stringset("qux", "quux"),
stringset("quux"),
stringset(),
},
SetOfLists: [][]string{
{"foo", "bar", "baz", "qux", "quux"},
{"bar", "baz", "qux", "quux"},
{"baz", "qux", "quux"},
{"qux", "quux"},
{"quux"},
{},
},
SetOfMaps: []map[string]string{
{"foo": "bar"},
{"bar": "baz"},
{"baz": "qux"},
{"qux": "quux"},
{"quux": "foo"},
},
},
},
}

benchmarkEncode := func(b *testing.B, bb benchCase) {
var buff bytes.Buffer

b.ResetTimer()
for i := 0; i < b.N; i++ {
buff.Reset()

w, err := bb.give.ToWire()
require.NoError(b, err, "ToWire")
require.NoError(b, protocol.Binary.Encode(w, &buff), "Encode")
}
}

benchmarkDecode := func(b *testing.B, bb benchCase) {
var buff bytes.Buffer
w, err := bb.give.ToWire()
require.NoError(b, err, "ToWire")
require.NoError(b, protocol.Binary.Encode(w, &buff), "Encode")

r := bytes.NewReader(buff.Bytes())

b.ResetTimer()
for i := 0; i < b.N; i++ {
r.Seek(0, 0)

wval, err := protocol.Binary.Decode(r, wire.TStruct)
require.NoError(b, err, "Decode")

require.NoError(b, bb.give.FromWire(wval), "FromWire")
}
}

for _, bb := range benchmarks {
b.Run(bb.name, func(b *testing.B) {
b.Run("Encode", func(b *testing.B) {
benchmarkEncode(b, bb)
})

b.Run("Decode", func(b *testing.B) {
benchmarkDecode(b, bb)
})
})
}
}

// Generates a slice representing the range [from, to).
func int32range(from, to int32) []int32 {
if from > to {
from, to = to, from
}

out := make([]int32, 0, to-from)
for i := from; i < to; i++ {
out = append(out, i)
}
return out
}

func int32set(i ...int32) map[int32]struct{} {
o := make(map[int32]struct{}, len(i))
for _, x := range i {
o[x] = struct{}{}
}
return o
}

// maps provided numbers to the result of multipliying them with the provided
// number.
func int32multiply(with int32, nums ...int32) map[int32]int32 {
o := make(map[int32]int32, len(nums))
for _, x := range nums {
o[x] = x * with
}
return o
}

func stringset(ss ...string) map[string]struct{} {
o := make(map[string]struct{}, len(ss))
for _, s := range ss {
o[s] = struct{}{}
}
return o
}
2 changes: 1 addition & 1 deletion gen/internal/tests/collision/collision.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 39f2ce9

Please sign in to comment.