From df801ebd56748756100881c96d4508934e2577aa Mon Sep 17 00:00:00 2001 From: Douglas Wilson Date: Thu, 25 Apr 2024 14:02:47 +0100 Subject: [PATCH] Add support for PolyFuncType in testing_schema, add a few tests --- .../src/hugr/serialization/testing_hugr.py | 3 +- hugr-py/src/hugr/serialization/tys.py | 6 +- hugr/src/hugr/serialize.rs | 25 +- hugr/src/types.rs | 11 +- hugr/src/types/type_param.rs | 7 + poetry.lock | 56 +- specification/schema/hugr_schema_v1.json | 6 +- .../schema/test_hugrtype_schema_v1.json | 540 ------------------ .../schema/testing_hugr_schema_v1.json | 186 +++++- 9 files changed, 257 insertions(+), 583 deletions(-) delete mode 100644 specification/schema/test_hugrtype_schema_v1.json diff --git a/hugr-py/src/hugr/serialization/testing_hugr.py b/hugr-py/src/hugr/serialization/testing_hugr.py index bfb6b6b779..55ae59fd30 100644 --- a/hugr-py/src/hugr/serialization/testing_hugr.py +++ b/hugr-py/src/hugr/serialization/testing_hugr.py @@ -1,6 +1,6 @@ from typing import Literal, Optional from pydantic import BaseModel -from .tys import Type, SumType +from .tys import Type, SumType, PolyFuncType from .ops import Value @@ -10,6 +10,7 @@ class TestingHugr(BaseModel): version: Literal["v1"] = "v1" typ: Optional[Type] = None sum_type: Optional[SumType] = None + poly_func_type: Optional[PolyFuncType] = None value: Optional[Value] = None @classmethod diff --git a/hugr-py/src/hugr/serialization/tys.py b/hugr-py/src/hugr/serialization/tys.py index ba08348a87..dc13076141 100644 --- a/hugr-py/src/hugr/serialization/tys.py +++ b/hugr-py/src/hugr/serialization/tys.py @@ -145,7 +145,7 @@ class Array(MultiContainer): class UnitSum(BaseModel): - """Simple predicate where all variants are empty tuples.""" + """Simple sum type where all variants are empty tuples.""" s: Literal["Unit"] = "Unit" size: int @@ -255,7 +255,7 @@ def join(*bs: "TypeBound") -> "TypeBound": class Opaque(BaseModel): - """An opaque operation that can be downcasted by the extensions that define it.""" + """An opaque Type that can be downcasted by the extensions that define it.""" t: Literal["Opaque"] = "Opaque" extension: ExtensionId @@ -265,7 +265,7 @@ class Opaque(BaseModel): class Alias(BaseModel): - """TODO""" + """An Alias Type""" t: Literal["Alias"] = "Alias" bound: TypeBound diff --git a/hugr/src/hugr/serialize.rs b/hugr/src/hugr/serialize.rs index 534789c198..c67947e95e 100644 --- a/hugr/src/hugr/serialize.rs +++ b/hugr/src/hugr/serialize.rs @@ -588,13 +588,14 @@ pub mod test { } #[rstest] - #[case(Type::new_unit_sum(1))] #[case(BOOL_T)] #[case(USIZE_T)] #[case(INT_TYPES[2].clone())] #[case(Type::new_alias(crate::ops::AliasDecl::new("t", TypeBound::Any)))] #[case(Type::new_var_use(2, TypeBound::Copyable))] #[case(Type::new_tuple(type_row![BOOL_T,QB_T]))] + #[case(Type::new_sum([type_row![BOOL_T,QB_T], type_row![Type::new_unit_sum(4)]]))] + #[case(Type::new_function(FunctionType::new_endo(type_row![QB_T,BOOL_T,USIZE_T])))] fn roundtrip_type(#[case] typ: Type) { #[derive(Serialize, Deserialize, PartialEq, Debug)] struct SerTesting { @@ -604,7 +605,7 @@ pub mod test { } #[rstest] - #[case(SumType::new([type_row![],type_row![]]))] + #[case(SumType::new_unary(2))] #[case(SumType::new([type_row![USIZE_T, QB_T], type_row![]]))] fn roundtrip_sumtype(#[case] sum_type: SumType) { #[derive(Serialize, Deserialize, PartialEq, Debug)] @@ -617,6 +618,7 @@ pub mod test { #[rstest] #[case(Value::unit())] #[case(Value::true_val())] + #[case(Value::unit_sum(3,5).unwrap())] #[case(Value::extension(ConstF64::new(-1.5)))] #[case(Value::extension(ConstF64::new(0.0)))] #[case(Value::extension(ConstF64::new(-0.0)))] @@ -626,6 +628,8 @@ pub mod test { // #[case(Value::extension(ConstF64::new(std::f64::NEG_INFINITY)))] #[case(Value::extension(ConstF64::new(std::f64::MIN_POSITIVE)))] #[case(Value::sum(1,[Value::extension(ConstIntS::new(2,1).unwrap())], SumType::new([vec![], vec![INT_TYPES[2].clone()]])).unwrap())] + #[case(Value::tuple([Value::false_val(), Value::extension(ConstIntS::new(2,1).unwrap())]))] + #[case(Value::function(crate::builder::test::simple_dfg_hugr()).unwrap())] fn roundtrip_value(#[case] value: Value) { #[derive(Serialize, Deserialize, PartialEq, Debug)] struct SerTesting { @@ -633,4 +637,21 @@ pub mod test { } check_testing_roundtrip(SerTesting { value }) } + + // fn polyfunctype1() -> PolyFuncType { + // let mut extension_set = ExtensionSet::new(); + // extension_set.insert_type_var(1); + // let function_type = FunctionType::new_endo(type_row![]).with_extension_delta(extension_set); + // PolyFuncType::new([TypeParam::max_nat(), TypeParam::Extensions], function_type) + // } + // #[rstest] + // #[case(FunctionType::new_endo(type_row![]).into())] + // #[case(polyfunctype1())] + // fn roundtrip_polyfunctype(#[case] poly_func_type: PolyFuncType) { + // #[derive(Serialize, Deserialize, PartialEq, Debug)] + // struct SerTesting { + // poly_func_type: PolyFuncType, + // } + // check_testing_roundtrip(SerTesting { poly_func_type }) + // } } diff --git a/hugr/src/types.rs b/hugr/src/types.rs index ed889630b9..8fc4776dbd 100644 --- a/hugr/src/types.rs +++ b/hugr/src/types.rs @@ -153,12 +153,17 @@ impl SumType { let len: usize = rows.len(); if len <= (u8::MAX as usize) && rows.iter().all(TypeRow::is_empty) { - Self::Unit { size: len as u8 } + Self::new_unary(len as u8) } else { Self::General { rows } } } + /// New UnitSum with empty Tuple variants + pub const fn new_unary(size: u8) -> Self { + Self::Unit { size } + } + /// Report the tag'th variant, if it exists. pub fn get_variant(&self, tag: usize) -> Option<&TypeRow> { match self { @@ -312,13 +317,13 @@ impl Type { /// New UnitSum with empty Tuple variants pub const fn new_unit_sum(size: u8) -> Self { // should be the only way to avoid going through SumType::new - Self(TypeEnum::Sum(SumType::Unit { size }), TypeBound::Eq) + Self(TypeEnum::Sum(SumType::new_unary(size)), TypeBound::Eq) } /// New use (occurrence) of the type variable with specified index. /// For use in type schemes only: `bound` must match that with which the /// variable was declared (i.e. as a [TypeParam::Type]`(bound)`). - pub fn new_var_use(idx: usize, bound: TypeBound) -> Self { + pub const fn new_var_use(idx: usize, bound: TypeBound) -> Self { Self(TypeEnum::Variable(idx, bound), bound) } diff --git a/hugr/src/types/type_param.rs b/hugr/src/types/type_param.rs index 22a6dcf0d7..467e222eef 100644 --- a/hugr/src/types/type_param.rs +++ b/hugr/src/types/type_param.rs @@ -124,12 +124,19 @@ impl From for TypeParam { } } +impl From for TypeParam { + fn from(bound: UpperBound) -> Self { + Self::BoundedNat { bound } + } +} + impl From for TypeArg { fn from(ty: Type) -> Self { Self::Type { ty } } } + /// A statically-known argument value to an operation. #[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize, serde::Serialize)] #[non_exhaustive] diff --git a/poetry.lock b/poetry.lock index bc824a84fd..13d25cede0 100644 --- a/poetry.lock +++ b/poetry.lock @@ -184,38 +184,38 @@ files = [ [[package]] name = "mypy" -version = "1.9.0" +version = "1.10.0" description = "Optional static typing for Python" optional = false python-versions = ">=3.8" files = [ - {file = "mypy-1.9.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:f8a67616990062232ee4c3952f41c779afac41405806042a8126fe96e098419f"}, - {file = "mypy-1.9.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d357423fa57a489e8c47b7c85dfb96698caba13d66e086b412298a1a0ea3b0ed"}, - {file = "mypy-1.9.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:49c87c15aed320de9b438ae7b00c1ac91cd393c1b854c2ce538e2a72d55df150"}, - {file = "mypy-1.9.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:48533cdd345c3c2e5ef48ba3b0d3880b257b423e7995dada04248725c6f77374"}, - {file = "mypy-1.9.0-cp310-cp310-win_amd64.whl", hash = "sha256:4d3dbd346cfec7cb98e6cbb6e0f3c23618af826316188d587d1c1bc34f0ede03"}, - {file = "mypy-1.9.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:653265f9a2784db65bfca694d1edd23093ce49740b2244cde583aeb134c008f3"}, - {file = "mypy-1.9.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:3a3c007ff3ee90f69cf0a15cbcdf0995749569b86b6d2f327af01fd1b8aee9dc"}, - {file = "mypy-1.9.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2418488264eb41f69cc64a69a745fad4a8f86649af4b1041a4c64ee61fc61129"}, - {file = "mypy-1.9.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:68edad3dc7d70f2f17ae4c6c1b9471a56138ca22722487eebacfd1eb5321d612"}, - {file = "mypy-1.9.0-cp311-cp311-win_amd64.whl", hash = "sha256:85ca5fcc24f0b4aeedc1d02f93707bccc04733f21d41c88334c5482219b1ccb3"}, - {file = "mypy-1.9.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:aceb1db093b04db5cd390821464504111b8ec3e351eb85afd1433490163d60cd"}, - {file = "mypy-1.9.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:0235391f1c6f6ce487b23b9dbd1327b4ec33bb93934aa986efe8a9563d9349e6"}, - {file = "mypy-1.9.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d4d5ddc13421ba3e2e082a6c2d74c2ddb3979c39b582dacd53dd5d9431237185"}, - {file = "mypy-1.9.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:190da1ee69b427d7efa8aa0d5e5ccd67a4fb04038c380237a0d96829cb157913"}, - {file = "mypy-1.9.0-cp312-cp312-win_amd64.whl", hash = "sha256:fe28657de3bfec596bbeef01cb219833ad9d38dd5393fc649f4b366840baefe6"}, - {file = "mypy-1.9.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:e54396d70be04b34f31d2edf3362c1edd023246c82f1730bbf8768c28db5361b"}, - {file = "mypy-1.9.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:5e6061f44f2313b94f920e91b204ec600982961e07a17e0f6cd83371cb23f5c2"}, - {file = "mypy-1.9.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:81a10926e5473c5fc3da8abb04119a1f5811a236dc3a38d92015cb1e6ba4cb9e"}, - {file = "mypy-1.9.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:b685154e22e4e9199fc95f298661deea28aaede5ae16ccc8cbb1045e716b3e04"}, - {file = "mypy-1.9.0-cp38-cp38-win_amd64.whl", hash = "sha256:5d741d3fc7c4da608764073089e5f58ef6352bedc223ff58f2f038c2c4698a89"}, - {file = "mypy-1.9.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:587ce887f75dd9700252a3abbc9c97bbe165a4a630597845c61279cf32dfbf02"}, - {file = "mypy-1.9.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:f88566144752999351725ac623471661c9d1cd8caa0134ff98cceeea181789f4"}, - {file = "mypy-1.9.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:61758fabd58ce4b0720ae1e2fea5cfd4431591d6d590b197775329264f86311d"}, - {file = "mypy-1.9.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:e49499be624dead83927e70c756970a0bc8240e9f769389cdf5714b0784ca6bf"}, - {file = "mypy-1.9.0-cp39-cp39-win_amd64.whl", hash = "sha256:571741dc4194b4f82d344b15e8837e8c5fcc462d66d076748142327626a1b6e9"}, - {file = "mypy-1.9.0-py3-none-any.whl", hash = "sha256:a260627a570559181a9ea5de61ac6297aa5af202f06fd7ab093ce74e7181e43e"}, - {file = "mypy-1.9.0.tar.gz", hash = "sha256:3cc5da0127e6a478cddd906068496a97a7618a21ce9b54bde5bf7e539c7af974"}, + {file = "mypy-1.10.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:da1cbf08fb3b851ab3b9523a884c232774008267b1f83371ace57f412fe308c2"}, + {file = "mypy-1.10.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:12b6bfc1b1a66095ab413160a6e520e1dc076a28f3e22f7fb25ba3b000b4ef99"}, + {file = "mypy-1.10.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9e36fb078cce9904c7989b9693e41cb9711e0600139ce3970c6ef814b6ebc2b2"}, + {file = "mypy-1.10.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:2b0695d605ddcd3eb2f736cd8b4e388288c21e7de85001e9f85df9187f2b50f9"}, + {file = "mypy-1.10.0-cp310-cp310-win_amd64.whl", hash = "sha256:cd777b780312ddb135bceb9bc8722a73ec95e042f911cc279e2ec3c667076051"}, + {file = "mypy-1.10.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:3be66771aa5c97602f382230165b856c231d1277c511c9a8dd058be4784472e1"}, + {file = "mypy-1.10.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:8b2cbaca148d0754a54d44121b5825ae71868c7592a53b7292eeb0f3fdae95ee"}, + {file = "mypy-1.10.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1ec404a7cbe9fc0e92cb0e67f55ce0c025014e26d33e54d9e506a0f2d07fe5de"}, + {file = "mypy-1.10.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e22e1527dc3d4aa94311d246b59e47f6455b8729f4968765ac1eacf9a4760bc7"}, + {file = "mypy-1.10.0-cp311-cp311-win_amd64.whl", hash = "sha256:a87dbfa85971e8d59c9cc1fcf534efe664d8949e4c0b6b44e8ca548e746a8d53"}, + {file = "mypy-1.10.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:a781f6ad4bab20eef8b65174a57e5203f4be627b46291f4589879bf4e257b97b"}, + {file = "mypy-1.10.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:b808e12113505b97d9023b0b5e0c0705a90571c6feefc6f215c1df9381256e30"}, + {file = "mypy-1.10.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8f55583b12156c399dce2df7d16f8a5095291354f1e839c252ec6c0611e86e2e"}, + {file = "mypy-1.10.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:4cf18f9d0efa1b16478c4c129eabec36148032575391095f73cae2e722fcf9d5"}, + {file = "mypy-1.10.0-cp312-cp312-win_amd64.whl", hash = "sha256:bc6ac273b23c6b82da3bb25f4136c4fd42665f17f2cd850771cb600bdd2ebeda"}, + {file = "mypy-1.10.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:9fd50226364cd2737351c79807775136b0abe084433b55b2e29181a4c3c878c0"}, + {file = "mypy-1.10.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:f90cff89eea89273727d8783fef5d4a934be2fdca11b47def50cf5d311aff727"}, + {file = "mypy-1.10.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fcfc70599efde5c67862a07a1aaf50e55bce629ace26bb19dc17cece5dd31ca4"}, + {file = "mypy-1.10.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:075cbf81f3e134eadaf247de187bd604748171d6b79736fa9b6c9685b4083061"}, + {file = "mypy-1.10.0-cp38-cp38-win_amd64.whl", hash = "sha256:3f298531bca95ff615b6e9f2fc0333aae27fa48052903a0ac90215021cdcfa4f"}, + {file = "mypy-1.10.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:fa7ef5244615a2523b56c034becde4e9e3f9b034854c93639adb667ec9ec2976"}, + {file = "mypy-1.10.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:3236a4c8f535a0631f85f5fcdffba71c7feeef76a6002fcba7c1a8e57c8be1ec"}, + {file = "mypy-1.10.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4a2b5cdbb5dd35aa08ea9114436e0d79aceb2f38e32c21684dcf8e24e1e92821"}, + {file = "mypy-1.10.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:92f93b21c0fe73dc00abf91022234c79d793318b8a96faac147cd579c1671746"}, + {file = "mypy-1.10.0-cp39-cp39-win_amd64.whl", hash = "sha256:28d0e038361b45f099cc086d9dd99c15ff14d0188f44ac883010e172ce86c38a"}, + {file = "mypy-1.10.0-py3-none-any.whl", hash = "sha256:f8c083976eb530019175aabadb60921e73b4f45736760826aa1689dda8208aee"}, + {file = "mypy-1.10.0.tar.gz", hash = "sha256:3d087fcbec056c4ee34974da493a826ce316947485cef3901f511848e687c131"}, ] [package.dependencies] diff --git a/specification/schema/hugr_schema_v1.json b/specification/schema/hugr_schema_v1.json index 25a64c351d..ba3b0f4930 100644 --- a/specification/schema/hugr_schema_v1.json +++ b/specification/schema/hugr_schema_v1.json @@ -1,7 +1,7 @@ { "$defs": { "Alias": { - "description": "TODO", + "description": "An Alias Type", "properties": { "t": { "const": "Alias", @@ -1063,7 +1063,7 @@ "title": "OpType" }, "Opaque": { - "description": "An opaque operation that can be downcasted by the extensions that define it.", + "description": "An opaque Type that can be downcasted by the extensions that define it.", "properties": { "t": { "const": "Opaque", @@ -1628,7 +1628,7 @@ "type": "object" }, "UnitSum": { - "description": "Simple predicate where all variants are empty tuples.", + "description": "Simple sum type where all variants are empty tuples.", "properties": { "s": { "const": "Unit", diff --git a/specification/schema/test_hugrtype_schema_v1.json b/specification/schema/test_hugrtype_schema_v1.json deleted file mode 100644 index 328a36a8b2..0000000000 --- a/specification/schema/test_hugrtype_schema_v1.json +++ /dev/null @@ -1,540 +0,0 @@ -{ - "$defs": { - "Alias": { - "description": "TODO", - "properties": { - "t": { - "const": "Alias", - "default": "Alias", - "enum": [ - "Alias" - ], - "title": "T", - "type": "string" - }, - "bound": { - "$ref": "#/$defs/TypeBound" - }, - "name": { - "title": "Name", - "type": "string" - } - }, - "required": [ - "bound", - "name" - ], - "title": "Alias", - "type": "object" - }, - "Array": { - "description": "Known size array whose elements are of the same type.", - "properties": { - "ty": { - "$ref": "#/$defs/Type" - }, - "t": { - "const": "Array", - "default": "Array", - "enum": [ - "Array" - ], - "title": "T", - "type": "string" - }, - "len": { - "title": "Len", - "type": "integer" - } - }, - "required": [ - "ty", - "len" - ], - "title": "Array", - "type": "object" - }, - "BoundedNatArg": { - "properties": { - "tya": { - "const": "BoundedNat", - "default": "BoundedNat", - "enum": [ - "BoundedNat" - ], - "title": "Tya", - "type": "string" - }, - "n": { - "title": "N", - "type": "integer" - } - }, - "required": [ - "n" - ], - "title": "BoundedNatArg", - "type": "object" - }, - "CustomTypeArg": { - "properties": { - "typ": { - "title": "Typ", - "type": "null" - }, - "value": { - "title": "Value", - "type": "string" - } - }, - "required": [ - "typ", - "value" - ], - "title": "CustomTypeArg", - "type": "object" - }, - "ExtensionSet": { - "anyOf": [ - { - "items": { - "type": "string" - }, - "type": "array" - }, - { - "type": "null" - } - ], - "default": null, - "description": "A set of extensions ids.", - "title": "ExtensionSet" - }, - "ExtensionsArg": { - "properties": { - "tya": { - "const": "Extensions", - "default": "Extensions", - "enum": [ - "Extensions" - ], - "title": "Tya", - "type": "string" - }, - "es": { - "$ref": "#/$defs/ExtensionSet" - } - }, - "required": [ - "es" - ], - "title": "ExtensionsArg", - "type": "object" - }, - "FunctionType": { - "description": "A graph encoded as a value. It contains a concrete signature and a set of required resources.", - "properties": { - "t": { - "const": "G", - "default": "G", - "enum": [ - "G" - ], - "title": "T", - "type": "string" - }, - "input": { - "items": { - "$ref": "#/$defs/Type" - }, - "title": "Input", - "type": "array" - }, - "output": { - "items": { - "$ref": "#/$defs/Type" - }, - "title": "Output", - "type": "array" - }, - "extension_reqs": { - "$ref": "#/$defs/ExtensionSet" - } - }, - "required": [ - "input", - "output" - ], - "title": "FunctionType", - "type": "object" - }, - "GeneralSum": { - "description": "General sum type that explicitly stores the types of the variants.", - "properties": { - "s": { - "const": "General", - "default": "General", - "enum": [ - "General" - ], - "title": "S", - "type": "string" - }, - "rows": { - "items": { - "items": { - "$ref": "#/$defs/Type" - }, - "type": "array" - }, - "title": "Rows", - "type": "array" - } - }, - "required": [ - "rows" - ], - "title": "GeneralSum", - "type": "object" - }, - "Opaque": { - "description": "An opaque operation that can be downcasted by the extensions that define it.", - "properties": { - "t": { - "const": "Opaque", - "default": "Opaque", - "enum": [ - "Opaque" - ], - "title": "T", - "type": "string" - }, - "extension": { - "title": "Extension", - "type": "string" - }, - "id": { - "title": "Id", - "type": "string" - }, - "args": { - "items": { - "$ref": "#/$defs/TypeArg" - }, - "title": "Args", - "type": "array" - }, - "bound": { - "$ref": "#/$defs/TypeBound" - } - }, - "required": [ - "extension", - "id", - "args", - "bound" - ], - "title": "Opaque", - "type": "object" - }, - "OpaqueArg": { - "properties": { - "tya": { - "const": "Opaque", - "default": "Opaque", - "enum": [ - "Opaque" - ], - "title": "Tya", - "type": "string" - }, - "arg": { - "$ref": "#/$defs/CustomTypeArg" - } - }, - "required": [ - "arg" - ], - "title": "OpaqueArg", - "type": "object" - }, - "Qubit": { - "description": "A qubit.", - "properties": { - "t": { - "const": "Q", - "default": "Q", - "enum": [ - "Q" - ], - "title": "T", - "type": "string" - } - }, - "title": "Qubit", - "type": "object" - }, - "SequenceArg": { - "properties": { - "tya": { - "const": "Sequence", - "default": "Sequence", - "enum": [ - "Sequence" - ], - "title": "Tya", - "type": "string" - }, - "args": { - "items": { - "$ref": "#/$defs/TypeArg" - }, - "title": "Args", - "type": "array" - } - }, - "required": [ - "args" - ], - "title": "SequenceArg", - "type": "object" - }, - "SumType": { - "properties": { - "t": { - "const": "Sum", - "default": "Sum", - "enum": [ - "Sum" - ], - "title": "T", - "type": "string" - }, - "st": { - "$ref": "#/$defs/SumTypeBase" - } - }, - "required": [ - "st" - ], - "title": "SumType", - "type": "object" - }, - "SumTypeBase": { - "discriminator": { - "mapping": { - "General": "#/$defs/GeneralSum", - "Unit": "#/$defs/UnitSum" - }, - "propertyName": "s" - }, - "oneOf": [ - { - "$ref": "#/$defs/UnitSum" - }, - { - "$ref": "#/$defs/GeneralSum" - } - ], - "title": "SumTypeBase" - }, - "Type": { - "description": "A HUGR type.", - "discriminator": { - "mapping": { - "Alias": "#/$defs/Alias", - "Array": "#/$defs/Array", - "G": "#/$defs/FunctionType", - "I": "#/$defs/USize", - "Opaque": "#/$defs/Opaque", - "Q": "#/$defs/Qubit", - "Sum": "#/$defs/SumType", - "V": "#/$defs/Variable" - }, - "propertyName": "t" - }, - "oneOf": [ - { - "$ref": "#/$defs/Qubit" - }, - { - "$ref": "#/$defs/Variable" - }, - { - "$ref": "#/$defs/USize" - }, - { - "$ref": "#/$defs/FunctionType" - }, - { - "$ref": "#/$defs/Array" - }, - { - "$ref": "#/$defs/SumType" - }, - { - "$ref": "#/$defs/Opaque" - }, - { - "$ref": "#/$defs/Alias" - } - ], - "title": "Type" - }, - "TypeArg": { - "description": "A type argument.", - "discriminator": { - "mapping": { - "BoundedNat": "#/$defs/BoundedNatArg", - "Extensions": "#/$defs/ExtensionsArg", - "Opaque": "#/$defs/OpaqueArg", - "Sequence": "#/$defs/SequenceArg", - "Type": "#/$defs/TypeTypeArg" - }, - "propertyName": "tya" - }, - "oneOf": [ - { - "$ref": "#/$defs/TypeTypeArg" - }, - { - "$ref": "#/$defs/BoundedNatArg" - }, - { - "$ref": "#/$defs/OpaqueArg" - }, - { - "$ref": "#/$defs/SequenceArg" - }, - { - "$ref": "#/$defs/ExtensionsArg" - } - ], - "title": "TypeArg" - }, - "TypeBound": { - "enum": [ - "E", - "C", - "A" - ], - "title": "TypeBound", - "type": "string" - }, - "TypeTypeArg": { - "properties": { - "tya": { - "const": "Type", - "default": "Type", - "enum": [ - "Type" - ], - "title": "Tya", - "type": "string" - }, - "ty": { - "$ref": "#/$defs/Type" - } - }, - "required": [ - "ty" - ], - "title": "TypeTypeArg", - "type": "object" - }, - "USize": { - "description": "Unsigned integer size type.", - "properties": { - "t": { - "const": "I", - "default": "I", - "enum": [ - "I" - ], - "title": "T", - "type": "string" - } - }, - "title": "USize", - "type": "object" - }, - "UnitSum": { - "description": "Simple predicate where all variants are empty tuples.", - "properties": { - "s": { - "const": "Unit", - "default": "Unit", - "enum": [ - "Unit" - ], - "title": "S", - "type": "string" - }, - "size": { - "title": "Size", - "type": "integer" - } - }, - "required": [ - "size" - ], - "title": "UnitSum", - "type": "object" - }, - "Variable": { - "description": "A type variable identified by an index into the array of TypeParams.", - "properties": { - "t": { - "const": "V", - "default": "V", - "enum": [ - "V" - ], - "title": "T", - "type": "string" - }, - "i": { - "title": "I", - "type": "integer" - }, - "b": { - "$ref": "#/$defs/TypeBound" - } - }, - "required": [ - "i", - "b" - ], - "title": "Variable", - "type": "object" - } - }, - "description": "A serializable representation of a Hugr Type. Intended for testing only.", - "properties": { - "typ": { - "anyOf": [ - { - "$ref": "#/$defs/Type" - }, - { - "$ref": "#/$defs/SumTypeBase" - } - ], - "title": "Typ" - }, - "version": { - "const": "v1", - "default": "v1", - "enum": [ - "v1" - ], - "title": "Version", - "type": "string" - } - }, - "required": [ - "typ" - ], - "title": "HugrType", - "type": "object" -} \ No newline at end of file diff --git a/specification/schema/testing_hugr_schema_v1.json b/specification/schema/testing_hugr_schema_v1.json index 223bf3f459..dfaec239b1 100644 --- a/specification/schema/testing_hugr_schema_v1.json +++ b/specification/schema/testing_hugr_schema_v1.json @@ -1,7 +1,7 @@ { "$defs": { "Alias": { - "description": "TODO", + "description": "An Alias Type", "properties": { "t": { "const": "Alias", @@ -76,6 +76,35 @@ "title": "BoundedNatArg", "type": "object" }, + "BoundedNatParam": { + "properties": { + "tp": { + "const": "BoundedNat", + "default": "BoundedNat", + "enum": [ + "BoundedNat" + ], + "title": "Tp", + "type": "string" + }, + "bound": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "title": "Bound" + } + }, + "required": [ + "bound" + ], + "title": "BoundedNatParam", + "type": "object" + }, "CustomTypeArg": { "properties": { "typ": { @@ -243,8 +272,29 @@ "title": "GeneralSum", "type": "object" }, + "ListParam": { + "properties": { + "tp": { + "const": "List", + "default": "List", + "enum": [ + "List" + ], + "title": "Tp", + "type": "string" + }, + "param": { + "$ref": "#/$defs/TypeParam" + } + }, + "required": [ + "param" + ], + "title": "ListParam", + "type": "object" + }, "Opaque": { - "description": "An opaque operation that can be downcasted by the extensions that define it.", + "description": "An opaque Type that can be downcasted by the extensions that define it.", "properties": { "t": { "const": "Opaque", @@ -304,6 +354,48 @@ "title": "OpaqueArg", "type": "object" }, + "OpaqueParam": { + "properties": { + "tp": { + "const": "Opaque", + "default": "Opaque", + "enum": [ + "Opaque" + ], + "title": "Tp", + "type": "string" + }, + "ty": { + "$ref": "#/$defs/Opaque" + } + }, + "required": [ + "ty" + ], + "title": "OpaqueParam", + "type": "object" + }, + "PolyFuncType": { + "description": "A polymorphic type scheme, i.e. of a FuncDecl, FuncDefn or OpDef. (Nodes/operations in the Hugr are not polymorphic.)", + "properties": { + "params": { + "items": { + "$ref": "#/$defs/TypeParam" + }, + "title": "Params", + "type": "array" + }, + "body": { + "$ref": "#/$defs/FunctionType" + } + }, + "required": [ + "params", + "body" + ], + "title": "PolyFuncType", + "type": "object" + }, "Qubit": { "description": "A qubit.", "properties": { @@ -420,6 +512,31 @@ "title": "TaggedSumType", "type": "object" }, + "TupleParam": { + "properties": { + "tp": { + "const": "Tuple", + "default": "Tuple", + "enum": [ + "Tuple" + ], + "title": "Tp", + "type": "string" + }, + "params": { + "items": { + "$ref": "#/$defs/TypeParam" + }, + "title": "Params", + "type": "array" + } + }, + "required": [ + "params" + ], + "title": "TupleParam", + "type": "object" + }, "TupleValue": { "description": "A constant tuple value.", "properties": { @@ -530,6 +647,37 @@ "title": "TypeBound", "type": "string" }, + "TypeParam": { + "description": "A type parameter.", + "discriminator": { + "mapping": { + "BoundedNat": "#/$defs/BoundedNatParam", + "List": "#/$defs/ListParam", + "Opaque": "#/$defs/OpaqueParam", + "Tuple": "#/$defs/TupleParam", + "Type": "#/$defs/TypeTypeParam" + }, + "propertyName": "tp" + }, + "oneOf": [ + { + "$ref": "#/$defs/TypeTypeParam" + }, + { + "$ref": "#/$defs/BoundedNatParam" + }, + { + "$ref": "#/$defs/OpaqueParam" + }, + { + "$ref": "#/$defs/ListParam" + }, + { + "$ref": "#/$defs/TupleParam" + } + ], + "title": "TypeParam" + }, "TypeTypeArg": { "properties": { "tya": { @@ -551,6 +699,27 @@ "title": "TypeTypeArg", "type": "object" }, + "TypeTypeParam": { + "properties": { + "tp": { + "const": "Type", + "default": "Type", + "enum": [ + "Type" + ], + "title": "Tp", + "type": "string" + }, + "b": { + "$ref": "#/$defs/TypeBound" + } + }, + "required": [ + "b" + ], + "title": "TypeTypeParam", + "type": "object" + }, "USize": { "description": "Unsigned integer size type.", "properties": { @@ -568,7 +737,7 @@ "type": "object" }, "UnitSum": { - "description": "Simple predicate where all variants are empty tuples.", + "description": "Simple sum type where all variants are empty tuples.", "properties": { "s": { "const": "Unit", @@ -678,6 +847,17 @@ ], "default": null }, + "poly_func_type": { + "anyOf": [ + { + "$ref": "#/$defs/PolyFuncType" + }, + { + "type": "null" + } + ], + "default": null + }, "value": { "anyOf": [ {