Optimization Analysis

Successful type inference and optimization are key to high-performing Julia programs. But as mentioned in the performance tips, there are some chances where Julia can not infer the types of your program very well and can not optimize it well accordingly.

While there are many possibilities of "type-instabilities", like usage of non-constant global variable most notably, probably the most tricky one would be "captured variable" – Julia can not really well infer the type of variable that is observed and modified by both inner function and enclosing one. And such type instabilities can lead to various optimization failures. One of the most common barriers to performance is known as "runtime dispatch", which happens when a matching method can't be resolved by the compiler due to the lack of type information and it is looked up at runtime instead. Since runtime dispatch is caused by poor type information, it often indicates the compiler could not do other optimizations including inlining and scalar replacements of aggregates.

In order to avoid such problems, we usually inspect the output of code_typed or its family, and check if there is anywhere type is not well inferred and optimization was not successful. But the problem is that one needs to have enough knowledge about inference and optimization in order to interpret the output. Another problem is that they can only present the "final" output of the inference and optimization, and we can not inspect the entire call graph and may miss finding where a problem actually happened and how the type-instability has been propagated. There is a nice package called Cthulhu.jl, which allows us to look at the outputs of code_typed by descending into a call tree, recursively and interactively. The workflow with Cthulhu is much more efficient and powerful, but still, it requires much familiarity with the Julia compiler and it tends to be tedious.

So, why not automate it? JET implements such an analyzer that investigates the optimized representation of your program and automatically detects anywhere the compiler failed in optimization. Especially, it can find where Julia creates captured variables, where runtime dispatch will happen, and where Julia gives up the optimization work due to unresolvable recursive function call.

SnoopCompile also detects inference failures, but JET and SnoopCompile use different mechanisms: JET performs static analysis of a particular call, while SnoopCompile performs dynamic analysis of new inference. As a consequence, JET's detection of inference failures is reproducible (you can run the same analysis repeatedly and get the same result) but terminates at any non-inferrable node of the call graph: you will miss runtime dispatch in any non-inferrable callees. Conversely, SnoopCompile's detection of inference failures can explore the entire callgraph, but only for those portions that have not been previously inferred, and the analysis cannot be repeated in the same session.

Quick Start

JET exports @report_opt, which analyzes the entire call graph of a given generic function call, and then reports detected performance pitfalls:

julia> using JET

As a first example, let's see how we can find and fix runtime dispatches using JET:

julia> n = rand(Int); # non-constant global variable
julia> make_vals(n) = n ≥ 0 ? (zero(n):n) : (n:zero(n));
julia> function sumup(f) # this function uses the non-constant global variable `n` here # and it makes every succeeding operations type-unstable vals = make_vals(n) s = zero(eltype(vals)) for v in vals s += f(v) end return s end;
julia> @report_opt sumup(sin) # runtime dispatches will be reported═════ 7 possible errors found ═════ ┌ @ REPL[3]:4 Main.make_vals(%1) │ runtime dispatch detected: Main.make_vals(%1::Any)::Any └───────────── ┌ @ REPL[3]:5 Main.eltype(%2) │ runtime dispatch detected: Main.eltype(%2::Any)::Any └───────────── ┌ @ REPL[3]:5 Main.zero(%3) │ runtime dispatch detected: Main.zero(%3::Any)::Any └───────────── ┌ @ REPL[3]:6 iterate(%2) │ runtime dispatch detected: iterate(%2::Any)::Any └───────────── ┌ @ REPL[3]:7 f(%11) │ runtime dispatch detected: f::typeof(sin)(%11::Any)::Any └───────────── ┌ @ REPL[3]:7 %10 Main.:+ %13 │ runtime dispatch detected: (%10::Any Main.:+ %13::Any)::Any └───────────── ┌ @ REPL[3]:8 iterate(%2, %12) │ runtime dispatch detected: iterate(%2::Any, %12::Any)::Any └─────────────

JET's analysis result will be dynamically updated when we (re-)define functions[1], and we can "hot-fix" the runtime dispatches within the same running Julia session like this:

julia> # we can pass parameters as a function argument instead, and then everything will be type-stable
       function sumup(f, n)
           vals = make_vals(n)
           s = zero(eltype(vals))
           for v in vals
               # NOTE here we may get union type like `s::Union{Int,Float64}`,
               # but Julia can optimize away such small unions (thus no runtime dispatch)
               s += f(v)
           end
           return s
       end;
