Skip to content

Commit

Permalink
improve inference of CPU_THREADS in Sys.__init__ (#54384)
Browse files Browse the repository at this point in the history
Without this change, the compiler fails to notice that `env_threads isa
Int` in the fall-through case, leading to a union-split with a branch
that is in fact unreachable:

```
43 ┄ %109 = φ (#41 => %105, #42 => %108)::Union{Nothing, Int64}
│    %110 = (%109 isa Int64)::Bool
└───        goto #45 if not %110
...
45 ─ %126 = π (%109, Nothing)
│           Base.convert(Int64, %126)::Union{}
└───        unreachable
```

After this change, the union-split is eliminated.

Co-authored-by: Jeff Bezanson <jeff.bezanson@gmail.com>
  • Loading branch information
topolarity and JeffBezanson committed May 7, 2024
1 parent e47fedd commit 99bda02
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion base/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function __init__()
end
global CPU_THREADS = if env_threads !== nothing
env_threads = tryparse(Int, env_threads)
if !(env_threads isa Int && env_threads > 0)
if env_threads === nothing || env_threads <= 0
env_threads = Int(ccall(:jl_cpu_threads, Int32, ()))
Core.print(Core.stderr, "WARNING: couldn't parse `JULIA_CPU_THREADS` environment variable. Defaulting Sys.CPU_THREADS to $env_threads.\n")
end
Expand Down

0 comments on commit 99bda02

Please sign in to comment.