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

InferenceBenchmarks: allow benchmark against Compiler as the stdlib #325

Merged
merged 1 commit into from
Nov 14, 2024
Merged
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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little concerned about this one. This is a runtime variable, but used in a compile-time context. It probably works fine for now, but we may want to do something like eval things on the fly when requested.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An eval-based implementation seems more correct. We need to be cautious about whether it affects benchmarks though. Currently the benchmark modules in BaseBenchmarks.jl are not precompiled, and since these benchmarks are essentially runtime-only, this approach should be fine for now.

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
Loading