Skip to content

Commit 079585e

Browse files
acl-cqchugrbot
andauthored
docs: Provide docs for array ops, fix bad doc for HugrView::poly_func_type (#2021)
Co-authored-by: hugrbot <CI_testing@quantinuum.com>
1 parent 1ad2c1b commit 079585e

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

hugr-core/src/hugr/views.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -338,16 +338,8 @@ pub trait HugrView: HugrInternals {
338338
self.root_type().inner_function_type()
339339
}
340340

341-
/// Returns the function type defined by this HUGR.
342-
///
343-
/// For HUGRs with a [`DataflowParent`][crate::ops::DataflowParent] root
344-
/// operation, report the signature of the inner dataflow sibling graph.
345-
///
346-
/// For HUGRS with a [`FuncDecl`][crate::ops::FuncDecl] or
347-
/// [`FuncDefn`][crate::ops::FuncDefn] root operation, report the signature
348-
/// of the function.
349-
///
350-
/// Otherwise, returns `None`.
341+
/// Returns the function type defined by this HUGR, i.e. `Some` iff the root is
342+
/// a [`FuncDecl`][crate::ops::FuncDecl] or [`FuncDefn`][crate::ops::FuncDefn].
351343
fn poly_func_type(&self) -> Option<PolyFuncType> {
352344
match self.root_type() {
353345
OpType::FuncDecl(decl) => Some(decl.signature.clone()),

hugr-core/src/std_extensions/collections/array/array_op.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,36 @@ use super::{array_type, array_type_def, ARRAY_TYPENAME};
2222

2323
/// Array operation definitions.
2424
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, EnumIter, IntoStaticStr, EnumString)]
25-
#[allow(non_camel_case_types, missing_docs)]
25+
#[allow(non_camel_case_types)]
2626
#[non_exhaustive]
2727
pub enum ArrayOpDef {
28+
/// Makes a new array, given distinct inputs equal to its length:
29+
/// `new_array<SIZE><elemty>: (elemty)^SIZE -> array<SIZE, elemty>`
30+
/// where `SIZE` must be statically known (not a variable)
2831
new_array,
32+
/// Copies an element out of the array ([TypeBound::Copyable] elements only):
33+
/// `get<size,elemty>: array<size, elemty>, index -> option<elemty>`
2934
get,
35+
/// Exchanges an element of the array with an external value:
36+
/// `set<size, elemty>: array<size, elemty>, index, elemty -> either(elemty, array | elemty, array)`
37+
/// tagged for failure/success respectively
3038
set,
39+
/// Exchanges the elements at two indices within the array:
40+
/// `swap<size, elemty>: array<size, elemty>, index, index -> either(array, array)`
41+
/// tagged for failure/success respectively
3142
swap,
43+
/// Separates the leftmost element from the rest of the array:
44+
/// `pop_left<SIZE><elemty>: array<SIZE, elemty> -> Option<elemty, array<SIZE-1, elemty>>`
45+
/// where `SIZE` must be known statically (not a variable).
46+
/// `None` is returned if the input array was size 0.
3247
pop_left,
48+
/// Separates the rightmost element from the rest of the array.
49+
/// `pop_right<SIZE><elemty>: array<SIZE, elemty> -> Option<elemty, array<SIZE-1, elemty>>`
50+
/// where `SIZE` must be known statically (not a variable).
51+
/// `None` is returned if the input array was size 0.
3352
pop_right,
53+
/// Allows discarding a 0-element array of linear type.
54+
/// `discard_empty<elemty>: array<0, elemty> -> ` (no outputs)
3455
discard_empty,
3556
}
3657

0 commit comments

Comments
 (0)