BaldDemian opened a new pull request, #3744: URL: https://github.com/apache/fory/pull/3744
## Why? - Identifiers colliding with Rust keywords should be escaped. - After naming normalization, some identifiers may collide with each other. The Fory compiler should handle above edge-cases carefully by sanitizing the identifiers or throwing collision errors to the user, instead of generating Rust code that cannot be compiled by the Rust compiler. ## What does this PR do? ### Scope This PR handles Rust identifier escaping and name collisions in both normal `message` definition and gRPC service definition. **Note**: for now the handling logic for gRPC service definition is also defined in `compiler/fory_compiler/generators/rust.py`, I plan to move them into `compiler/fory_compiler/generators/services/rust.py` in the Rust gRPC code generation PR. ### Workflow The current implementation broadly follows the approach used by prost-build. It first normalizes identifiers from the IDL according to Rust naming conventions, e.g. converting struct names to UpperCamelCase and field names to snake_case. It then checks whether the normalized identifiers are Rust keywords and escapes them when necessary. Finally it checks the sanitized (i.e. normalized + escaped) identifier with already allocated identifiers in the same scope for any collision. The sanitized identifiers are cached to make sure the definition site and all use sites refer to the same name. ## Related issues Close https://github.com/apache/fory/issues/3544. ## 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: `yes` / `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? N/A. ## 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
