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

MWE for broken using #129

Closed
macd opened this issue Mar 12, 2019 · 3 comments
Closed

MWE for broken using #129

macd opened this issue Mar 12, 2019 · 3 comments

Comments

@macd
Copy link
Contributor

macd commented Mar 12, 2019

Current build seems to have broken the using command.

using JuliaInterpreter
include("utils.jl")

module m
    using Test
end

ex = quote
    using Random
end

frame = JuliaInterpreter.prepare_thunk(m, ex)
JuliaInterpreter.finish_and_return!(frame)

This causes

macd@mlap:~/jlang/dev/JuliaInterpreter.jl/test$ julia randtest.jl
ERROR: Error while loading expression starting at /home/macd/jlang/dev/JuliaInterpreter.jl/test/randtest.jl:14
caused by [exception 1]
invalid lookup expr using Random
Stacktrace:
 [1] error(::String, ::Expr) at ./error.jl:42
 [2] eval_rhs(::Any, ::Frame, ::Expr) at /home/macd/jlang/dev/JuliaInterpreter.jl/src/interpret.jl:21
 [3] step_expr!(::Any, ::Frame, ::Any, ::Bool) at /home/macd/jlang/dev/JuliaInterpreter.jl/src/interpret.jl:478
 [4] step_expr! at /home/macd/jlang/dev/JuliaInterpreter.jl/src/interpret.jl:517 [inlined]
 [5] finish!(::Any, ::Frame, ::Bool) at /home/macd/jlang/dev/JuliaInterpreter.jl/src/commands.jl:14
 [6] finish_and_return! at /home/macd/jlang/dev/JuliaInterpreter.jl/src/commands.jl:29 [inlined]
 [7] finish_and_return! at /home/macd/jlang/dev/JuliaInterpreter.jl/src/commands.jl:33 [inlined] (repeats 2 times)
 [8] top-level scope at /home/macd/jlang/dev/JuliaInterpreter.jl/test/randtest.jl:14
 [9] include at ./boot.jl:325 [inlined]
 [10] include_relative(::Module, ::String) at ./loading.jl:1042
 [11] include(::Module, ::String) at ./Base.jl:29
 [12] exec_options(::Base.JLOptions) at ./client.jl:295
 [13] _start() at ./client.jl:464
@KristofferC
Copy link
Member

Since this is a toplevel expression you would AFAIU need

JuliaInterpreter.finish_and_return!(frame, true)

and this then works fine. Does this error somewhere when interpreting a working julia file?

@macd
Copy link
Contributor Author

macd commented Mar 13, 2019

Hmm, yes, I can see that now but it feels like this was working last week. Does this mean that you can only ever call using in main? If module m is defined, you cannot m.eval(:(using Random)) ?
What is now failing, because it needs to run at the top level, is the code from #13, ie:

include("utils.jl")
const juliadir = dirname(dirname(Sys.BINDIR))
const testdir = joinpath(juliadir, "test")
configure_test()
nstmts = 10000
run_test_by_eval("ambiguous", joinpath(testdir, "ambiguous.jl"), nstmts)

If that is now a limitation, how should I run the individual tests?

@timholy
Copy link
Member

timholy commented Mar 13, 2019

That's what the split_expressions loop is about. The key points:

  • some code must be run at top-level. That's why you can't safely put that loop inside a function. (It will work for things that don't require top-level, but this is a case that does.) See
    Core.eval(Main, Expr(:toplevel, :(module JuliaTests using Test, Random end), quote
    # These must be run at top level, so we can't put this in a function
  • to be completely safe, expressions need to be split apart and evaluated sequentially. Lowering doesn't do this automatically for you: if one quote...end block both defines a new macro and then uses it for later stuff, you'll get an error if you try to lower it as a complete block (because lowering does macro-expansion). You have to split it into pieces, evaluate the macro-defining part first, return to toplevel, and the evaluate any code that uses the macro.

All this happens automatically behind the scenes for you with ordinary Julia sessions, but when you're creating a parallel evaluation mechanism you have to face it a bit more directly.

@macd macd closed this as completed Mar 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants