ronantakizawa/codereview-bench huggingface dataset:
Repository: JuliaLang/julia
File: base/float.jl (Julia)

Code before:
                fneg = !fneg
            else
                fu = fu - du
            end
        else
            if fumax - fu < du
                fu = fumax
            else
                fu = fu + du
            end
        end
    end
    if fneg
        fu |= sign_mask(F)
    end
    reinterpret(F, fu)
end

"""
    nextfloat(x::AbstractFloat, n::Integer)

The result of `n` iterative applications of `nextfloat` to `x` if `n >= 0`, or `-n`
applications of [`prevfloat`](@ref) if `n < 0`.
"""
nextfloat(f::AbstractFloat, d::Integer) = _nextfloat(f, d < 0, uabs(d))
nextfloat(f::IEEEFloat, d::Unsigned) = _nextfloat(f, false, d)

"""
    nextfloat(x::AbstractFloat)

Return the smallest floating point number `y` of the same type as `x` such that `x < y`.
If no such `y` exists (e.g. if `x` is `Inf` or `NaN`), then return `x`.

See also: [`prevfloat`](@ref), [`eps`](@ref), [`issubnormal`](@ref).
"""
nextfloat(x::AbstractFloat) = nextfloat(x, 1)

"""
    prevfloat(x::AbstractFloat, n::Integer)

The result of `n` iterative applications of `prevfloat` to `x` if `n >= 0`, or `-n`
applications of [`nextfloat`](@ref) if `n < 0`.
"""
prevfloat(x::AbstractFloat, d::Integer) = _nextfloat(x, d > 0, uabs(d))

"""
    prevfloat(x::AbstractFloat)

Return the largest floating point number `y` of the same type as `x` such that `y < x`.
If no such `y` exists (e.g. if `x` is `-Inf` or `NaN`), then return `x`.
"""

Review comment (suggestion):
Seems not necessary to have an `Unsigned`-specific method.


```suggestion
```

Code after:
                fneg = !fneg
            else
                fu = fu - du
            end
        else
            if fumax - fu < du
                fu = fumax
            else
                fu = fu + du
            end
        end
    end
    if fneg
        fu |= sign_mask(F)
    end
    reinterpret(F, fu)
end

"""
    nextfloat(x::AbstractFloat, n::Integer)

The result of `n` iterative applications of `nextfloat` to `x` if `n >= 0`, or `-n`
applications of [`prevfloat`](@ref) if `n < 0`.
"""
nextfloat(f::AbstractFloat, d::Integer) = _nextfloat(f, isnegative(d), uabs(d))

"""
    nextfloat(x::AbstractFloat)

Return the smallest floating point number `y` of the same type as `x` such that `x < y`.
If no such `y` exists (e.g. if `x` is `Inf` or `NaN`), then return `x`.

See also: [`prevfloat`](@ref), [`eps`](@ref), [`issubnormal`](@ref).
"""
nextfloat(x::AbstractFloat) = nextfloat(x, 1)

"""
    prevfloat(x::AbstractFloat, n::Integer)

The result of `n` iterative applications of `prevfloat` to `x` if `n >= 0`, or `-n`
applications of [`nextfloat`](@ref) if `n < 0`.
"""
prevfloat(x::AbstractFloat, d::Integer) = _nextfloat(x, ispositive(d), uabs(d))

"""
    prevfloat(x::AbstractFloat)

Return the largest floating point number `y` of the same type as `x` such that `y < x`.
If no such `y` exists (e.g. if `x` is `-Inf` or `NaN`), then return `x`.
"""
prevfloat(x::AbstractFloat) = nextfloat(x, -1)
Repository: JuliaLang/julia
File: base/docs/basedocs.jl (Julia)

Code before:
    @warn "Could not write file."
end
```

or, when the file cannot be read into a variable:

```julia
lines = try
    open("/danger", "r") do f
        readlines(f)
    end
catch
    @warn "File not found."
end
```

The syntax `catch e` (where `e` is any variable) assigns the thrown
exception object to the given variable within the `catch` block.

```julia
try
    a_dangerous_operation()
