feat(compiler): reject non-thread-safe payload types in Rust compiler#3732
Open
BaldDemian wants to merge 1 commit into
Open
feat(compiler): reject non-thread-safe payload types in Rust compiler#3732BaldDemian wants to merge 1 commit into
BaldDemian wants to merge 1 commit into
Conversation
Contributor
Author
|
To address the Send and Sync issue, I have tried several other approaches. However, the current implementation appears to be the simplest one, although it may slightly affect the original design intent of |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why?
This is a prerequisite PR for Rust gRPC code generation.
In the Rust gRPC code generation requirement, we chose tonic as the network transport layer for gRPC, so the generated Rust code needs to be compatible with tonic.
In tonic, a gRPC payload (a request or a response) type must be both
SendandSync, e.g.https://docs.rs/tonic/latest/tonic/client/struct.Grpc.html#method.unary
However, in Fory, users can define the following types, which cause the generated Rust types to be neither
SendnorSync:anyIn addition, Fory currently generates an
UnknownCaseby default for a union type.fory/compiler/fory_compiler/generators/rust.py
Lines 379 to 380 in 33b0d6e
However, the type of its
valuefield isArc<dyn Any>, rather than something likeArc<dyn Any + Send + Sync>.fory/rust/fory-core/src/types/unknown_case.rs
Lines 24 to 32 in 33b0d6e
What does this PR do?
In this PR, I made the following changes:
any, an error will be raised directly with a corresponding diagnostic message for the user.UnknownCaseis not generated for unions used by gRPC payloads. Currently, I use a special macro attribute#[fory(no_unknown_case)]to make the derive macro logic handle this case specially, rather than directly panicking when encountering a union without anUnknownCase.It is worth noting that, for simplicity, if a gRPC payload type contains imported types, the current implementation will directly raise an error and exit.
Related issues
#3266
AI Contribution Checklist
noyes, I included a completed AI Contribution Checklist in this PR description and the requiredAI Usage Disclosure.yes, my PR description includes the requiredai_reviewsummary and screenshot evidence of the final clean AI review results from both fresh reviewers on the current PR diff or current HEAD after the latest code changes.Does this PR introduce any user-facing change?
All unions in gRPC payload types will not generate
UnknownCase.Benchmark
N/A.