Skip to content

Commit

Permalink
JETAnalyzer: disable bail_out_const_call
Browse files Browse the repository at this point in the history
To get nicer error reports.
  • Loading branch information
aviatesk committed Jan 30, 2024
1 parent 5960be0 commit ccb66fe
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
17 changes: 11 additions & 6 deletions src/analyzers/jetanalyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ function CC.add_call_backedges!(
sv::InferenceState)
end

@static if VERSION v"1.11.0-DEV.1284"
CC.bail_out_const_call(::JETAnalyzer, ::MethodCallResult, ::StmtInfo, ::MethodMatch, ::InferenceState) = false
else
CC.const_prop_enabled(::JETAnalyzer, ::MethodMatch, ::InferenceState) = true
CC.bail_out_const_call(::JETAnalyzer, ::MethodCallResult, ::StmtInfo, ::InferenceState) = false

Check warning on line 282 in src/analyzers/jetanalyzer.jl

View check run for this annotation

Codecov / codecov/patch

src/analyzers/jetanalyzer.jl#L281-L282

Added lines #L281 - L282 were not covered by tests
end

# TODO Reasons about error found by [semi-]concrete evaluation:
# For now JETAnalyzer allows the regular constant-prop' only,
# unless the analyzed effects are proven to be `:nothrow`.
Expand Down Expand Up @@ -1297,13 +1304,11 @@ function report_fieldaccess!(analyzer::JETAnalyzer, sv::InferenceState, @nospeci
end
end
fidx = _getfield_fieldindex(s, name)
fidx === nothing && @goto report_nofield_error
ftypes = Base.datatype_fieldtypes(s)
nf = length(ftypes)
(fidx < 1 || fidx > nf) && @goto report_nofield_error
return false
if fidx !== nothing
nf = length(Base.datatype_fieldtypes(s))
1 fidx nf && return false
end

@label report_nofield_error
namev = (name::Const).val
objtyp = s00
if namev isa Symbol
Expand Down
29 changes: 20 additions & 9 deletions test/analyzers/test_jetanalyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -701,15 +701,16 @@ access_field(x::InvalidBuiltinStruct, sym) = getfield(x, sym)
end

@testset "constant propagation" begin
result = report_call(x::InvalidBuiltinStruct->access_field(x,:v))
@test isempty(get_reports_with_test(result))

result = report_call(x::InvalidBuiltinStruct->access_field(x,:w))
report = only(get_reports_with_test(result))
@test report isa BuiltinErrorReport && report.f === getfield

result = report_call(x::InvalidBuiltinStruct->access_field(x,:v))
@test isempty(get_reports_with_test(result))
let result = report_call(x::InvalidBuiltinStruct->access_field(x,:v))
@test isempty(get_reports_with_test(result))
end
let result = report_call(x::InvalidBuiltinStruct->access_field(x,:w))
report = only(get_reports_with_test(result))
@test report isa BuiltinErrorReport && report.f === getfield
end
let result = report_call(x::InvalidBuiltinStruct->access_field(x,:v))
@test isempty(get_reports_with_test(result))
end
end
end

Expand Down Expand Up @@ -809,6 +810,16 @@ end
x.y = "bar"
end
end
let # Note: on v1.11 and above, we need to disable `bail_out_const_call`
# in order to get a nicer report for this case
result = report_call((Float64,)) do x
x.num
end
@test only(get_reports_with_test(result)) isa BuiltinErrorReport
test_builtinerror_compatibility(result) do
(0.0).num
end
end
end

@testset "getfield analysis" begin
Expand Down

0 comments on commit ccb66fe

Please sign in to comment.