Unrolled.jl – problems with "where" keyword

I have a function that takes an SVector of some type, i.e.

function foo(vec::SVector{2,T}) where T
    for x in vec
        #do something with x
    end
end

and want to use Unrolled.jl on it. However, when I add the @unroll macro like this

@unroll function foo(vec::SVector{2,T}) where T
    @unroll for x in vec
        #do something with x
    end
end

I get an error message: LoadError: AssertionError: @unroll must precede a function definition

Is there anything I’m doing wrong or is Unrolled.jl just not able to deal with wheres?

1 Like

Haven’t used Unrolled.jl before, but the readme and tests don’t show any examples of @unroll function ..., it’s just applied to for loops.

This looks like a bug in Unrolled.jl to me. The relevant line is here: https://github.com/cstjean/Unrolled.jl/blob/b71319847801847426886ca0720a7b5277ca09ff/src/Unrolled.jl#L70 and should probably include an @capture that matches against functions with where clauses. You can play around with this yourself using MacroTools.jl:

julia> using MacroTools

julia> @capture(:(function foo(x); end), function fname_(args__) body__ end)
true

julia> @capture(:(function foo(x) where {T}; end), function fname_(args__) body__ end)
false

julia> @capture(:(function foo(x) where {T}; end), function fname_(args__) where {T__} body__ end)
true
1 Like

Should be fixed on Unrolled.jl’s master. Thank you for the bug report.

2 Likes

If you’re using MacroTools, you might be interested in splitdef and combinedef for processing function definitions.