Skip to content

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Add @might_produce macro #198

wants to merge 8 commits into from

Conversation

penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Aug 19, 2025

This PR introduces a macro to generate a superset of the Libtask.might_produce methods needed for a function f that might contain a produce call. For example, for a function

function f(x::Int, y::Int)
    produce(x + y)
end

instead of writing

Libtask.might_produce(::Type{<:Tuple{typeof(f),Int,Int}}) = true

you can just write

Libtask.@might_produce(f)

This works for functions with multiple methods and keyword arguments.

See #197 for the original motivation.

@penelopeysm penelopeysm requested a review from mhauru August 19, 2025 11:48
Copy link

Libtask.jl documentation for PR #198 is available at:
https://TuringLang.github.io/Libtask.jl/previews/PR198/

@penelopeysm penelopeysm changed the title Add @might_produce_kwargs macro Add @might_produce macro Aug 19, 2025
In v0.40 (or earlier?), TracedModel was moved from essential to
src/mcmc/particle_mcmc.jl.
@penelopeysm
Copy link
Member Author

penelopeysm commented Aug 19, 2025

CI failures

The AdvancedPS "integration test" is failing, because AdvancedPS CI itself is failing, because TuringLang/SSMProblems.jl#108

The benchmark test is failing because this is the first time it's ever been run with the new version of Turing that supports it. A lot of the code in there is not even updated for the current version of Libtask. It needs to be updated, but I'd rather not do it in this PR.

The rest are Julia 1.12.

Comment on lines +394 to +395
function $(Libtask).might_produce(::Type{<:Tuple{typeof($(esc(f))),Vararg}})
return true
Copy link
Member Author

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 f with any positional arguments might produce'. This is not necessarily true because some methods of f might produce and 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.

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.

1 participant