Skip to content

Commit 6079f14

Browse files
lgoettgensLilithHafner
authored andcommitted
Make deepcopy_internal inferrable for BigInt and BigFloat (#54496)
Co-authored-by: Lilith Orion Hafner <[email protected]> (cherry picked from commit c28a9de)
1 parent 2b6f488 commit 6079f14

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
@@ -834,7 +834,7 @@ Base.add_with_overflow(a::BigInt, b::BigInt) = a + b, false
834834
Base.sub_with_overflow(a::BigInt, b::BigInt) = a - b, false
835835
Base.mul_with_overflow(a::BigInt, b::BigInt) = a * b, false
836836

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

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

base/mpfr.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ function Base.deepcopy_internal(x::BigFloat, stackdict::IdDict)
11931193
y = _BigFloat(x.prec, x.sign, x.exp, d′)
11941194
#ccall((:mpfr_custom_move,libmpfr), Cvoid, (Ref{BigFloat}, Ptr{Limb}), y, d) # unnecessary
11951195
return y
1196-
end
1196+
end::BigFloat
11971197
end
11981198

11991199
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
@@ -246,6 +246,11 @@ end
246246
@test (@inferred Base.deepcopy_internal(zeros(), IdDict())) == zeros()
247247
end
248248

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

0 commit comments

Comments
 (0)