Skip to content

Commit

Permalink
remove top-level branches checking for Base (#56507)
Browse files Browse the repository at this point in the history
These are no longer needed, now that the files are no longer included
twice.
  • Loading branch information
JeffBezanson authored Nov 9, 2024
1 parent ca2d6aa commit 4cbeea5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 49 deletions.
2 changes: 0 additions & 2 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -616,11 +616,9 @@ promote_rule(a::Type{Array{T,n}}, b::Type{Array{S,n}}) where {T,n,S} = el_same(p

## Constructors ##

if nameof(@__MODULE__) === :Base # avoid method overwrite
# constructors should make copies
Array{T,N}(x::AbstractArray{S,N}) where {T,N,S} = copyto_axcheck!(Array{T,N}(undef, size(x)), x)
AbstractArray{T,N}(A::AbstractArray{S,N}) where {T,N,S} = copyto_axcheck!(similar(A,T), A)
end

## copying iterators to containers

Expand Down
2 changes: 0 additions & 2 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,8 @@ end
reinterpret(::Type{Bool}, B::BitArray, dims::NTuple{N,Int}) where {N} = reinterpret(B, dims)
reinterpret(B::BitArray, dims::NTuple{N,Int}) where {N} = reshape(B, dims)

if nameof(@__MODULE__) === :Base # avoid method overwrite
(::Type{T})(x::T) where {T<:BitArray} = copy(x)::T
BitArray(x::BitArray) = copy(x)
end

"""
BitArray(itr)
Expand Down
2 changes: 0 additions & 2 deletions base/genericmemory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,8 @@ promote_rule(a::Type{Memory{T}}, b::Type{Memory{S}}) where {T,S} = el_same(promo

## Constructors ##

if nameof(@__MODULE__) === :Base # avoid method overwrite
# constructors should make copies
Memory{T}(x::AbstractArray{S,1}) where {T,S} = copyto_axcheck!(Memory{T}(undef, size(x)), x)
end

## copying iterators to containers

Expand Down
57 changes: 26 additions & 31 deletions base/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -587,37 +587,32 @@ julia> bitstring(bitrotate(0b01110010, 8))
bitrotate(x::T, k::Integer) where {T <: BitInteger} =
(x << ((sizeof(T) << 3 - 1) & k)) | (x >>> ((sizeof(T) << 3 - 1) & -k))

# @doc isn't available when running in Core at this point.
# Tuple syntax for documentation two function signatures at the same time
# doesn't work either at this point.
if nameof(@__MODULE__) === :Base
for fname in (:mod, :rem)
@eval @doc """
rem(x::Integer, T::Type{<:Integer}) -> T
mod(x::Integer, T::Type{<:Integer}) -> T
%(x::Integer, T::Type{<:Integer}) -> T
Find `y::T` such that `x` ≡ `y` (mod n), where n is the number of integers representable
in `T`, and `y` is an integer in `[typemin(T),typemax(T)]`.
If `T` can represent any integer (e.g. `T == BigInt`), then this operation corresponds to
a conversion to `T`.
# Examples
```jldoctest
julia> x = 129 % Int8
-127
julia> typeof(x)
Int8
julia> x = 129 % BigInt
129
julia> typeof(x)
BigInt
```
""" $fname(x::Integer, T::Type{<:Integer})
end
for fname in (:mod, :rem)
@eval @doc """
rem(x::Integer, T::Type{<:Integer}) -> T
mod(x::Integer, T::Type{<:Integer}) -> T
%(x::Integer, T::Type{<:Integer}) -> T
Find `y::T` such that `x` ≡ `y` (mod n), where n is the number of integers representable
in `T`, and `y` is an integer in `[typemin(T),typemax(T)]`.
If `T` can represent any integer (e.g. `T == BigInt`), then this operation corresponds to
a conversion to `T`.
# Examples
```jldoctest
julia> x = 129 % Int8
-127
julia> typeof(x)
Int8
julia> x = 129 % BigInt
129
julia> typeof(x)
BigInt
```
""" $fname(x::Integer, T::Type{<:Integer})
end

rem(x::T, ::Type{T}) where {T<:Integer} = x
Expand Down
6 changes: 0 additions & 6 deletions base/namedtuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ julia> (; t.x)
"""
Core.NamedTuple

if nameof(@__MODULE__) === :Base

@eval function (NT::Type{NamedTuple{names,T}})(args::Tuple) where {names, T <: Tuple}
if length(args) != length(names::Tuple)
throw(ArgumentError("Wrong number of arguments to named tuple constructor."))
Expand Down Expand Up @@ -150,8 +148,6 @@ end

NamedTuple(itr) = (; itr...)

end # if Base

# Like NamedTuple{names, T} as a constructor, but omits the additional
# `convert` call, when the types are known to match the fields
@eval function _new_NamedTuple(T::Type{NamedTuple{NTN, NTT}} where {NTN, NTT}, args::Tuple)
Expand Down Expand Up @@ -194,7 +190,6 @@ function convert(::Type{NT}, nt::NamedTuple{names}) where {names, NT<:NamedTuple
return NT1(T1(nt))::NT1::NT
end

if nameof(@__MODULE__) === :Base
Tuple(nt::NamedTuple) = (nt...,)
(::Type{T})(nt::NamedTuple) where {T <: Tuple} = (t = Tuple(nt); t isa T ? t : convert(T, t)::T)

Expand Down Expand Up @@ -230,7 +225,6 @@ function show(io::IO, t::NamedTuple)
print(io, ")")
end
end
end

eltype(::Type{T}) where T<:NamedTuple = nteltype(T)
nteltype(::Type) = Any
Expand Down
6 changes: 0 additions & 6 deletions base/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,6 @@ fill_to_length(t::Tuple{}, val, ::Val{2}) = (val, val)

# constructing from an iterator

# only define these in Base, to avoid overwriting the constructors
# NOTE: this means this constructor must be avoided in Core.Compiler!
if nameof(@__MODULE__) === :Base

function tuple_type_tail(T::Type)
@_foldable_meta # TODO: this method is wrong (and not :foldable)
if isa(T, UnionAll)
Expand Down Expand Up @@ -496,8 +492,6 @@ _totuple(::Type{Tuple}, itr::NamedTuple) = (itr...,)
_totuple(::Type{Tuple}, p::Pair) = (p.first, p.second)
_totuple(::Type{Tuple}, x::Number) = (x,) # to make Tuple(x) inferable

end

## find ##

_findfirst_rec(f, i::Int, ::Tuple{}) = nothing
Expand Down

0 comments on commit 4cbeea5

Please sign in to comment.