Skip to content

Prevent future memory leaks #2640

@overlookmotel

Description

@overlookmotel

We could prevent the possibility of any future memory leaks by:

  • Introduce a trait Arena.
  • Implement it for:
    • all primitive types which do not own external allocations - u32, &str etc.
    • oxc_allocator's Box, Vec and String.
  • Create a derive macro for the trait which requires all struct fields / enum variants to also be Arena (same as a type can only be Clone if all its constituent parts are also Clone).
  • #[derive(Arena)] on all AST types.
  • Add a bound to Allocator::alloc<T: Arena>.

The compiler will then make it impossible to add any type which owns data external to the arena to the AST, or allocate one in the arena.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions