yuyichao / FunctionWrappers.jl

Other
103 stars 10 forks source link

error in julia v0.7 #8

Closed chkwon closed 3 years ago

chkwon commented 6 years ago

I'm trying to update PATHSolver.jl for 0.7 compatibility. See https://github.com/chkwon/PATHSolver.jl/pull/28

When it is tested with FunctionWrappers.jl version 0.1.0, it passes test on travis (of course there are many warnings, etc.). See https://travis-ci.org/chkwon/PATHSolver.jl/jobs/415490117

When it tested with the master branch of FunctionWrappers.jl (which is tagged as v1.0.0), I obtain the following errors:

Path 4.7.03 (Thu Jan 24 15:44:12 2013)
Written by Todd Munson, Steven Dirkse, and Michael Ferris
linear complementarity problem: Error During Test at /Users/chkwon/.julia/dev/PATHSolver/test/lcp.jl:1
  Got exception TypeError(:CallWrapper, "cfunction", Core.Compiler.Const(not_int, false), [2.0, 2.0, -2.0, -6.0]) outside of a @test
  TypeError: in CallWrapper, in cfunction, expected Core.Compiler.Const(not_int, false), got Array{Float64,1}
  Stacktrace:
   [1] macro expansion at /Users/chkwon/.julia/packages/FunctionWrappers/mJrYu/src/FunctionWrappers.jl:111 [inlined]
   [2] do_ccall at /Users/chkwon/.julia/packages/FunctionWrappers/mJrYu/src/FunctionWrappers.jl:102 [inlined]
   [3] FunctionWrapper at /Users/chkwon/.julia/packages/FunctionWrappers/mJrYu/src/FunctionWrappers.jl:118 [inlined]
   [4] f_user_wrap(::Int32, ::Ptr{Float64}, ::Ptr{Float64}) at /Users/chkwon/.julia/dev/PATHSolver/src/PATHSolver.jl:53
Test Summary:                  | Error  Total
linear complementarity problem |     1      1
ERROR: LoadError: LoadError: Some tests did not pass: 0 passed, 0 failed, 1 errored, 0 broken.
in expression starting at /Users/chkwon/.julia/dev/PATHSolver/test/lcp.jl:1
in expression starting at /Users/chkwon/.julia/dev/PATHSolver/test/runtests.jl:6
ERROR: Package PATHSolver errored during testing

Any thought?

yuyichao commented 6 years ago

Couldn't reproduce locally, saw a few times on appveyor too. Seems to be a compiler bug afaict.

chkwon commented 6 years ago
(v0.7) pkg> add FunctionWrappers#master
  Updating git-repo `https://github.com/yuyichao/FunctionWrappers.jl.git`
 Resolving package versions...
  Updating `~/.julia/environments/v0.7/Project.toml`
  [069b7b12] + FunctionWrappers v0.1.0+ #master (https://github.com/yuyichao/FunctionWrappers.jl.git)
  Updating `~/.julia/environments/v0.7/Manifest.toml`
  [069b7b12] ↑ FunctionWrappers v0.1.0 ⇒ v0.1.0+ #master (https://github.com/yuyichao/FunctionWrappers.jl.git)

(v0.7) pkg> add PATHSolver#v0.7
(v0.7) pkg> test PATHSolver

results in

Path 4.7.03 (Wed May 28 13:11:13 2014)
Written by Todd Munson, Steven Dirkse, and Michael Ferris
linear complementarity problem: Error During Test at /home/chkwon/.julia/packages/PATHSolver/2goqH/test/lcp.jl:1
  Got exception TypeError(:CallWrapper, "cfunction", Core.Compiler.Pair{Int64,Any}(179, :((Base.slt_int)(%178, 0))), [2.0, 2.0, -2.0, -6.0]) outside of a @test
  TypeError: in CallWrapper, in cfunction, expected Core.Compiler.Pair{Int64,Any}(179, :((Base.slt_int)(%178, 0))), got Array{Float64,1}
  Stacktrace:
   [1] macro expansion at /home/chkwon/.julia/packages/FunctionWrappers/mJrYu/src/FunctionWrappers.jl:111 [inlined]
   [2] do_ccall at /home/chkwon/.julia/packages/FunctionWrappers/mJrYu/src/FunctionWrappers.jl:102 [inlined]
   [3] FunctionWrapper at /home/chkwon/.julia/packages/FunctionWrappers/mJrYu/src/FunctionWrappers.jl:118 [inlined]
   [4] f_user_wrap(::Int32, ::Ptr{Float64}, ::Ptr{Float64}) at /home/chkwon/.julia/packages/PATHSolver/2goqH/src/PATHSolver.jl:53
   [5] #solveLCP#8(::Bool, ::Function, ::Function, ::Array{Int64,2}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{String,1}, ::Array{String,1}) at /home/chkwon/.julia/packages/PATHSolver/2goqH/src/PATHSolver.jl:284
   [6] #solveLCP at ./none:0 [inlined]
   [7] #solveLCP#7 at /home/chkwon/.julia/packages/PATHSolver/2goqH/src/PATHSolver.jl:238 [inlined]
   [8] solveLCP at /home/chkwon/.julia/packages/PATHSolver/2goqH/src/PATHSolver.jl:238 [inlined] (repeats 3 times)
   [9] macro expansion at /home/chkwon/.julia/packages/PATHSolver/2goqH/test/lcp.jl:15 [inlined]
   [10] macro expansion at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v0.7/Test/src/Test.jl:1079 [inlined]
   [11] top-level scope at /home/chkwon/.julia/packages/PATHSolver/2goqH/test/lcp.jl:2
   [12] include at ./boot.jl:317 [inlined]
   [13] include_relative(::Module, ::String) at ./loading.jl:1038
   [14] include(::Module, ::String) at ./sysimg.jl:29
   [15] include(::String) at ./client.jl:398
   [16] top-level scope at none:0
   [17] include at ./boot.jl:317 [inlined]
   [18] include_relative(::Module, ::String) at ./loading.jl:1038
   [19] include(::Module, ::String) at ./sysimg.jl:29
   [20] include(::String) at ./client.jl:398
   [21] top-level scope at none:0
   [22] eval(::Module, ::Any) at ./boot.jl:319
   [23] macro expansion at ./logging.jl:317 [inlined]
   [24] exec_options(::Base.JLOptions) at ./client.jl:229
   [25] _start() at ./client.jl:432

