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

Implementing the change proposed in #502 #503

Merged
merged 11 commits into from
Dec 13, 2021

Conversation

goerch
Copy link
Contributor

@goerch goerch commented Dec 8, 2021

No description provided.

@goerch goerch changed the title Implementing change proposed #502 Implementing change proposed in #502 Dec 8, 2021
@goerch goerch changed the title Implementing change proposed in #502 Implementing the change proposed in #502 Dec 8, 2021
@codecov
Copy link

codecov bot commented Dec 8, 2021

Codecov Report

Merging #503 (27134da) into master (10fd8fc) will increase coverage by 0.76%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #503      +/-   ##
==========================================
+ Coverage   82.76%   83.53%   +0.76%     
==========================================
  Files          12       12              
  Lines        2443     2447       +4     
==========================================
+ Hits         2022     2044      +22     
+ Misses        421      403      -18     
Impacted Files Coverage Δ
src/precompile.jl 0.00% <0.00%> (ø)
src/interpret.jl 76.07% <93.33%> (+4.09%) ⬆️
src/types.jl 73.24% <100.00%> (ø)
src/utils.jl 85.10% <0.00%> (+0.23%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 10fd8fc...27134da. Read the comment docs.

src/types.jl Outdated Show resolved Hide resolved
Co-authored-by: Kristoffer Carlsson <[email protected]>
@goerch goerch requested a review from KristofferC December 8, 2021 15:13
src/types.jl Outdated Show resolved Hide resolved
src/types.jl Outdated Show resolved Hide resolved
@aviatesk
Copy link
Member

We want to add testcase that demonstrates how these added option can be used. I just come up with something like this:

@testset "interpretation of unoptimized frame" begin
    let # should be able to interprete nested calls within `:foreigncall` expressions
        # even if `JuliaInterpreter.optimize!` doesn't flatten them
        M = Module()
        lwr = Meta.@lower M begin
            global foo = @ccall strlen("foo"::Cstring)::Csize_t
            foo == 3
        end
        src = lwr.args[1]::Core.CodeInfo
        frame = Frame(M, src; optimize=false)
        @test length(frame.framecode.src.code) == length(src.code)
        @test JuliaInterpreter.finish_and_return!(frame, true)

        M = Module()
        lwr = Meta.@lower M begin
            strp = Ref{Ptr{Cchar}}(0)
            fmt = "hi+%hhd-%hhd-%hhd-%hhd-%hhd-%hhd-%hhd-%hhd-%hhd-%hhd-%hhd-%hhd-%hhd-%hhd-%hhd-%.1f-%.1f-%.1f-%.1f-%.1f-%.1f-%.1f-%.1f-%.1f\n"
            len = @ccall asprintf(
                strp::Ptr{Ptr{Cchar}},
                fmt::Cstring,
                ; # begin varargs
                0x1::UInt8, 0x2::UInt8, 0x3::UInt8, 0x4::UInt8, 0x5::UInt8, 0x6::UInt8, 0x7::UInt8, 0x8::UInt8, 0x9::UInt8, 0xa::UInt8, 0xb::UInt8, 0xc::UInt8, 0xd::UInt8, 0xe::UInt8, 0xf::UInt8,
                1.1::Cfloat, 2.2::Cfloat, 3.3::Cfloat, 4.4::Cfloat, 5.5::Cfloat, 6.6::Cfloat, 7.7::Cfloat, 8.8::Cfloat, 9.9::Cfloat,
            )::Cint
            str = unsafe_string(strp[], len)
            @ccall free(strp[]::Cstring)::Cvoid
            str == "hi+1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-1.1-2.2-3.3-4.4-5.5-6.6-7.7-8.8-9.9\n"
        end
        src = lwr.args[1]::Core.CodeInfo
        frame = Frame(M, src; optimize=false)
        @test length(frame.framecode.src.code) == length(src.code)
        @test JuliaInterpreter.finish_and_return!(frame, true)
    end
end

goerch and others added 4 commits December 11, 2021 10:32
Co-authored-by: Shuhei Kadowaki <[email protected]>
Co-authored-by: Shuhei Kadowaki <[email protected]>
finish_and_return! currently errors, therefore I commented it for now.
@goerch
Copy link
Contributor Author

goerch commented Dec 11, 2021

finish_and_return! currently errors, therefore I commented it for now.

Here are the errors:

WARNING: Method definition foobar() in module Main at C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\test\interpret.jl:779 overwritten at C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\test\interpret.jl:780.
interpretation of unoptimized frame: Error During Test at C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\test\interpret.jl:864
  Test threw exception
  Expression: JuliaInterpreter.finish_and_return!(frame, true)
  invalid lookup expr Core.svec(Cstring)
  Stacktrace:
    [1] error(::String, ::Expr)
      @ Base .\error.jl:42
    [2] lookup_expr(frame::Frame, e::Expr)
      @ JuliaInterpreter C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\src\interpret.jl:25
    [3] collect_args(frame::Frame, call_expr::Expr; isfc::Bool)
      @ JuliaInterpreter C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\src\interpret.jl:60
    [4] evaluate_foreigncall(frame::Frame, call_expr::Expr)
      @ JuliaInterpreter C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\src\interpret.jl:151
    [5] eval_rhs(recurse::Any, frame::Frame, node::Expr)
      @ JuliaInterpreter C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\src\interpret.jl:420
    [6] step_expr!(recurse::Any, frame::Frame, node::Any, istoplevel::Bool)
      @ JuliaInterpreter C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\src\interpret.jl:572
    [7] step_expr!
      @ C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\src\interpret.jl:627 [inlined]
    [8] finish!(recurse::Any, frame::Frame, istoplevel::Bool)
      @ JuliaInterpreter C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\src\commands.jl:14
    [9] finish_and_return!
      @ C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\src\commands.jl:30 [inlined]
   [10] finish_and_return!(frame::Frame, istoplevel::Bool)
      @ JuliaInterpreter C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\src\commands.jl:34
   [11] macro expansion
      @ C:\Users\Win10\AppData\Local\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\Test\src\Test.jl:445 [inlined]
   [12] macro expansion
      @ C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\test\interpret.jl:864 [inlined]
   [13] macro expansion
      @ C:\Users\Win10\AppData\Local\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\Test\src\Test.jl:1283 [inlined]
   [14] top-level scope
      @ C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\test\interpret.jl:854
interpretation of unoptimized frame: Error During Test at C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\test\interpret.jl:884
  Test threw exception
  Expression: JuliaInterpreter.finish_and_return!(frame, true)
  invalid lookup expr Core.svec(Core.apply_type(Ptr, Core.apply_type(Ptr, Cchar)), Cstring, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, 
UInt8, UInt8, UInt8, UInt8, Cfloat, Cfloat, Cfloat, Cfloat, Cfloat, Cfloat, Cfloat, Cfloat, Cfloat)
  Stacktrace:
    [1] error(::String, ::Expr)
      @ Base .\error.jl:42
    [2] lookup_expr(frame::Frame, e::Expr)
      @ JuliaInterpreter C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\src\interpret.jl:25
    [3] collect_args(frame::Frame, call_expr::Expr; isfc::Bool)
      @ JuliaInterpreter C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\src\interpret.jl:60
    [4] evaluate_foreigncall(frame::Frame, call_expr::Expr)
      @ JuliaInterpreter C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\src\interpret.jl:151
    [5] eval_rhs(recurse::Any, frame::Frame, node::Expr)
      @ JuliaInterpreter C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\src\interpret.jl:420
    [6] step_expr!(recurse::Any, frame::Frame, node::Any, istoplevel::Bool)
      @ JuliaInterpreter C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\src\interpret.jl:572
    [7] step_expr!
      @ C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\src\interpret.jl:627 [inlined]
    [8] finish!(recurse::Any, frame::Frame, istoplevel::Bool)
      @ JuliaInterpreter C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\src\commands.jl:14
    [9] finish_and_return!
      @ C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\src\commands.jl:30 [inlined]
   [10] finish_and_return!(frame::Frame, istoplevel::Bool)
      @ JuliaInterpreter C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\src\commands.jl:34
   [11] macro expansion
      @ C:\Users\Win10\AppData\Local\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\Test\src\Test.jl:445 [inlined]
   [12] macro expansion
      @ C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\test\interpret.jl:884 [inlined]
   [13] macro expansion
      @ C:\Users\Win10\AppData\Local\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\Test\src\Test.jl:1283 [inlined]
   [14] top-level scope
      @ C:\Users\Win10\Documents\GitHub\JuliaInterpreter.jl\test\interpret.jl:854

@goerch
Copy link
Contributor Author

goerch commented Dec 11, 2021

Interesting question: shouldn't collect_args get an additional recurse argument to use for lookup_or_eval?

function collect_args(frame::Frame, call_expr::Expr; isfc::Bool=false)
    args = frame.framedata.callargs
    resize!(args, length(call_expr.args))
    mod = moduleof(frame)
    args[1] = isfc ? resolvefc(frame, call_expr.args[1]) : @lookup(mod, frame, call_expr.args[1])
    for i = 2:length(args)
        if isexpr(call_expr.args[i], :call)
            args[i] = lookup_or_eval(finish_and_return!, frame, call_expr.args[i])
        else
            args[i] = @lookup(mod, frame, call_expr.args[i])
        end
    end
    return args
end

Copy link
Member

@timholy timholy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the ambiguity about call expressions can be resolved, this LGTM.

args = frame.framedata.callargs
resize!(args, length(call_expr.args))
mod = moduleof(frame)
args[1] = isfc ? resolvefc(frame, call_expr.args[1]) : @lookup(mod, frame, call_expr.args[1])
for i = 2:length(args)
args[i] = @lookup(mod, frame, call_expr.args[i])
if isexpr(call_expr.args[i], :call)
args[i] = lookup_or_eval(recurse, frame, call_expr.args[i])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, we might need to test

iscallexpr(ex::Expr) = ex.head === :call
@interpret iscallexpr(:(sin(3.14))

We need to be sure we distinguish a call expression intended as an argument from one produced by lowering.

@timholy timholy merged commit d5cb560 into JuliaDebug:master Dec 13, 2021
@timholy
Copy link
Member

timholy commented Dec 13, 2021

Thanks @goerch!

@goerch goerch deleted the frame-constructor-parameters branch December 13, 2021 17:29
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

Successfully merging this pull request may close these issues.

4 participants