julia> @report_opt sumup(sin, rand(Int)) # now runtime dispatch free !No errors detected

@report_opt can also report the existence of captured variables, which are really better to be eliminated within performance-sensitive context:

julia> # the examples below are all adapted from https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-captured
       function abmult(r::Int)
           if r < 0
               r = -r
           end
           # the closure assigned to `f` make the variable `r` captured
           f = x -> x * r
           return f
       end;
julia> @report_opt abmult(42)═════ 3 possible errors found ═════ ┌ @ REPL[1]:2 r = Core.Box(_7::Int64) │ captured variable `r` detected └───────────── ┌ @ REPL[1]:2 %6 Main.:< 0 │ runtime dispatch detected: (%6::Any Main.:< 0)::Any └───────────── ┌ @ REPL[1]:3 Main.:-(%13) │ runtime dispatch detected: Main.:-(%13::Any)::Any └─────────────
julia> function abmult(r0::Int) # we can improve the type stability of the variable `r` like this, # but it is still captured r::Int = r0 if r < 0 r = -r end f = x -> x * r return f end;
julia> @report_opt abmult(42)═════ 1 possible error found ═════ ┌ @ REPL[3]:4 r = Core.Box() │ captured variable `r` detected └─────────────
julia> function abmult(r::Int) if r < 0 r = -r end # we can try to eliminate the capturing # and now this function would be the most performing f = let r = r x -> x * r end return f end;
julia> @report_opt abmult(42)No errors detected

With the target_modules configuration, we can easily limit the analysis scope to a specific module context:

julia> # problem: when ∑1/n exceeds `x` ?
       function compute(x)
           r = 1
           s = 0.0
           n = 1
           @time while r < x
               s += 1/n
               if s ≥ r
                   # `println` call is full of runtime dispatches for good reasons
                   # and we're not interested in type-instabilities within this call
                   # since we know it's only called a few times
                   println("round $r/$x has been finished")
                   r += 1
               end
               n += 1
           end
           return n, s
       endcompute (generic function with 1 method)
julia> @report_opt compute(30) # bunch of reports will be reported from the `println` call═════ 24 possible errors found ═════ ┌ @ REPL[1]:11 Main.println(string("round ", r, "/", x, " has been finished")) ┌ @ coreio.jl:4 println(tuple(stdout), xs...) ┌ @ strings/io.jl:75 print(tuple(io), xs, tuple("\n")...) ┌ @ strings/io.jl:43 lock(io) ┌ @ show.jl:396 lock(io.io) ┌ @ stream.jl:283 lock(s.lock) ┌ @ lock.jl:147 slowlock(rl) ┌ @ lock.jl:156 wait(c) ┌ @ condition.jl:124 = wait() ┌ @ task.jl:973 result = Base.try_yieldto(Base.ensure_rescheduled) ┌ @ task.jl:901 undo($(Expr(:foreigncall, :(:jl_get_next_task), Ref{Task}, svec(), 0, :(:ccall)))) ┌ @ task.jl:937 Base.list_deletefirst!(W, ct) ┌ @ linked_list.jl:145 isequal(h.value, val) ┌ @ gcutils.jl:4 isequal(%1, v) │ runtime dispatch detected: isequal(%1::Any, v::Task)::Bool └──────────────── ┌ @ task.jl:932 pushfirst!(%19, othertask) │ runtime dispatch detected: pushfirst!(%19::Any, othertask::Task)::Any └─────────────── ┌ @ task.jl:937 Base.list_deletefirst!(%5, %1) │ runtime dispatch detected: Base.list_deletefirst!(%5::Any, %1::Task)::Any └─────────────── ┌ @ task.jl:972 Base.poptask(%5) │ runtime dispatch detected: Base.poptask(%5::Any)::Any └─────────────── ┌ @ condition.jl:126 Base.list_deletefirst!(%43, %37) │ runtime dispatch detected: Base.list_deletefirst!(%43::Any, %37::Task)::Any └──────────────────── ┌ @ strings/io.jl:49 unlock(io) ┌ @ show.jl:397 unlock(io.io) ┌ @ stream.jl:284 unlock(s.lock) ┌ @ lock.jl:177 _unlock(rl) ┌ @ lock.jl:183 notifywaiters(rl) ┌ @ lock.jl:187 = notify(cond_wait) ┌ @ condition.jl:142 #self#(c, Base.nothing) ┌ @ condition.jl:142 Base.:(var"#notify#621")(true, false, #self#, c, arg) ┌ @ condition.jl:142 notify(c, arg, all, error) ┌ @ condition.jl:148 Core.kwfunc(schedule)(NamedTuple{(:error,)}(tuple(error)), schedule, t, arg) ┌ @ task.jl:827 Base.:(var"#schedule#648")(_7, _3, t, arg) ┌ @ task.jl:838 Base.enq_work(t) ┌ @ task.jl:782 push!(%47, t) │ runtime dispatch detected: push!(%47::Any, t::Task)::Any └─────────────── ┌ @ task.jl:831 Base.list_deletefirst!(%10, t) │ runtime dispatch detected: Base.list_deletefirst!(%10::Any, t::Task)::Any └─────────────── ┌ @ coreio.jl:4 println(%1, %2) │ runtime dispatch detected: println(%1::IO, %2::String)::Nothing └─────────────── ┌ @ timing.jl:282 Base.time_print(elapsedtime, diff.allocd, diff.total_time, Base.gc_alloc_count(diff), first(compile_elapsedtimes), last(compile_elapsedtimes), true, !(has_msg)) ┌ @ timing.jl:140 str = sprint(#953) ┌ @ strings/io.jl:107 Base.:(var"#sprint#484")(tuple(Base.nothing, 0, #self#, f), args...) ┌ @ strings/io.jl:114 f(tuple(s), args...) ┌ @ timing.jl:143 %32 != 0 │ runtime dispatch detected: (%32::Any != 0)::Any └───────────────── ┌ @ timing.jl:145 %63 != 0 │ runtime dispatch detected: (%63::Any != 0)::Any └───────────────── ┌ @ timing.jl:146 Base.prettyprint_getunits(%71, %73, 1000) │ runtime dispatch detected: Base.prettyprint_getunits(%71::Any, %73::Int64, 1000)::Tuple{Any, Any} └───────────────── ┌ @ timing.jl:147 %78 == 1 │ runtime dispatch detected: (%78::Any == 1)::Any └───────────────── ┌ @ timing.jl:148 Base.Int(%86) │ runtime dispatch detected: Base.Int(%86::Any)::Any └───────────────── ┌ @ timing.jl:148 Base._cnt_units[%78] │ runtime dispatch detected: (Base._cnt_units)[%78::Any]::Any └───────────────── ┌ @ timing.jl:148 %94 == 1 │ runtime dispatch detected: (%94::Any == 1)::Any └───────────────── ┌ @ timing.jl:148 print(io, %87, %88, %99) │ runtime dispatch detected: print(io::IOBuffer, %87::Any, %88::Any, %99::String)::Any └───────────────── ┌ @ timing.jl:150 Base.Float64(%107) │ runtime dispatch detected: Base.Float64(%107::Any)::Any └───────────────── ┌ @ timing.jl:150 Base.Ryu.writefixed(%108, 2) │ runtime dispatch detected: Base.Ryu.writefixed(%108::Any, 2)::String └───────────────── ┌ @ timing.jl:150 Base._cnt_units[%78] │ runtime dispatch detected: (Base._cnt_units)[%78::Any]::Any └───────────────── ┌ @ timing.jl:150 print(io, %109, %110, " allocations: ") │ runtime dispatch detected: print(io::IOBuffer, %109::String, %110::Any, " allocations: ")::Any └───────────────── ┌ @ timing.jl:155 %133 != 0 │ runtime dispatch detected: (%133::Any != 0)::Any └───────────────── ┌ @ timing.jl:161 %165 != 0 │ runtime dispatch detected: (%165::Any != 0)::Any └───────────────── ┌ @ timing.jl:173 print(str) ┌ @ coreio.jl:3 print(%1, %2) │ runtime dispatch detected: print(%1::IO, %2::String)::Nothing └─────────────── ┌ @ timing.jl:139 allocs = Core.Box(_13::Int64) │ captured variable `allocs` detected └─────────────────
julia> @report_opt target_modules=(@__MODULE__,) compute(30) # focus on what we wrote, and no error should be reportedNo errors detected

There is also function_filter, which can ignore specific function calls.

@test_opt can be used to assert that a given function call is free from performance pitfalls. It is fully integrated with Test standard library's unit-testing infrastructure, and we can use it like other Test macros e.g. @test:

julia> @test_opt sumup(cos)JET-test failed at REPL[1]:1
  Expression: #= REPL[1]:1 =# JET.@test_call analyzer = JET.OptAnalyzer sumup(cos)
  ═════ 7 possible errors found ═════
  ┌ @ REPL[3]:4 Main.make_vals(%1)
  │ runtime dispatch detected: Main.make_vals(%1::Any)::Any
  └─────────────
  ┌ @ REPL[3]:5 Main.eltype(%2)
  │ runtime dispatch detected: Main.eltype(%2::Any)::Any
  └─────────────
  ┌ @ REPL[3]:5 Main.zero(%3)
  │ runtime dispatch detected: Main.zero(%3::Any)::Any
  └─────────────
  ┌ @ REPL[3]:6 iterate(%2)
  │ runtime dispatch detected: iterate(%2::Any)::Any
  └─────────────
  ┌ @ REPL[3]:7 f(%11)
  │ runtime dispatch detected: f::typeof(cos)(%11::Any)::Any
  └─────────────
  ┌ @ REPL[3]:7 %10 Main.:+ %13
  │ runtime dispatch detected: (%10::Any Main.:+ %13::Any)::Any
  └─────────────
  ┌ @ REPL[3]:8 iterate(%2, %12)
  │ runtime dispatch detected: iterate(%2::Any, %12::Any)::Any
  └─────────────
  
ERROR: There was an error during testing
julia> @test_opt target_modules=(@__MODULE__,) compute(30)Test Passed
julia> using Test
julia> @testset "check type-stabilities" begin @test_opt sumup(cos) # should fail n = rand(Int) @test_opt sumup(cos, n) # should pass @test_opt target_modules=(@__MODULE__,) compute(30) # should pass @test_opt broken=true compute(30) # should pass with the "broken" annotation endcheck type-stabilities: JET-test failed at REPL[4]:2 Expression: #= REPL[4]:2 =# JET.@test_call analyzer = JET.OptAnalyzer sumup(cos) ═════ 7 possible errors found ═════ ┌ @ REPL[3]:4 Main.make_vals(%1) │ runtime dispatch detected: Main.make_vals(%1::Any)::Any └───────────── ┌ @ REPL[3]:5 Main.eltype(%2) │ runtime dispatch detected: Main.eltype(%2::Any)::Any └───────────── ┌ @ REPL[3]:5 Main.zero(%3) │ runtime dispatch detected: Main.zero(%3::Any)::Any └───────────── ┌ @ REPL[3]:6 iterate(%2) │ runtime dispatch detected: iterate(%2::Any)::Any └───────────── ┌ @ REPL[3]:7 f(%11) │ runtime dispatch detected: f::typeof(cos)(%11::Any)::Any └───────────── ┌ @ REPL[3]:7 %10 Main.:+ %13 │ runtime dispatch detected: (%10::Any Main.:+ %13::Any)::Any └───────────── ┌ @ REPL[3]:8 iterate(%2, %12) │ runtime dispatch detected: iterate(%2::Any, %12::Any)::Any └───────────── Test Summary: | Pass Fail Broken Total Time check type-stabilities | 2 1 1 4 0.1s ERROR: Some tests did not pass: 2 passed, 1 failed, 0 errored, 1 broken.

Entry Points

Interactive Entry Points

The optimization analysis offers interactive entry points that can be used in the same way as @report_call and report_call:

JET.@report_optMacro
@report_opt [jetconfigs...] f(args...)

Evaluates the arguments to the function call, determines its types, and then calls report_opt on the resulting expression. As with @code_typed and its family, any of JET configurations or optimization analysis specific configurations can be given as the optional arguments like this:

# reports `rand(::Type{Bool})` with `unoptimize_throw_blocks` configuration turned on
julia> @report_opt unoptimize_throw_blocks=true rand(Bool)
source
JET.report_optFunction
report_opt(f, [types]; jetconfigs...) -> JETCallResult
report_opt(tt::Type{<:Tuple}; jetconfigs...) -> JETCallResult

Analyzes the generic function call with the given type signature with the optimization analyzer, which collects optimization failures and runtime dispatches involved within the call stack.

source

Test Integration

As with the default error analysis, the optimization analysis also offers the integration with Test standard library:

JET.@test_optMacro
@test_opt [jetconfigs...] [broken=false] [skip=false] f(args...)

Tests the generic function call f(args...) is free from runtime dispatch. Returns a Pass result if it is, a Fail result if if contains any location where runtime dispatch or optimization failure happens, or an Error result if this macro encounters an unexpected error. When the test Fails, abstract call stack to each problem location will also be printed to stdout.

