Skip to content

Commit

Permalink
Make deepcopy_internal inferrable for BigInt and BigFloat (#54496)
Browse files Browse the repository at this point in the history
Co-authored-by: Lilith Orion Hafner <lilithhafner@gmail.com>
  • Loading branch information
lgoettgens and LilithHafner authored May 18, 2024
1 parent 6c17db1 commit c28a9de
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ Base.add_with_overflow(a::BigInt, b::BigInt) = a + b, false
Base.sub_with_overflow(a::BigInt, b::BigInt) = a - b, false
Base.mul_with_overflow(a::BigInt, b::BigInt) = a * b, false

Base.deepcopy_internal(x::BigInt, stackdict::IdDict) = get!(() -> MPZ.set(x), stackdict, x)
Base.deepcopy_internal(x::BigInt, stackdict::IdDict) = get!(() -> MPZ.set(x), stackdict, x)::BigInt

## streamlined hashing for BigInt, by avoiding allocation from shifts ##

Expand Down
2 changes: 1 addition & 1 deletion base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ function Base.deepcopy_internal(x::BigFloat, stackdict::IdDict)
y = _BigFloat(x.prec, x.sign, x.exp, d′)
#ccall((:mpfr_custom_move,libmpfr), Cvoid, (Ref{BigFloat}, Ptr{Limb}), y, d) # unnecessary
return y
end
end::BigFloat
end

function decompose(x::BigFloat)::Tuple{BigInt, Int, Int}
Expand Down
5 changes: 5 additions & 0 deletions test/copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ end
@test (@inferred Base.deepcopy_internal(zeros(), IdDict())) == zeros()
end

@testset "deepcopy_internal big" begin
@inferred Base.deepcopy_internal(big(1), IdDict())
@inferred Base.deepcopy_internal(big(1.0), IdDict())
end

@testset "`copyto!`'s unaliasing" begin
a = view([1:3;], :)
@test copyto!(a, 2, a, 1, 2) == [1;1:2;]
Expand Down

0 comments on commit c28a9de

Please sign in to comment.