Addresses deprecations reported by the latest Rust nightly while preserving Rust 1.98 compatibility.
- Rename `unit-bindings` to `unit_bindings`: hyphenated lint names are deprecated in favor of their canonical underscore spelling.
- Replace `isize::max_value()` and `usize::max_value()` with `isize::MAX` and `usize::MAX`: the legacy numeric methods are deprecated in favor of associated constants.
- Set explicit `MAX_INDEX` values on `define_index_type!`: `oxc_index` otherwise generates `<raw>::max_value() as usize`; the explicit modern constants avoid that deprecated expansion without changing the index limits.
- Remove obsolete `clippy::legacy_numeric_constants` expectations: the corrected code no longer triggers that lint, so the expectations would be unfulfilled.
- Allow the AST scanner to consume optional `define_index_type!` configuration: it previously parsed only the struct declaration and rejected the added `MAX_INDEX` option.
AI-assisted.
Use `implements!` macro (introduced in #24721) in various tests, including adding some new ones.
The most valuable change is replacing a `compile_fail` doctest which checks that `Arena` is not `Sync`. Using `assert!(implements!(Arena: !Sync));` is more robust.
Small refactor to `Arena`. Use `cmp::max(a, b)` instead of the chained version `a.max(b)`. I find the former clearer.
Also simplify one `max` operation (see comment in code).
Add a method `Arena::used_bytes` which `Allocator::used_bytes` utilizes. Re-implement it to avoid using `ChunkRawIter` iterator, which is slightly more performant.
`ChunkRawIter` is an iterator over pointer & length pairs for an `Arena`'s chunks. Alter it to return `NonNull<u8>` pointers instead of `*mut u8` pointers.
This is not a breaking change, as we do not expose the `Arena` type externally.
Refactor `Arena` creation methods to simplify and clarify them:
- All `Arena<1>` methods delegate directly to the corresponding generic `Arena<MIN_ALIGN>` methods.
- Remove `Arena::try_new`. It's pointless as it always returns `Ok`, so is equivalent to `Arena::new`.
- Add `#[inline]` to small methods, and ones which purely delegate to another method.
Fix a test for `Bump` which was failing on 32-bit in CI.
#21291 temporarily disabled the test. Turn out, there's no easy way to make this test work on 32-bit platforms, and #21510 added ample unit tests which effectively test the same thing.
So keep it disabled on 32-bit, but fix the test to make it work properly on 64-bit.
Rationale for the fix is explained in https://github.com/fitzgen/bumpalo/pull/320.
`Arena` had a feature which allowed setting an upper bound on the size of an allocator. This complicates the implementation and is not useful for our purposes (how would we gracefully handle running out of memory during parsing anyway?). So remove it.
`Arena::from_raw_parts` (used by raw transfer) does need a way to prevent an allocator growing beyond it's initial size (2 GiB), but we can provide that with a simpler method - just a `bool` which indicates if the arena can create new chunks or not.
Pure refactor. Rename `bump.rs` to `arena.rs`, and rename `bump` tests directory to `arena` - in line with renaming `Bump` to `Arena` (#21394).
No substantive changes, only renaming.
Pure refactor. Rename `Bump` to `Arena`. The name "Bump" was a legacy from `bumpalo`, `Arena` is a more appropriate name.
No substantive changes, only renaming.
This test is consistently failing on 32-bit CI.
e.g. https://github.com/oxc-project/oxc/actions/runs/24210394836/job/70677275438
I don't understand the logic of this test. At first glance it looks like the test is flawed, and it's only passing on 64-bit for incidental reasons - due to the memory regions that allocators tend to use.
I'll investigate further, but in meantime just skip the test on 32-bit to make CI green again.
#20963 copied `bumpalo`'s code into `oxc_allocator` crate, but I
neglected to copy across the tests.
This PR copies all `bumpalo`'s test files that relate to `Bump`, and
makes only in the minimum required changes to make them compile and the
tests pass.
2 tests required modification to pass:
1. `change_allocation_limit_with_live_allocations`
2. `reset_updates_allocated_bytes`
Both failed because oxc's `Bump` uses a 16 KiB default chunk size (vs
`bumpalo`'s 512 bytes). The fix is to create the `Bump` with
`with_capacity(448)` / `with_capacity(512)` respectively, so the initial
chunk is small enough for the test logic to work as intended (limit not
already exceeded, and two allocations spanning multiple chunks).
That apart, the tests are unaltered except for import paths and other
cosmetic changes, the changes that are made are split into multiple
small commits for ease of review. I'm going to manually merge this PR,
so that we have a "paper trail" of what changes were made to the tests
in GitHub (not merging with Graphite which would squash all the
commits).