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

refactor(hugr-model)!: Reexport indexmap, bumpalo, and fxhash from hugr-model #1870

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 0 additions & 3 deletions hugr-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ strum = { workspace = true }
strum_macros = { workspace = true }
semver = { version = "1.0.23", features = ["serde"] }
hugr-model = { version = "0.16.0", path = "../hugr-model", optional = true }
indexmap.workspace = true
fxhash.workspace = true
bumpalo = { workspace = true, features = ["collections"] }

[dev-dependencies]
rstest = { workspace = true }
Expand Down
13 changes: 9 additions & 4 deletions hugr-core/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ use crate::{
},
Direction, Hugr, HugrView, IncomingPort, Node, Port,
};
use bumpalo::{collections::String as BumpString, collections::Vec as BumpVec, Bump};
use fxhash::FxHashMap;
use hugr_model::v0::{self as model};
use hugr_model::v0::{
self as model,
bumpalo::{
collections::{String as BumpString, Vec as BumpVec},
Bump,
},
fxhash::FxHashMap,
};
use std::fmt::Write;

pub(crate) const OP_FUNC_CALL_INDIRECT: &str = "func.call-indirect";
Expand Down Expand Up @@ -1148,7 +1153,7 @@ mod test {
#[rstest]
#[case(test_simple_circuit())]
fn test_export(#[case] hugr: Hugr) {
use bumpalo::Bump;
use hugr_model::v0::bumpalo::Bump;
let bump = Bump::new();
let _model = super::export_hugr(&hugr, &bump);
}
Expand Down
3 changes: 1 addition & 2 deletions hugr-core/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ use crate::{
},
Direction, Hugr, HugrView, Node, Port,
};
use fxhash::FxHashMap;
use hugr_model::v0::{self as model};
use hugr_model::v0::{self as model, fxhash::FxHashMap};
use itertools::Either;
use smol_str::{SmolStr, ToSmolStr};
use thiserror::Error;
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/tests/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use hugr_core::{export::export_hugr, import::import_hugr};
use hugr_model::v0 as model;

fn roundtrip(source: &str) -> String {
let bump = bumpalo::Bump::new();
let bump = model::bumpalo::Bump::new();
let parsed_model = model::text::parse(source, &bump).unwrap();
let imported_hugr = import_hugr(&parsed_model.module, &std_reg()).unwrap();
let exported_model = export_hugr(&imported_hugr, &bump);
Expand Down
2 changes: 1 addition & 1 deletion hugr-model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bench = false
base64 = { workspace = true }
bumpalo = { workspace = true, features = ["collections"] }
capnp = "0.20.1"
derive_more = { version = "1.0.0", features = ["display"] }
derive_more = { version = "1.0.0", features = ["display", "from", "error"] }
fxhash.workspace = true
indexmap.workspace = true
pest = "2.7.12"
Expand Down
2 changes: 1 addition & 1 deletion hugr-model/src/v0/binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
mod read;
mod write;

pub use read::read_from_slice;
pub use read::{read_from_slice, ReadError};
pub use write::write_to_vec;
11 changes: 10 additions & 1 deletion hugr-model/src/v0/binary/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ use crate::v0 as model;
use bumpalo::collections::Vec as BumpVec;
use bumpalo::Bump;

type ReadResult<T> = Result<T, capnp::Error>;
/// An error encounted while deserialising a model.
#[derive(Debug, derive_more::From, derive_more::Display, derive_more::Error)]
#[non_exhaustive]
pub enum ReadError {
#[from(forward)]
/// An error encounted while decoding a model from a `capnproto` buffer.
DecodingError(capnp::Error),
}

type ReadResult<T> = Result<T, ReadError>;

/// Read a hugr module from a byte slice.
pub fn read_from_slice<'a>(slice: &[u8], bump: &'a Bump) -> ReadResult<model::Module<'a>> {
Expand Down
4 changes: 4 additions & 0 deletions hugr-model/src/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ pub mod binary;
pub mod scope;
pub mod text;

pub use bumpalo;
pub use fxhash;
pub use indexmap;

macro_rules! define_index {
($(#[$meta:meta])* $vis:vis struct $name:ident(pub u32);) => {
#[repr(transparent)]
Expand Down
7 changes: 5 additions & 2 deletions hugr-model/src/v0/text/parse.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use base64::{prelude::BASE64_STANDARD, Engine};
use bumpalo::{collections::String as BumpString, collections::Vec as BumpVec, Bump};
use fxhash::FxHashMap;
use pest::{
iterators::{Pair, Pairs},
Parser, RuleType,
};
use thiserror::Error;

use crate::v0::{
bumpalo::{
collections::{String as BumpString, Vec as BumpVec},
Bump,
},
fxhash::FxHashMap,
scope::{LinkTable, SymbolTable, UnknownSymbolError, VarTable},
AliasDecl, ConstructorDecl, ExtSetPart, FuncDecl, LinkIndex, ListPart, Module, Node, NodeId,
Operation, OperationDecl, Param, ParamSort, Region, RegionId, RegionKind, RegionScope,
Expand Down
2 changes: 1 addition & 1 deletion hugr-model/tests/binary.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(missing_docs)]

use bumpalo::Bump;
use hugr_model::v0 as model;
use model::bumpalo::Bump;
use pretty_assertions::assert_eq;

/// Reads a module from a string, serializes it to binary, and then deserializes it back to a module.
Expand Down
2 changes: 1 addition & 1 deletion hugr-model/tests/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use hugr_model::v0 as model;

fn roundtrip(source: &str) -> String {
let bump = bumpalo::Bump::new();
let bump = model::bumpalo::Bump::new();
let parsed_model = model::text::parse(source, &bump).unwrap();
model::text::print_to_string(&parsed_model.module, 80).unwrap()
}
Expand Down
Loading