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

[WIP] Row Variables, the hard (but good?) way #903

Closed
wants to merge 60 commits into from
Closed

Conversation

acl-cqc
Copy link
Contributor

@acl-cqc acl-cqc commented Apr 2, 2024

  • Add RowVarOrType, used instead of Type in places where row variables are permitted
  • Add TypeRowVarLen (via common TypeRowBase), FuncTypeVarLen (via common FuncTypeBase) and PolyFuncVarLen(via common PolyFuncBase).
  • Function types in the type hierarchy can have variable arity; OpDefs can have variable arity; nodes (even with type variables) must have fixed arity
  • A few awkward cases of extra .into() or non-working Default::default() might be better
  • TypeRowElem seems badly placed and/or named - ideas welcome? There are also visibility issues.
  • Not nearly enough tests

Is it worth it??

  • It's a big change
  • But, once all the relevant classes/types had been defined (the three pairs listed above in naming) pretty much everything did just drop neatly into place.
  • However, +400 lines!! And that's without enough tests....
  • See what you think....the hacky version feat!: Allow "Row Variables" declared as List<Type> #804 might be more appealing now!!

after all, we never have fn foo<T>(x: impl Into<TypeRowBase<T>>) so no need to parameterize over that
@acl-cqc acl-cqc requested a review from aborgna-q April 2, 2024 08:36
@aborgna-q aborgna-q added this to the v0.3.0 milestone Apr 2, 2024
Copy link

codecov bot commented Apr 10, 2024

Codecov Report

Attention: Patch coverage is 81.46965% with 58 lines in your changes are missing coverage. Please review.

Project coverage is 85.39%. Comparing base (d98fb79) to head (34bd13b).

Files Patch % Lines
hugr/src/types.rs 50.94% 26 Missing ⚠️
hugr/src/types/serialize.rs 50.00% 11 Missing ⚠️
hugr/src/types/poly_func.rs 53.84% 6 Missing ⚠️
hugr/src/types/signature.rs 92.59% 4 Missing and 2 partials ⚠️
hugr/src/hugr/validate/test.rs 86.84% 1 Missing and 4 partials ⚠️
hugr/src/types/type_row.rs 95.45% 2 Missing ⚠️
hugr/src/extension/op_def.rs 93.75% 0 Missing and 1 partial ⚠️
hugr/src/types/check.rs 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #903      +/-   ##
==========================================
- Coverage   85.49%   85.39%   -0.11%     
==========================================
  Files          78       78              
  Lines       14220    14398     +178     
  Branches    14220    14398     +178     
==========================================
+ Hits        12158    12295     +137     
- Misses       1428     1461      +33     
- Partials      634      642       +8     
Flag Coverage Δ
rust 85.39% <81.46%> (-0.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -399,20 +400,38 @@ impl<'a> Substitution<'a> {
arg.clone()
}

fn apply_rowvar(&self, idx: usize, _bound: TypeBound) -> Vec<RowVarOrType> {
fn flatten(ta: &TypeArg) -> Vec<RowVarOrType> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to allow instantiating a TypeParam::List with something like [USIZE, var, BOOL] where var is itself a List....I'm not sure all cases here are necessary, and such an instantiation won't actually validate, so more to do here.

@doug-q
Copy link
Collaborator

doug-q commented Apr 11, 2024

I prefer #804 to this. Although I do agree that the approach here is more correct, it complicates the api to no benefit for uses that are "downstream" from any polymorphism.

@ss2165 ss2165 removed this from the v0.3.0 milestone Apr 12, 2024
@acl-cqc
Copy link
Contributor Author

acl-cqc commented Apr 15, 2024

I prefer #804 to this. Although I do agree that the approach here is more correct, it complicates the api to no benefit for uses that are "downstream" from any polymorphism.

Fair. TBH I think the main benefit of this way is that I am a lot more confident that it is (at least mostly) correct!...

@doug-q
Copy link
Collaborator

doug-q commented Apr 15, 2024

Another option is to parameterise instead by a const bool (defaulting to false) which determines whether row variables are allowed. Perhaps this would strike a balance between the correctness-by-construction here and the simplicity of the other PR.

@acl-cqc
Copy link
Contributor Author

acl-cqc commented May 13, 2024

Let's go with #804

@acl-cqc acl-cqc closed this May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants