Skip to content

Commit

Permalink
fix: handle nil pointers in deepcopy (#1195)
Browse files Browse the repository at this point in the history
Previously a deepcopy involving nil pointers would end up with a pointer
to a zero value.

Needed as part of #1155
  • Loading branch information
matt2e authored Apr 8, 2024
1 parent c1cb72d commit 3a0415f
Show file tree
Hide file tree
Showing 25 changed files with 432 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ linters-settings:
desc: "use fmt.Errorf or errors.New"
- pkg: os/exec
desc: "use github.com/TBD54566975/ftl/internal/exec"
- pkg: golang.design/x/reflect
desc: "use github.com/TBD54566975/ftl/internal/reflect"
# wrapcheck:
# ignorePackageGlobs:
# - github.com/TBD54566975/ftl/*
Expand Down
2 changes: 1 addition & 1 deletion backend/schema/builtin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package schema

import "golang.design/x/reflect"
import "github.com/TBD54566975/ftl/internal/reflect"

// BuiltinsSource is the schema source code for built-in types.
const BuiltinsSource = `
Expand Down
2 changes: 1 addition & 1 deletion backend/schema/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

"golang.design/x/reflect"
"github.com/TBD54566975/ftl/internal/reflect"
"google.golang.org/protobuf/proto"

schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema"
Expand Down
2 changes: 1 addition & 1 deletion backend/schema/normalise.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package schema

import "golang.design/x/reflect"
import "github.com/TBD54566975/ftl/internal/reflect"

// Normalise clones and normalises (zeroes) positional information in schema Nodes.
func Normalise[T Node](n T) T {
Expand Down
4 changes: 2 additions & 2 deletions backend/schema/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"sort"
"strings"

dc "github.com/TBD54566975/ftl/internal/reflect"
"github.com/alecthomas/participle/v2"
"github.com/alecthomas/types/optional"
xreflect "golang.design/x/reflect"
"golang.org/x/exp/maps"

"github.com/TBD54566975/ftl/internal/errors"
Expand Down Expand Up @@ -47,7 +47,7 @@ func MustValidate(schema *Schema) *Schema {

// Validate clones, normalises and semantically valies a schema.
func Validate(schema *Schema) (*Schema, error) {
schema = xreflect.DeepCopy(schema)
schema = dc.DeepCopy(schema)
modules := map[string]bool{}
merr := []error{}
ingress := map[string]*Verb{}
Expand Down
2 changes: 1 addition & 1 deletion buildengine/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"path/filepath"

"golang.design/x/reflect"
"github.com/TBD54566975/ftl/internal/reflect"

"github.com/TBD54566975/ftl/common/moduleconfig"
)
Expand Down
1 change: 0 additions & 1 deletion buildengine/testdata/projects/alpha/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ require (
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.design/x/reflect v0.0.0-20220504060917-02c43be63f3b // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.16.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions buildengine/testdata/projects/alpha/go.sum

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

1 change: 0 additions & 1 deletion buildengine/testdata/projects/another/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ require (
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.design/x/reflect v0.0.0-20220504060917-02c43be63f3b // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.16.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions buildengine/testdata/projects/another/go.sum

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

1 change: 0 additions & 1 deletion buildengine/testdata/projects/other/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ require (
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.design/x/reflect v0.0.0-20220504060917-02c43be63f3b // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.16.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions buildengine/testdata/projects/other/go.sum

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

1 change: 0 additions & 1 deletion examples/go/echo/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ require (
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.design/x/reflect v0.0.0-20220504060917-02c43be63f3b // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.16.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions examples/go/echo/go.sum

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

2 changes: 1 addition & 1 deletion go-runtime/compile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"strconv"
"strings"

"github.com/TBD54566975/ftl/internal/reflect"
"github.com/TBD54566975/scaffolder"
"golang.design/x/reflect"
"golang.org/x/mod/modfile"
"golang.org/x/sync/errgroup"
"google.golang.org/protobuf/proto"
Expand Down
1 change: 0 additions & 1 deletion go-runtime/compile/testdata/failing/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ require (
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.design/x/reflect v0.0.0-20220504060917-02c43be63f3b // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.16.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go-runtime/compile/testdata/failing/go.sum

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

1 change: 0 additions & 1 deletion go-runtime/compile/testdata/one/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ require (
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.design/x/reflect v0.0.0-20220504060917-02c43be63f3b // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.16.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go-runtime/compile/testdata/one/go.sum

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

1 change: 0 additions & 1 deletion go-runtime/compile/testdata/two/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ require (
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.design/x/reflect v0.0.0-20220504060917-02c43be63f3b // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.16.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go-runtime/compile/testdata/two/go.sum

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

1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ require (
github.com/serialx/hashring v0.0.0-20200727003509-22c0c7ab6b1b
github.com/swaggest/refl v1.3.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect
golang.design/x/reflect v0.0.0-20220504060917-02c43be63f3b
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum

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

Loading

0 comments on commit 3a0415f

Please sign in to comment.