Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro Expansion: Special case QuoteNode by Returnsing the unpacked value rather than the QuoteNode itself. #119

Merged
merged 6 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bench/runbenchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ end
@group begin "no compilation"
res = @b @eval (@b 100 rand seconds=.001)
@track res.time
@track res.compile_fraction < 1e-4 # A bit of compile time is necessary because of the @eval
@track res.compile_fraction > 1e-4 # A bit of compile time is necessary because of the @eval
end

@group begin "bignums don't explode in the reduction"
Expand Down
5 changes: 5 additions & 0 deletions src/macro_tools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ function extract_interpolations!(interpolations, expr::Expr)
end

create_first_function(f::Symbol) = f
# We use `Returns` to reduce compile time by using fewer anonymous functions.
# Assumeing that any value in an expression tree other than Expr or QuoteNode `eval`s to
# itself, using `Returns` is semantically equivalent to the documented behavior. Assuming
# that we prevent constant propagation elsewhere it should produce equivalent measurements.
create_first_function(x) = Returns(x)
create_first_function(x::QuoteNode) = Returns(x.value)
create_first_function(body::Expr) = :(() -> $body)
function create_function(f)
f === :_ && return identity
Expand Down
12 changes: 12 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ using Chairmarks: Sample, Benchmark
100.000 ms
100.000 ms"""
end

@testset "Issue 99" begin
@b :my_func isdefined(Main, _) seconds=.001
end
end

@testset "Statistics Extension" begin
Expand Down Expand Up @@ -306,6 +310,14 @@ using Chairmarks: Sample, Benchmark
end

@testset "Performance" begin
@testset "no compilation" begin
res = @b @eval @b 100 rand seconds=.001
@test res.compile_fraction < .1
@eval _Chairmarks_test_isdefined_in_Main(x) = isdefined(Main, x)
res = @b @eval @b :my_func _Chairmarks_test_isdefined_in_Main seconds=.001
@test res.compile_fraction < .1
end

### Begin stuff that doesn't run

function verbose_check(baseline, test, tolerance)
Expand Down
Loading