Skip to content

Commit

Permalink
Add Type::row_var_bound
Browse files Browse the repository at this point in the history
  • Loading branch information
acl-cqc committed May 14, 2024
1 parent 3cf333d commit 2929135
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
8 changes: 8 additions & 0 deletions hugr/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,14 @@ impl Type {
TypeBound::Copyable.contains(self.least_upper_bound())
}

/// If this Type is a row variable, return its bound, otherwise None
pub fn row_var_bound(&self) -> Option<TypeBound> {
match self.0 {
TypeEnum::RowVariable(_, b) => Some(b),
_ => None,
}
}

/// Checks that this [Type] represents a single Type, not a row variable,
/// that all variables used within are in the provided list of bound variables,
/// and that for each [CustomType], the corresponding
Expand Down
16 changes: 8 additions & 8 deletions hugr/src/types/type_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::extension::ExtensionRegistry;
use crate::extension::ExtensionSet;
use crate::extension::SignatureError;

use super::TypeEnum;
use super::{check_typevar_decl, CustomType, Substitution, Type, TypeBound};

/// The upper non-inclusive bound of a [`TypeParam::BoundedNat`]
Expand Down Expand Up @@ -366,7 +365,7 @@ fn check_type_arg_rv(
) if param.contains(cached_decl) => Ok(()),
(TypeArg::Type { ty }, TypeParam::Type { b: bound })
if bound.contains(ty.least_upper_bound())
&& (allow_rowvars || !matches!(ty.0, TypeEnum::RowVariable(_, _))) =>
&& (allow_rowvars || ty.row_var_bound().is_none()) =>
{
Ok(())
}
Expand All @@ -378,12 +377,13 @@ fn check_type_arg_rv(
}
// Also allow a single "Type" to be used for a List *only* if the Type is a row variable
// (i.e., it's not really a Type, it's multiple Types)
(
TypeArg::Type {
ty: Type(TypeEnum::RowVariable(_, b), _),
},
TypeParam::List { param },
) if param.contains(&(*b).into()) => Ok(()),
(TypeArg::Type { ty }, TypeParam::List { param })
if ty
.row_var_bound()
.is_some_and(|b| param.contains(&b.into())) =>
{
Ok(())
}

(TypeArg::Sequence { elems: items }, TypeParam::Tuple { params: types }) => {
if items.len() != types.len() {
Expand Down

0 comments on commit 2929135

Please sign in to comment.