Roger-luo / Configurations.jl

Options & Configurations made easy.
https://configurations.rogerluo.dev/stable
MIT License
80 stars 12 forks source link

Fatal error in type inference with Pluto configuration #88

Closed adrhill closed 1 year ago

adrhill commented 1 year ago

I'm currently running into issues with Configurations.jl and Pluto (CC @fonsp).

When using PlutoSliderServer, I get fatal type inference errors:

julia> PlutoSliderServer.export_notebook("my_notebook.jl")
ERROR: fatal error in type inference (type bound)
Stacktrace:
  [1] foreach_keywords
    @ ~/.julia/packages/Configurations/uH65h/src/from_kwargs.jl:146 [inlined]
  [2] collect_underscore_keywords!(list::Vector{Symbol}, ::Type{Pluto.Configuration.CompilerOptions}, prefix::Symbol)
    @ Configurations ~/.julia/packages/Configurations/uH65h/src/from_kwargs.jl:180
...

I was able to narrow this down to Pluto's CompilerOptions

https://github.com/fonsp/Pluto.jl/blob/f3d8946dd2743e605418d73cead26e6fcd79d11f/src/Configuration.jl#L231-L255

which can be called with default arguments:

julia> Pluto.Configuration.CompilerOptions()
Pluto.Configuration.CompilerOptions(nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, "no", "no", "4")

However, using Configurations.from_kwargs on this option appears to be the source of this error:

julia> Configurations.from_kwargs(Pluto.Configuration.CompilerOptions)
ERROR: fatal error in type inference (type bound)
Stacktrace:
  [1] foreach_keywords
    @ ~/.julia/packages/Configurations/uH65h/src/from_kwargs.jl:146 [inlined]
  [2] collect_underscore_keywords! (repeats 2 times)
    @ ~/.julia/packages/Configurations/uH65h/src/from_kwargs.jl:180 [inlined]
  [3] underscore_keywords(#unused#::Type{Pluto.Configuration.CompilerOptions})
    @ Configurations ~/.julia/packages/Configurations/uH65h/src/from_kwargs.jl:138
  [4] #from_underscore_kwargs!#25
    @ ~/.julia/packages/Configurations/uH65h/src/from_kwargs.jl:57 [inlined]
  [5] from_underscore_kwargs! (repeats 2 times)
    @ ~/.julia/packages/Configurations/uH65h/src/from_kwargs.jl:54 [inlined]
  [6] from_kwargs(convention!::typeof(Configurations.from_underscore_kwargs!), ::Type{Pluto.Configuration.CompilerOptions}; kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Configurations ~/.julia/packages/Configurations/uH65h/src/from_kwargs.jl:14
  [7] from_kwargs
    @ ~/.julia/packages/Configurations/uH65h/src/from_kwargs.jl:12 [inlined]
  [8] #from_underscore_kwargs#22
    @ ~/.julia/packages/Configurations/uH65h/src/from_kwargs.jl:31 [inlined]
  [9] from_underscore_kwargs
    @ ~/.julia/packages/Configurations/uH65h/src/from_kwargs.jl:30 [inlined]
 [10] #from_kwargs#21
    @ ~/.julia/packages/Configurations/uH65h/src/from_kwargs.jl:23 [inlined]
 [11] from_kwargs(::Type{Pluto.Configuration.CompilerOptions})
    @ Configurations ~/.julia/packages/Configurations/uH65h/src/from_kwargs.jl:23
 [12] top-level scope
    @ REPL[52]:1

Dependencies ``` Status `~/Developer/julia-ml-course/Project.toml` [5218b696] Configurations v0.17.4 [713c75ef] Franklin v0.10.79 [c3e4b0f8] Pluto v0.19.22 [2fc8631c] PlutoSliderServer v0.3.21 ```
Version Info ``` Julia Version 1.9.0-rc1 Commit 3b2e0d8fbc1 (2023-03-07 07:51 UTC) Platform Info: OS: macOS (x86_64-apple-darwin21.4.0) CPU: 16 × Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz WORD_SIZE: 64 LIBM: libopenlibm LLVM: libLLVM-14.0.6 (ORCJIT, skylake) Threads: 4 on 8 virtual cores Environment: JULIA_NUM_THREADS = 4 ```

Filed using BrowserMacros.jl

adrhill commented 1 year ago

It appears that this only happens on Julia 1.9.

Julia 1.8.5 with the same packages runs fine:

julia> versioninfo()
Julia Version 1.8.5
Commit 17cfb8e65ea (2023-01-08 06:45 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin21.4.0)
  CPU: 16 × Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, skylake)
  Threads: 4 on 8 virtual cores
Environment:
  JULIA_NUM_THREADS = 4

julia> using Pluto, Configurations

(test) pkg> status
Status `~/Developer/test/Project.toml`
  [5218b696] Configurations v0.17.4
  [713c75ef] Franklin v0.10.79
  [c3e4b0f8] Pluto v0.19.22
  [2fc8631c] PlutoSliderServer v0.3.21

julia> Configurations.from_kwargs(Pluto.Configuration.CompilerOptions)
key = underscore(prefix, name) = :compile
key = underscore(prefix, name) = :pkgimages
key = underscore(prefix, name) = :compiled_modules
key = underscore(prefix, name) = :sysimage
key = underscore(prefix, name) = :sysimage_native_code
key = underscore(prefix, name) = :banner
key = underscore(prefix, name) = :depwarn
key = underscore(prefix, name) = :optimize
key = underscore(prefix, name) = :min_optlevel
key = underscore(prefix, name) = :inline
key = underscore(prefix, name) = :check_bounds
key = underscore(prefix, name) = :math_mode
key = underscore(prefix, name) = :startup_file
key = underscore(prefix, name) = :history_file
key = underscore(prefix, name) = :threads
Pluto.Configuration.CompilerOptions(nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, "no", "no", "4")
Roger-luo commented 1 year ago

It seems to be a regression of 1.9 then?

adrhill commented 1 year ago

Yes, I think so.

Roger-luo commented 1 year ago

It's probably better to cross post this issue at Julia repo then, I think I don't have the knowledge of fixing a type inference failure. Thanks!

fonsp commented 1 year ago

https://github.com/JuliaLang/julia/issues/49103

fonsp commented 1 year ago

Fixed in Julia 1.9.0-rc2