diff --git a/stdlib/InteractiveUtils/src/macros.jl b/stdlib/InteractiveUtils/src/macros.jl index e338d8626fb0f..0c272940b82d9 100644 --- a/stdlib/InteractiveUtils/src/macros.jl +++ b/stdlib/InteractiveUtils/src/macros.jl @@ -2,7 +2,7 @@ # macro wrappers for various reflection functions -import Base: typesof, insert!, replace_ref_begin_end!, infer_effects +import Base: typesof, insert!, replace_ref_begin_end!, infer_effects, code_ircode # defined in Base so it's possible to time all imports, including InteractiveUtils and its deps # via. `Base.@time_imports` etc. @@ -249,6 +249,14 @@ macro code_lowered(ex0...) end end +macro code_ircode(ex0...) + thecall = gen_call_with_extracted_types_and_kwargs(__module__, :code_ircode, ex0) + quote + local results = $thecall + length(results) == 1 ? results[1] : results + end +end + """ @functionloc diff --git a/stdlib/InteractiveUtils/test/runtests.jl b/stdlib/InteractiveUtils/test/runtests.jl index e729ae67bde19..bb64153818c1d 100644 --- a/stdlib/InteractiveUtils/test/runtests.jl +++ b/stdlib/InteractiveUtils/test/runtests.jl @@ -819,6 +819,8 @@ end end @test Base.infer_effects(sin, (Int,)) == InteractiveUtils.@infer_effects sin(42) +@test first(InteractiveUtils.@code_ircode sin(42)) isa Core.Compiler.IRCode +@test first(InteractiveUtils.@code_ircode optimize_until="Inlining" sin(42)) isa Core.Compiler.IRCode @testset "Docstrings" begin @test isempty(Docs.undocumented_names(InteractiveUtils))