From 4cbeea559e903a353a5b1d08adbd54f47c5548fc Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Fri, 8 Nov 2024 23:47:13 -0500 Subject: [PATCH] remove top-level branches checking for Base (#56507) These are no longer needed, now that the files are no longer included twice. --- base/array.jl | 2 -- base/bitarray.jl | 2 -- base/genericmemory.jl | 2 -- base/int.jl | 57 ++++++++++++++++++++----------------------- base/namedtuple.jl | 6 ----- base/tuple.jl | 6 ----- 6 files changed, 26 insertions(+), 49 deletions(-) diff --git a/base/array.jl b/base/array.jl index 0f86bbeda7523..65cc29f38c911 100644 --- a/base/array.jl +++ b/base/array.jl @@ -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 diff --git a/base/bitarray.jl b/base/bitarray.jl index f7eeafbb62231..93fa48c56e379 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -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) diff --git a/base/genericmemory.jl b/base/genericmemory.jl index f814aa4d84bdd..fbf60255935a3 100644 --- a/base/genericmemory.jl +++ b/base/genericmemory.jl @@ -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 diff --git a/base/int.jl b/base/int.jl index a25b17e2cc958..8a80f90f7e2c1 100644 --- a/base/int.jl +++ b/base/int.jl @@ -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 diff --git a/base/namedtuple.jl b/base/namedtuple.jl index a7379121b2ce2..991c4d35da52f 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -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.")) @@ -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) @@ -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) @@ -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 diff --git a/base/tuple.jl b/base/tuple.jl index 8690f89bdc263..3791d74bfc698 100644 --- a/base/tuple.jl +++ b/base/tuple.jl @@ -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) @@ -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