Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ repos:
# built into a binary build (without using `maturin`)
#
# This feature list should be kept in sync with the `hugr-py/pyproject.toml`
entry: cargo test --workspace --exclude 'hugr-py' --features 'hugr/extension_inference hugr/declarative hugr/model_unstable hugr/llvm hugr/llvm-test hugr/zstd'
entry: cargo test --workspace --exclude 'hugr-py' --features 'hugr/extension_inference hugr/declarative hugr/llvm hugr/llvm-test hugr/zstd'
language: system
files: \.rs$
pass_filenames: false
Expand Down
96 changes: 34 additions & 62 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ regex = "1.10.6"
regex-syntax = "0.8.3"
rstest = "0.24.0"
semver = "1.0.26"
serde = "1.0.195"
serde = "1.0.219"
serde_json = "1.0.140"
serde_yaml = "0.9.34"
smol_str = "0.3.1"
Expand Down Expand Up @@ -87,8 +87,8 @@ zstd = "0.13.2"
# These public dependencies usually require breaking changes downstream, so we
# try to be as permissive as possible.
pyo3 = ">= 0.23.4, < 0.25"
portgraph = { version = ">= 0.13.3, < 0.15" }
petgraph = { version = ">= 0.7.1, < 0.9", default-features = false }
portgraph = { version = "0.14.1" }
petgraph = { version = ">= 0.8.1, < 0.9", default-features = false }

[profile.dev.package]
insta.opt-level = 3
Expand Down
6 changes: 3 additions & 3 deletions hugr-core/src/builder/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ pub(crate) mod test {

#[rstest]
fn dfg_hugr(simple_dfg_hugr: Hugr) {
assert_eq!(simple_dfg_hugr.node_count(), 3);
assert_matches!(simple_dfg_hugr.root_type().tag(), OpTag::Dfg);
assert_eq!(simple_dfg_hugr.num_nodes(), 3);
assert_matches!(simple_dfg_hugr.root_optype().tag(), OpTag::Dfg);
}

#[test]
Expand All @@ -533,7 +533,7 @@ pub(crate) mod test {
};

let hugr = module_builder.finish_hugr()?;
assert_eq!(hugr.node_count(), 7);
assert_eq!(hugr.num_nodes(), 7);

assert_eq!(hugr.get_metadata(hugr.root(), "x"), None);
assert_eq!(hugr.get_metadata(dfg_node, "x").cloned(), Some(json!(42)));
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub struct Wire<N = Node>(N, OutgoingPort);
impl Node {
/// Returns the node as a portgraph `NodeIndex`.
#[inline]
pub(crate) fn pg_index(self) -> portgraph::NodeIndex {
pub(crate) fn into_portgraph(self) -> portgraph::NodeIndex {
self.index
}
}
Expand Down
15 changes: 7 additions & 8 deletions hugr-core/src/export.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Exporting HUGR graphs to their `hugr-model` representation.
use crate::hugr::internal::HugrInternals;
use crate::{
extension::{ExtensionId, OpDef, SignatureFunc},
hugr::IdentList,
Expand Down Expand Up @@ -94,7 +95,7 @@ struct Context<'a> {
impl<'a> Context<'a> {
pub fn new(hugr: &'a Hugr, bump: &'a Bump) -> Self {
let mut module = table::Module::default();
module.nodes.reserve(hugr.node_count());
module.nodes.reserve(hugr.num_nodes());
let links = Links::new(hugr);

Self {
Expand Down Expand Up @@ -999,7 +1000,7 @@ impl<'a> Context<'a> {
let outer_hugr = std::mem::replace(&mut self.hugr, hugr);
let outer_node_to_id = std::mem::take(&mut self.node_to_id);

let region = match hugr.root_type() {
let region = match hugr.root_optype() {
OpType::DFG(_) => self.export_dfg(hugr.root(), model::ScopeClosure::Closed),
_ => panic!("Value::Function root must be a DFG"),
};
Expand Down Expand Up @@ -1031,7 +1032,7 @@ impl<'a> Context<'a> {
}

pub fn export_node_metadata(&mut self, node: Node) -> &'a [table::TermId] {
let metadata_map = self.hugr.get_node_metadata(node);
let metadata_map = self.hugr.node_metadata_map(node);

let has_order_edges = {
fn is_relevant_node(hugr: &Hugr, node: Node) -> bool {
Expand All @@ -1049,13 +1050,11 @@ impl<'a> Context<'a> {
.any(|(other, _)| is_relevant_node(self.hugr, other))
};

let meta_capacity = metadata_map.map_or(0, |map| map.len()) + has_order_edges as usize;
let meta_capacity = metadata_map.len() + has_order_edges as usize;
let mut meta = BumpVec::with_capacity_in(meta_capacity, self.bump);

if let Some(metadata_map) = metadata_map {
for (name, value) in metadata_map {
meta.push(self.export_json_meta(name, value));
}
for (name, value) in metadata_map {
meta.push(self.export_json_meta(name, value));
}

if has_order_edges {
Expand Down
Loading
Loading