catch e
    if isa(e, EOFError)
        @warn "The operation failed - EOF."
    elseif isa(e, IOError)
        @warn "The operation failed - IO Error."
    else
        rethrow() # ensure other exceptions can bubble up the call stack
    end
end
```

The power of the `try`/`catch` construct lies in the ability to unwind a deeply
nested computation immediately to a much higher level in the stack of calling functions.

A `try/catch` block can also have an `else` clause that executes only if no exception occurred:
```julia
try
    a_dangerous_operation()
catch
    @warn "The operation failed."
else
    @info "The operation succeeded."
end
```

A `try` or `try`/`catch` block can also have a [`finally`](@ref) clause that executes
at the end, regardless of whether an exception occurred.  For example, this can be
used to guarantee that an opened file is closed:
```julia

Review comment (suggestion):
I don't think `IOError` is exported (and maybe not even `public`).

Code after:
    @warn "Could not write file."
end
```

or, when the file cannot be read into a variable:

```julia
lines = try
    open("/danger", "r") do f
        readlines(f)
    end
catch
    @warn "File not found."
end
```

The syntax `catch e` (where `e` is any variable) assigns the thrown
exception object to the given variable within the `catch` block.

```julia
try
    a_dangerous_operation()
catch e
    if isa(e, EOFError)
        @warn "The operation failed - EOF."
    elseif isa(e, OutOfMemoryError)
        @warn "The operation failed - OOM."
    else
        rethrow() # ensure other exceptions can bubble up the call stack
    end
end
```

The power of the `try`/`catch` construct lies in the ability to unwind a deeply
nested computation immediately to a much higher level in the stack of calling functions.

A `try/catch` block can also have an `else` clause that executes only if no exception occurred:
```julia
try
    a_dangerous_operation()
catch
    @warn "The operation failed."
else
    @info "The operation succeeded."
end
```

A `try` or `try`/`catch` block can also have a [`finally`](@ref) clause that executes
at the end, regardless of whether an exception occurred.  For example, this can be
used to guarantee that an opened file is closed:
```julia
Repository: JuliaLang/julia
File: base/regex.jl (Julia)

Code before:
end

"""
    startswith(s::AbstractString, prefix::Regex)

Return `true` if `s` starts with the regex pattern, `prefix`.

!!! note
    `startswith` does not compile the anchoring into the regular
    expression, but instead passes the anchoring as
    `match_option` to PCRE. If compile time is amortized,
    `occursin(r"^...", s)` is faster than `startswith(s, r"...")`.

See also [`occursin`](@ref) and [`endswith`](@ref).

!!! compat "Julia 1.2"
    This method requires at least Julia 1.2.

# Examples
```jldoctest
julia> startswith("JuliaLang", r"Julia|Romeo")
true
```
# See also
[`endswith`](@ref), [`occursin`](@ref), [`match`](@ref)

"""
function startswith(s::AbstractString, r::Regex)
    compile(r)
    return PCRE.exec_r(r.regex, String(s), 0, r.match_options | PCRE.ANCHORED)
end

function startswith(s::SubString{String}, r::Regex)
    compile(r)
    return PCRE.exec_r(r.regex, s, 0, r.match_options | PCRE.ANCHORED)
end

"""
    endswith(s::AbstractString, suffix::Regex)

Return `true` if `s` ends with the regex pattern, `suffix`.

!!! note
    `endswith` does not compile the anchoring into the regular
    expression, but instead passes the anchoring as
    `match_option` to PCRE. If compile time is amortized,
    `occursin(r"...\$", s)` is faster than `endswith(s, r"...")`.

See also [`occursin`](@ref) and [`startswith`](@ref).

!!! compat "Julia 1.2"

Review comment (suggestion):
Adding `match` is a good idea, though it just needs to be added to the existing see also section above.

Same for the `endswith` docstring below

Code after:
end

"""
    startswith(s::AbstractString, prefix::Regex)

Return `true` if `s` starts with the regex pattern, `prefix`.

!!! note
    `startswith` does not compile the anchoring into the regular
    expression, but instead passes the anchoring as
    `match_option` to PCRE. If compile time is amortized,
    `occursin(r"^...", s)` is faster than `startswith(s, r"...")`.