I tested in both macos and ubuntu. I'm not sure what you mean by a complier bug.

yuyichao commented 6 years ago

It's a base bug.

tkoolen commented 6 years ago

As a very temporary workaround, you could use the tk/julia-0.7-quickfix branch on my fork.

chkwon commented 6 years ago

@tkoolen Thanks! I'll try.

tkoolen commented 6 years ago

I was seeing the same issue in Parametron.jl. I've reduced it down to the following self-contained example:

module Parametron2

using FunctionWrappers: FunctionWrapper

struct LazyExpression{F, A}
    f::F
    args::A
    LazyExpression(f::F, args...) where {F} = new{F, typeof(args)}(f, args)
end

# Evaluation
@inline evalarg(x) = x
@inline evalarg(x::LazyExpression) = x()
@inline (expr::LazyExpression{F, A})() where {F, A} = evalexpr(expr.f, expr.args)
@generated function evalexpr(f::F, args::Tuple{Vararg{Any, N}}) where {F, N}
    # equivalent to f(map(evalarg, args)...), minus the inference issues
    argexprs = [:(evalarg(args[$i])) for i = 1 : N]
    quote
        Base.@_inline_meta
        f($(argexprs...))
    end
end

# Wrapping
const WrappedExpression{T} = LazyExpression{FunctionWrapper{T, Tuple{}}, Tuple{}}

Base.convert(::Type{WrappedExpression{T}}, expr::LazyExpression) where {T} =
    LazyExpression(FunctionWrapper{T, Tuple{}}(expr))

function wrap(expr::Parametron2.LazyExpression)
    T = typeof(expr())
    convert(Parametron2.WrappedExpression{T}, expr)
end

end

module M

import Main.Parametron2

f1 = [1]
converted = Parametron2.wrap(Parametron2.LazyExpression(convert, Vector{Float64}, f1))
converted.f()

end

result:

ERROR: LoadError: TypeError: in CallWrapper, in cfunction, expected Core.Compiler.UseRef(nothing, 0), got Array{Float64,1}
Stacktrace:
 [1] macro expansion at /Users/twan/.julia/packages/FunctionWrappers/mJrYu/src/FunctionWrappers.jl:111 [inlined]
 [2] do_ccall at /Users/twan/.julia/packages/FunctionWrappers/mJrYu/src/FunctionWrappers.jl:102 [inlined]
 [3] (::FunctionWrappers.FunctionWrapper{Array{Float64,1},Tuple{}})() at /Users/twan/.julia/packages/FunctionWrappers/mJrYu/src/FunctionWrappers.jl:118
 [4] top-level scope at none:0
 [5] include at ./boot.jl:317 [inlined]
 [6] include_relative(::Module, ::String) at ./loading.jl:1038
 [7] include(::Module, ::String) at ./sysimg.jl:29
 [8] include(::String) at ./client.jl:398
 [9] top-level scope at none:0
in expression starting at /Users/twan/code/julia-projects/parametron/test.jl:43

This is on

julia> versioninfo()
Julia Version 0.7.0
Commit a4cb80f3ed (2018-08-08 06:46 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin14.5.0)
  CPU: Intel(R) Core(TM) i7-3820QM CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, ivybridge)

~Julia 1.0.0 doesn't appear to show the same issue for this example. The problem is still present in 1.0 for my original use case though.~ Problem does appear on 1.0 if you paste into the REPL. It's a bit flaky.

vtjnash commented 3 years ago

Suggest closing as this version is unsupported?