Skip to content

What about: custom allocators #442

Open
@RalfJung

Description

@RalfJung

Custom allocators (#[global_alloc]) come with all sorts of exciting interactions with the operational semantics:

  • The compiler is allowed to optimize away calls to them even if these calls have side-effects. Is there some operational way to rationalize this?
  • Something exciting happens with provenance of pointers that move in and out of the allocator. But what? See for example this. LLVM has return-position noalias to reflect this magic. That attribute is super strong though.
  • Also, which allocators are even affected by this? Right now, we tell LLVM that the registered global_allocator is magic, but direct calls to an allocator (whether it uses the GlobalAlloc trait or the Allocator trait) are just regular function calls. But maybe we want those to be magic as well for more optimizations? Or maybe we at least want a way for an allocator to opt-in to such magic? An Allocator that returns memory from some previously-allocated buffer certainly violates LLVM return-position noalias so we can't give them the full treatment (at least not without first working with LLVM to improve their semantics -- maybe the scope of the return-position noalias only lasts until free is called, not until the end of the program).
  • Also, the first point from this issue shows that dealloc resets memory to "uninit" before the custom allocator function runs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions