Skip to content

Commit c28a9de

Browse files
Make deepcopy_internal inferrable for BigInt and BigFloat (#54496)
Co-authored-by: Lilith Orion Hafner <[email protected]>
1 parent 6c17db1 commit c28a9de

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

base/gmp.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ Base.add_with_overflow(a::BigInt, b::BigInt) = a + b, false
832832
Base.sub_with_overflow(a::BigInt, b::BigInt) = a - b, false
833833
Base.mul_with_overflow(a::BigInt, b::BigInt) = a * b, false
834834

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

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

base/mpfr.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ function Base.deepcopy_internal(x::BigFloat, stackdict::IdDict)
11991199
y = _BigFloat(x.prec, x.sign, x.exp, d′)
12001200
#ccall((:mpfr_custom_move,libmpfr), Cvoid, (Ref{BigFloat}, Ptr{Limb}), y, d) # unnecessary
12011201
return y
1202-
end
1202+
end::BigFloat
12031203
end
12041204

12051205
function decompose(x::BigFloat)::Tuple{BigInt, Int, Int}

test/copy.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ end
248248
@test (@inferred Base.deepcopy_internal(zeros(), IdDict())) == zeros()
249249
end
250250

251+
@testset "deepcopy_internal big" begin
252+
@inferred Base.deepcopy_internal(big(1), IdDict())
253+
@inferred Base.deepcopy_internal(big(1.0), IdDict())
254+
end
255+
251256
@testset "`copyto!`'s unaliasing" begin
252257
a = view([1:3;], :)
253258
@test copyto!(a, 2, a, 1, 2) == [1;1:2;]

0 commit comments

Comments
 (0)