Hasty Briefsbeta

Bilingual

Placing Functions

9 months ago
  • #rust
  • #compiler-optimization
  • #memory-management
  • Placing functions allow return types to be constructed in the caller's stack frame, ensuring stable memory addresses.
  • The placing crate is a proc-macro-based prototype demonstrating how placing functions can be implemented in Rust.
  • Placing functions separate memory location creation from value initialization, improving performance and enabling features like dyn AFITs.
  • Desugaring involves rewriting functions to handle MaybeUninit and ensuring proper Drop implementations.
  • Placing functions draw inspiration from Rust's super let and C++'s guaranteed copy elision.
  • The design balances control, integration, and compatibility, treating emplacement as an effect similar to const or async functions.
  • Rust already guarantees emplacement in some cases, as seen in the SYSV ABI for x86.
  • Future extensions could include placing arguments and lifetime extensions for more comprehensive emplacement support.
  • Annotations are necessary for incremental adoption, allowing Rust to start small and expand emplacement features over time.
  • Placing functions are a step towards self-referential types, combining with self-lifetimes and partial constructors for advanced use cases.