See also [`occursin`](@ref), [`endswith`](@ref), [`match`](@ref)

!!! compat "Julia 1.2"
    This method requires at least Julia 1.2.

# Examples
```jldoctest
julia> startswith("JuliaLang", r"Julia|Romeo")
true
```
"""
function startswith(s::AbstractString, r::Regex)
    compile(r)
    return PCRE.exec_r(r.regex, String(s), 0, r.match_options | PCRE.ANCHORED)
end

function startswith(s::SubString{String}, r::Regex)
    compile(r)
    return PCRE.exec_r(r.regex, s, 0, r.match_options | PCRE.ANCHORED)
end

"""
    endswith(s::AbstractString, suffix::Regex)

Return `true` if `s` ends with the regex pattern, `suffix`.

!!! note
    `endswith` does not compile the anchoring into the regular
    expression, but instead passes the anchoring as
    `match_option` to PCRE. If compile time is amortized,
    `occursin(r"...\$", s)` is faster than `endswith(s, r"...")`.

See also [`occursin`](@ref), [`startswith`](@ref), [`match`](@ref)

!!! compat "Julia 1.2"
    This method requires at least Julia 1.2.

# Examples
Repository: JuliaLang/julia
File: base/rational.jl (Julia)

Code before:
//(x::Complex, y::Real) = complex(real(x)//y, imag(x)//y)
function //(x::Number, y::Complex{<:Rational})
    c, d = reim(y)
    if (isinf(c) | isinf(d))
        x * conj(zero(y))
    else
        x * conj(y)
    end//abs2(y)
end
function //(x::Number, y::Complex{<:Integer})
    c, d = reim(y)
    c_r, d_r = divgcd(c, d)
    abs2y_r = checked_add(checked_mul(c, c_r), checked_mul(d, d_r))
    (x * complex(c_r, checked_neg(d_r)))//abs2y_r
end
function //(x::Integer, y::Complex{<:Integer})
    a, c, d = promote(x, reim(y)...)
    c_r, d_r = divgcd(c, d)
    abs2y_r = checked_add(checked_mul(c, c_r), checked_mul(d, d_r))
    complex(checked_mul(a, c_r), checked_neg(checked_mul(a, d_r)))//abs2y_r
end
function //(x::Complex{<:Integer}, y::Complex{<:Integer})
    a, b, c, d = promote(reim(x)..., reim(y)...)
    c_r, d_r = divgcd(c, d)
    abs2y_r = checked_add(checked_mul(c, c_r), checked_mul(d, d_r))
    complex(
        checked_add(checked_mul(a, c_r), checked_mul(b, d_r)),
        checked_add(checked_mul(b, c_r), checked_neg(checked_mul(a, d_r)))
    )//abs2y_r
end

//(X::AbstractArray, y::Number) = X .// y

function show(io::IO, x::Rational)
    show(io, numerator(x))

    if isone(denominator(x)) && nonnothing_nonmissing_typeinfo(io) <: Rational
        return
    end

    print(io, "//")
    show(io, denominator(x))
end

function read(s::IO, ::Type{Rational{T}}) where T<:Integer
    r = read(s,T)
    i = read(s,T)
    r//i
end
function write(s::IO, z::Rational)
    write(s,numerator(z),denominator(z))

Review comment (performance):
is there any meaningful performance difference to spelling this method all out vs forwarding?
```
//(x::Integer, y::Complex{<:Integer}) = complex(x) // y
```

Code after:
//(x::Complex, y::Real) = complex(real(x)//y, imag(x)//y)

# Return a complex numerator and real denominator
# of the exact inverse of a Complex number.
function _complex_exact_inv(y::Complex)
    c, d = reim(y)
    num = if (isinf(c) | isinf(d))
        conj(zero(y))
    else
        conj(y)
    end
    num, abs2(y)
end
function _complex_exact_inv(y::Complex{<:Integer})
    c, d = reim(y)
    c_r, d_r = divgcd(c, d)
    abs2y_r = checked_add(checked_mul(c, c_r), checked_mul(d, d_r))
    num = complex(c_r, checked_neg(d_r))
    num, abs2y_r
end

function //(x::Number, y::Complex)
    num, den = _complex_exact_inv(y)
    (x * num) // den
