Skip to content

fix: Fix the grammar for constant function terms #2139

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
43 changes: 21 additions & 22 deletions .github/workflows/ci-rs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- main
pull_request:
branches:
- '**'
- "**"
merge_group:
types: [checks_requested]
workflow_dispatch: {}
Expand All @@ -25,7 +25,6 @@ env:
LLVM_VERSION: "14.0"
LLVM_FEATURE_NAME: "14-0"


jobs:
# Check if changes were made to the relevant files.
# Always returns true if running on the default branch, to ensure all changes are thoroughly checked.
Expand All @@ -43,25 +42,25 @@ jobs:
model: ${{ steps.filter.outputs.model == 'true' || steps.override.outputs.out == 'true' }}
llvm: ${{ steps.filter.outputs.llvm == 'true' || steps.override.outputs.out == 'true' }}
steps:
- uses: actions/checkout@v4
- name: Override label
id: override
run: |
echo "Label contains run-ci-checks: $OVERRIDE_LABEL"
if [ "$OVERRIDE_LABEL" == "true" ]; then
echo "Overriding due to label 'run-ci-checks'"
echo "out=true" >> $GITHUB_OUTPUT
elif [ "$DEFAULT_BRANCH" == "true" ]; then
echo "Overriding due to running on the default branch"
echo "out=true" >> $GITHUB_OUTPUT
fi
env:
OVERRIDE_LABEL: ${{ github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'run-ci-checks') }}
DEFAULT_BRANCH: ${{ github.ref_name == github.event.repository.default_branch }}
- uses: dorny/paths-filter@v3
id: filter
with:
filters: .github/change-filters.yml
- uses: actions/checkout@v4
- name: Override label
id: override
run: |
echo "Label contains run-ci-checks: $OVERRIDE_LABEL"
if [ "$OVERRIDE_LABEL" == "true" ]; then
echo "Overriding due to label 'run-ci-checks'"
echo "out=true" >> $GITHUB_OUTPUT
elif [ "$DEFAULT_BRANCH" == "true" ]; then
echo "Overriding due to running on the default branch"
echo "out=true" >> $GITHUB_OUTPUT
fi
env:
OVERRIDE_LABEL: ${{ github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'run-ci-checks') }}
DEFAULT_BRANCH: ${{ github.ref_name == github.event.repository.default_branch }}
- uses: dorny/paths-filter@v3
id: filter
with:
filters: .github/change-filters.yml

check:
needs: changes
Expand Down Expand Up @@ -109,7 +108,7 @@ jobs:
- name: Override criterion with the CodSpeed harness
run: cargo add --dev codspeed-criterion-compat --rename criterion --package hugr
- name: Build benchmarks
run: cargo codspeed build --profile bench --features extension_inference,declarative,model_unstable,llvm,llvm-test
run: cargo codspeed build --profile bench --features extension_inference,declarative,llvm,llvm-test
- name: Run benchmarks
uses: CodSpeedHQ/action@v3
with:
Expand Down
4 changes: 1 addition & 3 deletions hugr-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ workspace = true
[features]
extension_inference = []
declarative = ["serde_yaml"]
model_unstable = ["hugr-model"]
zstd = ["dep:zstd"]

[lib]
bench = false

[[test]]
name = "model"
required-features = ["model_unstable"]

[dependencies]
hugr-model = { version = "0.19.0", path = "../hugr-model", optional = true }
hugr-model = { version = "0.19.0", path = "../hugr-model" }

cgmath = { workspace = true, features = ["serde"] }
delegate = { workspace = true }
Expand Down
20 changes: 8 additions & 12 deletions hugr-core/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
![](/hugr/assets/hugr_logo.svg)

hugr-core
===============
# hugr-core

[![build_status][]](https://github.com/CQCL/hugr/actions)
[![crates][]](https://crates.io/crates/hugr-core)
Expand All @@ -21,9 +20,6 @@ Please read the [API documentation here][].
Not enabled by default.
- `declarative`:
Experimental support for declaring extensions in YAML files, support is limited.
- `model_unstable`
Import and export from the representation defined in the `hugr-model` crate.
Unstable and subject to change. Not enabled by default.

## Recent Changes

Expand All @@ -38,10 +34,10 @@ See [DEVELOPMENT.md](https://github.com/CQCL/hugr/blob/main/DEVELOPMENT.md) for

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
[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
33 changes: 1 addition & 32 deletions hugr-core/src/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ use std::io::Write;
#[allow(unused_imports)]
use itertools::Itertools as _;

#[cfg(feature = "model_unstable")]
use crate::import::ImportError;

/// Read a HUGR envelope from a reader.
Expand Down Expand Up @@ -197,19 +196,16 @@ pub enum EnvelopeError {
source: PackageEncodingError,
},
/// Error importing a HUGR from a hugr-model payload.
#[cfg(feature = "model_unstable")]
ModelImport {
/// The source error.
source: ImportError,
},
/// Error reading a HUGR model payload.
#[cfg(feature = "model_unstable")]
ModelRead {
/// The source error.
source: hugr_model::v0::binary::ReadError,
},
/// Error writing a HUGR model payload.
#[cfg(feature = "model_unstable")]
ModelWrite {
/// The source error.
source: hugr_model::v0::binary::WriteError,
Expand All @@ -225,17 +221,9 @@ fn read_impl(
match header.format {
#[allow(deprecated)]
EnvelopeFormat::PackageJson => Ok(Package::from_json_reader(payload, registry)?),
#[cfg(feature = "model_unstable")]
EnvelopeFormat::Model | EnvelopeFormat::ModelWithExtensions => {
decode_model(payload, registry, header.format)
}
#[cfg(not(feature = "model_unstable"))]
EnvelopeFormat::Model | EnvelopeFormat::ModelWithExtensions => {
Err(EnvelopeError::FormatUnsupported {
format: header.format,
feature: Some("model_unstable"),
})
}
}
}

Expand All @@ -246,7 +234,6 @@ fn read_impl(
/// - `extension_registry`: An extension registry with additional extensions to use when
/// decoding the HUGR, if they are not already included in the package.
/// - `format`: The format of the payload.
#[cfg(feature = "model_unstable")]
fn decode_model(
mut stream: impl BufRead,
extension_registry: &ExtensionRegistry,
Expand Down Expand Up @@ -286,22 +273,13 @@ fn write_impl(
match config.format {
#[allow(deprecated)]
EnvelopeFormat::PackageJson => package.to_json_writer(writer)?,
#[cfg(feature = "model_unstable")]
EnvelopeFormat::Model | EnvelopeFormat::ModelWithExtensions => {
encode_model(writer, package, config.format)?
}
#[cfg(not(feature = "model_unstable"))]
EnvelopeFormat::Model | EnvelopeFormat::ModelWithExtensions => {
return Err(EnvelopeError::FormatUnsupported {
format: config.format,
feature: Some("model_unstable"),
})
}
}
Ok(())
}

#[cfg(feature = "model_unstable")]
fn encode_model(
mut writer: impl Write,
package: &Package,
Expand Down Expand Up @@ -391,7 +369,6 @@ mod tests {
//#[case::empty(Package::default())] // Not currently supported
#[case::simple(simple_package())]
//#[case::multi(multi_module_package())] // Not currently supported
#[cfg(feature = "model_unstable")]
fn module_exts_roundtrip(#[case] package: Package) {
let mut buffer = Vec::new();
let config = EnvelopeConfig {
Expand All @@ -417,15 +394,7 @@ mod tests {
format: EnvelopeFormat::Model,
zstd: None,
};
let res = package.store(&mut buffer, config);

match cfg!(feature = "model_unstable") {
true => res.unwrap(),
false => {
assert_matches!(res, Err(EnvelopeError::FormatUnsupported { .. }));
return;
}
}
package.store(&mut buffer, config).unwrap();

let (decoded_config, new_package) =
read_envelope(BufReader::new(buffer.as_slice()), &PRELUDE_REGISTRY).unwrap();
Expand Down
2 changes: 0 additions & 2 deletions hugr-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
pub mod builder;
pub mod core;
pub mod envelope;
#[cfg(feature = "model_unstable")]
pub mod export;
pub mod extension;
pub mod hugr;
#[cfg(feature = "model_unstable")]
pub mod import;
pub mod macros;
pub mod ops;
Expand Down
1 change: 0 additions & 1 deletion hugr-core/src/std_extensions/arithmetic/float_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ impl std::ops::Deref for ConstF64 {

impl ConstF64 {
/// Name of the constructor for creating constant 64bit floats.
#[cfg_attr(not(feature = "model_unstable"), allow(dead_code))]
pub(crate) const CTR_NAME: &'static str = "arithmetic.float.const_f64";

/// Create a new [`ConstF64`]
Expand Down
1 change: 0 additions & 1 deletion hugr-core/src/std_extensions/arithmetic/int_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ pub struct ConstInt {

impl ConstInt {
/// Name of the constructor for creating constant integers.
#[cfg_attr(not(feature = "model_unstable"), allow(dead_code))]
pub(crate) const CTR_NAME: &'static str = "arithmetic.int.const";

/// Create a new [`ConstInt`] with a given width and unsigned value
Expand Down
1 change: 0 additions & 1 deletion hugr-core/src/std_extensions/collections/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ pub struct ArrayValue {

impl ArrayValue {
/// Name of the constructor for creating constant arrays.
#[cfg_attr(not(feature = "model_unstable"), allow(dead_code))]
pub(crate) const CTR_NAME: &'static str = "collections.array.const";

/// Create a new [CustomConst] for an array of values of type `typ`.
Expand Down
2 changes: 1 addition & 1 deletion hugr-model/src/v0/ast/hugr.pest
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ term_apply = { symbol_name | ("(" ~ symbol_name ~ term* ~ ")") }
term_list = { "[" ~ part* ~ "]" }
term_tuple = { "(" ~ "tuple" ~ part* ~ ")" }
term_list_type = { "(" ~ "list" ~ term ~ ")" }
term_const_func = { "(" ~ "fn" ~ term ~ ")" }
term_const_func = { "(" ~ "fn" ~ region ~ ")" }

part = { spliced_term | term }
spliced_term = { term ~ "..." }
5 changes: 5 additions & 0 deletions hugr-model/tests/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,8 @@ pub fn test_const() {
pub fn test_literals() {
binary_roundtrip(include_str!("fixtures/model-literals.edn"));
}

#[test]
pub fn test_const_func() {
binary_roundtrip(include_str!("fixtures/model-const-func.edn"));
}
8 changes: 8 additions & 0 deletions hugr-model/tests/fixtures/model-const-func.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(hugr 0)

(mod)

(define-alias id
(param ?t core.type)
(core.const (core.fn [?t] [?t]))
(fn (dfg [%x] [%x])))
13 changes: 13 additions & 0 deletions hugr-model/tests/snapshots/text__const_func.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
source: hugr-model/tests/text.rs
expression: "roundtrip(include_str!(\"fixtures/model-const-func.edn\"))"
---
(hugr 0)

(mod)

(define-alias
id
(param ?t core.type)
(core.const (core.fn [?t] [?t]))
(fn (dfg [%x] [%x])))
6 changes: 6 additions & 0 deletions hugr-model/tests/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ pub fn test_declarative_extensions() {
pub fn test_literals() {
insta::assert_snapshot!(roundtrip(include_str!("fixtures/model-literals.edn")))
}

#[test]
#[cfg_attr(miri, ignore)] // Opening files is not supported in (isolated) miri
pub fn test_const_func() {
insta::assert_snapshot!(roundtrip(include_str!("fixtures/model-const-func.edn")))
}
3 changes: 1 addition & 2 deletions hugr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ default = ["zstd"]

extension_inference = ["hugr-core/extension_inference"]
declarative = ["hugr-core/declarative"]
model_unstable = ["hugr-core/model_unstable", "hugr-model"]
llvm = ["hugr-llvm/llvm14-0"]
llvm-test = ["hugr-llvm/llvm14-0", "hugr-llvm/test-utils"]
zstd = ["hugr-core/zstd"]

[dependencies]
hugr-model = { path = "../hugr-model", optional = true, version = "0.19.0" }
hugr-model = { path = "../hugr-model", version = "0.19.0" }
hugr-core = { path = "../hugr-core", version = "0.15.3" }
hugr-passes = { path = "../hugr-passes", version = "0.15.3" }
hugr-llvm = { path = "../hugr-llvm", version = "0.15.3", optional = true }
Expand Down
23 changes: 9 additions & 14 deletions hugr/benches/benchmarks/hugr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ impl Serializer for JsonSer {
}
}

#[cfg(feature = "model_unstable")]
struct CapnpSer;

#[cfg(feature = "model_unstable")]
impl Serializer for CapnpSer {
fn serialize(&self, hugr: &Hugr) -> Vec<u8> {
let bump = bumpalo::Bump::new();
Expand Down Expand Up @@ -90,20 +88,17 @@ fn bench_serialization(c: &mut Criterion) {
}
group.finish();

#[cfg(feature = "model_unstable")]
{
let mut group = c.benchmark_group("circuit_roundtrip/capnp");
group.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));
for size in [0, 1, 10, 100, 1000].iter() {
group.bench_with_input(BenchmarkId::from_parameter(size), size, |b, &size| {
let h = circuit(size).0;
b.iter(|| {
black_box(roundtrip(&h, CapnpSer));
});
let mut group = c.benchmark_group("circuit_roundtrip/capnp");
group.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));
for size in [0, 1, 10, 100, 1000].iter() {
group.bench_with_input(BenchmarkId::from_parameter(size), size, |b, &size| {
let h = circuit(size).0;
b.iter(|| {
black_box(roundtrip(&h, CapnpSer));
});
}
group.finish();
});
}
group.finish();
}

criterion_group! {
Expand Down
4 changes: 1 addition & 3 deletions release-plz.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ version_group = "hugr"
[[package]]
name = "hugr-model"
release = true
# Use a separate version group while the dependency is `-unstable`,
# to avoid breaking releases of the main package.
version_group = "hugr-model"
version_group = "hugr"

[[package]]
name = "hugr-llvm"
Expand Down
Loading