- Notifications
You must be signed in to change notification settings - Fork 13.9k
Document and improve MIR transform passes #148293
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
Open
DevaanshPathak wants to merge 1 commit into rust-lang:master Choose a base branch from DevaanshPathak:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Open
+271 −33
Conversation
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
This commit enhances documentation and fixes several issues in the MIR transform optimization passes (compiler/rustc_mir_transform). ## Documentation improvements ### ConstParamHasTy interaction (rust-lang#127030) - Extensively documented the drop shim builder param-env issue that affects types with const parameters - Added detailed explanation of root cause: `build_drop_shim` uses `drop_in_place` intrinsic's DefId instead of dropped type's DefId, causing param-env to lack `ConstArgHasType` predicates - Documented workaround in inline.rs (preventing drop glue inlining for types with const params until monomorphization) - Added corresponding documentation in shim.rs at the problematic typing_env construction site - Outlined three potential fix approaches with implementation details ### Destination propagation (dest_prop.rs) - Documented storage statement handling: clarified why storage statements are currently deleted and provided TODO with specific implementation steps for merging storage ranges instead - Enhanced subtyping check documentation: explained soundness requirements for exact type equality and referenced issue rust-lang#112651 ### Global Value Numbering (gvn.rs) - Dramatically improved pointer identity issue documentation (issue rust-lang#79738) at 4 locations, explaining: * CTFE address aliasing problems * Pointer provenance loss during const prop * Interior pointer identity issues * Safety net assertions - Enhanced codegen uniformity documentation: explained why only GlobalAlloc::Memory works in Indirect constants and provided 3-step improvement plan for future work ### Dataflow constant propagation (dataflow_const_prop.rs) - Clarified tail call termination behavior: documented that tail calls naturally terminate dataflow analysis, which is correct ### Inlining (inline.rs) - Documented tail call constraints in two locations: explained why tail calls aren't inlined (complex transformations required, may defeat performance purpose) - Added note explaining why single-caller detection isn't implemented (requires inter-procedural analysis not currently available) ## Code improvements ### GVN subtype handling fix - Fixed subtype checking to use `relate_types` with `Variance::Covariant` - Now correctly handles assignments with valid subtyping relationships, including Subtype casts inserted by add_subtyping_projections pass - Uses same logic as MIR validator for consistency ### Inline heuristics enhancement - Added 50% bonus threshold for single-block functions (likely trivial getters/setters) - Improves inlining decisions for very small, high-value functions ## New files ### compiler/rustc_mir_transform/README.md Created comprehensive developer guide covering: - Key optimization passes (dest_prop, GVN, dataflow const prop, inlining) - How to add new passes - Testing commands - Pass ordering considerations - Known limitations (ConstParamHasTy issue) - Common patterns and performance considerations All changes maintain backward compatibility and follow existing conventions. No functional changes to optimization behavior except for the GVN subtype fix, which enables optimizations that were previously incorrectly rejected.
| Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
|
| The job Click to see the possible cause of the failure (guessed by this bot) |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
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.
This commit enhances documentation and fixes several issues in the MIR transform optimization passes (compiler/rustc_mir_transform).
Documentation improvements
ConstParamHasTy interaction (#127030)
build_drop_shimusesdrop_in_placeintrinsic's DefId instead of dropped type's DefId, causing param-env to lackConstArgHasTypepredicatesDestination propagation (dest_prop.rs)
Global Value Numbering (gvn.rs)
Dataflow constant propagation (dataflow_const_prop.rs)
Inlining (inline.rs)
Code improvements
GVN subtype handling fix
relate_typeswithVariance::CovariantInline heuristics enhancement
New files
compiler/rustc_mir_transform/README.md
Created comprehensive developer guide covering:
All changes maintain backward compatibility and follow existing conventions. No functional changes to optimization behavior except for the GVN subtype fix, which enables optimizations that were previously incorrectly rejected.