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

fix: Loading custom polymorphic function defs as values #260

Merged
merged 2 commits into from
Jun 25, 2024

Conversation

mark-koch
Copy link
Collaborator

Fixes #259

Comment on lines -149 to -150
# Find the module node by walking up the hierarchy
module: Node = dfg.node
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can put the FunctionDef anywhere, no need to walk up to the module


# Finally, load the function into the local DFG
return graph.add_load_constant(def_node.out_port(0), dfg.node).out_port(0)
return graph.add_load_function(def_node.out_port(0), [], dfg.node).out_port(0)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We already monomorphised, so we can load with empty type args

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment should be included! Maybe lower the ty = ... line below you're We create a .. comment, and add "instantiate the monomorphised type of the function" to that comment

@mark-koch mark-koch requested a review from doug-q June 24, 2024 12:16
@codecov-commenter
Copy link

codecov-commenter commented Jun 24, 2024

Codecov Report

Attention: Patch coverage is 12.50000% with 7 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@b2901d8). Learn more about missing BASE report.
Report is 8 commits behind head on main.

Files Patch % Lines
guppylang/definition/custom.py 12.50% 7 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #260   +/-   ##
=======================================
  Coverage        ?   91.05%           
=======================================
  Files           ?       44           
  Lines           ?     4973           
  Branches        ?        0           
=======================================
  Hits            ?     4528           
  Misses          ?      445           
  Partials        ?        0           

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

"Encountered node that is not contained in a module."
)
module = module.parent
ty = self.ty.instantiate(type_args)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ty = self.ty.instantiate(type_args)
func_ty = self.ty.instantiate(type_args)

Copy link
Contributor

Choose a reason for hiding this comment

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

There are lots of types flying around, I think renaming this would make it easier to understand.


# Finally, load the function into the local DFG
return graph.add_load_constant(def_node.out_port(0), dfg.node).out_port(0)
return graph.add_load_function(def_node.out_port(0), [], dfg.node).out_port(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment should be included! Maybe lower the ty = ... line below you're We create a .. comment, and add "instantiate the monomorphised type of the function" to that comment

module = GuppyModule("test")
T = guppy.type_var(module, "T")

@guppy.custom(module, CustomCompiler())
Copy link
Contributor

Choose a reason for hiding this comment

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

Are users expected to write a CustomCompiler? Needs much better docs and examples, and probably more helper functions. Happy to approve without, but recommend you add an issue to flesh this out if you haven't already.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

At the moment custom compilers are an escape hatch to build Hugr stuff that can't be directly expressed in Guppy. Not sure how much we want to expose that to users in the future?

I created issue #269 for discussion

@mark-koch mark-koch requested a review from a team as a code owner June 25, 2024 09:55
@mark-koch mark-koch requested review from acl-cqc and removed request for acl-cqc June 25, 2024 09:55
@mark-koch mark-koch added this pull request to the merge queue Jun 25, 2024
Merged via the queue into main with commit d15b2f5 Jun 25, 2024
3 checks passed
@mark-koch mark-koch deleted the fix/higher-order-poly branch June 25, 2024 10:07
github-merge-queue bot pushed a commit that referenced this pull request Jul 2, 2024
🤖 I have created a release *beep* *boop*
---


## [0.6.0](v0.5.2...v0.6.0)
(2024-07-02)


### Features

* Add array type ([#258](#258))
([041c621](041c621))
* Add nat type ([#254](#254))
([a461a9d](a461a9d))
* Add result function
([#271](#271))
([792fb87](792fb87)),
closes [#270](#270)
* Allow constant nats as type args
([#255](#255))
([d706735](d706735))
* Generate constructor methods for structs
([#262](#262))
([f68d0af](f68d0af)),
closes [#261](#261)
* Return already-compiled hugrs from `GuppyModule.compile`
([#247](#247))
([9d01eae](9d01eae))
* Turn int and float into core types
([#225](#225))
([99217dc](99217dc))


### Bug Fixes

* Add missing test file
([#266](#266))
([75231fe](75231fe))
* Loading custom polymorphic function defs as values
([#260](#260))
([d15b2f5](d15b2f5)),
closes [#259](#259)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

CustomFunctionDef.load_with_args is broken when type args are nonempty
3 participants