oxc/crates/oxc_codegen/src
branchseer f159f60084
Make ast types covariant over the allocator lifetime. (#2943)
## Why

Due to the usage of `&'alloc mut T` in `oxc_allocator::Box`, and
`bumpalo::collections::Vec` in `oxc_allocator::Vec`, ast types are
currently invariant over their allocator lifetime `'a`. This prevents
`ouroboros` from generating `borrow_*` on ast type fields, leading to
the unfriendly `with_*` api:
c250b288ef/crates/oxc_parser/examples/multi-thread.rs (L82-L84)

## How

- For `oxc_allocator::Vec`, switch to `allocator_api2::vec::Vec`, which
has a covariant relationship with the allocator lifetime.
- For `oxc_allocator::Box`, use `std::ptr::NonNull` which is
specifically designed to be covariant. I don't use
`allocator_api2::boxed::Box` because it holds the allocator for
dropping, so the size is bigger.

## Downside

Now that `oxc_allocator::Box` uses the unsafe `NonNull`. It has to be a
private field to be safe. This make it impossible to do `Box(....)`
pattern matching.
2024-04-12 18:12:18 +08:00
..
context.rs fix(codegen): format new expression + call expression with the correct parentheses (#2330) 2024-02-06 22:06:12 +08:00
gen.rs Make ast types covariant over the allocator lifetime. (#2943) 2024-04-12 18:12:18 +08:00
gen_ts.rs fix(parser): add support for empty module declaration (#2834) 2024-03-27 13:48:03 +08:00
lib.rs chore: fix clippy on unsafe comment 2024-04-03 19:57:21 +08:00
operator.rs feat(codegen): move minifying printer to codegen crate (#985) 2023-10-12 14:56:30 +08:00
sourcemap_builder.rs chore: avoid unsafe code search original name (#2895) 2024-04-03 11:34:21 +00:00