Skip to content

Commit

Permalink
refactor!: Bring the collections ext in line with other extension defs (
Browse files Browse the repository at this point in the history
#1469)

Refactors the list operations definition so it's easier to add new ones
(#1467), and to bring it in line with the other extension definitions.

- Make the operation enum variants `camelCase`, to match their op names.
This lets us us `strum` to auto-derive all the string conversions.
- Implemented `MakeOpDef`, `MakeRegisteredOp`,

BREAKING CHANGE: Renamed `ListOp` variants to camelCase.
`collections::EXTENSION_NAME` is now called `EXTENSION_ID`.
  • Loading branch information
aborgna-q authored Aug 27, 2024
1 parent 841f450 commit 069abd7
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 124 deletions.
6 changes: 3 additions & 3 deletions hugr-core/src/hugr/rewrite/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,21 +524,21 @@ mod test {
inputs: vec![listy.clone()].into(),
sum_rows: vec![type_row![]],
other_outputs: vec![listy.clone()].into(),
extension_delta: collections::EXTENSION_NAME.into(),
extension_delta: collections::EXTENSION_ID.into(),
},
);
let r_df1 = replacement.add_node_with_parent(
r_bb,
DFG {
signature: Signature::new(vec![listy.clone()], simple_unary_plus(intermed.clone()))
.with_extension_delta(collections::EXTENSION_NAME),
.with_extension_delta(collections::EXTENSION_ID),
},
);
let r_df2 = replacement.add_node_with_parent(
r_bb,
DFG {
signature: Signature::new(intermed, simple_unary_plus(just_list.clone()))
.with_extension_delta(collections::EXTENSION_NAME),
.with_extension_delta(collections::EXTENSION_ID),
},
);
[0, 1]
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/hugr/validate/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ fn no_polymorphic_consts() -> Result<(), Box<dyn std::error::Error>> {
PolyFuncType::new(
[BOUND],
Signature::new(vec![], vec![list_of_var.clone()])
.with_extension_delta(collections::EXTENSION_NAME),
.with_extension_delta(collections::EXTENSION_ID),
),
)?;
let empty_list = Value::extension(collections::ListValue::new_empty(Type::new_var_use(
Expand Down
Loading

0 comments on commit 069abd7

Please sign in to comment.