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

Replace unmaintained generational-arena with slotmap #5629

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@ -79,7 +79,7 @@
"typeArguments": null
},
"name": "C7_2",
"offset": 4476
"offset": 4516
},
{
"configurableType": {
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ script;
use storage_enum_abi::*;

fn main() -> u64 {
let contract_id = 0x097ea9a771b69bf349375a0d6db542e9c730194de4bcd27e4e6665ffb107dfaf;
let contract_id = 0x21ec4784feb8a4feda42fd1ccfb6c2496d42e03ff54f88be00602086491e1f7b;
let caller = abi(StorageEnum, contract_id);

let res = caller.read_write_enums();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use storage_access_abi::*;
use std::hash::*;

fn main() -> bool {
let contract_id = 0xcd976bf8d7f3a9b54416c215ee0c732cbae4f9221e281fbc6c6aa8f428f03eb1;
let contract_id = 0xed4bbc1286211512f6894d6eded69eb27a8eaf551de44f10d2efb93088d9db82;
let caller = abi(StorageAccess, contract_id);

caller.set_boolean(true);
Expand Down
Loading