timholy / SnoopCompile.jl

Provide insights about latency (TTFX) for Julia packages
https://timholy.github.io/SnoopCompile.jl/dev/
Other
309 stars 48 forks source link

Indexing error for `uinvalidated` #327

Closed TacHawkes closed 1 year ago

TacHawkes commented 1 year ago

I got the following error for passing a list of invalidations recorded with @snoopr to uinvalidated:

ERROR: BoundsError: attempt to access 1448-element Vector{Any} at index [1449]
Stacktrace:
 [1] getindex
   @ ./essentials.jl:13 [inlined]
 [2] uinvalidated(invlist::Vector{Any}; exclude_corecompiler::Bool)
   @ SnoopCompile ~/.julia/packages/SnoopCompile/Q8zUg/src/invalidations.jl:24
 [3] uinvalidated(invlist::Vector{Any})
   @ SnoopCompile ~/.julia/packages/SnoopCompile/Q8zUg/src/invalidations.jl:20
 [4] top-level scope
   @ show.jl:1128

The problem is if invlist[i+1] != "invalidate_mt_cache" which does not check if I + 1 is actually beyond the last element.

ranocha commented 1 year ago

I also just got this with Julia 1.9.0-beta2:

julia> using Pkg; Pkg.activate(temp=true); Pkg.add(["SnoopCompileCore", "SnoopCompile", "LoopVectorization"])
  Activating new project at `/tmp/jl_qqTUS0`
    Updating registry at `~/.julia/registries/General.toml`
   Resolving package versions...
    Updating `/tmp/jl_qqTUS0/Project.toml`
  [bdcacae8] + LoopVectorization v0.12.143
  [aa65fe97] + SnoopCompile v2.9.6
  [e2b509da] + SnoopCompileCore v2.9.0
    Updating `/tmp/jl_qqTUS0/Manifest.toml`
  [1520ce14] + AbstractTrees v0.4.3
  [79e6a3ab] + Adapt v3.4.0
  [4fba245c] + ArrayInterface v6.0.24
  [30b0a656] + ArrayInterfaceCore v0.1.28
  [015c0d05] + ArrayInterfaceOffsetArrays v0.1.7
  [b0d46f97] + ArrayInterfaceStaticArrays v0.1.5
  [dd5226c6] + ArrayInterfaceStaticArraysCore v0.1.3
  [62783981] + BitTwiddlingConvenienceFunctions v0.1.5
