From bb1565f61f76d9f7cc4de0df8edaccc94d9f1ecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Borgna?= <121866228+aborgna-q@users.noreply.github.com> Date: Tue, 28 May 2024 14:26:47 +0100 Subject: [PATCH] refactor: Add a `hugr-core` crate (#1108) Moves all the code from `hugr` into a `hugr-core` subcrate. This way, `hugr-passes` (and any other new subcrate) can depend on the core definitions and get reexported in `hugr`. This PR does not. Change any definition or visibility in the code, as the renamed files are noisy enough. In particular, having `hugr-core` will let us unseal `HugrInternals` and `HugrMutInternals` so they can be used in `tket2`, but that's work for another PR. As a bonus, #1100 is no longer a breaking change since we can re-export the library without a cyclic dependency. Closes #294 --- .github/CODEOWNERS | 4 +- .github/change-filters.yml | 2 +- Cargo.toml | 10 ++- hugr-core/CHANGELOG.md | 1 + hugr-core/Cargo.toml | 66 +++++++++++++++++++ hugr-core/README.md | 42 ++++++++++++ {hugr => hugr-core}/build.rs | 0 {hugr => hugr-core}/src/builder.rs | 0 .../src/builder/build_traits.rs | 0 {hugr => hugr-core}/src/builder/cfg.rs | 0 {hugr => hugr-core}/src/builder/circuit.rs | 0 .../src/builder/conditional.rs | 0 {hugr => hugr-core}/src/builder/dataflow.rs | 0 {hugr => hugr-core}/src/builder/handle.rs | 0 {hugr => hugr-core}/src/builder/module.rs | 0 {hugr => hugr-core}/src/builder/tail_loop.rs | 0 {hugr => hugr-core}/src/cli.rs | 0 {hugr => hugr-core}/src/core.rs | 0 {hugr => hugr-core}/src/extension.rs | 0 .../src/extension/const_fold.rs | 0 .../src/extension/declarative.rs | 6 +- .../src/extension/declarative/ops.rs | 0 .../src/extension/declarative/signature.rs | 0 .../src/extension/declarative/types.rs | 0 {hugr => hugr-core}/src/extension/infer.rs | 0 .../src/extension/infer/test.rs | 0 {hugr => hugr-core}/src/extension/op_def.rs | 0 {hugr => hugr-core}/src/extension/prelude.rs | 0 .../src/extension/simple_op.rs | 0 {hugr => hugr-core}/src/extension/type_def.rs | 0 {hugr => hugr-core}/src/extension/validate.rs | 0 {hugr => hugr-core}/src/hugr.rs | 0 {hugr => hugr-core}/src/hugr/hugrmut.rs | 0 {hugr => hugr-core}/src/hugr/ident.rs | 0 {hugr => hugr-core}/src/hugr/rewrite.rs | 0 .../src/hugr/rewrite/consts.rs | 0 .../src/hugr/rewrite/inline_dfg.rs | 0 .../src/hugr/rewrite/insert_identity.rs | 0 .../src/hugr/rewrite/outline_cfg.rs | 0 .../src/hugr/rewrite/replace.rs | 0 .../src/hugr/rewrite/simple_replace.rs | 0 {hugr => hugr-core}/src/hugr/serialize.rs | 0 .../src/hugr/serialize/test.rs | 0 {hugr => hugr-core}/src/hugr/validate.rs | 0 {hugr => hugr-core}/src/hugr/validate/test.rs | 0 {hugr => hugr-core}/src/hugr/views.rs | 0 .../src/hugr/views/descendants.rs | 0 .../src/hugr/views/petgraph.rs | 0 {hugr => hugr-core}/src/hugr/views/render.rs | 0 .../src/hugr/views/root_checked.rs | 0 {hugr => hugr-core}/src/hugr/views/sibling.rs | 0 .../src/hugr/views/sibling_subgraph.rs | 0 ...ugr_core__hugr__views__tests__dot_cfg.snap | 2 +- ...ugr_core__hugr__views__tests__dot_dfg.snap | 2 +- ...re__hugr__views__tests__dot_empty_dfg.snap | 2 +- ...ugr_core__hugr__views__tests__mmd_cfg.snap | 2 +- ...ugr_core__hugr__views__tests__mmd_dfg.snap | 2 +- ...re__hugr__views__tests__mmd_empty_dfg.snap | 2 +- {hugr => hugr-core}/src/hugr/views/tests.rs | 0 hugr-core/src/lib.rs | 31 +++++++++ {hugr => hugr-core}/src/macros.rs | 4 +- {hugr => hugr-core}/src/ops.rs | 0 {hugr => hugr-core}/src/ops/constant.rs | 0 .../src/ops/constant/custom.rs | 0 {hugr => hugr-core}/src/ops/controlflow.rs | 0 {hugr => hugr-core}/src/ops/custom.rs | 0 {hugr => hugr-core}/src/ops/dataflow.rs | 0 {hugr => hugr-core}/src/ops/handle.rs | 0 {hugr => hugr-core}/src/ops/leaf.rs | 0 {hugr => hugr-core}/src/ops/module.rs | 0 {hugr => hugr-core}/src/ops/tag.rs | 0 {hugr => hugr-core}/src/ops/validate.rs | 0 {hugr => hugr-core}/src/proptest.rs | 0 {hugr => hugr-core}/src/std_extensions.rs | 0 .../std_extensions/arithmetic/conversions.rs | 0 .../arithmetic/conversions/const_fold.rs | 0 .../std_extensions/arithmetic/float_ops.rs | 0 .../arithmetic/float_ops/const_fold.rs | 0 .../std_extensions/arithmetic/float_types.rs | 0 .../src/std_extensions/arithmetic/int_ops.rs | 0 .../arithmetic/int_ops/const_fold.rs | 0 .../std_extensions/arithmetic/int_types.rs | 0 .../src/std_extensions/arithmetic/mod.rs | 0 .../src/std_extensions/collections.rs | 0 .../src/std_extensions/logic.rs | 0 {hugr => hugr-core}/src/types.rs | 0 {hugr => hugr-core}/src/types/check.rs | 0 {hugr => hugr-core}/src/types/custom.rs | 0 {hugr => hugr-core}/src/types/poly_func.rs | 0 {hugr => hugr-core}/src/types/serialize.rs | 0 {hugr => hugr-core}/src/types/signature.rs | 0 {hugr => hugr-core}/src/types/type_param.rs | 0 {hugr => hugr-core}/src/types/type_row.rs | 0 {hugr => hugr-core}/src/utils.rs | 0 hugr-passes/Cargo.toml | 4 +- hugr-passes/src/const_fold.rs | 8 +-- hugr-passes/src/const_fold/test.rs | 36 +++++----- hugr-passes/src/half_node.rs | 14 ++-- hugr-passes/src/merge_bbs.rs | 34 +++++----- hugr-passes/src/nest_cfgs.rs | 40 +++++------ hugr/Cargo.toml | 46 +++---------- hugr/src/lib.rs | 36 ++++------ hugr/src/main.rs | 2 +- hugr/tests/cli.rs | 8 +-- release-plz.toml | 22 ++++--- 105 files changed, 269 insertions(+), 159 deletions(-) create mode 100644 hugr-core/CHANGELOG.md create mode 100644 hugr-core/Cargo.toml create mode 100644 hugr-core/README.md rename {hugr => hugr-core}/build.rs (100%) rename {hugr => hugr-core}/src/builder.rs (100%) rename {hugr => hugr-core}/src/builder/build_traits.rs (100%) rename {hugr => hugr-core}/src/builder/cfg.rs (100%) rename {hugr => hugr-core}/src/builder/circuit.rs (100%) rename {hugr => hugr-core}/src/builder/conditional.rs (100%) rename {hugr => hugr-core}/src/builder/dataflow.rs (100%) rename {hugr => hugr-core}/src/builder/handle.rs (100%) rename {hugr => hugr-core}/src/builder/module.rs (100%) rename {hugr => hugr-core}/src/builder/tail_loop.rs (100%) rename {hugr => hugr-core}/src/cli.rs (100%) rename {hugr => hugr-core}/src/core.rs (100%) rename {hugr => hugr-core}/src/extension.rs (100%) rename {hugr => hugr-core}/src/extension/const_fold.rs (100%) rename {hugr => hugr-core}/src/extension/declarative.rs (98%) rename {hugr => hugr-core}/src/extension/declarative/ops.rs (100%) rename {hugr => hugr-core}/src/extension/declarative/signature.rs (100%) rename {hugr => hugr-core}/src/extension/declarative/types.rs (100%) rename {hugr => hugr-core}/src/extension/infer.rs (100%) rename {hugr => hugr-core}/src/extension/infer/test.rs (100%) rename {hugr => hugr-core}/src/extension/op_def.rs (100%) rename {hugr => hugr-core}/src/extension/prelude.rs (100%) rename {hugr => hugr-core}/src/extension/simple_op.rs (100%) rename {hugr => hugr-core}/src/extension/type_def.rs (100%) rename {hugr => hugr-core}/src/extension/validate.rs (100%) rename {hugr => hugr-core}/src/hugr.rs (100%) rename {hugr => hugr-core}/src/hugr/hugrmut.rs (100%) rename {hugr => hugr-core}/src/hugr/ident.rs (100%) rename {hugr => hugr-core}/src/hugr/rewrite.rs (100%) rename {hugr => hugr-core}/src/hugr/rewrite/consts.rs (100%) rename {hugr => hugr-core}/src/hugr/rewrite/inline_dfg.rs (100%) rename {hugr => hugr-core}/src/hugr/rewrite/insert_identity.rs (100%) rename {hugr => hugr-core}/src/hugr/rewrite/outline_cfg.rs (100%) rename {hugr => hugr-core}/src/hugr/rewrite/replace.rs (100%) rename {hugr => hugr-core}/src/hugr/rewrite/simple_replace.rs (100%) rename {hugr => hugr-core}/src/hugr/serialize.rs (100%) rename {hugr => hugr-core}/src/hugr/serialize/test.rs (100%) rename {hugr => hugr-core}/src/hugr/validate.rs (100%) rename {hugr => hugr-core}/src/hugr/validate/test.rs (100%) rename {hugr => hugr-core}/src/hugr/views.rs (100%) rename {hugr => hugr-core}/src/hugr/views/descendants.rs (100%) rename {hugr => hugr-core}/src/hugr/views/petgraph.rs (100%) rename {hugr => hugr-core}/src/hugr/views/render.rs (100%) rename {hugr => hugr-core}/src/hugr/views/root_checked.rs (100%) rename {hugr => hugr-core}/src/hugr/views/sibling.rs (100%) rename {hugr => hugr-core}/src/hugr/views/sibling_subgraph.rs (100%) rename hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_cfg.snap => hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_cfg.snap (98%) rename hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_dfg.snap => hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_dfg.snap (98%) rename hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_empty_dfg.snap => hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_empty_dfg.snap (94%) rename hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_cfg.snap => hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_cfg.snap (94%) rename hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_dfg.snap => hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_dfg.snap (90%) rename hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_empty_dfg.snap => hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_empty_dfg.snap (81%) rename {hugr => hugr-core}/src/hugr/views/tests.rs (100%) create mode 100644 hugr-core/src/lib.rs rename {hugr => hugr-core}/src/macros.rs (97%) rename {hugr => hugr-core}/src/ops.rs (100%) rename {hugr => hugr-core}/src/ops/constant.rs (100%) rename {hugr => hugr-core}/src/ops/constant/custom.rs (100%) rename {hugr => hugr-core}/src/ops/controlflow.rs (100%) rename {hugr => hugr-core}/src/ops/custom.rs (100%) rename {hugr => hugr-core}/src/ops/dataflow.rs (100%) rename {hugr => hugr-core}/src/ops/handle.rs (100%) rename {hugr => hugr-core}/src/ops/leaf.rs (100%) rename {hugr => hugr-core}/src/ops/module.rs (100%) rename {hugr => hugr-core}/src/ops/tag.rs (100%) rename {hugr => hugr-core}/src/ops/validate.rs (100%) rename {hugr => hugr-core}/src/proptest.rs (100%) rename {hugr => hugr-core}/src/std_extensions.rs (100%) rename {hugr => hugr-core}/src/std_extensions/arithmetic/conversions.rs (100%) rename {hugr => hugr-core}/src/std_extensions/arithmetic/conversions/const_fold.rs (100%) rename {hugr => hugr-core}/src/std_extensions/arithmetic/float_ops.rs (100%) rename {hugr => hugr-core}/src/std_extensions/arithmetic/float_ops/const_fold.rs (100%) rename {hugr => hugr-core}/src/std_extensions/arithmetic/float_types.rs (100%) rename {hugr => hugr-core}/src/std_extensions/arithmetic/int_ops.rs (100%) rename {hugr => hugr-core}/src/std_extensions/arithmetic/int_ops/const_fold.rs (100%) rename {hugr => hugr-core}/src/std_extensions/arithmetic/int_types.rs (100%) rename {hugr => hugr-core}/src/std_extensions/arithmetic/mod.rs (100%) rename {hugr => hugr-core}/src/std_extensions/collections.rs (100%) rename {hugr => hugr-core}/src/std_extensions/logic.rs (100%) rename {hugr => hugr-core}/src/types.rs (100%) rename {hugr => hugr-core}/src/types/check.rs (100%) rename {hugr => hugr-core}/src/types/custom.rs (100%) rename {hugr => hugr-core}/src/types/poly_func.rs (100%) rename {hugr => hugr-core}/src/types/serialize.rs (100%) rename {hugr => hugr-core}/src/types/signature.rs (100%) rename {hugr => hugr-core}/src/types/type_param.rs (100%) rename {hugr => hugr-core}/src/types/type_row.rs (100%) rename {hugr => hugr-core}/src/utils.rs (100%) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 9ce5c2067..e75b144d6 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -8,6 +8,4 @@ # The release PRs that trigger publication to crates.io or PyPI always modify the changelog. # We require those PRs to be approved by someone with release permissions. -hugr/CHANGELOG.md @aborgna-q @cqc-alec @ss2165 -hugr-passes/CHANGELOG.md @aborgna-q @cqc-alec @ss2165 -hugr-py/CHANGELOG.md @aborgna-q @cqc-alec @ss2165 +**/CHANGELOG.md @aborgna-q @cqc-alec @ss2165 diff --git a/.github/change-filters.yml b/.github/change-filters.yml index ebf6b45e7..d3e901aa9 100644 --- a/.github/change-filters.yml +++ b/.github/change-filters.yml @@ -3,7 +3,7 @@ rust: - "hugr/**" - - "hugr-passes/**" + - "hugr-*/**" - "Cargo.toml" - "specification/schema/**" diff --git a/Cargo.toml b/Cargo.toml index b7adbd9b4..a1ff18b5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,8 +3,9 @@ lto = "thin" [workspace] resolver = "2" -members = ["hugr", "hugr-passes"] -default-members = ["hugr", "hugr-passes"] +members = ["hugr", "hugr-core", "hugr-passes"] +default-members = ["hugr", "hugr-core", "hugr-passes"] +default-run = "hugr" [workspace.package] rust-version = "1.75" @@ -17,6 +18,11 @@ license = "Apache-2.0" [workspace.lints.rust] missing_docs = "warn" +[workspace.lints.clippy] +# Unstable check, may cause false positives. +# https://github.com/rust-lang/rust-clippy/issues/5112 +debug_assert_with_mut_call = "warn" + [workspace.dependencies] portgraph = { version = "0.12.0" } insta = { version = "1.34.0" } diff --git a/hugr-core/CHANGELOG.md b/hugr-core/CHANGELOG.md new file mode 100644 index 000000000..825c32f0d --- /dev/null +++ b/hugr-core/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog diff --git a/hugr-core/Cargo.toml b/hugr-core/Cargo.toml new file mode 100644 index 000000000..5894ef984 --- /dev/null +++ b/hugr-core/Cargo.toml @@ -0,0 +1,66 @@ +[package] +name = "hugr-core" +version = "0.0.0" +edition = { workspace = true } +rust-version = { workspace = true } + +license = { workspace = true } +readme = "README.md" +documentation = "https://docs.rs/hugr/" +homepage = { workspace = true } +repository = { workspace = true } +description = "Quantinuum's Hierarchical Unified Graph Representation" +keywords = ["Quantum", "Quantinuum"] +categories = ["compilers"] + +[lints] +workspace = true + +[features] +extension_inference = [] +cli = ["dep:clap", "dep:clap-stdin"] + +[dependencies] +portgraph = { workspace = true, features = ["serde", "petgraph"] } +thiserror = { workspace = true } +regex = { workspace = true } +cgmath = { workspace = true, features = ["serde"] } +num-rational = { workspace = true, features = ["serde"] } +downcast-rs = { workspace = true } +# Rc used here for Extension, but unfortunately we must turn the feature on globally +serde = { workspace = true, features = ["derive", "rc"] } +serde_yaml = { workspace = true } +typetag = { workspace = true } +smol_str = { workspace = true, features = ["serde"] } +derive_more = { workspace = true } +itertools = { workspace = true } +html-escape = { workspace = true } +bitvec = { workspace = true, features = ["serde"] } +enum_dispatch = { workspace = true } +lazy_static = { workspace = true } +petgraph = { workspace = true } +context-iterators = { workspace = true } +serde_json = { workspace = true } +delegate = { workspace = true } +paste = { workspace = true } +strum = { workspace = true } +strum_macros = { workspace = true } +clap = { workspace = true, features = ["derive"], optional = true } +clap-stdin = { workspace = true, optional = true } + +[dev-dependencies] +rstest = { workspace = true } +webbrowser = { workspace = true } +urlencoding = { workspace = true } +cool_asserts = { workspace = true } +insta = { workspace = true, features = ["yaml"] } +jsonschema = { workspace = true } +proptest = { workspace = true } +proptest-derive = { workspace = true } +regex-syntax = { workspace = true } +assert_cmd = { workspace = true } +predicates = { workspace = true } +assert_fs = { workspace = true } + +# Required for documentation examples +hugr = { path = "../hugr" } diff --git a/hugr-core/README.md b/hugr-core/README.md new file mode 100644 index 000000000..2b45f92ec --- /dev/null +++ b/hugr-core/README.md @@ -0,0 +1,42 @@ +![](/hugr/assets/hugr_logo.svg) + +hugr-core +=============== + +[![build_status][]](https://github.com/CQCL/hugr/actions) +[![crates][]](https://crates.io/crates/hugr-core) +[![msrv][]](https://github.com/CQCL/hugr) +[![codecov][]](https://codecov.io/gh/CQCL/hugr) + +Internal core definitions for the `hugr` package. +Refer to the [main crate](http://crates.io/crates/hugr) for more information. + +Please read the [API documentation here][]. + +## Experimental Features + +- `extension_inference`: + Experimental feature which allows automatic inference of extension usages and + requirements in a HUGR and validation that extensions are correctly specified. + Not enabled by default. + +## Recent Changes + +See [CHANGELOG][] for a list of changes. The minimum supported rust +version will only change on major releases. + +## Development + +See [DEVELOPMENT.md](https://github.com/CQCL/hugr/blob/main/DEVELOPMENT.md) for instructions on setting up the development environment. + +## License + +This project is licensed under Apache License, Version 2.0 ([LICENSE][] or http://www.apache.org/licenses/LICENSE-2.0). + + [API documentation here]: https://docs.rs/hugr-core/ + [build_status]: https://github.com/CQCL/hugr/actions/workflows/ci-rs.yml/badge.svg?branch=main + [msrv]: https://img.shields.io/badge/rust-1.75.0%2B-blue.svg + [crates]: https://img.shields.io/crates/v/hugr-core + [codecov]: https://img.shields.io/codecov/c/gh/CQCL/hugr?logo=codecov + [LICENSE]: https://github.com/CQCL/hugr/blob/main/LICENCE + [CHANGELOG]: https://github.com/CQCL/hugr/blob/main/hugr-core/CHANGELOG.md diff --git a/hugr/build.rs b/hugr-core/build.rs similarity index 100% rename from hugr/build.rs rename to hugr-core/build.rs diff --git a/hugr/src/builder.rs b/hugr-core/src/builder.rs similarity index 100% rename from hugr/src/builder.rs rename to hugr-core/src/builder.rs diff --git a/hugr/src/builder/build_traits.rs b/hugr-core/src/builder/build_traits.rs similarity index 100% rename from hugr/src/builder/build_traits.rs rename to hugr-core/src/builder/build_traits.rs diff --git a/hugr/src/builder/cfg.rs b/hugr-core/src/builder/cfg.rs similarity index 100% rename from hugr/src/builder/cfg.rs rename to hugr-core/src/builder/cfg.rs diff --git a/hugr/src/builder/circuit.rs b/hugr-core/src/builder/circuit.rs similarity index 100% rename from hugr/src/builder/circuit.rs rename to hugr-core/src/builder/circuit.rs diff --git a/hugr/src/builder/conditional.rs b/hugr-core/src/builder/conditional.rs similarity index 100% rename from hugr/src/builder/conditional.rs rename to hugr-core/src/builder/conditional.rs diff --git a/hugr/src/builder/dataflow.rs b/hugr-core/src/builder/dataflow.rs similarity index 100% rename from hugr/src/builder/dataflow.rs rename to hugr-core/src/builder/dataflow.rs diff --git a/hugr/src/builder/handle.rs b/hugr-core/src/builder/handle.rs similarity index 100% rename from hugr/src/builder/handle.rs rename to hugr-core/src/builder/handle.rs diff --git a/hugr/src/builder/module.rs b/hugr-core/src/builder/module.rs similarity index 100% rename from hugr/src/builder/module.rs rename to hugr-core/src/builder/module.rs diff --git a/hugr/src/builder/tail_loop.rs b/hugr-core/src/builder/tail_loop.rs similarity index 100% rename from hugr/src/builder/tail_loop.rs rename to hugr-core/src/builder/tail_loop.rs diff --git a/hugr/src/cli.rs b/hugr-core/src/cli.rs similarity index 100% rename from hugr/src/cli.rs rename to hugr-core/src/cli.rs diff --git a/hugr/src/core.rs b/hugr-core/src/core.rs similarity index 100% rename from hugr/src/core.rs rename to hugr-core/src/core.rs diff --git a/hugr/src/extension.rs b/hugr-core/src/extension.rs similarity index 100% rename from hugr/src/extension.rs rename to hugr-core/src/extension.rs diff --git a/hugr/src/extension/const_fold.rs b/hugr-core/src/extension/const_fold.rs similarity index 100% rename from hugr/src/extension/const_fold.rs rename to hugr-core/src/extension/const_fold.rs diff --git a/hugr/src/extension/declarative.rs b/hugr-core/src/extension/declarative.rs similarity index 98% rename from hugr/src/extension/declarative.rs rename to hugr-core/src/extension/declarative.rs index 80c44b40f..99ea08adb 100644 --- a/hugr/src/extension/declarative.rs +++ b/hugr-core/src/extension/declarative.rs @@ -9,12 +9,12 @@ //! ### Example //! //! ```yaml -#![doc = include_str!("../../examples/extension/declarative.yaml")] +#![doc = include_str!("../../../hugr/examples/extension/declarative.yaml")] //! ``` //! //! The definition can be loaded into a registry using the [`load_extensions`] or [`load_extensions_file`] functions. //! ```rust -//! # const DECLARATIVE_YAML: &str = include_str!("../../examples/extension/declarative.yaml"); +//! # const DECLARATIVE_YAML: &str = include_str!("../../../hugr/examples/extension/declarative.yaml"); //! # use hugr::extension::declarative::load_extensions; //! // Required extensions must already be present in the registry. //! let mut reg = hugr::std_extensions::logic::LOGIC_REG.clone(); @@ -327,7 +327,7 @@ extensions: "#; /// The yaml used in the module documentation. - const EXAMPLE_YAML_FILE: &str = "examples/extension/declarative.yaml"; + const EXAMPLE_YAML_FILE: &str = "../hugr/examples/extension/declarative.yaml"; #[rstest] #[case(EMPTY_YAML, 1, 0, 0, &PRELUDE_REGISTRY)] diff --git a/hugr/src/extension/declarative/ops.rs b/hugr-core/src/extension/declarative/ops.rs similarity index 100% rename from hugr/src/extension/declarative/ops.rs rename to hugr-core/src/extension/declarative/ops.rs diff --git a/hugr/src/extension/declarative/signature.rs b/hugr-core/src/extension/declarative/signature.rs similarity index 100% rename from hugr/src/extension/declarative/signature.rs rename to hugr-core/src/extension/declarative/signature.rs diff --git a/hugr/src/extension/declarative/types.rs b/hugr-core/src/extension/declarative/types.rs similarity index 100% rename from hugr/src/extension/declarative/types.rs rename to hugr-core/src/extension/declarative/types.rs diff --git a/hugr/src/extension/infer.rs b/hugr-core/src/extension/infer.rs similarity index 100% rename from hugr/src/extension/infer.rs rename to hugr-core/src/extension/infer.rs diff --git a/hugr/src/extension/infer/test.rs b/hugr-core/src/extension/infer/test.rs similarity index 100% rename from hugr/src/extension/infer/test.rs rename to hugr-core/src/extension/infer/test.rs diff --git a/hugr/src/extension/op_def.rs b/hugr-core/src/extension/op_def.rs similarity index 100% rename from hugr/src/extension/op_def.rs rename to hugr-core/src/extension/op_def.rs diff --git a/hugr/src/extension/prelude.rs b/hugr-core/src/extension/prelude.rs similarity index 100% rename from hugr/src/extension/prelude.rs rename to hugr-core/src/extension/prelude.rs diff --git a/hugr/src/extension/simple_op.rs b/hugr-core/src/extension/simple_op.rs similarity index 100% rename from hugr/src/extension/simple_op.rs rename to hugr-core/src/extension/simple_op.rs diff --git a/hugr/src/extension/type_def.rs b/hugr-core/src/extension/type_def.rs similarity index 100% rename from hugr/src/extension/type_def.rs rename to hugr-core/src/extension/type_def.rs diff --git a/hugr/src/extension/validate.rs b/hugr-core/src/extension/validate.rs similarity index 100% rename from hugr/src/extension/validate.rs rename to hugr-core/src/extension/validate.rs diff --git a/hugr/src/hugr.rs b/hugr-core/src/hugr.rs similarity index 100% rename from hugr/src/hugr.rs rename to hugr-core/src/hugr.rs diff --git a/hugr/src/hugr/hugrmut.rs b/hugr-core/src/hugr/hugrmut.rs similarity index 100% rename from hugr/src/hugr/hugrmut.rs rename to hugr-core/src/hugr/hugrmut.rs diff --git a/hugr/src/hugr/ident.rs b/hugr-core/src/hugr/ident.rs similarity index 100% rename from hugr/src/hugr/ident.rs rename to hugr-core/src/hugr/ident.rs diff --git a/hugr/src/hugr/rewrite.rs b/hugr-core/src/hugr/rewrite.rs similarity index 100% rename from hugr/src/hugr/rewrite.rs rename to hugr-core/src/hugr/rewrite.rs diff --git a/hugr/src/hugr/rewrite/consts.rs b/hugr-core/src/hugr/rewrite/consts.rs similarity index 100% rename from hugr/src/hugr/rewrite/consts.rs rename to hugr-core/src/hugr/rewrite/consts.rs diff --git a/hugr/src/hugr/rewrite/inline_dfg.rs b/hugr-core/src/hugr/rewrite/inline_dfg.rs similarity index 100% rename from hugr/src/hugr/rewrite/inline_dfg.rs rename to hugr-core/src/hugr/rewrite/inline_dfg.rs diff --git a/hugr/src/hugr/rewrite/insert_identity.rs b/hugr-core/src/hugr/rewrite/insert_identity.rs similarity index 100% rename from hugr/src/hugr/rewrite/insert_identity.rs rename to hugr-core/src/hugr/rewrite/insert_identity.rs diff --git a/hugr/src/hugr/rewrite/outline_cfg.rs b/hugr-core/src/hugr/rewrite/outline_cfg.rs similarity index 100% rename from hugr/src/hugr/rewrite/outline_cfg.rs rename to hugr-core/src/hugr/rewrite/outline_cfg.rs diff --git a/hugr/src/hugr/rewrite/replace.rs b/hugr-core/src/hugr/rewrite/replace.rs similarity index 100% rename from hugr/src/hugr/rewrite/replace.rs rename to hugr-core/src/hugr/rewrite/replace.rs diff --git a/hugr/src/hugr/rewrite/simple_replace.rs b/hugr-core/src/hugr/rewrite/simple_replace.rs similarity index 100% rename from hugr/src/hugr/rewrite/simple_replace.rs rename to hugr-core/src/hugr/rewrite/simple_replace.rs diff --git a/hugr/src/hugr/serialize.rs b/hugr-core/src/hugr/serialize.rs similarity index 100% rename from hugr/src/hugr/serialize.rs rename to hugr-core/src/hugr/serialize.rs diff --git a/hugr/src/hugr/serialize/test.rs b/hugr-core/src/hugr/serialize/test.rs similarity index 100% rename from hugr/src/hugr/serialize/test.rs rename to hugr-core/src/hugr/serialize/test.rs diff --git a/hugr/src/hugr/validate.rs b/hugr-core/src/hugr/validate.rs similarity index 100% rename from hugr/src/hugr/validate.rs rename to hugr-core/src/hugr/validate.rs diff --git a/hugr/src/hugr/validate/test.rs b/hugr-core/src/hugr/validate/test.rs similarity index 100% rename from hugr/src/hugr/validate/test.rs rename to hugr-core/src/hugr/validate/test.rs diff --git a/hugr/src/hugr/views.rs b/hugr-core/src/hugr/views.rs similarity index 100% rename from hugr/src/hugr/views.rs rename to hugr-core/src/hugr/views.rs diff --git a/hugr/src/hugr/views/descendants.rs b/hugr-core/src/hugr/views/descendants.rs similarity index 100% rename from hugr/src/hugr/views/descendants.rs rename to hugr-core/src/hugr/views/descendants.rs diff --git a/hugr/src/hugr/views/petgraph.rs b/hugr-core/src/hugr/views/petgraph.rs similarity index 100% rename from hugr/src/hugr/views/petgraph.rs rename to hugr-core/src/hugr/views/petgraph.rs diff --git a/hugr/src/hugr/views/render.rs b/hugr-core/src/hugr/views/render.rs similarity index 100% rename from hugr/src/hugr/views/render.rs rename to hugr-core/src/hugr/views/render.rs diff --git a/hugr/src/hugr/views/root_checked.rs b/hugr-core/src/hugr/views/root_checked.rs similarity index 100% rename from hugr/src/hugr/views/root_checked.rs rename to hugr-core/src/hugr/views/root_checked.rs diff --git a/hugr/src/hugr/views/sibling.rs b/hugr-core/src/hugr/views/sibling.rs similarity index 100% rename from hugr/src/hugr/views/sibling.rs rename to hugr-core/src/hugr/views/sibling.rs diff --git a/hugr/src/hugr/views/sibling_subgraph.rs b/hugr-core/src/hugr/views/sibling_subgraph.rs similarity index 100% rename from hugr/src/hugr/views/sibling_subgraph.rs rename to hugr-core/src/hugr/views/sibling_subgraph.rs diff --git a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_cfg.snap b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_cfg.snap similarity index 98% rename from hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_cfg.snap rename to hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_cfg.snap index ac95341fd..c07f68144 100644 --- a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_cfg.snap +++ b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_cfg.snap @@ -1,5 +1,5 @@ --- -source: hugr/src/hugr/views/tests.rs +source: hugr-core/src/hugr/views/tests.rs expression: h.dot_string() --- digraph { diff --git a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_dfg.snap b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_dfg.snap similarity index 98% rename from hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_dfg.snap rename to hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_dfg.snap index 49497fac5..a77760fe3 100644 --- a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_dfg.snap +++ b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_dfg.snap @@ -1,5 +1,5 @@ --- -source: hugr/views/tests.rs +source: hugr-core/views/tests.rs expression: h.dot_string() --- digraph { diff --git a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_empty_dfg.snap b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_empty_dfg.snap similarity index 94% rename from hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_empty_dfg.snap rename to hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_empty_dfg.snap index 61b594731..fe82c83fe 100644 --- a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_empty_dfg.snap +++ b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_empty_dfg.snap @@ -1,5 +1,5 @@ --- -source: hugr/src/hugr/views/tests.rs +source: hugr-core/src/hugr/views/tests.rs expression: h.dot_string() --- digraph { diff --git a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_cfg.snap b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_cfg.snap similarity index 94% rename from hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_cfg.snap rename to hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_cfg.snap index cb75f44ab..e70c19256 100644 --- a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_cfg.snap +++ b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_cfg.snap @@ -1,5 +1,5 @@ --- -source: hugr/src/hugr/views/tests.rs +source: hugr-core/src/hugr/views/tests.rs expression: h.mermaid_string() --- graph LR diff --git a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_dfg.snap b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_dfg.snap similarity index 90% rename from hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_dfg.snap rename to hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_dfg.snap index 5e7debf9e..0ab5fcceb 100644 --- a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_dfg.snap +++ b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_dfg.snap @@ -1,5 +1,5 @@ --- -source: src/hugr/views/tests.rs +source: hugr-core/src/hugr/views/tests.rs expression: h.mermaid_string() --- graph LR diff --git a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_empty_dfg.snap b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_empty_dfg.snap similarity index 81% rename from hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_empty_dfg.snap rename to hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_empty_dfg.snap index 7f4d2c253..ff4422889 100644 --- a/hugr/src/hugr/views/snapshots/hugr__hugr__views__tests__mmd_empty_dfg.snap +++ b/hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_empty_dfg.snap @@ -1,5 +1,5 @@ --- -source: hugr/src/hugr/views/tests.rs +source: hugr-core/src/hugr/views/tests.rs expression: h.mermaid_string() --- graph LR diff --git a/hugr/src/hugr/views/tests.rs b/hugr-core/src/hugr/views/tests.rs similarity index 100% rename from hugr/src/hugr/views/tests.rs rename to hugr-core/src/hugr/views/tests.rs diff --git a/hugr-core/src/lib.rs b/hugr-core/src/lib.rs new file mode 100644 index 000000000..a0c7b95ba --- /dev/null +++ b/hugr-core/src/lib.rs @@ -0,0 +1,31 @@ +//! Extensible, graph-based program representation with first-class support for linear types. +//! +//! This crate contains the core definitions for the HUGR representation. +//! See the [top-level crate documentation](https://docs.rs/hugr/latest/hugr/) for more information. + +// proptest-derive generates many of these warnings. +// https://github.com/rust-lang/rust/issues/120363 +// https://github.com/proptest-rs/proptest/issues/447 +#![cfg_attr(test, allow(non_local_definitions))] + +pub mod builder; +pub mod core; +pub mod extension; +pub mod hugr; +pub mod macros; +pub mod ops; +pub mod std_extensions; +pub mod types; +pub mod utils; + +pub use crate::core::{ + CircuitUnit, Direction, IncomingPort, Node, NodeIndex, OutgoingPort, Port, PortIndex, Wire, +}; +pub use crate::extension::Extension; +pub use crate::hugr::{Hugr, HugrView, SimpleReplacement}; + +#[cfg(feature = "cli")] +pub mod cli; + +#[cfg(test)] +pub mod proptest; diff --git a/hugr/src/macros.rs b/hugr-core/src/macros.rs similarity index 97% rename from hugr/src/macros.rs rename to hugr-core/src/macros.rs index e6b511daa..10dccee70 100644 --- a/hugr/src/macros.rs +++ b/hugr-core/src/macros.rs @@ -42,7 +42,7 @@ pub(crate) use impl_box_clone; /// /// Example: /// ``` -/// # use hugr::macros::type_row; +/// # use hugr::type_row; /// # use hugr::types::{FunctionType, Type, TypeRow}; /// const U: Type = Type::UNIT; /// let static_row: TypeRow = type_row![U, U]; @@ -86,7 +86,7 @@ pub use type_row; /// of a test module only. Example: /// ```rust /// # mod test { -/// # use hugr::macros::const_extension_ids; +/// # use hugr::const_extension_ids; /// const_extension_ids! { /// pub const EXT_A: ExtensionId = "A"; /// /// A doc comment diff --git a/hugr/src/ops.rs b/hugr-core/src/ops.rs similarity index 100% rename from hugr/src/ops.rs rename to hugr-core/src/ops.rs diff --git a/hugr/src/ops/constant.rs b/hugr-core/src/ops/constant.rs similarity index 100% rename from hugr/src/ops/constant.rs rename to hugr-core/src/ops/constant.rs diff --git a/hugr/src/ops/constant/custom.rs b/hugr-core/src/ops/constant/custom.rs similarity index 100% rename from hugr/src/ops/constant/custom.rs rename to hugr-core/src/ops/constant/custom.rs diff --git a/hugr/src/ops/controlflow.rs b/hugr-core/src/ops/controlflow.rs similarity index 100% rename from hugr/src/ops/controlflow.rs rename to hugr-core/src/ops/controlflow.rs diff --git a/hugr/src/ops/custom.rs b/hugr-core/src/ops/custom.rs similarity index 100% rename from hugr/src/ops/custom.rs rename to hugr-core/src/ops/custom.rs diff --git a/hugr/src/ops/dataflow.rs b/hugr-core/src/ops/dataflow.rs similarity index 100% rename from hugr/src/ops/dataflow.rs rename to hugr-core/src/ops/dataflow.rs diff --git a/hugr/src/ops/handle.rs b/hugr-core/src/ops/handle.rs similarity index 100% rename from hugr/src/ops/handle.rs rename to hugr-core/src/ops/handle.rs diff --git a/hugr/src/ops/leaf.rs b/hugr-core/src/ops/leaf.rs similarity index 100% rename from hugr/src/ops/leaf.rs rename to hugr-core/src/ops/leaf.rs diff --git a/hugr/src/ops/module.rs b/hugr-core/src/ops/module.rs similarity index 100% rename from hugr/src/ops/module.rs rename to hugr-core/src/ops/module.rs diff --git a/hugr/src/ops/tag.rs b/hugr-core/src/ops/tag.rs similarity index 100% rename from hugr/src/ops/tag.rs rename to hugr-core/src/ops/tag.rs diff --git a/hugr/src/ops/validate.rs b/hugr-core/src/ops/validate.rs similarity index 100% rename from hugr/src/ops/validate.rs rename to hugr-core/src/ops/validate.rs diff --git a/hugr/src/proptest.rs b/hugr-core/src/proptest.rs similarity index 100% rename from hugr/src/proptest.rs rename to hugr-core/src/proptest.rs diff --git a/hugr/src/std_extensions.rs b/hugr-core/src/std_extensions.rs similarity index 100% rename from hugr/src/std_extensions.rs rename to hugr-core/src/std_extensions.rs diff --git a/hugr/src/std_extensions/arithmetic/conversions.rs b/hugr-core/src/std_extensions/arithmetic/conversions.rs similarity index 100% rename from hugr/src/std_extensions/arithmetic/conversions.rs rename to hugr-core/src/std_extensions/arithmetic/conversions.rs diff --git a/hugr/src/std_extensions/arithmetic/conversions/const_fold.rs b/hugr-core/src/std_extensions/arithmetic/conversions/const_fold.rs similarity index 100% rename from hugr/src/std_extensions/arithmetic/conversions/const_fold.rs rename to hugr-core/src/std_extensions/arithmetic/conversions/const_fold.rs diff --git a/hugr/src/std_extensions/arithmetic/float_ops.rs b/hugr-core/src/std_extensions/arithmetic/float_ops.rs similarity index 100% rename from hugr/src/std_extensions/arithmetic/float_ops.rs rename to hugr-core/src/std_extensions/arithmetic/float_ops.rs diff --git a/hugr/src/std_extensions/arithmetic/float_ops/const_fold.rs b/hugr-core/src/std_extensions/arithmetic/float_ops/const_fold.rs similarity index 100% rename from hugr/src/std_extensions/arithmetic/float_ops/const_fold.rs rename to hugr-core/src/std_extensions/arithmetic/float_ops/const_fold.rs diff --git a/hugr/src/std_extensions/arithmetic/float_types.rs b/hugr-core/src/std_extensions/arithmetic/float_types.rs similarity index 100% rename from hugr/src/std_extensions/arithmetic/float_types.rs rename to hugr-core/src/std_extensions/arithmetic/float_types.rs diff --git a/hugr/src/std_extensions/arithmetic/int_ops.rs b/hugr-core/src/std_extensions/arithmetic/int_ops.rs similarity index 100% rename from hugr/src/std_extensions/arithmetic/int_ops.rs rename to hugr-core/src/std_extensions/arithmetic/int_ops.rs diff --git a/hugr/src/std_extensions/arithmetic/int_ops/const_fold.rs b/hugr-core/src/std_extensions/arithmetic/int_ops/const_fold.rs similarity index 100% rename from hugr/src/std_extensions/arithmetic/int_ops/const_fold.rs rename to hugr-core/src/std_extensions/arithmetic/int_ops/const_fold.rs diff --git a/hugr/src/std_extensions/arithmetic/int_types.rs b/hugr-core/src/std_extensions/arithmetic/int_types.rs similarity index 100% rename from hugr/src/std_extensions/arithmetic/int_types.rs rename to hugr-core/src/std_extensions/arithmetic/int_types.rs diff --git a/hugr/src/std_extensions/arithmetic/mod.rs b/hugr-core/src/std_extensions/arithmetic/mod.rs similarity index 100% rename from hugr/src/std_extensions/arithmetic/mod.rs rename to hugr-core/src/std_extensions/arithmetic/mod.rs diff --git a/hugr/src/std_extensions/collections.rs b/hugr-core/src/std_extensions/collections.rs similarity index 100% rename from hugr/src/std_extensions/collections.rs rename to hugr-core/src/std_extensions/collections.rs diff --git a/hugr/src/std_extensions/logic.rs b/hugr-core/src/std_extensions/logic.rs similarity index 100% rename from hugr/src/std_extensions/logic.rs rename to hugr-core/src/std_extensions/logic.rs diff --git a/hugr/src/types.rs b/hugr-core/src/types.rs similarity index 100% rename from hugr/src/types.rs rename to hugr-core/src/types.rs diff --git a/hugr/src/types/check.rs b/hugr-core/src/types/check.rs similarity index 100% rename from hugr/src/types/check.rs rename to hugr-core/src/types/check.rs diff --git a/hugr/src/types/custom.rs b/hugr-core/src/types/custom.rs similarity index 100% rename from hugr/src/types/custom.rs rename to hugr-core/src/types/custom.rs diff --git a/hugr/src/types/poly_func.rs b/hugr-core/src/types/poly_func.rs similarity index 100% rename from hugr/src/types/poly_func.rs rename to hugr-core/src/types/poly_func.rs diff --git a/hugr/src/types/serialize.rs b/hugr-core/src/types/serialize.rs similarity index 100% rename from hugr/src/types/serialize.rs rename to hugr-core/src/types/serialize.rs diff --git a/hugr/src/types/signature.rs b/hugr-core/src/types/signature.rs similarity index 100% rename from hugr/src/types/signature.rs rename to hugr-core/src/types/signature.rs diff --git a/hugr/src/types/type_param.rs b/hugr-core/src/types/type_param.rs similarity index 100% rename from hugr/src/types/type_param.rs rename to hugr-core/src/types/type_param.rs diff --git a/hugr/src/types/type_row.rs b/hugr-core/src/types/type_row.rs similarity index 100% rename from hugr/src/types/type_row.rs rename to hugr-core/src/types/type_row.rs diff --git a/hugr/src/utils.rs b/hugr-core/src/utils.rs similarity index 100% rename from hugr/src/utils.rs rename to hugr-core/src/utils.rs diff --git a/hugr-passes/Cargo.toml b/hugr-passes/Cargo.toml index 688d32e48..4a1bdc680 100644 --- a/hugr-passes/Cargo.toml +++ b/hugr-passes/Cargo.toml @@ -13,14 +13,14 @@ keywords = ["Quantum", "Quantinuum"] categories = ["compilers"] [dependencies] -hugr = { path = "../hugr", version = "0.4.0" } +hugr-core = { path = "../hugr-core", version = "0.0.0" } itertools = { workspace = true } lazy_static = { workspace = true } paste = { workspace = true } thiserror = { workspace = true } [features] -extension_inference = ["hugr/extension_inference"] +extension_inference = ["hugr-core/extension_inference"] [dev-dependencies] rstest = "0.19.0" diff --git a/hugr-passes/src/const_fold.rs b/hugr-passes/src/const_fold.rs index 4a124c1a4..bead78c50 100644 --- a/hugr-passes/src/const_fold.rs +++ b/hugr-passes/src/const_fold.rs @@ -5,10 +5,10 @@ use std::collections::{BTreeSet, HashMap}; use itertools::Itertools; use thiserror::Error; -use hugr::hugr::{SimpleReplacementError, ValidationError}; -use hugr::types::SumType; -use hugr::Direction; -use hugr::{ +use hugr_core::hugr::{SimpleReplacementError, ValidationError}; +use hugr_core::types::SumType; +use hugr_core::Direction; +use hugr_core::{ builder::{DFGBuilder, Dataflow, DataflowHugr}, extension::{ConstFoldResult, ExtensionRegistry}, hugr::{ diff --git a/hugr-passes/src/const_fold/test.rs b/hugr-passes/src/const_fold/test.rs index 07b881bc7..3f5eb2ba4 100644 --- a/hugr-passes/src/const_fold/test.rs +++ b/hugr-passes/src/const_fold/test.rs @@ -1,25 +1,25 @@ use crate::const_fold::constant_fold_pass; -use hugr::builder::{DFGBuilder, Dataflow, DataflowHugr}; -use hugr::extension::prelude::{sum_with_error, ConstError, ConstString, BOOL_T, STRING_TYPE}; -use hugr::extension::{ExtensionRegistry, PRELUDE}; -use hugr::ops::Value; -use hugr::std_extensions::arithmetic; -use hugr::std_extensions::arithmetic::int_ops::IntOpDef; -use hugr::std_extensions::arithmetic::int_types::{ConstInt, INT_TYPES}; -use hugr::std_extensions::logic::{self, NaryLogic, NotOp}; -use hugr::type_row; -use hugr::types::{FunctionType, Type, TypeRow}; +use hugr_core::builder::{DFGBuilder, Dataflow, DataflowHugr}; +use hugr_core::extension::prelude::{sum_with_error, ConstError, ConstString, BOOL_T, STRING_TYPE}; +use hugr_core::extension::{ExtensionRegistry, PRELUDE}; +use hugr_core::ops::Value; +use hugr_core::std_extensions::arithmetic; +use hugr_core::std_extensions::arithmetic::int_ops::IntOpDef; +use hugr_core::std_extensions::arithmetic::int_types::{ConstInt, INT_TYPES}; +use hugr_core::std_extensions::logic::{self, NaryLogic, NotOp}; +use hugr_core::type_row; +use hugr_core::types::{FunctionType, Type, TypeRow}; use rstest::rstest; use lazy_static::lazy_static; use super::*; -use hugr::builder::Container; -use hugr::ops::{OpType, UnpackTuple}; -use hugr::std_extensions::arithmetic::conversions::ConvertOpDef; -use hugr::std_extensions::arithmetic::float_ops::FloatOps; -use hugr::std_extensions::arithmetic::float_types::{ConstF64, FLOAT64_TYPE}; +use hugr_core::builder::Container; +use hugr_core::ops::{OpType, UnpackTuple}; +use hugr_core::std_extensions::arithmetic::conversions::ConvertOpDef; +use hugr_core::std_extensions::arithmetic::float_ops::FloatOps; +use hugr_core::std_extensions::arithmetic::float_types::{ConstF64, FLOAT64_TYPE}; /// Check that a hugr just loads and returns a single expected constant. pub fn assert_fully_folded(h: &Hugr, expected_value: &Value) { @@ -127,7 +127,7 @@ fn test_big() { ignore = "inference fails for test graph, it shouldn't" )] fn test_list_ops() -> Result<(), Box> { - use hugr::std_extensions::collections::{self, ListOp, ListValue}; + use hugr_core::std_extensions::collections::{self, ListOp, ListValue}; let reg = ExtensionRegistry::try_new([ PRELUDE.to_owned(), @@ -230,8 +230,8 @@ fn orphan_output() { // // We arange things so that the `or` folds away first, leaving the not // with no outputs. - use hugr::hugr::NodeType; - use hugr::ops::handle::NodeHandle; + use hugr_core::hugr::NodeType; + use hugr_core::ops::handle::NodeHandle; let mut build = DFGBuilder::new(FunctionType::new(type_row![], vec![BOOL_T])).unwrap(); let true_wire = build.add_load_value(Value::true_val()); diff --git a/hugr-passes/src/half_node.rs b/hugr-passes/src/half_node.rs index cb9c6e55e..4bacac548 100644 --- a/hugr-passes/src/half_node.rs +++ b/hugr-passes/src/half_node.rs @@ -2,12 +2,12 @@ use std::hash::Hash; use super::nest_cfgs::CfgNodeMap; -use hugr::hugr::RootTagged; +use hugr_core::hugr::RootTagged; -use hugr::ops::handle::CfgID; -use hugr::ops::{OpTag, OpTrait}; +use hugr_core::ops::handle::CfgID; +use hugr_core::ops::{OpTag, OpTrait}; -use hugr::{Direction, Node}; +use hugr_core::{Direction, Node}; /// We provide a view of a cfg where every node has at most one of /// (multiple predecessors, multiple successors). @@ -97,9 +97,9 @@ impl> CfgNodeMap for HalfNodeView mod test { use super::super::nest_cfgs::{test::*, EdgeClassifier}; use super::{HalfNode, HalfNodeView}; - use hugr::builder::BuildError; - use hugr::hugr::views::RootChecked; - use hugr::ops::handle::NodeHandle; + use hugr_core::builder::BuildError; + use hugr_core::hugr::views::RootChecked; + use hugr_core::ops::handle::NodeHandle; use itertools::Itertools; use std::collections::HashSet; diff --git a/hugr-passes/src/merge_bbs.rs b/hugr-passes/src/merge_bbs.rs index 17adc4e57..7d1cf9d52 100644 --- a/hugr-passes/src/merge_bbs.rs +++ b/hugr-passes/src/merge_bbs.rs @@ -2,16 +2,16 @@ //! and the target BB has no other predecessors. use std::collections::HashMap; -use hugr::hugr::hugrmut::HugrMut; +use hugr_core::hugr::hugrmut::HugrMut; use itertools::Itertools; -use hugr::hugr::rewrite::inline_dfg::InlineDFG; -use hugr::hugr::rewrite::replace::{NewEdgeKind, NewEdgeSpec, Replacement}; -use hugr::hugr::RootTagged; -use hugr::ops::handle::CfgID; -use hugr::ops::leaf::UnpackTuple; -use hugr::ops::{DataflowBlock, DataflowParent, Input, Output, DFG}; -use hugr::{Hugr, HugrView, Node}; +use hugr_core::hugr::rewrite::inline_dfg::InlineDFG; +use hugr_core::hugr::rewrite::replace::{NewEdgeKind, NewEdgeSpec, Replacement}; +use hugr_core::hugr::RootTagged; +use hugr_core::ops::handle::CfgID; +use hugr_core::ops::leaf::UnpackTuple; +use hugr_core::ops::{DataflowBlock, DataflowParent, Input, Output, DFG}; +use hugr_core::{Hugr, HugrView, Node}; /// Merge any basic blocks that are direct children of the specified CFG /// i.e. where a basic block B has a single successor B' whose only predecessor @@ -161,15 +161,15 @@ mod test { use itertools::Itertools; use rstest::rstest; - use hugr::builder::{CFGBuilder, DFGWrapper, Dataflow, HugrBuilder}; - use hugr::extension::prelude::{ConstUsize, PRELUDE_ID, QB_T, USIZE_T}; - use hugr::extension::{ExtensionRegistry, ExtensionSet, PRELUDE, PRELUDE_REGISTRY}; - use hugr::hugr::views::sibling::SiblingMut; - use hugr::ops::constant::Value; - use hugr::ops::handle::CfgID; - use hugr::ops::{Lift, LoadConstant, Noop, OpTrait, OpType}; - use hugr::types::{FunctionType, Type, TypeRow}; - use hugr::{const_extension_ids, type_row, Extension, Hugr, HugrView, Wire}; + use hugr_core::builder::{CFGBuilder, DFGWrapper, Dataflow, HugrBuilder}; + use hugr_core::extension::prelude::{ConstUsize, PRELUDE_ID, QB_T, USIZE_T}; + use hugr_core::extension::{ExtensionRegistry, ExtensionSet, PRELUDE, PRELUDE_REGISTRY}; + use hugr_core::hugr::views::sibling::SiblingMut; + use hugr_core::ops::constant::Value; + use hugr_core::ops::handle::CfgID; + use hugr_core::ops::{Lift, LoadConstant, Noop, OpTrait, OpType}; + use hugr_core::types::{FunctionType, Type, TypeRow}; + use hugr_core::{const_extension_ids, type_row, Extension, Hugr, HugrView, Wire}; use super::merge_basic_blocks; diff --git a/hugr-passes/src/nest_cfgs.rs b/hugr-passes/src/nest_cfgs.rs index 4231e2583..8753464d0 100644 --- a/hugr-passes/src/nest_cfgs.rs +++ b/hugr-passes/src/nest_cfgs.rs @@ -44,14 +44,14 @@ use std::hash::Hash; use itertools::Itertools; use thiserror::Error; -use hugr::hugr::rewrite::outline_cfg::OutlineCfg; -use hugr::hugr::views::sibling::SiblingMut; -use hugr::hugr::views::{HierarchyView, HugrView, SiblingGraph}; -use hugr::hugr::{hugrmut::HugrMut, Rewrite, RootTagged}; -use hugr::ops::handle::{BasicBlockID, CfgID}; -use hugr::ops::OpTag; -use hugr::ops::OpTrait; -use hugr::{Direction, Hugr, Node}; +use hugr_core::hugr::rewrite::outline_cfg::OutlineCfg; +use hugr_core::hugr::views::sibling::SiblingMut; +use hugr_core::hugr::views::{HierarchyView, HugrView, SiblingGraph}; +use hugr_core::hugr::{hugrmut::HugrMut, Rewrite, RootTagged}; +use hugr_core::ops::handle::{BasicBlockID, CfgID}; +use hugr_core::ops::OpTag; +use hugr_core::ops::OpTrait; +use hugr_core::{Direction, Hugr, Node}; /// A "view" of a CFG in a Hugr which allows basic blocks in the underlying CFG to be split into /// multiple blocks in the view (or merged together). @@ -574,17 +574,19 @@ impl EdgeClassifier { #[cfg(test)] pub(crate) mod test { use super::*; - use hugr::builder::{BuildError, CFGBuilder, Container, DataflowSubContainer, HugrBuilder}; - use hugr::extension::PRELUDE_REGISTRY; - use hugr::extension::{prelude::USIZE_T, ExtensionSet}; - - use hugr::hugr::rewrite::insert_identity::{IdentityInsertion, IdentityInsertionError}; - use hugr::hugr::views::RootChecked; - use hugr::ops::handle::{ConstID, NodeHandle}; - use hugr::ops::Value; - use hugr::type_row; - use hugr::types::{EdgeKind, FunctionType, Type}; - use hugr::utils::depth; + use hugr_core::builder::{ + BuildError, CFGBuilder, Container, DataflowSubContainer, HugrBuilder, + }; + use hugr_core::extension::PRELUDE_REGISTRY; + use hugr_core::extension::{prelude::USIZE_T, ExtensionSet}; + + use hugr_core::hugr::rewrite::insert_identity::{IdentityInsertion, IdentityInsertionError}; + use hugr_core::hugr::views::RootChecked; + use hugr_core::ops::handle::{ConstID, NodeHandle}; + use hugr_core::ops::Value; + use hugr_core::type_row; + use hugr_core::types::{EdgeKind, FunctionType, Type}; + use hugr_core::utils::depth; const NAT: Type = USIZE_T; pub fn group_by(h: HashMap) -> HashSet> { diff --git a/hugr/Cargo.toml b/hugr/Cargo.toml index 4993a8cd7..59d468014 100644 --- a/hugr/Cargo.toml +++ b/hugr/Cargo.toml @@ -23,50 +23,24 @@ path = "src/lib.rs" [features] extension_inference = [] -cli = ["dep:clap", "dep:clap-stdin"] + +# Definitions used by the `hugr` binary +_cli = ["hugr-core/cli", "dep:clap"] [dependencies] -portgraph = { workspace = true, features = ["serde", "petgraph"] } -thiserror = { workspace = true } -regex = { workspace = true } -cgmath = { workspace = true, features = ["serde"] } -num-rational = { workspace = true, features = ["serde"] } -downcast-rs = { workspace = true } -# Rc used here for Extension, but unfortunately we must turn the feature on globally -serde = { workspace = true, features = ["derive", "rc"] } -serde_yaml = { workspace = true } -typetag = { workspace = true } -smol_str = { workspace = true, features = ["serde"] } -derive_more = { workspace = true } -itertools = { workspace = true } -html-escape = { workspace = true } -bitvec = { workspace = true, features = ["serde"] } -enum_dispatch = { workspace = true } -lazy_static = { workspace = true } -petgraph = { workspace = true } -context-iterators = { workspace = true } -serde_json = { workspace = true } -delegate = { workspace = true } -paste = { workspace = true } -strum = { workspace = true } -strum_macros = { workspace = true } +hugr-core = { path = "../hugr-core", version = "0.0.0" } +hugr-passes = { path = "../hugr-passes", version = "0.1.0" } + clap = { workspace = true, features = ["derive"], optional = true } -clap-stdin = { workspace = true, optional = true } [dev-dependencies] -criterion = { workspace = true, features = ["html_reports"] } rstest = { workspace = true } -webbrowser = { workspace = true } -urlencoding = { workspace = true } -cool_asserts = { workspace = true } -insta = { workspace = true, features = ["yaml"] } -jsonschema = { workspace = true } -proptest = { workspace = true } -proptest-derive = { workspace = true } -regex-syntax = { workspace = true } assert_cmd = { workspace = true } predicates = { workspace = true } assert_fs = { workspace = true } +lazy_static = { workspace = true } +criterion = { workspace = true, features = ["html_reports"] } +serde_json = { workspace = true } [[bench]] name = "bench_main" @@ -75,4 +49,4 @@ harness = false [[bin]] name = "hugr" -required-features = ["cli"] +required-features = ["_cli"] diff --git a/hugr/src/lib.rs b/hugr/src/lib.rs index c093ba2aa..d626d2dd8 100644 --- a/hugr/src/lib.rs +++ b/hugr/src/lib.rs @@ -132,32 +132,18 @@ //! println!("{}", serialized); //! ``` -// Unstable check, may cause false positives. -// https://github.com/rust-lang/rust-clippy/issues/5112 -#![warn(clippy::debug_assert_with_mut_call)] -// proptest-derive generates many of these warnings. -// https://github.com/rust-lang/rust/issues/120363 -// https://github.com/proptest-rs/proptest/issues/447 -#![cfg_attr(test, allow(non_local_definitions))] +// These modules are re-exported as-is. If more control is needed, define a new module in this crate with the desired exports. +// The doc inline directive is necessary for renamed modules to appear as if they were defined in this crate. +pub use hugr_core::{builder, core, extension, hugr, ops, std_extensions, types, utils}; +#[doc(inline)] +pub use hugr_passes as algorithms; -pub mod builder; -pub mod core; -pub mod extension; -pub mod hugr; -pub mod macros; -pub mod ops; -pub mod std_extensions; -pub mod types; -pub mod utils; - -pub use crate::core::{ +// Top-level re-exports for convenience. +pub use hugr_core::core::{ CircuitUnit, Direction, IncomingPort, Node, NodeIndex, OutgoingPort, Port, PortIndex, Wire, }; -pub use crate::extension::Extension; -pub use crate::hugr::{Hugr, HugrView, SimpleReplacement}; - -#[cfg(feature = "cli")] -pub mod cli; +pub use hugr_core::extension::Extension; +pub use hugr_core::hugr::{Hugr, HugrView, SimpleReplacement}; -#[cfg(test)] -pub mod proptest; +// Re-export macros. +pub use hugr_core::macros::{const_extension_ids, type_row}; diff --git a/hugr/src/main.rs b/hugr/src/main.rs index 7055446fa..4c2e163ac 100644 --- a/hugr/src/main.rs +++ b/hugr/src/main.rs @@ -10,7 +10,7 @@ use hugr::std_extensions::logic::EXTENSION as LOGICS_EXTENSION; use hugr::extension::{ExtensionRegistry, PRELUDE}; use clap::Parser; -use hugr::cli::CmdLineArgs; +use hugr_core::cli::CmdLineArgs; fn main() { let opts = CmdLineArgs::parse(); diff --git a/hugr/tests/cli.rs b/hugr/tests/cli.rs index 601762081..2da86bc32 100644 --- a/hugr/tests/cli.rs +++ b/hugr/tests/cli.rs @@ -1,6 +1,7 @@ -#![cfg(feature = "cli")] +#![cfg(feature = "_cli")] use assert_cmd::Command; use assert_fs::{fixture::FileWriteStr, NamedTempFile}; +use hugr::builder::DFGBuilder; use hugr::{ builder::{Container, Dataflow, DataflowHugr}, extension::prelude::{BOOL_T, QB_T}, @@ -8,14 +9,13 @@ use hugr::{ types::FunctionType, Hugr, }; +use hugr_core::cli::VALID_PRINT; use predicates::{prelude::*, str::contains}; use rstest::{fixture, rstest}; -use hugr::builder::DFGBuilder; -use hugr::cli::VALID_PRINT; #[fixture] fn cmd() -> Command { - Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap() + Command::cargo_bin("hugr").unwrap() } #[fixture] diff --git a/release-plz.toml b/release-plz.toml index 549cd7637..d67ae9122 100644 --- a/release-plz.toml +++ b/release-plz.toml @@ -1,32 +1,36 @@ # Automatic changelog generation for rust projects [workspace] +# Disable processing the packages by default +release = false + # Open the release PR as a draft pr_draft = true # Use a custom git-cliff configuration changelog_config = "cliff.toml" -# Disable the changelog generation by default -changelog_update = false - # Enforce adding the project name in the git tag, to avoid collisions with python. # (This would normally only be enabled once there are multiple packages in the workspace) git_tag_name = "{{ package }}-v{{ version }}" - git_release_name = "{{ package }}: v{{ version }}" [[package]] name = "hugr" +release = true + +[[package]] +name = "hugr-core" +release = true -# Enable the changelog for this package -changelog_update = true +# Disabled until the first version is manually published +publish = false +github_release = false [[package]] name = "hugr-passes" - -# Enable the changelog for this package -changelog_update = true +release = true # Disabled until the first version is manually published publish = false +github_release = false