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

try adding FunctionTypeVarArgs #1062

Closed
wants to merge 45 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7b242ac
Refactor: break out fn valid_row for validating a TypeRow
acl-cqc Jan 10, 2024
ba05010
Type::{validate,substitute}_in_row, {Substitution,SubstValues}::apply…
acl-cqc Jan 10, 2024
59c5854
[test] types.rs::construct - also validate
acl-cqc Jan 12, 2024
72b4fb2
[tests] poly_func.rs: test row variables
acl-cqc Jan 12, 2024
2cf1e7f
[test] validate Hugr passing around Function of unknown arity
acl-cqc Jan 12, 2024
8899806
[tests]Validation prevents row variables being used in node signatures
acl-cqc Jan 12, 2024
e1f1825
Simplify default apply_typevar_in_row
acl-cqc Jan 12, 2024
1074093
Separate TypeEnum::RowVariable
acl-cqc Jan 12, 2024
4291848
Merge remote-tracking branch 'origin/main' into feat/row_typevar
acl-cqc Apr 15, 2024
98c75a2
Doc updates - no DeBruijn, ref OpDef vs FuncDefn
acl-cqc Apr 15, 2024
b918bee
Remove unused test setup changes
acl-cqc Apr 15, 2024
a096f1a
Merge remote-tracking branch 'origin/main' into feat/row_typevar
acl-cqc May 9, 2024
4b0e23f
Combine Type::substitute(_in_row), doc, add TODOs
acl-cqc May 9, 2024
a0aba20
FunctionType/PolyFuncType validate_varargs (fixed-len not reqd)
acl-cqc May 9, 2024
bd0689f
Type::validate(=>_1type), fix TypeParam to call validate_in_row
acl-cqc May 10, 2024
72f4b98
{subst,valid}_row => TypeRow::{substitute,validate_var_len}
acl-cqc May 10, 2024
d9653aa
Normalize representation of row variable as TypeArg; extend check_typ…
acl-cqc May 10, 2024
15bf177
Test bad schema, test can't fit row variable into type hole
acl-cqc May 10, 2024
bc11c68
Extend validation tests using eval+parallel
acl-cqc May 10, 2024
f39373b
And extend no_outer_row_variables to include unconnected out'port's o…
acl-cqc May 10, 2024
bd39303
comments re. canonicalization, tests
acl-cqc May 10, 2024
ed64d12
clippy
acl-cqc May 11, 2024
d02c9c0
single_type_seq -> seq1ty
acl-cqc May 11, 2024
50b9c85
Merge remote-tracking branch 'origin/main' into feat/row_typevar
acl-cqc May 11, 2024
742ab55
Combine helpers giving extension_with_eval_parallel
acl-cqc May 12, 2024
ce72762
Add RowVar to serialization/tys.py
acl-cqc May 12, 2024
c556a8a
Regenerate schema
acl-cqc May 12, 2024
7214cbc
Really regenerate schema (after poetry install)
acl-cqc May 12, 2024
ce28154
Use Vec<TypeArg> .into() -> TypeArg
acl-cqc May 14, 2024
0e4b232
Add TypeParam::new_list
acl-cqc May 14, 2024
5b39b9c
rowparam() -> rowp.clone()
acl-cqc May 14, 2024
9ae2255
new_row_var => new_row_var_use, some cleanups using .into()
acl-cqc May 14, 2024
412ec08
squash! Add TypeParam::new_list
acl-cqc May 14, 2024
34ed4c9
Fix apply_row_var...TODO cover this
acl-cqc May 14, 2024
85d1969
check_type_arg_rv: improve comment
acl-cqc May 14, 2024
3cf333d
Remove rowvar_in_list using TypeParam::contains
acl-cqc May 14, 2024
2929135
Add Type::row_var_bound
acl-cqc May 14, 2024
0afdaf9
Remove check_type_arg_rv
acl-cqc May 14, 2024
5a8bf88
Use Type .into() -> TypeArg more
acl-cqc May 14, 2024
2e53529
Extend comment that TypeArg::Variable's are not row-vars
acl-cqc May 14, 2024
ed09ae6
type_row.rs: comment ...Variable]*s*
acl-cqc May 14, 2024
8c93c9d
Add check_type_arg tests as rstest cases
acl-cqc May 14, 2024
8811e1a
More tests! (giving up on rstest)
acl-cqc May 14, 2024
d728714
Add a couple of PolyFuncType-serialization tests
acl-cqc May 14, 2024
5ec995f
try adding FunctionTypeVarArgs
doug-q May 16, 2024
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
Prev Previous commit
Next Next commit
Normalize representation of row variable as TypeArg; extend check_typ…
…e_arg
  • Loading branch information
acl-cqc committed May 10, 2024
commit d9653aa406359b732ece5a6b51b1c51211ea82a5
36 changes: 34 additions & 2 deletions hugr/src/types/type_param.rs
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ 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`]
@@ -217,6 +218,12 @@ impl TypeArg {
TypeParam::Type { b } => TypeArg::Type {
ty: Type::new_var_use(idx, b),
},
TypeParam::List { param: bx } if matches!(*bx, TypeParam::Type { .. }) => {
let TypeParam::Type { b } = *bx else { panic!() };
TypeArg::Type {
ty: Type::new_row_var(idx, b),
}
}
TypeParam::Extensions => TypeArg::Extensions {
es: ExtensionSet::type_var(idx),
},
@@ -326,6 +333,23 @@ impl CustomTypeArg {

/// Checks a [TypeArg] is as expected for a [TypeParam]
pub fn check_type_arg(arg: &TypeArg, param: &TypeParam) -> Result<(), TypeArgError> {
check_type_arg_rv(arg, param, false)
}

fn check_type_arg_rv(
arg: &TypeArg,
param: &TypeParam,
allow_rowvars: bool,
) -> Result<(), TypeArgError> {
// allow_row_vars only applies if we are checking against values allowed inside a list
// (where the row variable could stand for *several* elements)
debug_assert!(!allow_rowvars || matches!(param, TypeParam::Type { .. }));
fn rowvar_in_list(ty: &Type, list_elem: &TypeParam) -> bool {
let TypeParam::Type { b } = list_elem else {
return false;
};
matches!(ty.0, TypeEnum::RowVariable(_, _)) && b.contains(ty.least_upper_bound())
}
match (arg, param) {
(
TypeArg::Variable {
@@ -334,13 +358,21 @@ pub fn check_type_arg(arg: &TypeArg, param: &TypeParam) -> Result<(), TypeArgErr
_,
) if param.contains(cached_decl) => Ok(()),
(TypeArg::Type { ty }, TypeParam::Type { b: bound })
if bound.contains(ty.least_upper_bound()) =>
if bound.contains(ty.least_upper_bound())
&& (allow_rowvars || !matches!(ty.0, TypeEnum::RowVariable(_, _))) =>
{
Ok(())
}
(TypeArg::Sequence { elems }, TypeParam::List { param }) => {
elems.iter().try_for_each(|arg| check_type_arg(arg, param))
let allow_rvs = matches!(&**param, TypeParam::Type { .. });
elems
.iter()
.try_for_each(|arg| check_type_arg_rv(arg, param, allow_rvs))
}
// 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 }, TypeParam::List { param }) if rowvar_in_list(ty, &**param) => Ok(()),

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