Keno / ASTInterpreter.jl

Gallium's AST interpreter as a separate package to simplify development
Other
16 stars 10 forks source link

Weird module scoping(?) in ``@enter`` #46

Closed joehuchette closed 8 years ago

joehuchette commented 8 years ago

Sorry for the uninformative title, but I can't wrap my head around this. using the ForwardDiff package seems to break ASTInterpreter completely:

julia> using Gallium

julia> macroexpand(:(@enter 1+1))
quote  # /Users/huchette/.julia/v0.5/ASTInterpreter/src/ASTInterpreter.jl, line 1451:
    #1#theargs = (+,1,1) # /Users/huchette/.julia/v0.5/ASTInterpreter/src/ASTInterpreter.jl, line 1452:
    ASTInterpreter.ASTInterpreter.RunDebugREPL(ASTInterpreter.ASTInterpreter.enter_call_expr(ASTInterpreter.nothing,ASTInterpreter.Expr(:call,#1#theargs...)))
end

julia> using ForwardDiff

julia> macroexpand(:(@enter 1+1))
:($(Expr(:error, MethodError(ForwardDiff.data,(:+,)))))

julia> macroexpand(:(@enter a[2]))
:($(Expr(:error, MethodError(ForwardDiff.data,(:a,)))))

This is on ASTInterpreter/Gallium master (as of this morning), and ForwardDiff v0.1.6. Note that I don't see this behavior on ForwardDiff master. This doesn't happen for other modules I've tested, e.g. DataStructures.

Also, ForwardDiff has a data function, but it's not exported. I'm guessing this is the culprit somehow.

Keno commented 8 years ago

Probably a macro hygine issue. Will take a look.

Keno commented 8 years ago

ForwardDiff globally overrides iteration, which is a big no-no:

start(partials) = start(data(partials))
next(partials, i) = next(data(partials), i)
done(partials, i) = done(data(partials), i)

Also you can use Gallium.breakpoint_on_error to debug this ;).

joehuchette commented 8 years ago

Cool, thanks for the tip. cc @mlubin @jrevels

mlubin commented 8 years ago

That's fixed but not tagged: https://github.com/JuliaDiff/ForwardDiff.jl/commit/5c5903fa5b6bd184d3da902ba3d0e71d134aaa83