You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
InteractiveUtils: Fully support broadcasting expressions for code introspection macros (#58349)
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 file name to clipboardExpand all lines: NEWS.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,6 +72,7 @@ Standard library changes
72
72
#### InteractiveUtils
73
73
74
74
* Introspection utilities such as `@code_typed`, `@which` and `@edit` now accept type annotations as substitutes for values, recognizing forms such as `f(1, ::Float64, 3)` or even `sum(::Vector{T}; init = ::T) where {T<:Real}`. Type-annotated variables as in `f(val::Int; kw::Float64)` are not evaluated if the type annotation provides the necessary information, making this syntax compatible with signatures found in stacktraces ([#57909], [#58222]).
75
+
* Code introspection macros such as `@code_lowered` and `@code_typed` now have a much better support for broadcasting expressions, including broadcasting assignments of the form `x .+= f(y)` ([#58349]).
0 commit comments