Skip to content

Commit

Permalink
feat!: add collections to serialized standard extensions (#1452)
Browse files Browse the repository at this point in the history
Bonus lazy static for standard registry

BREAKING CHANGE: collections extension name made lowercase for
consistency. ("Collections" -> "collections")
  • Loading branch information
ss2165 authored Aug 21, 2024
1 parent 31b77e8 commit 6bd7d7f
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 3 deletions.
2 changes: 1 addition & 1 deletion hugr-cli/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl ExtArgs {
pub fn run_dump(&self) {
let base_dir = &self.outdir;

for (name, ext) in hugr_core::std_extensions::std_reg().into_iter() {
for (name, ext) in hugr_core::std_extensions::STD_REG.iter() {
let mut path = base_dir.clone();
for part in name.split('.') {
path.push(part);
Expand Down
2 changes: 1 addition & 1 deletion hugr-cli/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl HugrArgs {
let mut reg: ExtensionRegistry = if self.no_std {
hugr_core::extension::PRELUDE_REGISTRY.to_owned()
} else {
hugr_core::std_extensions::std_reg()
hugr_core::std_extensions::STD_REG.to_owned()
};

// register packed extensions
Expand Down
6 changes: 6 additions & 0 deletions hugr-core/src/std_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ pub fn std_reg() -> ExtensionRegistry {
arithmetic::conversions::EXTENSION.to_owned(),
arithmetic::float_ops::EXTENSION.to_owned(),
arithmetic::float_types::EXTENSION.to_owned(),
collections::EXTENSION.to_owned(),
logic::EXTENSION.to_owned(),
ptr::EXTENSION.to_owned(),
])
.unwrap()
}

lazy_static::lazy_static! {
/// Standard extension registry.
pub static ref STD_REG: ExtensionRegistry = std_reg();
}
2 changes: 1 addition & 1 deletion hugr-core/src/std_extensions/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub const POP_NAME: OpName = OpName::new_inline("pop");
/// Push operation name.
pub const PUSH_NAME: OpName = OpName::new_inline("push");
/// Reported unique name of the extension
pub const EXTENSION_NAME: ExtensionId = ExtensionId::new_unchecked("Collections");
pub const EXTENSION_NAME: ExtensionId = ExtensionId::new_unchecked("collections");
/// Extension version.
pub const VERSION: semver::Version = semver::Version::new(0, 1, 0);

Expand Down
143 changes: 143 additions & 0 deletions specification/std_extensions/collections.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"version": "0.1.0",
"name": "collections",
"extension_reqs": [],
"types": {
"List": {
"extension": "collections",
"name": "List",
"params": [
{
"tp": "Type",
"b": "A"
}
],
"description": "Generic dynamically sized list of type T.",
"bound": {
"b": "FromParams",
"indices": [
0
]
}
}
},
"values": {},
"operations": {
"pop": {
"extension": "collections",
"name": "pop",
"description": "Pop from back of list",
"signature": {
"params": [
{
"tp": "Type",
"b": "A"
}
],
"body": {
"input": [
{
"t": "Opaque",
"extension": "collections",
"id": "List",
"args": [
{
"tya": "Type",
"ty": {
"t": "V",
"i": 0,
"b": "A"
}
}
],
"bound": "A"
}
],
"output": [
{
"t": "Opaque",
"extension": "collections",
"id": "List",
"args": [
{
"tya": "Type",
"ty": {
"t": "V",
"i": 0,
"b": "A"
}
}
],
"bound": "A"
},
{
"t": "V",
"i": 0,
"b": "A"
}
],
"extension_reqs": []
}
},
"binary": false
},
"push": {
"extension": "collections",
"name": "push",
"description": "Push to back of list",
"signature": {
"params": [
{
"tp": "Type",
"b": "A"
}
],
"body": {
"input": [
{
"t": "Opaque",
"extension": "collections",
"id": "List",
"args": [
{
"tya": "Type",
"ty": {
"t": "V",
"i": 0,
"b": "A"
}
}
],
"bound": "A"
},
{
"t": "V",
"i": 0,
"b": "A"
}
],
"output": [
{
"t": "Opaque",
"extension": "collections",
"id": "List",
"args": [
{
"tya": "Type",
"ty": {
"t": "V",
"i": 0,
"b": "A"
}
}
],
"bound": "A"
}
],
"extension_reqs": []
}
},
"binary": false
}
}
}

0 comments on commit 6bd7d7f

Please sign in to comment.