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

Unhygienic inlining #8978

Closed
MikeInnes opened this issue Nov 11, 2014 · 1 comment
Closed

Unhygienic inlining #8978

MikeInnes opened this issue Nov 11, 2014 · 1 comment
Labels
kind:bug Indicates an unexpected problem or unintended behavior

Comments

@MikeInnes
Copy link
Member

On d94b0be the build failds due to the delimter^n expression on this line, with an error due to a boolean being used as a function.

Renaming the repeat parameter (which should obviously have no effect) fixes the issue.

Since ^ calls repeat directly I suspect the issue lies in the inlining.

@MikeInnes MikeInnes added the kind:bug Indicates an unexpected problem or unintended behavior label Nov 11, 2014
@vtjnash
Copy link
Sponsor Member

vtjnash commented Nov 18, 2014

i can't seem to make a smaller testcase, but the cause is actually rather simple.

inlineable (and in particular resolve_globals) doesn't consider the existence of captured variables

The following AST partially illustrates the issue:

julia> h(;f=2) = cd() do
       g()+f
       end
h (generic function with 1 method)

julia> code_typed(h,())
1-element Array{Any,1}:
 :($(Expr(:lambda, Any[], Any[Any[],Any[],Any[]], :(begin $(Expr(:line, 1, :none, symbol("")))
        return __h#6__(2)
    end))))

julia> code_typed(eval(symbol("__h#6__")),(Int,))
1-element Array{Any,1}:
 :($(Expr(:lambda, Any[:f], Any[Any[:_var0],Any[Any[:f,Int64,1],Any[:_var0,Function,18]],Any[]], :(begin $(Expr(:line, 1, :none, :h))
        _var0 = AST(:($(Expr(:lambda, Any[], Any[Any[],Any[],Any[Any[:f,Int64,1]]], :(begin  # none, line 2:
        return g() + f
    end)))))
        return cd(_var0::F,getindex(ENV,"HOME")::Union(ASCIIString,UTF8String))
    end))))

The AST assigned to _var0 only mentions f in the captures array, not the args or locals arrays. So it doesn't make the necessary global/getfield annotations when inlining g.

@JeffBezanson do you want this fixed in the flisp code-lowering logic (to include captured variables in the locals array) or in the resolve_globals logic (to scan the captures array, in addition to the existing two)?

edit: code to reproduce just needed a for loop to force compilation:

julia> y = 1

julia> g() = f(y)

julia> f(x) = 2

julia> f(x::Int) = 3.0

julia> h(;f=4) = cd() do
       for i = 1:1
       g()+f
       end
       end
h (generic function with 1 method)

julia> h()
ERROR: `call` has no method matching call(::Int64, ::Int64)
 in anonymous at none:3
 in cd at ./file.jl:20
 in h at none:1

waTeim pushed a commit to waTeim/julia that referenced this issue Nov 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants