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 failure in SHA #101

Closed
macd opened this issue Mar 5, 2019 · 4 comments
Closed

MWE failure in SHA #101

macd opened this issue Mar 5, 2019 · 4 comments

Comments

@macd
Copy link
Contributor

macd commented Mar 5, 2019

Currently the tests for the stdlib SHA fail in the interpreter and that causes a latent bug in the runtests.jl of SHA to come up all X's in the interpreter tests. The problem is that the function warn is used there, which is undefined, instead of the macro call @warn. I have submitted a PR for that, and once that is merged, then there are two failures in SHA, both related to sha1. The following code, when run from the JuliaInterpreter/test directory shows the problem. Interestingly, if nstmts is set to only 10000 instead of 1000000, then the test passes.

using JuliaInterpreter
include("utils.jl")

module SHA_test
    using SHA
    using Test

    sha1_result = "34aa973cd4c4daa4f61eeb2bdbad27316534016f"
    so_many_as_array = repeat([0x61], 1000000)
end

m = SHA_test

ex = quote
    ctx = SHA.SHA1_CTX()
    SHA.update!(ctx, so_many_as_array[1:2*SHA.blocklen(typeof(ctx))])
    SHA.update!(ctx, so_many_as_array[2*SHA.blocklen(typeof(ctx))+1:end])
    hash = bytes2hex(SHA.digest!(ctx))
    @test hash == sha1_result
end

function runex(ex; m=Main, nstmts=10000)
    modexs, _ = JuliaInterpreter.split_expressions(m, ex)
    stack = JuliaStackFrame[]
    for modex in modexs
        frame = JuliaInterpreter.prepare_thunk(modex)
        nstmtsleft = nstmts
        while true
            ret, nstmtsleft = evaluate_limited!(stack, frame, nstmtsleft)
            if isa(ret, Aborted)
                run_compiled(frame)
                break
            elseif isa(ret, Some)
                break
            end
        end
    end
end

runex(ex, m=m, nstmts=1000000)
@timholy
Copy link
Member

timholy commented Mar 5, 2019

Just a comment, your runex actually defeats the purpose of that split_expressions loop (it's to avoid world-age errors, see #41, definitely one of the trickiest things we've had to face).

In cases where you don't define new structs/methods, you can replace the whole thing with just

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

where m is the module you want to evaluate into.

@macd
Copy link
Contributor Author

macd commented Mar 5, 2019

Aaah, I see now. Will do. (I was just using the recipe from #13)

@timholy
Copy link
Member

timholy commented Mar 5, 2019

Right, but #13 deliberately doesn't put it in a function. By not compiling it, it avoids the world-age errors. (Again, here not an issue anyway.)

timholy added a commit that referenced this issue Mar 6, 2019
timholy added a commit that referenced this issue Mar 6, 2019
timholy added a commit that referenced this issue Mar 6, 2019
@timholy
Copy link
Member

timholy commented Mar 6, 2019

It may still fail the test due to the warns but the test in this MWE now passes.

@timholy timholy closed this as completed Mar 6, 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

2 participants