julia> @test_opt sincos(10)
Test Passed
  Expression: #= none:1 =# JET.@test_opt sincos(10)

As with @report_opt, any of JET configurations or optimization analysis specific configurations can be given as the optional arguments like this:

julia> function f(n)
            r = sincos(n)
            # `println` is full of runtime dispatches,
            # but we can ignore the corresponding reports from `Base`
            # with the `target_modules` configuration
            println(r)
            return r
       end;

julia> @test_opt target_modules=(@__MODULE__,) f(10)
Test Passed
  Expression: #= REPL[3]:1 =# JET.@test_call analyzer = JET.OptAnalyzer target_modules = (#= REPL[3]:1 =# @__MODULE__(),) f(10)

Like @test_call, @test_opt is fully integrated with Test standard library. See @test_call for the details.

source
JET.test_optFunction
test_opt(f, [types]; broken::Bool = false, skip::Bool = false, jetconfigs...)
test_opt(tt::Type{<:Tuple}; broken::Bool = false, skip::Bool = false, jetconfigs...)

Tests the generic function call with the given type signature is free from runtime dispatch. Except that it takes a type signature rather than a call expression, this function works in the same way as @test_opt.

source

Top-level Entry Points

By default, JET doesn't offer top-level entry points for the optimization analysis, because it's usually used for only a selective portion of your program. But if you want you can just use report_file or similar top-level entry points with specifying analyzer = OptAnalyzer configuration in order to apply the optimization analysis on a top-level script, e.g. report_file("path/to/file.jl"; analyzer = OptAnalyzer).

Configurations

In addition to general configurations, the optimization analysis can take the following specific configurations:

JET.OptAnalyzerType

