Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Drop verb client interfaces #3110

Merged
merged 5 commits into from
Oct 16, 2024
Merged

fix: Drop verb client interfaces #3110

merged 5 commits into from
Oct 16, 2024

Conversation

tomdaffurn
Copy link
Contributor

@tomdaffurn tomdaffurn commented Oct 14, 2024

Drop the VerbClient, VerbClientSink, VerbClientSource, VerbClientEmpty interfaces. They conflict with verbs that use primitive params and responses.

Fixes #2757

@tomdaffurn tomdaffurn requested review from a team as code owners October 14, 2024 06:38
@tomdaffurn tomdaffurn requested review from stuartwdouglas and removed request for a team October 14, 2024 06:38
@github-actions github-actions bot changed the title Box Java verb param and response types feat: Box Java verb param and response types Oct 14, 2024
@tomdaffurn tomdaffurn changed the title feat: Box Java verb param and response types fix: Box Java verb param and response types Oct 14, 2024
@ftl-robot ftl-robot mentioned this pull request Oct 14, 2024
@@ -280,3 +280,13 @@ func TypeEnumVerb(ctx context.Context, val AnimalWrapper) (AnimalWrapper, error)
//func MixedEnumVerb(ctx context.Context, val Mixed) (Mixed, error) {
// return val, nil
//}

//ftl:verb export
func PrimitiveResponseVerb(ctx context.Context, val string) (int, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is already IntVerb above that has an int response type.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So looking into this I don't know if we need this change:

Currently we generate:

@VerbClientDefinition(
    name = "intVerb",
    module = "gomodule"
)
public interface IntVerbClient extends VerbClient<Long, Long> {
  long call(long value);
}

Which is valid, even though the primitive method does not override the interface type, because we actually generate both methods:

https://github.com/TBD54566975/ftl/blob/b0465e3c2d14cb72400b8724058db1445c663619/jvm-runtime/ftl-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/VerbProcessor.java#L93

Basically in the int -> int case we generate three different methods:

Object -> Object
Long -> Long
long -> long

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The compile error doesn't show up for IntVerb because the generated signature of call(long) is different to call(Long) in VerbClient. Need to have an Object param with primitive response value to make the signature the same but different response type.

I guess we can restrict boxing to cases where the param is an Object and the response isn't.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, I see what you mean.

I wonder how much implementing VerbClient actually matters. For the generated classes I don't think it actually adds anything, and not being able to use primitives is just kinda annoying. I am not 100% happy with the way verb clients currently work anyway, as invocation within the same module is clunky. Let me think about this a bit.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@tomdaffurn tomdaffurn changed the title fix: Box Java verb param and response types fix: Drop verb client interfaces Oct 16, 2024
Copy link
Collaborator

@stuartwdouglas stuartwdouglas left a comment

Choose a reason for hiding this comment

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

LGTM, although I think we might want to move to method annotations at some point.

}
}
return new VerbClientBuildItem(clients);
}

private MethodInfo getCallMethod(ClassInfo verbClient) {
for (var call : verbClient.methods()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need to throw an exception if the interface has additional non-static non-default methods, as they won't be implemented by the generated client.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would only happen if the user has mistakenly created their own @VerbClient interface right?

@tomdaffurn tomdaffurn merged commit 0a53566 into main Oct 16, 2024
96 checks passed
@tomdaffurn tomdaffurn deleted the tom/primitive-type-bug branch October 16, 2024 04:58
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.

Incorrect Java code generated for verbs with primitive response type
2 participants