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

stagedfunction fails to update cache #10178

Closed
mauro3 opened this issue Feb 12, 2015 · 5 comments
Closed

stagedfunction fails to update cache #10178

mauro3 opened this issue Feb 12, 2015 · 5 comments

Comments

@mauro3
Copy link
Contributor

mauro3 commented Feb 12, 2015

In some corner cases it seems that the stagedfunction cache is not updated. Consider:

immutable AI end

###############
print("\n\nThis works only in older julia-0.4\n")

print("\n1\n")
stagedfunction f{X}(::Type{AI}, x::X)
    print("\nstaging\n")
    :(x)
end

g(x) = f(AI, x)
@show g(5)

print("\n2\n")
stagedfunction f{X}(::Type{AI}, x::X)
    print("\nstaging\n")
    :(2x)
end

g(x) = f(AI, x)
@show g(5)


print("\n3\n")
stagedfunction f{X}(::Type{AI}, x::X)
    print("\nstaging\n")
    :(3x)
end

g(x) = f(AI, x)
@show g(5)

###############
print("\n\nWorks in both\n")

print("\n1\n")
stagedfunction ff{X}(::Type{AI}, x::X)
    print("\nstaging\n")
    :(x)
end
@show ff(AI, 5)

print("\n2\n")
stagedfunction ff{X}(::Type{AI}, x::X)
    print("\nstaging\n")
    :(2x)
end

@show ff(AI, 5)


print("\n3\n")
stagedfunction ff{X}(::Type{AI}, x::X)
    print("\nstaging\n")
    :(3x)
end

@show ff(AI, 5)

With version bcd0e5e of julia-0.4 (mid-January) I get output:

This works only in older julia-0.4

1

staging

staging
g(5) = 5

2

staging

staging
g(5) = 10

3

staging

staging
g(5) = 15


Works in both

1

staging
ff(AI,5) = 5

2

staging
ff(AI,5) = 10

3

staging
ff(AI,5) = 15

with a current build 1a9e1b1 I get this:


This works only in older julia-0.4

1

staging
g(5) = 5

2
g(5) = 5

3
g(5) = 5


Works in both

1

staging
ff(AI,5) = 5

2

staging
ff(AI,5) = 10

3

staging
ff(AI,5) = 15

I suspect the culprit is PR #9921

@mauro3
Copy link
Contributor Author

mauro3 commented Feb 12, 2015

Sorry, this could have been more succinct:

    stagedfunction f{X}(x::X)
        :(x)
    end
    g(x) = f(x)
    @assert g(5)==5
    stagedfunction f{X}(x::X)
        :(2x)
    end
    g(x) = f(x)
    @assert g(5)==10

Throws in current 0.4 but worked in bcd0e5e. Bonus trick, works in both versions if wrapped in a let-block.

@mauro3
Copy link
Contributor Author

mauro3 commented Feb 12, 2015

And last bit of noise: @Jutho

@Jutho
Copy link
Contributor

Jutho commented Feb 12, 2015

Well, this is clearly caused by the stagedcache introduced in my PR #9921, since overwriting it with the old definition by typing this in the REPL

    function Base.func_for_method(m::Method, tt, env)
        if !m.isstaged
            return m.func.code
        else
            f=ccall(:jl_instantiate_staged,Any,(Any,Any,Any),m,tt,env)
            return f.code
        end
    end

fixes your problem. But then again, we knew this could happen if PR #9921 got merged without anybody looking at it who actually understands what's going on in inference.jl. Maybe it is time to introduce a stagedfunction label for grouping all the remaining issues with stagedfunctions?

@mauro3
Copy link
Contributor Author

mauro3 commented Feb 12, 2015

Thanks for work-around. And a stagedfuntions label would probably be good.

@mauro3
Copy link
Contributor Author

mauro3 commented Jan 18, 2017

This was resolved in julia-0.5. Is the test as in #10178 (comment) desired?

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