From 1ed42e942d7369165f12c33b30a6300b457e4100 Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Fri, 22 Dec 2023 13:30:18 +0000 Subject: [PATCH 1/3] feat: Custom const for ERROR_TYPE (#756) --- src/extension/prelude.rs | 66 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/src/extension/prelude.rs b/src/extension/prelude.rs index f96046ba8..b411c3667 100644 --- a/src/extension/prelude.rs +++ b/src/extension/prelude.rs @@ -137,12 +137,11 @@ pub fn new_array_op(element_ty: Type, size: u64) -> LeafOp { .into() } +/// The custom type for Errors. +pub const ERROR_CUSTOM_TYPE: CustomType = + CustomType::new_simple(ERROR_TYPE_NAME, PRELUDE_ID, TypeBound::Eq); /// Unspecified opaque error type. -pub const ERROR_TYPE: Type = Type::new_extension(CustomType::new_simple( - ERROR_TYPE_NAME, - PRELUDE_ID, - TypeBound::Eq, -)); +pub const ERROR_TYPE: Type = Type::new_extension(ERROR_CUSTOM_TYPE); /// The string name of the error type. pub const ERROR_TYPE_NAME: SmolStr = SmolStr::new_inline("error"); @@ -191,6 +190,48 @@ impl KnownTypeConst for ConstUsize { const TYPE: CustomType = USIZE_CUSTOM_T; } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] +/// Structure for holding constant usize values. +pub struct ConstError { + /// Integer tag/signal for the error. + pub signal: u32, + /// Error message. + pub message: String, +} + +impl ConstError { + /// Define a new error value. + pub fn new(signal: u32, message: impl ToString) -> Self { + Self { + signal, + message: message.to_string(), + } + } +} + +#[typetag::serde] +impl CustomConst for ConstError { + fn name(&self) -> SmolStr { + format!("ConstError({:?}, {:?})", self.signal, self.message).into() + } + + fn check_custom_type(&self, typ: &CustomType) -> Result<(), CustomCheckFailure> { + self.check_known_type(typ) + } + + fn equal_consts(&self, other: &dyn CustomConst) -> bool { + crate::values::downcast_equal_consts(self, other) + } + + fn extension_reqs(&self) -> ExtensionSet { + ExtensionSet::singleton(&PRELUDE_ID) + } +} + +impl KnownTypeConst for ConstError { + const TYPE: CustomType = ERROR_CUSTOM_TYPE; +} + #[cfg(test)] mod test { use crate::{ @@ -219,7 +260,7 @@ mod test { } #[test] - /// Test building a HUGR involving a new_array operation. + /// test the prelude error type. fn test_error_type() { let ext_def = PRELUDE .get_type(&ERROR_TYPE_NAME) @@ -229,5 +270,18 @@ mod test { let ext_type = Type::new_extension(ext_def); assert_eq!(ext_type, ERROR_TYPE); + + let error_val = ConstError::new(2, "my message"); + + assert_eq!(error_val.name(), "ConstError(2, \"my message\")"); + + assert!(error_val.check_custom_type(&ERROR_CUSTOM_TYPE).is_ok()); + + assert_eq!( + error_val.extension_reqs(), + ExtensionSet::singleton(&PRELUDE_ID) + ); + assert!(error_val.equal_consts(&ConstError::new(2, "my message"))); + assert!(!error_val.equal_consts(&ConstError::new(3, "my message"))); } } From 4607d64151072ae453a31f49c7cf72a4002e1ca0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Jan 2024 08:53:44 +0000 Subject: [PATCH 2/3] chore(deps): update delegate requirement from 0.11.0 to 0.12.0 (#760) Updates the requirements on [delegate](https://github.com/kobzol/rust-delegate) to permit the latest version.
Changelog

Sourced from delegate's changelog.

0.12.0 (22. 12. 2023)

  • Add new #[newtype] function parameter modifier (#64). Implemented by Techassi

  • Allow passing arbitrary attributes to delegation segments:

impl Foo {
  delegate! {
    #[inline(always)]
    to self.0 { ... }
  }
}

0.11.0 (4. 12. 2023)

  • Allow delegating an associated function (not just a method).
struct A {}
impl A {
    fn foo(a: u32) -> u32 {
        a + 1
    }
}

struct B; impl B { delegate! { to A { fn foo(a: u32) -> u32; } } }

0.10.0 (29. 6. 2023)

  • Allow specifying certain attributes (e.g. #[into] or #[unwrap]) on delegated segments. The attribute will then be applied to all methods in that segment (unless it is overwritten on the method itself).
delegate! {
  #[unwrap]
  to self.inner {
    fn foo(&self) -> u32; // calls self.inner.foo().unwrap()
    fn bar(&self) -> u32; // calls self.inner.bar().unwrap()
  }
}
  • Add new #[unwrap] method modifier. Adding it on top of a delegated method will cause the generated code to .unwrap() the result.
</tr></table>

... (truncated)

Commits

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b1acc0bd4..ccff53f61 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,7 @@ lazy_static = "1.4.0" petgraph = { version = "0.6.3", default-features = false } context-iterators = "0.2.0" serde_json = "1.0.97" -delegate = "0.11.0" +delegate = "0.12.0" rustversion = "1.0.14" paste = "1.0" strum = "0.25.0" From 0edee65a5cab1ae03b72f0da1d9cbbad89df797b Mon Sep 17 00:00:00 2001 From: Luca Mondada <72734770+lmondada@users.noreply.github.com> Date: Tue, 2 Jan 2024 09:52:53 +0000 Subject: [PATCH 3/3] chore!: hike MSRV to 1.75 (#761) --- .github/workflows/ci.yml | 4 ++-- Cargo.toml | 2 +- README.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f895bc87c..5514dedee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,13 +56,13 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - rust: ['1.70', stable, beta, nightly] + rust: ['1.75', stable, beta, nightly] # workaround to ignore non-stable tests when running the merge queue checks # see: https://github.community/t/how-to-conditionally-include-exclude-items-in-matrix-eg-based-on-branch/16853/6 isMerge: - ${{ github.event_name == 'merge_group' }} exclude: - - rust: '1.70' + - rust: '1.75' isMerge: true - rust: beta isMerge: true diff --git a/Cargo.toml b/Cargo.toml index ccff53f61..ea4861062 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ description = "Hierarchical Unified Graph Representation" #categories = [] # TODO edition = "2021" -rust-version = "1.70" +rust-version = "1.75" [lib] # Using different names for the lib and for the package is supported, but may be confusing. diff --git a/README.md b/README.md index 91ab2c617..14adf32ed 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,6 @@ See [DEVELOPMENT.md](DEVELOPMENT.md) for instructions on setting up the developm This project is licensed under Apache License, Version 2.0 ([LICENSE][] or http://www.apache.org/licenses/LICENSE-2.0). [build_status]: https://github.com/CQCL/hugr/workflows/Continuous%20integration/badge.svg?branch=main - [msrv]: https://img.shields.io/badge/rust-1.70.0%2B-blue.svg + [msrv]: https://img.shields.io/badge/rust-1.75.0%2B-blue.svg [codecov]: https://img.shields.io/codecov/c/gh/CQCL/hugr?logo=codecov [LICENSE]: LICENCE