Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Provide docs for array ops, fix bad doc for HugrView::poly_func_type #2021

Merged
merged 6 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions hugr-core/src/hugr/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,8 @@ pub trait HugrView: HugrInternals {
self.root_type().inner_function_type()
}

/// Returns the function type defined by this HUGR.
///
/// For HUGRs with a [`DataflowParent`][crate::ops::DataflowParent] root
/// operation, report the signature of the inner dataflow sibling graph.
///
/// For HUGRS with a [`FuncDecl`][crate::ops::FuncDecl] or
/// [`FuncDefn`][crate::ops::FuncDefn] root operation, report the signature
/// of the function.
///
/// Otherwise, returns `None`.
/// Returns the function type defined by this HUGR, i.e. `Some` iff the root is
/// a [`FuncDecl`][crate::ops::FuncDecl] or [`FuncDefn`][crate::ops::FuncDefn].
fn poly_func_type(&self) -> Option<PolyFuncType> {
match self.root_type() {
OpType::FuncDecl(decl) => Some(decl.signature.clone()),
Expand Down
23 changes: 22 additions & 1 deletion hugr-core/src/std_extensions/collections/array/array_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,36 @@ use super::{array_type, array_type_def, ARRAY_TYPENAME};

/// Array operation definitions.
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, EnumIter, IntoStaticStr, EnumString)]
#[allow(non_camel_case_types, missing_docs)]
#[allow(non_camel_case_types)]
#[non_exhaustive]
pub enum ArrayOpDef {
/// Makes a new array, given distinct inputs equal to its length:
/// `new_array<SIZE><elemty>: (elemty)^SIZE -> array<SIZE, elemty>`
/// where `SIZE` must be statically known (not a variable)
new_array,
/// Copies an element out of the array ([TypeBound::Copyable] elements only):
/// `get<size,elemty>: array<size, elemty>, index -> option<elemty>`
get,
/// Exchanges an element of the array with an external value:
/// `set<size, elemty>: array<size, elemty>, index, elemty -> either(elemty, array | elemty, array)`
/// tagged for failure/success respectively
set,
/// Exchanges the elements at two indices within the array:
/// `swap<size, elemty>: array<size, elemty>, index, index -> either(array, array)`
/// tagged for failure/success respectively
swap,
/// Separates the leftmost element from the rest of the array:
/// `pop_left<SIZE><elemty>: array<SIZE, elemty> -> Option<elemty, array<SIZE-1, elemty>>`
/// where `SIZE` must be known statically (not a variable).
/// `None` is returned if the input array was size 0.
pop_left,
/// Separates the rightmost element from the rest of the array.
/// `pop_right<SIZE><elemty>: array<SIZE, elemty> -> Option<elemty, array<SIZE-1, elemty>>`
/// where `SIZE` must be known statically (not a variable).
/// `None` is returned if the input array was size 0.
pop_right,
/// Allows discarding a 0-element array of linear type.
/// `discard_empty<elemty>: array<0, elemty> -> ` (no outputs)
discard_empty,
}

Expand Down
Loading