Gtk.jl fails to precompile with Julia v1.7.0-beta2

Gtk.jl fails to precompile with julia v1.7.0-beta2. This is under Windows (Win10) and Linux (OpenSUSE Leap 15.2).

In both systems, I have a clean install, with the addition of Gtk:

(@v1.7) pkg> st
      Status `C:\Users\xxx\.julia\environments\v1.7\Project.toml`
  [4c0ca9eb] Gtk v1.1.7

I’ve been using the same version of Gtk with Julia v1.6.1, and can still do so. While the errors are almost certainly a result of changes in Julia, I don’t know whether that means there’s and error with Julia, or whether Gtk will need to be modified to adapt.

I’m happy to report to Julia directly, or to Gtk.jl, but don’t understand the problem well enough to know which is more appropriate.

Details of the output from precompilation follow:

All dependent packages of Gtk precompile successfully. If I then run

using Pkg(); Pkg.precompile()

the output is

Precompiling project...
  ✗ Gtk
  0 dependencies successfully precompiled in 21 seconds (74 already precompiled)

ERROR: The following 1 direct dependency failed to precompile:

Gtk [4c0ca9eb-093a-5379-98c5-f87ac0bbbf44]

Failed to precompile Gtk [4c0ca9eb-093a-5379-98c5-f87ac0bbbf44] to C:\Users\xxx\.julia\compiled\v1.7\Gtk\jl_7ACB.tmp.
ERROR: LoadError: TypeError: in ccall method definition, expected Type, got a value of type TypeVar
  [1] top-level scope
    @ C:\Users\xxx\.julia\packages\Gtk\3TfRG\src\GLib\signals.jl:331
  [2] include(mod::Module, _path::String)
    @ Base .\Base.jl:417
  [3] include(x::String)
    @ Gtk.GLib C:\Users\xxx\.julia\packages\Gtk\3TfRG\src\GLib\GLib.jl:1
  [4] top-level scope
    @ C:\Users\xxx\.julia\packages\Gtk\3TfRG\src\GLib\GLib.jl:62
  [5] include(mod::Module, _path::String)
    @ Base .\Base.jl:417
  [6] include(x::String)
    @ Gtk C:\Users\xxx\.julia\packages\Gtk\3TfRG\src\Gtk.jl:2
  [7] top-level scope
    @ C:\Users\xxx\.julia\packages\Gtk\3TfRG\src\Gtk.jl:17
  [8] include
    @ .\Base.jl:417 [inlined]
  [9] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::Nothing)
    @ Base .\loading.jl:1318
 [10] top-level scope
    @ none:1
 [11] eval
    @ .\boot.jl:373 [inlined]
 [12] eval(x::Expr)
    @ Base.MainInclude .\client.jl:453
 [13] top-level scope
    @ none:1
in expression starting at C:\Users\xxx\.julia\packages\Gtk\3TfRG\src\GLib\signals.jl:331
in expression starting at C:\Users\xxx\.julia\packages\Gtk\3TfRG\src\GLib\GLib.jl:1
in expression starting at C:\Users\xxx\.julia\packages\Gtk\3TfRG\src\Gtk.jl:2
 [1] pkgerror(msg::String)
   @ Pkg.Types C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.7\Pkg\src\Types.jl:68
 [2] precompile(ctx::Pkg.Types.Context; internal_call::Bool, strict::Bool, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ Pkg.API C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.7\Pkg\src\API.jl:1352
 [3] precompile
   @ C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.7\Pkg\src\API.jl:1006 [inlined]
 [4] #precompile#220
   @ C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.7\Pkg\src\API.jl:1004 [inlined]
 [5] precompile()
   @ Pkg.API C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.7\Pkg\src\API.jl:1004
 [6] top-level scope
   @ REPL[4]:1

The function at line 331 of signals.jl is

function uv_dispatch(src::Ptr{Nothing}, callback::Ptr{Nothing}, data::T) where T
    return ccall(callback, Cint, (T,), data)

I don’t know whether it’s relevant, but the only reference to the function name in the package is later in the same file:

@cfunction(uv_dispatch, Cint, (Ptr{Nothing}, Ptr{Nothing}, Int))

That’s a bug in Julia, not Gtk.jl. Can you create an issue on Github? The relevant part is the function definition

function uv_dispatch(src::Ptr{Nothing}, callback::Ptr{Nothing}, data::T) where T
    return ccall(callback, Cint, (T,), data)

which should work fine but errors in 1.7 and on master.

Thanks for the advice. I have opened an issue.

This is not a bug with Julia, parameters layout is not allowed to change in ccall. Not sure if that was changed or just more strictly enforced in v1.7 :

As for fixing it, I think there’s something wrong with Gtk.jl use of that dispatch function (type of data should be constant) but nobody understands that code very well (it allows for the REPL not to be blocked by Gtk’s main loop), so maybe we’ll have to hack our way around the compiler restriction with :

@generated function uv_dispatch(src::Ptr{Nothing}, callback::Ptr{Nothing}, data) 
    :( return ccall(callback, Cint, ($(data),), data) )

Which seems to restore v1.6 behavior (might be wrong, but it works).

1 Like

This has already been reported to GTK: GTK fails to precompile against master: ccall - type - typevar · Issue #573 · JuliaGraphics/Gtk.jl · GitHub.

Thank you all for your feedback. I realise now that it had also been reported as Julia issue #41278.