Every entry point of optimization analysis can accept any of general JET configurations as well as the following additional configurations that are specific to the optimization analysis.


  • skip_noncompileable_calls::Bool = true:
    Julia's runtime dispatch is "powerful" because it can always compile code with concrete runtime arguments so that a "kernel" function runs very effectively even if it's called from a type-instable call site. This means, we (really) often accept that some parts of our code are not inferred statically, and rather we want to just rely on information that is only available at runtime. To model this programming style, the optimization analyzer by default does NOT report any optimization failures or runtime dispatches detected within non-concrete calls (more correctly, "non-compileable" calls are ignored: see also the note below). We can turn off this skip_noncompileable_calls configuration to get type-instabilities within those calls.

    # the following examples are adapted from https://docs.julialang.org/en/v1/manual/performance-tips/#kernel-functions
    julia> function fill_twos!(a)
               for i = eachindex(a)
                   a[i] = 2
               end
           end;
    
    julia> function strange_twos(n)
               a = Vector{rand(Bool) ? Int64 : Float64}(undef, n)
               fill_twos!(a)
               return a
           end;
    
    # by default, only type-instabilities within concrete call (i.e. `strange_twos(3)`) are reported
    # and those within non-concrete calls (`fill_twos!(a)`) are not reported
    julia> @report_opt strange_twos(3)
    ═════ 2 possible errors found ═════
    ┌ @ REPL[2]:2 %45(Main.undef, n)
    │ runtime dispatch detected: %45::Type{Vector{_A}} where _A(Main.undef, n::Int64)
    └─────────────
    ┌ @ REPL[2]:3 Main.fill_twos!(%46)
    │ runtime dispatch detected: Main.fill_twos!(%46::Vector)
    └─────────────
    Vector (alias for Array{_A, 1} where _A)
    
    # we can get reports from non-concrete calls with `skip_noncompileable_calls=false`
    julia> @report_opt skip_noncompileable_calls=false strange_twos(3)
    ═════ 4 possible errors found ═════
    ┌ @ REPL[2]:3 Main.fill_twos!(a)
    │┌ @ REPL[1]:3 a[%14] = 2
    ││ runtime dispatch detected: Base.setindex!(a::Vector, 2, %14::Int64)
    │└─────────────
    │┌ @ REPL[1]:3 a[i] = 2
    ││┌ @ array.jl:877 Base.convert(_, x)
    │││ runtime dispatch detected: Base.convert(_::Any, x::Int64)
    ││└────────────────
    ┌ @ REPL[2]:2 %45(Main.undef, n)
    │ runtime dispatch detected: %45::Type{Vector{_A}} where _A(Main.undef, n::Int64)
    └─────────────
    ┌ @ REPL[2]:3 Main.fill_twos!(%46)
    │ runtime dispatch detected: Main.fill_twos!(%46::Vector)
    └─────────────
    Vector (alias for Array{_A, 1} where _A)
    Non-compileable calls

    Julia runtime system sometimes generate and execute native code of an abstract call. More technically, when some of call arguments are annotated as @nospecialize, Julia compiles the call even if those @nospecialized arguments aren't fully concrete. skip_noncompileable_calls = true also respects this behavior, i.e. doesn't skip compileable abstract calls:

    julia> function maybesin(@nospecialize x)
         if isa(x, Number)
             return sin(x) # this call is dynamically dispatched
         else
             return 0
         end
     end
     maybesin (generic function with 1 method)
    
     julia> report_opt((Vector{Any},)) do xs
         for x in xs
             s = maybesin(x) # this call is resolved statically and compiled
             s !== 0 && return s
         end
     end
     ═════ 1 possible error found ═════
     ┌ @ none:3 s = maybesin(x)
     │┌ @ none:3 sin(%3)
     ││ runtime dispatch detected: sin(%3::Number)::Any
     │└──────────
    
     julia> function maybesin(x)  # now `maybesin` is always called with concrete `x`
                if isa(x, Number)
                    return sin(x) # this call is dynamically dispatched
                else
                    return 0
                end
            end
            maybesin (generic function with 1 method)
    
     julia> report_opt((Vector{Any},)) do xs
                for x in xs
                    s = maybesin(x) # this call is dynamically dispatched
                    s !== 0 && return s
                end
            end
     ═════ 1 possible error found ═════
     ┌ @ none:3 maybesin(%21)
     │ runtime dispatch detected: maybesin(%21::Any)::Any
     └──────────

  • function_filter = @nospecialize(ft)->true:
    A predicate which takes a function type and returns false to skip runtime dispatch analysis on the function call. This configuration is particularly useful when your program uses a function that is intentionally written to use runtime dispatch.

    # ignores `Core.Compiler.widenconst` calls (since it's designed to be runtime-dispatched):
    julia> function_filter(@nospecialize(ft)) = ft !== typeof(Core.Compiler.widenconst)
    
    julia> @test_opt function_filter=function_filter f(args...)
    ...

  • skip_unoptimized_throw_blocks::Bool = true:
    By default, Julia's native compilation pipeline intentionally disables inference (and so succeeding optimizations too) on "throw blocks", which are code blocks that will eventually lead to throw calls, in order to ease the compilation latency problem, a.k.a. "first-time-to-plot". Accordingly, the optimization analyzer also ignores any performance pitfalls detected within those blocks since we usually don't mind if code involved with error handling isn't optimized. If skip_unoptimized_throw_blocks is set to false, it doesn't ignore them and will report type instabilities detected within "throw blocks".

    See also https://github.com/JuliaLang/julia/pull/35982.

    # by default, unoptimized "throw blocks" are not analyzed
    julia> @test_opt sin(10)
    Test Passed
      Expression: #= none:1 =# JET.@test_opt sin(10)
    
    # we can turn on the analysis on unoptimized "throw blocks" with `skip_unoptimized_throw_blocks=false`
    julia> @test_opt skip_unoptimized_throw_blocks=false sin(10)
    JET-test failed at none:1
      Expression: #= REPL[6]:1 =# JET.@test_call analyzer = JET.OptAnalyzer skip_unoptimized_throw_blocks = false sin(10)
      ═════ 1 possible error found ═════
      ┌ @ math.jl:1221 Base.Math.sin(xf)
      │┌ @ special/trig.jl:39 Base.Math.sin_domain_error(x)
      ││┌ @ special/trig.jl:28 Base.Math.DomainError(x, "sin(x) is only defined for finite x.")
      │││ runtime dispatch detected: Base.Math.DomainError(x::Float64, "sin(x) is only defined for finite x.")::Any
      ││└──────────────────────
    
    ERROR: There was an error during testing
    
    # we can also turns off the heuristic itself
    julia> @test_opt unoptimize_throw_blocks=false skip_unoptimized_throw_blocks=false sin(10)
    Test Passed
      Expression: #= REPL[7]:1 =# JET.@test_call analyzer = JET.OptAnalyzer unoptimize_throw_blocks = false skip_unoptimized_throw_blocks = false sin(10)

source