Skip to content

Commit

Permalink
feat!: Rename collections extension to collections.list (#1764)
Browse files Browse the repository at this point in the history
In preparation to moving arrays out of the prelude (#1497), this PR
renames the `collections` extension to `collections.list`. Arrays will
then be called `collections.array`.

I renamed the related module and struct definitions as well.

BREAKING CHANGE: `collections` extension renamed to `collections.list`
  • Loading branch information
aborgna-q authored Dec 11, 2024
1 parent 66465db commit eef239f
Show file tree
Hide file tree
Showing 46 changed files with 1,075 additions and 1,080 deletions.
6 changes: 3 additions & 3 deletions hugr-core/src/extension/op_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ pub(super) mod test {
use crate::extension::{ExtensionRegistry, ExtensionSet, PRELUDE};
use crate::extension::{SignatureError, EMPTY_REG, PRELUDE_REGISTRY};
use crate::ops::OpName;
use crate::std_extensions::collections::{EXTENSION, LIST_TYPENAME};
use crate::std_extensions::collections::list;
use crate::types::type_param::{TypeArgError, TypeParam};
use crate::types::{PolyFuncTypeRV, Signature, Type, TypeArg, TypeBound, TypeRV};
use crate::{const_extension_ids, Extension};
Expand Down Expand Up @@ -636,7 +636,7 @@ pub(super) mod test {

#[test]
fn op_def_with_type_scheme() -> Result<(), Box<dyn std::error::Error>> {
let list_def = EXTENSION.get_type(&LIST_TYPENAME).unwrap();
let list_def = list::EXTENSION.get_type(&list::LIST_TYPENAME).unwrap();
const OP_NAME: OpName = OpName::new_inline("Reverse");

let ext = Extension::try_new_test_arc(EXT_ID, |ext, extension_ref| {
Expand All @@ -658,7 +658,7 @@ pub(super) mod test {
Ok(())
})?;

let reg = ExtensionRegistry::new([PRELUDE.clone(), EXTENSION.clone(), ext]);
let reg = ExtensionRegistry::new([PRELUDE.clone(), list::EXTENSION.clone(), ext]);
reg.validate()?;
let e = reg.get(&EXT_ID).unwrap();

Expand Down
16 changes: 8 additions & 8 deletions hugr-core/src/hugr/rewrite/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ mod test {
use crate::ops::dataflow::DataflowOpTrait;
use crate::ops::handle::{BasicBlockID, ConstID, NodeHandle};
use crate::ops::{self, Case, DataflowBlock, OpTag, OpType, DFG};
use crate::std_extensions::collections::{self, list_type, ListOp};
use crate::std_extensions::collections::list;
use crate::types::{Signature, Type, TypeRow};
use crate::utils::{depth, test_quantum_extension};
use crate::{type_row, Direction, Extension, Hugr, HugrView, OutgoingPort};
Expand All @@ -466,14 +466,14 @@ mod test {
#[test]
#[ignore] // FIXME: This needs a rewrite now that `pop` returns an optional value -.-'
fn cfg() -> Result<(), Box<dyn std::error::Error>> {
let reg = ExtensionRegistry::new([PRELUDE.to_owned(), collections::EXTENSION.to_owned()]);
let reg = ExtensionRegistry::new([PRELUDE.to_owned(), list::EXTENSION.to_owned()]);
reg.validate()?;
let listy = list_type(usize_t());
let pop: ExtensionOp = ListOp::pop
let listy = list::list_type(usize_t());
let pop: ExtensionOp = list::ListOp::pop
.with_type(usize_t())
.to_extension_op(&reg)
.unwrap();
let push: ExtensionOp = ListOp::push
let push: ExtensionOp = list::ListOp::push
.with_type(usize_t())
.to_extension_op(&reg)
.unwrap();
Expand Down Expand Up @@ -518,21 +518,21 @@ mod test {
inputs: vec![listy.clone()].into(),
sum_rows: vec![type_row![]],
other_outputs: vec![listy.clone()].into(),
extension_delta: collections::EXTENSION_ID.into(),
extension_delta: list::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_ID),
.with_extension_delta(list::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_ID),
.with_extension_delta(list::EXTENSION_ID),
},
);
[0, 1]
Expand Down
12 changes: 6 additions & 6 deletions hugr-core/src/hugr/validate/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,27 +555,27 @@ fn nested_typevars() -> Result<(), Box<dyn std::error::Error>> {

#[test]
fn no_polymorphic_consts() -> Result<(), Box<dyn std::error::Error>> {
use crate::std_extensions::collections;
use crate::std_extensions::collections::list;
const BOUND: TypeParam = TypeParam::Type {
b: TypeBound::Copyable,
};
let list_of_var = Type::new_extension(
collections::EXTENSION
.get_type(&collections::LIST_TYPENAME)
list::EXTENSION
.get_type(&list::LIST_TYPENAME)
.unwrap()
.instantiate(vec![TypeArg::new_var_use(0, BOUND)])?,
);
let reg = ExtensionRegistry::new([collections::EXTENSION.to_owned()]);
let reg = ExtensionRegistry::new([list::EXTENSION.to_owned()]);
reg.validate()?;
let mut def = FunctionBuilder::new(
"myfunc",
PolyFuncType::new(
[BOUND],
Signature::new(vec![], vec![list_of_var.clone()])
.with_extension_delta(collections::EXTENSION_ID),
.with_extension_delta(list::EXTENSION_ID),
),
)?;
let empty_list = Value::extension(collections::ListValue::new_empty(Type::new_var_use(
let empty_list = Value::extension(list::ListValue::new_empty(Type::new_var_use(
0,
TypeBound::Copyable,
)));
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/ops/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ mod test {
use crate::{
ops::{constant::CustomSerialized, Value},
std_extensions::arithmetic::int_types::ConstInt,
std_extensions::collections::ListValue,
std_extensions::collections::list::ListValue,
types::{SumType, Type},
};
use ::proptest::{collection::vec, prelude::*};
Expand Down
4 changes: 2 additions & 2 deletions hugr-core/src/ops/constant/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub trait CustomConst:
/// The extension(s) defining the custom constant
/// (a set to allow, say, a [List] of [USize])
///
/// [List]: crate::std_extensions::collections::LIST_TYPENAME
/// [List]: crate::std_extensions::collections::list::LIST_TYPENAME
/// [USize]: crate::extension::prelude::usize_t
fn extension_reqs(&self) -> ExtensionSet;

Expand Down Expand Up @@ -362,7 +362,7 @@ mod test {
use crate::{
extension::prelude::{usize_t, ConstUsize},
ops::{constant::custom::serialize_custom_const, Value},
std_extensions::collections::ListValue,
std_extensions::collections::list::ListValue,
};

use super::{super::OpaqueValue, CustomConst, CustomConstBoxClone, CustomSerialized};
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/std_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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(),
collections::list::EXTENSION.to_owned(),
logic::EXTENSION.to_owned(),
ptr::EXTENSION.to_owned(),
]);
Expand Down
Loading

0 comments on commit eef239f

Please sign in to comment.