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

Inconsistent error behavior in @report_opt: error on first run, passes on subsequent runs #673

Open
ehehela opened this issue Oct 24, 2024 · 0 comments

Comments

@ehehela
Copy link

ehehela commented Oct 24, 2024

I encountered a strange issue with @report_opt. It throws an error on the first run but passes on the subsequent run. I suspect this might be a false positive. By following the steps below in the REPL, this behavior can be reproduced.

  1. run the following code
julia> VERSION
v"1.11.1"
  1. define some functions
each_edge(pts::AbstractVector) = @views zip(pts[begin:end-1], pts[begin+1:end])
distance(p1, p2) = (sum((p1 .- p2) .^ 2))
perimeter3(v::AbstractVector{NTuple{2,T}}) where {T} = mapfoldl(((p1, p2),) -> distance(p1, p2), +, each_edge(v); init=zero(T))
function perimeter2(v::AbstractVector{NTuple{2,T}}) where {T}
    l = zero(T)
    for (p1,p2) in each_edge(v)
        l += distance(p1, p2)
    end
    return l
end
  1. import JET.jl
julia> using JET
  1. define a polyline and call @report_opt the first time on perimeter3
julia> line = [(-0.5, 1.5), (1.0, 1.0), (3.0, 1.0), (4.5, 1.5)];
julia> @report_opt perimeter3(line)
═════ 18 possible errors found ═════
  1. call @report_opt a second time on perimeter2
julia> @report_opt perimeter2(line)
No errors detected
  1. now, call @report_opt a third time on perimeter3 again
julia> @report_opt perimeter3(line)
No errors detected

Note that in step 6, the error is gone, which is quite strange. If step 5 is removed, the error will still persist. Furthermore, if step 4 is skipped, after running step 5, step 6 will also not report any error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant