Conversation
…ents `combine_broadcast_args(args::Vector, kwargs::Vector)` built both halves of the `MixedArguments` wrongly, not just the keyword half as #309 reports: - the positional half spliced the original argument expressions, which refer to the outer, un-broadcast collections rather than the per-element slots; - the keyword half called `NamedTuple{keys}(args)` on the *whole* broadcast closure tuple, whose arity is `length(positional) + length(keywords)`. Inside the broadcasted expression `args` is the varargs tail of the closure, holding positional slices first and keyword values after, so both halves are now sliced out of it by index. They are emitted as a tuple literal and a named-tuple literal, mirroring the non-broadcast `combine_args`, so `proxy_args` wraps each element individually and the halves stay a `Tuple` and a `NamedTuple` as `MixedArguments{A <: Tuple, K <: NamedTuple}` requires. Updates the two tests that pinned the buggy generated shape. Closes #309. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #327 +/- ##
==========================================
+ Coverage 90.72% 90.73% +0.01%
==========================================
Files 16 16
Lines 2263 2266 +3
==========================================
+ Hits 2053 2056 +3
Misses 210 210 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #309.
Problem
combine_broadcast_args(args::Vector, kwargs::Vector)(src/model_macro.jl:617-628) was wrong inboth halves, not just the keyword half the issue identifies:
un-broadcast collections — not the per-element slots;
NamedTuplefrom the whole closure tuple, whose arity islength(positional) + length(keywords), so the arity mismatches.Inside the broadcasted expression,
argsis the varargs tail of the closure atmodel_macro.jl:734(
do ilhs, args...), populated at:726asvcat(positional, kwarg_values)— positional slices first,keyword values after.
Change
Both halves are now sliced out of that runtime tuple by index, emitted as a tuple literal and a
named-tuple literal (mirroring the non-broadcast
combine_args) so thatproxy_argswraps each elementindividually and the two halves stay a
Tupleand aNamedTuple, asMixedArguments{A <: Tuple, K <: NamedTuple}requires:Scope: what this does and does not fix
This fixes the lowering. It does not make stochastic mixed-argument broadcasts build, because
MixedArgumentsis rejected for any node that must be materialized(
graph_engine.jl:2038) — the non-broadcast~has exactly the same limitation, so the two paths stayconsistent. Lifting that is a feature, not a bug fix, and is out of scope here.
The user-visible effect is that
z .~ sub(mu; y = sg)now reports the real, documented limitation:instead of
MethodError: no method matching tuple(::GraphPPL.VariableRef{...}).Known remaining gap (pre-existing, not addressed here)
The comma form
f(a, b = c)is still not split into positional + keyword at all.convert_to_kwargs_expressiononly converts when every argument is a keyword(
is_kwargs_expression(::Vector)requires all), sob = cstays among the positional arguments and thecall still fails with an opaque
tupleMethodError. This affects~,.~and:=alike and isindependent of this fix —
x ~ Normal(mixed(1.0, s = 2.0), 1.0)fails identically onmain.I prototyped a split here but backed it out: Julia puts
:parametersfirst in the argument AST, so anaive trailing-keyword split breaks the existing
convert_to_kwargs_expressiontest attest/model_macro_tests.jl:553. It deserves its own issue and its own careful patch. Use the explicitsemicolon form
f(a; b = c)meanwhile.Tests
"combine_broadcast_args"(
model_macro_tests.jl:1448) and the codegen baseline in"convert_tilde_expression"(Test 13). Thesepinning the wrong output is why the bug survived.
test/graph_construction_tests.jlasserting the mixed broadcast reachesthe stated
MixedArgumentslimitation rather than aMethodError, and that keyword-only broadcastsstill build.
Verified the new test fails on
mainand passes here. Full suite on Julia 1.12:259/259 test items, all passing.
🤖 Generated with Claude Code