-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[move compiler] [CSE Step 1] add reaching-def analysis #18201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
ca16b0f to
6dd56f1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the final PR Bugbot will review for you during this billing cycle
Your free Bugbot reviews will reset on December 7
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
...d_party/move/move-compiler-v2/src/pipeline/reference_safety/reference_safety_processor_v3.rs
Show resolved
Hide resolved
6dd56f1 to
d9b6d27
Compare
third_party/move/move-compiler-v2/src/pipeline/reaching_def_analysis_processor.rs
Show resolved
Hide resolved
a6827da to
69c4e71
Compare
| pub mod reference_safety_processor_v3; | ||
|
|
||
| #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)] | ||
| pub enum Object { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object is a little general, maybe use a more specific name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Will update in the next PR.
69c4e71 to
54a1873
Compare
54a1873 to
cde52be
Compare
| | Operation::MoveFrom(mid, sid, _), | ||
| _, | ||
| _, | ||
| ) => Some(Object::Global(mid.qualified(sid))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: BorrowGlobal incorrectly treated as global resource definition
The collect_potential_global_access closure includes BorrowGlobal operations when collecting global resource definitions. However, BorrowGlobal only creates a reference to a global resource without modifying it, so it should not be treated as a definition. According to the documentation, only MoveFrom, MoveTo, and mutations via mutable references should be considered as definitions of global resources. Including BorrowGlobal causes the analysis to incorrectly mark global resources as redefined when they are merely borrowed.
cde52be to
88ac450
Compare
88ac450 to
2d543b1
Compare

Description
This PR adds reaching definition analysis for temporaries and global resources used in a function. It is the first PR on the stack to introduce Common Subexpression Elimination (CSE) for Move.
For each bytecode at
code_offset, the analysis provides a mapping from each local temporary or global resource to the set of code offsets where they may be defined that can reachcode_offset:ReachingDefState(code_offset) := Map<Object, Set<CodeOffset>>Object := Local(temp_index) | Global(struct_id)The analysis is over-approximation, producing may-definitions and may-reaches. A result
ReachingDefState(offset_1) := Map<obj1, Set<offset_2, offset_3>>means thatobj1is possibly defined atoffset_2andoffset_3and the definitions may reachoffset_1.================= for temporaries =================
Assign,Loadinstructions, andCallinstructions with destinations.WriteRef: all temporaries potentially pointed to by the reference are killed and re-definedmut_refpassed to callees: all temporaries potentially pointed to by the reference are killed and re-definedmut_refpassed to invoked closures: all temporaries potentially pointed to by the reference are killed and re-defined================ for global resources =================
Definitions of global resources are killed and re-defined at the following instructions:
MoveFromMoveTomut_ref, conservatively handled like temporariesCallees and invoked closures are handled conservatively:
Callto a child function, the child function and its transitively used functions are analyzed to collect the accessed resource structsInvokeof a closure, the functions used transitively by the current function are analyzed to collect the accessed resource structsImportant Note: The analysis only considers global resources that are declared in the same module of the target function
How Has This Been Tested?
Type of Change
Which Components or Systems Does This Change Impact?
Note
Introduces a reaching definitions analysis for locals and same-module global resources, and extends reference-safety to expose referenced objects used by the new pass.
pipeline/reaching_def_analysis_processor.rsimplementing forward may-reaching-defs forObject=Local|Globalwith per-instructionReachingDefAnnotationand formatter.Assign/Load/Calldest defs; kills on re-def, moves,Drop.WriteRef, passingmut_reftoFunction/Invoke.MoveFrom/MoveToand via transitive same-module accesses from callees/closures.reference_safety::Objectand addreferenced_objects_*helpers toLifetimeAnnotationandLifetimeInfotrait.referenced_objectsin bothreference_safety_processor_v2andv3(borrow-graph–based traversal), plus default no-op inNoLifetimeInfo.reaching_def_analysis_processormodule inpipeline/mod.rs.Written by Cursor Bugbot for commit 2d543b1. This will update automatically on new commits. Configure here.