First off, thatβs impressive. Only thing I would suggest is commenting out multiple lines between #=
and =#
instead of #
leading each line to make copy-pasting convenient.
Second, I tried @code_warntype
right out the gate before any execution, and it appears as type-stable as your reports after benchmarks. However, if we Cthulhu.@descend
deeper, we run into recursion with changing argument types:
305 all(f::Main.Euler2D_MWE.var"#1#2"{SClosedPolygon{4, Float64}}::Function, a::SVector{4, SVector{2, Float64}}::StaticArray; dims::Core.Const(Colon())=:)::Bool = _mapreduce(x->f(x)::Bool, &::Core.Const(&), dims::Core.Const(Colon()), true, Size(a::SVector{4, SVector{2, Float64}})::Core.Const(Size(4,)), a::SVector{4, SVector{2, Float64}})
Select a call to descend into or β© to ascend. [q]uit. [b]ookmark.
Toggles: [w]arn, [h]ide type-stable statements, [t]ype annotations, [s]yntax highlight for Source/LLVM/Native, [j]ump to source always.
Show: [S]ource code, [A]ST, [T]yped code, [L]LVM IR, [N]ative code
Actions: [E]dit source code, [R]evise and redisplay
Size(a::SVector{4, SVector{2, Float64}})
β’ _mapreduce(x->f(x)::Bool, &::Core.Const(&), dims::Core.Const(Colon()), true, Size(a::SVector{4, SVector{2, Float64}})::Core.Const(Size(4,)), a::SVecβ¦
β©
_mapreduce(args::Vararg{Any, N}) where N @ StaticArrays C:\Users\Benny\.julia\packages\StaticArrays\DsPgf\src\mapreduce.jl:153
β Warning: Inference terminated in an incomplete state due to argument-type changes during recursion
despite the ultimate return value of all
being inferred as Bool
. The implied recursion isnβt clear because some metaprogramming obscured calls on top of the compromised type information; in other words, itβs hard to pick which lines to manually descend further.
Fortunately, `JET.@reportopt` automatically ''descends'' into all the calls to filter out instability and dispatch issues, and it spots an explicit recursion becoming unoptimized and runtime-dispatched. It seems to corroborate your comment about `all(Base.Fix2(...),...)` being a potential issue for `point_inside_strict`, a function called in the input function for `all` in the benchmarked function.
julia> @report_opt Euler2D_MWE.is_cell_contained_by(test_cell, test_poly1)
βββββ 8 possible errors found βββββ
β is_cell_contained_by(cell1::TangentQuadCell_MWE{Float64, 3, 12}, poly::SClosedPolygon{4, Float64}) @ Main.Euler2D_MWE ./REPL[7]:35
ββ all(f::Main.Euler2D_MWE.var"#1#2"{SClosedPolygon{4, Float64}}, a::SVector{4, SVector{2, Float64}}) @ StaticArrays C:\Users\Benny\.julia\packages\StaticArrays\DsPgf\src\mapreduce.jl:305
βββ all(f::Main.Euler2D_MWE.var"#1#2"{SClosedPolygon{4, Float64}}, a::SVector{4, SVector{2, Float64}}; dims::Colon) @ StaticArrays C:\Users\Benny\.julia\packages\StaticArrays\DsPgf\src\mapreduce.jl:305
ββββ _mapreduce(::StaticArrays.var"#214#215"{β¦}, ::typeof(&), ::Colon, ::Bool, ::Size{β¦}, ::SVector{β¦}) @ StaticArrays C:\Users\Benny\.julia\packages\StaticArrays\DsPgf\src\mapreduce.jl:153
βββββ _mapfoldl(f::StaticArrays.var"#214#215"{β¦}, op::typeof(&), dims::Colon, init::Bool, ::Size{β¦}, a::SVector{β¦}) @ StaticArrays C:\Users\Benny\.julia\packages\StaticArrays\DsPgf\src\mapreduce.jl:180
ββββββ (::StaticArrays.var"#214#215"{Main.Euler2D_MWE.var"#1#2"{SClosedPolygon{4, Float64}}})(x::SVector{2, Float64}) @ StaticArrays C:\Users\Benny\.julia\packages\StaticArrays\DsPgf\src\mapreduce.jl:305
βββββββ (::Main.Euler2D_MWE.var"#1#2"{SClosedPolygon{4, Float64}})(pt::SVector{2, Float64}) @ Main.Euler2D_MWE ./REPL[7]:36
ββββββββ point_inside_strict(poly::SClosedPolygon{4, Float64}, pt::SVector{2, Float64}) @ Main.PlanePolygons_MWE ./REPL[6]:71
βββββββββ all(f::Base.Fix2{β¦}, a::SVector{β¦}) @ StaticArrays C:\Users\Benny\.julia\packages\StaticArrays\DsPgf\src\mapreduce.jl:305
ββββββββββ all(f::Base.Fix2{β¦}, a::SVector{β¦}; dims::Colon) @ StaticArrays C:\Users\Benny\.julia\packages\StaticArrays\DsPgf\src\mapreduce.jl:305
βββββββββββ _mapreduce(::StaticArrays.var"#214#215", ::typeof(&), ::Colon, ::Bool, ::Size{β¦}, ::SVector{β¦}) @ StaticArrays C:\Users\Benny\.julia\packages\StaticArrays\DsPgf\src\mapreduce.jl:153
βββββββββββ runtime dispatch detected: StaticArrays._mapfoldl(%1::StaticArrays.var"#214#215", &, Colon(), %2::Bool, [quote]::Size{(4,)}, %3::SVector{4, Main.PlanePolygons_MWE.Line{Float64}})::Bool
βββββββββββββββββββββββββββββββ
ββββββββββ all(f::Base.Fix2{β¦}, a::SVector{β¦}; dims::Colon) @ StaticArrays C:\Users\Benny\.julia\packages\StaticArrays\DsPgf\src\mapreduce.jl:305
ββββββββββ failed to optimize due to recursion: StaticArrays.var"#all#213"(::Colon, ::typeof(all), ::Base.Fix2{β¦}, ::SVector{β¦})
ββββββββββββββββββββββββββββββ
βββββββββ all(f::Base.Fix2{β¦}, a::SVector{β¦}) @ StaticArrays C:\Users\Benny\.julia\packages\StaticArrays\DsPgf\src\mapreduce.jl:305
βββββββββ failed to optimize due to recursion: all(::Base.Fix2{β¦}, ::SVector{β¦})
βββββββββββββββββββββββββββββ
ββββββββ point_inside_strict(poly::SClosedPolygon{4, Float64}, pt::SVector{2, Float64}) @ Main.PlanePolygons_MWE ./REPL[6]:70
ββββββββ failed to optimize due to recursion: Main.PlanePolygons_MWE.point_inside_strict(::SClosedPolygon{4, Float64}, ::SVector{2, Float64})
ββββββββββββββββββββββββββββ
βββββββ (::Main.Euler2D_MWE.var"#1#2"{SClosedPolygon{4, Float64}})(pt::SVector{2, Float64}) @ Main.Euler2D_MWE ./REPL[7]:36
βββββββ failed to optimize due to recursion: (::Main.Euler2D_MWE.var"#1#2"{SClosedPolygon{4, Float64}})(::SVector{2, Float64})
βββββββββββββββββββββββββββ
ββββββ (::StaticArrays.var"#214#215"{Main.Euler2D_MWE.var"#1#2"{SClosedPolygon{4, Float64}}})(x::SVector{2, Float64}) @ StaticArrays C:\Users\Benny\.julia\packages\StaticArrays\DsPgf\src\mapreduce.jl:305
ββββββ failed to optimize due to recursion: (::StaticArrays.var"#214#215"{Main.Euler2D_MWE.var"#1#2"{SClosedPolygon{4, Float64}}})(::SVector{2, Float64})
ββββββββββββββββββββββββββ
βββββ _mapfoldl(f::StaticArrays.var"#214#215"{β¦}, op::typeof(&), dims::Colon, init::Bool, ::Size{β¦}, a::SVector{β¦}) @ StaticArrays C:\Users\Benny\.julia\packages\StaticArrays\DsPgf\src\mapreduce.jl:155
βββββ failed to optimize due to recursion: StaticArrays._mapfoldl(::StaticArrays.var"#214#215"{β¦}, ::typeof(&), ::Colon, ::Bool, ::Size{β¦}, ::SVector{β¦})
βββββββββββββββββββββββββ
ββββ _mapreduce(::StaticArrays.var"#214#215"{β¦}, ::typeof(&), ::Colon, ::Bool, ::Size{β¦}, ::SVector{β¦}) @ StaticArrays C:\Users\Benny\.julia\packages\StaticArrays\DsPgf\src\mapreduce.jl:153
ββββ failed to optimize due to recursion: StaticArrays._mapreduce(::StaticArrays.var"#214#215"{β¦}, ::typeof(&), ::Colon, ::Bool, ::Size{β¦}, ::SVector{β¦})
ββββββββββββββββββββββββ
These reports persist after the 0 allocation benchmark. These reports also show up if run fresh after your MWE completed the 0 allocation benchmark. Like @code_warntype
etc, these packages seem to perform type inference fresh, so itβs still possible it diverges from the actually compiled code. Not great in the exceptional cases like these where state matters.