feat(rust): implement fine-grained ref tracking for rust #3101
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?
Currently Rust uses a boolean
write_ref_info/read_ref_infoparameter which only distinguishes between "write ref flag" vs "don't write ref flag". This doesn't support:Option<T>where T is not a shared ref)#[fory(ref=false)]attributeRefModedesign which has three modes:None,NullOnly,TrackingWhat does this PR do?
1. Add
RefModeenum to replace booleanwrite_ref_info/read_ref_info2. Update Serializer trait signature
3. Per-field RefMode determination in derive macro
None, Option →NullOnly, Rc/Arc/Weak →Tracking#[fory(ref=false)]to disable tracking,#[fory(nullable)]for null supportBox<dyn Any>,Rc<dyn Trait>, etc.) now respect field attributes4. Add
FieldRefModeenum withToTokensimpl for cleaner macro code generation5. Add
determine_field_ref_mode(field)helperCombines type classification with field meta attributes to determine the correct RefMode for each field, respecting
#[fory(ref=false)]and#[fory(nullable)]annotations.Related issues
Closes #3097
Does this PR introduce any user-facing change?
Serializer::fory_writeandSerializer::fory_readnow takeRefModeinstead ofboolRefModeenum exported fromfory_coreBenchmark
No performance regression expected - the
RefModeenum comparison (ref_mode != RefMode::None) compiles to the same machine code as the previous boolean comparison.