Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cfunction issues #385

Closed
pfitzseb opened this issue Mar 30, 2020 · 3 comments
Closed

cfunction issues #385

pfitzseb opened this issue Mar 30, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@pfitzseb
Copy link
Member

pfitzseb commented Mar 30, 2020

Couldn't really find a MWE for this, but if I include this file (after adding Sundials, of course) and call

using JuliaInterpreter
@interpret solve(prob, ARKODE(),abstol=1e-8,reltol=1e-8)

I'm getting

MethodError: no method matching iterate(::Type{Int32})
Closest candidates are:
  iterate(!Matched::Core.SimpleVector) at essentials.jl:603
  iterate(!Matched::Core.SimpleVector, !Matched::Any) at essentials.jl:603
  iterate(!Matched::ExponentialBackOff) at error.jl:253
  ...
iterate at generator.jl:44 [inlined]
collect(::Base.Generator{DataType,JuliaInterpreter.var"#98#99"{JuliaInterpreter.FrameData,UnionAll}}) at array.jl:665
map(::Function, ::Type{T} where T) at abstractarray.jl:2098
evaluate_foreigncall(::Frame, ::Expr) at interpret.jl:165
eval_rhs(::Any, ::Frame, ::Expr) at interpret.jl:389
step_expr!(::Any, ::Frame, ::Any, ::Bool) at interpret.jl:527
step_expr! at interpret.jl:566 [inlined]
finish!(::Any, ::Frame, ::Bool) at commands.jl:14
finish_and_return! at commands.jl:29 [inlined]
evaluate_call_recurse!(::Any, ::Frame, ::Expr; enter_generated::Bool) at interpret.jl:240
evaluate_call_recurse! at interpret.jl:202 [inlined]
eval_rhs(::Any, ::Frame, ::Expr) at interpret.jl:387
step_expr!(::Any, ::Frame, ::Any, ::Bool) at interpret.jl:443
step_expr! at interpret.jl:566 [inlined]
finish!(::Any, ::Frame, ::Bool) at commands.jl:14
finish_and_return! at commands.jl:29 [inlined]
...

The stacktrace points to these lines, which apparently can't handle one of the @cfunctions in Sundials.jl.

@KristofferC KristofferC added the bug Something isn't working label Mar 30, 2020
@jtant
Copy link

jtant commented Sep 30, 2020

I am getting the same error using FunctionWrappers:

using JuliaInterpreter
using FunctionWrappers:FunctionWrapper
@interpret FunctionWrapper{Int,Tuple{}}(()->42)

@goerch
Copy link
Contributor

goerch commented Dec 8, 2021

using JuliaInterpreter
using FunctionWrappers:FunctionWrapper
@interpret FunctionWrapper{Int,Tuple{}}(()->42)

Interesting: if I modify evaluate_foreigncall like so:

function evaluate_foreigncall(frame::Frame, call_expr::Expr)
    head = call_expr.head
    args = collect_args(frame, call_expr; isfc = head==:foreigncall)
    for i = 2:length(args)
        arg = args[i]
        args[i] = isa(arg, Symbol) ? QuoteNode(arg) : arg
    end
    head === :cfunction && (args[2] = QuoteNode(args[2]))
    #= scope = frame.framecode.scope
    data = frame.framedata
    if !isempty(data.sparams) && scope isa Method
        sig = scope.sig
        args[2] = instantiate_type_in_env(args[2], sig, data.sparams)
        args[3] = Core.svec(map(args[3]) do arg
            instantiate_type_in_env(arg, sig, data.sparams)
        end...)
    end =#
    return Core.eval(moduleof(frame), Expr(head, args...))
end

I get

FunctionWrapper{Int64, Tuple{}}(Ptr{Nothing} @0x000000006445dfe0, Ptr{Nothing} @0x000000000c823ea0, Base.RefValue{var"#7#8"}(var"#7#8"()), var"#7#8")

and Pkg.test() still seems to work. Does anyone have a good idea, how to thoroughly test this change?

goerch added a commit to goerch/JuliaInterpreter.jl that referenced this issue Dec 8, 2021
Tested with both cases from the issue.
goerch added a commit to goerch/JuliaInterpreter.jl that referenced this issue Dec 8, 2021
@aviatesk
Copy link
Member

aviatesk commented Dec 10, 2021

if I modify evaluate_foreigncall like so:

Another tip: using diff syntax would make change more clearer.

@goerch goerch mentioned this issue Dec 11, 2021
goerch added a commit to goerch/JuliaInterpreter.jl that referenced this issue Dec 14, 2021
goerch added a commit to goerch/JuliaInterpreter.jl that referenced this issue Dec 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants