From 23842d7f13ec4b7f5782572c75ad4eb49e530cb8 Mon Sep 17 00:00:00 2001 From: worstell Date: Tue, 1 Oct 2024 16:56:18 -0700 Subject: [PATCH] fix: verb call order (#2940) we can't sort this way because the generated resource providers need to match the param ordering to ensure they pass the correct resources in place. will have to think of another solution to stable sort here --- go-runtime/schema/schema_test.go | 2 +- go-runtime/schema/testdata/named/types.ftl.go | 11 +++--- .../schema/testdata/namedext/types.ftl.go | 1 - go-runtime/schema/testdata/one/types.ftl.go | 28 +++++++-------- .../schema/testdata/parent/types.ftl.go | 14 ++++---- .../schema/testdata/pubsub/types.ftl.go | 15 ++++---- .../schema/testdata/subscriber/types.ftl.go | 12 +++---- go-runtime/schema/testdata/two/types.ftl.go | 36 +++++++++---------- go-runtime/schema/verb/analyzer.go | 16 +-------- 9 files changed, 55 insertions(+), 80 deletions(-) diff --git a/go-runtime/schema/schema_test.go b/go-runtime/schema/schema_test.go index c696e54f0..acc7d75d1 100644 --- a/go-runtime/schema/schema_test.go +++ b/go-runtime/schema/schema_test.go @@ -273,7 +273,7 @@ func TestExtractModuleSchemaTwo(t *testing.T) { +calls two.two export verb callsTwoAndThree(two.Payload) two.Payload - +calls two.three, two.two + +calls two.two, two.three export verb ingress(builtin.HttpRequest) builtin.HttpResponse +ingress http POST /users diff --git a/go-runtime/schema/testdata/named/types.ftl.go b/go-runtime/schema/testdata/named/types.ftl.go index 0f11de20a..fdf041c79 100644 --- a/go-runtime/schema/testdata/named/types.ftl.go +++ b/go-runtime/schema/testdata/named/types.ftl.go @@ -2,9 +2,8 @@ package named import ( - "context" - - "github.com/TBD54566975/ftl/go-runtime/ftl/reflection" + "context" + "github.com/TBD54566975/ftl/go-runtime/ftl/reflection" ) type PingInternalUserClient func(context.Context, InternalUser) error @@ -14,10 +13,10 @@ type PingUserClient func(context.Context, User) error func init() { reflection.Register( reflection.ProvideResourcesForVerb( - PingInternalUser, + PingInternalUser, ), reflection.ProvideResourcesForVerb( - PingUser, + PingUser, ), ) -} \ No newline at end of file +} diff --git a/go-runtime/schema/testdata/namedext/types.ftl.go b/go-runtime/schema/testdata/namedext/types.ftl.go index d08d78d1d..7c5d283d6 100644 --- a/go-runtime/schema/testdata/namedext/types.ftl.go +++ b/go-runtime/schema/testdata/namedext/types.ftl.go @@ -1,3 +1,2 @@ // Code generated by FTL. DO NOT EDIT. package namedext - diff --git a/go-runtime/schema/testdata/one/types.ftl.go b/go-runtime/schema/testdata/one/types.ftl.go index d9b4f89d8..981057bd2 100644 --- a/go-runtime/schema/testdata/one/types.ftl.go +++ b/go-runtime/schema/testdata/one/types.ftl.go @@ -2,13 +2,11 @@ package one import ( - "context" - stdtime "time" - - "github.com/TBD54566975/ftl/go-runtime/ftl" - "github.com/TBD54566975/ftl/go-runtime/ftl/reflection" - - ftlbuiltin "ftl/builtin" + "context" + ftlbuiltin "ftl/builtin" + "github.com/TBD54566975/ftl/go-runtime/ftl" + "github.com/TBD54566975/ftl/go-runtime/ftl/reflection" + stdtime "time" ) type BatchStringToTimeClient func(context.Context, []string) ([]stdtime.Time, error) @@ -43,25 +41,25 @@ func init() { *new(ValueEnum), ), reflection.ProvideResourcesForVerb( - BatchStringToTime, + BatchStringToTime, ), reflection.ProvideResourcesForVerb( - Http, + Http, ), reflection.ProvideResourcesForVerb( - Nothing, + Nothing, ), reflection.ProvideResourcesForVerb( - Sink, + Sink, ), reflection.ProvideResourcesForVerb( - Source, + Source, ), reflection.ProvideResourcesForVerb( - StringToTime, + StringToTime, ), reflection.ProvideResourcesForVerb( - Verb, + Verb, ), ) -} \ No newline at end of file +} diff --git a/go-runtime/schema/testdata/parent/types.ftl.go b/go-runtime/schema/testdata/parent/types.ftl.go index 3347538dd..a90c35639 100644 --- a/go-runtime/schema/testdata/parent/types.ftl.go +++ b/go-runtime/schema/testdata/parent/types.ftl.go @@ -2,11 +2,9 @@ package parent import ( - "context" - - "github.com/TBD54566975/ftl/go-runtime/ftl/reflection" - - ftlchild "ftl/parent/child" + "context" + ftlchild "ftl/parent/child" + "github.com/TBD54566975/ftl/go-runtime/ftl/reflection" ) type ChildVerbClient func(context.Context) (ftlchild.Resp, error) @@ -20,10 +18,10 @@ func init() { *new(ftlchild.Scalar), ), reflection.ProvideResourcesForVerb( - ftlchild.ChildVerb, + ftlchild.ChildVerb, ), reflection.ProvideResourcesForVerb( - Verb, + Verb, ), ) -} \ No newline at end of file +} diff --git a/go-runtime/schema/testdata/pubsub/types.ftl.go b/go-runtime/schema/testdata/pubsub/types.ftl.go index 70b21e348..44e0e3324 100644 --- a/go-runtime/schema/testdata/pubsub/types.ftl.go +++ b/go-runtime/schema/testdata/pubsub/types.ftl.go @@ -2,9 +2,8 @@ package pubsub import ( - "context" - - "github.com/TBD54566975/ftl/go-runtime/ftl/reflection" + "context" + "github.com/TBD54566975/ftl/go-runtime/ftl/reflection" ) type BroadcastClient func(context.Context) error @@ -18,16 +17,16 @@ type ProcessPayinClient func(context.Context, PayinEvent) error func init() { reflection.Register( reflection.ProvideResourcesForVerb( - Broadcast, + Broadcast, ), reflection.ProvideResourcesForVerb( - Payin, + Payin, ), reflection.ProvideResourcesForVerb( - ProcessBroadcast, + ProcessBroadcast, ), reflection.ProvideResourcesForVerb( - ProcessPayin, + ProcessPayin, ), ) -} \ No newline at end of file +} diff --git a/go-runtime/schema/testdata/subscriber/types.ftl.go b/go-runtime/schema/testdata/subscriber/types.ftl.go index d6d78540f..fb6353da9 100644 --- a/go-runtime/schema/testdata/subscriber/types.ftl.go +++ b/go-runtime/schema/testdata/subscriber/types.ftl.go @@ -2,11 +2,9 @@ package subscriber import ( - "context" - - "github.com/TBD54566975/ftl/go-runtime/ftl/reflection" - - ftlpubsub "ftl/pubsub" + "context" + ftlpubsub "ftl/pubsub" + "github.com/TBD54566975/ftl/go-runtime/ftl/reflection" ) type ConsumesSubscriptionFromExternalTopicClient func(context.Context, ftlpubsub.PayinEvent) error @@ -14,7 +12,7 @@ type ConsumesSubscriptionFromExternalTopicClient func(context.Context, ftlpubsub func init() { reflection.Register( reflection.ProvideResourcesForVerb( - ConsumesSubscriptionFromExternalTopic, + ConsumesSubscriptionFromExternalTopic, ), ) -} \ No newline at end of file +} diff --git a/go-runtime/schema/testdata/two/types.ftl.go b/go-runtime/schema/testdata/two/types.ftl.go index 46dd843f4..a946d8646 100644 --- a/go-runtime/schema/testdata/two/types.ftl.go +++ b/go-runtime/schema/testdata/two/types.ftl.go @@ -2,15 +2,13 @@ package two import ( - "context" - - "github.com/TBD54566975/ftl/go-runtime/ftl" - "github.com/TBD54566975/ftl/go-runtime/ftl/reflection" - "github.com/TBD54566975/ftl/go-runtime/server" - "github.com/jpillora/backoff" - lib "github.com/TBD54566975/ftl/go-runtime/schema/testdata" - - ftlbuiltin "ftl/builtin" + "context" + ftlbuiltin "ftl/builtin" + "github.com/TBD54566975/ftl/go-runtime/ftl" + "github.com/TBD54566975/ftl/go-runtime/ftl/reflection" + lib "github.com/TBD54566975/ftl/go-runtime/schema/testdata" + "github.com/TBD54566975/ftl/go-runtime/server" + "github.com/jpillora/backoff" ) type CallsTwoClient func(context.Context, Payload[string]) (Payload[string], error) @@ -36,25 +34,25 @@ func init() { reflection.ExternalType(*new(backoff.Backoff)), reflection.ExternalType(*new(lib.NonFTLType)), reflection.ProvideResourcesForVerb( - CallsTwo, - server.VerbClient[TwoClient, Payload[string], Payload[string]](), + CallsTwo, + server.VerbClient[TwoClient, Payload[string], Payload[string]](), ), reflection.ProvideResourcesForVerb( - Two, + Two, ), reflection.ProvideResourcesForVerb( - CallsTwoAndThree, - server.VerbClient[ThreeClient, Payload[string], Payload[string]](), - server.VerbClient[TwoClient, Payload[string], Payload[string]](), + CallsTwoAndThree, + server.VerbClient[TwoClient, Payload[string], Payload[string]](), + server.VerbClient[ThreeClient, Payload[string], Payload[string]](), ), reflection.ProvideResourcesForVerb( - Three, + Three, ), reflection.ProvideResourcesForVerb( - Ingress, + Ingress, ), reflection.ProvideResourcesForVerb( - ReturnsUser, + ReturnsUser, ), ) -} \ No newline at end of file +} diff --git a/go-runtime/schema/verb/analyzer.go b/go-runtime/schema/verb/analyzer.go index 62552469a..edca99a7c 100644 --- a/go-runtime/schema/verb/analyzer.go +++ b/go-runtime/schema/verb/analyzer.go @@ -3,7 +3,6 @@ package verb import ( "go/ast" "go/types" - "slices" "strings" "unicode" @@ -94,7 +93,7 @@ func Extract(pass *analysis.Pass, node *ast.FuncDecl, obj types.Object) optional } verb.Request = reqV verb.Response = resV - sortMetadata(verb) + return optional.Some(verb) } @@ -172,16 +171,3 @@ func getResourceRef(paramObj types.Object, pass *analysis.Pass, param *ast.Field } return dbRef } - -func sortMetadata(verb *schema.Verb) { - for _, md := range verb.Metadata { - if calls, ok := md.(*schema.MetadataCalls); ok { - slices.SortFunc(calls.Calls, func(i, j *schema.Ref) int { - if i.Module != j.Module { - return strings.Compare(i.Module, j.Module) - } - return strings.Compare(i.Name, j.Name) - }) - } - } -}