code_lowered
code_lowered(f, types)
Returns an array of lowered ASTs for the methods matching the given generic function and type signature.
Examples
julia> function add_numbers(x, y)
return x + y
end
julia> methods_add_numbers = code_lowered(add_numbers, Tuple{Int, Int})
2-element Vector{Any}:
$(Expr(:lambda, Any[:x, :y], Any[], Any[:(x + y)]))
$(Expr(:lambda, Any[:x, :y], Any[], Any[:(x + y)]))
julia> subtract_numbers(x, y) = x - y
subtract_numbers (generic function with 1 method)
julia> methods_subtract_numbers = code_lowered(subtract_numbers, Tuple{Int, Int})
1-element Vector{Any}:
$(Expr(:lambda, Any[:x, :y], Any[], Any[:(x - y)]))
In the above examples, code_lowered
is used to retrieve the lowered ASTs (Abstract Syntax Trees) for the methods matching the given generic function and type signature.
-
Retrieve lowered ASTs for a function with specific argument types:
julia> function add_numbers(x, y) return x + y end julia> methods_add_numbers = code_lowered(add_numbers, Tuple{Int, Int})
The
code_lowered
function returns an array of lowered ASTs for the methods matching the generic functionadd_numbers
and the given argument typesTuple{Int, Int}
. In this example, there are two methods matching the signature, and their corresponding lowered ASTs are stored in themethods_add_numbers
array. -
Retrieve lowered ASTs for a function with multiple methods:
julia> subtract_numbers(x, y) = x - y subtract_numbers (generic function with 1 method) julia> methods_subtract_numbers = code_lowered(subtract_numbers, Tuple{Int, Int})
The
code_lowered
function can also be used to retrieve the lowered AST for a function with multiple methods. In this example, the functionsubtract_numbers
has one method, and its lowered AST is stored in themethods_subtract_numbers
array.
Note: The returned lowered ASTs can be further analyzed or manipulated using Julia's metaprogramming capabilities.
See Also
assert, backtrace, code_llvm, code_lowered, code_native, code_typed, code_warntype, :@which, compilecache, current_module, eval, finalize, finalizer, fullname, function_module, function_name, include_dependency, InterruptException, invoke, isconst, isdefined, isgeneric, methodswith, method_exists, module_name, module_parent, require, subtypes, unsafe_load, workspace, __precompile__,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.