- 
                Notifications
    
You must be signed in to change notification settings  - Fork 13.9k
 
[WIP] mir-opt: promoting const read-only arrays #125916
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
Changes from all commits
80bcc74
              1c2d0f5
              c7ac773
              3facd92
              7a97b1c
              3e21e5f
              b6bf4e4
              6b6bc18
              19a01fd
              dfcae48
              e53c231
              d11c9e2
              1f40fa4
              7c4dcca
              ea443af
              514e4a9
              dca7207
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -91,6 +91,7 @@ mod normalize_array_len; | |
| mod nrvo; | ||
| mod prettify; | ||
| mod promote_consts; | ||
| mod promote_consts_local_arrays; | ||
| mod ref_prop; | ||
| mod remove_noop_landing_pads; | ||
| mod remove_storage_markers; | ||
| 
          
            
          
           | 
    @@ -342,14 +343,22 @@ fn mir_promoted( | |
| 
     | 
||
| // What we need to run borrowck etc. | ||
| let promote_pass = promote_consts::PromoteTemps::default(); | ||
| let promote_array = promote_consts_local_arrays::PromoteArraysOpt::default(); | ||
| pm::run_passes( | ||
| tcx, | ||
| &mut body, | ||
| &[&promote_pass, &simplify::SimplifyCfg::PromoteConsts, &coverage::InstrumentCoverage], | ||
| &[ | ||
| &promote_pass, | ||
| &promote_array, | ||
| &simplify::SimplifyCfg::PromoteConsts, | ||
| &coverage::InstrumentCoverage, | ||
| ], | ||
| Some(MirPhase::Analysis(AnalysisPhase::Initial)), | ||
| ); | ||
| 
     | 
||
| let promoted = promote_pass.promoted_fragments.into_inner(); | ||
| let mut promoted = promote_pass.promoted_fragments.into_inner(); | ||
| let array_promoted = promote_array.promoted_fragments.into_inner(); | ||
| promoted.extend(array_promoted); | ||
| 
         
      Comment on lines
    
      +360
     to 
      +361
    
   
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. which does mean you won't be able to use the existing promotion scheme, but would need to start looking into  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. then again, if all we're doing is creating non-generic static items, that already has precedent (we do that for nested statics), so likely you can do the same in an optimization. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Though in that case I would expect this to fall out of GVN or some similar optimization, not be its own separate path There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With GVN or similar you don't even need to create new constants and MIR bodies, you can just stick the fully evaluated constant into a MIR constant  | 
||
| (tcx.alloc_steal_mir(body), tcx.alloc_steal_promoted(promoted)) | ||
| } | ||
| 
     | 
||
| 
          
            
          
           | 
    ||
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.
since this is something that should not have user-visible effects (e.g. affecting dropck, const eval UB or borrowck), it should be run as part of the regular runtime optimization pipeline