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

collect = true leads to a vector of nothing #105

Closed
Qiaoyi-Li opened this issue Apr 29, 2024 · 9 comments
Closed

collect = true leads to a vector of nothing #105

Qiaoyi-Li opened this issue Apr 29, 2024 · 9 comments

Comments

@Qiaoyi-Li
Copy link

I tried the following example in Public API

@tasks for i in 1:3
       @set collect=true
       i^2
end

and it will return a length-3 vector of nothing. Note explicit return i^2 will solve this problem and gives [1, 4, 9] correctly. Is this an expected behavior or just a bug?

The julia version is

Julia Version 1.9.4
Commit 8e5136fa297 (2023-11-14 08:46 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 12 × Apple M2 Max
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, apple-m1)
  Threads: 6 on 8 virtual cores
@MasonProtter
Copy link
Member

Hm, that's strange, I can't reproduce:

julia> using OhMyThreads

julia> @tasks for i in 1:3
           @set collect=true
           i^2
       end
3-element Vector{Int64}:
 1
 4
 9

(@v1.10) pkg> st OhMyThreads
Status `~/.julia/environments/v1.10/Project.toml`
  [67456a42] OhMyThreads v0.5.2

Can you please show me the output of

using Pkg; pkg"which OhMyThreads"

and

@macroexpand1 @tasks for i in 1:3
     @set collect=true
     i^2
end

?

@Qiaoyi-Li
Copy link
Author

Thanks for replying so quickly.

using Pkg; pkg"which OhMyThreads"

does not seem to be a julia command ? Maybe you mean the version? (OhMyThreads v0.5.2)

@macroexpand1 @tasks for i in 1:3
            @set collect=true
            i^2
       end
:(let
      begin
          #= /Users/qyli/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:80 =#
          begin
              #= /Users/qyli/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:246 =#
          end
          #= /Users/qyli/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:81 =#
          begin
              #= /Users/qyli/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:266 =#
          end
          #= /Users/qyli/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:82 =#
          nothing
          #= /Users/qyli/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:83 =#
          local function var"#4#mapping_function"(i)
                  #= /Users/qyli/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:57 =#
                  #= /Users/qyli/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:58 =#
                  begin
                      #= REPL[11]:2 =#
                      #= REPL[11]:3 =#
                      i ^ 2
                      #= REPL[11]:4 =#
                  end
              end
          #= /Users/qyli/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:84 =#
          OhMyThreads.tmap(var"#4#mapping_function", 1:3; )
      end
  end)

@Qiaoyi-Li
Copy link
Author

Note additionally, I tried it with Julia v1.10.2, the result is correct.

@carstenbauer
Copy link
Member

We can't reproduce the issue and apparently it works for you on the latest stable Julia version. For these reasons, I'm going to close this.

@MasonProtter
Copy link
Member

Thanks for replying so quickly.

using Pkg; pkg"which OhMyThreads"

does not seem to be a julia command ? Maybe you mean the version? (OhMyThreads v0.5.2)

Yes, sorry I meant pkg"st OhMyThreads".

I just checked on v1.9.2 and 1.9.4 and and I am able to reproduce the issue. That's quite strange, I wonder what could cause it. I'm going to re-open this because we do claim support for v1.9. I'd say we should either look for a fix, or drop v1.9 support.

@MasonProtter MasonProtter reopened this Apr 29, 2024
@MasonProtter
Copy link
Member

Even more bizarre is that the error only occurs for me when using the macro, not if I copy-paste the macroexpanded code:

julia> @tasks for i in 1:3
           @set collect=true
           i^2
       end
3-element Vector{Nothing}:
 nothing
 nothing
 nothing

julia> @macroexpand1 @tasks for i in 1:3
           @set collect=true
           i^2
       end
:(let
      begin
          #= /home/mason/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:80 =#
          begin
              #= /home/mason/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:246 =#
          end
          #= /home/mason/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:81 =#
          begin
              #= /home/mason/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:266 =#
          end
          #= /home/mason/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:82 =#
          nothing
          #= /home/mason/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:83 =#
          local function var"#10#mapping_function"(i)
                  #= /home/mason/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:57 =#
                  #= /home/mason/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:58 =#
                  begin
                      #= REPL[18]:2 =#
                      #= REPL[18]:3 =#
                      i ^ 2
                      #= REPL[18]:4 =#
                  end
              end
          #= /home/mason/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:84 =#
          OhMyThreads.tmap(var"#10#mapping_function", 1:3; )
      end
  end)

julia> let
             begin
                 #= /home/mason/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:80 =#
                 begin
                     #= /home/mason/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:246 =#
                 end
                 #= /home/mason/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:81 =#
                 begin
                     #= /home/mason/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:266 =#
                 end
                 #= /home/mason/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:82 =#
                 nothing
                 #= /home/mason/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:83 =#
                 local function var"#10#mapping_function"(i)
                         #= /home/mason/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:57 =#
                         #= /home/mason/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:58 =#
                         begin
                             #= REPL[18]:2 =#
                             #= REPL[18]:3 =#
                             i ^ 2
                             #= REPL[18]:4 =#
                         end
                     end
                 #= /home/mason/.julia/packages/OhMyThreads/V13wc/src/macro_impl.jl:84 =#
                 OhMyThreads.tmap(var"#10#mapping_function", 1:3; )
             end
         end
3-element Vector{Int64}:
 1
 4
 9

but I do get the wrong behaviour if I directly eval that macroexpanded code:

julia> eval(begin
           @macroexpand1 @tasks for i in 1:3
               @set collect=true
               i^2
           end
       end)
3-element Vector{Nothing}:
 nothing
 nothing
 nothing

That's really spooky. I'm starting to suspect this is a julia-side bug, but it'll require some more digging.

@carstenbauer
Copy link
Member

Although a bit disappointing, I think we should drop 1.9 support given that 1.10 is the new LTS. (FWIW, I'm doing the same for ThreadPinning.jl in the next version.)

@MasonProtter
Copy link
Member

Yeah lets do that.

@carstenbauer
Copy link
Member

Support for Julia < 1.10 will be dropped in version 0.6 (to be released soon).

@carstenbauer carstenbauer closed this as not planned Won't fix, can't repro, duplicate, stale Aug 15, 2024
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