Skip to content

Conversation

@serenity4
Copy link
Member

This PR includes a fix and a feature for code introspection macros (@code_typed, @code_llvm and friends but not @which, @edit, etc):

  • Fixes a bug for expressions of the form f.(x; y = 3), for which keyword arguments were not properly handled and led to an internal error.
  • Adds support for broadcasting assignments of the form x .= f(y), x .<<= f.(y, z), etc.

The way this was (and still is) implemented is by constructing a temporary function, f(x1, x2, x3, ...) = <body> and feeding that to code introspection functions. This trick doesn't apply to @which and @edit, which need to map to a single function call (we could arguably choose to target materialize/materialize!, but this behavior could be a bit surprising and difficult to support).

The switch differentiating the families of macro @code_typed/@code_llvm and @which/@edit etc was further exposed as an additional argument to gen_call_with_extracted_types and gen_call_with_extracted_types_and_kwargs, which default to the previous behavior (differentiating them based on whether their name starts with code_). The intent is to allow other macros such as Cthulhu.@descend to register themselves as code introspection macros. Quick tests indicate that it works as intended, e.g. with this PR Cthulhu supports @descend [1, 2] .+= [2, 3] (or equivalently, as added in #57909, @descend ::Vector{Int} .+= ::Vector{Int}).

I originally just went for the fix, and after some refactoring I realized the feature was very straightforward to implement.

Copy link
Member

@topolarity topolarity left a comment

Choose a reason for hiding this comment

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

The structure looks right to me, although I didn't do a close check for correct-ness

Thanks much, @serenity4 !

serenity4 added 3 commits May 24, 2025 01:08
Also includes another `supports_binding_reflection` parameter
to remove the special-cased support for `@which` reflection into
bindings.
@topolarity
Copy link
Member

CI is still green here, so I'm going to take the liberty to merge this 👍

@topolarity topolarity merged commit 602d6ee into JuliaLang:master Jun 4, 2025
7 checks passed
@serenity4 serenity4 deleted the fix-broadcast-with-kwargs branch June 4, 2025 15:26
@serenity4
Copy link
Member Author

Thanks for the review @topolarity!

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.

2 participants