Skip to content

Commit

Permalink
reducing dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubDoka committed Sep 24, 2024
1 parent 622deb9 commit fcbc26b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ repository = "https://github.com/bytecodealliance/regalloc2"
log = { version = "0.4.8", default-features = false }
smallvec = { version = "1.6.1", features = ["union"] }
rustc-hash = { version = "2.0.0", default-features = false }
slice-group-by = { version = "0.3.0", default-features = false }
hashbrown = { version = "0.14", default-features = false, features = [] }

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

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

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

[features]
default = ["std"]
default = ["std", "allocator-api2"]

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

# Enables serde for exposed types.
enable-serde = ["serde"]

allocator-api2 = ["dep:allocator-api2", "bumpalo/allocator-api2"]
nightly = ["bumpalo/allocator_api"]
18 changes: 14 additions & 4 deletions src/ion/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,21 @@ use alloc::collections::VecDeque;
use alloc::rc::Rc;
use alloc::string::String;
use alloc::vec::Vec;
use allocator_api2::alloc::Allocator;
use core::cmp::Ordering;
use core::convert::identity;
use core::fmt::Debug;
use core::ops::{Deref, DerefMut};
use smallvec::SmallVec;

#[cfg(not(feature = "allocator-api2"))]
use core as allocator_api2;

#[cfg(not(feature = "allocator-api2"))]
use alloc::vec as bump_vec;
#[cfg(feature = "allocator-api2")]
use allocator_api2::vec as bump_vec;

#[derive(Debug, Clone, Default)]
pub struct Bump(Rc<bumpalo::Bump>);

Expand All @@ -42,7 +51,7 @@ impl Bump {
}

// simply delegating beause `Rc<bumpalo::Bump>` does not implement `Allocator`
unsafe impl allocator_api2::alloc::Allocator for Bump {
unsafe impl Allocator for Bump {
fn allocate(
&self,
layout: core::alloc::Layout,
Expand Down Expand Up @@ -85,7 +94,8 @@ unsafe impl allocator_api2::alloc::Allocator for Bump {
old_layout: core::alloc::Layout,
new_layout: core::alloc::Layout,
) -> Result<core::ptr::NonNull<[u8]>, allocator_api2::alloc::AllocError> {
self.0.deref().shrink(ptr, old_layout, new_layout)
let f = self.0.deref().shrink(ptr, old_layout, new_layout);
f
}
}

Expand Down Expand Up @@ -230,8 +240,8 @@ pub struct LiveRangeListEntry {
pub index: LiveRangeIndex,
}

pub type LiveRangeList = allocator_api2::vec::Vec<LiveRangeListEntry, Bump>;
pub type UseList = allocator_api2::vec::Vec<Use, Bump>;
pub type LiveRangeList = bump_vec::Vec<LiveRangeListEntry, Bump>;
pub type UseList = bump_vec::Vec<Use, Bump>;

#[derive(Clone, Debug)]
pub struct LiveRange {
Expand Down
3 changes: 1 addition & 2 deletions src/ion/liveranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use crate::{
Allocation, Block, Function, Inst, InstPosition, Operand, OperandConstraint, OperandKind,
OperandPos, PReg, ProgPoint, RegAllocError, VReg, VecExt,
};
use slice_group_by::GroupByMut;
use smallvec::{smallvec, SmallVec};

/// A spill weight computed for a certain Use.
Expand Down Expand Up @@ -781,7 +780,7 @@ impl<'a, F: Function> Env<'a, F> {
// Find groups of uses that occur in at the same program point.
for uses in self.ctx.ranges[range]
.uses
.linear_group_by_key_mut(|u| u.pos)
.chunk_by_mut(|a, b| a.pos == b.pos)
{
if uses.len() < 2 {
continue;
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@

#![allow(dead_code)]
#![allow(clippy::all)]
#![cfg_attr(not(feature = "allocator-api2"), feature(allocator_api))]
#![no_std]

#[cfg(not(any(feature = "allocator-api2", feature = "nightly")))]
compile_error!("feature `nightly` is required if `allocator-api2` is disabled");

#[cfg(feature = "std")]
extern crate std;

Expand Down

0 comments on commit fcbc26b

Please sign in to comment.