fonsp / Pluto.jl

🎈 Simple reactive notebooks for Julia
https://plutojl.org/
MIT License
4.91k stars 284 forks source link

Nightly tests: overload of Base function not recovered #2806

Closed fonsp closed 5 months ago

fonsp commented 5 months ago

On Julia nightly, it looks like we are unable to restore an overloaded Base function:

https://github.com/fonsp/Pluto.jl/actions/runs/7761348184/job/21169580988#step:5:1320

We should check whether this is the case in general, or if something else is up with this particular test.

If so, oh ohh... maybe we need to get in touch with the Julia devs before this gets released and we lose the ability to reset base overloads? That would be a big bummer.

fonsp commented 5 months ago

Looks like a problem!


julia> typeof(Base.tan).name.mt
# 13 methods for generic function "tan" from Base:
  [1] tan(a::ComplexF16)
     @ Base.Math math.jl:1584
  [2] tan(::Missing)
     @ Base.Math math.jl:1605
  [3] tan(x::BigFloat)
     @ Base.MPFR mpfr.jl:860
  [4] tan(a::Float16)
     @ Base.Math math.jl:1583
  [5] tan(::Irrational{:Ï€})
     @ Base.MathConstants mathconstants.jl:129
  [6] tan(x::Real)
     @ Base.Math math.jl:1600
  [7] tan(D::LinearAlgebra.Diagonal)
     @ LinearAlgebra /Applications/Julia-1.11.app/Contents/Resources/julia/share/julia/stdlib/v1.11/LinearAlgebra/src/diagonal.jl:720
  [8] tan(z::Complex)
     @ complex.jl:932
  [9] tan(J::LinearAlgebra.UniformScaling)
     @ LinearAlgebra /Applications/Julia-1.11.app/Contents/Resources/julia/share/julia/stdlib/v1.11/LinearAlgebra/src/uniformscaling.jl:173
 [10] tan(A::AbstractMatrix)
     @ LinearAlgebra /Applications/Julia-1.11.app/Contents/Resources/julia/share/julia/stdlib/v1.11/LinearAlgebra/src/dense.jl:1125
 [11] tan(A::LinearAlgebra.Hermitian{var"#s128", S} where {var"#s128"<:Complex, S<:(AbstractMatrix{<:var"#s128"})})
     @ LinearAlgebra /Applications/Julia-1.11.app/Contents/Resources/julia/share/julia/stdlib/v1.11/LinearAlgebra/src/symmetric.jl:694
 [12] tan(A::Union{LinearAlgebra.Hermitian{var"#s1110", S}, LinearAlgebra.Symmetric{var"#s1110", S}} where {var"#s1110"<:Real, S})
     @ LinearAlgebra /Applications/Julia-1.11.app/Contents/Resources/julia/share/julia/stdlib/v1.11/LinearAlgebra/src/symmetric.jl:690
 [13] tan(x::T) where T<:Union{Float32, Float64}
     @ Base.Math special/trig.jl:216

julia> Base.tan(::Missing) = 222

julia> tan(missing)
222

julia> f = tan
tan (generic function with 13 methods)

julia> methods_table = typeof(f).name.mt
# 14 methods for generic function "tan" from Base:
  [1] tan(a::ComplexF16)
     @ Base.Math math.jl:1584
  [2] tan(::Missing)
     @ Main REPL[3]:1
  [3] tan(::Missing)
     @ Base.Math math.jl:1605
  [4] tan(x::BigFloat)
     @ Base.MPFR mpfr.jl:860
  [5] tan(a::Float16)
     @ Base.Math math.jl:1583
  [6] tan(::Irrational{:Ï€})
     @ Base.MathConstants mathconstants.jl:129
  [7] tan(x::Real)
     @ Base.Math math.jl:1600
  [8] tan(D::LinearAlgebra.Diagonal)
     @ LinearAlgebra /Applications/Julia-1.11.app/Contents/Resources/julia/share/julia/stdlib/v1.11/LinearAlgebra/src/diagonal.jl:720
  [9] tan(z::Complex)
     @ complex.jl:932
 [10] tan(J::LinearAlgebra.UniformScaling)
     @ LinearAlgebra /Applications/Julia-1.11.app/Contents/Resources/julia/share/julia/stdlib/v1.11/LinearAlgebra/src/uniformscaling.jl:173
 [11] tan(A::AbstractMatrix)
     @ LinearAlgebra /Applications/Julia-1.11.app/Contents/Resources/julia/share/julia/stdlib/v1.11/LinearAlgebra/src/dense.jl:1125
 [12] tan(A::LinearAlgebra.Hermitian{var"#s128", S} where {var"#s128"<:Complex, S<:(AbstractMatrix{<:var"#s128"})})
     @ LinearAlgebra /Applications/Julia-1.11.app/Contents/Resources/julia/share/julia/stdlib/v1.11/LinearAlgebra/src/symmetric.jl:694
 [13] tan(A::Union{LinearAlgebra.Hermitian{var"#s1110", S}, LinearAlgebra.Symmetric{var"#s1110", S}} where {var"#s1110"<:Real, S})
     @ LinearAlgebra /Applications/Julia-1.11.app/Contents/Resources/julia/share/julia/stdlib/v1.11/LinearAlgebra/src/symmetric.jl:690
 [14] tan(x::T) where T<:Union{Float32, Float64}
     @ Base.Math special/trig.jl:216

julia> Base.visit(methods_table) do method
           if occursin("REPL", String(method.file))
               @info "Deleting" method
               Base.delete_method(method)
           end
       end
┌ Info: Deleting
│   method = tan(::Missing) @ Main REPL[3]:1
â”” @ Main REPL[13]:3

julia> tan(missing)
ERROR: MethodError: no method matching tan(::Missing)
The function `tan` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  tan(::ComplexF16)
   @ Base math.jl:1584
  tan(::BigFloat)
   @ Base mpfr.jl:860
  tan(::Float16)
   @ Base math.jl:1583
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[15]:1

julia> tan
tan (generic function with 12 methods)
fonsp commented 5 months ago

Ah easy! It was in the error message:

ERROR: LoadError: ConcurrencyViolationError("setfield!: atomic field cannot be written non-atomically")

from this line

https://github.com/fonsp/Pluto.jl/blob/7566d3587586b5bbdc2bd593c5a78c36fd75dc3f/src/runner/PlutoRunner/src/PlutoRunner.jl#L820

So this was caused by https://github.com/JuliaLang/julia/pull/52997

Fix is to add @atomic :)

vtjnash commented 5 months ago

This field is @atomic because changing it will incur a huge amount of Undefined Behavior in the compiler and runtime, as these are tracked by identity in many places, so reinsertion requires copying them first (so that they get a new pointer for the runtime to track)