- 
                Notifications
    
You must be signed in to change notification settings  - Fork 13.9k
 
          Vec::push in consts MVP
          #147893
        
          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: master
Are you sure you want to change the base?
  
    Vec::push in consts MVP
  
  #147893
              
            Conversation
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
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.
We used to have the plan to have a dedicated compile-time allocator type... this is an interesting alternative. Given that it also involves the library surface, we should probably involve t-libs-api.
Why have you picked Vec as the first type for this? I think it'd make more sense for Box to go first since that is the most primitive type for heap allocations.
        
          
                library/alloc/src/alloc.rs
              
                Outdated
          
        
      | let mut offset = 0; | ||
| while offset < size { | ||
| offset += 1; | ||
| // SAFETY: the pointer returned by `const_allocate` is valid to write to. | ||
| ptr.add(offset).write(0) | ||
| } | 
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.
It would be much more efficient to use write_bytes here.
        
          
                library/alloc/src/vec/mod.rs
              
                Outdated
          
        
      | /// `Vec<T>` created during compile time. | ||
| #[unstable(feature = "const_heap", issue = "79597")] | ||
| #[rustc_const_unstable(feature = "const_heap", issue = "79597")] | ||
| pub const fn const_leak(mut self) -> &'static [T] { | 
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 conceptually quite different from leak which IMO should be reflected in the name, so I would indeed prefer const_make_global.
        
          
                library/alloc/src/vec/mod.rs
              
                Outdated
          
        
      | /// `Vec<T>` created during compile time. | ||
| #[unstable(feature = "const_heap", issue = "79597")] | ||
| #[rustc_const_unstable(feature = "const_heap", issue = "79597")] | ||
| pub const fn const_leak(mut self) -> &'static [T] { | 
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 needs a where T: Freeze for soundness.
        
          
                library/alloc/src/vec/mod.rs
              
                Outdated
          
        
      | } | ||
| 
               | 
          ||
| /// Leaks the `Vec<T>` to be interned statically. This mut be done for all | ||
| /// `Vec<T>` created during compile time. | 
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.
It doesn't need to be done for all Vec created during compile-time -- only for those that you want to carry over to runtime. You can use intermediate Vec as scratch space or so during compile time that you never call this method on.
          
 That will either require us doing a   | 
    
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
09046cc    to
    1c6257e      
    Compare
  
    
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
1c6257e    to
    aded02c      
    Compare
  
    | 
           @bors try @rust-timer queue  | 
    
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
`Vec::push` in consts MVP
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
| 
           Finished benchmarking commit (b3f7ade): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with  @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy. 
 Max RSS (memory usage)Results (primary 0.4%, secondary -0.3%)A less reliable metric. May be of interest, but not used to determine the overall result above. 
 CyclesResults (primary 3.3%)A less reliable metric. May be of interest, but not used to determine the overall result above. 
 Binary sizeResults (primary 0.3%, secondary 0.6%)A less reliable metric. May be of interest, but not used to determine the overall result above. 
 Bootstrap: 473.751s -> 473.82s (0.01%)  | 
    
| 
           Yeah, rustdoc output is non-ideal. It shows all the   | 
    
Example:
Oh this is fun...
Globalsuch that it callsintrinsics::const_allocateandintrinsics::const_deallocateduring compile time. This is achieved usingconst_eval_selectimpl const Allocator for GlobalVec::with_capacityandVec::push.Vec::const_leakto leak the final value viaintrinsics::const_make_global. If we see any pointer in the final value of aconstthat did not callconst_make_global, we error as implemented in addconst_make_global; err forconst_allocateptrs if didn't call #143595. (should we name theVecmethod const_make_global as well?)r? @rust-lang/wg-const-eval
To-do for me: