You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fory.apache.org by "BaldDemian (via GitHub)" <gi...@apache.org> on 2026/06/02 12:32:45 UTC

[PR] feat(compiler): reject non-thread-safe payload types in Rust compiler [fory]

BaldDemian opened a new pull request, #3732:
URL: https://github.com/apache/fory/pull/3732

   ## 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 `Send` and `Sync`, 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 `Send` nor `Sync`:
   
   - Non-thread-safe refs
   - `any`
   
   In addition, Fory currently generates an `UnknownCase` by default for a union type.
   
   https://github.com/apache/fory/blob/33b0d6e8b73d1769d98824195b9155043266f3fe/compiler/fory_compiler/generators/rust.py#L379-L380
   
   However, the type of its `value` field is `Arc<dyn Any>`, rather than something like `Arc<dyn Any + Send + Sync>`.
   
   https://github.com/apache/fory/blob/33b0d6e8b73d1769d98824195b9155043266f3fe/rust/fory-core/src/types/unknown_case.rs#L24-L32
   
   ## What does this PR do?
   
   In this PR, I made the following changes:
   
   1. Before generating Rust gRPC stub code, all types used by gRPC payloads are checked via graph traversal. If their fields contain non-thread-safe refs or `any`, an error will be raised directly with a corresponding diagnostic message for the user.
   2. `UnknownCase` is 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 an `UnknownCase`.
   3. Add testcases accordingly.
   
   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
   
   https://github.com/apache/fory/issues/3266
   
   ## AI Contribution Checklist
   
   <!-- Full requirements and disclosure template:
   https://github.com/apache/fory/blob/main/AI_POLICY.md#9-contributor-checklist-for-ai-assisted-prs -->
   
   - [ ] Substantial AI assistance was used in this PR: `no`
   - [ ] If `yes`, I included a completed [AI Contribution Checklist](https://github.com/apache/fory/blob/main/AI_POLICY.md#9-contributor-checklist-for-ai-assisted-prs) in this PR description and the required `AI Usage Disclosure`.
   - [ ] If `yes`, my PR description includes the required `ai_review` summary 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.
   
   <!-- If substantial AI assistance = `yes`, paste the completed checklist and disclosure block here, including the final ai_review summary and screenshot evidence 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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(compiler): reject non-thread-safe payload types in Rust compiler [fory]

Posted by "BaldDemian (via GitHub)" <gi...@apache.org>.
BaldDemian commented on PR #3732:
URL: https://github.com/apache/fory/pull/3732#issuecomment-4602431190

   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 `UnknownCase`. Happy to hear your feedback or advice @chaokunyang 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(compiler): reject non-thread-safe payload types in Rust compiler [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang closed pull request #3732: feat(compiler): reject non-thread-safe payload types in Rust compiler
URL: https://github.com/apache/fory/pull/3732


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(compiler): reject non-thread-safe payload types in Rust compiler [fory]

Posted by "BaldDemian (via GitHub)" <gi...@apache.org>.
BaldDemian commented on PR #3732:
URL: https://github.com/apache/fory/pull/3732#issuecomment-4618577007

   @chaokunyang Thanks for addressing the issue, this really saved my day 🚀


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org