Polyester.jl icon indicating copy to clipboard operation
Polyester.jl copied to clipboard

cannot convert Expr to object of type Symbol

Open Roger-luo opened this issue 4 years ago • 2 comments

I got this error for (since it errors on the expression directly, I omit other parts, but let me know if you need other definitions), I currently need to wrap the thread task inside a function manually to workaround this

    @inbounds @batch for tid in 1:nthreads
        range = BQCESubroutine.schedule_task(space, tid, nthreads)
        for (k, b, _j) in range
            j = _j << plain_locs
            i = j+k
            ST1 = U11 * S[b, i+1] + U12 * S[b, i+step_1+1]
            ST2 = U21 * S[b, i+1] + U22 * S[b, i+step_1+1]

            S[b, i+1] = ST1
            S[b, i+step_1+1] = ST2
        end
    end
ERROR: LoadError: MethodError: Cannot `convert` an object of type Expr to an object of type Symbol
Closest candidates are:
  convert(::Type{T}, ::T) where T at essentials.jl:205
  Symbol(::Any...) at strings/basic.jl:229
Stacktrace:
 [1] setindex!(h::Dict{Symbol, Nothing}, v0::Nothing, key0::Expr)
   @ Base ./dict.jl:374
 [2] push!(s::Set{Symbol}, x::Expr)
   @ Base ./set.jl:57
 [3] define_induction_variables!(defined::Set{Symbol}, ex::Expr)
   @ CheapThreads ~/.julia/packages/CheapThreads/BWiwl/src/closure.jl:34
 [4] extractargs!(arguments::Vector{Symbol}, defined::Set{Symbol}, expr::Expr)
   @ CheapThreads ~/.julia/packages/CheapThreads/BWiwl/src/closure.jl:49
 [5] extractargs!(arguments::Vector{Symbol}, defined::Set{Symbol}, expr::Expr) (repeats 2 times)
   @ CheapThreads ~/.julia/packages/CheapThreads/BWiwl/src/closure.jl:75
 [6] enclose(exorig::Expr, reserve_per::Int64, minbatchsize::Int64)
   @ CheapThreads ~/.julia/packages/CheapThreads/BWiwl/src/closure.jl:91
 [7] enclose(exorig::Expr)
   @ CheapThreads ~/.julia/packages/CheapThreads/BWiwl/src/closure.jl:80
 [8] var"@batch"(__source__::LineNumberNode, __module__::Module, ex::Any)
   @ CheapThreads ~/.julia/packages/CheapThreads/BWiwl/src/closure.jl:160
in expression starting at REPL[48]:1

Roger-luo avatar Apr 16 '21 05:04 Roger-luo

Thanks for the issue. That error was fixed here: https://github.com/JuliaSIMD/CheapThreads.jl/commit/4120d333183b455796f423fb1271d492754b164a But I still need to add a test.

As an aside, @inbounds doesn't penetrate closures, so it won't work with macros like @threads or @batch. @batch automatically applies @inbounds partly for that reason. There may still be bounds checks in the expanded code in some cases, though.

chriselrod avatar Apr 16 '21 18:04 chriselrod

Actually, this isn't fixed because the iteration splitting code assumes step is defined. Making anything Iterators.product-like work using CheapThreads's current behavior would require some hacky overloads.

Should make try and think of a more general way of doing this.

chriselrod avatar Apr 19 '21 02:04 chriselrod