-
Couldn't load subscription status.
- Fork 10
Add @might_produce macro
#198
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
843bc83
Add `@might_produce_kwargs` macro
penelopeysm 96228ce
Add docs entry
penelopeysm 429b131
Format
penelopeysm cfb7402
Expand to cover positional args as well
penelopeysm a622dd3
rename doctest
penelopeysm b27694f
Format
penelopeysm 3e93f7a
Use function reference instead of another module
penelopeysm 73e7b68
Fix Turing performance tests
penelopeysm e4dc773
Improve macro docstring
penelopeysm fefc990
Improve warning
penelopeysm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This line is a little bit of a sledgehammer: we're basically saying, 'any invocation of
fwith any positional arguments mightproduce'. This is not necessarily true because some methods offmightproduceand some might not.But since there isn't any real downside to marking all methods are
produceable, I don't think this is a huge issue. And if someone wants to be surgical, they can still use the non-macro version.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 would guess that there's a performance downside. Maybe for both compile-time and for run-time.
I was just thinking of proposing a comment in the docstring noting this aspect, and directing the user to
might_produceif the function has many methods and they want to be performance-optimal.Also, in the future we could make a version where you could restrict the types, like
@might_produce(f(::Int,::Any)). Not in this PR though.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.
Not super important now, but would be curious to hear more about this, since I never looked closely at how it actually works.
Will do
Interestingly enough parsing a function signature in a macro is exactly what I did here so this actually feels a bit familiar 😄 agree it can be a separate thing though
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 think if
might_producereturnsfalsefor some method/functionf, the Libtask-transformed function just callsf. Whereas ifmight_producereturnstrue, I think we recurse into transformingf, which means doing all the slow reading/writing of all intermediate variables withinfas well.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.
Ah, I see, thanks :)
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 will make the warning a bit more strident then because that actually sounds non-trivial 😅