Skip to content

Commit

Permalink
Validate linfo in asserts builds, and abort on errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Jan 13, 2024
1 parent 8ef828b commit 011becb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion base/compiler/inferencestate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ function InferenceState(result::InferenceResult, cache_mode::UInt8, interp::Abst
world = get_world_counter(interp)
src = retrieve_code_info(result.linfo, world)
src === nothing && return nothing
validate_code_in_debug_mode(result.linfo, src, "lowered")
maybe_validate_code(result.linfo, src, "lowered")
return InferenceState(result, src, cache_mode, interp)
end
InferenceState(result::InferenceResult, cache_mode::Symbol, interp::AbstractInterpreter) =
Expand Down
9 changes: 5 additions & 4 deletions base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ is_declared_inline(@nospecialize src::MaybeCompressed) =
is_declared_noinline(@nospecialize src::MaybeCompressed) =
ccall(:jl_ir_flag_inlining, UInt8, (Any,), src) == 2

is_asserts() = ccall(:jl_is_assertsbuild, Cint, ()) == 1

#####################
# OptimizationState #
#####################
Expand Down Expand Up @@ -188,7 +186,7 @@ function ir_to_codeinf!(opt::OptimizationState)
(; linfo, src) = opt
src = ir_to_codeinf!(src, opt.ir::IRCode)
opt.ir = nothing
validate_code_in_debug_mode(linfo, src, "optimized")
maybe_validate_code(linfo, src, "optimized")
return src
end

Expand Down Expand Up @@ -937,7 +935,10 @@ function run_passes_ipo_safe(
@pass "compact 3" ir = compact!(ir, true)
end
if is_asserts()
@timeit "verify 3" (verify_ir(ir, true, false, optimizer_lattice(sv.inlining.interp)); verify_linetable(ir.linetable))
@timeit "verify 3" begin
verify_ir(ir, true, false, optimizer_lattice(sv.inlining.interp))
verify_linetable(ir.linetable)
end
end
@label __done__ # used by @pass
return ir
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ function finish(me::InferenceState, interp::AbstractInterpreter)
end
end

validate_code_in_debug_mode(me.linfo, me.src, "inferred")
maybe_validate_code(me.linfo, me.src, "inferred")
nothing
end

Expand Down
4 changes: 4 additions & 0 deletions base/compiler/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ end
is_root_module(m::Module) = false

inlining_enabled() = (JLOptions().can_inline == 1)

function coverage_enabled(m::Module)
generating_output() && return false # don't alter caches
cov = JLOptions().code_coverage
Expand All @@ -533,9 +534,12 @@ function coverage_enabled(m::Module)
end
return false
end

function inbounds_option()
opt_check_bounds = JLOptions().check_bounds
opt_check_bounds == 0 && return :default
opt_check_bounds == 1 && return :on
return :off
end

is_asserts() = ccall(:jl_is_assertsbuild, Cint, ()) == 1
6 changes: 3 additions & 3 deletions base/compiler/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ struct InvalidCodeError <: Exception
end
InvalidCodeError(kind::AbstractString) = InvalidCodeError(kind, nothing)

function validate_code_in_debug_mode(linfo::MethodInstance, src::CodeInfo, kind::String)
if ccall(:jl_is_debugbuild, Cint, ()) == 1
# this is a debug build of julia, so let's validate linfo
function maybe_validate_code(linfo::MethodInstance, src::CodeInfo, kind::String)
if is_asserts()
errors = validate_code(linfo, src)
if !isempty(errors)
for e in errors
Expand All @@ -75,6 +74,7 @@ function validate_code_in_debug_mode(linfo::MethodInstance, src::CodeInfo, kind:
linfo.def, ": ", e)
end
end
error("")
end
end
end
Expand Down

0 comments on commit 011becb

Please sign in to comment.