Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove dependency on generational-arena #4207

Merged
merged 29 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f27b439
wip: remove dependency on generational-arena, add minimal vec-based a…
michaeljklein Jan 30, 2024
7f95c26
cargo fmt
michaeljklein Jan 30, 2024
648c00c
Merge branch 'master' into michaeljklein/vec-arena
michaeljklein Jan 30, 2024
f761a97
Merge branch 'master' into michaeljklein/vec-arena
michaeljklein Jan 30, 2024
da7e219
cargo clippy
michaeljklein Jan 30, 2024
f836981
revert warnings for unused crates
michaeljklein Jan 30, 2024
257ca9d
Merge branch 'master' into michaeljklein/vec-arena
michaeljklein Jan 30, 2024
10f161a
Merge branch 'master' into michaeljklein/vec-arena
michaeljklein Jan 30, 2024
9203fe5
rename ix -> index
michaeljklein Jan 30, 2024
ad7958e
Merge branch 'master' into michaeljklein/vec-arena
michaeljklein Jan 31, 2024
00531d2
make Index a tuple struct
michaeljklein Jan 31, 2024
b8098c8
Update compiler/noirc_frontend/src/hir/type_check/mod.rs
kevaundray Feb 1, 2024
d8581f4
Merge branch 'master' into michaeljklein/vec-arena
michaeljklein Feb 5, 2024
151a23c
added back generational_arena, added copy of generational_arena::{Are…
michaeljklein Feb 5, 2024
86d120e
wip debugging failing test
michaeljklein Feb 6, 2024
5d0a77b
Merge remote-tracking branch 'origin/master' into michaeljklein/vec-a…
kevaundray Feb 12, 2024
cd279cd
Fix compile errors from aztec_macros
jfecher Feb 12, 2024
ed62fd7
Fmt
jfecher Feb 12, 2024
e1aa513
Merge branch 'master' into michaeljklein/vec-arena
jfecher Feb 12, 2024
0f4f32d
Fix frontend test
jfecher Feb 12, 2024
ec1c5c4
Merge branch 'master' into michaeljklein/vec-arena
kevaundray Feb 13, 2024
948447c
Merge branch 'master' into michaeljklein/vec-arena
michaeljklein Feb 13, 2024
aa35b34
remove generational arena test stubs, indices, etc
michaeljklein Feb 13, 2024
9dbb84c
Merge branch 'master' into michaeljklein/vec-arena
michaeljklein Feb 13, 2024
68d7cb6
cargo fmt
michaeljklein Feb 13, 2024
b8d5b2e
Merge branch 'master' into michaeljklein/vec-arena
kevaundray Feb 15, 2024
e49fde4
fix: DefinitionIds should not be stored in id_to_type (#4397)
jfecher Feb 16, 2024
7885574
cleanup debugging, remove generational arena note from deny.toml
michaeljklein Feb 16, 2024
881373d
Merge branch 'master' into michaeljklein/vec-arena
michaeljklein Feb 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/hir/def_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct LocalModuleId(pub Index);

impl LocalModuleId {
pub fn dummy_id() -> LocalModuleId {
LocalModuleId(Index::from_raw_parts(std::usize::MAX, std::u64::MAX))
LocalModuleId(Index { ix: std::usize::MAX })
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_frontend/src/hir/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ mod test {
}

fn local_module_id(&self) -> LocalModuleId {
LocalModuleId(arena::Index::from_raw_parts(0, 0))
LocalModuleId(arena::Index { ix: 0 })
kevaundray marked this conversation as resolved.
Show resolved Hide resolved
}

fn module_id(&self) -> ModuleId {
Expand Down Expand Up @@ -505,7 +505,7 @@ mod test {
let mut def_maps = BTreeMap::new();
let file = FileId::default();

let mut modules = arena::Arena::new();
let mut modules = arena::Arena::default();
let location = Location::new(Default::default(), file);
modules.insert(ModuleData::new(None, location, false));

Expand Down
10 changes: 5 additions & 5 deletions compiler/noirc_frontend/src/node_interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl DefinitionId {

impl From<DefinitionId> for Index {
fn from(id: DefinitionId) -> Self {
Index::from_raw_parts(id.0, u64::MAX)
jfecher marked this conversation as resolved.
Show resolved Hide resolved
Index { ix: id.0 }
}
}

Expand All @@ -254,7 +254,7 @@ impl StmtId {
// This can be anything, as the program will ultimately fail
// after resolution
pub fn dummy_id() -> StmtId {
StmtId(Index::from_raw_parts(std::usize::MAX, 0))
StmtId(Index { ix: std::usize::MAX })
}
}

Expand All @@ -263,7 +263,7 @@ pub struct ExprId(Index);

impl ExprId {
pub fn empty_block_id() -> ExprId {
ExprId(Index::from_raw_parts(0, 0))
ExprId(Index { ix: 0 })
}
}
#[derive(Debug, Eq, PartialEq, Hash, Copy, Clone)]
Expand All @@ -274,7 +274,7 @@ impl FuncId {
// This can be anything, as the program will ultimately fail
// after resolution
pub fn dummy_id() -> FuncId {
FuncId(Index::from_raw_parts(std::usize::MAX, 0))
FuncId(Index { ix: std::usize::MAX })
}
}

Expand Down Expand Up @@ -352,7 +352,7 @@ macro_rules! partialeq {
($id_type:ty) => {
impl PartialEq<usize> for &$id_type {
fn eq(&self, other: &usize) -> bool {
let (index, _) = self.0.into_raw_parts();
let index = self.0.ix;
index == *other
}
}
Expand Down
5 changes: 0 additions & 5 deletions compiler/utils/arena/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,3 @@ version.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
generational-arena = "0.2.8"
51 changes: 49 additions & 2 deletions compiler/utils/arena/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,52 @@
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]

// For now we use a wrapper around generational-arena
pub use generational_arena::{Arena, Index};
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
pub struct Index {
pub ix: usize,
michaeljklein marked this conversation as resolved.
Show resolved Hide resolved
}

#[derive(Debug, Eq, PartialEq, Hash, Clone)]
pub struct Arena<T> {
vec: Vec<T>,
}

impl<T> Default for Arena<T> {
fn default() -> Self {
Self { vec: Vec::new() }
}
}

impl<T> core::ops::Index<Index> for Arena<T> {
type Output = T;

fn index(&self, index: Index) -> &Self::Output {
self.vec.index(index.ix)
}
}

impl<T> core::ops::IndexMut<Index> for Arena<T> {
fn index_mut(&mut self, index: Index) -> &mut Self::Output {
self.vec.index_mut(index.ix)
}
}

impl<T> Arena<T> {
pub fn insert(&mut self, item: T) -> Index {
let ix = self.vec.len();
self.vec.push(item);
Index { ix }
}

pub fn get(&self, index: Index) -> Option<&T> {
self.vec.get(index.ix)
}

pub fn get_mut(&mut self, index: Index) -> Option<&mut T> {
self.vec.get_mut(index.ix)
}

pub fn iter(&self) -> impl Iterator<Item = (Index, &T)> {
self.vec.iter().enumerate().map(|(ix, item)| (Index { ix }, item))
}
}
Loading