Skip to content

Commit

Permalink
PolyFuncType defaults to <true>
Browse files Browse the repository at this point in the history
  • Loading branch information
acl-cqc committed May 24, 2024
1 parent 9d9b859 commit cac4efb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
22 changes: 11 additions & 11 deletions hugr/src/extension/op_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub trait CustomSignatureFunc: Send + Sync {
arg_values: &[TypeArg],
def: &'o OpDef,
extension_registry: &ExtensionRegistry,
) -> Result<PolyFuncType<true>, SignatureError>;
) -> Result<PolyFuncType, SignatureError>;
/// The declared type parameters which require values in order for signature to
/// be computed.
fn static_params(&self) -> &[TypeParam];
Expand All @@ -37,7 +37,7 @@ pub trait SignatureFromArgs: Send + Sync {
fn compute_signature(
&self,
arg_values: &[TypeArg],
) -> Result<PolyFuncType<true>, SignatureError>;
) -> Result<PolyFuncType, SignatureError>;
/// The declared type parameters which require values in order for signature to
/// be computed.
fn static_params(&self) -> &[TypeParam];
Expand All @@ -50,7 +50,7 @@ impl<T: SignatureFromArgs> CustomSignatureFunc for T {
arg_values: &[TypeArg],
_def: &'o OpDef,
_extension_registry: &ExtensionRegistry,
) -> Result<PolyFuncType<true>, SignatureError> {
) -> Result<PolyFuncType, SignatureError> {
SignatureFromArgs::compute_signature(self, arg_values)
}

Expand Down Expand Up @@ -123,14 +123,14 @@ pub trait CustomLowerFunc: Send + Sync {
#[derive(serde::Deserialize, serde::Serialize)]
pub struct CustomValidator {
#[serde(flatten)]
poly_func: PolyFuncType<true>,
poly_func: PolyFuncType,
#[serde(skip)]
pub(crate) validate: Box<dyn ValidateTypeArgs>,
}

impl CustomValidator {
/// Encode a signature using a `PolyFuncType`
pub fn from_polyfunc(poly_func: impl Into<PolyFuncType<true>>) -> Self {
pub fn from_polyfunc(poly_func: impl Into<PolyFuncType>) -> Self {
Self {
poly_func: poly_func.into(),
validate: Default::default(),
Expand All @@ -140,7 +140,7 @@ impl CustomValidator {
/// Encode a signature using a `PolyFuncType`, with a custom function for
/// validating type arguments before returning the signature.
pub fn new_with_validator(
poly_func: impl Into<PolyFuncType<true>>,
poly_func: impl Into<PolyFuncType>,
validate: impl ValidateTypeArgs + 'static,
) -> Self {
Self {
Expand Down Expand Up @@ -189,8 +189,8 @@ impl<T: CustomSignatureFunc + 'static> From<T> for SignatureFunc {
}
}

impl From<PolyFuncType<true>> for SignatureFunc {
fn from(v: PolyFuncType<true>) -> Self {
impl From<PolyFuncType> for SignatureFunc {
fn from(v: PolyFuncType) -> Self {
Self::TypeScheme(CustomValidator::from_polyfunc(v))
}
}
Expand Down Expand Up @@ -232,7 +232,7 @@ impl SignatureFunc {
args: &[TypeArg],
exts: &ExtensionRegistry,
) -> Result<Signature, SignatureError> {
let temp: PolyFuncType<true>;
let temp: PolyFuncType;
let (pf, args) = match &self {
SignatureFunc::TypeScheme(custom) => {
custom.validate.validate(args, def, exts)?;
Expand Down Expand Up @@ -335,7 +335,7 @@ impl OpDef {
exts: &ExtensionRegistry,
var_decls: &[TypeParam],
) -> Result<(), SignatureError> {
let temp: PolyFuncType<true>; // to keep alive
let temp: PolyFuncType; // to keep alive
let (pf, args) = match &self.signature_func {
SignatureFunc::TypeScheme(ts) => (&ts.poly_func, args),
SignatureFunc::CustomFunc(custom) => {
Expand Down Expand Up @@ -548,7 +548,7 @@ mod test {
fn compute_signature(
&self,
arg_values: &[TypeArg],
) -> Result<PolyFuncType<true>, SignatureError> {
) -> Result<PolyFuncType, SignatureError> {
const TP: TypeParam = TypeParam::Type { b: TypeBound::Any };
let [TypeArg::BoundedNat { n }] = arg_values else {
return Err(SignatureError::InvalidTypeArgs);
Expand Down
6 changes: 3 additions & 3 deletions hugr/src/types/poly_func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use super::Substitution;
"params.iter().map(ToString::to_string).join(\" \")",
"body"
)]
pub struct PolyFuncType<const ROWVARS: bool> {
pub struct PolyFuncType<const ROWVARS: bool = true> {
/// The declared type parameters, i.e., these must be instantiated with
/// the same number of [TypeArg]s before the function can be called. This
/// defines the indices used by variables inside the body.
Expand Down Expand Up @@ -99,7 +99,7 @@ impl<const RV: bool> PolyFuncType<RV> {
}
}

impl PolyFuncType<true> {
impl PolyFuncType {
/// Validates this instance, checking that the types in the body are
/// wellformed with respect to the registry, and the type variables declared.
/// Allows both inputs and outputs to contain [RowVariable]s
Expand Down Expand Up @@ -135,7 +135,7 @@ pub(crate) mod test {
ExtensionRegistry::try_new([PRELUDE.to_owned(), EXTENSION.to_owned()]).unwrap();
}

impl PolyFuncType<true> {
impl PolyFuncType {
fn new_validated(
params: impl Into<Vec<TypeParam>>,
body: FunctionType,
Expand Down

0 comments on commit cac4efb

Please sign in to comment.