Skip to content

Commit

Permalink
InferenceBenchmarks: allow benchmark against Compiler as the stdlib (
Browse files Browse the repository at this point in the history
…#325)

This is especially useful for optimizing the compiler’s implementation
while using Revise in a local environment.
  • Loading branch information
aviatesk authored Nov 14, 2024
1 parent 048f664 commit 8ea74c9
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/inference/InferenceBenchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ module InferenceBenchmarks
# managed by the runtime system: this allows us to profile Julia-level inference reliably
# without being influenced by previous trials or some native execution

@static if VERSION v"1.12.0-DEV.1581"
if Base.REFLECTION_COMPILER[] === nothing
const CC = Base.Compiler
else
const CC = Base.REFLECTION_COMPILER[]
end
else
const CC = Core.Compiler
end

using Core:
MethodInstance, CodeInstance, MethodTable, SimpleVector
Expand Down Expand Up @@ -94,17 +102,17 @@ end
using Base: _which
else
function _which(@nospecialize(tt::Type);
method_table::Union{Nothing,MethodTable,Core.Compiler.MethodTableView}=nothing,
method_table::Union{Nothing,MethodTable,CC.MethodTableView}=nothing,
world::UInt=get_world_counter(),
raise::Bool=false)
if method_table === nothing
table = Core.Compiler.InternalMethodTable(world)
table = CC.InternalMethodTable(world)
elseif isa(method_table, MethodTable)
table = Core.Compiler.OverlayMethodTable(world, method_table)
table = CC.OverlayMethodTable(world, method_table)
else
table = method_table
end
match, = Core.Compiler.findsup(tt, table)
match, = CC.findsup(tt, table)
if match === nothing
raise && error("no unique matching method found for the specified argument types")
return nothing
Expand Down Expand Up @@ -175,7 +183,7 @@ function opt_call(@nospecialize(f), @nospecialize(types = Base.default_tt(f));
#cfg = @static hasfield(InferenceState, :cfg) ? copy(frame.cfg) : nothing
#unreachable = @static hasfield(InferenceState, :unreachable) ? copy(frame.unreachable) : nothing
#bb_vartables = @static hasfield(InferenceState, :bb_vartables) ? copy(frame.bb_vartables) : nothing
@static if !hasfield(Core.Compiler.InliningState, :params)
@static if !hasfield(CC.InliningState, :params)
opt = OptimizationState(frame, interp)
CC.optimize(interp, opt, frame.result)
else
Expand Down

0 comments on commit 8ea74c9

Please sign in to comment.