⌅ [2a0fbf3d] + CPUSummary v0.1.30
  [d360d2e6] + ChainRulesCore v1.15.6
  [9e997f8a] + ChangesOfVariables v0.1.4
  [fb6a15b2] + CloseOpenIntervals v0.1.11
  [da1fd8a2] + CodeTracking v1.2.0
  [3da002f7] + ColorTypes v0.11.4
  [5ae59095] + Colors v0.12.10
  [bbf7d656] + CommonSubexpressions v0.3.0
  [34da2185] + Compat v4.5.0
  [adafc99b] + CpuId v0.3.1
  [f68482b8] + Cthulhu v2.7.6
  [163ba53b] + DiffResults v1.1.0
  [b552c78f] + DiffRules v1.12.2
  [ffbed154] + DocStringExtensions v0.9.3
  [5789e2e9] + FileIO v1.16.0
  [53c48c17] + FixedPointNumbers v0.8.4
  [08572546] + FlameGraphs v1.0.0
  [1eca21be] + FoldingTrees v1.2.1
  [f6369f11] + ForwardDiff v0.10.34
  [3e5b6fbb] + HostCPUFeatures v0.1.13
  [615f187c] + IfElse v0.1.1
  [9b13fd28] + IndirectArrays v1.0.0
  [3587e190] + InverseFunctions v0.1.8
  [92d709cd] + IrrationalConstants v0.1.1
  [c3a54625] + JET v0.6.21
  [692b3bcd] + JLLWrappers v1.4.1
  [aa1ae85d] + JuliaInterpreter v0.9.20
  [10f19ff3] + LayoutPointers v0.1.12
  [1d6d02ad] + LeftChildRightSiblingTrees v0.2.0
  [2ab3a3ac] + LogExpFunctions v0.3.19
  [bdcacae8] + LoopVectorization v0.12.143
  [6f1432cf] + LoweredCodeUtils v2.3.0
  [1914dd2f] + MacroTools v0.5.10
  [d125e4d3] + ManualMemory v0.1.8
  [77ba4419] + NaNMath v1.0.1
  [6fe1bfb0] + OffsetArrays v1.12.8
  [bac558e1] + OrderedCollections v1.4.1
  [1d0040c9] + PolyesterWeave v0.1.13
  [21216c6a] + Preferences v1.3.0
  [189a3867] + Reexport v1.2.2
  [ae029012] + Requires v1.3.0
  [295af30f] + Revise v3.4.0
  [3cdde19b] + SIMDDualNumbers v0.1.1
  [94e857df] + SIMDTypes v0.1.0
  [476501e8] + SLEEFPirates v0.6.37
  [aa65fe97] + SnoopCompile v2.9.6
  [e2b509da] + SnoopCompileCore v2.9.0
  [66db9d55] + SnoopPrecompile v1.0.1
  [276daf66] + SpecialFunctions v2.1.7
  [aedffcd0] + Static v0.8.3
  [90137ffa] + StaticArrays v1.5.12
  [1e83bf80] + StaticArraysCore v1.4.0
  [69024149] + StringEncodings v0.3.5
  [8290d209] + ThreadingUtilities v0.5.0
  [3a884ed6] + UnPack v1.0.2
  [3d5dd08c] + VectorizationBase v0.21.56
  [ddb6d928] + YAML v0.4.8
  [94ce4f54] + Libiconv_jll v1.16.1+2
  [efe28fd5] + OpenSpecFun_jll v0.5.5+0
  [0dad84c5] + ArgTools v1.1.1
  [56f22d72] + Artifacts
  [2a0f44e3] + Base64
  [ade2ca70] + Dates
  [8ba89e20] + Distributed
  [f43a241f] + Downloads v1.6.0
  [7b1f6079] + FileWatching
  [b77e0a4c] + InteractiveUtils
  [b27032c2] + LibCURL v0.6.3
  [76f85450] + LibGit2
  [8f399da3] + Libdl
  [37e2e46d] + LinearAlgebra
  [56ddb016] + Logging
  [d6f4376e] + Markdown
  [ca575930] + NetworkOptions v1.2.0
  [44cfe95a] + Pkg v1.8.0
  [de0858da] + Printf
  [9abbd945] + Profile
  [3fa0cd96] + REPL
  [9a3f8284] + Random
  [ea8e919c] + SHA v0.7.0
  [9e88b42a] + Serialization
  [6462fe0b] + Sockets
  [2f01184e] + SparseArrays
  [10745b16] + Statistics v1.9.0
  [4607b0f0] + SuiteSparse
  [fa267f1f] + TOML v1.0.3
  [a4e569a6] + Tar v1.10.0
  [8dfed614] + Test
  [cf7118a7] + UUIDs
  [4ec0a83e] + Unicode
  [e66e0078] + CompilerSupportLibraries_jll v1.0.2+0
  [deac9b47] + LibCURL_jll v7.84.0+0
  [29816b5a] + LibSSH2_jll v1.10.2+0
  [c8ffd9c3] + MbedTLS_jll v2.28.0+0
  [14a3606d] + MozillaCACerts_jll v2022.10.11
  [4536629a] + OpenBLAS_jll v0.3.21+0
  [05823500] + OpenLibm_jll v0.8.1+0
  [bea87d4a] + SuiteSparse_jll v5.10.1+0
  [83775a58] + Zlib_jll v1.2.13+0
  [8e850b90] + libblastrampoline_jll v5.2.0+0
  [8e850ede] + nghttp2_jll v1.48.0+0
  [3f19e933] + p7zip_jll v17.4.0+0
        Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated -m`

julia> using SnoopCompileCore; invalidations = @snoopr(using LoopVectorization); using SnoopCompile

julia> length(uinvalidated(invalidations))
ERROR: BoundsError: attempt to access 1860-element Vector{Any} at index [1861]
Stacktrace:
 [1] getindex
   @ ./essentials.jl:13 [inlined]
 [2] uinvalidated(invlist::Vector{Any}; exclude_corecompiler::Bool)
   @ SnoopCompile ~/.julia/packages/SnoopCompile/x8HIu/src/invalidations.jl:26
 [3] uinvalidated(invlist::Vector{Any})
   @ SnoopCompile ~/.julia/packages/SnoopCompile/x8HIu/src/invalidations.jl:22
 [4] top-level scope
   @ REPL[3]:1
chriselrod commented 1 year ago

The problem is if invlist[i+1] != "invalidate_mt_cache" which does not check if I + 1 is actually beyond the last element.

Yeah, while for (i, item) in enumerate(invlist)

https://github.com/timholy/SnoopCompile.jl/blob/4e00e2272a42712b4101d381add27384d40cb568/src/invalidations.jl#L24-L26 It'll throw a bounds error if the last item is a Core.MethodInstance. Was it an invariant that this wasn't the case in earlier versions?

https://github.com/JuliaSIMD/LoopVectorization.jl/actions/runs/3835627348/jobs/6529023176