Skip to content

Commit

Permalink
feat!: Add non_exhaustive to various enums (#952)
Browse files Browse the repository at this point in the history
Mainly to `std_extensions` definitions and error enums.

This missing caused #942 to be a breaking change, since it adds new
variants to the `FloatOps` and `IntOpDef` extensions. See the failing
semver-checks in #928.
  • Loading branch information
aborgna-q committed Apr 23, 2024
1 parent efba356 commit e4217e4
Show file tree
Hide file tree
Showing 26 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions hugr/src/algorithm/nest_cfgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ impl<H: HugrMut> CfgNester<Node> for IdentityCfgMap<H> {

/// An error trying to get the blocks of a SESE (single-entry-single-exit) region
#[derive(Clone, Debug, Error)]
#[non_exhaustive]
pub enum RegionBlocksError<T> {
/// The specified exit edge did not exist in the CFG
ExitEdgeNotPresent(T, T),
Expand Down
1 change: 1 addition & 0 deletions hugr/src/builder/conditional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use thiserror::Error;
pub type CaseBuilder<B> = DFGWrapper<B, BuildHandle<CaseID>>;

#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum ConditionalBuildError {
/// Case already built.
#[error("Case {case} of Conditional node {conditional:?} has already been built.")]
Expand Down
1 change: 1 addition & 0 deletions hugr/src/extension/declarative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ struct DeclarationContext<'a> {

/// Errors that can occur while loading an extension set.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum ExtensionDeclarationError {
/// An error occurred while deserializing the extension set.
#[error("Error while parsing the extension set yaml: {0}")]
Expand Down
1 change: 1 addition & 0 deletions hugr/src/extension/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ enum Constraint {
}

#[derive(Debug, Clone, PartialEq, Error)]
#[non_exhaustive]
/// Errors which arise during unification
pub enum InferExtensionError {
#[error("Mismatched extension sets {expected} and {actual}")]
Expand Down
1 change: 1 addition & 0 deletions hugr/src/extension/simple_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use thiserror::Error;
#[derive(Debug, Error, PartialEq)]
#[error("{0}")]
#[allow(missing_docs)]
#[non_exhaustive]
pub enum OpLoadError {
#[error("Op with name {0} is not a member of this set.")]
NotMember(String),
Expand Down
1 change: 1 addition & 0 deletions hugr/src/extension/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ impl ExtensionValidator {
/// Errors that can occur while validating a Hugr.
#[derive(Debug, Clone, PartialEq, Error)]
#[allow(missing_docs)]
#[non_exhaustive]
pub enum ExtensionError {
/// Missing lift node
#[error("Extensions at target node {to:?} ({to_extensions}) exceed those at source {from:?} ({from_extensions})")]
Expand Down
1 change: 1 addition & 0 deletions hugr/src/hugr/rewrite/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct RemoveLoadConstant(pub Node);

/// Error from an [`RemoveConst`] or [`RemoveLoadConstant`] operation.
#[derive(Debug, Clone, Error, PartialEq, Eq)]
#[non_exhaustive]
pub enum RemoveError {
/// Invalid node.
#[error("Node is invalid (either not in HUGR or not correct operation).")]
Expand Down
1 change: 1 addition & 0 deletions hugr/src/hugr/rewrite/inline_dfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct InlineDFG(pub DfgID);

/// Errors from an [InlineDFG] rewrite.
#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum InlineDFGError {
/// Node to inline was not a DFG. (E.g. node has been overwritten since the DfgID originated.)
#[error("Node {0} was not a DFG")]
Expand Down
1 change: 1 addition & 0 deletions hugr/src/hugr/rewrite/insert_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl IdentityInsertion {

/// Error from an [`IdentityInsertion`] operation.
#[derive(Debug, Clone, Error, PartialEq, Eq)]
#[non_exhaustive]
pub enum IdentityInsertionError {
/// Invalid parent node.
#[error("Parent node is invalid.")]
Expand Down
1 change: 1 addition & 0 deletions hugr/src/hugr/rewrite/outline_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ impl Rewrite for OutlineCfg {

/// Errors that can occur in expressing an OutlineCfg rewrite.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum OutlineCfgError {
/// The set of blocks were not siblings
#[error("The nodes did not all have the same parent")]
Expand Down
1 change: 1 addition & 0 deletions hugr/src/hugr/rewrite/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ fn transfer_edges<'a>(

/// Error in a [`Replacement`]
#[derive(Clone, Debug, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum ReplaceError {
/// The node(s) to replace had no parent i.e. were root(s).
// (Perhaps if there is only one node to replace we should be able to?)
Expand Down
1 change: 1 addition & 0 deletions hugr/src/hugr/rewrite/simple_replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ impl Rewrite for SimpleReplacement {

/// Error from a [`SimpleReplacement`] operation.
#[derive(Debug, Clone, Error, PartialEq, Eq)]
#[non_exhaustive]
pub enum SimpleReplacementError {
/// Invalid parent node.
#[error("Parent node is invalid.")]
Expand Down
1 change: 1 addition & 0 deletions hugr/src/hugr/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct SerHugrV1 {

/// Errors that can occur while serializing a HUGR.
#[derive(Debug, Clone, PartialEq, Error)]
#[non_exhaustive]
pub enum HUGRSerializationError {
/// Unexpected hierarchy error.
#[error("Failed to attach child to parent: {0:?}.")]
Expand Down
2 changes: 2 additions & 0 deletions hugr/src/hugr/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ impl<'a, 'b> ValidationContext<'a, 'b> {
/// Errors that can occur while validating a Hugr.
#[derive(Debug, Clone, PartialEq, Error)]
#[allow(missing_docs)]
#[non_exhaustive]
pub enum ValidationError {
/// The root node of the Hugr is not a root in the hierarchy.
#[error("The root node of the Hugr {node:?} is not a root in the hierarchy.")]
Expand Down Expand Up @@ -706,6 +707,7 @@ pub enum ValidationError {
/// Errors related to the inter-graph edge validations.
#[derive(Debug, Clone, PartialEq, Error)]
#[allow(missing_docs)]
#[non_exhaustive]
pub enum InterGraphEdgeError {
/// Inter-Graph edges can only carry copyable data.
#[error("Inter-graph edges can only carry copyable data. In an inter-graph edge from {from:?} ({from_offset:?}) to {to:?} ({to_offset:?}) with type {ty:?}.")]
Expand Down
3 changes: 3 additions & 0 deletions hugr/src/hugr/views/sibling_subgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ fn has_other_edge<H: HugrView>(hugr: &H, node: Node, dir: Direction) -> bool {

/// Errors that can occur while constructing a [`SimpleReplacement`].
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum InvalidReplacement {
/// No DataflowParent root in replacement graph.
#[error("No DataflowParent root in replacement graph.")]
Expand All @@ -642,6 +643,7 @@ pub enum InvalidReplacement {

/// Errors that can occur while constructing a [`SiblingSubgraph`].
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum InvalidSubgraph {
/// The subgraph is not convex.
#[error("The subgraph is not convex.")]
Expand All @@ -659,6 +661,7 @@ pub enum InvalidSubgraph {

/// Errors that can occur while constructing a [`SiblingSubgraph`].
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum InvalidSubgraphBoundary {
/// A boundary port's node is not in the set of nodes.
#[error("(node {0:?}, port {1:?}) is in the boundary, but node {0:?} is not in the set.")]
Expand Down
2 changes: 2 additions & 0 deletions hugr/src/ops/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl PartialEq for ExtensionConst {

/// Struct for custom type check fails.
#[derive(Clone, Debug, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum CustomCheckFailure {
/// The value had a specific type that was not what was expected
#[error("Expected type: {expected} but value was of type: {found}")]
Expand All @@ -87,6 +88,7 @@ pub enum CustomCheckFailure {

/// Errors that arise from typechecking constants
#[derive(Clone, Debug, PartialEq, Error)]
#[non_exhaustive]
pub enum ConstTypeError {
/// Invalid sum type definition.
#[error("{0}")]
Expand Down
1 change: 1 addition & 0 deletions hugr/src/ops/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ pub fn resolve_opaque_op(
/// Errors that arise after loading a Hugr containing opaque ops (serialized just as their names)
/// when trying to resolve the serialized names against a registry of known Extensions.
#[derive(Clone, Debug, Error, PartialEq)]
#[non_exhaustive]
pub enum CustomOpError {
/// The Extension was found but did not contain the expected OpDef
#[error("Operation {0} not found in Extension {1}")]
Expand Down
2 changes: 2 additions & 0 deletions hugr/src/ops/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ impl ValidateOp for super::CFG {
/// Errors that can occur while checking the children of a node.
#[derive(Debug, Clone, PartialEq, Error)]
#[allow(missing_docs)]
#[non_exhaustive]
pub enum ChildrenValidationError {
/// An CFG graph has an exit operation as a non-second child.
#[error("Exit basic blocks are only allowed as the second child in a CFG graph")]
Expand Down Expand Up @@ -208,6 +209,7 @@ impl ChildrenValidationError {
/// Errors that can occur while checking the edges between children of a node.
#[derive(Debug, Clone, PartialEq, Error)]
#[allow(missing_docs)]
#[non_exhaustive]
pub enum EdgeValidationError {
/// The dataflow signature of two connected basic blocks does not match.
#[error("The dataflow signature of two connected basic blocks does not match. Output signature: {source_op:?}, input signature: {target_op:?}",
Expand Down
1 change: 1 addition & 0 deletions hugr/src/std_extensions/arithmetic/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub const EXTENSION_ID: ExtensionId = ExtensionId::new_unchecked("arithmetic.con
/// Extension for conversions between floats and integers.
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, EnumIter, IntoStaticStr, EnumString)]
#[allow(missing_docs, non_camel_case_types)]
#[non_exhaustive]
pub enum ConvertOpDef {
trunc_u,
trunc_s,
Expand Down
1 change: 1 addition & 0 deletions hugr/src/std_extensions/arithmetic/float_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub const EXTENSION_ID: ExtensionId = ExtensionId::new_unchecked("arithmetic.flo
/// Integer extension operation definitions.
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, EnumIter, IntoStaticStr, EnumString)]
#[allow(missing_docs, non_camel_case_types)]
#[non_exhaustive]
pub enum FloatOps {
feq,
fne,
Expand Down
1 change: 1 addition & 0 deletions hugr/src/std_extensions/arithmetic/int_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl ValidateJustArgs for IOValidator {
/// Integer extension operation definitions.
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, EnumIter, IntoStaticStr, EnumString)]
#[allow(missing_docs, non_camel_case_types)]
#[non_exhaustive]
pub enum IntOpDef {
iwiden_u,
iwiden_s,
Expand Down
1 change: 1 addition & 0 deletions hugr/src/std_extensions/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ fn list_and_elem_type_vars(list_type_def: &TypeDef) -> (Type, Type) {

/// A list operation
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum ListOp {
/// Pop from end of list
Pop,
Expand Down
1 change: 1 addition & 0 deletions hugr/src/std_extensions/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub const TRUE_NAME: &str = "TRUE";
/// Logic extension operation definitions.
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, EnumIter, IntoStaticStr, EnumString)]
#[allow(missing_docs)]
#[non_exhaustive]
pub enum NaryLogic {
And,
Or,
Expand Down
1 change: 1 addition & 0 deletions hugr/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub(crate) fn least_upper_bound(mut tags: impl Iterator<Item = TypeBound>) -> Ty

#[derive(Clone, PartialEq, Debug, Eq, Serialize, Deserialize)]
#[serde(tag = "s")]
#[non_exhaustive]
/// Representation of a Sum type.
/// Either store the types of the variants, or in the special (but common) case
/// of a UnitSum (sum over empty tuples), store only the size of the Sum.
Expand Down
1 change: 1 addition & 0 deletions hugr/src/types/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::ops::Const;

/// Errors that arise from typechecking constants
#[derive(Clone, Debug, PartialEq, Error)]
#[non_exhaustive]
pub enum SumTypeError {
/// The type of the variant doesn't match the type of the value.
#[error("Expected type {expected} for element {index} of variant #{tag}, but found {}", .found.const_type())]
Expand Down
1 change: 1 addition & 0 deletions hugr/src/types/type_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ pub fn check_type_args(args: &[TypeArg], params: &[TypeParam]) -> Result<(), Typ

/// Errors that can occur fitting a [TypeArg] into a [TypeParam]
#[derive(Clone, Debug, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum TypeArgError {
#[allow(missing_docs)]
/// For now, general case of a type arg not fitting a param.
Expand Down

0 comments on commit e4217e4

Please sign in to comment.