-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: Generic function definitions #618
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #618 +/- ##
==========================================
+ Coverage 92.45% 92.61% +0.15%
==========================================
Files 66 66
Lines 7465 7487 +22
==========================================
+ Hits 6902 6934 +32
+ Misses 563 553 -10 ☔ View full report in Codecov by Sentry. |
|
||
def test_id(validate): | ||
module = GuppyModule("test") | ||
T = guppy.type_var("T", module=module) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it's possible to make type_var
a method on GuppyModule
? Specifying the module like this everytime seems a bit arduous
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to keep it a guppy
method because most users will work with implicit modules. Explicit modules are only really used in tests, so imo it's fine to be more verbose there
|
||
@guppy(module) | ||
def foo(xs: array[int, n]) -> int: | ||
return int(n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be good to see versions of the call
and recurse
tests with nat variables
@@ -100,7 +105,9 @@ def check_cfg( | |||
check_rows_match(input_row, compiled[bb].sig.input_row, bb) | |||
else: | |||
# Otherwise, check the BB and enqueue its successors | |||
checked_bb = check_bb(bb, checked_cfg, input_row, return_ty, globals) | |||
checked_bb = check_bb( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not need to worry about passing along type vars that are defined in predecessor bbs? I can't quite see how that's happening
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type vars are the same in all BBs since they are introduced by the function signature. There is no way you can define new ones in a BB
🤖 I have created a release *beep* *boop* --- ## [0.13.1](v0.13.0...v0.13.1) (2024-11-15) ### Features * Generic function definitions ([#618](#618)) ([7519b90](7519b90)), closes [#522](#522) * mem_swap function for swapping two inout values ([#653](#653)) ([89e10a5](89e10a5)) ### Bug Fixes * Fix generic array functions ([#630](#630)) ([f4e5655](f4e5655)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Allow function definitions that are generic over parameters of kind
type
ornat
.GenericParamValue
AST node to represent usages of generic nat paramsn
inside function bodies. We need a way to encode this in Hugr. For now, we just emit a dummy node. See OpType to load BoundedNat / TypeArg into runtime value hugr#1629Note: Nested generic functions are not supported yet, so we don't have to worry about scoping of type params.
Closes #522