end
function //(x::Integer, y::Complex{<:Integer})
    complex(x) // y
end
function //(x::Complex{<:Integer}, y::Complex{<:Integer})
    a, b, c, d = promote(reim(x)..., reim(y)...)
    c_r, d_r = divgcd(c, d)
    abs2y_r = checked_add(checked_mul(c, c_r), checked_mul(d, d_r))
    complex(
        checked_add(checked_mul(a, c_r), checked_mul(b, d_r)),
        checked_add(checked_mul(b, c_r), checked_neg(checked_mul(a, d_r)))
    )//abs2y_r
end

//(X::AbstractArray, y::Number) = X .// y

function show(io::IO, x::Rational)
    show(io, numerator(x))

    if isone(denominator(x)) && nonnothing_nonmissing_typeinfo(io) <: Rational
        return
    end

    print(io, "//")
    show(io, denominator(x))
end
Repository: JuliaLang/julia
File: base/rational.jl (Julia)

Code before:
```
"""
//(n::Integer,  d::Integer) = Rational(n,d)

function //(x::Rational, y::Integer)
    xn, yn = divgcd(promote(x.num, y)...)
    checked_den(xn, checked_mul(x.den, yn))
end
function //(x::Integer,  y::Rational)
    xn, yn = divgcd(promote(x, y.num)...)
    checked_den(checked_mul(xn, y.den), yn)
end
function //(x::Rational, y::Rational)
    xn,yn = divgcd(promote(x.num, y.num)...)
    xd,yd = divgcd(promote(x.den, y.den)...)
    checked_den(checked_mul(xn, yd), checked_mul(xd, yn))
end

//(x::Complex, y::Real) = complex(real(x)//y, imag(x)//y)
function //(x::Number, y::Complex{<:Rational})
    c, d = reim(y)
    if (isinf(c) | isinf(d))
        x * conj(zero(y))
    else
        x * conj(y)
    end//abs2(y)
end
function //(x::Number, y::Complex{<:Integer})
    c, d = reim(y)
    c_r, d_r = divgcd(c, d)
    abs2y_r = checked_add(checked_mul(c, c_r), checked_mul(d, d_r))
    (x * complex(c_r, checked_neg(d_r)))//abs2y_r
end
function //(x::Integer, y::Complex{<:Integer})
    complex(x) // y
end
function //(x::Complex{<:Integer}, y::Complex{<:Integer})
    a, b, c, d = promote(reim(x)..., reim(y)...)
    c_r, d_r = divgcd(c, d)
    abs2y_r = checked_add(checked_mul(c, c_r), checked_mul(d, d_r))
    complex(
        checked_add(checked_mul(a, c_r), checked_mul(b, d_r)),
        checked_add(checked_mul(b, c_r), checked_neg(checked_mul(a, d_r)))
    )//abs2y_r
end

//(X::AbstractArray, y::Number) = X .// y

function show(io::IO, x::Rational)
    show(io, numerator(x))


Review comment (suggestion):
```suggestion

```

don't intend to be style police but something about this looks so unsettling haha

Code after:
```
"""
//(n::Integer,  d::Integer) = Rational(n,d)

function //(x::Rational, y::Integer)
    xn, yn = divgcd(promote(x.num, y)...)
    checked_den(xn, checked_mul(x.den, yn))
end
function //(x::Integer,  y::Rational)
    xn, yn = divgcd(promote(x, y.num)...)
    checked_den(checked_mul(xn, y.den), yn)
end
function //(x::Rational, y::Rational)
    xn,yn = divgcd(promote(x.num, y.num)...)
    xd,yd = divgcd(promote(x.den, y.den)...)
    checked_den(checked_mul(xn, yd), checked_mul(xd, yn))
end

//(x::Complex, y::Real) = complex(real(x)//y, imag(x)//y)

# Return a complex numerator and real denominator
# of the exact inverse of a Complex number.
function _complex_exact_inv(y::Complex)
    c, d = reim(y)
    num = if (isinf(c) | isinf(d))
        conj(zero(y))
    else
        conj(y)
    end
    num, abs2(y)
end
function _complex_exact_inv(y::Complex{<:Integer})
    c, d = reim(y)
    c_r, d_r = divgcd(c, d)
    abs2y_r = checked_add(checked_mul(c, c_r), checked_mul(d, d_r))
    num = complex(c_r, checked_neg(d_r))
    num, abs2y_r
end

function //(x::Number, y::Complex)
    num, den = _complex_exact_inv(y)
    (x * num) // den
end
function //(x::Integer, y::Complex{<:Integer})
    complex(x) // y
end
function //(x::Complex{<:Integer}, y::Complex{<:Integer})
    a, b, c, d = promote(reim(x)..., reim(y)...)
    c_r, d_r = divgcd(c, d)
    abs2y_r = checked_add(checked_mul(c, c_r), checked_mul(d, d_r))
    complex(
Repository: JuliaLang/julia
File: stdlib/Markdown/test/runtests.jl (Julia)

Code before:
    - item

        domaths(x::Number) = x + 5


        domath(x::Int) = x + 10
    """

    # Parse Markdown normally
    md = Markdown.parse(input)

    # Convert to HTML
    html = sprint(show, MIME"text/html"(), md)

    # Must still be a single list item
    @test occursin("<ul>", html)
    @test occursin("<li>", html)

    # Content must not be dropped or split
    @test occursin("item", html)
    @test occursin("domaths", html)
    @test occursin("domath", html)

    # And importantly: no premature list termination
    # Apply occursin elementwise using broadcasting
    @test count(occursin.("<li>", split(html, '\n'))) == 1
end

@testset "Lazy Strings" begin
    @test Markdown.parse(lazy"foo") == Markdown.parse("foo")
end


Review comment (suggestion):
But this test also passes with the *current* version of the code. You are not actually testing that your change does something!

I would recommend to just test the full HTML output as is done e.g. in line 1122 and in other places. That then also will catch other (intended or unintended) changes affecting this output.

Code after:
    md = Markdown.parse("""
    - code block inside a list with more than one blank line with indentation works
      ```julia
      domaths(x::Number) = x + 5


      domath(x::Int) = x + 10
      ```
    - another entry, now testing code blocks without fences

          # this is a code block
          x = 1 + 1


          # Two empty lines don't interrupt the code
          y = x * 3

    - a final list entry

    And now to something completely different!
    """)
    expected =
    """
    <ul>
    <li><p>code block inside a list with more than one blank line with indentation works</p>
    <pre><code class="language-julia">domaths&#40;x::Number&#41; &#61; x &#43; 5


    domath&#40;x::Int&#41; &#61; x &#43; 10</code></pre>
    </li>
    <li><p>another entry, now testing code blocks without fences</p>
    <pre><code># this is a code block
    x &#61; 1 &#43; 1


    # Two empty lines don&#39;t interrupt the code
    y &#61; x * 3</code></pre>
    </li>
    <li><p>a final list entry</p>
    </li>
    </ul>
    <p>And now to something completely different&#33;</p>
    """

    @test expected == Markdown.html(md)
end

@testset "Lazy Strings" begin
    @test Markdown.parse(lazy"foo") == Markdown.parse("foo")
end
Repository: JuliaLang/julia
File: stdlib/Markdown/test/runtests.jl (Julia)

Code before:
    @test isempty(Docs.undocumented_names(Markdown))
end

@testset "Non-Markdown" begin
    # https://github.com/JuliaLang/julia/issues/37765
    @test isa(insert_hlines(Text("foo")), Text)
    # https://github.com/JuliaLang/julia/issues/37757
    @test insert_hlines(nothing) === nothing
end

@testset "#59967: indented code blocks with more than one blank line" begin
    # Test the broken case in issue: indented code block with multiple blank lines
    md = Markdown.parse("""
- code block with more than one blank line with indention does not work
  ```julia
  domaths(x::Number) = x + 5


  domath(x::Int) = x + 10
  ```
""")

    expected =
        """
        <ul>
        <li><p>code block with more than one blank line with indention does not work</p>
        <pre><code class="language-julia">domaths&#40;x::Number&#41; &#61; x &#43; 5


        domath&#40;x::Int&#41; &#61; x &#43; 10</code></pre>
        </li>
        </ul>
        """
    @test expected == Markdown.html(md)
end

@testset "Lazy Strings" begin
    @test Markdown.parse(lazy"foo") == Markdown.parse("foo")
end


Review comment (suggestion):
```suggestion
        <li><p> code block inside a list with more than one blank line with indentation works</p>
```

Code after:
    @test isempty(Docs.undocumented_names(Markdown))
end

@testset "Non-Markdown" begin
    # https://github.com/JuliaLang/julia/issues/37765
    @test isa(insert_hlines(Text("foo")), Text)
    # https://github.com/JuliaLang/julia/issues/37757
    @test insert_hlines(nothing) === nothing
end

@testset "#59967: indented code blocks with more than one blank line" begin
    # Test the broken case in issue: indented code block with multiple blank lines
    md = Markdown.parse("""
    - code block inside a list with more than one blank line with indentation works
      ```julia
      domaths(x::Number) = x + 5


      domath(x::Int) = x + 10
      ```
    - another entry, now testing code blocks without fences

          # this is a code block
          x = 1 + 1


          # Two empty lines don't interrupt the code
          y = x * 3

    - a final list entry

    And now to something completely different!
    """)
    expected =
    """
    <ul>
    <li><p>code block inside a list with more than one blank line with indentation works</p>
    <pre><code class="language-julia">domaths&#40;x::Number&#41; &#61; x &#43; 5


    domath&#40;x::Int&#41; &#61; x &#43; 10</code></pre>
    </li>
    <li><p>another entry, now testing code blocks without fences</p>
    <pre><code># this is a code block
    x &#61; 1 &#43; 1


    # Two empty lines don&#39;t interrupt the code
    y &#61; x * 3</code></pre>
    </li>
    <li><p>a final list entry</p>
Repository: JuliaLang/julia
File: test/precompile_utils.jl (Julia)

Code before:
# This file is a part of Julia. License is MIT: https://julialang.org/license

include("tempdepot.jl")

function precompile_test_harness(@nospecialize(f), testset::String)
    @testset "$testset" precompile_test_harness(f, true)
end
function precompile_test_harness(@nospecialize(f), separate::Bool=true)
    load_path = mkdepottempdir()
    load_cache_path = separate ? mkdepottempdir() : load_path
    try
        pushfirst!(LOAD_PATH, load_path)
        pushfirst!(DEPOT_PATH, load_cache_path)
        f(load_path)
    finally
        filter!((≠)(load_path), LOAD_PATH)
        separate && filter!((≠)(load_cache_path), DEPOT_PATH)
    end
    return nothing
end

let original_depot_path = copy(Base.DEPOT_PATH)
    original_load_path = copy(Base.LOAD_PATH)

    global function finish_precompile_test!()
        empty!(Base.DEPOT_PATH)
        append!(Base.DEPOT_PATH, original_depot_path)
        empty!(Base.LOAD_PATH)
        append!(Base.LOAD_PATH, original_load_path)
    end
end


Review comment (bug):
Something probably went horribly wrong if `ci.max_world != WORLD_AGE_REVALIDATION_SENTINEL`, since that means the Compiler made a mistake and forgot to validate it

Code after:
    try
        pushfirst!(LOAD_PATH, load_path)
        pushfirst!(DEPOT_PATH, load_cache_path)
        f(load_path)
    finally
        filter!((≠)(load_path), LOAD_PATH)
        separate && filter!((≠)(load_cache_path), DEPOT_PATH)
    end
    return nothing
end

let original_depot_path = copy(Base.DEPOT_PATH)
    original_load_path = copy(Base.LOAD_PATH)

    global function finish_precompile_test!()
        empty!(Base.DEPOT_PATH)
        append!(Base.DEPOT_PATH, original_depot_path)
        empty!(Base.LOAD_PATH)
        append!(Base.LOAD_PATH, original_load_path)
    end
end

function check_presence(mi, token)
    ci = isdefined(mi, :cache) ? mi.cache : nothing
    while ci !== nothing
        if ci.owner === token && ci.max_world == typemax(UInt)
            return ci
        end
        ci = isdefined(ci, :next) ? ci.next : nothing
    end
    return nothing
end