- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
          Make needs_drop less pessimistic on generators
          #70015
        
          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
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            3 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      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 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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -99,6 +99,23 @@ where | |
| } | ||
| } | ||
|  | ||
| ty::Generator(_, substs, _) => { | ||
| let substs = substs.as_generator(); | ||
| for upvar_ty in substs.upvar_tys() { | ||
| queue_type(self, upvar_ty); | ||
| } | ||
|  | ||
| let witness = substs.witness(); | ||
| let interior_tys = match &witness.kind { | ||
| ty::GeneratorWitness(tys) => tcx.erase_late_bound_regions(tys), | ||
|          | ||
| _ => bug!(), | ||
| }; | ||
|  | ||
| for interior_ty in interior_tys { | ||
| queue_type(self, interior_ty); | ||
| } | ||
| } | ||
|  | ||
| // Check for a `Drop` impl and whether this is a union or | ||
| // `ManuallyDrop`. If it's a struct or enum without a `Drop` | ||
| // impl then check whether the field types need `Drop`. | ||
|  | ||
  
    
      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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,11 +1,14 @@ | ||
| #![feature(generators, generator_trait)] | ||
|  | ||
| // ignore-wasm32-bare compiled with panic=abort by default | ||
|  | ||
| // Regression test for #58892, generator drop shims should not have blocks | ||
| // spuriously marked as cleanup | ||
|  | ||
| // EMIT_MIR rustc.main-{{closure}}.generator_drop.0.mir | ||
| fn main() { | ||
| let gen = || { | ||
| let _s = String::new(); | ||
| yield; | ||
| }; | ||
| } | 
        
          
          
            79 changes: 53 additions & 26 deletions
          
          79 
        
  src/test/mir-opt/generator-drop-cleanup/rustc.main-{{closure}}.generator_drop.0.mir
  
  
      
      
   
        
      
      
    
  
    
      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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,53 +1,80 @@ | ||
