Skip to content

Commit

Permalink
Replace unmaintained generational-arena with slotmap
Browse files Browse the repository at this point in the history
Fixes #5628
  • Loading branch information
IGI-111 committed Feb 19, 2024
1 parent 65c1927 commit 8a9d9d2
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 48 deletions.
20 changes: 10 additions & 10 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 sway-ir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ repository.workspace = true
anyhow = "1.0"
downcast-rs = "1.2.0"
filecheck = "0.5"
generational-arena = "0.2"
indexmap = { version = "2.0.0", features = ["rayon"] }
itertools = "0.10.3"
once_cell = "1.18.0"
peg = "0.7"
prettydiff = "0.6.4"
rustc-hash = "1.1.0"
slotmap = "1.0.7"
sway-ir-macros = { version = "0.50.0", path = "sway-ir-macros" }
sway-types = { version = "0.50.0", path = "../sway-types" }
sway-utils = { version = "0.50.0", path = "../sway-utils" }
Expand Down
6 changes: 3 additions & 3 deletions sway-ir/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ use crate::{
Type,
};

/// A wrapper around an [ECS](https://github.com/fitzgen/generational-arena) handle into the
/// A wrapper around an [ECS](https://github.com/orlp/slotmap) handle into the
/// [`Context`].
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, DebugWithContext)]
pub struct Block(pub generational_arena::Index);
pub struct Block(pub slotmap::DefaultKey);

