Skip to content

Commit

Permalink
tidy deps
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-q committed Jan 17, 2025
1 parent b38a2e8 commit c84c6ca
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 22 deletions.
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
6 changes: 2 additions & 4 deletions hugr-core/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ 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, fxhash::FxHashMap, bumpalo::{Bump, collections::{Vec as BumpVec, String as BumpString}}};
use std::fmt::Write;

pub(crate) const OP_FUNC_CALL_INDIRECT: &str = "func.call-indirect";
Expand Down Expand Up @@ -1148,7 +1146,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
4 changes: 2 additions & 2 deletions 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 write::write_to_vec;
pub use read::{read_from_reader, read_from_slice, ReadError};
pub use write::{write_to_vec, write_to_writer, WriteError};
20 changes: 18 additions & 2 deletions hugr-model/src/v0/binary/read.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
use std::io::BufRead;

use crate::hugr_v0_capnp as hugr_capnp;
use crate::v0 as model;
use bumpalo::collections::Vec as BumpVec;
use bumpalo::Bump;

type ReadResult<T> = Result<T, capnp::Error>;
/// TODO docs
#[derive(Debug, derive_more::From, derive_more::Display, derive_more::Error)]
#[non_exhaustive]
pub enum ReadError {
#[from(forward)]
/// TODO docs
EncodingError(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>> {
read_from_reader(slice, bump)
}

/// Read a hugr module from an impl of [BufRead].
pub fn read_from_reader(reader: impl BufRead, bump: &Bump) -> ReadResult<model::Module<'_>> {
let reader =
capnp::serialize_packed::read_message(slice, capnp::message::ReaderOptions::new())?;
capnp::serialize_packed::read_message(reader, capnp::message::ReaderOptions::new())?;
let root = reader.get_root::<hugr_capnp::module::Reader>()?;
read_module(bump, root)
}
Expand Down
19 changes: 19 additions & 0 deletions hugr-model/src/v0/binary/write.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
use std::io::Write;

use crate::hugr_v0_capnp as hugr_capnp;
use crate::v0 as model;

/// TODO docs
#[derive(Debug, derive_more::From, derive_more::Display, derive_more::Error)]
#[non_exhaustive]
pub enum WriteError {
/// TODO docs
EncodingError(capnp::Error),
}

/// Write a list of items into a list builder.
macro_rules! write_list {
($builder:expr, $init:ident, $write:expr, $list:expr) => {
Expand All @@ -11,6 +21,15 @@ macro_rules! write_list {
};
}

/// Writes a module to an impl of [Write].
pub fn write_to_writer(module: &model::Module, writer: impl Write) -> Result<(), WriteError> {
let mut message = capnp::message::Builder::new_default();
let builder = message.init_root();
write_module(builder, module);

Ok(capnp::serialize_packed::write_message(writer, &message)?)
}

/// Writes a module to a byte vector.
pub fn write_to_vec(module: &model::Module) -> Vec<u8> {
let mut message = capnp::message::Builder::new_default();
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
10 changes: 5 additions & 5 deletions hugr-model/src/v0/text/parse.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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::{
fxhash::FxHashMap,
bumpalo::{Bump, collections::{Vec as BumpVec, String as BumpString}},
scope::{LinkTable, SymbolTable, UnknownSymbolError, VarTable},
AliasDecl, ConstructorDecl, ExtSetPart, FuncDecl, LinkIndex, ListPart, Module, Node, NodeId,
Operation, OperationDecl, Param, ParamSort, Region, RegionId, RegionKind, RegionScope,
ScopeClosure, Term, TermId,
AliasDecl, ConstructorDecl, ExtSetPart, FuncDecl, LinkIndex,
ListPart, Module, Node, NodeId, Operation, OperationDecl, Param, ParamSort, Region, RegionId,
RegionKind, RegionScope, ScopeClosure, Term, TermId,
};

mod pest_parser {
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

0 comments on commit c84c6ca

Please sign in to comment.