| // MIR for `main::{{closure}}#0` 0 generator_drop | ||
| // generator_layout = GeneratorLayout { field_tys: [], variant_fields: [[], [], [], []], storage_conflicts: BitMatrix { num_rows: 0, num_columns: 0, words: [], marker: PhantomData } } | ||
| // generator_layout = GeneratorLayout { field_tys: [std::string::String], variant_fields: [[], [], [], [_0]], storage_conflicts: BitMatrix { num_rows: 1, num_columns: 1, words: [1], marker: PhantomData } } | ||
|  | ||
| fn main::{{closure}}#0(_1: *mut [generator@$DIR/generator-drop-cleanup.rs:8:15: 10:6 {()}]) -> () { | ||
| let mut _0: (); // return place in scope 0 at $DIR/generator-drop-cleanup.rs:8:15: 10:6 | ||
| let mut _2: (); // in scope 0 at $DIR/generator-drop-cleanup.rs:8:15: 10:6 | ||
| let _3: (); // in scope 0 at $DIR/generator-drop-cleanup.rs:9:9: 9:14 | ||
| let mut _4: (); // in scope 0 at $DIR/generator-drop-cleanup.rs:9:9: 9:14 | ||
| let mut _5: (); // in scope 0 at $DIR/generator-drop-cleanup.rs:8:18: 8:18 | ||
| let mut _6: (); // in scope 0 at $DIR/generator-drop-cleanup.rs:8:15: 10:6 | ||
| let mut _7: isize; // in scope 0 at $DIR/generator-drop-cleanup.rs:8:15: 10:6 | ||
| fn main::{{closure}}#0(_1: *mut [generator@$DIR/generator-drop-cleanup.rs:10:15: 13:6 {std::string::String, ()}]) -> () { | ||
| let mut _0: (); // return place in scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6 | ||
| let mut _2: (); // in scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6 | ||
| let _3: std::string::String; // in scope 0 at $DIR/generator-drop-cleanup.rs:11:13: 11:15 | ||
| let _4: (); // in scope 0 at $DIR/generator-drop-cleanup.rs:12:9: 12:14 | ||
| let mut _5: (); // in scope 0 at $DIR/generator-drop-cleanup.rs:12:9: 12:14 | ||
| let mut _7: (); // in scope 0 at $DIR/generator-drop-cleanup.rs:10:18: 10:18 | ||
| let mut _8: (); // in scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6 | ||
| let mut _9: isize; // in scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6 | ||
| scope 1 { | ||
| debug _s => (((*_1) as variant#3).0: std::string::String); // in scope 1 at $DIR/generator-drop-cleanup.rs:11:13: 11:15 | ||
| } | ||
| scope 2 { | ||
| let mut _6: std::vec::Vec<u8>; // in scope 2 at $DIR/generator-drop-cleanup.rs:11:18: 11:31 | ||
| scope 3 { | ||
| } | ||
| } | ||
|  | ||
| bb0: { | ||
| _7 = discriminant((*_1)); // bb0[0]: scope 0 at $DIR/generator-drop-cleanup.rs:8:15: 10:6 | ||
| switchInt(move _7) -> [0u32: bb4, 3u32: bb7, otherwise: bb8]; // bb0[1]: scope 0 at $DIR/generator-drop-cleanup.rs:8:15: 10:6 | ||
| _9 = discriminant((*_1)); // bb0[0]: scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6 | ||
| switchInt(move _9) -> [0u32: bb7, 3u32: bb11, otherwise: bb12]; // bb0[1]: scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6 | ||
| } | ||
|  | ||
| bb1: { | ||
| StorageDead(_4); // bb1[0]: scope 0 at $DIR/generator-drop-cleanup.rs:9:13: 9:14 | ||
| StorageDead(_3); // bb1[1]: scope 0 at $DIR/generator-drop-cleanup.rs:9:14: 9:15 | ||
| goto -> bb5; // bb1[2]: scope 0 at $DIR/generator-drop-cleanup.rs:10:5: 10:6 | ||
| bb1 (cleanup): { | ||
| resume; // bb1[0]: scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6 | ||
| } | ||
|  | ||
| bb2: { | ||
| return; // bb2[0]: scope 0 at $DIR/generator-drop-cleanup.rs:8:15: 10:6 | ||
| bb2 (cleanup): { | ||
| nop; // bb2[0]: scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6 | ||
| goto -> bb8; // bb2[1]: scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6 | ||
| } | ||
|  | ||
| bb3: { | ||
| return; // bb3[0]: scope 0 at $DIR/generator-drop-cleanup.rs:8:15: 10:6 | ||
| StorageDead(_5); // bb3[0]: scope 1 at $DIR/generator-drop-cleanup.rs:12:13: 12:14 | ||
| StorageDead(_4); // bb3[1]: scope 1 at $DIR/generator-drop-cleanup.rs:12:14: 12:15 | ||
| drop((((*_1) as variant#3).0: std::string::String)) -> [return: bb4, unwind: bb2]; // bb3[2]: scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6 | ||
| } | ||
|  | ||
| bb4: { | ||
| goto -> bb6; // bb4[0]: scope 0 at $DIR/generator-drop-cleanup.rs:8:15: 10:6 | ||
| nop; // bb4[0]: scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6 | ||
| goto -> bb9; // bb4[1]: scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6 | ||
| } | ||
|  | ||
| bb5: { | ||
| goto -> bb2; // bb5[0]: scope 0 at $DIR/generator-drop-cleanup.rs:10:5: 10:6 | ||
| return; // bb5[0]: scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6 | ||
| } | ||
|  | ||
| bb6: { | ||
| goto -> bb3; // bb6[0]: scope 0 at $DIR/generator-drop-cleanup.rs:8:15: 10:6 | ||
| return; // bb6[0]: scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6 | ||
| } | ||
|  | ||
| bb7: { | ||
| StorageLive(_3); // bb7[0]: scope 0 at $DIR/generator-drop-cleanup.rs:8:15: 10:6 | ||
| StorageLive(_4); // bb7[1]: scope 0 at $DIR/generator-drop-cleanup.rs:8:15: 10:6 | ||
| goto -> bb1; // bb7[2]: scope 0 at $DIR/generator-drop-cleanup.rs:8:15: 10:6 | ||
| goto -> bb10; // bb7[0]: scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6 | ||
| } | ||
|  | ||
| bb8 (cleanup): { | ||
| goto -> bb1; // bb8[0]: scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6 | ||
| } | ||
|  | ||
| bb9: { | ||
| goto -> bb5; // bb9[0]: scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6 | ||
| } | ||
|  | ||
| bb10: { | ||
| goto -> bb6; // bb10[0]: scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6 | ||
| } | ||
|  | ||
| bb11: { | ||
| StorageLive(_4); // bb11[0]: scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6 | ||
| StorageLive(_5); // bb11[1]: scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6 | ||
| goto -> bb3; // bb11[2]: scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6 | ||
| } | ||
|  | ||
| bb8: { | ||
| return; // bb8[0]: scope 0 at $DIR/generator-drop-cleanup.rs:8:15: 10:6 | ||
| bb12: { | ||
| return; // bb12[0]: scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6 | ||
| } | ||
| } | 
  
    
      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 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
    
  
  
    
              
  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.
  
    
  
    
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.
Do we have assertions somewhere that could catch bugs in
needs_drop(i.e., catch cases where a type has drop glue butneeds_dropsays no)?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.
Not that I know of, but we have several mir-opt tests for generators, as well as diagnostics tests, which were (correctly) affected by this change.