From df40bab2dadf6ad46b822e5ea3e71ac3ee238628 Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Tue, 28 Nov 2023 13:19:12 +0100 Subject: [PATCH] fix invalidations related to `ismutable` (#52170) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Related to #52134. It would be nice if the underlying inference issue was fixed but this seems to be a hotfix for now. I have seen this inference problem occurring in Julia v1.9, v1.10, and current `master`. For example, on Julia v1.9.3, I get ```julia julia> code_warntype(ismutable, (Function,)) MethodInstance for ismutable(::Function) from ismutable(x) @ Base reflection.jl:521 Arguments #self#::Core.Const(ismutable) x::Function Body::Any 1 ─ nothing │ nothing │ %3 = Base.typeof(x)::Type{<:Function} │ %4 = Base.getproperty(%3, :name)::Any │ %5 = Base.getproperty(%4, :flags)::Any │ %6 = (%5 & 0x02)::Any │ %7 = (%6 == 0x02)::Any └── return %7 ``` This causes some invalidations when `using OrdinaryDiffEq`. --- base/reflection.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/base/reflection.jl b/base/reflection.jl index 4d59942cf4013..19dd289efbebf 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -627,7 +627,9 @@ true !!! compat "Julia 1.5" This function requires at least Julia 1.5. """ -ismutable(@nospecialize(x)) = (@_total_meta; typeof(x).name.flags & 0x2 == 0x2) +ismutable(@nospecialize(x)) = (@_total_meta; (typeof(x).name::Core.TypeName).flags & 0x2 == 0x2) +# The type assertion above is required to fix some invalidations. +# See also https://github.com/JuliaLang/julia/issues/52134 """ ismutabletype(T) -> Bool