Skip to content

Conversation

@glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented Mar 9, 2020

Motivation:

  • Generated services must also add conformance to the request/response
    types that they require
  • If different services rely on the same message type then this
    conformance is generated multiple times; leading to a build error

Modifications:

  • Pass the observed message types between each run of the generator

Result:

  • Code generated for services defined in different files with the same
    message types does not cause a build error

Motivation:

- Generated services must also add conformance to the request/response
  types that they require
- If different services rely on the same message type then this
  conformance is generated multiple times; leading to a build error

Modifications:

- Pass the observed message types between each run of the generator

Result:

- Code generated for services defined in different files with the same
  message types does not cause a build error
@glbrntt glbrntt added the nio label Mar 9, 2020
@glbrntt
Copy link
Collaborator Author

glbrntt commented Mar 9, 2020

cc @Davidde94

@glbrntt glbrntt added the 🔨 semver/patch No public API change. label Mar 9, 2020
@glbrntt
Copy link
Collaborator Author

glbrntt commented Mar 9, 2020

Fixes #738

Copy link
Collaborator

@MrMage MrMage left a comment

Choose a reason for hiding this comment

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

Is there a way we could test that no double conformance are generated?

var observedMessages = Set<String>()

// process each .proto file separately
for fileDescriptor in descriptorSet.files {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this ordering stable? Otherwise the location of the declaration might shift around.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good question; I honestly have no idea. It's certainly stable when the input is stable so I assume it depends on the order you pass them to protoc. Do you think it matters?

I'm not super happy with this approach but I'm not sure of a better one. The alternative I considered was generating the extensions based on the message descriptions (instead of the input/output for each RPC), that would make the location stable but it means you can generate conformance for messages which aren't used for RPCs. We'd also need to provide conformance for the "built in" messages (e.g. Any, Timestamp, etc) within GRPC so we'd be forced to update if SwiftProtobuf adds new messages.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The problem with an unstable ordering would be that every protoc run could create different files, resulting in a lot of churn. How about simply sorting the list ourselves in some stable fashion to be sure? Just an idea, though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorting by filename is straightforward to add, so might as well.

@glbrntt
Copy link
Collaborator Author

glbrntt commented Mar 10, 2020

Is there a way we could test that no double conformance are generated?

I ran this on a case I ran into the other day to double check.

I think we probably need some integration style tests to generate code and build it to validate but we need all the infrastructure first. I'll have a think about it because it would also be useful to have things like allocation counting and perf tests as part of CI.

@MrMage
Copy link
Collaborator

MrMage commented Mar 10, 2020

I ran this on a case I ran into the other day to double check.

I think we probably need some integration style tests to generate code and build it to validate but we need all the infrastructure first. I'll have a think about it because it would also be useful to have things like allocation counting and perf tests as part of CI.

SGTM; let's not worry about that in this PR.

@glbrntt glbrntt merged commit c4dc6a3 into grpc:nio Mar 10, 2020
@kmarcell
Copy link

Hi @glbrntt,

I updated to alpha-11 and still run into this issue in some cases where redundant GRPCProtobufPayload conformance was generated for structs.

Unfortunately I can't share the original proto files and the generated swift files, but pls let me know how I could help debug this issue.

@glbrntt glbrntt deleted the gb-protobuf-payload-generation branch April 30, 2020 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants