Skip to content

Commit fcbc26b

Browse files
committed
reducing dependencies
1 parent 622deb9 commit fcbc26b

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

Cargo.toml

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ repository = "https://github.com/bytecodealliance/regalloc2"
1717
log = { version = "0.4.8", default-features = false }
1818
smallvec = { version = "1.6.1", features = ["union"] }
1919
rustc-hash = { version = "2.0.0", default-features = false }
20-
slice-group-by = { version = "0.3.0", default-features = false }
2120
hashbrown = { version = "0.14", default-features = false, features = [] }
2221

2322
# Optional serde support, enabled by feature below.
@@ -28,8 +27,8 @@ serde = { version = "1.0.136", features = [
2827

2928
# The below are only needed for fuzzing.
3029
libfuzzer-sys = { version = "0.4.2", optional = true }
31-
bumpalo = { version = "3.16.0", features = ["allocator-api2"] }
32-
allocator-api2 = { version = "0.2.18", default-features = false, features = ["alloc"] }
30+
bumpalo = { version = "3.16.0", features = [] }
31+
allocator-api2 = { version = "0.2.18", default-features = false, features = ["alloc"], optional = true }
3332

3433
# When testing regalloc2 by itself, enable debug assertions and overflow checks
3534
[profile.release]
@@ -38,7 +37,7 @@ debug-assertions = true
3837
overflow-checks = true
3938

4039
[features]
41-
default = ["std"]
40+
default = ["std", "allocator-api2"]
4241

4342
# Enables std-specific features such as the Error trait for RegAllocError.
4443
std = []
@@ -54,3 +53,6 @@ fuzzing = ["libfuzzer-sys", "checker", "trace-log"]
5453

5554
# Enables serde for exposed types.
5655
enable-serde = ["serde"]
56+
57+
allocator-api2 = ["dep:allocator-api2", "bumpalo/allocator-api2"]
58+
nightly = ["bumpalo/allocator_api"]

src/ion/data_structures.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,21 @@ use alloc::collections::VecDeque;
2626
use alloc::rc::Rc;
2727
use alloc::string::String;
2828
use alloc::vec::Vec;
29+
use allocator_api2::alloc::Allocator;
2930
use core::cmp::Ordering;
3031
use core::convert::identity;
3132
use core::fmt::Debug;
3233
use core::ops::{Deref, DerefMut};
3334
use smallvec::SmallVec;
3435

36+
#[cfg(not(feature = "allocator-api2"))]
37+
use core as allocator_api2;
38+
39+
#[cfg(not(feature = "allocator-api2"))]
40+
use alloc::vec as bump_vec;
41+
#[cfg(feature = "allocator-api2")]
42+
use allocator_api2::vec as bump_vec;
43+
3544
#[derive(Debug, Clone, Default)]
3645
pub struct Bump(Rc<bumpalo::Bump>);
3746

@@ -42,7 +51,7 @@ impl Bump {
4251
}
4352

4453
// simply delegating beause `Rc<bumpalo::Bump>` does not implement `Allocator`
45-
unsafe impl allocator_api2::alloc::Allocator for Bump {
54+
unsafe impl Allocator for Bump {
4655
fn allocate(
4756
&self,
4857
layout: core::alloc::Layout,
@@ -85,7 +94,8 @@ unsafe impl allocator_api2::alloc::Allocator for Bump {
8594
old_layout: core::alloc::Layout,
8695
new_layout: core::alloc::Layout,
8796
) -> Result<core::ptr::NonNull<[u8]>, allocator_api2::alloc::AllocError> {
88-
self.0.deref().shrink(ptr, old_layout, new_layout)
97+
let f = self.0.deref().shrink(ptr, old_layout, new_layout);
98+
f
8999
}
90100
}
91101

@@ -230,8 +240,8 @@ pub struct LiveRangeListEntry {
230240
pub index: LiveRangeIndex,
231241
}
232242

233-
pub type LiveRangeList = allocator_api2::vec::Vec<LiveRangeListEntry, Bump>;
234-
pub type UseList = allocator_api2::vec::Vec<Use, Bump>;
243+
pub type LiveRangeList = bump_vec::Vec<LiveRangeListEntry, Bump>;
244+
pub type UseList = bump_vec::Vec<Use, Bump>;
235245

236246
#[derive(Clone, Debug)]
237247
pub struct LiveRange {

src/ion/liveranges.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use crate::{
2424
Allocation, Block, Function, Inst, InstPosition, Operand, OperandConstraint, OperandKind,
2525
OperandPos, PReg, ProgPoint, RegAllocError, VReg, VecExt,
2626
};
27-
use slice_group_by::GroupByMut;
2827
use smallvec::{smallvec, SmallVec};
2928

3029
/// A spill weight computed for a certain Use.
@@ -781,7 +780,7 @@ impl<'a, F: Function> Env<'a, F> {
781780
// Find groups of uses that occur in at the same program point.
782781
for uses in self.ctx.ranges[range]
783782
.uses
784-
.linear_group_by_key_mut(|u| u.pos)
783+
.chunk_by_mut(|a, b| a.pos == b.pos)
785784
{
786785
if uses.len() < 2 {
787786
continue;

src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212

1313
#![allow(dead_code)]
1414
#![allow(clippy::all)]
15+
#![cfg_attr(not(feature = "allocator-api2"), feature(allocator_api))]
1516
#![no_std]
1617

18+
#[cfg(not(any(feature = "allocator-api2", feature = "nightly")))]
19+
compile_error!("feature `nightly` is required if `allocator-api2` is disabled");
20+
1721
#[cfg(feature = "std")]
1822
extern crate std;
1923

0 commit comments

Comments
 (0)