#[doc(hidden)]
pub struct BlockContent {
Expand Down Expand Up @@ -570,7 +570,7 @@ impl Block {

/// An iterator over each block in a [`Function`].
pub struct BlockIterator {
blocks: Vec<generational_arena::Index>,
blocks: Vec<slotmap::DefaultKey>,
next: usize,
}

Expand Down
18 changes: 9 additions & 9 deletions sway-ir/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! The main handle to an IR instance.
//!
//! [`Context`] contains several
//! [generational_arena](https://github.com/fitzgen/generational-arena) collections to maintain the
//! [slotmap](https://github.com/orlp/slotmap) collections to maintain the
//! IR ECS.
//!
//! It is passed around as a mutable reference to many of the Sway-IR APIs.

use generational_arena::Arena;
use rustc_hash::FxHashMap;
use slotmap::{DefaultKey, SlotMap};
use sway_types::SourceEngine;

use crate::{
Expand All @@ -23,14 +23,14 @@ use crate::{
pub struct Context<'eng> {
pub source_engine: &'eng SourceEngine,

pub(crate) modules: Arena<ModuleContent>,
pub(crate) functions: Arena<FunctionContent>,
pub(crate) blocks: Arena<BlockContent>,
pub(crate) values: Arena<ValueContent>,
pub(crate) local_vars: Arena<LocalVarContent>,
pub(crate) types: Arena<TypeContent>,
pub(crate) modules: SlotMap<DefaultKey, ModuleContent>,
pub(crate) functions: SlotMap<DefaultKey, FunctionContent>,
pub(crate) blocks: SlotMap<DefaultKey, BlockContent>,
pub(crate) values: SlotMap<DefaultKey, ValueContent>,
pub(crate) local_vars: SlotMap<DefaultKey, LocalVarContent>,
pub(crate) types: SlotMap<DefaultKey, TypeContent>,
pub(crate) type_map: FxHashMap<TypeContent, Type>,
pub(crate) metadata: Arena<Metadatum>,
pub(crate) metadata: SlotMap<DefaultKey, Metadatum>,

pub program_kind: Kind,

Expand Down
6 changes: 3 additions & 3 deletions sway-ir/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ use crate::{
BlockArgument, BranchToWithArgs,
};

/// A wrapper around an [ECS](https://github.com/fitzgen/generational-arena) handle into the
/// A wrapper around an [ECS](https://github.com/orlp/slotmap) handle into the
/// [`Context`].
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub struct Function(pub generational_arena::Index);
pub struct Function(pub slotmap::DefaultKey);

#[doc(hidden)]
pub struct FunctionContent {
Expand Down Expand Up @@ -541,7 +541,7 @@ impl Function {

/// An iterator over each [`Function`] in a [`Module`].
pub struct FunctionIterator {
functions: Vec<generational_arena::Index>,
functions: Vec<slotmap::DefaultKey>,
next: usize,
}

Expand Down
2 changes: 1 addition & 1 deletion sway-ir/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ impl InstOp {

/// Iterate over all [`Instruction`]s in a specific [`Block`].
pub struct InstructionIterator {
instructions: Vec<generational_arena::Index>,
instructions: Vec<slotmap::DefaultKey>,
next: usize,
next_back: isize,
}
Expand Down
2 changes: 1 addition & 1 deletion sway-ir/src/irtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use crate::{context::Context, pretty::DebugWithContext, Constant, ConstantValue, Value};

#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, DebugWithContext)]
pub struct Type(pub generational_arena::Index);
pub struct Type(pub slotmap::DefaultKey);

#[derive(Debug, Clone, DebugWithContext, Hash, PartialEq, Eq)]
pub enum TypeContent {
Expand Down
2 changes: 1 addition & 1 deletion sway-ir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//!
//! Most of the public data types used in this library are in fact wrappers around a handle into
//! the context. The context uses the
//! [generational_arena](https://github.com/fitzgen/generational-arena) crate to maintain an entity
//! [slotmap](https://github.com/orlp/slotmap) crate to maintain an entity
//! component system, or ECS.
//!
//! The nature of SSA is that it represents a graph of modules, functions, basic blocks and
Expand Down
4 changes: 2 additions & 2 deletions sway-ir/src/local_var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use crate::{
pretty::DebugWithContext,
};

/// A wrapper around an [ECS](https://github.com/fitzgen/generational-arena) handle into the
/// A wrapper around an [ECS](https://github.com/orlp/slotmap) handle into the
/// [`Context`].
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, DebugWithContext)]
pub struct LocalVar(#[in_context(local_vars)] pub generational_arena::Index);
pub struct LocalVar(#[in_context(local_vars)] pub slotmap::DefaultKey);

#[doc(hidden)]
#[derive(Clone, DebugWithContext)]
Expand Down
2 changes: 1 addition & 1 deletion sway-ir/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use sway_types::SourceId;
use crate::context::Context;

#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
pub struct MetadataIndex(pub generational_arena::Index);
pub struct MetadataIndex(pub slotmap::DefaultKey);

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub enum Metadatum {
Expand Down
6 changes: 3 additions & 3 deletions sway-ir/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use crate::{
value::Value,
};

/// A wrapper around an [ECS](https://github.com/fitzgen/generational-arena) handle into the
/// A wrapper around an [ECS](https://github.com/orlp/slotmap) handle into the
/// [`Context`].
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub struct Module(pub generational_arena::Index);
pub struct Module(pub slotmap::DefaultKey);

#[doc(hidden)]
pub struct ModuleContent {
Expand Down Expand Up @@ -113,7 +113,7 @@ impl Module {

/// An iterator over [`Module`]s within a [`Context`].
pub struct ModuleIterator {
modules: Vec<generational_arena::Index>,
modules: Vec<slotmap::DefaultKey>,
next: usize,
}

Expand Down
8 changes: 4 additions & 4 deletions sway-ir/src/pass_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ pub type AnalysisResult = Box<dyn AnalysisResultT>;

/// Program scope over which a pass executes.
pub trait PassScope {
fn get_arena_idx(&self) -> generational_arena::Index;
fn get_arena_idx(&self) -> slotmap::DefaultKey;
}
impl PassScope for Module {
fn get_arena_idx(&self) -> generational_arena::Index {
fn get_arena_idx(&self) -> slotmap::DefaultKey {
self.0
}
}
impl PassScope for Function {
fn get_arena_idx(&self) -> generational_arena::Index {
fn get_arena_idx(&self) -> slotmap::DefaultKey {
self.0
}
}
Expand Down Expand Up @@ -77,7 +77,7 @@ impl Pass {
#[derive(Default)]
pub struct AnalysisResults {
// Hash from (AnalysisResultT, (PassScope, Scope Identity)) to an actual result.
results: FxHashMap<(TypeId, (TypeId, generational_arena::Index)), AnalysisResult>,
results: FxHashMap<(TypeId, (TypeId, slotmap::DefaultKey)), AnalysisResult>,
name_typeid_map: FxHashMap<&'static str, TypeId>,
}

Expand Down
4 changes: 2 additions & 2 deletions sway-ir/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ use crate::{
Block, Instruction,
};

/// A wrapper around an [ECS](https://github.com/fitzgen/generational-arena) handle into the
/// A wrapper around an [ECS](https://github.com/orlp/slotmap) handle into the
/// [`Context`].
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, DebugWithContext)]
pub struct Value(#[in_context(values)] pub generational_arena::Index);
pub struct Value(#[in_context(values)] pub slotmap::DefaultKey);

#[doc(hidden)]
#[derive(Debug, Clone, DebugWithContext)]
Expand Down
9 changes: 3 additions & 6 deletions sway-ir/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,8 @@ impl<'eng> Context<'eng> {
if function.get_module(self) != cur_module {
return Err(IrError::InconsistentParent(
function.get_name(self).into(),
format!("Module_Index_{:?}", cur_module.0.into_raw_parts()),
format!(
"Module_Index_{:?}",
function.get_module(self).0.into_raw_parts()
),
format!("Module_Index_{:?}", cur_module.0),
format!("Module_Index_{:?}", function.get_module(self).0),
));
}
let entry_block = function.get_entry_block(self);
Expand Down Expand Up @@ -193,7 +190,7 @@ impl<'a, 'eng> InstructionVerifier<'a, 'eng> {
if let ValueDatum::Instruction(instruction) = &value_content.value {
if instruction.parent != self.cur_block {
return Err(IrError::InconsistentParent(
format!("Instr_{:?}", ins.0.into_raw_parts()),
format!("Instr_{:?}", ins.0),
self.cur_block.get_label(self.context),
instruction.parent.get_label(self.context),
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ script;
use basic_storage_abi::{BasicStorage, Quad};

fn main() -> u64 {
let addr = abi(BasicStorage, 0x7ee9d721777c523e408a966d97605116e1f2bbad1c16403446c6d734d46258a6);
let addr = abi(BasicStorage, 0x68c0e1ebcddb900439182bf0673a4dde93c02f8c14072305b55f1dd4d1470def);
let key = 0x0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
let value = 4242;

Expand Down

0 comments on commit 8a9d9d2

Please sign in to comment.