before_code
stringlengths
30
149k
reviewer_comment
stringlengths
16
20.6k
after_code
stringlengths
30
163k
diff_context
stringlengths
0
22.4k
file_path
stringlengths
6
155
comment_line
int64
0
26
language
stringclasses
19 values
quality_score
float64
0.07
1
comment_type
stringclasses
9 values
comment_length
int64
16
20.6k
before_lines
int64
2
4.61k
after_lines
int64
2
4.4k
is_negative
bool
2 classes
pr_title
stringlengths
7
140
pr_number
int64
18
61.2k
repo_name
stringclasses
29 values
repo_stars
int64
321
56k
repo_language
stringclasses
14 values
reviewer_username
stringclasses
378 values
author_username
stringclasses
739 values
user
stringlengths
361
200k
assistant
stringlengths
16
20.6k
system
stringclasses
1 value
# precompilepkgs precompile(Tuple{typeof(Base.get), Type{Array{String, 1}}, Base.Dict{String, Any}, String}) precompile(Tuple{typeof(Base.get), Type{Base.Dict{String, Any}}, Base.Dict{String, Any}, String}) precompile(Tuple{typeof(Base.haskey), Base.Dict{String, Any}, String}) precompile(Tuple{typeof(Base.indexed_iter...
This is likely to get stale and break the build.
precompile(Base.StackTraces.lookup, (Ptr{Nothing},)) precompile(Tuple{typeof(Base.run_module_init), Module, Int}) # precompilepkgs precompile(Tuple{typeof(Base.get), Type{Array{String, 1}}, Base.Dict{String, Any}, String}) precompile(Tuple{typeof(Base.get), Type{Base.Dict{String, Any}}, Base.Dict{String, Any}, String}...
@@ -114,6 +114,30 @@ precompile(Tuple{typeof(Base.setup_stdio), Base.TTY, Bool}) precompile(Tuple{typeof(Base.spawn_opts_inherit), Base.DevNull, Base.TTY, Base.TTY}) precompile(Tuple{typeof(Core.kwcall), NamedTuple{(:context,), Tuple{Base.TTY}}, typeof(Base.sprint), Function}) precompile(Tuple{Type{Base.UUID}, Base....
contrib/generate_precompile.jl
26
Julia
0.071
suggestion
48
51
51
false
Avoid confounding compilation side effects of `@time_imports`
55,729
JuliaLang/julia
35,573
Julia
KristofferC
IanButterworth
Review this pull request change. Language: Julia File: contrib/generate_precompile.jl PR Title: Avoid confounding compilation side effects of `@time_imports` BEFORE CODE: # precompilepkgs precompile(Tuple{typeof(Base.get), Type{Array{String, 1}}, Base.Dict{String, Any}, String}) precompile(Tuple{typeof(Base.get), ...
This is likely to get stale and break the build.
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
end end dup(posix_fd, RawFD(unix_fd)) nothing end function _redirect_io_global(io, unix_fd::Int) unix_fd == 0 && (global stdin = io) unix_fd == 1 && (global stdout = io) unix_fd == 2 && (global stderr = io) nothing end function (f::RedirectStdStream)(handle::Union{LibuvStream, IOStre...
Rather than duplicate, why not ```suggestion f(handle) close(handle) return devnull ``` ?
@static if Sys.iswindows() if 0 <= unix_fd <= 2 ccall(:SetStdHandle, stdcall, Int32, (Int32, OS_HANDLE), -10 - unix_fd, Libc._get_osfhandle(posix_fd)) end end GC.@preserve stream dup(posix_fd, RawFD(unix_fd)) nothing end function _redirect_io_cglobal(handle::U...
@@ -1264,6 +1264,11 @@ function (f::RedirectStdStream)(::DevNull) nulldev = @static Sys.iswindows() ? "NUL" : "/dev/null" handle = open(nulldev, write=f.writable) _redirect_io_libc(handle, f.unix_fd) + c_sym = f.unix_fd == 0 ? cglobal(:jl_uv_stdin, Ptr{Cvoid}) :
base/stream.jl
26
Julia
0.714
refactor
95
51
51
false
also redirect JL_STDERR etc. when redirecting to devnull
55,958
JuliaLang/julia
35,573
Julia
Keno
IanButterworth
Review this pull request change. Language: Julia File: base/stream.jl PR Title: also redirect JL_STDERR etc. when redirecting to devnull BEFORE CODE: end end dup(posix_fd, RawFD(unix_fd)) nothing end function _redirect_io_global(io, unix_fd::Int) unix_fd == 0 && (global stdin = io) unix_...
Rather than duplicate, why not ```suggestion f(handle) close(handle) return devnull ``` ?
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
# --help let header = "\n julia [switches] -- [programfile] [args...]" @test startswith(read(`$exename -h`, String), header) @test startswith(read(`$exename --help`, String), header) end # ~ expansion in --project and JULIA_PROJECT if !Sys.iswindows() let expanded = absp...
It looks like this `for` loop has a misplaced closing parenthesis: ```julia [("project", expanded, ("outside", pwd()))] ^ ``` I'm guessing it should be ```julia [("project", expanded), ("outside", pwd())] ^ ``` Otherwise this loop has only one iter...
# --help let header = "\n julia [switches] -- [programfile] [args...]" @test startswith(read(`$exename -h`, String), header) @test startswith(read(`$exename --help`, String), header) end # ~ expansion in --project and JULIA_PROJECT if !Sys.iswindows() let expanded = absp...
@@ -257,6 +257,16 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no` @test expanded == readchomp(addenv(`$exename -e 'println(Base.active_project())'`, "JULIA_PROJECT" => "@foo", "HOME" => homedir())) end + # --project=@script handling + let expanded = abspath(joinpath(@__DIR__, "...
test/cmdlineargs.jl
26
Julia
0.857
suggestion
362
51
51
false
Fix `--project=@script` when outside script directory
56,351
JuliaLang/julia
35,573
Julia
StevenWhitaker
awadell1
Review this pull request change. Language: Julia File: test/cmdlineargs.jl PR Title: Fix `--project=@script` when outside script directory BEFORE CODE: # --help let header = "\n julia [switches] -- [programfile] [args...]" @test startswith(read(`$exename -h`, String), header) @test start...
It looks like this `for` loop has a misplaced closing parenthesis: ```julia [("project", expanded, ("outside", pwd()))] ^ ``` I'm guessing it should be ```julia [("project", expanded), ("outside", pwd())] ^ ``` Otherwise this loop has only one iter...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
length(x::IterableStatePairs) = length(x.x) Base.eltype(::Type{IterableStatePairs{T}}) where T = Pair{<:Any, eltype(T)} function iterate(x::IterableStatePairs, state=first(keys(x.x))) it = iterate(x.x, state) it === nothing && return nothing (state => first(it), last(it)) end reverse(x::IterableStatePairs...
Returning `nothing` makes it impossible to distinguish between "the nth element was `nothing`", and "there was no nth element". Perhaps return `Union{Nothing, Some}`?
pairs by only calling iterate on the values. """ struct IterableStatePairs{T} x::T end IteratorSize(::Type{<:IterableStatePairs{T}}) where T = IteratorSize(T) length(x::IterableStatePairs) = length(x.x) Base.eltype(::Type{IterableStatePairs{T}}) where T = Pair{<:Any, eltype(T)} function iterate(x::IterableStateP...
@@ -1595,4 +1595,72 @@ end # be the same as the keys, so this is a valid optimization (see #51631) pairs(s::AbstractString) = IterableStatePairs(s) +""" + nth(itr, n::Integer) + +Get the `n`th element of an iterable collection. Return `nothing` if not existing.
base/iterators.jl
26
Julia
0.5
question
166
51
51
false
adds the `nth` function for iterables
56,580
JuliaLang/julia
35,573
Julia
jakobnissen
ghyatzo
Review this pull request change. Language: Julia File: base/iterators.jl PR Title: adds the `nth` function for iterables BEFORE CODE: length(x::IterableStatePairs) = length(x.x) Base.eltype(::Type{IterableStatePairs{T}}) where T = Pair{<:Any, eltype(T)} function iterate(x::IterableStatePairs, state=first(keys(x.x)...
Returning `nothing` makes it impossible to distinguish between "the nth element was `nothing`", and "there was no nth element". Perhaps return `Union{Nothing, Some}`?
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
it === nothing && return nothing (state => first(it), last(it)) end # According to the docs of iterate(::AbstractString), the iteration state must # be the same as the keys, so this is a valid optimization (see #51631) pairs(s::AbstractString) = IterableStatePairs(s) """ nth(itr, n::Integer) Get the `n`t...
This assumes one-based indexing. Perhaps do `itr[begin + n - 1]`.
(state => first(it), last(it)) end reverse(x::IterableStatePairs) = IterableStatePairs(Iterators.reverse(x.x)) reverse(x::IterableStatePairs{<:Iterators.Reverse}) = IterableStatePairs(x.x.itr) function iterate(x::IterableStatePairs{<:Iterators.Reverse}, state=last(keys(x.x.itr))) it = iterate(x.x, state) ...
@@ -1595,4 +1595,72 @@ end # be the same as the keys, so this is a valid optimization (see #51631) pairs(s::AbstractString) = IterableStatePairs(s) +""" + nth(itr, n::Integer) + +Get the `n`th element of an iterable collection. Return `nothing` if not existing. + +See also: [`first`](@ref), [`last`](@ref) + +# E...
base/iterators.jl
26
Julia
0.357
suggestion
65
51
51
false
adds the `nth` function for iterables
56,580
JuliaLang/julia
35,573
Julia
jakobnissen
ghyatzo
Review this pull request change. Language: Julia File: base/iterators.jl PR Title: adds the `nth` function for iterables BEFORE CODE: it === nothing && return nothing (state => first(it), last(it)) end # According to the docs of iterate(::AbstractString), the iteration state must # be the same as the keys,...
This assumes one-based indexing. Perhaps do `itr[begin + n - 1]`.
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
""" nth(itr, n::Integer) Get the `n`th element of an iterable collection. Return `nothing` if not existing. See also: [`first`](@ref), [`last`](@ref) # Examples ```jldoctest julia> nth(2:2:10, 4) 8 julia> nth(reshape(1:30, (5,6)), 6) 6 ``` """ nth(itr, n::Integer) = _nth(IteratorSize(itr), itr, n) nth(itr::Abs...
Same as above - assumes 1-based indexing.
it = iterate(x.x, state) it === nothing && return nothing (state => first(it), last(it)) end # According to the docs of iterate(::AbstractString), the iteration state must # be the same as the keys, so this is a valid optimization (see #51631) pairs(s::AbstractString) = IterableStatePairs(s) """ nth(i...
@@ -1595,4 +1595,72 @@ end # be the same as the keys, so this is a valid optimization (see #51631) pairs(s::AbstractString) = IterableStatePairs(s) +""" + nth(itr, n::Integer) + +Get the `n`th element of an iterable collection. Return `nothing` if not existing. + +See also: [`first`](@ref), [`last`](@ref) + +# E...
base/iterators.jl
26
Julia
0.071
suggestion
41
51
51
false
adds the `nth` function for iterables
56,580
JuliaLang/julia
35,573
Julia
jakobnissen
ghyatzo
Review this pull request change. Language: Julia File: base/iterators.jl PR Title: adds the `nth` function for iterables BEFORE CODE: """ nth(itr, n::Integer) Get the `n`th element of an iterable collection. Return `nothing` if not existing. See also: [`first`](@ref), [`last`](@ref) # Examples ```jldoctest ...
Same as above - assumes 1-based indexing.
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
@testset "r: $r" for r ∈ mappers1 @testset "f: $f" for f ∈ maps @test_throws MethodError r(f) @test !applicable(r, f) @test !hasmethod(r, Tuple{typeof(f)}) end end end @testset "mapreduce" begin @testset "mr: $mr" f...
I would put these in a `Vector{Any}` - no need to create specialized code for long tuples here. Since the test only runs once, using a tuple will be much slower.
end end @testset "proper partition for non-1-indexed vector" begin @test partition(IdentityUnitRange(11:19), 5) |> collect == [11:15,16:19] # IdentityUnitRange end @testset "Iterators.peel" begin @test Iterators.peel([]) === nothing @test Iterators.peel(1:10)[1] == 1 @test Iterators.peel(1:10)[2] ...
@@ -1074,6 +1074,30 @@ end end end +@testset "nth" begin + Z = Array{Int,0}(undef) + Z[] = 17 + itrs = (collect(1:1000), 10:6:1000, "∀ϵ>0", (1, 3, 5, 10, 78), reshape(1:30, (5, 6)),
test/iterators.jl
26
Julia
0.5
performance
161
50
51
false
adds the `nth` function for iterables
56,580
JuliaLang/julia
35,573
Julia
jakobnissen
ghyatzo
Review this pull request change. Language: Julia File: test/iterators.jl PR Title: adds the `nth` function for iterables BEFORE CODE: @testset "r: $r" for r ∈ mappers1 @testset "f: $f" for f ∈ maps @test_throws MethodError r(f) @test !applicable(r, f) ...
I would put these in a `Vector{Any}` - no need to create specialized code for long tuples here. Since the test only runs once, using a tuple will be much slower.
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
reverse(x::IterableStatePairs{<:Iterators.Reverse}) = IterableStatePairs(x.x.itr) function iterate(x::IterableStatePairs{<:Iterators.Reverse}, state=last(keys(x.x.itr))) it = iterate(x.x, state) it === nothing && return nothing (state => first(it), last(it)) end # According to the docs of iterate(::Abstra...
I would also mention that it will advance the iterator `n` steps, and perhaps show an example of how it affects a stateful iterator in the examples: ``` julia> stateful = Stateful(1:10); nth(stateful, 7) 7 julia> first(stateful) 8 ```
function iterate(x::IterableStatePairs, state=first(keys(x.x))) it = iterate(x.x, state) it === nothing && return nothing (state => first(it), last(it)) end reverse(x::IterableStatePairs) = IterableStatePairs(Iterators.reverse(x.x)) reverse(x::IterableStatePairs{<:Iterators.Reverse}) = IterableStatePairs(...
@@ -1595,4 +1595,72 @@ end # be the same as the keys, so this is a valid optimization (see #51631) pairs(s::AbstractString) = IterableStatePairs(s) +""" + nth(itr, n::Integer) + +Get the `n`th element of an iterable collection. Return `nothing` if not existing. +
base/iterators.jl
26
Julia
0.786
suggestion
242
51
51
false
adds the `nth` function for iterables
56,580
JuliaLang/julia
35,573
Julia
jakobnissen
ghyatzo
Review this pull request change. Language: Julia File: base/iterators.jl PR Title: adds the `nth` function for iterables BEFORE CODE: reverse(x::IterableStatePairs{<:Iterators.Reverse}) = IterableStatePairs(x.x.itr) function iterate(x::IterableStatePairs{<:Iterators.Reverse}, state=last(keys(x.x.itr))) it = it...
I would also mention that it will advance the iterator `n` steps, and perhaps show an example of how it affects a stateful iterator in the examples: ``` julia> stateful = Stateful(1:10); nth(stateful, 7) 7 julia> first(stateful) 8 ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
julia> nth(2:2:10, 4) 8 julia> nth(reshape(1:30, (5,6)), 6) 6 julia> stateful = Stateful(1:10); nth(stateful, 7) 7 julia> first(stateful) 8 ``` """ nth(itr, n::Integer) = _nth(itr, n) # Count nth(itr::Count, n::Integer) = n > 0 ? itr.start + itr.step * (n - 1) : throw(ArgumentError("n must be positive.")) # Repeate...
```suggestion nth(itr::Take{Repeated{T}}, n::Integer) where T = begin n > itr.n ? throw(BoundsError(itr, n)) : nth(itr.xs, n) end ```
```jldoctest julia> Iterators.nth(2:2:10, 4) 8 julia> Iterators.nth(reshape(1:30, (5,6)), 6) 6 julia> stateful = Iterators.Stateful(1:10); Iterators.nth(stateful, 7) 7 julia> first(stateful) 8 ``` """ nth(itr, n::Integer) = _nth(IteratorSize(itr), itr, n) nth(itr::Cycle{I}, n::Integer) where I = _nth(IteratorSize(I)...
@@ -1602,4 +1602,84 @@ end # be the same as the keys, so this is a valid optimization (see #51631) pairs(s::AbstractString) = IterableStatePairs(s) +""" + nth(itr, n::Integer) + +Get the `n`th element of an iterable collection. Throw a `BoundsError`[@ref] if not existing. +Will advance any `Stateful`[@ref] itera...
base/iterators.jl
26
Julia
0.857
suggestion
141
51
51
false
adds the `nth` function for iterables
56,580
JuliaLang/julia
35,573
Julia
adienes
ghyatzo
Review this pull request change. Language: Julia File: base/iterators.jl PR Title: adds the `nth` function for iterables BEFORE CODE: julia> nth(2:2:10, 4) 8 julia> nth(reshape(1:30, (5,6)), 6) 6 julia> stateful = Stateful(1:10); nth(stateful, 7) 7 julia> first(stateful) 8 ``` """ nth(itr, n::Integer) = _nth(itr...
```suggestion nth(itr::Take{Repeated{T}}, n::Integer) where T = begin n > itr.n ? throw(BoundsError(itr, n)) : nth(itr.xs, n) end ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
julia> nth(2:2:10, 4) 8 julia> nth(reshape(1:30, (5,6)), 6) 6 julia> stateful = Stateful(1:10); nth(stateful, 7) 7 julia> first(stateful) 8 ``` """ nth(itr, n::Integer) = _nth(itr, n) # Count nth(itr::Count, n::Integer) = n > 0 ? itr.start + itr.step * (n - 1) : throw(ArgumentError("n must be positive.")) # Repeate...
```suggestion nth(itr::Take{<:Repeated}, n::Integer) = n > itr.n ? throw(BoundsError(itr, n)) : nth(itr.xs, n) ```
```jldoctest julia> Iterators.nth(2:2:10, 4) 8 julia> Iterators.nth(reshape(1:30, (5,6)), 6) 6 julia> stateful = Iterators.Stateful(1:10); Iterators.nth(stateful, 7) 7 julia> first(stateful) 8 ``` """ nth(itr, n::Integer) = _nth(IteratorSize(itr), itr, n) nth(itr::Cycle{I}, n::Integer) where I = _nth(IteratorSize(I)...
@@ -1632,8 +1632,8 @@ nth(itr::Count, n::Integer) = n > 0 ? itr.start + itr.step * (n - 1) : throw(Arg # Repeated nth(itr::Repeated, ::Integer) = itr.x # Take(Repeated) -nth(itr::Take{Repeated}, n::Integer) = begin - n > itr.n ? throw(BoundsError(itr, n)) : nth(itr.xs) +nth(itr::Take{Repeated{T}}, n::Integer) whe...
base/iterators.jl
26
Julia
0.857
suggestion
121
51
51
false
adds the `nth` function for iterables
56,580
JuliaLang/julia
35,573
Julia
stevengj
ghyatzo
Review this pull request change. Language: Julia File: base/iterators.jl PR Title: adds the `nth` function for iterables BEFORE CODE: julia> nth(2:2:10, 4) 8 julia> nth(reshape(1:30, (5,6)), 6) 6 julia> stateful = Stateful(1:10); nth(stateful, 7) 7 julia> first(stateful) 8 ``` """ nth(itr, n::Integer) = _nth(itr...
```suggestion nth(itr::Take{<:Repeated}, n::Integer) = n > itr.n ? throw(BoundsError(itr, n)) : nth(itr.xs, n) ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
julia> Iterators.nth(2:2:10, 4) 8 julia> Iterators.nth(reshape(1:30, (5,6)), 6) 6 julia> stateful = Iterators.Stateful(1:10); nth(stateful, 7) 7 julia> first(stateful) 8 ``` """ nth(itr, n::Integer) = _nth(itr, n) # Count nth(itr::Count, n::Integer) = n > 0 ? itr.start + itr.step * (n - 1) : throw(ArgumentError("n ...
```suggestion nth(itr::Take{<:Repeated}, n::Integer) = n > itr.n ? throw(BoundsError(itr, n)) : nth(itr.xs, n) ```
```jldoctest julia> Iterators.nth(2:2:10, 4) 8 julia> Iterators.nth(reshape(1:30, (5,6)), 6) 6 julia> stateful = Iterators.Stateful(1:10); Iterators.nth(stateful, 7) 7 julia> first(stateful) 8 ``` """ nth(itr, n::Integer) = _nth(IteratorSize(itr), itr, n) nth(itr::Cycle{I}, n::Integer) where I = _nth(IteratorSize(I)...
@@ -1602,4 +1602,84 @@ end # be the same as the keys, so this is a valid optimization (see #51631) pairs(s::AbstractString) = IterableStatePairs(s) +""" + nth(itr, n::Integer) + +Get the `n`th element of an iterable collection. Throw a `BoundsError`[@ref] if not existing. +Will advance any `Stateful`[@ref] itera...
base/iterators.jl
26
Julia
0.857
suggestion
121
51
51
false
adds the `nth` function for iterables
56,580
JuliaLang/julia
35,573
Julia
stevengj
ghyatzo
Review this pull request change. Language: Julia File: base/iterators.jl PR Title: adds the `nth` function for iterables BEFORE CODE: julia> Iterators.nth(2:2:10, 4) 8 julia> Iterators.nth(reshape(1:30, (5,6)), 6) 6 julia> stateful = Iterators.Stateful(1:10); nth(stateful, 7) 7 julia> first(stateful) 8 ``` """ n...
```suggestion nth(itr::Take{<:Repeated}, n::Integer) = n > itr.n ? throw(BoundsError(itr, n)) : nth(itr.xs, n) ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
julia> Iterators.nth(2:2:10, 4) 8 julia> Iterators.nth(reshape(1:30, (5,6)), 6) 6 julia> stateful = Iterators.Stateful(1:10); nth(stateful, 7) 7 julia> first(stateful) 8 ``` """ nth(itr, n::Integer) = _nth(itr, n) # Count nth(itr::Count, n::Integer) = n > 0 ? itr.start + itr.step * (n - 1) : throw(ArgumentError("n ...
```suggestion function nth(itr::Cycle{I}, n::Integer) where {I} ```
```jldoctest julia> Iterators.nth(2:2:10, 4) 8 julia> Iterators.nth(reshape(1:30, (5,6)), 6) 6 julia> stateful = Iterators.Stateful(1:10); Iterators.nth(stateful, 7) 7 julia> first(stateful) 8 ``` """ nth(itr, n::Integer) = _nth(IteratorSize(itr), itr, n) nth(itr::Cycle{I}, n::Integer) where I = _nth(IteratorSize(I)...
@@ -1602,4 +1602,84 @@ end # be the same as the keys, so this is a valid optimization (see #51631) pairs(s::AbstractString) = IterableStatePairs(s) +""" + nth(itr, n::Integer) + +Get the `n`th element of an iterable collection. Throw a `BoundsError`[@ref] if not existing. +Will advance any `Stateful`[@ref] itera...
base/iterators.jl
26
Julia
0.571
suggestion
69
51
51
false
adds the `nth` function for iterables
56,580
JuliaLang/julia
35,573
Julia
stevengj
ghyatzo
Review this pull request change. Language: Julia File: base/iterators.jl PR Title: adds the `nth` function for iterables BEFORE CODE: julia> Iterators.nth(2:2:10, 4) 8 julia> Iterators.nth(reshape(1:30, (5,6)), 6) 6 julia> stateful = Iterators.Stateful(1:10); nth(stateful, 7) 7 julia> first(stateful) 8 ``` """ n...
```suggestion function nth(itr::Cycle{I}, n::Integer) where {I} ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
julia> first(stateful) 8 ``` """ nth(itr, n::Integer) = _nth(itr, n) # Count nth(itr::Count, n::Integer) = n > 0 ? itr.start + itr.step * (n - 1) : throw(ArgumentError("n must be positive.")) # Repeated nth(itr::Repeated, ::Integer) = itr.x # Take(Repeated) nth(itr::Take{Repeated{T}}, n::Integer) where T = begin n...
```suggestion function nth(itr::Flatten{Take{Repeated{O}}}, n::Integer) where {O} ```
julia> first(stateful) 8 ``` """ nth(itr, n::Integer) = _nth(IteratorSize(itr), itr, n) nth(itr::Cycle{I}, n::Integer) where I = _nth(IteratorSize(I), itr, n) nth(itr::Flatten{Take{Repeated{O}}}, n::Integer) where O = _nth(IteratorSize(O), itr, n) @propagate_inbounds nth(itr::AbstractArray, n::Integer) = itr[begin + n...
@@ -1602,4 +1602,84 @@ end # be the same as the keys, so this is a valid optimization (see #51631) pairs(s::AbstractString) = IterableStatePairs(s) +""" + nth(itr, n::Integer) + +Get the `n`th element of an iterable collection. Throw a `BoundsError`[@ref] if not existing. +Will advance any `Stateful`[@ref] itera...
base/iterators.jl
26
Julia
0.571
suggestion
87
51
51
false
adds the `nth` function for iterables
56,580
JuliaLang/julia
35,573
Julia
stevengj
ghyatzo
Review this pull request change. Language: Julia File: base/iterators.jl PR Title: adds the `nth` function for iterables BEFORE CODE: julia> first(stateful) 8 ``` """ nth(itr, n::Integer) = _nth(itr, n) # Count nth(itr::Count, n::Integer) = n > 0 ? itr.start + itr.step * (n - 1) : throw(ArgumentError("n must be po...
```suggestion function nth(itr::Flatten{Take{Repeated{O}}}, n::Integer) where {O} ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
if IteratorSize(I) isa Union{HasShape, HasLength} _nth(itr.xs, mod1(n, length(itr.xs))) else _nth(itr, n) end end # finite cycle: in reality a Flatten{Take{Repeated{O}}} iterator function nth(itr::Flatten{Take{Repeated{O}}}, n::Integer) where {O} if IteratorSize(O) isa Union{HasShape, H...
I would delete this `nth(n)` function. We don't have that for `getindex` or any similar function, so I don't see why we should have it hear. People can always just write `itr -> nth(itr, n)` if they need this.
end # Flatten{Take{Repeated{O}}} is the actual type of an Iterators.cycle(iterable::O, m) iterator function _nth(::Union{HasShape, HasLength}, itr::Flatten{Take{Repeated{O}}}, n::Integer) where {O} cycles = itr.it.n torepeat = itr.it.xs.x k = length(torepeat) (n > k*cycles || k == 0) && throw(BoundsErr...
@@ -1602,4 +1602,83 @@ end # be the same as the keys, so this is a valid optimization (see #51631) pairs(s::AbstractString) = IterableStatePairs(s) +""" + nth(itr, n::Integer) + +Get the `n`th element of an iterable collection. Throw a `BoundsError`[@ref] if not existing. +Will advance any `Stateful`[@ref] itera...
base/iterators.jl
26
Julia
0.643
suggestion
212
46
47
false
adds the `nth` function for iterables
56,580
JuliaLang/julia
35,573
Julia
stevengj
ghyatzo
Review this pull request change. Language: Julia File: base/iterators.jl PR Title: adds the `nth` function for iterables BEFORE CODE: if IteratorSize(I) isa Union{HasShape, HasLength} _nth(itr.xs, mod1(n, length(itr.xs))) else _nth(itr, n) end end # finite cycle: in reality a Flatten{Ta...
I would delete this `nth(n)` function. We don't have that for `getindex` or any similar function, so I don't see why we should have it hear. People can always just write `itr -> nth(itr, n)` if they need this.
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
# Take(Repeated) nth(itr::Take{<:Repeated}, n::Integer) = n > itr.n ? throw(BoundsError(itr, n)) : nth(itr.xs, n) # infinite cycle function nth(itr::Cycle{I}, n::Integer) where {I} if IteratorSize(I) isa Union{HasShape, HasLength} _nth(itr.xs, mod1(n, length(itr.xs))) else _nth(itr, n) ...
did any benchmarking show these `@inline` are needed? not that these calls shouldn't be inlined, but I'm just curious if there was a situation where the compiler didn't do that already
function _nth(::Union{HasShape, HasLength}, itr::Cycle{I}, n::Integer) where {I} N = length(itr.xs) N == 0 && throw(BoundsError(itr, n)) # prevents wrap around behaviour and inherit the error handling return nth(itr.xs, n > 0 ? mod1(n, N) : n) end # Flatten{Take{Repeated{O}}} is the actual type of an...
@@ -1602,4 +1601,81 @@ end # be the same as the keys, so this is a valid optimization (see #51631) pairs(s::AbstractString) = IterableStatePairs(s) +""" + nth(itr, n::Integer) + +Get the `n`th element of an iterable collection. Throw a `BoundsError`[@ref] if not existing. +Will advance any `Stateful`[@ref] itera...
base/iterators.jl
26
Julia
0.571
suggestion
184
50
51
false
adds the `nth` function for iterables
56,580
JuliaLang/julia
35,573
Julia
adienes
ghyatzo
Review this pull request change. Language: Julia File: base/iterators.jl PR Title: adds the `nth` function for iterables BEFORE CODE: # Take(Repeated) nth(itr::Take{<:Repeated}, n::Integer) = n > itr.n ? throw(BoundsError(itr, n)) : nth(itr.xs, n) # infinite cycle function nth(itr::Cycle{I}, n::Integer) where ...
did any benchmarking show these `@inline` are needed? not that these calls shouldn't be inlined, but I'm just curious if there was a situation where the compiler didn't do that already
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
julia> first(stateful) 8 ``` """ nth(itr, n::Integer) = _nth(itr, n) # Count nth(itr::Count, n::Integer) = n > 0 ? itr.start + itr.step * (n - 1) : throw(ArgumentError("n must be positive.")) # Repeated nth(itr::Repeated, ::Integer) = itr.x # Take(Repeated) nth(itr::Take{<:Repeated}, n::Integer) = n > itr.n ? thr...
Is there a clear need for all these specialisations? They seem quite exotic... do they show up? Are they really almost always faster? Are they in fact all well-tested? When I looked at the benchmarks [earlier](https://github.com/JuliaLang/julia/pull/56580#issuecomment-2480888746), the total time was driven by one ca...
julia> stateful = Iterators.Stateful(1:10); Iterators.nth(stateful, 7) 7 julia> first(stateful) 8 ``` """ nth(itr, n::Integer) = _nth(IteratorSize(itr), itr, n) nth(itr::Cycle{I}, n::Integer) where I = _nth(IteratorSize(I), itr, n) nth(itr::Flatten{Take{Repeated{O}}}, n::Integer) where O = _nth(IteratorSize(O), itr, n...
@@ -1602,4 +1601,81 @@ end # be the same as the keys, so this is a valid optimization (see #51631) pairs(s::AbstractString) = IterableStatePairs(s) +""" + nth(itr, n::Integer) + +Get the `n`th element of an iterable collection. Throw a `BoundsError`[@ref] if not existing. +Will advance any `Stateful`[@ref] itera...
base/iterators.jl
26
Julia
0.429
suggestion
357
51
51
false
adds the `nth` function for iterables
56,580
JuliaLang/julia
35,573
Julia
mcabbott
ghyatzo
Review this pull request change. Language: Julia File: base/iterators.jl PR Title: adds the `nth` function for iterables BEFORE CODE: julia> first(stateful) 8 ``` """ nth(itr, n::Integer) = _nth(itr, n) # Count nth(itr::Count, n::Integer) = n > 0 ? itr.start + itr.step * (n - 1) : throw(ArgumentError("n must be p...
Is there a clear need for all these specialisations? They seem quite exotic... do they show up? Are they really almost always faster? Are they in fact all well-tested? When I looked at the benchmarks [earlier](https://github.com/JuliaLang/julia/pull/56580#issuecomment-2480888746), the total time was driven by one ca...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
# This file is a part of Julia. License is MIT: https://julialang.org/license """ Methods for working with Iterators. """ baremodule Iterators # small dance to make this work from Base or Intrinsics const Base = parentmodule(@__MODULE__) using .Base: @inline, Pair, Pairs, AbstractDict, IndexLinear, IndexStyle, Ab...
this line was needed, otherwise compilation fails
# This file is a part of Julia. License is MIT: https://julialang.org/license """ Methods for working with Iterators. """ baremodule Iterators # small dance to make this work from Base or Intrinsics import Base: @__MODULE__, parentmodule const Base = parentmodule(@__MODULE__) using .Base: @inline, Pair, Pairs, Ab...
@@ -6,7 +6,6 @@ Methods for working with Iterators. baremodule Iterators # small dance to make this work from Base or Intrinsics -import Base: @__MODULE__, parentmodule
base/iterators.jl
9
Julia
0.071
bug
49
34
34
false
adds the `nth` function for iterables
56,580
JuliaLang/julia
35,573
Julia
adienes
ghyatzo
Review this pull request change. Language: Julia File: base/iterators.jl PR Title: adds the `nth` function for iterables BEFORE CODE: # This file is a part of Julia. License is MIT: https://julialang.org/license """ Methods for working with Iterators. """ baremodule Iterators # small dance to make this work from ...
this line was needed, otherwise compilation fails
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
function iterate(x::IterableStatePairs, state=first(keys(x.x))) it = iterate(x.x, state) it === nothing && return nothing (state => first(it), last(it)) end reverse(x::IterableStatePairs) = IterableStatePairs(Iterators.reverse(x.x)) reverse(x::IterableStatePairs{<:Iterators.Reverse}) = IterableStatePairs(x...
```suggestion See also: [`first`](@ref), [`last`](@ref) ```
function iterate(x::IterableStatePairs, state=first(keys(x.x))) it = iterate(x.x, state) it === nothing && return nothing (state => first(it), last(it)) end reverse(x::IterableStatePairs) = IterableStatePairs(Iterators.reverse(x.x)) reverse(x::IterableStatePairs{<:Iterators.Reverse}) = IterableStatePairs(x...
@@ -1602,4 +1603,92 @@ end # be the same as the keys, so this is a valid optimization (see #51631) pairs(s::AbstractString) = IterableStatePairs(s) +""" + nth(itr, n::Integer) + +Get the `n`th element of an iterable collection. Throw a `BoundsError`[@ref] if not existing. +Will advance any `Stateful`[@ref] itera...
base/iterators.jl
26
Julia
0.571
suggestion
61
51
51
false
adds the `nth` function for iterables
56,580
JuliaLang/julia
35,573
Julia
adienes
ghyatzo
Review this pull request change. Language: Julia File: base/iterators.jl PR Title: adds the `nth` function for iterables BEFORE CODE: function iterate(x::IterableStatePairs, state=first(keys(x.x))) it = iterate(x.x, state) it === nothing && return nothing (state => first(it), last(it)) end reverse(x::I...
```suggestion See also: [`first`](@ref), [`last`](@ref) ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
## 2 argument function map!(f::F, dest::AbstractArray, A::AbstractArray, B::AbstractArray) where F for (i, j, k) in zip(eachindex(dest), eachindex(A), eachindex(B)) @inbounds a, b = A[j], B[k] val = f(a, b) @inbounds dest[i] = val end return dest end ## N argument @inline ith_all(...
```suggestion idxs = mapreduce(LinearIndices, intersect, As) checkbounds(dest, inds) for i = idxs ``` - I don't see why we need `eachindex` is here - We should only include bounds-check elision if benchmarks reveal that it makes a difference. In this case, we would also need to add `@propagate_inbou...
See also: [`map`](@ref), [`foreach`](@ref), [`zip`](@ref), [`copyto!`](@ref). # Examples ```jldoctest julia> a = zeros(3); julia> map!(x -> x * 2, a, [1, 2, 3]); julia> a 3-element Vector{Float64}: 2.0 4.0 6.0 julia> map!(+, zeros(Int, 5), 100:999, 1:3) 5-element Vector{$(Int)}: 101 103 105 0 0 ``` """ ...
@@ -3462,8 +3462,11 @@ function ith_all(i, as) end function map_n!(f::F, dest::AbstractArray, As) where F - idxs1 = LinearIndices(As[1]) - @boundscheck LinearIndices(dest) == idxs1 && all(x -> LinearIndices(x) == idxs1, As) + idxs1 = eachindex(LinearIndices(As[1])) + @boundscheck begin + idxs1 = ...
base/abstractarray.jl
26
Julia
1
performance
627
51
51
false
fix map! undefined value exposure
56,673
JuliaLang/julia
35,573
Julia
LilithHafner
adienes
Review this pull request change. Language: Julia File: base/abstractarray.jl PR Title: fix map! undefined value exposure BEFORE CODE: ## 2 argument function map!(f::F, dest::AbstractArray, A::AbstractArray, B::AbstractArray) where F for (i, j, k) in zip(eachindex(dest), eachindex(A), eachindex(B)) @inb...
```suggestion idxs = mapreduce(LinearIndices, intersect, As) checkbounds(dest, inds) for i = idxs ``` - I don't see why we need `eachindex` is here - We should only include bounds-check elision if benchmarks reveal that it makes a difference. In this case, we would also need to add `@propagate_inbou...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
@test LinearAlgebra.checksquare(zeros(2,2),zeros(3,3)) == [2,3] @test_throws DimensionMismatch LinearAlgebra.checksquare(zeros(2,3)) end #----- run tests -------------------------------------------------------------# @testset for T in (T24Linear, TSlow), shape in ((24,), (2, 12), (2,3,4), (1,2,3,4), (4,3,2,1)...
Would you also add a test for https://github.com/JuliaLang/julia/issues/36235#issuecomment-2503895662, please?
@test LinearAlgebra.checksquare(zeros(2,2),zeros(3,3)) == [2,3] @test_throws DimensionMismatch LinearAlgebra.checksquare(zeros(2,3)) end #----- run tests -------------------------------------------------------------# @testset for T in (T24Linear, TSlow), shape in ((24,), (2, 12), (2,3,4), (1,2,3,4), (4,3,2,1)...
@@ -910,6 +910,9 @@ include("generic_map_tests.jl") generic_map_tests(map, map!) @test_throws ArgumentError map!(-, [1]) +# Issue #30624 +@test map!(+, [0,0,0], [1,2], [10,20,30], [100]) == [111,0,0]
test/abstractarray.jl
26
Julia
0.357
question
110
51
51
false
fix map! undefined value exposure
56,673
JuliaLang/julia
35,573
Julia
LilithHafner
adienes
Review this pull request change. Language: Julia File: test/abstractarray.jl PR Title: fix map! undefined value exposure BEFORE CODE: @test LinearAlgebra.checksquare(zeros(2,2),zeros(3,3)) == [2,3] @test_throws DimensionMismatch LinearAlgebra.checksquare(zeros(2,3)) end #----- run tests -------------------...
Would you also add a test for https://github.com/JuliaLang/julia/issues/36235#issuecomment-2503895662, please?
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
ridx = ifelse.(dim_mask, Slice.(axes(R)), Tuple(I)) R[ridx...] = r else ridx = ifelse.(dim_mask, first.(axes(R)), Tuple(I)) R[ridx...] = r end end else # we can't guarantee safety (#18524), so allocate new storag...
While this could result in normal bounds errors, the docstring permits `dest` to be larger than `A`. In those cases, this could land in-bounds but in the wrong place. Better to check explicitly that the docs are followed, and then we can still use paired indices and such. ```suggestion length(dest) < length(A...
ridx = ifelse.(dim_mask, Slice.(axes(R)), Tuple(I)) R[ridx...] = r else ridx = ifelse.(dim_mask, first.(axes(R)), Tuple(I)) R[ridx...] = r end end else # we can't guarantee safety (#18524), so allocate new storag...
@@ -3355,9 +3355,9 @@ concatenate_setindex!(R, X::AbstractArray, I...) = (R[I...] = X) ## 1 argument function map!(f::F, dest::AbstractArray, A::AbstractArray) where F - for (i,j) in zip(eachindex(dest),eachindex(A)) - val = f(@inbounds A[j]) - @inbounds dest[i] = val + inds = LinearIndices(A) +...
base/abstractarray.jl
26
Julia
1
bug
528
51
51
false
fix map! undefined value exposure
56,673
JuliaLang/julia
35,573
Julia
mbauman
adienes
Review this pull request change. Language: Julia File: base/abstractarray.jl PR Title: fix map! undefined value exposure BEFORE CODE: ridx = ifelse.(dim_mask, Slice.(axes(R)), Tuple(I)) R[ridx...] = r else ridx = ifelse.(dim_mask, first.(axes(R)), Tuple(I)...
While this could result in normal bounds errors, the docstring permits `dest` to be larger than `A`. In those cases, this could land in-bounds but in the wrong place. Better to check explicitly that the docs are followed, and then we can still use paired indices and such. ```suggestion length(dest) < length(A...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
```jldoctest julia> map(x -> x * 2, [1, 2, 3]) 3-element Vector{Int64}: 2 4 6 julia> map(+, [1, 2, 3], [10, 20, 30, 400, 5000]) 3-element Vector{Int64}: 11 22 33 ``` """ map(f, A) = collect(Generator(f,A)) # default to returning an Array for `map` on general iterators map(f, ::AbstractDict) = error("map is not ...
Similarly: ```suggestion length(dest) < min(length(A), length(B)) && throw(ArgumentError("destination is smaller than the smallest mapped argument")) for (i, j, k) in zip(eachindex(dest), eachindex(A), eachindex(B)) @inbounds a, b = A[j], B[k] val = f(a, b) @inbounds dest[i] = va...
```jldoctest julia> map(x -> x * 2, [1, 2, 3]) 3-element Vector{Int64}: 2 4 6 julia> map(+, [1, 2, 3], [10, 20, 30, 400, 5000]) 3-element Vector{Int64}: 11 22 33 ``` """ map(f, A) = collect(Generator(f,A)) # default to returning an Array for `map` on general iterators map(f, ::AbstractDict) = error("map is not ...
@@ -3400,10 +3400,11 @@ map(f, ::AbstractSet) = error("map is not defined on sets") ## 2 argument function map!(f::F, dest::AbstractArray, A::AbstractArray, B::AbstractArray) where F - for (i, j, k) in zip(eachindex(dest), eachindex(A), eachindex(B)) - @inbounds a, b = A[j], B[k] - val = f(a, b) - ...
base/abstractarray.jl
26
Julia
0.929
suggestion
359
51
51
false
fix map! undefined value exposure
56,673
JuliaLang/julia
35,573
Julia
mbauman
adienes
Review this pull request change. Language: Julia File: base/abstractarray.jl PR Title: fix map! undefined value exposure BEFORE CODE: ```jldoctest julia> map(x -> x * 2, [1, 2, 3]) 3-element Vector{Int64}: 2 4 6 julia> map(+, [1, 2, 3], [10, 20, 30, 400, 5000]) 3-element Vector{Int64}: 11 22 33 ``` """ map(f...
Similarly: ```suggestion length(dest) < min(length(A), length(B)) && throw(ArgumentError("destination is smaller than the smallest mapped argument")) for (i, j, k) in zip(eachindex(dest), eachindex(A), eachindex(B)) @inbounds a, b = A[j], B[k] val = f(a, b) @inbounds dest[i] = va...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
map(f, ::AbstractSet) = error("map is not defined on sets") ## 2 argument function map!(f::F, dest::AbstractArray, A::AbstractArray, B::AbstractArray) where F IL = IndexLinear() inds = intersect(eachindex(IL, A), eachindex(IL, B)) @boundscheck checkbounds(dest, inds) for i = inds dest[i] = f(A[...
```suggestion length(dest) < minimum(length, As) && throw(ArgumentError("destination is smaller than the smallest mapped argument")) idxs1 = LinearIndices(As[1]) if LinearIndices(dest) == idxs1 && all(x -> LinearIndices(x) == idxs1, As) for i in idxs1 @inbounds as = ith_all(i, As) ...
map(f, ::AbstractSet) = error("map is not defined on sets") ## 2 argument function map!(f::F, dest::AbstractArray, A::AbstractArray, B::AbstractArray) where F for (i, j, k) in zip(eachindex(dest), eachindex(A), eachindex(B)) @inbounds a, b = A[j], B[k] val = f(a, b) @inbounds dest[i] = val ...
@@ -3417,12 +3418,10 @@ function ith_all(i, as) end function map_n!(f::F, dest::AbstractArray, As) where F - idxs1 = LinearIndices(As[1]) - @boundscheck LinearIndices(dest) == idxs1 && all(x -> LinearIndices(x) == idxs1, As) - for i = idxs1 - @inbounds I = ith_all(i, As) - val = f(I...) - ...
base/abstractarray.jl
26
Julia
0.929
suggestion
610
51
51
false
fix map! undefined value exposure
56,673
JuliaLang/julia
35,573
Julia
mbauman
adienes
Review this pull request change. Language: Julia File: base/abstractarray.jl PR Title: fix map! undefined value exposure BEFORE CODE: map(f, ::AbstractSet) = error("map is not defined on sets") ## 2 argument function map!(f::F, dest::AbstractArray, A::AbstractArray, B::AbstractArray) where F IL = IndexLinear()...
```suggestion length(dest) < minimum(length, As) && throw(ArgumentError("destination is smaller than the smallest mapped argument")) idxs1 = LinearIndices(As[1]) if LinearIndices(dest) == idxs1 && all(x -> LinearIndices(x) == idxs1, As) for i in idxs1 @inbounds as = ith_all(i, As) ...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
sRi, sAi = length(Ri), length(Ai) if sRi == 1 if sAi > 1 if had_nonreduc lsiz = 0 # to reduce along i, but some previous dimensions were non-reducing else lsiz *= sAi # if lsiz was set to zero, it will stay to be zero ...
otherwise it will cause `maximum!` and `minimum!` on `OffsetArrays` to fail via some interaction with `mapfirst!` since `view(A::OffsetArray, :)` has offset indices but `view(A::OffsetArray, firstindex(A):lastindex(A))` has 1-based indices, so I changed the destination to match
sRi, sAi = length(Ri), length(Ai) if sRi == 1 if sAi > 1 if had_nonreduc lsiz = 0 # to reduce along i, but some previous dimensions were non-reducing else lsiz *= sAi # if lsiz was set to zero, it will stay to be zero ...
@@ -238,7 +238,7 @@ copyfirst!(R::AbstractArray, A::AbstractArray) = mapfirst!(identity, R, A) function mapfirst!(f::F, R::AbstractArray, A::AbstractArray{<:Any,N}) where {N, F} lsiz = check_reducedims(R, A) t = _firstreducedslice(axes(R), axes(A)) - map!(f, R, view(A, t...)) + map!(f, view(R, firstind...
base/reducedim.jl
26
Julia
0.643
bug
278
51
51
false
fix map! undefined value exposure
56,673
JuliaLang/julia
35,573
Julia
adienes
adienes
Review this pull request change. Language: Julia File: base/reducedim.jl PR Title: fix map! undefined value exposure BEFORE CODE: sRi, sAi = length(Ri), length(Ai) if sRi == 1 if sAi > 1 if had_nonreduc lsiz = 0 # to reduce along i, but some previous ...
otherwise it will cause `maximum!` and `minimum!` on `OffsetArrays` to fail via some interaction with `mapfirst!` since `view(A::OffsetArray, :)` has offset indices but `view(A::OffsetArray, firstindex(A):lastindex(A))` has 1-based indices, so I changed the destination to match
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
## shuffle & shuffle! function _tuple_without_element_at_index(tup::(Tuple{T, Vararg{T, N}} where {T}), i::Int) where {N} clo = let tup = tup, i = i function closure(j::Int) k = if j < i j else j + 1 end tup[k] end ...
It's also possible to rely on `Memory` getting stack-allocated, avoiding recursion: ```suggestion function shuffle(rng::AbstractRNG, tup::(Tuple{Vararg{T, N}} where {T})) where {N} if tup isa Tuple{Any, Vararg} @inline let # `@inline` and `@inbounds` are here to help escape analysis clo ...
## shuffle & shuffle! function shuffle(rng::AbstractRNG, tup::NTuple{N}) where {N} # `@inline` and `@inbounds` are here to help escape analysis eliminate the `Memory` allocation # # * `@inline` might be necessary because escape analysis relies on everything # touching the `Memory` being inlined becau...
@@ -183,6 +183,36 @@ ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw( ## shuffle & shuffle! +function _tuple_without_element_at_index(tup::(Tuple{T, Vararg{T, N}} where {T}), i::Int) where {N} + clo = let tup = tup, i = i + function closure(j::Int) + k = if j < ...
stdlib/Random/src/misc.jl
26
Julia
1
security
812
51
51
false
add `shuffle(::NTuple)` to `Random`
56,906
JuliaLang/julia
35,573
Julia
nsajko
nsajko
Review this pull request change. Language: Julia File: stdlib/Random/src/misc.jl PR Title: add `shuffle(::NTuple)` to `Random` BEFORE CODE: ## shuffle & shuffle! function _tuple_without_element_at_index(tup::(Tuple{T, Vararg{T, N}} where {T}), i::Int) where {N} clo = let tup = tup, i = i function closu...
It's also possible to rely on `Memory` getting stack-allocated, avoiding recursion: ```suggestion function shuffle(rng::AbstractRNG, tup::(Tuple{Vararg{T, N}} where {T})) where {N} if tup isa Tuple{Any, Vararg} @inline let # `@inline` and `@inbounds` are here to help escape analysis clo ...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
large.) Technically, this process is known as "Bernoulli sampling" of `A`. # Examples ```jldoctest julia> randsubseq(Xoshiro(123), 1:8, 0.3) 2-element Vector{Int64}: 4 7 ``` """ randsubseq(A::AbstractArray, p::Real) = randsubseq(default_rng(), A, p) ## rand Less Than Masked 52 bits (helper function) "Return a sam...
```suggestion shuffle!(rng, mem) ```
large.) Technically, this process is known as "Bernoulli sampling" of `A`. # Examples ```jldoctest julia> randsubseq(Xoshiro(123), 1:8, 0.3) 2-element Vector{Int64}: 4 7 ``` """ randsubseq(A::AbstractArray, p::Real) = randsubseq(default_rng(), A, p) ## rand Less Than Masked 52 bits (helper function) "Return a sam...
@@ -183,6 +183,29 @@ ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw( ## shuffle & shuffle! +function shuffle(rng::AbstractRNG, tup::(Tuple{Vararg{T, N}} where {T})) where {N} + if tup isa Tuple{Any, Vararg} + @inline let # `@inline` and `@inbounds` are here to help escap...
stdlib/Random/src/misc.jl
26
Julia
0.571
suggestion
54
51
51
false
add `shuffle(::NTuple)` to `Random`
56,906
JuliaLang/julia
35,573
Julia
nsajko
nsajko
Review this pull request change. Language: Julia File: stdlib/Random/src/misc.jl PR Title: add `shuffle(::NTuple)` to `Random` BEFORE CODE: large.) Technically, this process is known as "Bernoulli sampling" of `A`. # Examples ```jldoctest julia> randsubseq(Xoshiro(123), 1:8, 0.3) 2-element Vector{Int64}: 4 7 ```...
```suggestion shuffle!(rng, mem) ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
large.) Technically, this process is known as "Bernoulli sampling" of `A`. # Examples ```jldoctest julia> randsubseq(Xoshiro(123), 1:8, 0.3) 2-element Vector{Int64}: 4 7 ``` """ randsubseq(A::AbstractArray, p::Real) = randsubseq(default_rng(), A, p) ## rand Less Than Masked 52 bits (helper function) "Return a sam...
```suggestion randperm!(rng, mem) ```
large.) Technically, this process is known as "Bernoulli sampling" of `A`. # Examples ```jldoctest julia> randsubseq(Xoshiro(123), 1:8, 0.3) 2-element Vector{Int64}: 4 7 ``` """ randsubseq(A::AbstractArray, p::Real) = randsubseq(default_rng(), A, p) ## rand Less Than Masked 52 bits (helper function) "Return a sam...
@@ -183,6 +183,29 @@ ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw( ## shuffle & shuffle! +function shuffle(rng::AbstractRNG, tup::(Tuple{Vararg{T, N}} where {T})) where {N} + if tup isa Tuple{Any, Vararg} + @inline let # `@inline` and `@inbounds` are here to help escap...
stdlib/Random/src/misc.jl
26
Julia
0.571
suggestion
55
51
51
false
add `shuffle(::NTuple)` to `Random`
56,906
JuliaLang/julia
35,573
Julia
nsajko
nsajko
Review this pull request change. Language: Julia File: stdlib/Random/src/misc.jl PR Title: add `shuffle(::NTuple)` to `Random` BEFORE CODE: large.) Technically, this process is known as "Bernoulli sampling" of `A`. # Examples ```jldoctest julia> randsubseq(Xoshiro(123), 1:8, 0.3) 2-element Vector{Int64}: 4 7 ```...
```suggestion randperm!(rng, mem) ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
randsubseq([rng=default_rng(),] A, p) -> Vector Return a vector consisting of a random subsequence of the given array `A`, where each element of `A` is included (in order) with independent probability `p`. (Complexity is linear in `p*length(A)`, so this function is efficient even if `p` is small and `A` is large.)...
Why not the simpler ```suggestion function shuffle(rng::AbstractRNG, tup::NTuple{N}) where {N} ``` ?
randsubseq([rng=default_rng(),] A, p) -> Vector Return a vector consisting of a random subsequence of the given array `A`, where each element of `A` is included (in order) with independent probability `p`. (Complexity is linear in `p*length(A)`, so this function is efficient even if `p` is small and `A` is large.)...
@@ -183,6 +183,32 @@ ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw( ## shuffle & shuffle! +function shuffle(rng::AbstractRNG, tup::(Tuple{Vararg{T, N}} where {T})) where {N}
stdlib/Random/src/misc.jl
26
Julia
0.714
refactor
104
51
51
false
add `shuffle(::NTuple)` to `Random`
56,906
JuliaLang/julia
35,573
Julia
rfourquet
nsajko
Review this pull request change. Language: Julia File: stdlib/Random/src/misc.jl PR Title: add `shuffle(::NTuple)` to `Random` BEFORE CODE: randsubseq([rng=default_rng(),] A, p) -> Vector Return a vector consisting of a random subsequence of the given array `A`, where each element of `A` is included (in order)...
Why not the simpler ```suggestion function shuffle(rng::AbstractRNG, tup::NTuple{N}) where {N} ``` ?
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
2-element Vector{Int64}: 4 7 ``` """ randsubseq(A::AbstractArray, p::Real) = randsubseq(default_rng(), A, p) ## rand Less Than Masked 52 bits (helper function) "Return a sampler generating a random `Int` (masked with `mask`) in ``[0, n)``, when `n <= 2^52`." ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1,...
What is the intended effect of this `@inbounds`, given that there is another one below in front of the indexing?
2-element Vector{Int64}: 4 7 ``` """ randsubseq(A::AbstractArray, p::Real) = randsubseq(default_rng(), A, p) ## rand Less Than Masked 52 bits (helper function) "Return a sampler generating a random `Int` (masked with `mask`) in ``[0, n)``, when `n <= 2^52`." ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1,...
@@ -183,6 +183,32 @@ ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw( ## shuffle & shuffle! +function shuffle(rng::AbstractRNG, tup::(Tuple{Vararg{T, N}} where {T})) where {N} + @inline let # `@inline` and `@inbounds` are here to help escape analysis + # use a narrow inte...
stdlib/Random/src/misc.jl
26
Julia
0.5
question
112
51
51
false
add `shuffle(::NTuple)` to `Random`
56,906
JuliaLang/julia
35,573
Julia
rfourquet
nsajko
Review this pull request change. Language: Julia File: stdlib/Random/src/misc.jl PR Title: add `shuffle(::NTuple)` to `Random` BEFORE CODE: 2-element Vector{Int64}: 4 7 ``` """ randsubseq(A::AbstractArray, p::Real) = randsubseq(default_rng(), A, p) ## rand Less Than Masked 52 bits (helper function) "Return a s...
What is the intended effect of this `@inbounds`, given that there is another one below in front of the indexing?
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
function shuffle(rng::AbstractRNG, tup::(Tuple{Vararg{T, N}} where {T})) where {N} @inline let # `@inline` and `@inbounds` are here to help escape analysis # use a narrow integer type to save stack space and prevent heap allocation Ind = if N ≤ typemax(UInt8) UInt8 elseif N ≤ t...
Personal preference, feel free to ignore: ```suggestion shuffle(tup::NTuple) = shuffle(default_rng(), tup) ```
function shuffle(rng::AbstractRNG, tup::NTuple{N}) where {N} # `@inline` and `@inbounds` are here to help escape analysis eliminate the `Memory` allocation # # * `@inline` might be necessary because escape analysis relies on everything # touching the `Memory` being inlined because there's no interpro...
@@ -183,6 +183,32 @@ ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw( ## shuffle & shuffle! +function shuffle(rng::AbstractRNG, tup::(Tuple{Vararg{T, N}} where {T})) where {N} + @inline let # `@inline` and `@inbounds` are here to help escape analysis + # use a narrow inte...
stdlib/Random/src/misc.jl
26
Julia
0.786
suggestion
113
51
51
false
add `shuffle(::NTuple)` to `Random`
56,906
JuliaLang/julia
35,573
Julia
rfourquet
nsajko
Review this pull request change. Language: Julia File: stdlib/Random/src/misc.jl PR Title: add `shuffle(::NTuple)` to `Random` BEFORE CODE: function shuffle(rng::AbstractRNG, tup::(Tuple{Vararg{T, N}} where {T})) where {N} @inline let # `@inline` and `@inbounds` are here to help escape analysis # use ...
Personal preference, feel free to ignore: ```suggestion shuffle(tup::NTuple) = shuffle(default_rng(), tup) ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
4 7 ``` """ randsubseq(A::AbstractArray, p::Real) = randsubseq(default_rng(), A, p) ## rand Less Than Masked 52 bits (helper function) "Return a sampler generating a random `Int` (masked with `mask`) in ``[0, n)``, when `n <= 2^52`." ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw(I...
```suggestion shuffle!(rng, copyto!(mem, Base.OneTo(N))) # just use `randperm!` once it supports `Memory` ```
4 7 ``` """ randsubseq(A::AbstractArray, p::Real) = randsubseq(default_rng(), A, p) ## rand Less Than Masked 52 bits (helper function) "Return a sampler generating a random `Int` (masked with `mask`) in ``[0, n)``, when `n <= 2^52`." ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw(I...
@@ -183,6 +183,32 @@ ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw( ## shuffle & shuffle! +function shuffle(rng::AbstractRNG, tup::(Tuple{Vararg{T, N}} where {T})) where {N} + @inline let # `@inline` and `@inbounds` are here to help escape analysis + # use a narrow inte...
stdlib/Random/src/misc.jl
26
Julia
0.929
performance
124
51
51
false
add `shuffle(::NTuple)` to `Random`
56,906
JuliaLang/julia
35,573
Julia
nsajko
nsajko
Review this pull request change. Language: Julia File: stdlib/Random/src/misc.jl PR Title: add `shuffle(::NTuple)` to `Random` BEFORE CODE: 4 7 ``` """ randsubseq(A::AbstractArray, p::Real) = randsubseq(default_rng(), A, p) ## rand Less Than Masked 52 bits (helper function) "Return a sampler generating a rando...
```suggestion shuffle!(rng, copyto!(mem, Base.OneTo(N))) # just use `randperm!` once it supports `Memory` ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
Return a randomly permuted copy of `v`. The optional `rng` argument specifies a random number generator (see [Random Numbers](@ref)). To permute `v` in-place, see [`shuffle!`](@ref). To obtain randomly permuted indices, see [`randperm`](@ref). # Examples ```jldoctest julia> shuffle(Xoshiro(123), Vector(1:10)) 10-elem...
```suggestion shuffle(a::Union{Tuple, AbstractArray}) = shuffle(default_rng(), a) ```
""" shuffle([rng=default_rng(),] v::Union{NTuple,AbstractArray}) Return a randomly permuted copy of `v`. The optional `rng` argument specifies a random number generator (see [Random Numbers](@ref)). To permute `v` in-place, see [`shuffle!`](@ref). To obtain randomly permuted indices, see [`randperm`](@ref). !!! c...
@@ -261,6 +287,8 @@ julia> shuffle(Xoshiro(123), Vector(1:10)) 7 ``` """ +function shuffle end + shuffle(r::AbstractRNG, a::AbstractArray) = shuffle!(r, copymutable(a)) shuffle(a::AbstractArray) = shuffle(default_rng(), a)
stdlib/Random/src/misc.jl
26
Julia
0.571
refactor
87
51
51
false
add `shuffle(::NTuple)` to `Random`
56,906
JuliaLang/julia
35,573
Julia
rfourquet
nsajko
Review this pull request change. Language: Julia File: stdlib/Random/src/misc.jl PR Title: add `shuffle(::NTuple)` to `Random` BEFORE CODE: Return a randomly permuted copy of `v`. The optional `rng` argument specifies a random number generator (see [Random Numbers](@ref)). To permute `v` in-place, see [`shuffle!`]...
```suggestion shuffle(a::Union{Tuple, AbstractArray}) = shuffle(default_rng(), a) ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
@test maximum(m) <= 0.106 end @testset "`shuffle(::NTuple)`" begin @testset "sorted" begin for n ∈ 0:20 tup = ntuple(identity, n) @test tup === sort(@inferred shuffle(tup)) end end @testset "not identity" begin function is_not_identity_at_least_once() ...
This testset fails with `--check-bounds=yes` (which is how the test suite gets run), so I'm just going to delete it. The reason is, as discussed, that escape analysis fails in the presence of bounds checking. ```suggestion ```
# Test that shuffle! is uniformly random on BitArrays rng = MersenneTwister(123) a = (reshape(1:(4*5), 4, 5) .<= 2) # 4x5 BitMatrix whose first two elements are true, rest are false m = sum(1:50_000) do _ shuffle!(rng, a) end/50_000 # mean result of shuffle!-ing a 50_000 times. If the shuffl...
@@ -1063,6 +1063,34 @@ end @test maximum(m) <= 0.106 end +@testset "`shuffle(::NTuple)`" begin + @testset "sorted" begin + for n ∈ 0:20 + tup = ntuple(identity, n) + @test tup === sort(@inferred shuffle(tup)) + end + end + @testset "not identity" begin + funct...
stdlib/Random/test/runtests.jl
26
Julia
0.786
bug
230
51
51
false
add `shuffle(::NTuple)` to `Random`
56,906
JuliaLang/julia
35,573
Julia
nsajko
nsajko
Review this pull request change. Language: Julia File: stdlib/Random/test/runtests.jl PR Title: add `shuffle(::NTuple)` to `Random` BEFORE CODE: @test maximum(m) <= 0.106 end @testset "`shuffle(::NTuple)`" begin @testset "sorted" begin for n ∈ 0:20 tup = ntuple(identity, n) ...
This testset fails with `--check-bounds=yes` (which is how the test suite gets run), so I'm just going to delete it. The reason is, as discussed, that escape analysis fails in the presence of bounds checking. ```suggestion ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
rng = MersenneTwister(123) a = (reshape(1:(4*5), 4, 5) .<= 2) # 4x5 BitMatrix whose first two elements are true, rest are false m = sum(1:50_000) do _ shuffle!(rng, a) end/50_000 # mean result of shuffle!-ing a 50_000 times. If the shuffle! is uniform, then each index has a # 10% chance of h...
I'm confused... is the goal to clarify what the test ("check not identity at least once") does ? What about ```suggestion # shuffle should not be the identity at least once tup = ntuple(identity, 9) @test any(1:1000000) do _ tup != shuffle(tup) end ```
x = rand(s) # should use precision of s @test precision(x) == 100 x = BigFloat() @test_throws ArgumentError rand!(rng, x, s) # incompatible precision end @testset "shuffle! for BitArray" begin # Test that shuffle! is uniformly random on BitArrays rng = MersenneTwister(123) a = (reshape(1:(4...
@@ -1063,6 +1063,25 @@ end @test maximum(m) <= 0.106 end +@testset "`shuffle(::NTuple)`" begin + @testset "sorted" begin + for n ∈ 0:20 + tup = ntuple(identity, n) + @test tup === sort(@inferred shuffle(tup)) + end + end + @testset "not identity" begin + funct...
stdlib/Random/test/runtests.jl
26
Julia
0.857
suggestion
304
51
51
false
add `shuffle(::NTuple)` to `Random`
56,906
JuliaLang/julia
35,573
Julia
rfourquet
nsajko
Review this pull request change. Language: Julia File: stdlib/Random/test/runtests.jl PR Title: add `shuffle(::NTuple)` to `Random` BEFORE CODE: rng = MersenneTwister(123) a = (reshape(1:(4*5), 4, 5) .<= 2) # 4x5 BitMatrix whose first two elements are true, rest are false m = sum(1:50_000) do _ ...
I'm confused... is the goal to clarify what the test ("check not identity at least once") does ? What about ```suggestion # shuffle should not be the identity at least once tup = ntuple(identity, 9) @test any(1:1000000) do _ tup != shuffle(tup) end ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
7 ``` """ randsubseq(A::AbstractArray, p::Real) = randsubseq(default_rng(), A, p) ## rand Less Than Masked 52 bits (helper function) "Return a sampler generating a random `Int` (masked with `mask`) in ``[0, n)``, when `n <= 2^52`." ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw(Int)...
I tested both with and without this `let` and couldn't notice a difference. Is it really necessary here?
7 ``` """ randsubseq(A::AbstractArray, p::Real) = randsubseq(default_rng(), A, p) ## rand Less Than Masked 52 bits (helper function) "Return a sampler generating a random `Int` (masked with `mask`) in ``[0, n)``, when `n <= 2^52`." ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw(Int)...
@@ -183,6 +183,28 @@ ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw( ## shuffle & shuffle! +function shuffle(rng::AbstractRNG, tup::NTuple{N}) where {N} + @inline let # `@inline` and `@inbounds` are here to help escape analysis + # use a narrow integer type to save stack...
stdlib/Random/src/misc.jl
26
Julia
0.571
question
104
51
51
false
add `shuffle(::NTuple)` to `Random`
56,906
JuliaLang/julia
35,573
Julia
rfourquet
nsajko
Review this pull request change. Language: Julia File: stdlib/Random/src/misc.jl PR Title: add `shuffle(::NTuple)` to `Random` BEFORE CODE: 7 ``` """ randsubseq(A::AbstractArray, p::Real) = randsubseq(default_rng(), A, p) ## rand Less Than Masked 52 bits (helper function) "Return a sampler generating a random `...
I tested both with and without this `let` and couldn't notice a difference. Is it really necessary here?
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
j = 1 + rand(r, ltm52(i, mask)) a[i], a[j] = a[j], a[i] i == 1 + mask && (mask = 2 * mask + 1) end return a end function shuffle!(r::AbstractRNG, a::AbstractArray{Bool}) old_count = count(a) len = length(a) uncommon_value = 2old_count <= len fuel = uncommon_value ? old_c...
```suggestion shuffle([rng=default_rng(),] v::Union{NTuple,AbstractArray}) ```
require_one_based_indexing(a) n = length(a) @assert n <= Int64(2)^52 n == 0 && return a mask = 3 @inbounds for i = 2:n j = 1 + rand(r, ltm52(i, mask)) a[i], a[j] = a[j], a[i] i == 1 + mask && (mask = 2 * mask + 1) end return a end function shuffle!(r::AbstractRNG...
@@ -238,7 +260,7 @@ end shuffle!(a::AbstractArray) = shuffle!(default_rng(), a) """ - shuffle([rng=default_rng(),] v::AbstractArray) + shuffle([rng=default_rng(),] v::Union{Tuple,AbstractArray})
stdlib/Random/src/misc.jl
26
Julia
0.571
refactor
84
51
51
false
add `shuffle(::NTuple)` to `Random`
56,906
JuliaLang/julia
35,573
Julia
rfourquet
nsajko
Review this pull request change. Language: Julia File: stdlib/Random/src/misc.jl PR Title: add `shuffle(::NTuple)` to `Random` BEFORE CODE: j = 1 + rand(r, ltm52(i, mask)) a[i], a[j] = a[j], a[i] i == 1 + mask && (mask = 2 * mask + 1) end return a end function shuffle!(r::AbstractRN...
```suggestion shuffle([rng=default_rng(),] v::Union{NTuple,AbstractArray}) ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
``` """ randsubseq(A::AbstractArray, p::Real) = randsubseq(default_rng(), A, p) ## rand Less Than Masked 52 bits (helper function) "Return a sampler generating a random `Int` (masked with `mask`) in ``[0, n)``, when `n <= 2^52`." ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw(Int))) ...
for which sizes of tuples does this `Ind` help? is there a cutoff?
``` """ randsubseq(A::AbstractArray, p::Real) = randsubseq(default_rng(), A, p) ## rand Less Than Masked 52 bits (helper function) "Return a sampler generating a random `Int` (masked with `mask`) in ``[0, n)``, when `n <= 2^52`." ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw(Int))) ...
@@ -183,6 +183,34 @@ ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw( ## shuffle & shuffle! +function shuffle(rng::AbstractRNG, tup::NTuple{N}) where {N} + # `@inline` and `@inbounds` are here to help escape analysis eliminate the `Memory` allocation + # + # * `@inline` mig...
stdlib/Random/src/misc.jl
26
Julia
0.357
question
66
51
51
false
add `shuffle(::NTuple)` to `Random`
56,906
JuliaLang/julia
35,573
Julia
adienes
nsajko
Review this pull request change. Language: Julia File: stdlib/Random/src/misc.jl PR Title: add `shuffle(::NTuple)` to `Random` BEFORE CODE: ``` """ randsubseq(A::AbstractArray, p::Real) = randsubseq(default_rng(), A, p) ## rand Less Than Masked 52 bits (helper function) "Return a sampler generating a random `Int...
for which sizes of tuples does this `Ind` help? is there a cutoff?
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw(Int))) ## shuffle & shuffle! function shuffle(rng::AbstractRNG, tup::NTuple{N}) where {N} # `@inline` and `@inbounds` are here to help escape analysis eliminate the `Memory` allocation # # * `@inline` might be necessary becaus...
could this be a `Fix1` or an anonymous function?
ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw(Int))) ## shuffle & shuffle! function shuffle(rng::AbstractRNG, tup::NTuple{N}) where {N} # `@inline` and `@inbounds` are here to help escape analysis eliminate the `Memory` allocation # # * `@inline` might be necessary becaus...
@@ -183,6 +183,34 @@ ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw( ## shuffle & shuffle! +function shuffle(rng::AbstractRNG, tup::NTuple{N}) where {N} + # `@inline` and `@inbounds` are here to help escape analysis eliminate the `Memory` allocation + # + # * `@inline` mig...
stdlib/Random/src/misc.jl
26
Julia
0.286
question
48
51
51
false
add `shuffle(::NTuple)` to `Random`
56,906
JuliaLang/julia
35,573
Julia
adienes
nsajko
Review this pull request change. Language: Julia File: stdlib/Random/src/misc.jl PR Title: add `shuffle(::NTuple)` to `Random` BEFORE CODE: ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw(Int))) ## shuffle & shuffle! function shuffle(rng::AbstractRNG, tup::NTuple{N}) where {N} ...
could this be a `Fix1` or an anonymous function?
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
function shuffle(rng::AbstractRNG, tup::NTuple{N}) where {N} # `@inline` and `@inbounds` are here to help escape analysis eliminate the `Memory` allocation # # * `@inline` might be necessary because escape analysis relies on everything # touching the `Memory` being inlined because there's no interpro...
```suggestion ntuple(closure, Val{N}()) ``` is the return type assertion actually necessary if `closure` is type stable?
function shuffle(rng::AbstractRNG, tup::NTuple{N}) where {N} # `@inline` and `@inbounds` are here to help escape analysis eliminate the `Memory` allocation # # * `@inline` might be necessary because escape analysis relies on everything # touching the `Memory` being inlined because there's no interpro...
@@ -183,6 +183,34 @@ ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw( ## shuffle & shuffle! +function shuffle(rng::AbstractRNG, tup::NTuple{N}) where {N} + # `@inline` and `@inbounds` are here to help escape analysis eliminate the `Memory` allocation + # + # * `@inline` mig...
stdlib/Random/src/misc.jl
26
Julia
0.857
question
133
51
51
false
add `shuffle(::NTuple)` to `Random`
56,906
JuliaLang/julia
35,573
Julia
adienes
nsajko
Review this pull request change. Language: Julia File: stdlib/Random/src/misc.jl PR Title: add `shuffle(::NTuple)` to `Random` BEFORE CODE: function shuffle(rng::AbstractRNG, tup::NTuple{N}) where {N} # `@inline` and `@inbounds` are here to help escape analysis eliminate the `Memory` allocation # # * `...
```suggestion ntuple(closure, Val{N}()) ``` is the return type assertion actually necessary if `closure` is type stable?
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
""" String(v::AbstractVector{UInt8}) = unsafe_takestring(copyto!(StringMemory(length(v)), v)) function String(v::Vector{UInt8}) #return ccall(:jl_array_to_string, Ref{String}, (Any,), v) len = length(v) len == 0 && return "" ref = v.ref if ref.ptr_or_offset == ref.mem.ptr str = ccall(:jl_gen...
Hmm, the `Cstring` versions is unary. So perhaps ```suggestion unsafe_string(p::Ptr{UInt8}, [length::Integer]) unsafe_string(p::Cstring) ``` But I am not completely sure if this is supposed to be "official". If it is, then one can also wonder about the methods dealing with "wide" strings: `Cwstring` and `P...
""" String(v::AbstractVector{UInt8}) = unsafe_takestring(copyto!(StringMemory(length(v)), v)) function String(v::Vector{UInt8}) len = length(v) len == 0 && return "" ref = v.ref if ref.ptr_or_offset == ref.mem.ptr str = ccall(:jl_genericmemory_to_string, Ref{String}, (Any, Int), ref.mem, len) ...
@@ -85,7 +85,7 @@ function unsafe_takestring(m::Memory{UInt8}) end """ - unsafe_string(p::Ptr{UInt8}, [length::Integer]) + unsafe_string(p::Union{Ptr{UInt8},Cstring}, [length::Integer])
base/strings/string.jl
26
Julia
0.786
suggestion
353
51
51
false
document that unsafe_string accepts Cstring
56,907
JuliaLang/julia
35,573
Julia
fingolfin
stevengj
Review this pull request change. Language: Julia File: base/strings/string.jl PR Title: document that unsafe_string accepts Cstring BEFORE CODE: """ String(v::AbstractVector{UInt8}) = unsafe_takestring(copyto!(StringMemory(length(v)), v)) function String(v::Vector{UInt8}) #return ccall(:jl_array_to_string, Ref{...
Hmm, the `Cstring` versions is unary. So perhaps ```suggestion unsafe_string(p::Ptr{UInt8}, [length::Integer]) unsafe_string(p::Cstring) ``` But I am not completely sure if this is supposed to be "official". If it is, then one can also wonder about the methods dealing with "wide" strings: `Cwstring` and `P...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
""" unsafe_string(p::Ptr{UInt8}, [length::Integer]) unsafe_string(p::Cstring) Copy a string from the address of a C-style (NUL-terminated) string encoded as UTF-8. (The pointer can be safely freed afterwards.) If `length` is specified (the length of the data in bytes), the string does not have to be NUL-termin...
Also `Cwstring` and `Ptr{UInt8}` ? ``` julia> methods(unsafe_string) # 5 methods for generic function "unsafe_string" from Base: [1] unsafe_string(cw::Cwstring) @ strings/cstring.jl:307 [2] unsafe_string(s::Cstring) @ strings/cstring.jl:62 [3] unsafe_string(p::Ptr{T}, length::Integer) where T<:Un...
""" function unsafe_takestring(m::Memory{UInt8}) isempty(m) ? "" : ccall(:jl_genericmemory_to_string, Ref{String}, (Any, Int), m, length(m)) end """ takestring!(x) -> String Create a string from the content of `x`, emptying `x`. # Examples ```jldoctest julia> v = [0x61, 0x62, 0x63]; julia> s = takestring!(v...
@@ -86,6 +86,7 @@ end """ unsafe_string(p::Ptr{UInt8}, [length::Integer]) + unsafe_string(p::Cstring)
base/strings/string.jl
26
Julia
0.786
suggestion
561
51
51
false
document that unsafe_string accepts Cstring
56,907
JuliaLang/julia
35,573
Julia
vchuravy
stevengj
Review this pull request change. Language: Julia File: base/strings/string.jl PR Title: document that unsafe_string accepts Cstring BEFORE CODE: """ unsafe_string(p::Ptr{UInt8}, [length::Integer]) unsafe_string(p::Cstring) Copy a string from the address of a C-style (NUL-terminated) string encoded as UTF-8...
Also `Cwstring` and `Ptr{UInt8}` ? ``` julia> methods(unsafe_string) # 5 methods for generic function "unsafe_string" from Base: [1] unsafe_string(cw::Cwstring) @ strings/cstring.jl:307 [2] unsafe_string(s::Cstring) @ strings/cstring.jl:62 [3] unsafe_string(p::Ptr{T}, length::Integer) where T<:Un...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
ret < 0 && utf8proc_error(ret) return ret end function utf8proc_decompose(str, options, buffer, nwords, chartransform::F) where F ret = ccall(:utf8proc_decompose_custom, Int, (Ptr{UInt8}, Int, Ptr{UInt8}, Int, Cint, Ptr{Cvoid}, Ref{F}), str, sizeof(str), buffer, nwords, options, ...
I guess it's nicer to make it a doc string, using Markdown: ```suggestion """ `Dict` of `original codepoint => replacement codepoint` normalizations to perform on Julia identifiers, to canonicalize characters that are both easily confused and easily inputted by accident. !!! warning When this table is up...
ret < 0 && utf8proc_error(ret) return ret end function utf8proc_decompose(str, options, buffer, nwords, chartransform::F) where F ret = ccall(:utf8proc_decompose_custom, Int, (Ptr{UInt8}, Int, Ptr{UInt8}, Int, Cint, Ptr{Cvoid}, Ref{F}), str, sizeof(str), buffer, nwords, options, ...
@@ -174,14 +174,19 @@ function utf8proc_map(str::Union{String,SubString{String}}, options::Integer, ch return String(resize!(buffer, nbytes)) end -# from julia_charmap.h, used by julia_chartransform in the Unicode stdlib +# Array of {original codepoint, replacement codepoint} normalizations +# to perform on Jul...
base/strings/unicode.jl
26
Julia
0.857
suggestion
409
51
51
false
base/strings: Add documentation to unicode conversion table
56,929
JuliaLang/julia
35,573
Julia
nsajko
eschnett
Review this pull request change. Language: Julia File: base/strings/unicode.jl PR Title: base/strings: Add documentation to unicode conversion table BEFORE CODE: ret < 0 && utf8proc_error(ret) return ret end function utf8proc_decompose(str, options, buffer, nwords, chartransform::F) where F ret = ccall(...
I guess it's nicer to make it a doc string, using Markdown: ```suggestion """ `Dict` of `original codepoint => replacement codepoint` normalizations to perform on Julia identifiers, to canonicalize characters that are both easily confused and easily inputted by accident. !!! warning When this table is up...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
over the `--trace-eval` command-line option. Set to: - `nothing` - use the command-line `--trace-eval` setting (default) - `:no` - disable expression tracing - `:loc` - show only location information during evaluation - `:full` - show full expressions being evaluated # Examples ```julia # Enable full expression traci...
Can be a typed global instead of `Ref`? Also, does it need a `nothing` value?
Set to: - `nothing` - use the command-line `--trace-eval` setting (default) - `:no` - disable expression tracing - `:loc` - show only location information during evaluation - `:full` - show full expressions being evaluated # Examples ```julia # Enable full expression tracing Base.TRACE_EVAL = :full # Show only locati...
@@ -2323,6 +2323,39 @@ const toplevel_load = Ref(true) const _require_world_age = Ref{UInt}(typemax(UInt)) +# Global control for trace eval functionality that takes priority over --trace-eval command line arg +# Can be set to :no, :loc, :full, or nothing (to use command line setting) +""" + Base.TRACE_EVAL + +G...
base/loading.jl
26
Julia
0.571
question
77
51
51
false
Add `--trace-eval` and `Base.TRACE_EVAL` for showing each top level eval
57,137
JuliaLang/julia
35,573
Julia
KristofferC
IanButterworth
Review this pull request change. Language: Julia File: base/loading.jl PR Title: Add `--trace-eval` and `Base.TRACE_EVAL` for showing each top level eval BEFORE CODE: over the `--trace-eval` command-line option. Set to: - `nothing` - use the command-line `--trace-eval` setting (default) - `:no` - disable expressio...
Can be a typed global instead of `Ref`? Also, does it need a `nothing` value?
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
signed(::Type{UInt32}) = Int32 signed(::Type{UInt64}) = Int64 signed(::Type{UInt128}) = Int128 signed(::Type{T}) where {T<:Signed} = T ## integer comparisons ## (<)(x::T, y::T) where {T<:BitSigned} = slt_int(x, y) (-)(x::BitInteger) = neg_int(x) (-)(x::T, y::T) where {T<:BitInteger} = sub_int(x, ...
```suggestion mul_hi(a::T, b::T) where {T<:Base.BitInteger} ``` This doesn't yet support general `Integer`s. Alternatively, it would be reasonable to declare it with `T <: Integer` if we defined it for other Base integers (i.e. `Bool`, `BigInt`) or decide that we want mul_hi to throw on BigInt, and specify a...
signed(::Type{UInt32}) = Int32 signed(::Type{UInt64}) = Int64 signed(::Type{UInt128}) = Int128 signed(::Type{T}) where {T<:Signed} = T ## integer comparisons ## (<)(x::T, y::T) where {T<:BitSigned} = slt_int(x, y) (-)(x::BitInteger) = neg_int(x) (-)(x::T, y::T) where {T<:BitInteger} = sub_int(x, ...
@@ -96,6 +96,44 @@ inv(x::Integer) = float(one(x)) / float(x) # skip promotion for system integer types (/)(x::BitInteger, y::BitInteger) = float(x) / float(y) + +""" + mul_hi(a::T, b::T) where {T<:Integer}
base/int.jl
26
Julia
1
suggestion
426
51
51
false
Add mul_hi function for bit integers
57,276
JuliaLang/julia
35,573
Julia
LilithHafner
sumiya11
Review this pull request change. Language: Julia File: base/int.jl PR Title: Add mul_hi function for bit integers BEFORE CODE: signed(::Type{UInt32}) = Int32 signed(::Type{UInt64}) = Int64 signed(::Type{UInt128}) = Int128 signed(::Type{T}) where {T<:Signed} = T ## integer comparisons ## (<)(x::T, y::T) where {T<:...
```suggestion mul_hi(a::T, b::T) where {T<:Base.BitInteger} ``` This doesn't yet support general `Integer`s. Alternatively, it would be reasonable to declare it with `T <: Integer` if we defined it for other Base integers (i.e. `Bool`, `BigInt`) or decide that we want mul_hi to throw on BigInt, and specify a...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
(*)(x::T, y::T) where {T<:BitInteger} = mul_int(x, y) negate(x) = -x negate(x::Unsigned) = -convert(Signed, x) #widenegate(x) = -convert(widen(signed(typeof(x))), x) inv(x::Integer) = float(one(x)) / float(x) (/)(x::T, y::T) where {T<:Integer} = float(x) / float(y) # skip promotion for system integer types (/)(x::Bit...
```suggestion julia> Base.mul_hi(12345678987654321, 123456789) 82624 julia> (widen(12345678987654321) * 123456789) >> 64 82624 julia> Base.mul_hi(0xff, 0xff) ``` Because `mul_hi` isn't exported. This (or `using Base: mul_hi`) is required to make doctests pass.
(*)(x::T, y::T) where {T<:BitInteger} = mul_int(x, y) negate(x) = -x negate(x::Unsigned) = -convert(Signed, x) #widenegate(x) = -convert(widen(signed(typeof(x))), x) inv(x::Integer) = float(one(x)) / float(x) (/)(x::T, y::T) where {T<:Integer} = float(x) / float(y) # skip promotion for system integer types (/)(x::Bit...
@@ -96,6 +96,44 @@ inv(x::Integer) = float(one(x)) / float(x) # skip promotion for system integer types (/)(x::BitInteger, y::BitInteger) = float(x) / float(y) + +""" + mul_hi(a::T, b::T) where {T<:Base.BitInteger} + +Returns the higher half of the product of `a` and `b`. + +# Examples +```jldoctest +julia> mul_...
base/int.jl
26
Julia
0.857
suggestion
273
51
51
false
Add mul_hi function for bit integers
57,276
JuliaLang/julia
35,573
Julia
LilithHafner
sumiya11
Review this pull request change. Language: Julia File: base/int.jl PR Title: Add mul_hi function for bit integers BEFORE CODE: (*)(x::T, y::T) where {T<:BitInteger} = mul_int(x, y) negate(x) = -x negate(x::Unsigned) = -convert(Signed, x) #widenegate(x) = -convert(widen(signed(typeof(x))), x) inv(x::Integer) = flo...
```suggestion julia> Base.mul_hi(12345678987654321, 123456789) 82624 julia> (widen(12345678987654321) * 123456789) >> 64 82624 julia> Base.mul_hi(0xff, 0xff) ``` Because `mul_hi` isn't exported. This (or `using Base: mul_hi`) is required to make doctests pass.
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
moduleroot, jit_total_bytes, summarysize, isexported, ispublic, remove_linenums!, # Operators operator_associativity, operator_precedence, isbinaryoperator, isoperator, isunaryoperator, # Integer math mul_hi, # C interface cconvert, unsafe_convert, # Error han...
If this is going to be public, it'd be nice for it to have a more descriptive name (and ideally one that is stylistically consistent, i.e. germanic case rather than snake case). Perhaps `mulhighhalf` or something like that?
isidentifier, issingletontype, identify_package, locate_package, moduleroot, jit_total_bytes, summarysize, isexported, ispublic, remove_linenums!, # AST handling IR, isa_ast_node, quoted, # Operators operator_associativity, operator_precedence, isbinaryo...
@@ -71,6 +71,9 @@ public isoperator, isunaryoperator, +# Integer math + mul_hi,
base/public.jl
26
Julia
0.571
question
223
51
51
false
Add mul_hi function for bit integers
57,276
JuliaLang/julia
35,573
Julia
ararslan
sumiya11
Review this pull request change. Language: Julia File: base/public.jl PR Title: Add mul_hi function for bit integers BEFORE CODE: moduleroot, jit_total_bytes, summarysize, isexported, ispublic, remove_linenums!, # Operators operator_associativity, operator_precedence, isbinaryop...
If this is going to be public, it'd be nice for it to have a more descriptive name (and ideally one that is stylistically consistent, i.e. germanic case rather than snake case). Perhaps `mulhighhalf` or something like that?
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
inv(x::Integer) = float(one(x)) / float(x) (/)(x::T, y::T) where {T<:Integer} = float(x) / float(y) # skip promotion for system integer types (/)(x::BitInteger, y::BitInteger) = float(x) / float(y) """ mul_hi(a::T, b::T) where {T<:Base.BitInteger} Returns the higher half of the product of `a` and `b`. # Exampl...
```suggestion ((widen(a)*b) >>> Base.top_set_bit(-1 % T)) % T ``` From @StefanKarpinski at Triage
inv(x::Integer) = float(one(x)) / float(x) (/)(x::T, y::T) where {T<:Integer} = float(x) / float(y) # skip promotion for system integer types (/)(x::BitInteger, y::BitInteger) = float(x) / float(y) """ mul_hi(a::T, b::T) where {T<:Base.Integer} Returns the higher half of the product of `a` and `b` where `T` is ...
@@ -96,6 +96,44 @@ inv(x::Integer) = float(one(x)) / float(x) # skip promotion for system integer types (/)(x::BitInteger, y::BitInteger) = float(x) / float(y) + +""" + mul_hi(a::T, b::T) where {T<:Base.BitInteger} + +Returns the higher half of the product of `a` and `b`. + +# Examples +```jldoctest +julia> Base...
base/int.jl
26
Julia
0.714
suggestion
104
51
51
false
Add mul_hi function for bit integers
57,276
JuliaLang/julia
35,573
Julia
LilithHafner
sumiya11
Review this pull request change. Language: Julia File: base/int.jl PR Title: Add mul_hi function for bit integers BEFORE CODE: inv(x::Integer) = float(one(x)) / float(x) (/)(x::T, y::T) where {T<:Integer} = float(x) / float(y) # skip promotion for system integer types (/)(x::BitInteger, y::BitInteger) = float(x) /...
```suggestion ((widen(a)*b) >>> Base.top_set_bit(-1 % T)) % T ``` From @StefanKarpinski at Triage
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
#widenegate(x) = -convert(widen(signed(typeof(x))), x) inv(x::Integer) = float(one(x)) / float(x) (/)(x::T, y::T) where {T<:Integer} = float(x) / float(y) # skip promotion for system integer types (/)(x::BitInteger, y::BitInteger) = float(x) / float(y) """ mul_hi(a::T, b::T) where {T<:Base.BitInteger} Returns t...
```suggestion function mul_hi(a::T, b::T) where {T<:Integer} ```
#widenegate(x) = -convert(widen(signed(typeof(x))), x) inv(x::Integer) = float(one(x)) / float(x) (/)(x::T, y::T) where {T<:Integer} = float(x) / float(y) # skip promotion for system integer types (/)(x::BitInteger, y::BitInteger) = float(x) / float(y) """ mul_hi(a::T, b::T) where {T<:Base.Integer} Returns the ...
@@ -96,6 +96,44 @@ inv(x::Integer) = float(one(x)) / float(x) # skip promotion for system integer types (/)(x::BitInteger, y::BitInteger) = float(x) / float(y) + +""" + mul_hi(a::T, b::T) where {T<:Base.BitInteger} + +Returns the higher half of the product of `a` and `b`. + +# Examples +```jldoctest +julia> Base...
base/int.jl
26
Julia
0.571
suggestion
64
51
51
false
Add mul_hi function for bit integers
57,276
JuliaLang/julia
35,573
Julia
LilithHafner
sumiya11
Review this pull request change. Language: Julia File: base/int.jl PR Title: Add mul_hi function for bit integers BEFORE CODE: #widenegate(x) = -convert(widen(signed(typeof(x))), x) inv(x::Integer) = float(one(x)) / float(x) (/)(x::T, y::T) where {T<:Integer} = float(x) / float(y) # skip promotion for system integ...
```suggestion function mul_hi(a::T, b::T) where {T<:Integer} ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
signed(::Type{UInt32}) = Int32 signed(::Type{UInt64}) = Int64 signed(::Type{UInt128}) = Int128 signed(::Type{T}) where {T<:Signed} = T ## integer comparisons ## (<)(x::T, y::T) where {T<:BitSigned} = slt_int(x, y) (-)(x::BitInteger) = neg_int(x) (-)(x::T, y::T) where {T<:BitInteger} = sub_int(x, ...
```suggestion mul_hi(a::T, b::T) where {T<:Base.Integer} ```
signed(::Type{UInt32}) = Int32 signed(::Type{UInt64}) = Int64 signed(::Type{UInt128}) = Int128 signed(::Type{T}) where {T<:Signed} = T ## integer comparisons ## (<)(x::T, y::T) where {T<:BitSigned} = slt_int(x, y) (-)(x::BitInteger) = neg_int(x) (-)(x::T, y::T) where {T<:BitInteger} = sub_int(x, ...
@@ -96,6 +96,44 @@ inv(x::Integer) = float(one(x)) / float(x) # skip promotion for system integer types (/)(x::BitInteger, y::BitInteger) = float(x) / float(y) + +""" + mul_hi(a::T, b::T) where {T<:Base.BitInteger}
base/int.jl
26
Julia
0.571
suggestion
64
51
51
false
Add mul_hi function for bit integers
57,276
JuliaLang/julia
35,573
Julia
LilithHafner
sumiya11
Review this pull request change. Language: Julia File: base/int.jl PR Title: Add mul_hi function for bit integers BEFORE CODE: signed(::Type{UInt32}) = Int32 signed(::Type{UInt64}) = Int64 signed(::Type{UInt128}) = Int128 signed(::Type{T}) where {T<:Signed} = T ## integer comparisons ## (<)(x::T, y::T) where {T<:...
```suggestion mul_hi(a::T, b::T) where {T<:Base.Integer} ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
signed(::Type{UInt128}) = Int128 signed(::Type{T}) where {T<:Signed} = T ## integer comparisons ## (<)(x::T, y::T) where {T<:BitSigned} = slt_int(x, y) (-)(x::BitInteger) = neg_int(x) (-)(x::T, y::T) where {T<:BitInteger} = sub_int(x, y) (+)(x::T, y::T) where {T<:BitInteger} = add_int(x, y) (*)(x...
```suggestion Returns the higher half of the product of `a` and `b` where `T` is a fixed size integer. ```
signed(::Type{UInt128}) = Int128 signed(::Type{T}) where {T<:Signed} = T ## integer comparisons ## (<)(x::T, y::T) where {T<:BitSigned} = slt_int(x, y) (-)(x::BitInteger) = neg_int(x) (-)(x::T, y::T) where {T<:BitInteger} = sub_int(x, y) (+)(x::T, y::T) where {T<:BitInteger} = add_int(x, y) (*)(x...
@@ -96,6 +96,44 @@ inv(x::Integer) = float(one(x)) / float(x) # skip promotion for system integer types (/)(x::BitInteger, y::BitInteger) = float(x) / float(y) + +""" + mul_hi(a::T, b::T) where {T<:Base.BitInteger} + +Returns the higher half of the product of `a` and `b`.
base/int.jl
26
Julia
0.714
suggestion
106
51
51
false
Add mul_hi function for bit integers
57,276
JuliaLang/julia
35,573
Julia
LilithHafner
sumiya11
Review this pull request change. Language: Julia File: base/int.jl PR Title: Add mul_hi function for bit integers BEFORE CODE: signed(::Type{UInt128}) = Int128 signed(::Type{T}) where {T<:Signed} = T ## integer comparisons ## (<)(x::T, y::T) where {T<:BitSigned} = slt_int(x, y) (-)(x::BitInteger) ...
```suggestion Returns the higher half of the product of `a` and `b` where `T` is a fixed size integer. ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
julia> typeof(p) Pair{String, Int64} julia> p.first "foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ Pair, => eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing ...
```suggestion const _pairhash_seed = 0x94cb2bb20a28ce96 % UInt ```
julia> typeof(p) Pair{String, Int64} julia> p.first "foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ Pair, => eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing ...
@@ -41,7 +41,8 @@ eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing : (getfield(p, i), i + 1) indexed_iterate(p::Pair, i::Int, state=1) = (getfield(p, i), i + 1) -hash(p::Pair, h::UInt) = hash(p.second, hash(p.first, h)) +const _pairhash_seed = 0x246e48dbf41ba0c83c7429cc...
base/pair.jl
26
Julia
0.571
suggestion
68
51
51
false
prevent unnecessary `hash` collisions for `Pair`
57,285
JuliaLang/julia
35,573
Julia
nsajko
nsajko
Review this pull request change. Language: Julia File: base/pair.jl PR Title: prevent unnecessary `hash` collisions for `Pair` BEFORE CODE: julia> typeof(p) Pair{String, Int64} julia> p.first "foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element V...
```suggestion const _pairhash_seed = 0x94cb2bb20a28ce96 % UInt ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
julia> typeof(p) Pair{String, Int64} julia> p.first "foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ Pair, => eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing ...
```suggestion const _pairhash_seed = if UInt == UInt64 0x94cb2bb20a28ce96 else 0x1f60a087 end::UInt ```
julia> typeof(p) Pair{String, Int64} julia> p.first "foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ Pair, => eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing ...
@@ -41,7 +41,8 @@ eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing : (getfield(p, i), i + 1) indexed_iterate(p::Pair, i::Int, state=1) = (getfield(p, i), i + 1) -hash(p::Pair, h::UInt) = hash(p.second, hash(p.first, h)) +const _pairhash_seed = 0x94cb2bb20a28ce96 % UInt
base/pair.jl
26
Julia
0.714
suggestion
117
51
51
false
prevent unnecessary `hash` collisions for `Pair`
57,285
JuliaLang/julia
35,573
Julia
nsajko
nsajko
Review this pull request change. Language: Julia File: base/pair.jl PR Title: prevent unnecessary `hash` collisions for `Pair` BEFORE CODE: julia> typeof(p) Pair{String, Int64} julia> p.first "foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element V...
```suggestion const _pairhash_seed = if UInt == UInt64 0x94cb2bb20a28ce96 else 0x1f60a087 end::UInt ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
julia> typeof(p) Pair{String, Int64} julia> p.first "foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ Pair, => eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing ...
```suggestion const _pairhash_seed = if UInt === UInt64 ```
julia> typeof(p) Pair{String, Int64} julia> p.first "foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ Pair, => eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing ...
@@ -41,7 +41,12 @@ eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing : (getfield(p, i), i + 1) indexed_iterate(p::Pair, i::Int, state=1) = (getfield(p, i), i + 1) -hash(p::Pair, h::UInt) = hash(p.second, hash(p.first, h)) +const _pairhash_seed = if UInt == UInt64
base/pair.jl
26
Julia
0.571
suggestion
61
51
51
false
prevent unnecessary `hash` collisions for `Pair`
57,285
JuliaLang/julia
35,573
Julia
nsajko
nsajko
Review this pull request change. Language: Julia File: base/pair.jl PR Title: prevent unnecessary `hash` collisions for `Pair` BEFORE CODE: julia> typeof(p) Pair{String, Int64} julia> p.first "foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element V...
```suggestion const _pairhash_seed = if UInt === UInt64 ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
"foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ Pair, => eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing : (getfield(p, i), i + 1) indexed_iterate(p::Pair, i::...
FWIW, this also passes the new tests while being simpler/cheaper: ```suggestion hash(p::Pair, h::UInt) = hash(p.second, hash(p.first, ~h)) ``` I think it relies on `hash(p.first, ~h) != ~hash(p.first, h)`. Not sure whether it has any other disadvantages.
"foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ Pair, => eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing : (getfield(p, i), i + 1) indexed_iterate(p::Pair, i::...
@@ -41,7 +41,12 @@ eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing : (getfield(p, i), i + 1) indexed_iterate(p::Pair, i::Int, state=1) = (getfield(p, i), i + 1) -hash(p::Pair, h::UInt) = hash(p.second, hash(p.first, h)) +const _pairhash_seed = if UInt === UInt64 + 0...
base/pair.jl
26
Julia
0.786
suggestion
258
51
51
false
prevent unnecessary `hash` collisions for `Pair`
57,285
JuliaLang/julia
35,573
Julia
martinholters
nsajko
Review this pull request change. Language: Julia File: base/pair.jl PR Title: prevent unnecessary `hash` collisions for `Pair` BEFORE CODE: "foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ Pair, => eltyp...
FWIW, this also passes the new tests while being simpler/cheaper: ```suggestion hash(p::Pair, h::UInt) = hash(p.second, hash(p.first, ~h)) ``` I think it relies on `hash(p.first, ~h) != ~hash(p.first, h)`. Not sure whether it has any other disadvantages.
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
"foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ Pair, => eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing : (getfield(p, i), i + 1) indexed_iterate(p::Pair, i::...
```suggestion hash(p::Pair, h::UInt) = hash(p.second, hash(p.first, _pairhash_seed - 3h)) ```
"foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ Pair, => eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing : (getfield(p, i), i + 1) indexed_iterate(p::Pair, i::...
@@ -41,7 +41,12 @@ eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing : (getfield(p, i), i + 1) indexed_iterate(p::Pair, i::Int, state=1) = (getfield(p, i), i + 1) -hash(p::Pair, h::UInt) = hash(p.second, hash(p.first, h)) +const _pairhash_seed = if UInt === UInt64 + 0...
base/pair.jl
26
Julia
0.571
suggestion
95
51
51
false
prevent unnecessary `hash` collisions for `Pair`
57,285
JuliaLang/julia
35,573
Julia
nsajko
nsajko
Review this pull request change. Language: Julia File: base/pair.jl PR Title: prevent unnecessary `hash` collisions for `Pair` BEFORE CODE: "foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ Pair, => eltyp...
```suggestion hash(p::Pair, h::UInt) = hash(p.second, hash(p.first, _pairhash_seed - 3h)) ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
"foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ Pair, => eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing : (getfield(p, i), i + 1) indexed_iterate(p::Pair, i::...
```suggestion hash(p::Pair, h::UInt) = hash(p.second, hash(p.first, xor(_pairhash_seed, h))) ```
"foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ Pair, => eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing : (getfield(p, i), i + 1) indexed_iterate(p::Pair, i::...
@@ -41,7 +41,12 @@ eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing : (getfield(p, i), i + 1) indexed_iterate(p::Pair, i::Int, state=1) = (getfield(p, i), i + 1) -hash(p::Pair, h::UInt) = hash(p.second, hash(p.first, h)) +const _pairhash_seed = if UInt === UInt64 + 0...
base/pair.jl
26
Julia
0.571
suggestion
98
51
51
false
prevent unnecessary `hash` collisions for `Pair`
57,285
JuliaLang/julia
35,573
Julia
nsajko
nsajko
Review this pull request change. Language: Julia File: base/pair.jl PR Title: prevent unnecessary `hash` collisions for `Pair` BEFORE CODE: "foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ Pair, => eltyp...
```suggestion hash(p::Pair, h::UInt) = hash(p.second, hash(p.first, xor(_pairhash_seed, h))) ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
julia> p.first "foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ Pair, => eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing : (getfield(p, i), i + 1) indexed_itera...
```suggestion end ``` is this needed?
julia> p.first "foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ Pair, => eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing : (getfield(p, i), i + 1) indexed_itera...
@@ -41,7 +41,12 @@ eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing : (getfield(p, i), i + 1) indexed_iterate(p::Pair, i::Int, state=1) = (getfield(p, i), i + 1) -hash(p::Pair, h::UInt) = hash(p.second, hash(p.first, h)) +const _pairhash_seed = if UInt === UInt64 + 0...
base/pair.jl
26
Julia
0.429
question
42
51
51
false
prevent unnecessary `hash` collisions for `Pair`
57,285
JuliaLang/julia
35,573
Julia
adienes
nsajko
Review this pull request change. Language: Julia File: base/pair.jl PR Title: prevent unnecessary `hash` collisions for `Pair` BEFORE CODE: julia> p.first "foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ ...
```suggestion end ``` is this needed?
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
julia> typeof(p) Pair{String, Int64} julia> p.first "foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ Pair, => eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing ...
```suggestion const _pairhash_seed = 0x94cb2bb20a28ce96 % UInt ``` code golfing is fun
julia> typeof(p) Pair{String, Int64} julia> p.first "foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element Vector{String}: "oops" "oops" ``` """ Pair, => eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing ...
@@ -41,7 +41,12 @@ eltype(p::Type{Pair{A, B}}) where {A, B} = Union{A, B} iterate(p::Pair, i=1) = i > 2 ? nothing : (getfield(p, i), i + 1) indexed_iterate(p::Pair, i::Int, state=1) = (getfield(p, i), i + 1) -hash(p::Pair, h::UInt) = hash(p.second, hash(p.first, h)) +const _pairhash_seed = if UInt === UInt64
base/pair.jl
26
Julia
0.571
suggestion
91
51
51
false
prevent unnecessary `hash` collisions for `Pair`
57,285
JuliaLang/julia
35,573
Julia
adienes
nsajko
Review this pull request change. Language: Julia File: base/pair.jl PR Title: prevent unnecessary `hash` collisions for `Pair` BEFORE CODE: julia> typeof(p) Pair{String, Int64} julia> p.first "foo" julia> for x in p println(x) end foo 7 julia> replace.(["xops", "oxps"], "x" => "o") 2-element V...
```suggestion const _pairhash_seed = 0x94cb2bb20a28ce96 % UInt ``` code golfing is fun
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
// we must have implicitly imported this with using, so call jl_binding_dbgmodule to try to get the name of the module we got this from jl_errorf("invalid method definition in %s: exported function %s.%s does not exist", jl_module_debug_name(m), jl_module_debug_name(from), jl_symbol_...
If I'm a user who wrote `String(x) = 1` or whatever and got this warning, I don't think I'd make the connection that the problem was actually because I was extending a type constructor without qualification. Can that be made more explicit? Also, it could be worthwhile to encourage qualification for extension in the mes...
// we must have implicitly imported this with using, so call jl_binding_dbgmodule to try to get the name of the module we got this from jl_errorf("invalid method definition in %s: exported function %s.%s does not exist", jl_module_debug_name(m), jl_module_debug_name(from), jl_symbol_...
@@ -626,13 +626,25 @@ JL_DLLEXPORT jl_binding_t *jl_get_binding_for_method_def(jl_module_t *m, jl_sym_ // or we might want to drop this error entirely jl_module_t *from = jl_binding_dbgmodule(b, m, var); jl_errorf("invalid method definition in %s: function %s.%s must be expl...
src/module.c
26
C
0.786
suggestion
398
51
51
false
Add a warning for auto-import of types
57,311
JuliaLang/julia
35,573
Julia
ararslan
Keno
Review this pull request change. Language: C File: src/module.c PR Title: Add a warning for auto-import of types BEFORE CODE: // we must have implicitly imported this with using, so call jl_binding_dbgmodule to try to get the name of the module we got this from jl_errorf("invalid method definition i...
If I'm a user who wrote `String(x) = 1` or whatever and got this warning, I don't think I'd make the connection that the problem was actually because I was extending a type constructor without qualification. Can that be made more explicit? Also, it could be worthwhile to encourage qualification for extension in the mes...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
kwargs = (;$(log_data.kwargs...)) true else @invokelatest $(logging_error)(logger, level, _module, group, id, file, line, err, false) false end end end else logrecord = quote ...
Is there a reason this was quoted as `$(_min_enabled_level)`? It was ``` if var"#2#std_level" >= (Base.Threads.Atomic{Int32}(-1000))[] #= logging/logging.jl:400 =# ``` With this it's ``` if (var"#23#std_level").level >= Base.CoreLogging._min_enabled_level[] #= logging/...
msg = $(message) kwargs = (;$(log_data.kwargs...)) true else @invokelatest $(logging_error)(logger, level, _module, group, id, file, line, err, false) false end end end...
@@ -394,7 +395,7 @@ function logmsg_code(_module, file, line, level, message, exs...) level = $level # simplify std_level code emitted, if we know it is one of our global constants std_level = $(level isa Symbol ? :level : :(level isa $LogLevel ? level : convert($LogLevel, level):...
base/logging/logging.jl
26
Julia
0.929
suggestion
342
51
51
false
Logging: Improve threadsafety
57,591
JuliaLang/julia
35,573
Julia
IanButterworth
IanButterworth
Review this pull request change. Language: Julia File: base/logging/logging.jl PR Title: Logging: Improve threadsafety BEFORE CODE: kwargs = (;$(log_data.kwargs...)) true else @invokelatest $(logging_error)(logger, level, _module, group, id...
Is there a reason this was quoted as `$(_min_enabled_level)`? It was ``` if var"#2#std_level" >= (Base.Threads.Atomic{Int32}(-1000))[] #= logging/logging.jl:400 =# ``` With this it's ``` if (var"#23#std_level").level >= Base.CoreLogging._min_enabled_level[] #= logging/...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
shouldlog(logger::SimpleLogger, level, _module, group, id) = @lock logger.lock get(logger.message_limits, id, 1) > 0 min_enabled_level(logger::SimpleLogger) = logger.min_level catch_exceptions(logger::SimpleLogger) = false function handle_message(logger::SimpleLogger, level::LogLevel, message, _module, group, i...
This also seems not necessarily thread-safe (TOCTOU issues with the IO object)
min_level::LogLevel message_limits::Dict{Any,Int} end SimpleLogger(stream::IO, level=Info) = SimpleLogger(stream, ReentrantLock(), level, Dict{Any,Int}()) SimpleLogger(level=Info) = SimpleLogger(closed_stream, level) shouldlog(logger::SimpleLogger, level, _module, group, id) = @lock logger.lock get(logger....
@@ -684,9 +686,11 @@ function handle_message(logger::SimpleLogger, level::LogLevel, message, _module, @nospecialize maxlog = get(kwargs, :maxlog, nothing) if maxlog isa Core.BuiltinInts - remaining = get!(logger.message_limits, id, Int(maxlog)::Int) - logger.message_limits[id] = remaining -...
base/logging/logging.jl
26
Julia
0.357
suggestion
78
48
51
false
Logging: Improve threadsafety
57,591
JuliaLang/julia
35,573
Julia
vtjnash
IanButterworth
Review this pull request change. Language: Julia File: base/logging/logging.jl PR Title: Logging: Improve threadsafety BEFORE CODE: shouldlog(logger::SimpleLogger, level, _module, group, id) = @lock logger.lock get(logger.message_limits, id, 1) > 0 min_enabled_level(logger::SimpleLogger) = logger.min_level c...
This also seems not necessarily thread-safe (TOCTOU issues with the IO object)
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
false end end end else logrecord = quote try msg = $(esc(message)) kwargs = (;$(log_data.kwargs...)) true catch err @invokelatest $(logging_error)(logger, level, _m...
Need to check again that the logger level matches after loading this
@invokelatest $(logging_error)(logger, level, _module, group, id, file, line, err, false) false end end end else logrecord = quote try msg = $(esc(message)) kwargs = (;$(log_data.kwargs......
@@ -394,7 +395,7 @@ function logmsg_code(_module, file, line, level, message, exs...) level = $level # simplify std_level code emitted, if we know it is one of our global constants std_level = $(level isa Symbol ? :level : :(level isa $LogLevel ? level : convert($LogLevel, level):...
base/logging/logging.jl
26
Julia
0.214
suggestion
69
51
51
false
Logging: Improve threadsafety
57,591
JuliaLang/julia
35,573
Julia
vtjnash
IanButterworth
Review this pull request change. Language: Julia File: base/logging/logging.jl PR Title: Logging: Improve threadsafety BEFORE CODE: false end end end else logrecord = quote try msg = $(esc(message)) kwarg...
Need to check again that the logger level matches after loading this
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
data["failure_expanded"] = [Dict{String,Any}("expanded" => split(err, '\n'), "backtrace" => split(trace, '\n'))] else data["failure_expanded"] = [Dict{String,Any}("expanded" => split(result_show, '\n'), "backtrace" => [])] end end rid = get_rid(data) duplicate = hask...
```suggestion function collect_results!(results::Vector{Dict{String,Any}}, result::Test.DefaultTestSet, common_data::Dict{String,Any}, result_counts::ResultCountDict) collect_results!(results, result, common_data["scope"]) end function collect_results!(results::Vector{Dict{String,Any}}, result, common_data::Dict{S...
data["failure_expanded"] = [Dict{String,Any}("expanded" => split(err, '\n'), "backtrace" => split(trace, '\n'))] else data["failure_expanded"] = [Dict{String,Any}("expanded" => split(result_show, '\n'), "backtrace" => [])] end end rid = get_rid(data) duplicate = hask...
@@ -142,49 +197,85 @@ function result_dict(result::Test.Result) data["failure_expanded"] = [Dict{String,Any}("expanded" => split(result_show, '\n'), "backtrace" => [])] end end - return data + + rid = get_rid(data) + duplicate = haskey(result_counts, rid) + + if duplicate + ...
test/buildkitetestjson.jl
26
Julia
0.786
suggestion
387
51
51
false
CI: Store Passes in results.json + various improvements.
57,686
JuliaLang/julia
35,573
Julia
IanButterworth
IanButterworth
Review this pull request change. Language: Julia File: test/buildkitetestjson.jl PR Title: CI: Store Passes in results.json + various improvements. BEFORE CODE: data["failure_expanded"] = [Dict{String,Any}("expanded" => split(err, '\n'), "backtrace" => split(trace, '\n'))] else data[...
```suggestion function collect_results!(results::Vector{Dict{String,Any}}, result::Test.DefaultTestSet, common_data::Dict{String,Any}, result_counts::ResultCountDict) collect_results!(results, result, common_data["scope"]) end function collect_results!(results::Vector{Dict{String,Any}}, result, common_data::Dict{S...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
function LinRange(start, stop, len::Integer) T = typeof((zero(stop) - zero(start)) / oneunit(len)) LinRange{T}(start, stop, len) end range_start_stop_length(start, stop, len::Integer) = range_start_stop_length(promote(start, stop)..., len) range_start_stop_length(start::T, stop::T, len::Integer) where {T} ...
This is the 2-argument `show`, which should be parseable Julia code. See https://docs.julialang.org/en/v1/base/io-network/#Base.show-Tuple{IO,%20Any} .
function LinRange(start, stop, len::Integer) T = typeof((zero(stop) - zero(start)) / oneunit(len)) LinRange{T}(start, stop, len) end range_start_stop_length(start, stop, len::Integer) = range_start_stop_length(promote(start, stop)..., len) range_start_stop_length(start::T, stop::T, len::Integer) where {T} ...
@@ -618,6 +618,9 @@ function show(io::IO, r::LinRange{T}) where {T} print(io, ", ") show(io, length(r)) print(io, ')') + if isempty(r)
base/range.jl
26
Julia
0.571
suggestion
151
51
51
false
display "(empty range)" in case of empty ranges
57,697
JuliaLang/julia
35,573
Julia
Seelengrab
prashantrahul141
Review this pull request change. Language: Julia File: base/range.jl PR Title: display "(empty range)" in case of empty ranges BEFORE CODE: function LinRange(start, stop, len::Integer) T = typeof((zero(stop) - zero(start)) / oneunit(len)) LinRange{T}(start, stop, len) end range_start_stop_length(start, sto...
This is the 2-argument `show`, which should be parseable Julia code. See https://docs.julialang.org/en/v1/base/io-network/#Base.show-Tuple{IO,%20Any} .
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
# This file is a part of Julia. License is MIT: https://julialang.org/license using .Compiler: has_typevar function show(io::IO, ::MIME"text/plain", u::UndefInitializer) show(io, u) get(io, :compact, false)::Bool && return print(io, ": array initializer with undefined values") end # first a few multiline...
More efficient: ```suggestion show(io, first(r)) print(io, ':') show(io, last(r)) ``` Proof: ```julia-repl julia> f(io, a, b) = print(io, repr(a), ':', repr(b)) f (generic function with 1 method) julia> function g(io, a, b) show(io, a) print(io, ':') sho...
# This file is a part of Julia. License is MIT: https://julialang.org/license using .Compiler: has_typevar function show(io::IO, ::MIME"text/plain", u::UndefInitializer) show(io, u) get(io, :compact, false)::Bool && return print(io, ": array initializer with undefined values") end # first a few multiline...
@@ -12,6 +12,13 @@ end show(io::IO, ::MIME"text/plain", r::AbstractRange) = show(io, r) # always use the compact form for printing ranges +function show(io::IO, ::MIME"text/plain", r::UnitRange) + print(io, repr(first(r)), ':', repr(last(r)))
base/show.jl
16
Julia
0.929
performance
652
41
41
false
display "(empty range)" in case of empty ranges
57,697
JuliaLang/julia
35,573
Julia
nsajko
prashantrahul141
Review this pull request change. Language: Julia File: base/show.jl PR Title: display "(empty range)" in case of empty ranges BEFORE CODE: # This file is a part of Julia. License is MIT: https://julialang.org/license using .Compiler: has_typevar function show(io::IO, ::MIME"text/plain", u::UndefInitializer) s...
More efficient: ```suggestion show(io, first(r)) print(io, ':') show(io, last(r)) ``` Proof: ```julia-repl julia> f(io, a, b) = print(io, repr(a), ':', repr(b)) f (generic function with 1 method) julia> function g(io, a, b) show(io, a) print(io, ':') sho...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
# This file is a part of Julia. License is MIT: https://julialang.org/license using .Compiler: has_typevar function show(io::IO, ::MIME"text/plain", u::UndefInitializer) show(io, u) get(io, :compact, false)::Bool && return print(io, ": array initializer with undefined values") end # first a few multiline...
I'd type assert `Bool` here just to be safe, because `typeof(io)` is often not known concretely at compilation time (`stdout` is a global variable that's not concretely typed). Might make some code less vulnerable to invalidation. ```suggestion if !(get(io, :compact, false)::Bool) && isempty(r) ```
# This file is a part of Julia. License is MIT: https://julialang.org/license using .Compiler: has_typevar function show(io::IO, ::MIME"text/plain", u::UndefInitializer) show(io, u) get(io, :compact, false)::Bool && return print(io, ": array initializer with undefined values") end # first a few multiline...
@@ -12,6 +12,15 @@ end show(io::IO, ::MIME"text/plain", r::AbstractRange) = show(io, r) # always use the compact form for printing ranges +function show(io::IO, ::MIME"text/plain", r::UnitRange) + show(io, first(r)) + print(io, ':') + show(io, last(r)) + if !get(io, :compact, false) && isempty(r)
base/show.jl
19
Julia
1
security
308
44
44
false
display "(empty range)" in case of empty ranges
57,697
JuliaLang/julia
35,573
Julia
nsajko
prashantrahul141
Review this pull request change. Language: Julia File: base/show.jl PR Title: display "(empty range)" in case of empty ranges BEFORE CODE: # This file is a part of Julia. License is MIT: https://julialang.org/license using .Compiler: has_typevar function show(io::IO, ::MIME"text/plain", u::UndefInitializer) s...
I'd type assert `Bool` here just to be safe, because `typeof(io)` is often not known concretely at compilation time (`stdout` is a global variable that's not concretely typed). Might make some code less vulnerable to invalidation. ```suggestion if !(get(io, :compact, false)::Bool) && isempty(r) ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
# This file is a part of Julia. License is MIT: https://julialang.org/license using .Compiler: has_typevar function show(io::IO, ::MIME"text/plain", u::UndefInitializer) show(io, u) get(io, :compact, false)::Bool && return print(io, ": array initializer with undefined values") end # first a few multiline...
```suggestion show(io, r) ``` The implementation here should match the 2-arg implementation (so might as well call the 2-arg method). While @nsako's suggestion is reasonable, it shouldn't only be applied to the 3-arg and not the 2-arg method because that would cause inconsistencies like this: ```julia-rep...
# This file is a part of Julia. License is MIT: https://julialang.org/license using .Compiler: has_typevar function show(io::IO, ::MIME"text/plain", u::UndefInitializer) show(io, u) get(io, :compact, false)::Bool && return print(io, ": array initializer with undefined values") end # first a few multiline...
@@ -12,6 +12,15 @@ end show(io::IO, ::MIME"text/plain", r::AbstractRange) = show(io, r) # always use the compact form for printing ranges +function show(io::IO, ::MIME"text/plain", r::UnitRange) + show(io, first(r)) + print(io, ':') + show(io, last(r))
base/show.jl
18
Julia
1
performance
724
43
43
false
display "(empty range)" in case of empty ranges
57,697
JuliaLang/julia
35,573
Julia
LilithHafner
prashantrahul141
Review this pull request change. Language: Julia File: base/show.jl PR Title: display "(empty range)" in case of empty ranges BEFORE CODE: # This file is a part of Julia. License is MIT: https://julialang.org/license using .Compiler: has_typevar function show(io::IO, ::MIME"text/plain", u::UndefInitializer) s...
```suggestion show(io, r) ``` The implementation here should match the 2-arg implementation (so might as well call the 2-arg method). While @nsako's suggestion is reasonable, it shouldn't only be applied to the 3-arg and not the 2-arg method because that would cause inconsistencies like this: ```julia-rep...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
outboxed = (output_type != (jl_value_t*)jl_voidpointer_type); if (outboxed) { assert(jl_datatype_size(output_type) == sizeof(void*) * 4); Value *strct = emit_allocobj(ctx, (jl_datatype_t*)output_type, true); setName(ctx.emission_context, strct, "cfun_result"); ...
```suggestion const char *jl_generate_ccallable(Module *llvmmod, jl_value_t *nameval, jl_value_t *declrt, jl_value_t *sigt, jl_codegen_params_t &params) ``` Not technically required for this PR, but it looks like https://github.com/JuliaLang/julia/pull/56987/ missed that we always call this with a NULL `sysimg_han...
outboxed = (output_type != (jl_value_t*)jl_voidpointer_type); if (outboxed) { assert(jl_datatype_size(output_type) == sizeof(void*) * 4); Value *strct = emit_allocobj(ctx, (jl_datatype_t*)output_type, true); setName(ctx.emission_context, strct, "cfun_result"); ...
@@ -7709,14 +7709,14 @@ static jl_cgval_t emit_cfunction(jl_codectx_t &ctx, jl_value_t *output_type, con // do codegen to create a C-callable alias/wrapper, or if sysimg_handle is set, // restore one from a loaded system image. -const char *jl_generate_ccallable(Module *llvmmod, void *sysimg_handle, jl_value_t *dec...
src/codegen.cpp
26
C++
0.929
suggestion
328
51
51
false
add the ability to specify the external name of a ccallable
57,763
JuliaLang/julia
35,573
Julia
topolarity
JeffBezanson
Review this pull request change. Language: C++ File: src/codegen.cpp PR Title: add the ability to specify the external name of a ccallable BEFORE CODE: outboxed = (output_type != (jl_value_t*)jl_voidpointer_type); if (outboxed) { assert(jl_datatype_size(output_type) == sizeof(void*) * 4)...
```suggestion const char *jl_generate_ccallable(Module *llvmmod, jl_value_t *nameval, jl_value_t *declrt, jl_value_t *sigt, jl_codegen_params_t &params) ``` Not technically required for this PR, but it looks like https://github.com/JuliaLang/julia/pull/56987/ missed that we always call this with a NULL `sysimg_han...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
// This file is a part of Julia. License is MIT: https://julialang.org/license #include "llvm-gc-interface-passes.h" #define DEBUG_TYPE "mmtk_final_gc_lowering" STATISTIC(GCAllocBytesCount, "Number of lowered GCAllocBytesFunc intrinsics"); Value* FinalLowerGC::lowerGCAllocBytes(CallInst *target, Function &F) { +...
Will the passes be ever used together? I assume no. Then I would prefer to use one debug string across both final lower implementation so that I don't need to remember which GC implementation I have
// This file is a part of Julia. License is MIT: https://julialang.org/license #include "llvm-gc-interface-passes.h" #define DEBUG_TYPE "final_gc_lowering" STATISTIC(GCAllocBytesCount, "Number of lowered GCAllocBytesFunc intrinsics"); Value* FinalLowerGC::lowerGCAllocBytes(CallInst *target, Function &F) { ++GCAl...
@@ -2,19 +2,31 @@ #include "llvm-gc-interface-passes.h" -Value* LateLowerGCFrame::lowerGCAllocBytesLate(CallInst *target, Function &F) +#define DEBUG_TYPE "mmtk_final_gc_lowering"
src/llvm-final-gc-lowering-mmtk.cpp
5
C++
0.571
bug
198
30
30
false
Refactoring codegen passes that lower write barrier and allocation
57,769
JuliaLang/julia
35,573
Julia
vchuravy
udesou
Review this pull request change. Language: C++ File: src/llvm-final-gc-lowering-mmtk.cpp PR Title: Refactoring codegen passes that lower write barrier and allocation BEFORE CODE: // This file is a part of Julia. License is MIT: https://julialang.org/license #include "llvm-gc-interface-passes.h" #define DEBUG_TYPE...
Will the passes be ever used together? I assume no. Then I would prefer to use one debug string across both final lower implementation so that I don't need to remember which GC implementation I have
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
function repl_display_error(errio::IO, @nospecialize errval) # this will be set to true if types in the stacktrace are truncated limitflag = Ref(false) errio = IOContext(errio, :stacktrace_types_limited => limitflag) Base.invokelatest(Base.display_error, errio, errval) if limitflag[] print(e...
```suggestion val, iserr = if specialdisplay === nothing ```
function repl_display_error(errio::IO, @nospecialize errval) # this will be set to true if types in the stacktrace are truncated limitflag = Ref(false) errio = IOContext(errio, :stacktrace_types_limited => limitflag) Base.invokelatest(Base.display_error, errio, errval) if limitflag[] print(e...
@@ -557,9 +584,14 @@ function print_response(errio::IO, response, show_value::Bool, have_color::Bool, if val !== nothing && show_value try if specialdisplay === nothing
stdlib/REPL/src/REPL.jl
26
Julia
0.571
suggestion
86
51
51
false
REPL: call display on the backend
57,773
JuliaLang/julia
35,573
Julia
vtjnash
IanButterworth
Review this pull request change. Language: Julia File: stdlib/REPL/src/REPL.jl PR Title: REPL: call display on the backend BEFORE CODE: function repl_display_error(errio::IO, @nospecialize errval) # this will be set to true if types in the stacktrace are truncated limitflag = Ref(false) errio = IOContex...
```suggestion val, iserr = if specialdisplay === nothing ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
end function print_response(errio::IO, response, backend::Union{REPLBackendRef,Nothing}, show_value::Bool, have_color::Bool, specialdisplay::Union{AbstractDisplay,Nothing}=nothing) Base.sigatomic_begin() val, iserr = response while true try Base.sigatomic_end() if iserr ...
```suggestion iserr && throw(val) catch ``` (you can probably think of better ways to do this than try catch, but that was the easiest way to write the suggestion to avoid changing indents)
end function print_response(errio::IO, response, backend::Union{REPLBackendRef,Nothing}, show_value::Bool, have_color::Bool, specialdisplay::Union{AbstractDisplay,Nothing}=nothing) Base.sigatomic_begin() val, iserr = response while true try Base.sigatomic_end() if iserr ...
@@ -557,9 +584,14 @@ function print_response(errio::IO, response, show_value::Bool, have_color::Bool, if val !== nothing && show_value try if specialdisplay === nothing - Base.invokelatest(display, val) + ...
stdlib/REPL/src/REPL.jl
26
Julia
0.857
suggestion
233
51
51
false
REPL: call display on the backend
57,773
JuliaLang/julia
35,573
Julia
vtjnash
IanButterworth
Review this pull request change. Language: Julia File: stdlib/REPL/src/REPL.jl PR Title: REPL: call display on the backend BEFORE CODE: end function print_response(errio::IO, response, backend::Union{REPLBackendRef,Nothing}, show_value::Bool, have_color::Bool, specialdisplay::Union{AbstractDisplay,Nothing}=nothing...
```suggestion iserr && throw(val) catch ``` (you can probably think of better ways to do this than try catch, but that was the easiest way to write the suggestion to avoid changing indents)
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
dst.idxF = src.idxF dst.idxI = src.idxI dst.adv = src.adv dst.adv_jump = src.adv_jump dst.adv_vals = src.adv_vals dst.adv_ints = src.adv_ints dst end copy(src::MersenneTwister) = MersenneTwister(src.seed, copy(src.state), copy(src.vals), copy(src.ints), src.idxF, src...
I think this is over-prioritizing terse-ness and hinders readability Please spell out these function invocations by hand at the call-sites
dst.idxF = src.idxF dst.idxI = src.idxI dst.adv = src.adv dst.adv_jump = src.adv_jump dst.adv_vals = src.adv_vals dst.adv_ints = src.adv_ints dst end copy(src::MersenneTwister) = MersenneTwister(src.seed, copy(src.state), copy(src.vals), copy(src.ints), src.idxF, src...
@@ -141,27 +141,39 @@ hash(r::MersenneTwister, h::UInt) = foldr(hash, (r.seed, r.state, r.vals, r.ints, r.idxF, r.idxI); init=h) function show(io::IO, rng::MersenneTwister) + sep() = print(io, ", ") + sho(x) = show(io, x)
stdlib/Random/src/RNGs.jl
26
Julia
0.357
suggestion
141
51
51
false
`Random`: `show` method for `MersenneTwister`: invalidation resistance
57,913
JuliaLang/julia
35,573
Julia
topolarity
nsajko
Review this pull request change. Language: Julia File: stdlib/Random/src/RNGs.jl PR Title: `Random`: `show` method for `MersenneTwister`: invalidation resistance BEFORE CODE: dst.idxF = src.idxF dst.idxI = src.idxI dst.adv = src.adv dst.adv_jump = src.adv_jump dst.adv_vals = src.adv_vals dst...
I think this is over-prioritizing terse-ness and hinders readability Please spell out these function invocations by hand at the call-sites
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
isequal(r1.vals, r2.vals) && isequal(r1.ints, r2.ints) && r1.idxF == r2.idxF && r1.idxI == r2.idxI hash(r::MersenneTwister, h::UInt) = foldr(hash, (r.seed, r.state, r.vals, r.ints, r.idxF, r.idxI); init=h) function show(io::IO, rng::MersenneTwister) # seed if rng.adv_jump == 0 && rng.adv == 0 ...
Github won't let me highlight the whole `if`, but hopefully the idea is clear: ```suggestion # "(0, 0)" is nicer on the eyes than (-1, 1002) (a, b) = (rng.adv_vals != -1) ? (rng.adv_vals, rng.idxF) : (Int64(0), 0) print(io, a) print(io, sep) print(io, b)...
isequal(r1.vals, r2.vals) && isequal(r1.ints, r2.ints) && r1.idxF == r2.idxF && r1.idxI == r2.idxI hash(r::MersenneTwister, h::UInt) = foldr(hash, (r.seed, r.state, r.vals, r.ints, r.idxF, r.idxI); init=h) function show(io::IO, rng::MersenneTwister) # seed if rng.adv_jump == 0 && rng.adv == 0 ...
@@ -147,21 +147,32 @@ function show(io::IO, rng::MersenneTwister) end print(io, MersenneTwister, "(", repr(rng.seed), ", (") # state - adv = Integer[rng.adv_jump, rng.adv] + sep = ", " + show(io, rng.adv_jump) + print(io, sep) + show(io, rng.adv) if rng.adv_vals != -1 || rng.adv_ints ...
stdlib/Random/src/RNGs.jl
26
Julia
0.786
suggestion
325
51
51
false
`Random`: `show` method for `MersenneTwister`: invalidation resistance
57,913
JuliaLang/julia
35,573
Julia
topolarity
nsajko
Review this pull request change. Language: Julia File: stdlib/Random/src/RNGs.jl PR Title: `Random`: `show` method for `MersenneTwister`: invalidation resistance BEFORE CODE: isequal(r1.vals, r2.vals) && isequal(r1.ints, r2.ints) && r1.idxF == r2.idxF && r1.idxI == r2.idxI hash(r::MersenneTwister, h::U...
Github won't let me highlight the whole `if`, but hopefully the idea is clear: ```suggestion # "(0, 0)" is nicer on the eyes than (-1, 1002) (a, b) = (rng.adv_vals != -1) ? (rng.adv_vals, rng.idxF) : (Int64(0), 0) print(io, a) print(io, sep) print(io, b)...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
!!! compat "Julia 1.8" This function requires at least Julia 1.8. """ function set_active_project(projfile::Union{AbstractString,Nothing}) ACTIVE_PROJECT[] = projfile for f in active_project_callbacks try Base.invokelatest(f) catch @error "active project callback $f f...
```suggestion project_file === @something project_file active_project(search_load_path) ```
catch @error "active project callback $f failed" maxlog=1 end end end """ active_manifest() active_manifest(project_file::AbstractString) Return the path of the active manifest file, or the manifest file that would be used for a given `project_file`. In a stacked environment (...
@@ -379,6 +379,21 @@ function set_active_project(projfile::Union{AbstractString,Nothing}) end end +""" + active_manifest() + active_manifest(project_file::AbstractString) + +Return the path of the active manifest file, or the manifest file that would be used for a given `project_file`. +See [`Project envi...
base/initdefs.jl
26
Julia
0.571
suggestion
95
51
51
false
Add `Base.active_manifest()`
57,937
JuliaLang/julia
35,573
Julia
DilumAluthge
IanButterworth
Review this pull request change. Language: Julia File: base/initdefs.jl PR Title: Add `Base.active_manifest()` BEFORE CODE: !!! compat "Julia 1.8" This function requires at least Julia 1.8. """ function set_active_project(projfile::Union{AbstractString,Nothing}) ACTIVE_PROJECT[] = projfile for f in acti...
```suggestion project_file === @something project_file active_project(search_load_path) ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
cmd = `$(Base.julia_cmd()) --startup-file=no -e $(script)` cmd = addenv(cmd, "JULIA_PROJECT" => "foo") cmd = pipeline(cmd; stdout, stderr) @test success(cmd) end; end end # Base.active_project when version directory exist in depot, but contains no project file mktempdir() do dir ...
```suggestion @testset "Base.active_manifest()" begin ```
script = """ using Test old = Base.active_project() cd("foo") @test Base.active_project() == old """ cmd = `$(Base.julia_cmd()) --startup-file=no -e $(script)` cmd = addenv(cmd, "JULIA_PROJECT" => "foo") cmd = pipeline(cmd; stdout, stderr) ...
@@ -702,6 +702,16 @@ mktempdir() do dir @test success(cmd) end +@testset "Base.active_manifest()" begin
test/loading.jl
26
Julia
0.571
suggestion
57
51
51
false
Add `Base.active_manifest()`
57,937
JuliaLang/julia
35,573
Julia
DilumAluthge
IanButterworth
Review this pull request change. Language: Julia File: test/loading.jl PR Title: Add `Base.active_manifest()` BEFORE CODE: cmd = `$(Base.julia_cmd()) --startup-file=no -e $(script)` cmd = addenv(cmd, "JULIA_PROJECT" => "foo") cmd = pipeline(cmd; stdout, stderr) @test success(cmd) ...
```suggestion @testset "Base.active_manifest()" begin ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
!!! compat "Julia 1.8" This function requires at least Julia 1.8. """ function set_active_project(projfile::Union{AbstractString,Nothing}) ACTIVE_PROJECT[] = projfile for f in active_project_callbacks try Base.invokelatest(f) catch @error "active project callback $f ...
Should `search_load_path` be a kwarg instead of a positional arg?
!!! compat "Julia 1.8" This function requires at least Julia 1.8. """ function set_active_project(projfile::Union{AbstractString,Nothing}) ACTIVE_PROJECT[] = projfile for f in active_project_callbacks try Base.invokelatest(f) catch @error "active project callback $f ...
@@ -371,6 +371,21 @@ function set_active_project(projfile::Union{AbstractString,Nothing}) end end +""" + active_manifest() + active_manifest(project_file::AbstractString) + +Return the path of the active manifest file, or the manifest file that would be used for a given `project_file`. +See [`Project envi...
base/initdefs.jl
26
Julia
0.429
question
65
51
51
false
Add `Base.active_manifest()`
57,937
JuliaLang/julia
35,573
Julia
DilumAluthge
IanButterworth
Review this pull request change. Language: Julia File: base/initdefs.jl PR Title: Add `Base.active_manifest()` BEFORE CODE: !!! compat "Julia 1.8" This function requires at least Julia 1.8. """ function set_active_project(projfile::Union{AbstractString,Nothing}) ACTIVE_PROJECT[] = projfile for f in act...
Should `search_load_path` be a kwarg instead of a positional arg?
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
!!! compat "Julia 1.8" This function requires at least Julia 1.8. """ function set_active_project(projfile::Union{AbstractString,Nothing}) ACTIVE_PROJECT[] = projfile for f in active_project_callbacks try Base.invokelatest(f) catch @error "active project callback $f f...
```suggestion # If `project_file` was specified, use that, otherwise get the active project: project_file === !isnothing(project_file) ? project_file : active_project(search_load_path) ```
!!! compat "Julia 1.8" This function requires at least Julia 1.8. """ function set_active_project(projfile::Union{AbstractString,Nothing}) ACTIVE_PROJECT[] = projfile for f in active_project_callbacks try Base.invokelatest(f) catch @error "active project callback $f f...
@@ -371,6 +371,21 @@ function set_active_project(projfile::Union{AbstractString,Nothing}) end end +""" + active_manifest() + active_manifest(project_file::AbstractString) + +Return the path of the active manifest file, or the manifest file that would be used for a given `project_file`. +See [`Project envi...
base/initdefs.jl
26
Julia
0.786
suggestion
196
51
51
false
Add `Base.active_manifest()`
57,937
JuliaLang/julia
35,573
Julia
DilumAluthge
IanButterworth
Review this pull request change. Language: Julia File: base/initdefs.jl PR Title: Add `Base.active_manifest()` BEFORE CODE: !!! compat "Julia 1.8" This function requires at least Julia 1.8. """ function set_active_project(projfile::Union{AbstractString,Nothing}) ACTIVE_PROJECT[] = projfile for f in acti...
```suggestion # If `project_file` was specified, use that, otherwise get the active project: project_file === !isnothing(project_file) ? project_file : active_project(search_load_path) ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
This function requires at least Julia 1.8. """ function set_active_project(projfile::Union{AbstractString,Nothing}) ACTIVE_PROJECT[] = projfile for f in active_project_callbacks try Base.invokelatest(f) catch @error "active project callback $f failed" maxlog=1 ...
```suggestion project_file = !isnothing(project_file) ? project_file : active_project(search_load_path) ```
This function requires at least Julia 1.8. """ function set_active_project(projfile::Union{AbstractString,Nothing}) ACTIVE_PROJECT[] = projfile for f in active_project_callbacks try Base.invokelatest(f) catch @error "active project callback $f failed" maxlog=1 ...
@@ -371,6 +371,22 @@ function set_active_project(projfile::Union{AbstractString,Nothing}) end end +""" + active_manifest() + active_manifest(project_file::AbstractString) + +Return the path of the active manifest file, or the manifest file that would be used for a given `project_file`. +See [`Project envi...
base/initdefs.jl
26
Julia
0.714
suggestion
115
51
51
false
Add `Base.active_manifest()`
57,937
JuliaLang/julia
35,573
Julia
IanButterworth
IanButterworth
Review this pull request change. Language: Julia File: base/initdefs.jl PR Title: Add `Base.active_manifest()` BEFORE CODE: This function requires at least Julia 1.8. """ function set_active_project(projfile::Union{AbstractString,Nothing}) ACTIVE_PROJECT[] = projfile for f in active_project_callbacks ...
```suggestion project_file = !isnothing(project_file) ? project_file : active_project(search_load_path) ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
""" function set_active_project(projfile::Union{AbstractString,Nothing}) ACTIVE_PROJECT[] = projfile for f in active_project_callbacks try Base.invokelatest(f) catch @error "active project callback $f failed" maxlog=1 end end end """ active_manifest() ...
We should probably mention stacked environments. This function gives the impression there is only one manifest being respected.
""" function set_active_project(projfile::Union{AbstractString,Nothing}) ACTIVE_PROJECT[] = projfile for f in active_project_callbacks try Base.invokelatest(f) catch @error "active project callback $f failed" maxlog=1 end end end """ active_manifest() ...
@@ -371,6 +371,22 @@ function set_active_project(projfile::Union{AbstractString,Nothing}) end end +""" + active_manifest() + active_manifest(project_file::AbstractString) + +Return the path of the active manifest file, or the manifest file that would be used for a given `project_file`. +See [`Project envi...
base/initdefs.jl
26
Julia
0.429
suggestion
127
51
51
false
Add `Base.active_manifest()`
57,937
JuliaLang/julia
35,573
Julia
IanButterworth
IanButterworth
Review this pull request change. Language: Julia File: base/initdefs.jl PR Title: Add `Base.active_manifest()` BEFORE CODE: """ function set_active_project(projfile::Union{AbstractString,Nothing}) ACTIVE_PROJECT[] = projfile for f in active_project_callbacks try Base.invokelatest(f) ...
We should probably mention stacked environments. This function gives the impression there is only one manifest being respected.
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
module Ryu using .Base.Libc import .Base: significand_bits, significand_mask, exponent_bits, exponent_mask, exponent_bias, exponent_max, uinttype include("utils.jl") include("shortest.jl") include("fixed.jl") include("exp.jl") """ Ryu.neededdigits(T) Number of digits necessary to represent type `T` in fixed-pre...
"If an IEEE 754 double-precision number is converted to a decimal string with at least 17 significant digits, and then converted back to double-precision representation, the final result must match the original number" 17 + decimal point + sign bit + "e" + second sign bit + max exponent (3) = 24? https://en.wikip...
module Ryu using .Base.Libc import .Base: significand_bits, significand_mask, exponent_bits, exponent_mask, exponent_bias, exponent_max, uinttype include("utils.jl") include("shortest.jl") include("fixed.jl") include("exp.jl") """ Ryu.neededdigits(T) Number of digits necessary to represent type `T` in fixed-pre...
@@ -17,6 +17,15 @@ neededdigits(::Type{Float64}) = 309 + 17 neededdigits(::Type{Float32}) = 39 + 9 + 2 neededdigits(::Type{Float16}) = 9 + 5 + 9 +""" + Ryu.neededfloatdigits(T) + +Number of digits necessary to represent type `T` in shortest precision. +""" +neededfloatdigits(::Type{Float64}) = 23
base/ryu/Ryu.jl
25
Julia
0.429
style
372
50
50
false
reduce allocations for string(::IEEEFloat)
57,977
JuliaLang/julia
35,573
Julia
vtjnash
oscardssmith
Review this pull request change. Language: Julia File: base/ryu/Ryu.jl PR Title: reduce allocations for string(::IEEEFloat) BEFORE CODE: module Ryu using .Base.Libc import .Base: significand_bits, significand_mask, exponent_bits, exponent_mask, exponent_bias, exponent_max, uinttype include("utils.jl") include("sh...
"If an IEEE 754 double-precision number is converted to a decimal string with at least 17 significant digits, and then converted back to double-precision representation, the final result must match the original number" 17 + decimal point + sign bit + "e" + second sign bit + max exponent (3) = 24? https://en.wikip...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
module Ryu using .Base.Libc import .Base: significand_bits, significand_mask, exponent_bits, exponent_mask, exponent_bias, exponent_max, uinttype include("utils.jl") include("shortest.jl") include("fixed.jl") include("exp.jl") """ Ryu.neededdigits(T) Number of digits necessary to represent type `T` in fixed-pre...
9 + decimal point + sign bit + "f" + second sign bit + max exponent (2) = 15
module Ryu using .Base.Libc import .Base: significand_bits, significand_mask, exponent_bits, exponent_mask, exponent_bias, exponent_max, uinttype include("utils.jl") include("shortest.jl") include("fixed.jl") include("exp.jl") """ Ryu.neededdigits(T) Number of digits necessary to represent type `T` in fixed-pre...
@@ -17,6 +17,15 @@ neededdigits(::Type{Float64}) = 309 + 17 neededdigits(::Type{Float32}) = 39 + 9 + 2 neededdigits(::Type{Float16}) = 9 + 5 + 9 +""" + Ryu.neededfloatdigits(T) + +Number of digits necessary to represent type `T` in shortest precision. +""" +neededfloatdigits(::Type{Float64}) = 23 +neededfloatdig...
base/ryu/Ryu.jl
26
Julia
0.214
suggestion
78
51
51
false
reduce allocations for string(::IEEEFloat)
57,977
JuliaLang/julia
35,573
Julia
vtjnash
oscardssmith
Review this pull request change. Language: Julia File: base/ryu/Ryu.jl PR Title: reduce allocations for string(::IEEEFloat) BEFORE CODE: module Ryu using .Base.Libc import .Base: significand_bits, significand_mask, exponent_bits, exponent_mask, exponent_bias, exponent_max, uinttype include("utils.jl") include("sh...
9 + decimal point + sign bit + "f" + second sign bit + max exponent (2) = 15
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
using .Base.Libc import .Base: significand_bits, significand_mask, exponent_bits, exponent_mask, exponent_bias, exponent_max, uinttype include("utils.jl") include("shortest.jl") include("fixed.jl") include("exp.jl") """ Ryu.neededdigits(T) Number of digits necessary to represent type `T` in fixed-precision deci...
5 + decimal point + sign bit + "e" + second sign bit + max exponent (2) = 11 ``` julia> extrema(i->length(string(reinterpret(Float16, i))), typemin(UInt16):typemax(UInt16)) (3, 11) ``` (so maximum = 20 with typed=true)
using .Base.Libc import .Base: significand_bits, significand_mask, exponent_bits, exponent_mask, exponent_bias, exponent_max, uinttype include("utils.jl") include("shortest.jl") include("fixed.jl") include("exp.jl") """ Ryu.neededdigits(T) Number of digits necessary to represent type `T` in fixed-precision deci...
@@ -17,6 +17,15 @@ neededdigits(::Type{Float64}) = 309 + 17 neededdigits(::Type{Float32}) = 39 + 9 + 2 neededdigits(::Type{Float16}) = 9 + 5 + 9 +""" + Ryu.neededfloatdigits(T) + +Number of digits necessary to represent type `T` in shortest precision. +""" +neededfloatdigits(::Type{Float64}) = 23 +neededfloatdig...
base/ryu/Ryu.jl
26
Julia
0.929
suggestion
225
51
51
false
reduce allocations for string(::IEEEFloat)
57,977
JuliaLang/julia
35,573
Julia
vtjnash
oscardssmith
Review this pull request change. Language: Julia File: base/ryu/Ryu.jl PR Title: reduce allocations for string(::IEEEFloat) BEFORE CODE: using .Base.Libc import .Base: significand_bits, significand_mask, exponent_bits, exponent_mask, exponent_bias, exponent_max, uinttype include("utils.jl") include("shortest.jl")...
5 + decimal point + sign bit + "e" + second sign bit + max exponent (2) = 11 ``` julia> extrema(i->length(string(reinterpret(Float16, i))), typemin(UInt16):typemax(UInt16)) (3, 11) ``` (so maximum = 20 with typed=true)
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
@test parse(Float16, Ryu.writeshortest(x)) == x x = nextfloat(x) end end # function testfloats(T) # x = floatmin(T) # i = 0 # fails = 0 # success = 0 # while x < floatmax(T) # test = parse(T, Ryu.writeshortest(x)) == x # if !test # fails += 1 # ...
I don't know if a test set called "regression" with a single test in it is that useful.
end @testset "LooksLikePow5" begin # These numbers have a mantissa that is the largest power of 5 that fits, # and an exponent that causes the computation for q to result in 10, which is a corner # case for Ryu. @test "6.7108864e17" == Ryu.writeshortest(Core.bitcast(Float32, 0x5D1502F9)) @test "1.3...
@@ -368,6 +372,9 @@ end # return fails / (fails + success) # end +@testset "Regression" begin
test/ryu.jl
26
Julia
0.286
suggestion
88
51
51
false
reduce allocations for string(::IEEEFloat)
57,977
JuliaLang/julia
35,573
Julia
KristofferC
oscardssmith
Review this pull request change. Language: Julia File: test/ryu.jl PR Title: reduce allocations for string(::IEEEFloat) BEFORE CODE: @test parse(Float16, Ryu.writeshortest(x)) == x x = nextfloat(x) end end # function testfloats(T) # x = floatmin(T) # i = 0 # fails = 0 # success ...
I don't know if a test set called "regression" with a single test in it is that useful.
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
end end # function testfloats(T) # x = floatmin(T) # i = 0 # fails = 0 # success = 0 # while x < floatmax(T) # test = parse(T, Ryu.writeshortest(x)) == x # if !test # fails += 1 # else # success += 1 # end # x = nextfloat(x) # ...
```suggestion @test "-0.00010014" == Ryu.writeshortest(Float16(-0.00010014)) #longest Float16 ```
end end # function testfloats(T) # x = floatmin(T) # i = 0 # fails = 0 # success = 0 # while x < floatmax(T) # test = parse(T, Ryu.writeshortest(x)) == x # if !test # fails += 1 # else # success += 1 # end # x = nextfloat(x) # ...
@@ -418,6 +422,9 @@ end # return fails / (fails + success) # end +@testset "Regression" begin + @test "-0.00010014" == Ryu.writeshortest(Float16(-0.00010014)) #longest Float16 +end
test/ryu.jl
26
Julia
0.571
suggestion
99
51
51
false
reduce allocations for string(::IEEEFloat)
57,977
JuliaLang/julia
35,573
Julia
oscardssmith
oscardssmith
Review this pull request change. Language: Julia File: test/ryu.jl PR Title: reduce allocations for string(::IEEEFloat) BEFORE CODE: end end # function testfloats(T) # x = floatmin(T) # i = 0 # fails = 0 # success = 0 # while x < floatmax(T) # test = parse(T, Ryu.writeshortest(x)) =...
```suggestion @test "-0.00010014" == Ryu.writeshortest(Float16(-0.00010014)) #longest Float16 ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
# Check that `last_punct` is either the last '(' or placed after a previous '(' frange, method_name_end = find_start_brace(@view partial[1:idx_last_punct]) method_name_end ∈ frange || return fail # Strip the preceding ! operators, if any, and close the expression with a ')' s = replace(partial[fran...
Why 500? If it's been tuned perhaps add a comment? Also why not just increase MAX_METHOD_COMPLETIONS? Perhaps it should be another global const? `MAX_METHOD_COMPLETIONS_WHEN_{some common UX context}`
# Complete ordinary strings: # "~/exa TAB => "~/example.txt" # "~/example.txt TAB => "/home/user/example.txt" r, closed = find_str(cur) if r !== nothing s = do_string_unescape(string[r]) ret, success = complete_path_string(s, hint; string_escape=true, ...
@@ -1082,7 +1082,7 @@ function complete_keyword_argument(partial::String, last_idx::Int, context_modul kwargs_flag == 2 && return fail # one of the previous kwargs is invalid methods = Completion[] - complete_methods!(methods, funct, Any[Vararg{Any}], kwargs_ex, shift ? -1 : MAX_METHOD_COMPLETIONS, kwarg...
stdlib/REPL/src/REPLCompletions.jl
26
Julia
0.643
question
206
51
51
false
Re-enable tab completion of kwargs for large method tables
58,012
JuliaLang/julia
35,573
Julia
IanButterworth
mbauman
Review this pull request change. Language: Julia File: stdlib/REPL/src/REPLCompletions.jl PR Title: Re-enable tab completion of kwargs for large method tables BEFORE CODE: # Check that `last_punct` is either the last '(' or placed after a previous '(' frange, method_name_end = find_start_brace(@view partial...
Why 500? If it's been tuned perhaps add a comment? Also why not just increase MAX_METHOD_COMPLETIONS? Perhaps it should be another global const? `MAX_METHOD_COMPLETIONS_WHEN_{some common UX context}`
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
# Strip the preceding ! operators, if any, and close the expression with a ')' s = replace(partial[frange], r"\G\!+([^=\(]+)" => s"\1"; count=1) * ')' ex = Meta.parse(s, raise=false, depwarn=false) isa(ex, Expr) || return fail # `wordrange` is the position of the last argument to complete word...
```suggestion # of methods to _display_ before showing an alternative message; here we're ```
r, closed = find_str(cur) if r !== nothing s = do_string_unescape(string[r]) ret, success = complete_path_string(s, hint; string_escape=true, dirsep=Sys.iswindows() ? '\\' : '/') if length(ret) == 1 && !closed && close_path_completion(ret[1].pa...
@@ -1082,7 +1082,12 @@ function complete_keyword_argument(partial::String, last_idx::Int, context_modul kwargs_flag == 2 && return fail # one of the previous kwargs is invalid methods = Completion[] - complete_methods!(methods, funct, Any[Vararg{Any}], kwargs_ex, shift ? -1 : MAX_METHOD_COMPLETIONS, kwar...
stdlib/REPL/src/REPLCompletions.jl
26
Julia
0.571
suggestion
99
51
51
false
Re-enable tab completion of kwargs for large method tables
58,012
JuliaLang/julia
35,573
Julia
mbauman
mbauman
Review this pull request change. Language: Julia File: stdlib/REPL/src/REPLCompletions.jl PR Title: Re-enable tab completion of kwargs for large method tables BEFORE CODE: # Strip the preceding ! operators, if any, and close the expression with a ')' s = replace(partial[frange], r"\G\!+([^=\(]+)" => s"\1";...
```suggestion # of methods to _display_ before showing an alternative message; here we're ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
matches = String[] for key in keys(identifier) rkey = repr(key) startswith(rkey,partial_key) && push!(matches,rkey) end return matches end # Provide completion for keyword arguments in function calls # Returns true if the current argument must be a keyword because the cursor is beyond t...
```suggestion isabstract(funct) && return false ```
matches = String[] for key in keys(identifier) rkey = repr(key) startswith(rkey,partial_key) && push!(matches,rkey) end return matches end # Provide completion for keyword arguments in function calls # Returns true if the current argument must be a keyword because the cursor is beyond t...
@@ -910,7 +910,15 @@ function complete_keyword_argument!(suggestions::Vector{Completion}, kwargs_flag == 2 && return false # one of the previous kwargs is invalid methods = Completion[] - complete_methods!(methods, funct, Any[Vararg{Any}], kwargs_ex, shift ? -1 : MAX_METHOD_COMPLETIONS, arg_pos == :kwarg...
stdlib/REPL/src/REPLCompletions.jl
26
Julia
0.571
refactor
57
51
51
false
Re-enable tab completion of kwargs for large method tables
58,012
JuliaLang/julia
35,573
Julia
mbauman
mbauman
Review this pull request change. Language: Julia File: stdlib/REPL/src/REPLCompletions.jl PR Title: Re-enable tab completion of kwargs for large method tables BEFORE CODE: matches = String[] for key in keys(identifier) rkey = repr(key) startswith(rkey,partial_key) && push!(matches,rkey) ...
```suggestion isabstract(funct) && return false ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
matches = String[] for key in keys(identifier) rkey = repr(key) startswith(rkey,partial_key) && push!(matches,rkey) end return matches end # Provide completion for keyword arguments in function calls # Returns true if the current argument must be a keyword because the cursor is beyond t...
Is there any reason not to use `isconcretetype`? Or it might be possible to use `Base.Compiler.singletonType(funct)!==Nothing` as well.
matches = String[] for key in keys(identifier) rkey = repr(key) startswith(rkey,partial_key) && push!(matches,rkey) end return matches end # Provide completion for keyword arguments in function calls # Returns true if the current argument must be a keyword because the cursor is beyond t...
@@ -910,7 +910,15 @@ function complete_keyword_argument!(suggestions::Vector{Completion}, kwargs_flag == 2 && return false # one of the previous kwargs is invalid methods = Completion[] - complete_methods!(methods, funct, Any[Vararg{Any}], kwargs_ex, shift ? -1 : MAX_METHOD_COMPLETIONS, arg_pos == :kwarg...
stdlib/REPL/src/REPLCompletions.jl
26
Julia
0.714
suggestion
136
51
51
false
Re-enable tab completion of kwargs for large method tables
58,012
JuliaLang/julia
35,573
Julia
aviatesk
mbauman
Review this pull request change. Language: Julia File: stdlib/REPL/src/REPLCompletions.jl PR Title: Re-enable tab completion of kwargs for large method tables BEFORE CODE: matches = String[] for key in keys(identifier) rkey = repr(key) startswith(rkey,partial_key) && push!(matches,rkey) ...
Is there any reason not to use `isconcretetype`? Or it might be possible to use `Base.Compiler.singletonType(funct)!==Nothing` as well.
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
matches = String[] for key in keys(identifier) rkey = repr(key) startswith(rkey,partial_key) && push!(matches,rkey) end return matches end # Provide completion for keyword arguments in function calls # Returns true if the current argument must be a keyword because the cursor is beyond t...
Let's try it! ```suggestion isconcretype(funct) || return false ```
matches = String[] for key in keys(identifier) rkey = repr(key) startswith(rkey,partial_key) && push!(matches,rkey) end return matches end # Provide completion for keyword arguments in function calls # Returns true if the current argument must be a keyword because the cursor is beyond t...
@@ -910,7 +910,15 @@ function complete_keyword_argument!(suggestions::Vector{Completion}, kwargs_flag == 2 && return false # one of the previous kwargs is invalid methods = Completion[] - complete_methods!(methods, funct, Any[Vararg{Any}], kwargs_ex, shift ? -1 : MAX_METHOD_COMPLETIONS, arg_pos == :kwarg...
stdlib/REPL/src/REPLCompletions.jl
26
Julia
0.714
suggestion
76
51
51
false
Re-enable tab completion of kwargs for large method tables
58,012
JuliaLang/julia
35,573
Julia
mbauman
mbauman
Review this pull request change. Language: Julia File: stdlib/REPL/src/REPLCompletions.jl PR Title: Re-enable tab completion of kwargs for large method tables BEFORE CODE: matches = String[] for key in keys(identifier) rkey = repr(key) startswith(rkey,partial_key) && push!(matches,rkey) ...
Let's try it! ```suggestion isconcretype(funct) || return false ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
# This needs to be a separate non-inlined function, see #19441 @noinline function find_dict_matches(identifier::AbstractDict, partial_key) matches = String[] for key in keys(identifier) rkey = repr(key) startswith(rkey,partial_key) && push!(matches,rkey) end return matches end # Provide...
```suggestion isconcretetype(funct) || return false ```
# This needs to be a separate non-inlined function, see #19441 @noinline function find_dict_matches(identifier::AbstractDict, partial_key) matches = String[] for key in keys(identifier) rkey = repr(key) startswith(rkey,partial_key) && push!(matches,rkey) end return matches end # Provide...
@@ -910,7 +910,13 @@ function complete_keyword_argument!(suggestions::Vector{Completion}, kwargs_flag == 2 && return false # one of the previous kwargs is invalid methods = Completion[] - complete_methods!(methods, funct, Any[Vararg{Any}], kwargs_ex, shift ? -1 : MAX_METHOD_COMPLETIONS, arg_pos == :kwarg...
stdlib/REPL/src/REPLCompletions.jl
26
Julia
0.714
suggestion
61
51
51
false
Re-enable tab completion of kwargs for large method tables
58,012
JuliaLang/julia
35,573
Julia
mbauman
mbauman
Review this pull request change. Language: Julia File: stdlib/REPL/src/REPLCompletions.jl PR Title: Re-enable tab completion of kwargs for large method tables BEFORE CODE: # This needs to be a separate non-inlined function, see #19441 @noinline function find_dict_matches(identifier::AbstractDict, partial_key) m...
```suggestion isconcretetype(funct) || return false ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
function typeinf_ext_toplevel(interp::AbstractInterpreter, mi::MethodInstance, source_mode::UInt8) ci = typeinf_ext(interp, mi, source_mode) ci = add_codeinsts_to_jit!(interp, ci, source_mode) if collect_dispatch_backtrace[] dispatch_backtrace[ci] = backtrace() end return ci end # This is a...
This method is not actually relevant to dispatch, so these additional changes (just the first one) should not be included in this PR
matches === nothing && return nothing length(matches.matches) == 0 && return nothing match = only(matches.matches) compileable_atype = get_compileable_sig(match.method, match.spec_types, match.sparams) compileable_atype === nothing && return nothing if match.spec_types !== compileable_atype ...
@@ -1432,6 +1438,7 @@ function typeinf_ext_toplevel(methods::Vector{Any}, worlds::Vector{UInt}, trim_m inspected = IdSet{CodeInstance}() tocompile = Vector{CodeInstance}() codeinfos = [] + bt = collect_dispatch_backtrace[] ? backtrace() : nothing
Compiler/src/typeinfer.jl
26
Julia
0.429
suggestion
132
51
51
false
Log a backtrace on entrance to type inference
58,124
JuliaLang/julia
35,573
Julia
vtjnash
timholy
Review this pull request change. Language: Julia File: Compiler/src/typeinfer.jl PR Title: Log a backtrace on entrance to type inference BEFORE CODE: function typeinf_ext_toplevel(interp::AbstractInterpreter, mi::MethodInstance, source_mode::UInt8) ci = typeinf_ext(interp, mi, source_mode) ci = add_codeinst...
This method is not actually relevant to dispatch, so these additional changes (just the first one) should not be included in this PR
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
elseif linfo isa Method return linfo.module elseif linfo isa Module return linfo else # The module is not always available (common reasons include # frames arising from the interpreter) nothing end end """ from(frame::StackFrame, filter_mod::Module)::Bool Re...
ReentrantLock may be somewhat segfault-y when used in inference itself (since it does not expect to block, it violates the lock hierarchy also). This needs to be in C, since it cannot be running code that can be inferred
# This file is a part of Julia. License is MIT: https://julialang.org/license """ Tools for collecting and manipulating stack traces. Mainly used for building errors. """ module StackTraces import Base: hash, ==, show using Core: CodeInfo, MethodInstance, CodeInstance using Base.IRShow export StackTrace, StackFram...
@@ -375,4 +375,15 @@ function from(frame::StackFrame, m::Module) return parentmodule(frame) === m end +end # module StackTraces + +# Back to Base +# Implement locking for Compiler.store_dispatch_backtrace +const dispatch_backtrace = IdDict{Core.CodeInstance,Any}() +const dispatch_backtrace_lock = ReentrantLock...
base/stacktraces.jl
26
Julia
0.5
bug
220
33
379
false
Log a backtrace on entrance to type inference
58,124
JuliaLang/julia
35,573
Julia
vtjnash
timholy
Review this pull request change. Language: Julia File: base/stacktraces.jl PR Title: Log a backtrace on entrance to type inference BEFORE CODE: elseif linfo isa Method return linfo.module elseif linfo isa Module return linfo else # The module is not always available (common reaso...
ReentrantLock may be somewhat segfault-y when used in inference itself (since it does not expect to block, it violates the lock hierarchy also). This needs to be in C, since it cannot be running code that can be inferred
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
JL_DLLEXPORT jl_module_t *jl_base_relative_to(jl_module_t *m) { for (;;) { if (m->istopmod) return m; if (m == m->parent) break; m = m->parent; } return jl_top_module; } static void expr_attributes(jl_value_t *v, jl_array_t *body, int *has_ccall, int *has_def...
I think `jl_latestworld_sym` is now the equivalent to put here?
{ for (;;) { if (m->istopmod) return m; if (m == m->parent) break; m = m->parent; } return jl_top_module; } static void expr_attributes(jl_value_t *v, jl_array_t *body, int *has_ccall, int *has_defs, int *has_opaque) { if (!jl_is_expr(v)) return; ...
@@ -386,7 +386,7 @@ static void expr_attributes(jl_value_t *v, jl_array_t *body, int *has_ccall, int // might still need to be optimized. return; } - else if (head == jl_const_sym || head == jl_copyast_sym) { + else if (head == jl_copyast_sym) {
src/toplevel.c
26
C
0.357
question
63
51
51
false
Lower `const x = ...` to new builtin `Core.setconst!`
58,187
JuliaLang/julia
35,573
Julia
vtjnash
xal-0
Review this pull request change. Language: C File: src/toplevel.c PR Title: Lower `const x = ...` to new builtin `Core.setconst!` BEFORE CODE: JL_DLLEXPORT jl_module_t *jl_base_relative_to(jl_module_t *m) { for (;;) { if (m->istopmod) return m; if (m == m->parent) break; ...
I think `jl_latestworld_sym` is now the equivalent to put here?
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
Atomically perform the operations to get and conditionally set a global to a given value. !!! compat "Julia 1.11" This function requires Julia 1.11 or later. See also [`replaceproperty!`](@ref Base.replaceproperty!) and [`setglobal!`](@ref). """ replaceglobal! """ setglobalonce!(module::Module, name::Symbol,...
bikeshed: I think `declare_const` might make more sense than calling it "set!"? Later we can add `declare_method` similarly. They also do not modify anything (they create a new world for possible execution, but do not change anything), so they likely should not have a `!` (similar to `Base.delete_method`)
""" replaceglobal!(module::Module, name::Symbol, expected, desired, [success_order::Symbol, [fail_order::Symbol=success_order]) -> (; old, success::Bool) Atomically perform the operations to get and conditionally set a global to a given value. !!! compat "Julia 1.11" This function requires ...
@@ -2753,6 +2753,38 @@ See also [`setpropertyonce!`](@ref Base.setpropertyonce!) and [`setglobal!`](@re """ setglobalonce! +""" + setconst!(module::Module, name::Symbol, [x])
base/docs/basedocs.jl
26
Julia
0.643
suggestion
306
51
51
false
Lower `const x = ...` to new builtin `Core.setconst!`
58,187
JuliaLang/julia
35,573
Julia
vtjnash
xal-0
Review this pull request change. Language: Julia File: base/docs/basedocs.jl PR Title: Lower `const x = ...` to new builtin `Core.setconst!` BEFORE CODE: Atomically perform the operations to get and conditionally set a global to a given value. !!! compat "Julia 1.11" This function requires Julia 1.11 or later....
bikeshed: I think `declare_const` might make more sense than calling it "set!"? Later we can add `declare_method` similarly. They also do not modify anything (they create a new world for possible execution, but do not change anything), so they likely should not have a `!` (similar to `Base.delete_method`)
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
replaceglobal! """ setglobalonce!(module::Module, name::Symbol, value, [success_order::Symbol, [fail_order::Symbol=success_order]) -> success::Bool Atomically perform the operations to set a global to a given value, only if it was previously not set. !!! compat "Julia 1.11" This function re...
```suggestion Unlike the syntax `const`, calling this function does not insert `Core.@latestworld` to update the world age of the current frame: ```
!!! compat "Julia 1.11" This function requires Julia 1.11 or later. See also [`replaceproperty!`](@ref Base.replaceproperty!) and [`setglobal!`](@ref). """ replaceglobal! """ setglobalonce!(module::Module, name::Symbol, value, [success_order::Symbol, [fail_order::Symbol=success_order]) -> su...
@@ -2753,6 +2753,38 @@ See also [`setpropertyonce!`](@ref Base.setpropertyonce!) and [`setglobal!`](@re """ setglobalonce! +""" + setconst!(module::Module, name::Symbol, [x]) + +Create or replace the constant `name` in `module` with the new value `x`. When +replacing, `x` does not need to have the same type as ...
base/docs/basedocs.jl
26
Julia
0.714
suggestion
152
51
51
false
Lower `const x = ...` to new builtin `Core.setconst!`
58,187
JuliaLang/julia
35,573
Julia
vtjnash
xal-0
Review this pull request change. Language: Julia File: base/docs/basedocs.jl PR Title: Lower `const x = ...` to new builtin `Core.setconst!` BEFORE CODE: replaceglobal! """ setglobalonce!(module::Module, name::Symbol, value, [success_order::Symbol, [fail_order::Symbol=success_order]) -> succe...
```suggestion Unlike the syntax `const`, calling this function does not insert `Core.@latestworld` to update the world age of the current frame: ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
Create or replace the constant `name` in `module` with the new value `x`. When replacing, `x` does not need to have the same type as the original constant. When `x` is not given, `name` becomes an undefined constant; it cannot be read or written to, but can be redefined. Note that this function does not update the w...
```suggestion Core.@latestworld println(x) end 1 2 2 3 ```
setglobalonce! """ declare_const(module::Module, name::Symbol, [x]) Create or replace the constant `name` in `module` with the new value `x`. When replacing, `x` does not need to have the same type as the original constant. When `x` is not given, `name` becomes an undefined constant; it cannot be read or writte...
@@ -2753,6 +2753,38 @@ See also [`setpropertyonce!`](@ref Base.setpropertyonce!) and [`setglobal!`](@re """ setglobalonce! +""" + setconst!(module::Module, name::Symbol, [x]) + +Create or replace the constant `name` in `module` with the new value `x`. When +replacing, `x` does not need to have the same type as ...
base/docs/basedocs.jl
26
Julia
0.571
suggestion
95
51
51
false
Lower `const x = ...` to new builtin `Core.setconst!`
58,187
JuliaLang/julia
35,573
Julia
vtjnash
xal-0
Review this pull request change. Language: Julia File: base/docs/basedocs.jl PR Title: Lower `const x = ...` to new builtin `Core.setconst!` BEFORE CODE: Create or replace the constant `name` in `module` with the new value `x`. When replacing, `x` does not need to have the same type as the original constant. When...
```suggestion Core.@latestworld println(x) end 1 2 2 3 ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
@test accumulate(op, arr, dims=10) ≈ arr if eltype(arr) in [Int, Float64] # eltype of out easy out = similar(arr) @test accumulate!(op, out, arr) ≈ accumulate_arr @test out ≈ accumulate_arr end end arr_cop = similar(arr...
This will always pass because tests are run with bounds checked :) You can put this in boundscheck_exec to explicitly test it when checkbounds isn't entirely disabled. You could also just test with `getindex` directly: ```julia julia> accumulate(getindex, [1:10,2:10,2:10,2:10]) 4-element Vector{UnitRange{Int...
@test accumulate(op, arr, dims=10) ≈ arr if eltype(arr) in [Int, Float64] # eltype of out easy out = similar(arr) @test accumulate!(op, out, arr) ≈ accumulate_arr @test out ≈ accumulate_arr end end arr_cop = similar(arr...
@@ -2908,6 +2908,11 @@ end @inferred accumulate(+, randn(3)) @inferred accumulate(+, randn(3); init=1) + # inbounds propagation + Base.@propagate_inbounds op_bounds(a, b) = (1, 2)[a] + (1, 2)[b] + @test_throws BoundsError accumulate(op_bounds, 1:10) + @test_throws BoundsError Base.accumulate_pai...
test/arrayops.jl
26
Julia
1
suggestion
506
51
51
false
Narrow `@inbounds` annotations in `accumulate.jl` to only indexing calls
58,200
JuliaLang/julia
35,573
Julia
mbauman
adienes
Review this pull request change. Language: Julia File: test/arrayops.jl PR Title: Narrow `@inbounds` annotations in `accumulate.jl` to only indexing calls BEFORE CODE: @test accumulate(op, arr, dims=10) ≈ arr if eltype(arr) in [Int, Float64] # eltype of out easy out = simila...
This will always pass because tests are run with bounds checked :) You can put this in boundscheck_exec to explicitly test it when checkbounds isn't entirely disabled. You could also just test with `getindex` directly: ```julia julia> accumulate(getindex, [1:10,2:10,2:10,2:10]) 4-element Vector{UnitRange{Int...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
""" replaceglobal! """ setglobalonce!(module::Module, name::Symbol, value, [success_order::Symbol, [fail_order::Symbol=success_order]) -> success::Bool Atomically perform the operations to set a global to a given value, only if it was previously not set. !!! compat "Julia 1.11" This functio...
Since this is impossible for any function to do, it seems odd to call out that this function doesn't do it ```suggestion ```
""" replaceglobal! """ setglobalonce!(module::Module, name::Symbol, value, [success_order::Symbol, [fail_order::Symbol=success_order]) -> success::Bool Atomically perform the operations to set a global to a given value, only if it was previously not set. !!! compat "Julia 1.11" This functio...
@@ -2758,6 +2758,19 @@ See also [`setpropertyonce!`](@ref Base.setpropertyonce!) and [`setglobal!`](@re """ setglobalonce! +""" + declare_global(module::Module, name::Symbol, strong::Bool=false, [ty::Type]) + +Declare the global `name` in module `module`. If `ty` is given, declares a +"strong" global, which can...
base/docs/basedocs.jl
26
Julia
0.714
suggestion
126
51
51
false
Remove :globaldecl and :global lowered forms; add Core.declare_global
58,279
JuliaLang/julia
35,573
Julia
vtjnash
xal-0
Review this pull request change. Language: Julia File: base/docs/basedocs.jl PR Title: Remove :globaldecl and :global lowered forms; add Core.declare_global BEFORE CODE: """ replaceglobal! """ setglobalonce!(module::Module, name::Symbol, value, [success_order::Symbol, [fail_order::Symbol=succ...
Since this is impossible for any function to do, it seems odd to call out that this function doesn't do it ```suggestion ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
ret === nothing && return nothing item2, state2 = ret return SCartesianIndex2{K}(1, item2), (1, item2, state2) end function iterate(iter::SCartesianIndices2{K}, (state1, item2, state2)) where {K} if state1 < K item1 = state1 + 1 return SCartesianIndex2{K}(item1, item2), (item1, item2, s...
It looks simpler to fuse the index transformation for IndexCartesian. ```julia # fallbacks function _getindex(::IndexSCartesian2, A::AbstractArray, I::Vararg{Int, N}) where {N} @_propagate_inbounds_meta _getindex(IndexCartesian(), A, I...) end function _setindex!(::IndexSCartesian2, A::AbstractArray, v, ...
ret === nothing && return nothing item2, state2 = ret return SCartesianIndex2{K}(1, item2), (1, item2, state2) end function iterate(iter::SCartesianIndices2{K}, (state1, item2, state2)) where {K} if state1 < K item1 = state1 + 1 return SCartesianIndex2{K}(item1, item2), (item1, item2, s...
@@ -314,11 +314,11 @@ end _maybe_reshape(::IndexSCartesian2, A::ReshapedReinterpretArray, I...) = A # fallbacks -function _getindex(::IndexSCartesian2, A::AbstractArray{T,N}, I::Vararg{Int, N}) where {T,N} +function _getindex(::IndexSCartesian2, A::AbstractArray{T,N}, I::Int...) where {T,N}
base/reinterpretarray.jl
26
Julia
0.857
refactor
481
51
51
false
fix trailing indices stackoverflow in reinterpreted array
58,293
JuliaLang/julia
35,573
Julia
N5N3
adienes
Review this pull request change. Language: Julia File: base/reinterpretarray.jl PR Title: fix trailing indices stackoverflow in reinterpreted array BEFORE CODE: ret === nothing && return nothing item2, state2 = ret return SCartesianIndex2{K}(1, item2), (1, item2, state2) end function iterate(iter::SCar...
It looks simpler to fuse the index transformation for IndexCartesian. ```julia # fallbacks function _getindex(::IndexSCartesian2, A::AbstractArray, I::Vararg{Int, N}) where {N} @_propagate_inbounds_meta _getindex(IndexCartesian(), A, I...) end function _setindex!(::IndexSCartesian2, A::AbstractArray, v, ...
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.
{ jl_value_t **types = jl_svec_data(((jl_datatype_t*)tt)->parameters); jl_value_t **sigs = jl_svec_data(((jl_datatype_t*)simplesig)->parameters); size_t i, lensig = jl_nparams(simplesig); assert(lensig == jl_nparams(tt)); assert(lensig > 0 && !jl_is_vararg(jl_tparam(simplesig, lensig - 1))); for...
I don't see why you are calling out either of these details, since that is a common feature of all of the fields of TypeMapLevel ```suggestion // This entire chain is type-equal to tt (by construction), so it is unnecessary to call `tt<:entry->sig` ```
return 0; if (definition->sig == (jl_value_t*)jl_anytuple_type && jl_atomic_load_relaxed(&definition->unspecialized)) return jl_egal((jl_value_t*)type, definition->sig); // handle builtin methods size_t i, np = jl_nparams(type); size_t nargs = definition->nargs; // == jl_nparams(jl_unwrap_u...
@@ -1389,10 +1389,15 @@ static int concretesig_equal(jl_value_t *tt, jl_value_t *simplesig) JL_NOTSAFEPO return 1; } +// if available, returns a TypeMapEntry in the "leafcache" that matches `tt` (by type-equality) and is valid during `world` static inline jl_typemap_entry_t *lookup_leafcache(jl_genericmemory_t...
src/gf.c
26
C
0.929
suggestion
263
51
51
false
gf.c: Add some comments to `ml_matches` (NFC)
58,304
JuliaLang/julia
35,573
Julia
vtjnash
topolarity
Review this pull request change. Language: C File: src/gf.c PR Title: gf.c: Add some comments to `ml_matches` (NFC) BEFORE CODE: { jl_value_t **types = jl_svec_data(((jl_datatype_t*)tt)->parameters); jl_value_t **sigs = jl_svec_data(((jl_datatype_t*)simplesig)->parameters); size_t i, lensig = jl_nparams...
I don't see why you are calling out either of these details, since that is a common feature of all of the fields of TypeMapLevel ```suggestion // This entire chain is type-equal to tt (by construction), so it is unnecessary to call `tt<:entry->sig` ```
You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate.