LilithHafner / Chairmarks.jl

Benchmarks with back support
GNU General Public License v3.0
81 stars 8 forks source link

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

Closed LilithHafner closed 2 weeks ago

LilithHafner commented 2 weeks ago

Fixes #99.

This special case assumes that all non-Expr objects in an expression tree evaluate to themselves. This is a false assumption in the case of QuoteNode(::Symbol).

Additionally, this Returns gives the compiler slightly less information by inhibiting constant propagation of literals. Constant propagation of literals is usually bad (misleadingly low runtimes) in this case but this particular fix also results in @b 2 rand and @b 1+1 rand having different properties with the latter more constprop-able. I was not able to find a case where the Returns is helpful.

Returns was added in 4f8a8c8bb0635b53a0162d3958a7c24430d7766d to avoid compilation time and paired with the test

@testset "no compilation" begin
    res = @b @eval (@b 100 rand seconds=.001)
    @test .001 < 1e-9res.time < .002
    @test res.compile_fraction === 0.0
end

I expect the "no compilation" regression test to regress.

LilithHafner commented 2 weeks ago

The regression tests failed as expected. See comment in source code and commit comment of 9ec4ef565a839f5f21fe199ceb1afe912d943ded for explanation. The OP is out of date.