From 9f342c7f6542998270a9dcbaa4dd87b7e6531dfe Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Fri, 29 Aug 2025 23:36:49 +0200 Subject: [PATCH 1/4] introduce constructing functions with typeassert for several types Introduce functions to construct and typeassert several concrete types: * `Bool` * other primitive integers * `Char` * `String` The new functions are meant to be used internally instead of the original constructors to help inference. Cross-reference issue #42372. --- base/Base_compiler.jl | 1 + base/constructingfunctions.jl | 36 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 base/constructingfunctions.jl diff --git a/base/Base_compiler.jl b/base/Base_compiler.jl index 5d786a325940a..f3ae2e50f4bdb 100644 --- a/base/Base_compiler.jl +++ b/base/Base_compiler.jl @@ -289,6 +289,7 @@ end setfield!(typeof(invoke_in_world).name, :max_args, Int32(3), :monotonic) # invoke_in_world, world, f, args... # core operations & types +include("constructingfunctions.jl") include("promotion.jl") include("tuple.jl") include("expr.jl") diff --git a/base/constructingfunctions.jl b/base/constructingfunctions.jl new file mode 100644 index 0000000000000..8621a08b098c0 --- /dev/null +++ b/base/constructingfunctions.jl @@ -0,0 +1,36 @@ +# Constructing functions for some concrete types. +# +# Meant to be used to improve inference, when the input arguments are not necessarily +# precisely inferred. Partial workaround for issue #42372. +module _ConstructingFunctions + export + _Bool, + _Int, _Int8, _Int16, _Int32, _Int64, _Int128, + _UInt, _UInt8, _UInt16, _UInt32, _UInt64, _UInt128, + _Char, _String + struct ConstructorStrict{F} <: Function end + # Keyword arguments are not available at this point in bootstrap, so they're not + # supported. + function (::ConstructorStrict{F})(args::Vararg{Any, N}) where {F, N} + @inline + r = F(args...) + r::F + end + const _Bool = ConstructorStrict{Bool}() + const _Int = ConstructorStrict{Int}() + const _Int8 = ConstructorStrict{Int8}() + const _Int16 = ConstructorStrict{Int16}() + const _Int32 = ConstructorStrict{Int32}() + const _Int64 = ConstructorStrict{Int64}() + const _Int128 = ConstructorStrict{Int128}() + const _UInt = ConstructorStrict{UInt}() + const _UInt8 = ConstructorStrict{UInt8}() + const _UInt16 = ConstructorStrict{UInt16}() + const _UInt32 = ConstructorStrict{UInt32}() + const _UInt64 = ConstructorStrict{UInt64}() + const _UInt128 = ConstructorStrict{UInt128}() + const _Char = ConstructorStrict{Char}() + const _String = ConstructorStrict{String}() +end + +using ._ConstructingFunctions From 41a456bb8fa07deb047708a6fa5e963869ed92be Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Sat, 30 Aug 2025 12:06:02 +0200 Subject: [PATCH 2/4] test return type inference --- test/core.jl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/core.jl b/test/core.jl index 7eae62d2fef34..0678062ef0da8 100644 --- a/test/core.jl +++ b/test/core.jl @@ -8191,6 +8191,29 @@ end @test_throws "expected Union{$Int, Symbol}" getfield((1,2), Int8(1)) end +@testset "constructing functions should have perfect return type inference" begin + for (type, func) in ( + (Bool, Base._Bool), + (Int, Base._Int), + (Int8, Base._Int8), + (Int16, Base._Int16), + (Int32, Base._Int32), + (Int64, Base._Int64), + (Int128, Base._Int128), + (UInt, Base._UInt), + (UInt8, Base._UInt8), + (UInt16, Base._UInt16), + (UInt32, Base._UInt32), + (UInt64, Base._UInt64), + (UInt128, Base._UInt128), + (Char, Base._Char), + (String, Base._String), + ) + @test isconcretetype(type) # meta test + @test type === Base.infer_return_type(x -> func(x)) + end +end + # Correct isdefined error for isdefined of Module of Int fld f_isdefined_one(@nospecialize(x)) = isdefined(x, 1) @test (try; f_isdefined_one(@__MODULE__); catch err; err; end).got === 1 From 59a28fa92e9523d29260d283a726d1c297df70fe Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Sat, 30 Aug 2025 00:59:14 +0200 Subject: [PATCH 3/4] apply the constructing functions to some code under `base/` --- base/abstractarray.jl | 28 +++++++++---------- base/abstractarraymath.jl | 4 +-- base/abstractset.jl | 2 +- base/array.jl | 36 ++++++++++++------------ base/arraymath.jl | 2 +- base/arrayshow.jl | 2 +- base/binaryplatforms.jl | 5 ++-- base/bitarray.jl | 52 +++++++++++++++++------------------ base/broadcast.jl | 11 ++++---- base/char.jl | 24 ++++++++-------- base/client.jl | 4 +-- base/cmd.jl | 4 +-- base/deprecated.jl | 2 +- base/dict.jl | 6 ++-- base/docs/Docs.jl | 3 +- base/env.jl | 2 +- base/file.jl | 8 +++--- base/filesystem.jl | 8 ++++-- base/flfrontend.jl | 2 +- base/float.jl | 4 +-- base/gmp.jl | 16 ++++++----- base/hashing.jl | 40 +++++++++++++-------------- base/io.jl | 8 +++--- base/iobuffer.jl | 20 +++++++------- base/iterators.jl | 17 +++++++----- base/loading.jl | 34 +++++++++++------------ base/logging/ConsoleLogger.jl | 4 +-- base/logging/logging.jl | 5 ++-- base/meta.jl | 10 ++++--- base/methodshow.jl | 8 +++--- base/multidimensional.jl | 12 ++++---- base/multimedia.jl | 5 ++-- base/namedtuple.jl | 4 +-- base/parse.jl | 6 ++-- base/path.jl | 14 +++++----- base/pcre.jl | 9 +++--- base/pointer.jl | 16 +++++------ base/precompilation.jl | 10 ++++--- base/process.jl | 2 +- base/regex.jl | 18 ++++++------ base/secretbuffer.jl | 4 +-- base/show.jl | 4 +-- base/sort.jl | 4 ++- base/stat.jl | 4 +-- base/stream.jl | 12 ++++---- base/strings/annotated_io.jl | 4 +-- base/strings/basic.jl | 30 ++++++++++---------- base/strings/cstring.jl | 22 +++++++-------- base/strings/io.jl | 16 +++++------ base/strings/search.jl | 24 ++++++++-------- base/strings/string.jl | 30 ++++++++++---------- base/strings/substring.jl | 4 +-- base/strings/unicode.jl | 14 ++++++---- base/strings/util.jl | 36 ++++++++++++------------ base/sysinfo.jl | 2 +- base/terminfo.jl | 8 +++--- base/timing.jl | 4 +-- base/toml_parser.jl | 3 +- base/tuple.jl | 4 +-- base/twiceprecision.jl | 2 +- base/util.jl | 2 +- base/uuid.jl | 2 +- base/version.jl | 8 +++--- 63 files changed, 366 insertions(+), 344 deletions(-) diff --git a/base/abstractarray.jl b/base/abstractarray.jl index d4d430a5a1811..a86041052490a 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -108,8 +108,8 @@ If multiple arguments are passed, equivalent to `has_offset_axes(A) || has_offse See also [`require_one_based_indexing`](@ref). """ has_offset_axes() = false -has_offset_axes(A) = _any_tuple(x->Int(first(x))::Int != 1, false, axes(A)...) -has_offset_axes(A::AbstractVector) = Int(firstindex(A))::Int != 1 # improve performance of a common case (ranges) +has_offset_axes(A) = _any_tuple(!=(1) ∘ _Int ∘ first, false, axes(A)...) +has_offset_axes(A::AbstractVector) = _Int(firstindex(A)) != 1 # improve performance of a common case (ranges) has_offset_axes(::Colon) = false has_offset_axes(::Array) = false # note: this could call `any` directly if the compiler can infer it. We don't use _any_tuple @@ -212,8 +212,8 @@ String """ valtype(A::Type{<:AbstractArray}) = eltype(A) -prevind(::AbstractArray, i::Integer) = Int(i)-1 -nextind(::AbstractArray, i::Integer) = Int(i)+1 +prevind(::AbstractArray, i::Integer) = _Int(i)-1 +nextind(::AbstractArray, i::Integer) = _Int(i)+1 """ @@ -838,10 +838,10 @@ to_shape(dims::Dims) = dims to_shape(dims::DimsOrInds) = map(to_shape, dims)::DimsOrInds # each dimension to_shape(i::Int) = i -to_shape(i::Integer) = Int(i) +to_shape(i::Integer) = _Int(i) to_shape(r::AbstractOneTo) = _to_shape(last(r)) _to_shape(x::Integer) = to_shape(x) -_to_shape(x) = Int(x) +_to_shape(x) = _Int(x) to_shape(r::AbstractUnitRange) = r """ @@ -951,7 +951,7 @@ function copyto!(dest::AbstractArray, src) end function copyto!(dest::AbstractArray, dstart::Integer, src) - i = Int(dstart) + i = _Int(dstart) if haslength(src) && length(dest) > 0 @boundscheck checkbounds(dest, i:(i + length(src) - 1)) for x in src @@ -986,7 +986,7 @@ function copyto!(dest::AbstractArray, dstart::Integer, src, sstart::Integer) "source has fewer elements than required, ", "expected at least ",sstart," got ", sstart-1))) end - i = Int(dstart) + i = _Int(dstart) while y !== nothing val, st = y dest[i] = val @@ -1023,7 +1023,7 @@ function copyto!(dest::AbstractArray, dstart::Integer, src, sstart::Integer, n:: "expected at least ",sstart," got ", sstart-1))) end val, st = y - i = Int(dstart) + i = _Int(dstart) @inbounds dest[i] = val for val in Iterators.take(Iterators.rest(src, st), n-1) i += 1 @@ -1269,7 +1269,7 @@ end pointer(x::AbstractArray{T}) where {T} = unsafe_convert(Ptr{T}, cconvert(Ptr{T}, x)) function pointer(x::AbstractArray{T}, i::Integer) where T @inline - pointer(x) + Int(_memory_offset(x, i))::Int + pointer(x) + _Int(_memory_offset(x, i)) end # The distance from pointer(x) to the element at x[I...] in bytes @@ -1601,8 +1601,8 @@ parts can specialize this method to return the concatenation of the `dataids` of their component parts. A typical definition for an array that wraps a parent is `Base.dataids(C::CustomArray) = dataids(C.parent)`. """ -dataids(A::AbstractArray) = (UInt(objectid(A)),) -dataids(A::Memory) = (UInt(A.ptr),) +dataids(A::AbstractArray) = (_UInt(objectid(A)),) +dataids(A::Memory) = (_UInt(A.ptr),) dataids(A::Array) = dataids(A.ref.mem) dataids(::AbstractRange) = () dataids(x) = () @@ -1702,9 +1702,9 @@ _typed_vcat(::Type{T}, V::AbstractVecOrTuple{AbstractVector}) where T = function _typed_vcat!(a::AbstractVector{T}, V::AbstractVecOrTuple{AbstractVector}) where T pos = 1 - for k=1:Int(length(V))::Int + for k=1:_Int(length(V)) Vk = V[k] - p1 = pos + Int(length(Vk))::Int - 1 + p1 = pos + _Int(length(Vk)) - 1 a[pos:p1] = Vk pos = p1+1 end diff --git a/base/abstractarraymath.jl b/base/abstractarraymath.jl index 66c75cf977c56..4c8ec516ef383 100644 --- a/base/abstractarraymath.jl +++ b/base/abstractarraymath.jl @@ -91,7 +91,7 @@ function _dropdims(A::AbstractArray, dims::Dims) ax = _foldoneto((ds, d) -> d in dims ? ds : (ds..., axes(A,d)), (), Val(ndims(A))) reshape(A, ax::typeof(_sub(axes(A), dims))) end -_dropdims(A::AbstractArray, dim::Integer) = _dropdims(A, (Int(dim),)) +_dropdims(A::AbstractArray, dim::Integer) = _dropdims(A, (_Int(dim),)) """ @@ -153,7 +153,7 @@ function _insertdims(A::AbstractArray{T, N}, dims::NTuple{M, Int}) where {T, N, new_shape = inds[1] return reshape(A, new_shape) end -_insertdims(A::AbstractArray, dim::Integer) = _insertdims(A, (Int(dim),)) +_insertdims(A::AbstractArray, dim::Integer) = _insertdims(A, (_Int(dim),)) diff --git a/base/abstractset.jl b/base/abstractset.jl index 315260e16d2d1..b549eb17112ce 100644 --- a/base/abstractset.jl +++ b/base/abstractset.jl @@ -101,7 +101,7 @@ max_values(::Type{Bool}) = 2 max_values(::Type{Nothing}) = 1 function union!(s::AbstractSet{T}, itr) where T - haslength(itr) && sizehint!(s, length(s) + Int(length(itr))::Int; shrink = false) + haslength(itr) && sizehint!(s, length(s) + _Int(length(itr)); shrink = false) for x in itr push!(s, x) length(s) == max_values(T) && break diff --git a/base/array.jl b/base/array.jl index ce15c3c2cd69c..8eafff528a212 100644 --- a/base/array.jl +++ b/base/array.jl @@ -185,7 +185,7 @@ function vect(X...) return T[X...] end -size(a::Array, d::Integer) = size(a, Int(d)::Int) +size(a::Array, d::Integer) = size(a, _Int(d)) function size(a::Array, d::Int) d < 1 && error("arraysize: dimension out of range") sz = getfield(a, :size) @@ -672,7 +672,7 @@ _similar_for(c::AbstractArray, ::Type{T}, itr, ::HasShape, axs) where {T} = # make a collection appropriate for collecting `itr::Generator` _array_for(::Type{T}, ::SizeUnknown, ::Nothing) where {T} = Vector{T}(undef, 0) -_array_for(::Type{T}, ::HasLength, len::Integer) where {T} = Vector{T}(undef, Int(len)) +_array_for(::Type{T}, ::HasLength, len::Integer) where {T} = Vector{T}(undef, _Int(len)) _array_for(::Type{T}, ::HasShape{N}, axs) where {T,N} = similar(Array{T,N}, axs) # used by syntax lowering for simple typed comprehensions @@ -1112,7 +1112,7 @@ end function _growbeg!(a::Vector, delta::Integer) @_noub_meta - delta = Int(delta) + delta = _Int(delta) delta == 0 && return # avoid attempting to index off the end delta >= 0 || throw(ArgumentError("grow requires delta >= 0")) ref = a.ref @@ -1167,7 +1167,7 @@ end function _growend!(a::Vector, delta::Integer) @_noub_meta - delta = Int(delta) + delta = _Int(delta) delta >= 0 || throw(ArgumentError("grow requires delta >= 0")) ref = a.ref mem = ref.mem @@ -1185,8 +1185,8 @@ end function _growat!(a::Vector, i::Integer, delta::Integer) @_terminates_globally_noub_meta - delta = Int(delta) - i = Int(i) + delta = _Int(delta) + i = _Int(i) i == 1 && return _growbeg!(a, delta) len = length(a) i == len + 1 && return _growend!(a, delta) @@ -1230,7 +1230,7 @@ end # efficiently delete part of an array function _deletebeg!(a::Vector, delta::Integer) - delta = Int(delta) + delta = _Int(delta) len = length(a) 0 <= delta <= len || throw(ArgumentError("_deletebeg! requires delta in 0:length(a)")) for i in 1:delta @@ -1245,7 +1245,7 @@ function _deletebeg!(a::Vector, delta::Integer) return end function _deleteend!(a::Vector, delta::Integer) - delta = Int(delta) + delta = _Int(delta) len = length(a) 0 <= delta <= len || throw(ArgumentError("_deleteend! requires delta in 0:length(a)")) newlen = len - delta @@ -1256,7 +1256,7 @@ function _deleteend!(a::Vector, delta::Integer) return end function _deleteat!(a::Vector, i::Integer, delta::Integer) - i = Int(i) + i = _Int(i) len = length(a) 0 <= delta || throw(ArgumentError("_deleteat! requires delta >= 0")) 1 <= i <= len || throw(BoundsError(a, i)) @@ -1372,7 +1372,7 @@ function append! end function append!(a::Vector{T}, items::Union{AbstractVector{<:T},Tuple}) where T items isa Tuple && (items = map(x -> convert(T, x), items)) - n = Int(length(items))::Int + n = _Int(length(items)) _growend!(a, n) copyto!(a, length(a)-n+1, items, firstindex(items), n) return a @@ -1383,7 +1383,7 @@ push!(a::AbstractVector, iter...) = append!(a, iter) append!(a::AbstractVector, iter...) = (foreach(v -> append!(a, v), iter); a) function _append!(a::AbstractVector, ::Union{HasLength,HasShape}, iter) - n = Int(length(iter))::Int + n = _Int(length(iter)) i = lastindex(a) sizehint!(a, length(a) + n; shrink=false) for item in iter @@ -1446,7 +1446,7 @@ prepend!(a::AbstractVector, iter...) = (for v = reverse(iter); prepend!(a, v); e function _prepend!(a::Vector, ::Union{HasLength,HasShape}, iter) @_terminates_locally_meta require_one_based_indexing(a) - n = Int(length(iter))::Int + n = _Int(length(iter)) sizehint!(a, length(a) + n; first=true, shrink=false) n = 0 for item in iter @@ -1497,7 +1497,7 @@ julia> a[1:6] ``` """ function resize!(a::Vector, nl_::Integer) - nl = Int(nl_)::Int + nl = _Int(nl_) l = length(a) if nl > l _growend!(a, nl-l) @@ -1551,7 +1551,7 @@ function sizehint!(a::Vector, sz::Integer; first::Bool=false, shrink::Bool=true) ref = a.ref mem = ref.mem memlen = length(mem) - sz = max(Int(sz), len) + sz = max(_Int(sz), len) inc = sz - len if sz <= memlen # if we don't save at least 1/8th memlen then its not worth it to shrink @@ -2185,7 +2185,7 @@ julia> reverse(A, 3, 5) ``` """ function reverse(A::AbstractVector, start::Integer, stop::Integer=lastindex(A)) - s, n = Int(start), Int(stop) + s, n = _Int(start), _Int(stop) B = similar(A) for i = firstindex(A):s-1 B[i] = A[i] @@ -2249,7 +2249,7 @@ julia> A ``` """ function reverse!(v::AbstractVector, start::Integer, stop::Integer=lastindex(v)) - s, n = Int(start), Int(stop) + s, n = _Int(start), _Int(stop) if n > s # non-empty and non-trivial liv = LinearIndices(v) if !(first(liv) ≤ s ≤ last(liv)) @@ -3196,12 +3196,12 @@ end $(Expr(:new, :(Array{T, N}), :ref, :dims)) end @eval @propagate_inbounds function wrap(::Type{Array}, m::MemoryRef{T}, l::Integer) where {T} - dims = (Int(l),) + dims = (_Int(l),) ref = _wrap(m, dims) $(Expr(:new, :(Array{T, 1}), :ref, :dims)) end @eval @propagate_inbounds function wrap(::Type{Array}, m::Memory{T}, l::Integer) where {T} - dims = (Int(l),) + dims = (_Int(l),) ref = _wrap(memoryref(m), (l,)) $(Expr(:new, :(Array{T, 1}), :ref, :dims)) end diff --git a/base/arraymath.jl b/base/arraymath.jl index 53a7d132a2c0c..e132cf680911a 100644 --- a/base/arraymath.jl +++ b/base/arraymath.jl @@ -69,7 +69,7 @@ Like [`reverse`](@ref), but operates in-place in `A`. """ reverse!(A::AbstractArray; dims=:) = _reverse!(A, dims) _reverse!(A::AbstractArray{<:Any,N}, ::Colon) where {N} = _reverse!(A, ntuple(identity, Val{N}())) -_reverse!(A, dim::Integer) = _reverse!(A, (Int(dim),)) +_reverse!(A, dim::Integer) = _reverse!(A, (_Int(dim),)) _reverse!(A, dims::NTuple{M,Integer}) where {M} = _reverse!(A, Int.(dims)) function _reverse!(A::AbstractArray{<:Any,N}, dims::NTuple{M,Int}) where {N,M} dims === () && return A # nothing to reverse diff --git a/base/arrayshow.jl b/base/arrayshow.jl index cbdca7b2686c4..2348cf4eea3d9 100644 --- a/base/arrayshow.jl +++ b/base/arrayshow.jl @@ -172,7 +172,7 @@ function print_matrix(io::IO, X::AbstractVecOrMat, end function _print_matrix(io, @nospecialize(X::AbstractVecOrMat), pre, sep, post, hdots, vdots, ddots, hmod, vmod, rowsA, colsA) - hmod, vmod = Int(hmod)::Int, Int(vmod)::Int + hmod, vmod = _Int(hmod), _Int(vmod) ncols, idxlast = length(colsA), last(colsA) if !(get(io, :limit, false)::Bool) screenheight = screenwidth = typemax(Int) diff --git a/base/binaryplatforms.jl b/base/binaryplatforms.jl index 9428c653f3887..5cedb6cfbdc28 100644 --- a/base/binaryplatforms.jl +++ b/base/binaryplatforms.jl @@ -8,6 +8,7 @@ export AbstractPlatform, Platform, HostPlatform, platform_dlext, tags, arch, os, detect_libstdcxx_version, detect_cxxstring_abi, call_abi, wordsize, triplet, select_platform, platforms_match, platform_name import .Libc.Libdl +using .._ConstructingFunctions ### Submodule with information about CPU features include("cpuid.jl") @@ -116,7 +117,7 @@ function Platform(arch::String, os::String; validate_strict::Bool = false, compare_strategies::Dict{String,<:Function} = Dict{String,Function}(), kwargs...) - tags = Dict{String,Any}(String(tag)::String=>tagvalue(value) for (tag, value) in kwargs) + tags = Dict{String,Any}(_String(tag)=>tagvalue(value) for (tag, value) in kwargs) return Platform(arch, os, tags; validate_strict, compare_strategies) end @@ -740,7 +741,7 @@ function Base.parse(::Type{Platform}, triplet::String; validate_strict::Bool = f if isempty(tag_fields) return Pair{String,String}[] end - return map(v -> String(v[1]) => String(v[2]), split.(tag_fields, "+")) + return map(v -> _String(v[1]) => _String(v[2]), split.(tag_fields, "+")) end merge!(tags, Dict(split_tags(m["tags"]))) diff --git a/base/bitarray.jl b/base/bitarray.jl index 5a3469fa7c7a2..039d9fc26a166 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -456,12 +456,12 @@ function copyto!(dest::BitArray, src::BitArray) end function unsafe_copyto!(dest::BitArray, doffs::Integer, src::Union{BitArray,Array}, soffs::Integer, n::Integer) - copy_to_bitarray_chunks!(dest.chunks, Int(doffs), src, Int(soffs), Int(n)) + copy_to_bitarray_chunks!(dest.chunks, _Int(doffs), src, _Int(soffs), _Int(n)) return dest end copyto!(dest::BitArray, doffs::Integer, src::Union{BitArray,Array}, soffs::Integer, n::Integer) = - _copyto_int!(dest, Int(doffs), src, Int(soffs), Int(n)) + _copyto_int!(dest, _Int(doffs), src, _Int(soffs), _Int(n)) function _copyto_int!(dest::BitArray, doffs::Int, src::Union{BitArray,Array}, soffs::Int, n::Int) n == 0 && return dest n < 0 && throw(ArgumentError("Number of elements to copy must be non-negative.")) @@ -811,7 +811,7 @@ function sizehint!(B::BitVector, sz::Integer) return B end -resize!(B::BitVector, n::Integer) = _resize_int!(B, Int(n)) +resize!(B::BitVector, n::Integer) = _resize_int!(B, _Int(n)) function _resize_int!(B::BitVector, n::Int) n0 = length(B) n == n0 && return B @@ -861,7 +861,7 @@ function pushfirst!(B::BitVector, item) for i = length(Bc) : -1 : 2 Bc[i] = (Bc[i] << 1) | (Bc[i-1] >>> 63) end - Bc[1] = UInt64(item) | (Bc[1] << 1) + Bc[1] = _UInt64(item) | (Bc[1] << 1) return B end @@ -888,9 +888,9 @@ function popfirst!(B::BitVector) return item end -insert!(B::BitVector, i::Integer, item) = _insert_int!(B, Int(i), item) +insert!(B::BitVector, i::Integer, item) = _insert_int!(B, _Int(i), item) function _insert_int!(B::BitVector, i::Int, item) - i = Int(i) + i = _Int(i) n = length(B) 1 <= i <= n+1 || throw(BoundsError(B, i)) item = convert(Bool, item) @@ -952,7 +952,7 @@ end function deleteat!(B::BitVector, i::Integer) i isa Bool && depwarn("passing Bool as an index is deprecated", :deleteat!) - i = Int(i) + i = _Int(i) n = length(B) 1 <= i <= n || throw(BoundsError(B, i)) @@ -1005,14 +1005,14 @@ function deleteat!(B::BitVector, inds) end new_l -= 1 if i > q - copy_chunks!(Bc, Int(p), Bc, Int(q), Int(i-q)) + copy_chunks!(Bc, _Int(p), Bc, _Int(q), _Int(i-q)) p += i-q end q = i+1 y = iterate(inds, s) end - q <= n && copy_chunks!(Bc, Int(p), Bc, Int(q), Int(n-q+1)) + q <= n && copy_chunks!(Bc, _Int(p), Bc, _Int(q), _Int(n-q+1)) delta_k = num_bit_chunks(new_l) - length(Bc) delta_k < 0 && _deleteend!(Bc, -delta_k) @@ -1046,14 +1046,14 @@ function deleteat!(B::BitVector, inds::AbstractVector{Bool}) s = y + 1 new_l -= 1 if i > q - copy_chunks!(Bc, Int(p), Bc, Int(q), Int(i-q)) + copy_chunks!(Bc, _Int(p), Bc, _Int(q), _Int(i-q)) p += i - q end q = i + 1 y = findnext(inds, s) end - q <= n && copy_chunks!(Bc, Int(p), Bc, Int(q), Int(n - q + 1)) + q <= n && copy_chunks!(Bc, _Int(p), Bc, _Int(q), _Int(n - q + 1)) delta_k = num_bit_chunks(new_l) - length(Bc) delta_k < 0 && _deleteend!(Bc, -delta_k) @@ -1075,7 +1075,7 @@ function splice!(B::BitVector, i::Integer) # as v = B[i] is enough to do both bounds checking # and Bool check then just pass Int(i) to _deleteat! i isa Bool && depwarn("passing Bool as an index is deprecated", :splice!) - i = Int(i) + i = _Int(i) n = length(B) 1 <= i <= n || throw(BoundsError(B, i)) @@ -1088,7 +1088,7 @@ const _default_bit_splice = BitVector() function splice!(B::BitVector, r::Union{AbstractUnitRange{Int}, Integer}, ins::AbstractArray = _default_bit_splice) r isa Bool && depwarn("passing Bool as an index is deprecated", :splice!) - _splice_int!(B, isa(r, AbstractUnitRange{Int}) ? r : Int(r), ins) + _splice_int!(B, isa(r, AbstractUnitRange{Int}) ? r : _Int(r), ins) end function _splice_int!(B::BitVector, r, ins) @@ -1134,7 +1134,7 @@ function splice!(B::BitVector, r::Union{AbstractUnitRange{Int}, Integer}, ins) Bins = BitVector(undef, length(ins)) i = 1 for x in ins - Bins[i] = Bool(x) + Bins[i] = _Bool(x) i += 1 end return splice!(B, r, Bins) @@ -1325,7 +1325,7 @@ function (<<)(B::BitVector, i::UInt) n = length(B) i == 0 && return copy(B) A = falses(n) - i < n && copy_chunks!(A.chunks, 1, B.chunks, Int(i+1), Int(n-i)) + i < n && copy_chunks!(A.chunks, 1, B.chunks, _Int(i+1), _Int(n-i)) return A end @@ -1333,7 +1333,7 @@ function (>>>)(B::BitVector, i::UInt) n = length(B) i == 0 && return copy(B) A = falses(n) - i < n && copy_chunks!(A.chunks, Int(i+1), B.chunks, 1, Int(n-i)) + i < n && copy_chunks!(A.chunks, _Int(i+1), B.chunks, 1, _Int(n-i)) return A end @@ -1420,9 +1420,9 @@ details and examples. """ (>>>)(B::BitVector, i::Int) = (i >=0 ? B >> unsigned(i) : B << unsigned(-i)) -circshift!(dest::BitVector, src::BitVector, i::Integer) = _circshift_int!(dest, src, Int(i)) +circshift!(dest::BitVector, src::BitVector, i::Integer) = _circshift_int!(dest, src, _Int(i)) function _circshift_int!(dest::BitVector, src::BitVector, i::Int) - i = Int(i) + i = _Int(i) length(dest) == length(src) || throw(ArgumentError("destination and source should be of same size")) n = length(dest) i %= n @@ -1474,7 +1474,7 @@ end # returns the index of the next true element, or nothing if all false function findnext(B::BitArray, start::Integer) - start = Int(start) + start = _Int(start) start > 0 || throw(BoundsError(B, start)) start > length(B) && return nothing unsafe_bitfindnext(B.chunks, start) @@ -1518,14 +1518,14 @@ findfirstnot(B::BitArray) = findnextnot(B,1) function findnext(pred::Fix2{<:Union{typeof(isequal),typeof(==)},Bool}, B::BitArray, start::Integer) v = pred.x - v == false && return findnextnot(B, Int(start)) + v == false && return findnextnot(B, _Int(start)) v == true && return findnext(B, start) return nothing end #findfirst(B::BitArray, v) = findnext(B, 1, v) ## defined in array.jl # returns the index of the first element for which the function returns true -findnext(testf::Function, B::BitArray, start::Integer) = _findnext_int(testf, B, Int(start)) +findnext(testf::Function, B::BitArray, start::Integer) = _findnext_int(testf, B, _Int(start)) function _findnext_int(testf::Function, B::BitArray, start::Int) f0::Bool = testf(false) f1::Bool = testf(true) @@ -1559,14 +1559,14 @@ end # returns the index of the previous true element, or nothing if all false function findprev(B::BitArray, start::Integer) - start = Int(start) + start = _Int(start) start > 0 || return nothing start > length(B) && throw(BoundsError(B, start)) unsafe_bitfindprev(B.chunks, start) end function findprevnot(B::BitArray, start::Int) - start = Int(start) + start = _Int(start) start > 0 || return nothing start > length(B) && throw(BoundsError(B, start)) @@ -1594,14 +1594,14 @@ findlastnot(B::BitArray) = findprevnot(B, length(B)) function findprev(pred::Fix2{<:Union{typeof(isequal),typeof(==)},Bool}, B::BitArray, start::Integer) v = pred.x - v == false && return findprevnot(B, Int(start)) + v == false && return findprevnot(B, _Int(start)) v == true && return findprev(B, start) return nothing end #findlast(B::BitArray, v) = findprev(B, 1, v) ## defined in array.jl # returns the index of the previous element for which the function returns true -findprev(testf::Function, B::BitArray, start::Integer) = _findprev_int(testf, B, Int(start)) +findprev(testf::Function, B::BitArray, start::Integer) = _findprev_int(testf, B, _Int(start)) function _findprev_int(testf::Function, B::BitArray, start::Int) f0::Bool = testf(false) f1::Bool = testf(true) @@ -1908,7 +1908,7 @@ function vcat(A::BitMatrix...) end # general case, specialized for BitArrays and Integers -_cat(dims::Integer, X::Union{BitArray, Bool}...) = _cat(Int(dims)::Int, X...) +_cat(dims::Integer, X::Union{BitArray, Bool}...) = _cat(_Int(dims), X...) function _cat(dims::Int, X::Union{BitArray, Bool}...) dims = Int(dims) catdims = dims2cat(dims) diff --git a/base/broadcast.jl b/base/broadcast.jl index b86baf08ddfe0..a6519eded941f 100644 --- a/base/broadcast.jl +++ b/base/broadcast.jl @@ -11,6 +11,7 @@ using .Base.Cartesian using .Base: Indices, OneTo, tail, to_shape, isoperator, promote_typejoin, promote_typejoin_union, _msk_end, unsafe_bitgetindex, bitcache_chunks, bitcache_size, dumpbitcache, unalias, negate import .Base: copy, copyto!, axes +using .._ConstructingFunctions export broadcast, broadcast!, BroadcastStyle, broadcast_axes, broadcastable, dotview, @__dot__, BroadcastFunction ## Computing the result's axes: deprecated name @@ -593,7 +594,7 @@ Base.@propagate_inbounds _newindex(ax::Tuple{}, I::Tuple{}) = () # If dot-broadcasting were already defined, this would be `ifelse.(keep, I, Idefault)`. @inline newindex(I::CartesianIndex, keep, Idefault) = to_index(_newindex(I.I, keep, Idefault)) @inline newindex(I::CartesianIndex{1}, keep, Idefault) = newindex(I.I[1], keep, Idefault) -@inline newindex(i::Integer, keep::Tuple, idefault) = CartesianIndex(ifelse(keep[1], Int(i), Int(idefault[1])), idefault[2]) +@inline newindex(i::Integer, keep::Tuple, idefault) = CartesianIndex(ifelse(keep[1], _Int(i), _Int(idefault[1])), idefault[2]) @inline newindex(i::Integer, keep::Tuple{Bool}, idefault) = ifelse(keep[1], i, idefault[1]) @inline newindex(i::Integer, keep::Tuple{}, idefault) = CartesianIndex() @inline _newindex(I, keep, Idefault) = @@ -1015,7 +1016,7 @@ end if ndims(bc) == 1 || bitst >= 64 - length(ax1) if ndims(bc) > 1 && bitst != 0 @inbounds @simd for j = bitst:63 - remain |= UInt64(convert(Bool, bc′[i+=1, I])) << (j & 63) + remain |= _UInt64(convert(Bool, bc′[i+=1, I])) << (j & 63) end @inbounds destc[indc+=1] = remain bitst, remain = 0, UInt64(0) @@ -1023,13 +1024,13 @@ end while i <= last(ax1) - 64 z = UInt64(0) @inbounds @simd for j = 0:63 - z |= UInt64(convert(Bool, bc′[i+=1, I])) << (j & 63) + z |= _UInt64(convert(Bool, bc′[i+=1, I])) << (j & 63) end @inbounds destc[indc+=1] = z end end @inbounds @simd for j = i+1:last(ax1) - remain |= UInt64(convert(Bool, bc′[j, I])) << (bitst & 63) + remain |= _UInt64(convert(Bool, bc′[j, I])) << (bitst & 63) bitst += 1 end end @@ -1291,7 +1292,7 @@ function __dot__(x::Expr) tmp = x.head === :(<:) ? :.<: : :.>: Expr(:call, tmp, dotargs...) else - head = String(x.head)::String + head = _String(x.head) if last(head) == '=' && first(head) != '.' || head == "&&" || head == "||" Expr(Symbol('.', head), dotargs...) else diff --git a/base/char.jl b/base/char.jl index 90636a6d9536e..c6ba5d534e8c3 100644 --- a/base/char.jl +++ b/base/char.jl @@ -47,8 +47,8 @@ represents a valid Unicode character. """ Char -@constprop :aggressive (::Type{T})(x::Number) where {T<:AbstractChar} = T(UInt32(x)) -@constprop :aggressive AbstractChar(x::Number) = Char(x) +@constprop :aggressive (::Type{T})(x::Number) where {T<:AbstractChar} = T(_UInt32(x)) +@constprop :aggressive AbstractChar(x::Number) = _Char(x) @constprop :aggressive (::Type{T})(x::AbstractChar) where {T<:Union{Number,AbstractChar}} = T(codepoint(x)) @constprop :aggressive (::Type{T})(x::AbstractChar) where {T<:Union{Int32,Int64}} = codepoint(x) % T (::Type{T})(x::T) where {T<:AbstractChar} = x @@ -189,7 +189,7 @@ end 0 ≤ b ≤ 0x7f ? bitcast(Char, (b % UInt32) << 24) : Char_cold(UInt32(b)) end -convert(::Type{AbstractChar}, x::Number) = Char(x) # default to Char +convert(::Type{AbstractChar}, x::Number) = _Char(x) # default to Char convert(::Type{T}, x::Number) where {T<:AbstractChar} = T(x)::T convert(::Type{T}, x::AbstractChar) where {T<:Number} = T(x)::T convert(::Type{T}, c::AbstractChar) where {T<:AbstractChar} = T(c)::T @@ -225,31 +225,31 @@ hash(x::Char, h::UInt) = hash_finalizer(((bitcast(UInt32, x) + UInt64(0xd4d64234)) << 32) ⊻ UInt64(h)) % UInt # fallbacks: -isless(x::AbstractChar, y::AbstractChar) = isless(Char(x), Char(y)) -==(x::AbstractChar, y::AbstractChar) = Char(x) == Char(y) -hash(x::AbstractChar, h::UInt) = hash(Char(x), h) +isless(x::AbstractChar, y::AbstractChar) = isless(_Char(x), _Char(y)) +==(x::AbstractChar, y::AbstractChar) = _Char(x) == _Char(y) +hash(x::AbstractChar, h::UInt) = hash(_Char(x), h) widen(::Type{T}) where {T<:AbstractChar} = T -@inline -(x::AbstractChar, y::AbstractChar) = Int(x) - Int(y) +@inline -(x::AbstractChar, y::AbstractChar) = _Int(x) - _Int(y) @inline function -(x::T, y::Integer) where {T<:AbstractChar} if x isa Char u = Int32((bitcast(UInt32, x) >> 24) % Int8) if u >= 0 # inline the runtime fast path z = u - y - return 0 <= z < 0x80 ? bitcast(Char, (z % UInt32) << 24) : Char(UInt32(z)) + return 0 <= z < 0x80 ? bitcast(Char, (z % UInt32) << 24) : Char(_UInt32(z)) end end - return T(Int32(x) - Int32(y)) + return T(_Int32(x) - _Int32(y)) end @inline function +(x::T, y::Integer) where {T<:AbstractChar} if x isa Char u = Int32((bitcast(UInt32, x) >> 24) % Int8) if u >= 0 # inline the runtime fast path z = u + y - return 0 <= z < 0x80 ? bitcast(Char, (z % UInt32) << 24) : Char(UInt32(z)) + return 0 <= z < 0x80 ? bitcast(Char, (z % UInt32) << 24) : Char(_UInt32(z)) end end - return T(Int32(x) + Int32(y)) + return T(_Int32(x) + _Int32(y)) end @inline +(x::Integer, y::AbstractChar) = y + x @@ -257,7 +257,7 @@ end # (Packages may implement other IO subtypes to specify different encodings.) # In contrast, `write(io, c)` outputs a `c` in an encoding determined by typeof(c). print(io::IO, c::Char) = (write(io, c); nothing) -print(io::IO, c::AbstractChar) = print(io, Char(c)) # fallback: convert to output UTF-8 +print(io::IO, c::AbstractChar) = print(io, _Char(c)) # fallback: convert to output UTF-8 const hex_chars = UInt8['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', diff --git a/base/client.jl b/base/client.jl index 8ff97328a74cb..ddb7d5377a04f 100644 --- a/base/client.jl +++ b/base/client.jl @@ -93,7 +93,7 @@ function scrub_repl_backtrace(bt) if bt !== nothing && !(bt isa Vector{Any}) # ignore our sentinel value types bt = bt isa Vector{StackFrame} ? copy(bt) : stacktrace(bt) # remove REPL-related frames from interactive printing - eval_ind = findlast(frame -> !frame.from_c && startswith(String(frame.func), "__repl_entry"), bt) + eval_ind = findlast(frame -> !frame.from_c && startswith(_String(frame.func), "__repl_entry"), bt) eval_ind === nothing || deleteat!(bt, eval_ind:length(bt)) end return bt @@ -200,7 +200,7 @@ function parse_input_line(s::String; filename::String="none", depwarn=true) end return ex end -parse_input_line(s::AbstractString) = parse_input_line(String(s)) +parse_input_line(s::AbstractString) = parse_input_line(_String(s)) # detect the reason which caused an :incomplete expression # from the error message diff --git a/base/cmd.jl b/base/cmd.jl index a67cb317843b8..8dec5159400b4 100644 --- a/base/cmd.jl +++ b/base/cmd.jl @@ -241,7 +241,7 @@ function cstr(s) if Base.containsnul(s) throw(ArgumentError("strings containing NUL cannot be passed to spawned processes")) end - return String(s)::String + return _String(s) end # convert various env representations into an array of "key=val" strings @@ -507,6 +507,6 @@ Process(`echo 1`, ProcessExited(0)) ``` """ macro cmd(str::String) - cmd_ex = shell_parse(str, special=shell_special, filename=String(__source__.file))[1] + cmd_ex = shell_parse(str, special=shell_special, filename=_String(__source__.file))[1] return :(cmd_gen($(esc(cmd_ex)))) end diff --git a/base/deprecated.jl b/base/deprecated.jl index 0ee6b6b790837..6ed5861df6bb3 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -276,7 +276,7 @@ end Core # TODO: Is it reasonable to attribute callers without linfo to Core? end end, - _file=String(caller.file), + _file=_String(caller.file), _line=caller.line, _id=(frame,funcsym), _group=:depwarn, diff --git a/base/dict.jl b/base/dict.jl index 4021401f89ce3..2d1d208d8ccba 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -89,7 +89,7 @@ mutable struct Dict{K,V} <: AbstractDict{K,V} end function Dict{K,V}(kv) where V where K h = Dict{K,V}() - haslength(kv) && sizehint!(h, Int(length(kv))::Int) + haslength(kv) && sizehint!(h, _Int(length(kv))) for (k,v) in kv h[k] = v end @@ -125,7 +125,7 @@ _shorthash7(hsh::UInt) = (hsh >> (8sizeof(UInt)-7))%UInt8 | 0x80 # idx - optimal position in the hash table # sh::UInt8 - short hash (7 highest hash bits) function hashindex(key, sz::Integer) - sz = Int(sz)::Int + sz = _Int(sz) hsh = hash(key)::UInt idx = ((hsh % Int) & (sz-1)) + 1 return idx, _shorthash7(hsh) @@ -192,7 +192,7 @@ end end function sizehint!(d::Dict{T}, newsz::Integer; shrink::Bool=true) where T - newsz = Int(newsz)::Int + newsz = _Int(newsz) oldsz = length(d.slots) # limit new element count to max_values of the key type newsz = min(max(newsz, length(d)), max_values(T)::Int) diff --git a/base/docs/Docs.jl b/base/docs/Docs.jl index 13a5b35a115da..402aee6edf2eb 100644 --- a/base/docs/Docs.jl +++ b/base/docs/Docs.jl @@ -68,6 +68,7 @@ include("bindings.jl") import .Base.Meta: quot, isexpr, unblock, unescape, uncurly import .Base: Callable, with_output_color using .Base: RefValue, mapany +using .._ConstructingFunctions import ..CoreDocs: lazy_iterpolate export doc, hasdoc, undocumented_names @@ -337,7 +338,7 @@ Fields that may be included in the returned `Dict`: function metadata(__source__, __module__, expr, ismodule) args = [] # Filename and linenumber of the docstring. - __file__ = isa(__source__.file, Symbol) ? String(__source__.file) : "" + __file__ = isa(__source__.file, Symbol) ? _String(__source__.file) : "" push!(args, Pair(:path, __file__)) push!(args, Pair(:linenumber, __source__.line)) # Module in which the docstring is defined. diff --git a/base/env.jl b/base/env.jl index 5472456e22885..79b39765a0854 100644 --- a/base/env.jl +++ b/base/env.jl @@ -181,7 +181,7 @@ if Sys.iswindows() isempty(s) && return s LOCALE_INVARIANT = 0x0000007f LCMAP_UPPERCASE = 0x00000200 - ws = transcode(UInt16, String(s)) + ws = transcode(UInt16, _String(s)) result = ccall(:LCMapStringW, stdcall, Cint, (UInt32, UInt32, Ptr{UInt16}, Cint, Ptr{UInt16}, Cint), LOCALE_INVARIANT, LCMAP_UPPERCASE, ws, length(ws), ws, length(ws)) systemerror(:LCMapStringW, iszero(result)) diff --git a/base/file.jl b/base/file.jl index 24a21396721d3..ec73a772f1e23 100644 --- a/base/file.jl +++ b/base/file.jl @@ -371,7 +371,7 @@ function cptree(src::String, dst::String; force::Bool=false, end end cptree(src::AbstractString, dst::AbstractString; kwargs...) = - cptree(String(src)::String, String(dst)::String; kwargs...) + cptree(_String(src), _String(dst); kwargs...) """ cp(src::AbstractString, dst::AbstractString; force::Bool=false, follow_symlinks::Bool=false) @@ -1240,7 +1240,7 @@ function sendfile(src::AbstractString, dst::AbstractString) dst_open = true bytes = filesize(stat(src_file)) - sendfile(dst_file, src_file, Int64(0), Int(bytes)) + sendfile(dst_file, src_file, Int64(0), _Int(bytes)) finally if src_open && isopen(src_file) close(src_file) @@ -1436,8 +1436,8 @@ struct DiskStat end function Base.getproperty(stats::DiskStat, field::Symbol) - total = Int64(getfield(stats, :bsize) * getfield(stats, :blocks)) - available = Int64(getfield(stats, :bsize) * getfield(stats, :bavail)) + total = _Int64(getfield(stats, :bsize) * getfield(stats, :blocks)) + available = _Int64(getfield(stats, :bsize) * getfield(stats, :bavail)) field === :total && return total field === :available && return available field === :used && return total - available diff --git a/base/filesystem.jl b/base/filesystem.jl index a5f1327b5cff1..ea2e6ae7a99aa 100644 --- a/base/filesystem.jl +++ b/base/filesystem.jl @@ -145,6 +145,8 @@ import .Base: import .Base.RefValue +using .._ConstructingFunctions + if Sys.iswindows() import .Base: cwstring end @@ -390,7 +392,7 @@ function isexecutable(path::String) X_OK = 0x01 return ccall(:jl_fs_access, Cint, (Cstring, Cint), path, X_OK) == 0 end -isexecutable(path::AbstractString) = isexecutable(String(path)) +isexecutable(path::AbstractString) = isexecutable(_String(path)) """ isreadable(path::String) @@ -417,7 +419,7 @@ function isreadable(path::String) R_OK = 0x04 return ccall(:jl_fs_access, Cint, (Cstring, Cint), path, R_OK) == 0 end -isreadable(path::AbstractString) = isreadable(String(path)) +isreadable(path::AbstractString) = isreadable(_String(path)) """ iswritable(path::String) @@ -444,7 +446,7 @@ function iswritable(path::String) W_OK = 0x02 return ccall(:jl_fs_access, Cint, (Cstring, Cint), path, W_OK) == 0 end -iswritable(path::AbstractString) = iswritable(String(path)) +iswritable(path::AbstractString) = iswritable(_String(path)) end diff --git a/base/flfrontend.jl b/base/flfrontend.jl index 86b291cf7328b..ede02ad59edb8 100644 --- a/base/flfrontend.jl +++ b/base/flfrontend.jl @@ -15,7 +15,7 @@ function fl_parse(text::Union{Core.SimpleVector,String}, end function fl_parse(text::AbstractString, filename::AbstractString, lineno, offset, options) - fl_parse(String(text), String(filename), lineno, offset, options) + fl_parse(_String(text), _String(filename), lineno, offset, options) end function fl_lower(ex, mod::Module, filename::Union{String,Ptr{UInt8}}="none", diff --git a/base/float.jl b/base/float.jl index d5bfd044cf3b0..d1fad001596cd 100644 --- a/base/float.jl +++ b/base/float.jl @@ -164,7 +164,7 @@ function exponent_raw_max end """ IEEE 754 definition of the minimum exponent. """ -ieee754_exponent_min(::Type{T}) where {T<:IEEEFloat} = Int(1 - exponent_max(T))::Int +ieee754_exponent_min(::Type{T}) where {T<:IEEEFloat} = _Int(1 - exponent_max(T)) exponent_min(::Type{Float16}) = ieee754_exponent_min(Float16) exponent_min(::Type{Float32}) = ieee754_exponent_min(Float32) @@ -802,7 +802,7 @@ _precision_with_base_2(::Type{Float64}) = 53 function _precision(x, base::Integer) base > 1 || throw(DomainError(base, "`base` cannot be less than 2.")) p = _precision_with_base_2(x) - return base == 2 ? Int(p) : floor(Int, p / log2(base)) + return base == 2 ? _Int(p) : floor(Int, p / log2(base)) end precision(::Type{T}; base::Integer=2) where {T<:AbstractFloat} = _precision(T, base) precision(::T; base::Integer=2) where {T<:AbstractFloat} = precision(T; base) diff --git a/base/gmp.jl b/base/gmp.jl index e4d9294766aaa..9d2c0a7fd308b 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -15,6 +15,8 @@ import .Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), xor, import Core: Signed, Float16, Float32, Float64 +using .._ConstructingFunctions + if Clong == Int32 const ClongMax = Union{Int8, Int16, Int32} const CulongMax = Union{UInt8, UInt16, UInt32} @@ -288,9 +290,9 @@ Signed(x::BigInt) = x function tryparse_internal(::Type{BigInt}, s::AbstractString, startpos::Int, endpos::Int, base_::Integer, raise::Bool) # don't make a copy in the common case where we are parsing a whole String - bstr = startpos == firstindex(s) && endpos == lastindex(s) ? String(s) : String(SubString(s,startpos,endpos)) + bstr = startpos == firstindex(s) && endpos == lastindex(s) ? _String(s) : _String(SubString(s,startpos,endpos)) - sgn, base, i = Base.parseint_preamble(true,Int(base_),bstr,firstindex(bstr),lastindex(bstr)) + sgn, base, i = Base.parseint_preamble(true,_Int(base_),bstr,firstindex(bstr),lastindex(bstr)) if !(2 <= base <= 62) raise && throw(ArgumentError("invalid base: base must be 2 ≤ base ≤ 62, got $base")) return nothing @@ -425,7 +427,7 @@ function Float64(x::BigInt, ::RoundingMode{:Nearest}) y += n > (precision(Float64) - 32) ? 0 : (unsafe_load(x.d, xsize-2) >> (10+n)) end y = (y + 1) >> 1 # round, ties up - y &= ~UInt64(trailing_zeros(x) == (n-54 + (xsize-1)*BITS_PER_LIMB)) # fix last bit to round to even + y &= ~_UInt64(trailing_zeros(x) == (n-54 + (xsize-1)*BITS_PER_LIMB)) # fix last bit to round to even d = ((n+1021) % UInt64) << 52 z = reinterpret(Float64, d+y) z = ldexp(z, (xsize-1)*BITS_PER_LIMB) @@ -447,7 +449,7 @@ function Float32(x::BigInt, ::RoundingMode{:Nearest}) y = (y1 >> (n - (precision(Float32)+1))) % UInt32 y += (n > precision(Float32) ? 0 : unsafe_load(x.d, xsize-1) >> (BITS_PER_LIMB - (25-n))) % UInt32 y = (y + one(UInt32)) >> 1 # round, ties up - y &= ~UInt32(trailing_zeros(x) == (n-25 + (xsize-1)*BITS_PER_LIMB)) # fix last bit to round to even + y &= ~_UInt32(trailing_zeros(x) == (n-25 + (xsize-1)*BITS_PER_LIMB)) # fix last bit to round to even d = ((n+125) % UInt32) << 23 z = reinterpret(Float32, d+y) z = ldexp(z, (xsize-1)*BITS_PER_LIMB) @@ -465,7 +467,7 @@ function Float16(x::BigInt, ::RoundingMode{:Nearest}) # load first 12(1 + 10 bits for fraction + 1 for rounding) y = (y1 >> (n - (precision(Float16)+1))) % UInt16 y = (y + one(UInt16)) >> 1 # round, ties up - y &= ~UInt16(trailing_zeros(x) == (n-12)) # fix last bit to round to even + y &= ~_UInt16(trailing_zeros(x) == (n-12)) # fix last bit to round to even d = ((n+13) % UInt16) << 10 z = reinterpret(Float16, d+y) end @@ -749,7 +751,7 @@ end show(io::IO, x::BigInt) = print(io, string(x)) function string(n::BigInt; base::Integer = 10, pad::Integer = 1) - base < 0 && return Base._base(Int(base), n, pad, (base>0) & (n.size<0)) + base < 0 && return Base._base(_Int(base), n, pad, (base>0) & (n.size<0)) 2 <= base <= 62 || throw(ArgumentError("base must be 2 ≤ base ≤ 62, got $base")) iszero(n) && pad < 1 && return "" nd1 = ndigits(n, base=base) @@ -802,7 +804,7 @@ function ndigits0zpb(x::BigInt, b::Integer) n = MPZ.sizeinbase(x, 2) lb = log2(b) # assumed accurate to <1ulp (true for openlibm) q,r = divrem(n,lb) - iq = Int(q) + iq = _Int(q) maxerr = q*eps(lb) # maximum error in remainder if r-1.0 < maxerr abs(x) >= big(b)^iq ? iq+1 : iq diff --git a/base/hashing.jl b/base/hashing.jl index 30a5e28447809..bab151faf30d5 100644 --- a/base/hashing.jl +++ b/base/hashing.jl @@ -81,7 +81,7 @@ function _hash_integer( u = u0 # always left-pad to full byte - buflen = UInt(max(cld(top_set_bit(u), 8), 1)) + buflen = _UInt(max(cld(top_set_bit(u), 8), 1)) seed = seed ⊻ hash_mix(seed ⊻ secret[3], secret[2]) a = zero(UInt64) @@ -92,14 +92,14 @@ function _hash_integer( if buflen ≥ 4 seed ⊻= buflen if buflen ≥ 8 - a = UInt64(u % UInt64) - b = UInt64((u >>> (8 * (buflen - 8))) % UInt64) + a = (u % UInt64)::UInt64 + b = ((u >>> (8 * (buflen - 8))) % UInt64)::UInt64 else - a = UInt64(u % UInt32) - b = UInt64((u >>> (8 * (buflen - 4))) % UInt32) + a = UInt64((u % UInt32)::UInt32) + b = UInt64(((u >>> (8 * (buflen - 4))) % UInt32)::UInt32) end else # buflen > 0 - b0 = u % UInt8 + b0 = (u % UInt8)::UInt8 b1 = (u >>> (8 * div(buflen, 2))) % UInt8 b2 = (u >>> (8 * (buflen - 1))) % UInt8 a = (UInt64(b0) << 45) | UInt64(b2) @@ -213,8 +213,8 @@ function hash(x::Real, h::UInt) # 2^-1074 is the minimum Float64 so if the power is smaller, not a Float64 if -1074 <= pow if 0 <= pow # if pow is non-negative, it is an integer - left <= 63 && return hash(Int64(num) << Int(pow), h) - left <= 64 && !signbit(num) && return hash(UInt64(num) << Int(pow), h) + left <= 63 && return hash(_Int64(num) << _Int(pow), h) + left <= 64 && !signbit(num) && return hash(_UInt64(num) << _Int(pow), h) end # typemin(Int64) handled by Float64 case # 2^1024 is the maximum Float64 so if the power is greater, not a Float64 # Float64s only have 53 mantisa bits (including implicit bit) @@ -351,7 +351,7 @@ end result = zero(UInt64) for i in 0:7 byte = @inbounds arr[idx + i] - result |= UInt64(byte) << (8 * i) + result |= _UInt64(byte) << (8 * i) end return result end @@ -360,7 +360,7 @@ end result = zero(UInt32) for i in 0:3 byte = @inbounds arr[idx + i] - result |= UInt32(byte) << (8 * i) + result |= _UInt32(byte) << (8 * i) end return result end @@ -372,7 +372,7 @@ end ) # Adapted with gratitude from [rapidhash](https://github.com/Nicoshev/rapidhash) n = length(arr) - buflen = UInt64(n) + buflen = _UInt64(n) seed = seed ⊻ hash_mix(seed ⊻ secret[3], secret[2]) firstidx = firstindex(arr) @@ -387,12 +387,12 @@ end a = load_le_array(UInt64, arr, firstidx) b = load_le_array(UInt64, arr, firstidx + n - 8) else - a = UInt64(load_le_array(UInt32, arr, firstidx)) - b = UInt64(load_le_array(UInt32, arr, firstidx + n - 4)) + a = _UInt64(load_le_array(UInt32, arr, firstidx)) + b = _UInt64(load_le_array(UInt32, arr, firstidx + n - 4)) end elseif buflen > 0 - a = (UInt64(@inbounds arr[firstidx]) << 45) | UInt64(@inbounds arr[firstidx + n - 1]) - b = UInt64(@inbounds arr[firstidx + div(n, 2)]) + a = (_UInt64(@inbounds arr[firstidx]) << 45) | _UInt64(@inbounds arr[firstidx + n - 1]) + b = _UInt64(@inbounds arr[firstidx + div(n, 2)]) end else pos = 0 @@ -456,7 +456,7 @@ end next_result = iterate(iter, state) next_result === nothing && return value, state, UInt8(i - 1) byte, state = next_result - value |= UInt64(byte) << ((i - 1) * 8) + value |= _UInt64(byte) << ((i - 1) * 8) end return value, state, 0x8 end @@ -465,7 +465,7 @@ end next_result = iterate(iter) next_result === nothing && return nothing byte, state = next_result - value = UInt64(byte) + value = _UInt64(byte) @nexprs 7 i -> begin next_result = iterate(iter, state) next_result === nothing && return value, state, UInt8(i) @@ -588,11 +588,11 @@ end a = l0 b = t1 else - a = UInt64(l0 % UInt32) - b = UInt64((l0 >>> ((0x8 * (bytes_chunk - 0x4)) % 0x3f)) % UInt32) + a = UInt64((l0 % UInt32)::UInt32) + b = UInt64(((l0 >>> ((0x8 * (bytes_chunk - 0x4)) % 0x3f)) % UInt32)::UInt32) end elseif bytes_chunk > 0x0 - b0 = l0 % UInt8 + b0 = (l0 % UInt8)::UInt8 b1 = (l0 >>> ((0x8 * div(bytes_chunk, 0x2)) % 0x3f)) % UInt8 b2 = (l0 >>> ((0x8 * (bytes_chunk - 0x1)) % 0x3f)) % UInt8 a = (UInt64(b0) << 45) | UInt64(b2) diff --git a/base/io.jl b/base/io.jl index 71e4c404dfeac..a8d9982e45686 100644 --- a/base/io.jl +++ b/base/io.jl @@ -813,7 +813,7 @@ unsafe_write(s::IO, p::Ptr, n::Integer) = unsafe_write(s, convert(Ptr{UInt8}, p) function write(s::IO, x::Ref{T}) where {T} x isa Ptr && error("write cannot copy from a Ptr") if isbitstype(T) - Int(unsafe_write(s, x, Core.sizeof(T))) + _Int(unsafe_write(s, x, Core.sizeof(T))) else write(s, x[]) end @@ -1112,7 +1112,7 @@ function copyuntil(out::IO, io::IO, target::AbstractString; keep::Bool=false) end # convert String to a utf8-byte-iterator if !(target isa String) && !(target isa SubString{String}) - target = String(target) + target = _String(target) end target = codeunits(target)::AbstractVector return copyuntil(out, io, target, keep=keep) @@ -1304,7 +1304,7 @@ function iterate(r::Iterators.Reverse{<:EachLine}, state) # extract the string from chunks[ichunk][inewline+1] to chunks[jchunk][jnewline] if ichunk == jchunk # common case: current and previous newline in same chunk chunk = chunks[ichunk] - s = String(view(chunk, inewline+1:_stripnewline(r.itr.keep, jnewline, chunk))) + s = _String(view(chunk, inewline+1:_stripnewline(r.itr.keep, jnewline, chunk))) else buf = IOBuffer(sizehint=max(128, length(chunks[ichunk])-inewline+jnewline)) write(buf, view(chunks[ichunk], inewline+1:length(chunks[ichunk]))) @@ -1533,7 +1533,7 @@ julia> rm("my_file.txt") """ function countlines(io::IO; eol::AbstractChar='\n') isascii(eol) || throw(ArgumentError("only ASCII line terminators are supported")) - aeol = UInt8(eol) + aeol = _UInt8(eol) a = Vector{UInt8}(undef, 8192) nl = nb = 0 while !eof(io) diff --git a/base/iobuffer.jl b/base/iobuffer.jl index dd3b757c0e3f0..2d5064c06a54f 100644 --- a/base/iobuffer.jl +++ b/base/iobuffer.jl @@ -102,7 +102,7 @@ mutable struct GenericIOBuffer{T<:AbstractVector{UInt8}} <: IO append::Bool, maxsize::Int, ) where T<:AbstractVector{UInt8} - len = Int(length(data))::Int + len = _Int(length(data)) return new{T}(data, false, readable, writable, seekable, append, len, maxsize, 1, 0, -1) end end @@ -117,8 +117,8 @@ function GenericIOBuffer{T}( truncate::Bool, ) where T<:AbstractVector{UInt8} require_one_based_indexing(data) - mz = Int(maxsize)::Int - len = Int(length(data))::Int + mz = _Int(maxsize) + len = _Int(length(data)) if !truncate && mz < len throw(ArgumentError("maxsize must not be smaller than data length")) end @@ -145,7 +145,7 @@ function GenericIOBuffer(data::Vector{UInt8}, readable::Bool, writable::Bool, se offset = memoryrefoffset(ref) - 1 # The user may pass a vector of length <= maxsize, but where the underlying memory # is larger than maxsize. Don't throw an error in that case. - mz = Int(maxsize)::Int + mz = _Int(maxsize) if !truncate && mz < length(data) throw(ArgumentError("maxsize must not be smaller than data length")) end @@ -250,13 +250,13 @@ function IOBuffer(; maxsize::Integer=typemax(Int), sizehint::Union{Integer,Nothing}=nothing, ) - mz = Int(maxsize)::Int + mz = _Int(maxsize) if mz < 0 throw(ArgumentError("negative maxsize")) end size = if sizehint !== nothing # Allow negative sizehint, just like `sizehint!` does - min(mz, max(0, Int(sizehint)::Int)) + min(mz, max(0, _Int(sizehint))) else min(mz, 32) end @@ -561,7 +561,7 @@ function truncate(io::GenericIOBuffer, n::Integer) io.seekable || throw(ArgumentError("truncate failed, IOBuffer is not seekable")) n < 0 && throw(ArgumentError("truncate failed, n bytes must be ≥ 0, got $n")) n > io.maxsize && throw(ArgumentError("truncate failed, $(n) bytes is exceeds IOBuffer maxsize $(io.maxsize)")) - n = Int(n)::Int + n = _Int(n) offset = get_offset(io) current_size = io.size - offset if io.reinit @@ -855,7 +855,7 @@ function takestring!(io::IOBuffer) end # Fallback methods -takestring!(io::GenericIOBuffer) = String(take!(io)) +takestring!(io::GenericIOBuffer) = _String(take!(io)) """ _unsafe_take!(io::IOBuffer) @@ -898,7 +898,7 @@ function unsafe_write(to::GenericIOBuffer, p::Ptr{UInt8}, nb::UInt) append = to.append ptr = append ? size+1 : to.ptr data = to.data - to_write = min(nb, (min(Int(length(data))::Int, to.maxsize + get_offset(to)) - ptr + 1) % UInt) % Int + to_write = min(nb, (min(_Int(length(data)), to.maxsize + get_offset(to)) - ptr + 1) % UInt) % Int # Dispatch based on the type of data, to possibly allow using memcpy _unsafe_write(data, p, ptr, to_write % UInt) # Update to.size only if the ptr has advanced to higher than @@ -953,7 +953,7 @@ end return sizeof(UInt8) end -readbytes!(io::GenericIOBuffer, b::MutableDenseArrayType{UInt8}, nb=length(b)) = readbytes!(io, b, Int(nb)) +readbytes!(io::GenericIOBuffer, b::MutableDenseArrayType{UInt8}, nb=length(b)) = readbytes!(io, b, _Int(nb)) function readbytes!(io::GenericIOBuffer, b::MutableDenseArrayType{UInt8}, nb::Int) io.readable || _throw_not_readable() diff --git a/base/iterators.jl b/base/iterators.jl index 5909608709e36..75fe28e50eb80 100644 --- a/base/iterators.jl +++ b/base/iterators.jl @@ -32,6 +32,9 @@ import Base: getindex, setindex!, get, iterate, popfirst!, isdone, peek, intersect +using Base: _ConstructingFunctions +using ._ConstructingFunctions + export enumerate, zip, rest, countfrom, take, drop, takewhile, dropwhile, cycle, repeated, product, flatten, flatmap, partition, nth, findeach public accumulate, filter, map, peel, reverse, Stateful @@ -769,8 +772,8 @@ julia> collect(Iterators.take(a,3)) 5 ``` """ -take(xs, n::Integer) = Take(xs, Int(n)) -take(xs::Take, n::Integer) = Take(xs.xs, min(Int(n), xs.n)) +take(xs, n::Integer) = Take(xs, _Int(n)) +take(xs::Take, n::Integer) = Take(xs.xs, min(_Int(n), xs.n)) eltype(::Type{Take{I}}) where {I} = eltype(I) IteratorEltype(::Type{Take{I}}) where {I} = IteratorEltype(I) @@ -825,9 +828,9 @@ julia> collect(Iterators.drop(a,4)) 11 ``` """ -drop(xs, n::Integer) = Drop(xs, Int(n)) -drop(xs::Take, n::Integer) = Take(drop(xs.xs, Int(n)), max(0, xs.n - Int(n))) -drop(xs::Drop, n::Integer) = Drop(xs.xs, Int(n) + xs.n) +drop(xs, n::Integer) = Drop(xs, _Int(n)) +drop(xs::Take, n::Integer) = Take(drop(xs.xs, _Int(n)), max(0, xs.n - _Int(n))) +drop(xs::Drop, n::Integer) = Drop(xs.xs, _Int(n) + xs.n) eltype(::Type{Drop{I}}) where {I} = eltype(I) IteratorEltype(::Type{Drop{I}}) where {I} = IteratorEltype(I) @@ -1065,7 +1068,7 @@ julia> Iterators.cycle([1 2], 4) |> collect |> println [1, 2, 1, 2, 1, 2, 1, 2] ``` """ -repeated(x, n::Integer) = take(repeated(x), Int(n)) +repeated(x, n::Integer) = take(repeated(x), _Int(n)) eltype(::Type{Repeated{O}}) where {O} = O @@ -1382,7 +1385,7 @@ julia> collect(Iterators.partition([1,2,3,4,5], 2)) ``` """ function partition(c, n::Integer) n < 1 && throw(ArgumentError("cannot create partitions of length $n")) - return PartitionIterator(c, Int(n)) + return PartitionIterator(c, _Int(n)) end struct PartitionIterator{T} diff --git a/base/loading.jl b/base/loading.jl index 2da72b7828ea0..6a0533beb6316 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -45,7 +45,7 @@ elseif Sys.isapple() # getattrpath(path, &attr_list, &buf, sizeof(buf), FSOPT_NOFOLLOW); function isfile_casesensitive(path) isaccessiblefile(path) || return false - path_basename = String(basename(path)) + path_basename = _String(basename(path)) local casepreserved_basename header_size = 12 buf = Vector{UInt8}(undef, length(path_basename) + header_size + 1) @@ -243,7 +243,7 @@ function get_updated_dict(p::TOML.Parser, f::CachedTOMLDict) f.mtime = s.mtime f.size = s.size f.hash = new_hash - TOML.reinit!(p, String(content); filepath=f.path) + TOML.reinit!(p, _String(content); filepath=f.path) return f.d = TOML.parse(p) end end @@ -1759,9 +1759,9 @@ function parse_image_target(io::IO) feature_en = read(io, 4*nfeature) feature_dis = read(io, 4*nfeature) name_len = read(io, Int32) - name = String(read(io, name_len)) + name = _String(read(io, name_len)) ext_features_len = read(io, Int32) - ext_features = String(read(io, ext_features_len)) + ext_features = _String(read(io, ext_features_len)) ImageTarget(name, flags, ext_features, feature_en, feature_dis) end @@ -1937,7 +1937,7 @@ function _tryrequire_from_serialized(modkey::PkgId, build_id::UInt128) try modpath = locate_package(modkey) isnothing(modpath) && error("Cannot locate source for $(repr("text/plain", modkey))") - modpath = String(modpath)::String + modpath = _String(modpath) set_pkgorigin_version_path(modkey, modpath) loaded = _require_search_from_serialized(modkey, modpath, build_id, true) finally @@ -2263,7 +2263,7 @@ function _include_dependency!(dep_list::Vector{Any}, track_dependencies::Bool, if track_content hash = (isdir(path) ? _crc32c(join(readdir(path))) : open(_crc32c, path, "r"))::UInt32 # use mtime=-1.0 here so that fsize==0 && mtime==0.0 corresponds to a missing include_dependency - push!(dep_list, (mod, path, UInt64(filesize(path)), hash, -1.0)) + push!(dep_list, (mod, path, _UInt64(filesize(path)), hash, -1.0)) else push!(dep_list, (mod, path, UInt64(0), UInt32(0), mtime(path))) end @@ -3409,9 +3409,9 @@ function read_module_list(f::IO, has_buildid_hi::Bool) while true n = read(f, Int32) n == 0 && break - sym = String(read(f, n)) # module name + sym = _String(read(f, n)) # module name uuid = UUID((read(f, UInt64), read(f, UInt64))) # pkg UUID - build_id_hi = UInt128(has_buildid_hi ? read(f, UInt64) : UInt64(0)) << 64 + build_id_hi = _UInt128(has_buildid_hi ? read(f, UInt64) : UInt64(0)) << 64 build_id = (build_id_hi | read(f, UInt64)) # build id (checksum + time - not a UUID) push!(modules, PkgId(uuid, sym) => build_id) end @@ -3421,7 +3421,7 @@ end function _parse_cache_header(f::IO, cachefile::AbstractString) flags = read(f, UInt8) modules = read_module_list(f, false) - totbytes = Int64(read(f, UInt64)) # total bytes for file dependencies + preferences + totbytes = _Int64(read(f, UInt64)) # total bytes for file dependencies + preferences # read the list of requirements # and split the list into include and requires statements includes = CacheHeaderIncludes[] @@ -3432,7 +3432,7 @@ function _parse_cache_header(f::IO, cachefile::AbstractString) if n2 == 0 break end - depname = String(read(f, n2)) + depname = _String(read(f, n2)) totbytes -= n2 fsize = read(f, UInt64) totbytes -= 8 @@ -3453,7 +3453,7 @@ function _parse_cache_header(f::IO, cachefile::AbstractString) if n1 == 0 break end - push!(modpath, String(read(f, n1))) + push!(modpath, _String(read(f, n1))) totbytes -= n1 end end @@ -3470,7 +3470,7 @@ function _parse_cache_header(f::IO, cachefile::AbstractString) if n2 == 0 break end - push!(prefs, String(read(f, n2))) + push!(prefs, _String(read(f, n2))) totbytes -= n2 end prefs_hash = read(f, UInt64) @@ -3617,7 +3617,7 @@ function _read_dependency_src(io::IO, filename::AbstractString, includes::Vector while !eof(io) filenamelen = read(io, Int32) filenamelen == 0 && break - depotfn = String(read(io, filenamelen)) + depotfn = _String(read(io, filenamelen)) len = read(io, UInt64) fn = if !startswith(depotfn, string("@depot", Filesystem.pathsep())) depotfn @@ -3629,7 +3629,7 @@ function _read_dependency_src(io::IO, filename::AbstractString, includes::Vector isnothing(idx) ? depotfn : includes[idx].filename end if fn == filename - return String(read(io, len)) + return _String(read(io, len)) end seek(io, position(io) + len) end @@ -3653,7 +3653,7 @@ function srctext_files(f::IO, srctextpos::Int64, includes::Vector{CacheHeaderInc while !eof(f) filenamelen = read(f, Int32) filenamelen == 0 && break - filename = String(read(f, filenamelen)) + filename = _String(read(f, filenamelen)) len = read(f, UInt64) push!(files, filename) seek(f, position(f) + len) @@ -4023,7 +4023,7 @@ end return true end id_build = id.second - id_build = (UInt128(checksum) << 64) | (id_build % UInt64) + id_build = (_UInt128(checksum) << 64) | (id_build % UInt64) if build_id != UInt128(0) if id_build != build_id @debug "Ignoring cache file $cachefile for $modkey ($(UUID(id_build))) since it does not provide desired build_id ($((UUID(build_id))))" @@ -4079,7 +4079,7 @@ end for (req_key, req_build_id) in _concrete_dependencies build_id = get(modules, req_key, UInt64(0)) if build_id !== UInt64(0) - build_id |= UInt128(checksum) << 64 + build_id |= _UInt128(checksum) << 64 if build_id === req_build_id stalecheck = false break diff --git a/base/logging/ConsoleLogger.jl b/base/logging/ConsoleLogger.jl index 6521bf49b3e66..7b9d165359bdf 100644 --- a/base/logging/ConsoleLogger.jl +++ b/base/logging/ConsoleLogger.jl @@ -114,7 +114,7 @@ function handle_message(logger::ConsoleLogger, level::LogLevel, message, _module maxlog = get(kwargs, :maxlog, nothing) if maxlog isa Core.BuiltinInts @lock logger.lock begin - remaining = get!(logger.message_limits, id, Int(maxlog)::Int) + remaining = get!(logger.message_limits, id, _Int(maxlog)) remaining == 0 && return logger.message_limits[id] = remaining - 1 end @@ -125,7 +125,7 @@ function handle_message(logger::ConsoleLogger, level::LogLevel, message, _module # and reduce the risk of resulting method invalidations. message = string(message) msglines = if Base._isannotated(message) && !isempty(Base.annotations(message)) - message = Base.AnnotatedString(String(message), Base.annotations(message)) + message = Base.AnnotatedString(_String(message), Base.annotations(message)) @NamedTuple{indent::Int, msg::Union{SubString{Base.AnnotatedString{String}}, SubString{String}}}[ (indent=0, msg=l) for l in split(chomp(message), '\n')] else diff --git a/base/logging/logging.jl b/base/logging/logging.jl index 25f4dbe4902be..c0688d30fbf8a 100644 --- a/base/logging/logging.jl +++ b/base/logging/logging.jl @@ -4,6 +4,7 @@ module CoreLogging import Base: isless, +, -, convert, show import Base.ScopedValues: ScopedValue, with, @with +using .._ConstructingFunctions export AbstractLogger, @@ -518,7 +519,7 @@ function logmsg_shim(level, message, _module, group, id, file, line, kwargs) real_kws = Any[(kwargs[i], kwargs[i+1]) for i in 1:2:length(kwargs)] @logmsg(convert(LogLevel, level), message, _module=_module, _id=id, _group=group, - _file=String(file), _line=line, real_kws...) + _file=_String(file), _line=line, real_kws...) nothing end @@ -696,7 +697,7 @@ function handle_message(logger::SimpleLogger, level::LogLevel, message, _module, maxlog = get(kwargs, :maxlog, nothing) if maxlog isa Core.BuiltinInts @lock logger.lock begin - remaining = get!(logger.message_limits, id, Int(maxlog)::Int) + remaining = get!(logger.message_limits, id, _Int(maxlog)) remaining == 0 && return logger.message_limits[id] = remaining - 1 end diff --git a/base/meta.jl b/base/meta.jl index fa07c9582cd0c..0873676935d43 100644 --- a/base/meta.jl +++ b/base/meta.jl @@ -20,6 +20,8 @@ public parse import Base: isexpr +using .._ConstructingFunctions + ## AST decoding helpers ## is_id_start_char(c::AbstractChar) = ccall(:jl_id_start_char, Cint, (UInt32,), c) != 0 @@ -115,7 +117,7 @@ julia> Meta.ispostfixoperator(Symbol("'")), Meta.ispostfixoperator(Symbol("'ᵀ" ``` """ function ispostfixoperator(s::Union{Symbol,AbstractString}) - s = String(s)::String + s = _String(s) return startswith(s, '\'') && all(is_op_suffix_char, SubString(s, 2)) end @@ -347,7 +349,7 @@ julia> Meta.parse("(α, β) = 3, 5", 11, greedy=false) """ function parse(str::AbstractString, pos::Integer; filename="none", greedy::Bool=true, raise::Bool=true, depwarn::Bool=true) - ex, pos = _parse_string(str, String(filename), 1, pos, greedy ? :statement : :atom) + ex, pos = _parse_string(str, _String(filename), 1, pos, greedy ? :statement : :atom) if raise && isexpr(ex, :error) err = ex.args[1] if err isa String @@ -399,11 +401,11 @@ function parse(str::AbstractString; end function parseatom(text::AbstractString, pos::Integer; filename="none", lineno=1) - return _parse_string(text, String(filename), lineno, pos, :atom) + return _parse_string(text, _String(filename), lineno, pos, :atom) end function parseall(text::AbstractString; filename="none", lineno=1) - ex,_ = _parse_string(text, String(filename), lineno, 1, :all) + ex,_ = _parse_string(text, _String(filename), lineno, 1, :all) return ex end diff --git a/base/methodshow.jl b/base/methodshow.jl index 1470303a01bbc..234d40b7fc35e 100644 --- a/base/methodshow.jl +++ b/base/methodshow.jl @@ -7,7 +7,7 @@ function strip_gensym(sym) if sym === :var"#self#" || sym === :var"#unused#" return empty_sym end - return Symbol(replace(String(sym), r"^(.*)#(.*#)?\d+$"sa => s"\1")) + return Symbol(replace(_String(sym), r"^(.*)#(.*#)?\d+$"sa => s"\1")) end function argtype_decl(env, n, @nospecialize(sig::DataType), i::Int, nargs, isva::Bool) # -> (argname, argtype) @@ -138,7 +138,7 @@ function fixup_stdlib_path(path::String) path = npath == npath′ ? path : npath′ end if isdefined(@__MODULE__, :Core) && isdefined(Core, :Compiler) - compiler_folder = dirname(String(Base.moduleloc(Core.Compiler).file)) + compiler_folder = dirname(_String(Base.moduleloc(Core.Compiler).file)) if dirname(path) == compiler_folder return abspath(Sys.STDLIB, "..", "..", "Compiler", "src", basename(path)) end @@ -157,7 +157,7 @@ function updated_methodloc(m::Method)::Tuple{String, Int32} end end file = fixup_stdlib_path(string(file)) - return file, Int32(line) + return file, _Int32(line) end functionloc(m::Core.MethodInstance) = functionloc(m.def) @@ -202,7 +202,7 @@ function sym_to_string(sym) if sym === :var"..." return "..." end - s = String(sym) + s = _String(sym) if endswith(s, "...") return string(sprint(show_sym, Symbol(s[1:end-3])), "...") else diff --git a/base/multidimensional.jl b/base/multidimensional.jl index 9512d5d6dbe8b..f33309d280573 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -1466,7 +1466,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra cind = pos_s lastind = pos_d + numbits - 1 @inbounds while bind ≤ lastind - unsafe_bitsetindex!(Bc, Bool(C[cind]), bind) + unsafe_bitsetindex!(Bc, _Bool(C[cind]), bind) bind += 1 cind += 1 end @@ -1507,7 +1507,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra @inbounds if ld0 > 0 c = UInt64(0) for j = ld0:lt0 - c |= (UInt64(unchecked_bool_convert(C[ind])) << j) + c |= (_UInt64(unchecked_bool_convert(C[ind])) << j) ind += 1 end Bc[kd0] = (Bc[kd0] & msk_d0) | (c & ~msk_d0) @@ -1518,7 +1518,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra @inbounds for i = 1:nc c = UInt64(0) for j = 0:63 - c |= (UInt64(unchecked_bool_convert(C[ind])) << j) + c |= (_UInt64(unchecked_bool_convert(C[ind])) << j) ind += 1 end Bc[bind] = c @@ -1529,7 +1529,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra @assert bind == kd1 c = UInt64(0) for j = 0:ld1 - c |= (UInt64(unchecked_bool_convert(C[ind])) << j) + c |= (_UInt64(unchecked_bool_convert(C[ind])) << j) ind += 1 end Bc[kd1] = (Bc[kd1] & msk_d1) | (c & ~msk_d1) @@ -1602,7 +1602,7 @@ function fill!(V::SubArray{Bool, <:Any, <:BitArray, <:Tuple{AbstractUnitRange{In I0 = V.indices[1] l0 = length(I0) l0 == 0 && return V - fill_chunks!(B.chunks, Bool(x), first(I0), l0) + fill_chunks!(B.chunks, _Bool(x), first(I0), l0) return V end @@ -1613,7 +1613,7 @@ fill!(V::SubArray{Bool, <:Any, <:BitArray, <:Tuple{AbstractUnitRange{Int}, Varar I0::AbstractUnitRange{Int}, I::Union{Int,AbstractUnitRange{Int}}...) N = length(I) quote - y = Bool(x) + y = _Bool(x) idxlens = @ncall $N index_lengths I0 d->I[d] f0 = indexoffset(I0)+1 diff --git a/base/multimedia.jl b/base/multimedia.jl index 883e4831a39fb..f9637f90ea7e3 100644 --- a/base/multimedia.jl +++ b/base/multimedia.jl @@ -3,6 +3,7 @@ module Multimedia import .Base: show, print, convert, repr +using .._ConstructingFunctions export AbstractDisplay, display, pushdisplay, popdisplay, displayable, redisplay, MIME, @MIME_str, istextmime, @@ -160,9 +161,9 @@ repr(m::MIME, x; context=nothing) = istextmime(m) ? _textrepr(m, x, context) : _ repr(m::AbstractString, x; context=nothing) = repr(MIME(m), x; context=context) # strings are shown escaped for text/plain -_textrepr(m::MIME, x, context) = String(__binrepr(m, x, context)) +_textrepr(m::MIME, x, context) = _String(__binrepr(m, x, context)) _textrepr(::MIME, x::AbstractString, context) = x -_textrepr(m::MIME"text/plain", x::AbstractString, context) = String(__binrepr(m, x, context)) +_textrepr(m::MIME"text/plain", x::AbstractString, context) = _String(__binrepr(m, x, context)) function __binrepr(m::MIME, x, context) diff --git a/base/namedtuple.jl b/base/namedtuple.jl index 37f3a3ef8436b..5043edb8473b7 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -172,8 +172,8 @@ isempty(::NamedTuple{()}) = true isempty(::NamedTuple) = false empty(::NamedTuple) = NamedTuple() -prevind(@nospecialize(t::NamedTuple), i::Integer) = Int(i)-1 -nextind(@nospecialize(t::NamedTuple), i::Integer) = Int(i)+1 +prevind(@nospecialize(t::NamedTuple), i::Integer) = _Int(i)-1 +nextind(@nospecialize(t::NamedTuple), i::Integer) = _Int(i)+1 convert(::Type{NT}, nt::NT) where {names, NT<:NamedTuple{names}} = nt convert(::Type{NT}, nt::NT) where {names, T<:Tuple, NT<:NamedTuple{names,T}} = nt diff --git a/base/parse.jl b/base/parse.jl index 7e6f35cf6b35a..e251a6cdccd58 100644 --- a/base/parse.jl +++ b/base/parse.jl @@ -110,7 +110,7 @@ end function tryparse_internal(::Type{T}, s::AbstractString, startpos::Int, endpos::Int, base_::Integer, raise::Bool) where T<:Integer - sgn, base, i = parseint_preamble(T<:Signed, Int(base_), s, startpos, endpos) + sgn, base, i = parseint_preamble(T<:Signed, _Int(base_), s, startpos, endpos) if sgn == 0 && base == 0 && i == 0 raise && throw(ArgumentError("input string is empty or only contains whitespace")) return nothing @@ -299,7 +299,7 @@ function tryparse_internal(::Type{Float32}, s::SubString{String}, startpos::Int, (Ptr{UInt8},Csize_t,Csize_t), s.string, s.offset+startpos-1, endpos-startpos+1) hasvalue ? val : nothing end -tryparse(::Type{T}, s::AbstractString) where {T<:Union{Float32,Float64}} = tryparse(T, String(s)) +tryparse(::Type{T}, s::AbstractString) where {T<:Union{Float32,Float64}} = tryparse(T, _String(s)) tryparse(::Type{Float16}, s::AbstractString) = convert(Union{Float16, Nothing}, tryparse(Float32, s)) tryparse_internal(::Type{Float16}, s::AbstractString, startpos::Int, endpos::Int) = @@ -366,7 +366,7 @@ end # the ±1 indexing above for ascii chars is specific to String, so convert: tryparse_internal(T::Type{Complex{S}}, s::AbstractString, i::Int, e::Int, raise::Bool) where S<:Real = - tryparse_internal(T, String(s), i, e, raise) + tryparse_internal(T, _String(s), i, e, raise) # fallback methods for tryparse_internal tryparse_internal(::Type{T}, s::AbstractString, startpos::Int, endpos::Int) where T<:Real = diff --git a/base/path.jl b/base/path.jl index 4a3605dc398ed..15799682035f5 100644 --- a/base/path.jl +++ b/base/path.jl @@ -53,7 +53,7 @@ elseif Sys.iswindows() function splitdrive(path::String) m = match(splitdrive_re, path)::AbstractMatch - String(something(m.captures[1])), String(something(m.captures[2])) + _String(something(m.captures[1])), _String(something(m.captures[2])) end else error("path primitives for this OS need to be defined") @@ -160,7 +160,7 @@ function _splitdir_nodrive(a::String, b::String) getcapture(cs, i) = cs[i]::AbstractString c1, c2, c3 = getcapture(cs, 1), getcapture(cs, 2), getcapture(cs, 3) a = string(a, isempty(c1) ? c2[1] : c1) - a, String(c3) + a, _String(c3) end """ @@ -227,7 +227,7 @@ function splitext(path::String) a, b = splitdrive(path) m = match(path_ext_splitter, b) m === nothing && return (path,"") - (a*something(m.captures[1])), String(something(m.captures[2])) + (a*something(m.captures[1])), _String(something(m.captures[2])) end # NOTE: deprecated in 1.4 @@ -253,7 +253,7 @@ julia> splitpath("/home/myuser/example.jl") "example.jl" ``` """ -splitpath(p::AbstractString) = splitpath(String(p)) +splitpath(p::AbstractString) = splitpath(_String(p)) function splitpath(p::String) drive, p = splitdrive(p) @@ -608,10 +608,10 @@ function relpath(path::String, startpath::String = ".") return isempty(relpath_) ? curdir : relpath_ end relpath(path::AbstractString, startpath::AbstractString) = - relpath(String(path), String(startpath)) + relpath(_String(path), _String(startpath)) for f in (:isdirpath, :splitdir, :splitdrive, :splitext, :normpath, :abspath) - @eval $f(path::AbstractString) = $f(String(path)) + @eval $f(path::AbstractString) = $f(_String(path)) end # RFC3986 Section 2.1 @@ -665,4 +665,4 @@ else end end -uripath(path::AbstractString) = uripath(String(path)) +uripath(path::AbstractString) = uripath(_String(path)) diff --git a/base/pcre.jl b/base/pcre.jl index 213fc1890f51d..c6cc482bc43e8 100644 --- a/base/pcre.jl +++ b/base/pcre.jl @@ -5,6 +5,7 @@ module PCRE import ..RefValue +using .._ConstructingFunctions # include($BUILDROOT/base/pcre_h.jl) include(string(Base.BUILDROOT, "pcre_h.jl")) @@ -154,7 +155,7 @@ end function compile(pattern::AbstractString, options::Integer) if !(pattern isa Union{String,SubString{String}}) - pattern = String(pattern) + pattern = _String(pattern) end errno = RefValue{Cint}(0) erroff = RefValue{Csize_t}(0) @@ -199,7 +200,7 @@ end exec(re, subject::Union{String,SubString{String}}, offset, options, match_data) = _exec(re, subject, offset, options, match_data) exec(re, subject, offset, options, match_data) = - _exec(re, String(subject)::String, offset, options, match_data) + _exec(re, _String(subject), offset, options, match_data) function _exec(re, subject, offset, options, match_data) rc = ccall((:pcre2_match_8, PCRE_LIB), Cint, @@ -265,8 +266,8 @@ function capture_names(re) offset = (i-1)*name_entry_size + 1 # The capture group index corresponding to name 'i' is stored as a # big-endian 16-bit value. - high_byte = UInt16(unsafe_load(nametable_ptr, offset)) - low_byte = UInt16(unsafe_load(nametable_ptr, offset+1)) + high_byte = _UInt16(unsafe_load(nametable_ptr, offset)) + low_byte = _UInt16(unsafe_load(nametable_ptr, offset+1)) idx = (high_byte << 8) | low_byte # The capture group name is a null-terminated string located directly # after the index. diff --git a/base/pointer.jl b/base/pointer.jl index 72c567eaf2a85..44d0dae84d267 100644 --- a/base/pointer.jl +++ b/base/pointer.jl @@ -55,8 +55,8 @@ See also [`cconvert`](@ref) function unsafe_convert end # convert strings to String etc. to pass as pointers -cconvert(::Type{Ptr{UInt8}}, s::AbstractString) = String(s) -cconvert(::Type{Ptr{Int8}}, s::AbstractString) = String(s) +cconvert(::Type{Ptr{UInt8}}, s::AbstractString) = _String(s) +cconvert(::Type{Ptr{Int8}}, s::AbstractString) = _String(s) unsafe_convert(::Type{Ptr{UInt8}}, x::Symbol) = ccall(:jl_symbol_name, Ptr{UInt8}, (Any,), x) unsafe_convert(::Type{Ptr{Int8}}, x::Symbol) = ccall(:jl_symbol_name, Ptr{Int8}, (Any,), x) @@ -80,7 +80,7 @@ function unsafe_convert(::Type{Ptr{Cvoid}}, a::GenericMemoryRef{<:Any,T,Core.CPU elsz = datatype_layoutsize(MemT) isboxed = 1; isunion = 2 if arrayelem == isunion || elsz == 0 - offset = UInt(offset) * elsz + offset = _UInt(offset) * elsz offset += unsafe_convert(Ptr{Cvoid}, mem) end return offset @@ -148,10 +148,10 @@ memory region allocated as different type may be valid provided that the types a See also: [`atomic`](@ref) """ -unsafe_load(p::Ptr, i::Integer=1) = pointerref(p, Int(i), 1) +unsafe_load(p::Ptr, i::Integer=1) = pointerref(p, _Int(i), 1) unsafe_load(p::Ptr, order::Symbol) = atomic_pointerref(p, order) function unsafe_load(p::Ptr, i::Integer, order::Symbol) - unsafe_load(p + (elsize(typeof(p)) * (Int(i) - 1)), order) + unsafe_load(p + (elsize(typeof(p)) * (_Int(i) - 1)), order) end """ @@ -174,11 +174,11 @@ different type may be valid provided that the types are compatible. See also: [`atomic`](@ref) """ -unsafe_store!(p::Ptr{Any}, @nospecialize(x), i::Integer=1) = pointerset(p, x, Int(i), 1) -unsafe_store!(p::Ptr{T}, x, i::Integer=1) where {T} = pointerset(p, convert(T,x), Int(i), 1) +unsafe_store!(p::Ptr{Any}, @nospecialize(x), i::Integer=1) = pointerset(p, x, _Int(i), 1) +unsafe_store!(p::Ptr{T}, x, i::Integer=1) where {T} = pointerset(p, convert(T,x), _Int(i), 1) unsafe_store!(p::Ptr{T}, x, order::Symbol) where {T} = atomic_pointerset(p, x isa T ? x : convert(T,x), order) function unsafe_store!(p::Ptr, x, i::Integer, order::Symbol) - unsafe_store!(p + (elsize(typeof(p)) * (Int(i) - 1)), x, order) + unsafe_store!(p + (elsize(typeof(p)) * (_Int(i) - 1)), x, order) end """ diff --git a/base/precompilation.jl b/base/precompilation.jl index 45634d877115f..bc38fef5660cf 100644 --- a/base/precompilation.jl +++ b/base/precompilation.jl @@ -4,6 +4,8 @@ using Base: PkgId, UUID, SHA1, parsed_toml, project_file_name_uuid, project_name project_file_manifest_path, get_deps, preferences_names, isaccessibledir, isfile_casesensitive, base_project, isdefined +using .._ConstructingFunctions + # This is currently only used for pkgprecompile but the plan is to use this in code loading in the future # see the `kc/codeloading2.0` branch struct ExplicitEnv @@ -923,7 +925,7 @@ function _precompilepkgs(pkgs::Union{Vector{String}, Vector{PkgId}}, elseif started[pkg_config] # Offset each spinner animation using the first character in the package name as the seed. # If not offset, on larger terminal fonts it looks odd that they all sync-up - anim_char = anim_chars[(i + Int(dep.name[1])) % length(anim_chars) + 1] + anim_char = anim_chars[(i + _Int(dep.name[1])) % length(anim_chars) + 1] anim_char_colored = dep in project_deps ? anim_char : color_string(anim_char, :light_black) waiting = if haskey(pkgspidlocked, pkg_config) who_has_lock = pkgspidlocked[pkg_config] @@ -1043,7 +1045,7 @@ function _precompilepkgs(pkgs::Union{Vector{String}, Vector{PkgId}}, close(std_pipe.in) # close pipe to end the std output monitor wait(t_monitor) if err isa ErrorException || (err isa ArgumentError && startswith(err.msg, "Invalid header in cache file")) - errmsg = String(take!(get(IOBuffer, std_outputs, pkg_config))) + errmsg = _String(take!(get(IOBuffer, std_outputs, pkg_config))) delete!(std_outputs, pkg_config) # so it's not shown as warnings, given error report failed_deps[pkg_config] = (strict || is_project_dep) ? string(sprint(showerror, err), "\n", strip(errmsg)) : "" !fancyprint && @lock print_lock begin @@ -1127,7 +1129,7 @@ function _precompilepkgs(pkgs::Union{Vector{String}, Vector{PkgId}}, end # show any stderr output, even if Pkg.precompile has been interrupted (quick_exit=true), given user may be # interrupting a hanging precompile job with stderr output. julia#48371 - let std_outputs = Tuple{PkgConfig,SubString{String}}[(pkg_config, strip(String(take!(io)))) for (pkg_config,io) in std_outputs] + let std_outputs = Tuple{PkgConfig,SubString{String}}[(pkg_config, strip(_String(take!(io)))) for (pkg_config,io) in std_outputs] filter!(kv -> !isempty(last(kv)), std_outputs) if !isempty(std_outputs) local plural1 = length(std_outputs) == 1 ? "y" : "ies" @@ -1171,7 +1173,7 @@ function _precompilepkgs(pkgs::Union{Vector{String}, Vector{PkgId}}, truncate(err_str, position(err_str)) pluralde = n_direct_errs == 1 ? "y" : "ies" direct = strict ? "" : "direct " - err_msg = "The following $n_direct_errs $(direct)dependenc$(pluralde) failed to precompile:\n$(String(take!(err_str)))" + err_msg = "The following $n_direct_errs $(direct)dependenc$(pluralde) failed to precompile:\n$(_String(take!(err_str)))" if internal_call # aka. auto-precompilation if isinteractive() plural1 = length(failed_deps) == 1 ? "y" : "ies" diff --git a/base/process.jl b/base/process.jl index e2fb2b266cc97..f4a9d00f79c59 100644 --- a/base/process.jl +++ b/base/process.jl @@ -488,7 +488,7 @@ end Run `command` and return the resulting output as a `String`. """ -read(cmd::AbstractCmd, ::Type{String}) = String(read(cmd))::String +read(cmd::AbstractCmd, ::Type{String}) = _String(read(cmd)) """ run(command, args...; wait::Bool = true) diff --git a/base/regex.jl b/base/regex.jl index 691dbc94c5563..e42b29e5632d8 100644 --- a/base/regex.jl +++ b/base/regex.jl @@ -28,9 +28,9 @@ mutable struct Regex <: AbstractPattern function Regex(pattern::AbstractString, compile_options::Integer, match_options::Integer) - pattern = String(pattern)::String - compile_options = UInt32(compile_options) - match_options = UInt32(match_options) + pattern = _String(pattern) + compile_options = _UInt32(compile_options) + match_options = _UInt32(match_options) if (compile_options & ~PCRE.COMPILE_MASK) != 0 throw(ArgumentError("invalid regex compile options: $compile_options")) end @@ -305,7 +305,7 @@ Dict(m::RegexMatch) = Dict(pairs(m)) function occursin(r::Regex, s::AbstractString; offset::Integer=0) compile(r) - return PCRE.exec_r(r.regex, String(s), offset, r.match_options) + return PCRE.exec_r(r.regex, _String(s), offset, r.match_options) end function occursin(r::Regex, s::SubString{String}; offset::Integer=0) @@ -337,7 +337,7 @@ true """ function startswith(s::AbstractString, r::Regex) compile(r) - return PCRE.exec_r(r.regex, String(s), 0, r.match_options | PCRE.ANCHORED) + return PCRE.exec_r(r.regex, _String(s), 0, r.match_options | PCRE.ANCHORED) end function startswith(s::SubString{String}, r::Regex) @@ -369,7 +369,7 @@ true """ function endswith(s::AbstractString, r::Regex) compile(r) - return PCRE.exec_r(r.regex, String(s), 0, r.match_options | PCRE.ENDANCHORED) + return PCRE.exec_r(r.regex, _String(s), 0, r.match_options | PCRE.ENDANCHORED) end function endswith(s::SubString{String}, r::Regex) @@ -495,7 +495,7 @@ function _findnext_re(re::Regex, str, idx::Integer, match_data::Ptr{Cvoid}) end if matched p = PCRE.ovec_ptr(data) - ans = (Int(unsafe_load(p,1))+1):prevind(str,Int(unsafe_load(p,2))+1) + ans = (_Int(unsafe_load(p,1))+1):prevind(str,_Int(unsafe_load(p,2))+1) else ans = nothing end @@ -725,9 +725,9 @@ struct RegexMatchIterator{S <: AbstractString} overlap::Bool RegexMatchIterator(regex::Regex, string::AbstractString, ovr::Bool=false) = - new{String}(regex, String(string), ovr) + new{String}(regex, _String(string), ovr) RegexMatchIterator(regex::Regex, string::AnnotatedString, ovr::Bool=false) = - new{AnnotatedString{String}}(regex, AnnotatedString(String(string.string), string.annotations), ovr) + new{AnnotatedString{String}}(regex, AnnotatedString(_String(string.string), string.annotations), ovr) end compile(itr::RegexMatchIterator) = (compile(itr.regex); itr) eltype(::Type{<:RegexMatchIterator}) = RegexMatch diff --git a/base/secretbuffer.jl b/base/secretbuffer.jl index bf37c3caa6c23..127d0528dbdd1 100644 --- a/base/secretbuffer.jl +++ b/base/secretbuffer.jl @@ -51,7 +51,7 @@ Instead of starting with a string, either construct the `SecretBuffer` incrementally with `SecretBuffer()` and [`write`](@ref), or use a `Vector{UInt8}` with the `Base.SecretBuffer!(::AbstractVector{UInt8})` constructor. """ -SecretBuffer(str::AbstractString) = SecretBuffer(String(str)) +SecretBuffer(str::AbstractString) = SecretBuffer(_String(str)) function SecretBuffer(str::String) buf = codeunits(str) s = SecretBuffer(sizehint=length(buf)) @@ -61,7 +61,7 @@ function SecretBuffer(str::String) seek(s, 0) s end -convert(::Type{SecretBuffer}, s::AbstractString) = SecretBuffer(String(s)) +convert(::Type{SecretBuffer}, s::AbstractString) = SecretBuffer(_String(s)) """ SecretBuffer!(data::Vector{UInt8}) diff --git a/base/show.jl b/base/show.jl index 7016c55c57fe4..ded310c86c3bc 100644 --- a/base/show.jl +++ b/base/show.jl @@ -1070,7 +1070,7 @@ function check_world_bounded(tn::Core.TypeName) if isa(cval, Type) && cval <: tn.wrapper max_world = @atomic partition.max_world max_world == typemax(UInt) && return nothing - return Int(partition.min_world):Int(max_world) + return _Int(partition.min_world):_Int(max_world) end end isdefined(partition, :next) || return nothing @@ -2366,7 +2366,7 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In end print(io, ")") else - escape_string(io, String(x)::String, "\"\$") + escape_string(io, _String(x), "\"\$") end end print(io, '"') diff --git a/base/sort.jl b/base/sort.jl index bfa65d2459680..db7722a110e5e 100644 --- a/base/sort.jl +++ b/base/sort.jl @@ -14,6 +14,8 @@ import Base: sortperm, to_indices +using .._ConstructingFunctions + export # also exported by Base # order-only: issorted, @@ -1436,7 +1438,7 @@ function radix_chunk_size_heuristic(lo::Integer, hi::Integer, bits::Unsigned) # We need iterations * chunk size ≥ bits, and these cld's # make an effort to get iterations * chunk size ≈ bits - UInt8(cld(bits, cld(bits, guess))) + _UInt8(cld(bits, cld(bits, guess))) end maybe_unsigned(x::Integer) = x # this is necessary to avoid calling unsigned on BigInt diff --git a/base/stat.jl b/base/stat.jl index fbab5126d39bc..2f947c8ead680 100644 --- a/base/stat.jl +++ b/base/stat.jl @@ -91,7 +91,7 @@ end StatStruct() = StatStruct("", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Base.UV_ENOENT) StatStruct(buf::Union{Memory{UInt8},Vector{UInt8},Ptr{UInt8}}, ioerrno::Int32) = StatStruct("", buf, ioerrno) StatStruct(desc::Union{AbstractString, OS_HANDLE}, buf::Union{Memory{UInt8},Vector{UInt8},Ptr{UInt8}}, ioerrno::Int32) = StatStruct( - desc isa OS_HANDLE ? desc : String(desc), + desc isa OS_HANDLE ? desc : _String(desc), ioerrno != 0 ? zero(UInt32) : ccall(:jl_stat_dev, UInt32, (Ptr{UInt8},), buf), ioerrno != 0 ? zero(UInt32) : ccall(:jl_stat_ino, UInt32, (Ptr{UInt8},), buf), ioerrno != 0 ? zero(UInt32) : ccall(:jl_stat_mode, UInt32, (Ptr{UInt8},), buf), @@ -380,7 +380,7 @@ function ispath(path::String) end return r == 0 end -ispath(path::AbstractString) = ispath(String(path)) +ispath(path::AbstractString) = ispath(_String(path)) """ isfifo(path)::Bool diff --git a/base/stream.jl b/base/stream.jl index 40106436ebd05..58662d88eacc0 100644 --- a/base/stream.jl +++ b/base/stream.jl @@ -629,7 +629,7 @@ function notify_filled(buffer::IOBuffer, nread::Int) end function alloc_buf_hook(stream::LibuvStream, size::UInt) - throttle = UInt(stream.throttle) + throttle = _UInt(stream.throttle) return alloc_request(stream.buffer, (size > throttle) ? throttle : size) end @@ -711,7 +711,7 @@ function uv_readcb(handle::Ptr{Cvoid}, nread::Cssize_t, buf::Ptr{Cvoid}) end nothing end - readcb_specialized(stream_unknown_type, Int(nread), UInt(nrequested)) + readcb_specialized(stream_unknown_type, _Int(nread), _UInt(nrequested)) nothing end @@ -913,7 +913,7 @@ end # bulk read / write -readbytes!(s::LibuvStream, a::Vector{UInt8}, nb = length(a)) = readbytes!(s, a, Int(nb)) +readbytes!(s::LibuvStream, a::Vector{UInt8}, nb = length(a)) = readbytes!(s, a, _Int(nb)) function readbytes!(s::LibuvStream, a::Vector{UInt8}, nb::Int) iolock_begin() sbuf = s.buffer @@ -980,16 +980,16 @@ function unsafe_read(s::LibuvStream, p::Ptr{UInt8}, nb::UInt) end if nb <= SZ_UNBUFFERED_IO # Under this limit we are OK with copying the array from the stream's buffer - wait_locked(s, sbuf, Int(nb)) + wait_locked(s, sbuf, _Int(nb)) end if bytesavailable(sbuf) >= nb unsafe_read(sbuf, p, nb) else - newbuf = _truncated_pipebuffer(unsafe_wrap(Array, p, nb); maxsize=Int(nb)) + newbuf = _truncated_pipebuffer(unsafe_wrap(Array, p, nb); maxsize=_Int(nb)) try s.buffer = newbuf write(newbuf, sbuf) - wait_locked(s, newbuf, Int(nb)) + wait_locked(s, newbuf, _Int(nb)) finally s.buffer = sbuf end diff --git a/base/strings/annotated_io.jl b/base/strings/annotated_io.jl index 9698fd5909b68..c5e23e161efb3 100644 --- a/base/strings/annotated_io.jl +++ b/base/strings/annotated_io.jl @@ -37,7 +37,7 @@ function write(io::AnnotatedIOBuffer, astr::Union{AnnotatedString, SubString{<:A offset = position(io.io) eof(io) || _clear_annotations_in_region!(io.annotations, offset+1:offset+ncodeunits(astr)) _insert_annotations!(io, astr.annotations) - write(io.io, String(astr)) + write(io.io, _String(astr)) end write(io::AnnotatedIOBuffer, c::AnnotatedChar) = @@ -211,7 +211,7 @@ using ..Base: eachregion, invoke_in_world, tls_world_age # Write -ansi_write(f::Function, io::IO, x::Any) = f(io, String(x)) +ansi_write(f::Function, io::IO, x::Any) = f(io, _String(x)) ansi_write_(f::Function, io::IO, @nospecialize(x::Any)) = invoke_in_world(tls_world_age(), ansi_write, f, io, x) diff --git a/base/strings/basic.jl b/base/strings/basic.jl index 352d42eb3a40f..5bbd252485dea 100644 --- a/base/strings/basic.jl +++ b/base/strings/basic.jl @@ -105,7 +105,7 @@ UInt8 See also [`ncodeunits`](@ref), [`checkbounds`](@ref). """ @propagate_inbounds codeunit(s::AbstractString, i::Integer) = i isa Int ? - throw(MethodError(codeunit, (s, i))) : codeunit(s, Int(i)) + throw(MethodError(codeunit, (s, i))) : codeunit(s, _Int(i)) """ isvalid(s::AbstractString, i::Integer)::Bool @@ -141,7 +141,7 @@ Stacktrace: ``` """ @propagate_inbounds isvalid(s::AbstractString, i::Integer) = i isa Int ? - throw(MethodError(isvalid, (s, i))) : isvalid(s, Int(i)) + throw(MethodError(isvalid, (s, i))) : isvalid(s, _Int(i)) """ iterate(s::AbstractString, i::Integer)::Union{Tuple{<:AbstractChar, Int}, Nothing} @@ -154,7 +154,7 @@ of the iteration protocol may assume that `i` is the start of a character in `s` See also [`getindex`](@ref), [`checkbounds`](@ref). """ @propagate_inbounds iterate(s::AbstractString, i::Integer) = i isa Int ? - throw(MethodError(iterate, (s, i))) : iterate(s, Int(i)) + throw(MethodError(iterate, (s, i))) : iterate(s, _Int(i)) ## basic generic definitions ## @@ -217,11 +217,11 @@ checkbounds(s::AbstractString, I::Union{Integer,AbstractArray}) = string() = "" string(s::AbstractString) = s -Vector{UInt8}(s::AbstractString) = unsafe_wrap(Vector{UInt8}, String(s)) -Array{UInt8}(s::AbstractString) = unsafe_wrap(Vector{UInt8}, String(s)) +Vector{UInt8}(s::AbstractString) = unsafe_wrap(Vector{UInt8}, _String(s)) +Array{UInt8}(s::AbstractString) = unsafe_wrap(Vector{UInt8}, _String(s)) Vector{T}(s::AbstractString) where {T<:AbstractChar} = collect(T, s) -Symbol(s::AbstractString) = Symbol(String(s)) +Symbol(s::AbstractString) = Symbol(_String(s)) Symbol(x...) = Symbol(string(x...)) convert(::Type{T}, s::T) where {T<:AbstractString} = s @@ -364,7 +364,7 @@ isless(a::Symbol, b::Symbol) = cmp(a, b) < 0 # hashing -hash(s::AbstractString, h::UInt) = hash(String(s), h) +hash(s::AbstractString, h::UInt) = hash(_String(s), h) ## character index arithmetic ## @@ -412,7 +412,7 @@ function length(s::AbstractString, i::Int, j::Int) end @propagate_inbounds length(s::AbstractString, i::Integer, j::Integer) = - length(s, Int(i), Int(j)) + length(s, _Int(i), _Int(j)) """ thisind(s::AbstractString, i::Integer)::Int @@ -446,7 +446,7 @@ ERROR: BoundsError: attempt to access 2-codeunit String at index [-1] [...] ``` """ -thisind(s::AbstractString, i::Integer) = thisind(s, Int(i)) +thisind(s::AbstractString, i::Integer) = thisind(s, _Int(i)) function thisind(s::AbstractString, i::Int) z = ncodeunits(s)::Int + 1 @@ -502,8 +502,8 @@ julia> prevind("α", 2, 3) -1 ``` """ -prevind(s::AbstractString, i::Integer, n::Integer) = prevind(s, Int(i), Int(n)) -prevind(s::AbstractString, i::Integer) = prevind(s, Int(i)) +prevind(s::AbstractString, i::Integer, n::Integer) = prevind(s, _Int(i), _Int(n)) +prevind(s::AbstractString, i::Integer) = prevind(s, _Int(i)) prevind(s::AbstractString, i::Int) = prevind(s, i, 1) function prevind(s::AbstractString, i::Int, n::Int) @@ -561,8 +561,8 @@ julia> nextind("α", 1, 2) 4 ``` """ -nextind(s::AbstractString, i::Integer, n::Integer) = nextind(s, Int(i), Int(n)) -nextind(s::AbstractString, i::Integer) = nextind(s, Int(i)) +nextind(s::AbstractString, i::Integer, n::Integer) = nextind(s, _Int(i), _Int(n)) +nextind(s::AbstractString, i::Integer) = nextind(s, _Int(i)) nextind(s::AbstractString, i::Int) = nextind(s, i, 1) function nextind(s::AbstractString, i::Int, n::Int) @@ -621,7 +621,7 @@ julia> replace("abcdeγfgh", !isascii=>' ') # replace non-ASCII chars with space """ isascii(c::Char) = bswap(reinterpret(UInt32, c)) < 0x80 isascii(s::AbstractString) = all(isascii, s) -isascii(c::AbstractChar) = UInt32(c) < 0x80 +isascii(c::AbstractChar) = _UInt32(c) < 0x80 @inline function _isascii(code_units::AbstractVector{CU}, first, last) where {CU} r = zero(CU) @@ -757,7 +757,7 @@ julia> repeat("ha", 3) "hahaha" ``` """ -repeat(s::AbstractString, r::Integer) = repeat(String(s), r) +repeat(s::AbstractString, r::Integer) = repeat(_String(s), r) """ ^(s::Union{AbstractString,AbstractChar}, n::Integer)::AbstractString diff --git a/base/strings/cstring.jl b/base/strings/cstring.jl index 3a377ab0e7b1e..5da0e6aee9421 100644 --- a/base/strings/cstring.jl +++ b/base/strings/cstring.jl @@ -64,10 +64,10 @@ unsafe_string(s::Cstring) = unsafe_string(convert(Ptr{UInt8}, s)) # convert strings to String etc. to pass as pointers cconvert(::Type{Cstring}, s::String) = s cconvert(::Type{Cstring}, s::AbstractString) = - cconvert(Cstring, String(s)::String) + cconvert(Cstring, _String(s)) function cconvert(::Type{Cwstring}, s::AbstractString) - v = transcode(Cwchar_t, String(s)) + v = transcode(Cwchar_t, _String(s)) push!(v, 0) return cconvert(Cwstring, v) end @@ -117,7 +117,7 @@ same argument. This is only available on Windows. """ function cwstring(s::AbstractString) - bytes = codeunits(String(s)) + bytes = codeunits(_String(s)) 0 in bytes && throw(ArgumentError("embedded NULs are not allowed in C strings: $(repr(s))")) return push!(transcode(UInt16, bytes), 0) end @@ -163,9 +163,9 @@ function transcode end transcode(::Type{T}, src::AbstractVector{T}) where {T<:Union{UInt8,UInt16,UInt32,Int32}} = src transcode(::Type{T}, src::String) where {T<:Union{Int32,UInt32}} = T[T(c) for c in src] transcode(::Type{T}, src::AbstractVector{UInt8}) where {T<:Union{Int32,UInt32}} = - transcode(T, String(Vector(src))) + transcode(T, _String(Vector(src))) transcode(::Type{T}, src::CodeUnits{UInt8,String}) where {T<:Union{Int32,UInt32}} = - transcode(T, String(src)) + transcode(T, _String(src)) function transcode(::Type{UInt8}, src::Vector{<:Union{Int32,UInt32}}) buf = IOBuffer() @@ -176,7 +176,7 @@ function transcode(::Type{UInt8}, src::Vector{<:Union{Int32,UInt32}}) end transcode(::Type{String}, src::String) = src transcode(T, src::String) = transcode(T, codeunits(src)) -transcode(::Type{String}, src) = String(transcode(UInt8, src)) +transcode(::Type{String}, src) = _String(transcode(UInt8, src)) function transcode(::Type{UInt16}, src::AbstractVector{UInt8}) require_one_based_indexing(src) @@ -193,24 +193,24 @@ function transcode(::Type{UInt16}, src::AbstractVector{UInt8}) push!(dst, a) a = b; continue elseif a < 0xe0 # 2-byte UTF-8 - push!(dst, xor(0x3080, UInt16(a) << 6, b)) + push!(dst, xor(0x3080, _UInt16(a) << 6, b)) elseif i < n # 3/4-byte character c = src[i += 1] if -64 <= (c % Int8) # invalid UTF-8 (non-continuation) push!(dst, a, b) a = c; continue elseif a < 0xf0 # 3-byte UTF-8 - push!(dst, xor(0x2080, UInt16(a) << 12, UInt16(b) << 6, c)) + push!(dst, xor(0x2080, _UInt16(a) << 12, _UInt16(b) << 6, c)) elseif i < n d = src[i += 1] if -64 <= (d % Int8) # invalid UTF-8 (non-continuation) push!(dst, a, b, c) a = d; continue elseif a == 0xf0 && b < 0x90 # overlong encoding - push!(dst, xor(0x2080, UInt16(b) << 12, UInt16(c) << 6, d)) + push!(dst, xor(0x2080, _UInt16(b) << 12, _UInt16(c) << 6, d)) else # 4-byte UTF-8 - push!(dst, 0xe5b8 + (UInt16(a) << 8) + (UInt16(b) << 2) + (c >> 4), - xor(0xdc80, UInt16(c & 0xf) << 6, d)) + push!(dst, 0xe5b8 + (_UInt16(a) << 8) + (_UInt16(b) << 2) + (c >> 4), + xor(0xdc80, _UInt16(c & 0xf) << 6, d)) end else # too short push!(dst, a, b, c) diff --git a/base/strings/io.jl b/base/strings/io.jl index f3a0783e98a9b..bbba16922cb64 100644 --- a/base/strings/io.jl +++ b/base/strings/io.jl @@ -193,7 +193,7 @@ string(a::Symbol) = String(a) # note: print uses an encoding determined by `io` (defaults to UTF-8), whereas # write uses an encoding determined by `s` (UTF-8 for `String`) print(io::IO, s::AbstractString) = for c in s; print(io, c); end -write(io::IO, s::AbstractString) = (len = 0; for c in s; len += Int(write(io, c))::Int; end; len) +write(io::IO, s::AbstractString) = (len = 0; for c in s; len += _Int(write(io, c)); end; len) show(io::IO, s::AbstractString) = print_quoted(io, s) # show elided string if more than `limit` characters @@ -364,7 +364,7 @@ function _join_preserve_annotations(iterator, args...) seekstart(io) read(io, AnnotatedString{String}) else - String(take!(io.io)) + _String(take!(io.io)) end end end @@ -442,14 +442,14 @@ function escape_string(io::IO, s::AbstractString, esc=""; keep = (), ascii::Bool c == '\0' ? print(io, escape_nul(peek(a)::Union{AbstractChar,Nothing})) : c == '\e' ? print(io, "\\e") : c == '\\' ? print(io, "\\\\") : - '\a' <= c <= '\r' ? print(io, '\\', "abtnvfr"[Int(c)-6]) : + '\a' <= c <= '\r' ? print(io, '\\', "abtnvfr"[_Int(c)-6]) : isprint(c) ? print(io, c) : - print(io, "\\x", string(UInt32(c), base = 16, pad = 2)) + print(io, "\\x", string(_UInt32(c), base = 16, pad = 2)) elseif !isoverlong(c) && !ismalformed(c) !ascii && isprint(c) ? print(io, c) : - c <= '\x7f' ? print(io, "\\x", string(UInt32(c), base = 16, pad = 2)) : - c <= '\uffff' ? print(io, "\\u", string(UInt32(c), base = 16, pad = fullhex || need_full_hex(peek(a)::Union{AbstractChar,Nothing}) ? 4 : 2)) : - print(io, "\\U", string(UInt32(c), base = 16, pad = fullhex || need_full_hex(peek(a)::Union{AbstractChar,Nothing}) ? 8 : 4)) + c <= '\x7f' ? print(io, "\\x", string(_UInt32(c), base = 16, pad = 2)) : + c <= '\uffff' ? print(io, "\\u", string(_UInt32(c), base = 16, pad = fullhex || need_full_hex(peek(a)::Union{AbstractChar,Nothing}) ? 4 : 2)) : + print(io, "\\U", string(_UInt32(c), base = 16, pad = fullhex || need_full_hex(peek(a)::Union{AbstractChar,Nothing}) ? 8 : 4)) else # malformed or overlong u = bswap(reinterpret(UInt32, c)::UInt32) while true @@ -800,7 +800,7 @@ end function AnnotatedString(chars::AbstractVector{C}) where {C<:AbstractChar} str = if C <: AnnotatedChar - String(getfield.(chars, :char)) + _String(getfield.(chars, :char)) else sprint(sizehint=length(chars)) do io for c in chars diff --git a/base/strings/search.jl b/base/strings/search.jl index a68b5f52b9f0a..b02974406b2bd 100644 --- a/base/strings/search.jl +++ b/base/strings/search.jl @@ -55,7 +55,7 @@ struct FwCharPosIter{S} end function FwCharPosIter(s::Union{String, SubString{String}}, c::AbstractChar) - char = Char(c)::Char + char = _Char(c) byte = last_utf8_byte(char) FwCharPosIter{typeof(s)}(s, char, byte) end @@ -106,7 +106,7 @@ IteratorSize(s::Type{<:Union{FwCharPosIter, RvCharPosIter}}) = SizeUnknown() eltype(::Type{<:Union{FwCharPosIter, RvCharPosIter}}) = Int function RvCharPosIter(s::Union{String, SubString{String}}, c::AbstractChar) - char = Char(c)::Char + char = _Char(c) byte = last_utf8_byte(char) RvCharPosIter{typeof(s)}(s, char, byte) end @@ -157,9 +157,9 @@ function findnext( # The most common case is probably searching for an ASCII char. # We inline this critical path here to avoid instantiating a # FwCharPosIter in the common case. - c = Char(pred.x)::Char + c = _Char(pred.x) u = (reinterpret(UInt32, c) >> 24) % UInt8 - i = Int(i)::Int + i = _Int(i) isvalid(s, i) || string_index_err(s, i) return if is_standalone_byte(u) _search(s, u, i) @@ -211,9 +211,9 @@ function findprev( throw(BoundsError(s, i)) end # Manually inline the fast path if c is ASCII, as we expect it to often be - c = Char(pred.x)::Char + c = _Char(pred.x) u = (reinterpret(UInt32, c) >> 24) % UInt8 - i = Int(i)::Int + i = _Int(i) return if is_standalone_byte(u) _rsearch(s, u, i) else @@ -322,7 +322,7 @@ findfirst(pattern::AbstractVector{<:Union{Int8,UInt8}}, # AbstractString implementation of the generic findnext interface function findnext(testf::Function, s::AbstractString, i::Integer) - i = Int(i) + i = _Int(i) z = ncodeunits(s) + 1 1 ≤ i ≤ z || throw(BoundsError(s, i)) @inbounds i == z || isvalid(s, i) || string_index_err(s, i) @@ -378,7 +378,7 @@ function _searchindex(s::AbstractVector{<:Union{Int8,UInt8}}, sentinel = firstindex(s) - 1 n = length(t) m = length(s) - i = Int(_i) - sentinel + i = _Int(_i) - sentinel (i < 1 || i > m+1) && throw(BoundsError(s, _i)) if n == 0 @@ -478,7 +478,7 @@ julia> findnext("Lang", "JuliaLang", 2) 6:9 ``` """ -findnext(t::AbstractString, s::AbstractString, start::Integer) = _search(s, t, Int(start)) +findnext(t::AbstractString, s::AbstractString, start::Integer) = _search(s, t, _Int(start)) """ findnext(ch::AbstractChar, string::AbstractString, start::Integer) @@ -640,7 +640,7 @@ end # AbstractString implementation of the generic findprev interface function findprev(testf::Function, s::AbstractString, i::Integer) - i = Int(i) + i = _Int(i) z = ncodeunits(s) + 1 0 ≤ i ≤ z || throw(BoundsError(s, i)) i == z && return nothing @@ -696,7 +696,7 @@ function _rsearchindex(s::AbstractVector{<:Union{Int8,UInt8}}, t::AbstractVector sentinel = firstindex(s) - 1 n = length(t) m = length(s) - k = Int(_k) - sentinel + k = _Int(_k) - sentinel k < 0 && throw(BoundsError(s, _k)) if n == 0 @@ -792,7 +792,7 @@ julia> findprev("Julia", "JuliaLang", 6) 1:5 ``` """ -findprev(t::AbstractString, s::AbstractString, i::Integer) = _rsearch(s, t, Int(i)) +findprev(t::AbstractString, s::AbstractString, i::Integer) = _rsearch(s, t, _Int(i)) """ findprev(ch::AbstractChar, string::AbstractString, start::Integer) diff --git a/base/strings/string.jl b/base/strings/string.jl index c944da935a2ae..6bb2538b26f44 100644 --- a/base/strings/string.jl +++ b/base/strings/string.jl @@ -10,7 +10,7 @@ struct StringIndexError <: Exception index::Int end @noinline string_index_err((@nospecialize s::AbstractString), i::Integer) = - throw(StringIndexError(s, Int(i))) + throw(StringIndexError(s, _Int(i))) function Base.showerror(io::IO, exc::StringIndexError) s = exc.string print(io, "StringIndexError: ", "invalid index [$(exc.index)]") @@ -152,12 +152,12 @@ String(s::CodeUnits{UInt8,String}) = s.s ## low-level functions ## pointer(s::String) = unsafe_convert(Ptr{UInt8}, s) -pointer(s::String, i::Integer) = pointer(s) + Int(i)::Int - 1 +pointer(s::String, i::Integer) = pointer(s) + _Int(i) - 1 ncodeunits(s::String) = Core.sizeof(s) codeunit(s::String) = UInt8 -codeunit(s::String, i::Integer) = codeunit(s, Int(i)) +codeunit(s::String, i::Integer) = codeunit(s, _Int(i)) @assume_effects :foldable @inline function codeunit(s::String, i::Int) @boundscheck checkbounds(s, i) b = GC.@preserve s unsafe_load(pointer(s, i)) @@ -359,7 +359,7 @@ const _UTF8_DFA_TABLE = let # let block rather than function doesn't pollute bas row = _UTF8DFAState(0) for j in 1:num_states #Calculate the shift required for the next state - to_shift = UInt8((state_shifts[state_arrays[i,j]+1]) ) + to_shift = _UInt8((state_shifts[state_arrays[i,j]+1]) ) #Shift the next state into the position of the current state row = row | (_UTF8DFAState(to_shift) << state_shifts[j]) end @@ -453,7 +453,7 @@ is_valid_continuation(c) = c & 0xc0 == 0x80 @inline function iterate(s::String, i::Int=firstindex(s)) (i % UInt) - 1 < ncodeunits(s) || return nothing b = @inbounds codeunit(s, i) - u = UInt32(b) << 24 + u = _UInt32(b) << 24 between(b, 0x80, 0xf7) || return reinterpret(Char, u), i+1 return @noinline iterate_continued(s, i, u) end @@ -466,24 +466,24 @@ function iterate_continued(s, i::Int, u::UInt32) (i += 1) > n && @goto ret @inbounds b = codeunit(s, i) b & 0xc0 == 0x80 || @goto ret - u |= UInt32(b) << 16 + u |= _UInt32(b) << 16 # second continuation byte ((i += 1) > n) | (u < 0xe0000000) && @goto ret @inbounds b = codeunit(s, i) b & 0xc0 == 0x80 || @goto ret - u |= UInt32(b) << 8 + u |= _UInt32(b) << 8 # third continuation byte ((i += 1) > n) | (u < 0xf0000000) && @goto ret @inbounds b = codeunit(s, i) b & 0xc0 == 0x80 || @goto ret - u |= UInt32(b); i += 1 + u |= _UInt32(b); i += 1 @label ret return reinterpret(Char, u), i end @propagate_inbounds function getindex(s::String, i::Int) b = codeunit(s, i) - u = UInt32(b) << 24 + u = _UInt32(b) << 24 between(b, 0x80, 0xf7) || return reinterpret(Char, u) return getindex_continued(s, i, u) end @@ -500,22 +500,22 @@ function getindex_continued(s, i::Int, u::UInt32) (i += 1) > n && @goto ret @inbounds b = codeunit(s, i) # cont byte 1 b & 0xc0 == 0x80 || @goto ret - u |= UInt32(b) << 16 + u |= _UInt32(b) << 16 ((i += 1) > n) | (u < 0xe0000000) && @goto ret @inbounds b = codeunit(s, i) # cont byte 2 b & 0xc0 == 0x80 || @goto ret - u |= UInt32(b) << 8 + u |= _UInt32(b) << 8 ((i += 1) > n) | (u < 0xf0000000) && @goto ret @inbounds b = codeunit(s, i) # cont byte 3 b & 0xc0 == 0x80 || @goto ret - u |= UInt32(b) + u |= _UInt32(b) @label ret return reinterpret(Char, u) end -getindex(s::String, r::AbstractUnitRange{<:Integer}) = s[Int(first(r)):Int(last(r))] +getindex(s::String, r::AbstractUnitRange{<:Integer}) = s[_Int(first(r)):_Int(last(r))] @inline function getindex(s::String, r::UnitRange{Int}) isempty(r) && return "" @@ -595,8 +595,8 @@ julia> repeat('A', 3) """ function repeat(c::AbstractChar, r::Integer) r < 0 && throw(ArgumentError("can't repeat a character $r times")) - r = UInt(r)::UInt - c = Char(c)::Char + r = _UInt(r) + c = _Char(c) r == 0 && return "" u = bswap(reinterpret(UInt32, c)) n = 4 - (leading_zeros(u | 0xff) >> 3) diff --git a/base/strings/substring.jl b/base/strings/substring.jl index 860895207f444..71faa6f83c4b6 100644 --- a/base/strings/substring.jl +++ b/base/strings/substring.jl @@ -48,7 +48,7 @@ end @propagate_inbounds SubString(s::T, i::Int, j::Int) where {T<:AbstractString} = SubString{T}(s, i, j) @propagate_inbounds SubString(s::T, i::Int, j::Int, v::Val{:noshift}) where {T<:AbstractString} = SubString{T}(s, i, j, v) -@propagate_inbounds SubString(s::AbstractString, i::Integer, j::Integer=lastindex(s)) = SubString(s, Int(i), Int(j)) +@propagate_inbounds SubString(s::AbstractString, i::Integer, j::Integer=lastindex(s)) = SubString(s, _Int(i), _Int(j)) @propagate_inbounds SubString(s::AbstractString, r::AbstractUnitRange{<:Integer}) = SubString(s, first(r), last(r)) @propagate_inbounds function SubString(s::SubString, i::Int, j::Int) @@ -270,7 +270,7 @@ end function repeat(s::Union{String, SubString{String}}, r::Integer) r < 0 && throw(ArgumentError("can't repeat a string $r times")) - r = UInt(r)::UInt + r = _UInt(r) r == 0 && return "" r == 1 && return String(s) n = sizeof(s) diff --git a/base/strings/unicode.jl b/base/strings/unicode.jl index 520226aacd3cb..ba698bcc7efd6 100644 --- a/base/strings/unicode.jl +++ b/base/strings/unicode.jl @@ -8,6 +8,8 @@ import Base: show, ==, hash, string, Symbol, isless, length, eltype, AnnotatedString, AnnotatedChar, annotated_chartransform, @assume_effects, annotations, is_overlong_enc +using .._ConstructingFunctions + # whether codepoints are valid Unicode scalar values, i.e. 0-0xd7ff, 0xe000-0x10ffff """ @@ -149,7 +151,7 @@ utf8proc_error(result) = error(unsafe_string(ccall(:utf8proc_errmsg, Cstring, (C # static wrapper around user callback function utf8proc_custom_func(codepoint::UInt32, callback::Any) = - UInt32(callback(codepoint))::UInt32 + _UInt32(callback(codepoint)) function utf8proc_decompose(str, options, buffer, nwords, chartransform::typeof(identity)) ret = ccall(:utf8proc_decompose, Int, (Ptr{UInt8}, Int, Ptr{UInt8}, Int, Cint), @@ -171,7 +173,7 @@ function utf8proc_map(str::Union{String,SubString{String}}, options::Integer, ch nwords = utf8proc_decompose(str, options, buffer, nwords, chartransform) nbytes = ccall(:utf8proc_reencode, Int, (Ptr{UInt8}, Int, Cint), buffer, nwords, options) nbytes < 0 && utf8proc_error(nbytes) - return String(resize!(buffer, nbytes)) + return _String(resize!(buffer, nbytes)) end """ @@ -191,7 +193,7 @@ const _julia_charmap = Dict{UInt32,UInt32}( 0x210F => 0x0127, # hbar -> small letter h with stroke (#48870) ) -utf8proc_map(s::AbstractString, flags::Integer, chartransform::F = identity) where F = utf8proc_map(String(s), flags, chartransform) +utf8proc_map(s::AbstractString, flags::Integer, chartransform::F = identity) where F = utf8proc_map(_String(s), flags, chartransform) # Documented in Unicode module function normalize( @@ -262,12 +264,12 @@ julia> textwidth('⛵') 2 ``` """ -textwidth(c::AbstractChar) = textwidth(Char(c)::Char) +textwidth(c::AbstractChar) = textwidth(_Char(c)) function textwidth(c::Char) u = reinterpret(UInt32, c) b = bswap(u) # from isascii(c) - b < 0x7f && return Int(b >= 0x20) # ASCII fast path + b < 0x7f && return _Int(b >= 0x20) # ASCII fast path # We can't know a priori how terminals will render invalid UTF8 chars, # so we conservatively decide a width of 1. (ismalformed(c) || is_overlong_enc(u)) && return 1 @@ -360,7 +362,7 @@ titlecase(c::AnnotatedChar) = AnnotatedChar(titlecase(c.char), annotations(c)) # returns UTF8PROC_CATEGORY code in 0:30 giving Unicode category function category_code(c::AbstractChar) - !ismalformed(c) ? category_code(UInt32(c)) : Cint(31) + !ismalformed(c) ? category_code(_UInt32(c)) : Cint(31) end function category_code(x::Integer) diff --git a/base/strings/util.jl b/base/strings/util.jl index c3df790cd81e6..70800b9c0320e 100644 --- a/base/strings/util.jl +++ b/base/strings/util.jl @@ -96,7 +96,7 @@ function Base.startswith(io::IO, prefix::Union{String,SubString{String}}) reset(io) return s == codeunits(prefix) end -Base.startswith(io::IO, prefix::AbstractString) = startswith(io, String(prefix)) +Base.startswith(io::IO, prefix::AbstractString) = startswith(io, _String(prefix)) function endswith(a::Union{String, SubString{String}}, b::Union{String, SubString{String}}) @@ -483,10 +483,10 @@ function lpad( ) stringfn = if _isannotated(s) || _isannotated(p) annotatedstring else string end - n = Int(n)::Int - m = signed(n) - Int(textwidth(s))::Int + n = _Int(n) + m = signed(n) - _Int(textwidth(s)) m ≤ 0 && return stringfn(s) - l = Int(textwidth(p))::Int + l = _Int(textwidth(p)) if l == 0 throw(ArgumentError("$(repr(p)) has zero textwidth" * (ncodeunits(p) != 1 ? "" : "; maybe you want pad^max(0, npad - ncodeunits(str)) * str to pad by codeunits" * @@ -520,10 +520,10 @@ function rpad( ) stringfn = if _isannotated(s) || _isannotated(p) annotatedstring else string end - n = Int(n)::Int - m = signed(n) - Int(textwidth(s))::Int + n = _Int(n) + m = signed(n) - _Int(textwidth(s)) m ≤ 0 && return stringfn(s) - l = Int(textwidth(p))::Int + l = _Int(textwidth(p)) if l == 0 throw(ArgumentError("$(repr(p)) has zero textwidth" * (ncodeunits(p) != 1 ? "" : "; maybe you want str * pad^max(0, npad - ncodeunits(str)) to pad by codeunits" * @@ -557,7 +557,7 @@ julia> rtruncate("foo", 3) See also [`ltruncate`](@ref) and [`ctruncate`](@ref). """ function rtruncate(str::AbstractString, maxwidth::Integer, replacement::Union{AbstractString,AbstractChar} = '…') - ret = string_truncate_boundaries(str, Int(maxwidth), replacement, Val(:right)) + ret = string_truncate_boundaries(str, _Int(maxwidth), replacement, Val(:right)) if isnothing(ret) return string(str) else @@ -590,7 +590,7 @@ julia> ltruncate("foo", 3) See also [`rtruncate`](@ref) and [`ctruncate`](@ref). """ function ltruncate(str::AbstractString, maxwidth::Integer, replacement::Union{AbstractString,AbstractChar} = '…') - ret = string_truncate_boundaries(str, Int(maxwidth), replacement, Val(:left)) + ret = string_truncate_boundaries(str, _Int(maxwidth), replacement, Val(:left)) if isnothing(ret) return string(str) else @@ -624,7 +624,7 @@ julia> ctruncate("foo", 3) See also [`ltruncate`](@ref) and [`rtruncate`](@ref). """ function ctruncate(str::AbstractString, maxwidth::Integer, replacement::Union{AbstractString,AbstractChar} = '…'; prefer_left::Bool = true) - ret = string_truncate_boundaries(str, Int(maxwidth), replacement, Val(:center), prefer_left) + ret = string_truncate_boundaries(str, _Int(maxwidth), replacement, Val(:center), prefer_left) if isnothing(ret) return string(str) else @@ -996,7 +996,7 @@ function _replace_finish(io::IO, str, count::Int, j > e1 && break if i == a || i <= k # copy out preserved portion - GC.@preserve str unsafe_write(io, pointer(str, i), UInt(j-i)) + GC.@preserve str unsafe_write(io, pointer(str, i), _UInt(j-i)) # copy out replacement string _replace(io, replaces[p], str, r, patterns[p]) end @@ -1044,11 +1044,11 @@ end # note: leave str untyped here to make it easier for packages like StringViews to hook in function _replace_(str, pat_repl::NTuple{N, Pair}, count::Int) where N - count == 0 && return String(str) + count == 0 && return _String(str) e1, patterns, replaces, rs, notfound = _replace_init(str, pat_repl, count) if notfound foreach(_free_pat_replacer, patterns) - return String(str) + return _String(str) end out = IOBuffer(sizehint=floor(Int, 1.2sizeof(str))) return takestring!(_replace_finish(out, str, count, e1, patterns, replaces, rs)) @@ -1105,10 +1105,10 @@ julia> replace("abcabc", "a" => "b", "b" => "c", r".+" => "a") ``` """ replace(io::IO, s::AbstractString, pat_f::Pair...; count=typemax(Int)) = - _replace_(io, String(s), pat_f, Int(count)) + _replace_(io, _String(s), pat_f, _Int(count)) replace(s::AbstractString, pat_f::Pair...; count=typemax(Int)) = - _replace_(String(s), pat_f, Int(count)) + _replace_(_String(s), pat_f, _Int(count)) # TODO: allow transform as the first argument to replace? @@ -1195,7 +1195,7 @@ function hex2bytes!(dest::AbstractArray{UInt8}, itr) return dest end -@inline number_from_hex(c::AbstractChar) = number_from_hex(Char(c)) +@inline number_from_hex(c::AbstractChar) = number_from_hex(_Char(c)) @inline number_from_hex(c::Char) = number_from_hex(UInt8(c)) @inline function number_from_hex(c::UInt8) UInt8('0') <= c <= UInt8('9') && return c - UInt8('0') @@ -1246,7 +1246,7 @@ end function bytes2hex(io::IO, itr) eltype(itr) === UInt8 || throw(ArgumentError("eltype of iterator not UInt8")) for x in itr - print(io, Char(hex_chars[1 + x >> 4]), Char(hex_chars[1 + x & 0xf])) + print(io, _Char(hex_chars[1 + x >> 4]), _Char(hex_chars[1 + x & 0xf])) end end @@ -1278,7 +1278,7 @@ julia> ascii("abcdefgh") "abcdefgh" ``` """ -ascii(x::AbstractString) = ascii(String(x)) +ascii(x::AbstractString) = ascii(_String(x)) Base.rest(s::Union{String,SubString{String}}, i=1) = SubString(s, i) function Base.rest(s::AbstractString, st...) diff --git a/base/sysinfo.jl b/base/sysinfo.jl index 06e5cd298caf1..818965c8b7ec4 100644 --- a/base/sysinfo.jl +++ b/base/sysinfo.jl @@ -676,7 +676,7 @@ function which(program_name::String) # If we couldn't find anything, don't return anything nothing end -which(program_name::AbstractString) = which(String(program_name)) +which(program_name::AbstractString) = which(_String(program_name)) """ Sys.username()::String diff --git a/base/terminfo.jl b/base/terminfo.jl index be0dd53b1ac74..748279ec36382 100644 --- a/base/terminfo.jl +++ b/base/terminfo.jl @@ -85,7 +85,7 @@ function read(data::IO, ::Type{TermInfoRaw}) name_bytes, flag_bytes, numbers_count, string_count, table_bytes = @ntuple 5 _->read(data, Int16) |> ltoh # Terminal Names - term_names = map(String, split(String(read(data, name_bytes - 1)), '|')) + term_names = map(String, split(_String(read(data, name_bytes - 1)), '|')) 0x00 == read(data, UInt8) || throw(ArgumentError("Terminfo data did not contain a null byte after the terminal names section")) # Boolean Flags @@ -131,7 +131,7 @@ function extendedterminfo(data::IO, NumInt::Union{Type{Int16}, Type{Int32}}) table_indices = map(ltoh, reinterpret(Int16, read(data, table_count * sizeof(Int16)))) table_data = read(data, table_bytes) strings = _terminfo_read_strings(table_data, table_indices[1:string_count]) - table_halfoffset = Int16(get(table_indices, string_count, 0) + + table_halfoffset = _Int16(get(table_indices, string_count, 0) + ncodeunits(something(get(strings, length(strings), ""), "")) + 1) for index in string_count+1:lastindex(table_indices) table_indices[index] += table_halfoffset @@ -183,7 +183,7 @@ function TermInfo(raw::TermInfoRaw) aliases[flag.capname] = flag.name end for (num, value) in zip(TERM_NUMBERS, raw.numbers) - numbers[num.name] = Int(value) + numbers[num.name] = _Int(value) aliases[num.capname] = num.name end for (str, value) in zip(TERM_STRINGS, raw.strings) @@ -250,7 +250,7 @@ taken to be the first entry of `@TERMINFO_DIRS@`. """ function find_terminfo_file(term::String) isempty(term) && return - chr, chrcode = string(first(term)), string(Int(first(term)), base=16) + chr, chrcode = string(first(term)), string(_Int(first(term)), base=16) terminfo_dirs = if haskey(ENV, "TERMINFO") [ENV["TERMINFO"]] elseif isdir(joinpath(homedir(), ".terminfo")) diff --git a/base/timing.jl b/base/timing.jl index 998103d1e78bc..2db533a5c6326 100644 --- a/base/timing.jl +++ b/base/timing.jl @@ -202,7 +202,7 @@ function format_bytes(bytes; binary=true) # also used by InteractiveUtils factor = binary ? 1024 : 1000 bytes, mb = prettyprint_getunits(bytes, length(units), Int64(factor)) if mb == 1 - return string(Int(bytes), " ", _mem_units[mb], bytes==1 ? "" : "s") + return string(_Int(bytes), " ", _mem_units[mb], bytes==1 ? "" : "s") else return string(Ryu.writefixed(Float64(bytes), 3), binary ? " $(units[mb])" : "$(units[mb])B") end @@ -223,7 +223,7 @@ function time_print(io::IO, elapsedtime, bytes=0, gctime=0, allocs=0, lock_confl if bytes != 0 || allocs != 0 allocs, ma = prettyprint_getunits(allocs, length(_cnt_units), Int64(1000)) if ma == 1 - print(io, Int(allocs), _cnt_units[ma], allocs==1 ? " allocation: " : " allocations: ") + print(io, _Int(allocs), _cnt_units[ma], allocs==1 ? " allocation: " : " allocations: ") else print(io, Ryu.writefixed(Float64(allocs), 2), _cnt_units[ma], " allocations: ") end diff --git a/base/toml_parser.jl b/base/toml_parser.jl index bf13fc2b0617a..94a6b5da032bf 100644 --- a/base/toml_parser.jl +++ b/base/toml_parser.jl @@ -8,6 +8,7 @@ TOML.jl standard library instead (by `import TOML` or `using TOML`). module TOML using Base: IdSet +using .._ConstructingFunctions # we parse DateTime into these internal structs, # unless a different DateTime library is passed to the Parser constructor @@ -617,7 +618,7 @@ function _parse_key(l::Parser) c = eat_char(l) return ParserError(ErrInvalidBareKeyCharacter, c) end - String(take_substring(l)) + _String(take_substring(l)) else c = eat_char(l) return ParserError(ErrInvalidBareKeyCharacter, c) diff --git a/base/tuple.jl b/base/tuple.jl index 62a07f7ecf6a2..d4d1e86e744f9 100644 --- a/base/tuple.jl +++ b/base/tuple.jl @@ -144,8 +144,8 @@ CartesianIndex(1, 3) """ function nextind end -prevind(@nospecialize(t::Tuple), i::Integer) = Int(i)-1 -nextind(@nospecialize(t::Tuple), i::Integer) = Int(i)+1 +prevind(@nospecialize(t::Tuple), i::Integer) = _Int(i)-1 +nextind(@nospecialize(t::Tuple), i::Integer) = _Int(i)+1 function keys(t::Tuple, t2::Tuple...) @inline diff --git a/base/twiceprecision.jl b/base/twiceprecision.jl index 920ba71eba24f..c7a889d73d848 100644 --- a/base/twiceprecision.jl +++ b/base/twiceprecision.jl @@ -407,7 +407,7 @@ function (:)(start::T, step::T, stop::T) where T<:IEEEFloat rem(den, start_d) == 0 && rem(den, step_d) == 0 # check lcm overflow start_n = round(Int, start*den) step_n = round(Int, step*den) - len = max(0, Int(div(den*stop_n - stop_d*start_n + step_n*stop_d, step_n*stop_d))) + len = max(0, _Int(div(den*stop_n - stop_d*start_n + step_n*stop_d, step_n*stop_d))) # Integer ops could overflow, so check that this makes sense if isbetween(start, start + (len-1)*step, stop + step/2) && !isbetween(start, start + len*step, stop) diff --git a/base/util.jl b/base/util.jl index b11757b3d771a..2bc1e38e9ee9a 100644 --- a/base/util.jl +++ b/base/util.jl @@ -496,7 +496,7 @@ if Sys.iswindows() # Done. passbuf_ = passbuf[1:passlen[]-1] - result = (String(transcode(UInt8, usernamebuf[1:usernamelen[]-1])), + result = (_String(transcode(UInt8, usernamebuf[1:usernamelen[]-1])), SecretBuffer!(transcode(UInt8, passbuf_))) securezero!(passbuf_) securezero!(passbuf) diff --git a/base/uuid.jl b/base/uuid.jl index 4b9bae863d926..22209aa170c4f 100644 --- a/base/uuid.jl +++ b/base/uuid.jl @@ -40,7 +40,7 @@ _crc32c(uuid::UUID, crc::UInt32=0x00000000) = _crc32c(uuid.value, crc) let @inline function uuid_kernel(s, i, u) - _c = UInt32(@inbounds codeunit(s, i)) + _c = _UInt32(@inbounds codeunit(s, i)) d = __convert_digit(_c, UInt32(16)) d >= 16 && return nothing u <<= 4 diff --git a/base/version.jl b/base/version.jl index 71192916a5b22..b129d3a433490 100644 --- a/base/version.jl +++ b/base/version.jl @@ -82,8 +82,8 @@ VersionNumber(major::Integer, minor::Integer = 0, patch::Integer = 0, pre::Tuple{Vararg{Union{Integer,AbstractString}}} = (), bld::Tuple{Vararg{Union{Integer,AbstractString}}} = ()) = VersionNumber(VInt(major), VInt(minor), VInt(patch), - map(x->x isa Integer ? UInt64(x) : String(x), pre), - map(x->x isa Integer ? UInt64(x) : String(x), bld)) + map(x->x isa Integer ? _UInt64(x) : _String(x), pre), + map(x->x isa Integer ? _UInt64(x) : _String(x), bld)) VersionNumber(v::Tuple) = VersionNumber(v...) VersionNumber(v::VersionNumber) = v @@ -122,13 +122,13 @@ $"ix function split_idents(s::AbstractString) idents = eachsplit(s, '.') - pidents = Union{UInt64,String}[occursin(r"^\d+$", ident) ? parse(UInt64, ident) : String(ident) for ident in idents] + pidents = Union{UInt64,String}[occursin(r"^\d+$", ident) ? parse(UInt64, ident) : _String(ident) for ident in idents] return tuple(pidents...)::VerTuple end function tryparse(::Type{VersionNumber}, v::AbstractString) v == "∞" && return typemax(VersionNumber) - m = match(VERSION_REGEX, String(v)::String) + m = match(VERSION_REGEX, _String(v)) m === nothing && return nothing major, minor, patch, minus, prerl, plus, build = m.captures major = parse(VInt, major::AbstractString) From 5535aaf15ca51839f8c496dc7a4f20814e5b74c3 Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Mon, 1 Sep 2025 05:54:00 +0200 Subject: [PATCH 4/4] revert all changes that add a typeassert where there was none --- base/abstractarray.jl | 18 ++++++------- base/abstractarraymath.jl | 4 +-- base/array.jl | 26 +++++++++--------- base/arraymath.jl | 2 +- base/binaryplatforms.jl | 2 +- base/bitarray.jl | 50 +++++++++++++++++------------------ base/broadcast.jl | 8 +++--- base/char.jl | 24 ++++++++--------- base/client.jl | 4 +-- base/cmd.jl | 2 +- base/deprecated.jl | 2 +- base/docs/Docs.jl | 3 +-- base/env.jl | 2 +- base/file.jl | 6 ++--- base/filesystem.jl | 8 +++--- base/flfrontend.jl | 2 +- base/float.jl | 2 +- base/gmp.jl | 16 +++++------ base/hashing.jl | 40 ++++++++++++++-------------- base/io.jl | 8 +++--- base/iobuffer.jl | 4 +-- base/iterators.jl | 17 +++++------- base/loading.jl | 32 +++++++++++----------- base/logging/ConsoleLogger.jl | 2 +- base/logging/logging.jl | 2 +- base/meta.jl | 6 ++--- base/methodshow.jl | 8 +++--- base/multidimensional.jl | 12 ++++----- base/multimedia.jl | 5 ++-- base/namedtuple.jl | 4 +-- base/parse.jl | 6 ++--- base/path.jl | 14 +++++----- base/pcre.jl | 6 ++--- base/pointer.jl | 16 +++++------ base/precompilation.jl | 10 +++---- base/regex.jl | 16 +++++------ base/secretbuffer.jl | 4 +-- base/show.jl | 2 +- base/sort.jl | 4 +-- base/stat.jl | 4 +-- base/stream.jl | 12 ++++----- base/strings/annotated_io.jl | 4 +-- base/strings/basic.jl | 30 ++++++++++----------- base/strings/cstring.jl | 20 +++++++------- base/strings/io.jl | 14 +++++----- base/strings/search.jl | 12 ++++----- base/strings/string.jl | 24 ++++++++--------- base/strings/substring.jl | 2 +- base/strings/unicode.jl | 8 +++--- base/strings/util.jl | 24 ++++++++--------- base/sysinfo.jl | 2 +- base/terminfo.jl | 8 +++--- base/timing.jl | 4 +-- base/toml_parser.jl | 3 +-- base/tuple.jl | 4 +-- base/twiceprecision.jl | 2 +- base/util.jl | 2 +- base/uuid.jl | 2 +- base/version.jl | 6 ++--- 59 files changed, 286 insertions(+), 300 deletions(-) diff --git a/base/abstractarray.jl b/base/abstractarray.jl index a86041052490a..3eaa34f268937 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -212,8 +212,8 @@ String """ valtype(A::Type{<:AbstractArray}) = eltype(A) -prevind(::AbstractArray, i::Integer) = _Int(i)-1 -nextind(::AbstractArray, i::Integer) = _Int(i)+1 +prevind(::AbstractArray, i::Integer) = Int(i)-1 +nextind(::AbstractArray, i::Integer) = Int(i)+1 """ @@ -838,10 +838,10 @@ to_shape(dims::Dims) = dims to_shape(dims::DimsOrInds) = map(to_shape, dims)::DimsOrInds # each dimension to_shape(i::Int) = i -to_shape(i::Integer) = _Int(i) +to_shape(i::Integer) = Int(i) to_shape(r::AbstractOneTo) = _to_shape(last(r)) _to_shape(x::Integer) = to_shape(x) -_to_shape(x) = _Int(x) +_to_shape(x) = Int(x) to_shape(r::AbstractUnitRange) = r """ @@ -951,7 +951,7 @@ function copyto!(dest::AbstractArray, src) end function copyto!(dest::AbstractArray, dstart::Integer, src) - i = _Int(dstart) + i = Int(dstart) if haslength(src) && length(dest) > 0 @boundscheck checkbounds(dest, i:(i + length(src) - 1)) for x in src @@ -986,7 +986,7 @@ function copyto!(dest::AbstractArray, dstart::Integer, src, sstart::Integer) "source has fewer elements than required, ", "expected at least ",sstart," got ", sstart-1))) end - i = _Int(dstart) + i = Int(dstart) while y !== nothing val, st = y dest[i] = val @@ -1023,7 +1023,7 @@ function copyto!(dest::AbstractArray, dstart::Integer, src, sstart::Integer, n:: "expected at least ",sstart," got ", sstart-1))) end val, st = y - i = _Int(dstart) + i = Int(dstart) @inbounds dest[i] = val for val in Iterators.take(Iterators.rest(src, st), n-1) i += 1 @@ -1601,8 +1601,8 @@ parts can specialize this method to return the concatenation of the `dataids` of their component parts. A typical definition for an array that wraps a parent is `Base.dataids(C::CustomArray) = dataids(C.parent)`. """ -dataids(A::AbstractArray) = (_UInt(objectid(A)),) -dataids(A::Memory) = (_UInt(A.ptr),) +dataids(A::AbstractArray) = (UInt(objectid(A)),) +dataids(A::Memory) = (UInt(A.ptr),) dataids(A::Array) = dataids(A.ref.mem) dataids(::AbstractRange) = () dataids(x) = () diff --git a/base/abstractarraymath.jl b/base/abstractarraymath.jl index 4c8ec516ef383..66c75cf977c56 100644 --- a/base/abstractarraymath.jl +++ b/base/abstractarraymath.jl @@ -91,7 +91,7 @@ function _dropdims(A::AbstractArray, dims::Dims) ax = _foldoneto((ds, d) -> d in dims ? ds : (ds..., axes(A,d)), (), Val(ndims(A))) reshape(A, ax::typeof(_sub(axes(A), dims))) end -_dropdims(A::AbstractArray, dim::Integer) = _dropdims(A, (_Int(dim),)) +_dropdims(A::AbstractArray, dim::Integer) = _dropdims(A, (Int(dim),)) """ @@ -153,7 +153,7 @@ function _insertdims(A::AbstractArray{T, N}, dims::NTuple{M, Int}) where {T, N, new_shape = inds[1] return reshape(A, new_shape) end -_insertdims(A::AbstractArray, dim::Integer) = _insertdims(A, (_Int(dim),)) +_insertdims(A::AbstractArray, dim::Integer) = _insertdims(A, (Int(dim),)) diff --git a/base/array.jl b/base/array.jl index 8eafff528a212..7a693d5691c77 100644 --- a/base/array.jl +++ b/base/array.jl @@ -672,7 +672,7 @@ _similar_for(c::AbstractArray, ::Type{T}, itr, ::HasShape, axs) where {T} = # make a collection appropriate for collecting `itr::Generator` _array_for(::Type{T}, ::SizeUnknown, ::Nothing) where {T} = Vector{T}(undef, 0) -_array_for(::Type{T}, ::HasLength, len::Integer) where {T} = Vector{T}(undef, _Int(len)) +_array_for(::Type{T}, ::HasLength, len::Integer) where {T} = Vector{T}(undef, Int(len)) _array_for(::Type{T}, ::HasShape{N}, axs) where {T,N} = similar(Array{T,N}, axs) # used by syntax lowering for simple typed comprehensions @@ -1112,7 +1112,7 @@ end function _growbeg!(a::Vector, delta::Integer) @_noub_meta - delta = _Int(delta) + delta = Int(delta) delta == 0 && return # avoid attempting to index off the end delta >= 0 || throw(ArgumentError("grow requires delta >= 0")) ref = a.ref @@ -1167,7 +1167,7 @@ end function _growend!(a::Vector, delta::Integer) @_noub_meta - delta = _Int(delta) + delta = Int(delta) delta >= 0 || throw(ArgumentError("grow requires delta >= 0")) ref = a.ref mem = ref.mem @@ -1185,8 +1185,8 @@ end function _growat!(a::Vector, i::Integer, delta::Integer) @_terminates_globally_noub_meta - delta = _Int(delta) - i = _Int(i) + delta = Int(delta) + i = Int(i) i == 1 && return _growbeg!(a, delta) len = length(a) i == len + 1 && return _growend!(a, delta) @@ -1230,7 +1230,7 @@ end # efficiently delete part of an array function _deletebeg!(a::Vector, delta::Integer) - delta = _Int(delta) + delta = Int(delta) len = length(a) 0 <= delta <= len || throw(ArgumentError("_deletebeg! requires delta in 0:length(a)")) for i in 1:delta @@ -1245,7 +1245,7 @@ function _deletebeg!(a::Vector, delta::Integer) return end function _deleteend!(a::Vector, delta::Integer) - delta = _Int(delta) + delta = Int(delta) len = length(a) 0 <= delta <= len || throw(ArgumentError("_deleteend! requires delta in 0:length(a)")) newlen = len - delta @@ -1256,7 +1256,7 @@ function _deleteend!(a::Vector, delta::Integer) return end function _deleteat!(a::Vector, i::Integer, delta::Integer) - i = _Int(i) + i = Int(i) len = length(a) 0 <= delta || throw(ArgumentError("_deleteat! requires delta >= 0")) 1 <= i <= len || throw(BoundsError(a, i)) @@ -1551,7 +1551,7 @@ function sizehint!(a::Vector, sz::Integer; first::Bool=false, shrink::Bool=true) ref = a.ref mem = ref.mem memlen = length(mem) - sz = max(_Int(sz), len) + sz = max(Int(sz), len) inc = sz - len if sz <= memlen # if we don't save at least 1/8th memlen then its not worth it to shrink @@ -2185,7 +2185,7 @@ julia> reverse(A, 3, 5) ``` """ function reverse(A::AbstractVector, start::Integer, stop::Integer=lastindex(A)) - s, n = _Int(start), _Int(stop) + s, n = Int(start), Int(stop) B = similar(A) for i = firstindex(A):s-1 B[i] = A[i] @@ -2249,7 +2249,7 @@ julia> A ``` """ function reverse!(v::AbstractVector, start::Integer, stop::Integer=lastindex(v)) - s, n = _Int(start), _Int(stop) + s, n = Int(start), Int(stop) if n > s # non-empty and non-trivial liv = LinearIndices(v) if !(first(liv) ≤ s ≤ last(liv)) @@ -3196,12 +3196,12 @@ end $(Expr(:new, :(Array{T, N}), :ref, :dims)) end @eval @propagate_inbounds function wrap(::Type{Array}, m::MemoryRef{T}, l::Integer) where {T} - dims = (_Int(l),) + dims = (Int(l),) ref = _wrap(m, dims) $(Expr(:new, :(Array{T, 1}), :ref, :dims)) end @eval @propagate_inbounds function wrap(::Type{Array}, m::Memory{T}, l::Integer) where {T} - dims = (_Int(l),) + dims = (Int(l),) ref = _wrap(memoryref(m), (l,)) $(Expr(:new, :(Array{T, 1}), :ref, :dims)) end diff --git a/base/arraymath.jl b/base/arraymath.jl index e132cf680911a..53a7d132a2c0c 100644 --- a/base/arraymath.jl +++ b/base/arraymath.jl @@ -69,7 +69,7 @@ Like [`reverse`](@ref), but operates in-place in `A`. """ reverse!(A::AbstractArray; dims=:) = _reverse!(A, dims) _reverse!(A::AbstractArray{<:Any,N}, ::Colon) where {N} = _reverse!(A, ntuple(identity, Val{N}())) -_reverse!(A, dim::Integer) = _reverse!(A, (_Int(dim),)) +_reverse!(A, dim::Integer) = _reverse!(A, (Int(dim),)) _reverse!(A, dims::NTuple{M,Integer}) where {M} = _reverse!(A, Int.(dims)) function _reverse!(A::AbstractArray{<:Any,N}, dims::NTuple{M,Int}) where {N,M} dims === () && return A # nothing to reverse diff --git a/base/binaryplatforms.jl b/base/binaryplatforms.jl index 5cedb6cfbdc28..1efa3e83bfb9f 100644 --- a/base/binaryplatforms.jl +++ b/base/binaryplatforms.jl @@ -741,7 +741,7 @@ function Base.parse(::Type{Platform}, triplet::String; validate_strict::Bool = f if isempty(tag_fields) return Pair{String,String}[] end - return map(v -> _String(v[1]) => _String(v[2]), split.(tag_fields, "+")) + return map(v -> String(v[1]) => String(v[2]), split.(tag_fields, "+")) end merge!(tags, Dict(split_tags(m["tags"]))) diff --git a/base/bitarray.jl b/base/bitarray.jl index 039d9fc26a166..8599d1b6e3555 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -456,12 +456,12 @@ function copyto!(dest::BitArray, src::BitArray) end function unsafe_copyto!(dest::BitArray, doffs::Integer, src::Union{BitArray,Array}, soffs::Integer, n::Integer) - copy_to_bitarray_chunks!(dest.chunks, _Int(doffs), src, _Int(soffs), _Int(n)) + copy_to_bitarray_chunks!(dest.chunks, Int(doffs), src, Int(soffs), Int(n)) return dest end copyto!(dest::BitArray, doffs::Integer, src::Union{BitArray,Array}, soffs::Integer, n::Integer) = - _copyto_int!(dest, _Int(doffs), src, _Int(soffs), _Int(n)) + _copyto_int!(dest, Int(doffs), src, Int(soffs), Int(n)) function _copyto_int!(dest::BitArray, doffs::Int, src::Union{BitArray,Array}, soffs::Int, n::Int) n == 0 && return dest n < 0 && throw(ArgumentError("Number of elements to copy must be non-negative.")) @@ -811,7 +811,7 @@ function sizehint!(B::BitVector, sz::Integer) return B end -resize!(B::BitVector, n::Integer) = _resize_int!(B, _Int(n)) +resize!(B::BitVector, n::Integer) = _resize_int!(B, Int(n)) function _resize_int!(B::BitVector, n::Int) n0 = length(B) n == n0 && return B @@ -861,7 +861,7 @@ function pushfirst!(B::BitVector, item) for i = length(Bc) : -1 : 2 Bc[i] = (Bc[i] << 1) | (Bc[i-1] >>> 63) end - Bc[1] = _UInt64(item) | (Bc[1] << 1) + Bc[1] = UInt64(item) | (Bc[1] << 1) return B end @@ -888,9 +888,9 @@ function popfirst!(B::BitVector) return item end -insert!(B::BitVector, i::Integer, item) = _insert_int!(B, _Int(i), item) +insert!(B::BitVector, i::Integer, item) = _insert_int!(B, Int(i), item) function _insert_int!(B::BitVector, i::Int, item) - i = _Int(i) + i = Int(i) n = length(B) 1 <= i <= n+1 || throw(BoundsError(B, i)) item = convert(Bool, item) @@ -952,7 +952,7 @@ end function deleteat!(B::BitVector, i::Integer) i isa Bool && depwarn("passing Bool as an index is deprecated", :deleteat!) - i = _Int(i) + i = Int(i) n = length(B) 1 <= i <= n || throw(BoundsError(B, i)) @@ -1005,14 +1005,14 @@ function deleteat!(B::BitVector, inds) end new_l -= 1 if i > q - copy_chunks!(Bc, _Int(p), Bc, _Int(q), _Int(i-q)) + copy_chunks!(Bc, Int(p), Bc, Int(q), Int(i-q)) p += i-q end q = i+1 y = iterate(inds, s) end - q <= n && copy_chunks!(Bc, _Int(p), Bc, _Int(q), _Int(n-q+1)) + q <= n && copy_chunks!(Bc, Int(p), Bc, Int(q), Int(n-q+1)) delta_k = num_bit_chunks(new_l) - length(Bc) delta_k < 0 && _deleteend!(Bc, -delta_k) @@ -1046,14 +1046,14 @@ function deleteat!(B::BitVector, inds::AbstractVector{Bool}) s = y + 1 new_l -= 1 if i > q - copy_chunks!(Bc, _Int(p), Bc, _Int(q), _Int(i-q)) + copy_chunks!(Bc, Int(p), Bc, Int(q), Int(i-q)) p += i - q end q = i + 1 y = findnext(inds, s) end - q <= n && copy_chunks!(Bc, _Int(p), Bc, _Int(q), _Int(n - q + 1)) + q <= n && copy_chunks!(Bc, Int(p), Bc, Int(q), Int(n - q + 1)) delta_k = num_bit_chunks(new_l) - length(Bc) delta_k < 0 && _deleteend!(Bc, -delta_k) @@ -1075,7 +1075,7 @@ function splice!(B::BitVector, i::Integer) # as v = B[i] is enough to do both bounds checking # and Bool check then just pass Int(i) to _deleteat! i isa Bool && depwarn("passing Bool as an index is deprecated", :splice!) - i = _Int(i) + i = Int(i) n = length(B) 1 <= i <= n || throw(BoundsError(B, i)) @@ -1088,7 +1088,7 @@ const _default_bit_splice = BitVector() function splice!(B::BitVector, r::Union{AbstractUnitRange{Int}, Integer}, ins::AbstractArray = _default_bit_splice) r isa Bool && depwarn("passing Bool as an index is deprecated", :splice!) - _splice_int!(B, isa(r, AbstractUnitRange{Int}) ? r : _Int(r), ins) + _splice_int!(B, isa(r, AbstractUnitRange{Int}) ? r : Int(r), ins) end function _splice_int!(B::BitVector, r, ins) @@ -1134,7 +1134,7 @@ function splice!(B::BitVector, r::Union{AbstractUnitRange{Int}, Integer}, ins) Bins = BitVector(undef, length(ins)) i = 1 for x in ins - Bins[i] = _Bool(x) + Bins[i] = Bool(x) i += 1 end return splice!(B, r, Bins) @@ -1325,7 +1325,7 @@ function (<<)(B::BitVector, i::UInt) n = length(B) i == 0 && return copy(B) A = falses(n) - i < n && copy_chunks!(A.chunks, 1, B.chunks, _Int(i+1), _Int(n-i)) + i < n && copy_chunks!(A.chunks, 1, B.chunks, Int(i+1), Int(n-i)) return A end @@ -1333,7 +1333,7 @@ function (>>>)(B::BitVector, i::UInt) n = length(B) i == 0 && return copy(B) A = falses(n) - i < n && copy_chunks!(A.chunks, _Int(i+1), B.chunks, 1, _Int(n-i)) + i < n && copy_chunks!(A.chunks, Int(i+1), B.chunks, 1, Int(n-i)) return A end @@ -1420,9 +1420,9 @@ details and examples. """ (>>>)(B::BitVector, i::Int) = (i >=0 ? B >> unsigned(i) : B << unsigned(-i)) -circshift!(dest::BitVector, src::BitVector, i::Integer) = _circshift_int!(dest, src, _Int(i)) +circshift!(dest::BitVector, src::BitVector, i::Integer) = _circshift_int!(dest, src, Int(i)) function _circshift_int!(dest::BitVector, src::BitVector, i::Int) - i = _Int(i) + i = Int(i) length(dest) == length(src) || throw(ArgumentError("destination and source should be of same size")) n = length(dest) i %= n @@ -1474,7 +1474,7 @@ end # returns the index of the next true element, or nothing if all false function findnext(B::BitArray, start::Integer) - start = _Int(start) + start = Int(start) start > 0 || throw(BoundsError(B, start)) start > length(B) && return nothing unsafe_bitfindnext(B.chunks, start) @@ -1518,14 +1518,14 @@ findfirstnot(B::BitArray) = findnextnot(B,1) function findnext(pred::Fix2{<:Union{typeof(isequal),typeof(==)},Bool}, B::BitArray, start::Integer) v = pred.x - v == false && return findnextnot(B, _Int(start)) + v == false && return findnextnot(B, Int(start)) v == true && return findnext(B, start) return nothing end #findfirst(B::BitArray, v) = findnext(B, 1, v) ## defined in array.jl # returns the index of the first element for which the function returns true -findnext(testf::Function, B::BitArray, start::Integer) = _findnext_int(testf, B, _Int(start)) +findnext(testf::Function, B::BitArray, start::Integer) = _findnext_int(testf, B, Int(start)) function _findnext_int(testf::Function, B::BitArray, start::Int) f0::Bool = testf(false) f1::Bool = testf(true) @@ -1559,14 +1559,14 @@ end # returns the index of the previous true element, or nothing if all false function findprev(B::BitArray, start::Integer) - start = _Int(start) + start = Int(start) start > 0 || return nothing start > length(B) && throw(BoundsError(B, start)) unsafe_bitfindprev(B.chunks, start) end function findprevnot(B::BitArray, start::Int) - start = _Int(start) + start = Int(start) start > 0 || return nothing start > length(B) && throw(BoundsError(B, start)) @@ -1594,14 +1594,14 @@ findlastnot(B::BitArray) = findprevnot(B, length(B)) function findprev(pred::Fix2{<:Union{typeof(isequal),typeof(==)},Bool}, B::BitArray, start::Integer) v = pred.x - v == false && return findprevnot(B, _Int(start)) + v == false && return findprevnot(B, Int(start)) v == true && return findprev(B, start) return nothing end #findlast(B::BitArray, v) = findprev(B, 1, v) ## defined in array.jl # returns the index of the previous element for which the function returns true -findprev(testf::Function, B::BitArray, start::Integer) = _findprev_int(testf, B, _Int(start)) +findprev(testf::Function, B::BitArray, start::Integer) = _findprev_int(testf, B, Int(start)) function _findprev_int(testf::Function, B::BitArray, start::Int) f0::Bool = testf(false) f1::Bool = testf(true) diff --git a/base/broadcast.jl b/base/broadcast.jl index a6519eded941f..61b46a66d693f 100644 --- a/base/broadcast.jl +++ b/base/broadcast.jl @@ -594,7 +594,7 @@ Base.@propagate_inbounds _newindex(ax::Tuple{}, I::Tuple{}) = () # If dot-broadcasting were already defined, this would be `ifelse.(keep, I, Idefault)`. @inline newindex(I::CartesianIndex, keep, Idefault) = to_index(_newindex(I.I, keep, Idefault)) @inline newindex(I::CartesianIndex{1}, keep, Idefault) = newindex(I.I[1], keep, Idefault) -@inline newindex(i::Integer, keep::Tuple, idefault) = CartesianIndex(ifelse(keep[1], _Int(i), _Int(idefault[1])), idefault[2]) +@inline newindex(i::Integer, keep::Tuple, idefault) = CartesianIndex(ifelse(keep[1], Int(i), Int(idefault[1])), idefault[2]) @inline newindex(i::Integer, keep::Tuple{Bool}, idefault) = ifelse(keep[1], i, idefault[1]) @inline newindex(i::Integer, keep::Tuple{}, idefault) = CartesianIndex() @inline _newindex(I, keep, Idefault) = @@ -1016,7 +1016,7 @@ end if ndims(bc) == 1 || bitst >= 64 - length(ax1) if ndims(bc) > 1 && bitst != 0 @inbounds @simd for j = bitst:63 - remain |= _UInt64(convert(Bool, bc′[i+=1, I])) << (j & 63) + remain |= UInt64(convert(Bool, bc′[i+=1, I])) << (j & 63) end @inbounds destc[indc+=1] = remain bitst, remain = 0, UInt64(0) @@ -1024,13 +1024,13 @@ end while i <= last(ax1) - 64 z = UInt64(0) @inbounds @simd for j = 0:63 - z |= _UInt64(convert(Bool, bc′[i+=1, I])) << (j & 63) + z |= UInt64(convert(Bool, bc′[i+=1, I])) << (j & 63) end @inbounds destc[indc+=1] = z end end @inbounds @simd for j = i+1:last(ax1) - remain |= _UInt64(convert(Bool, bc′[j, I])) << (bitst & 63) + remain |= UInt64(convert(Bool, bc′[j, I])) << (bitst & 63) bitst += 1 end end diff --git a/base/char.jl b/base/char.jl index c6ba5d534e8c3..90636a6d9536e 100644 --- a/base/char.jl +++ b/base/char.jl @@ -47,8 +47,8 @@ represents a valid Unicode character. """ Char -@constprop :aggressive (::Type{T})(x::Number) where {T<:AbstractChar} = T(_UInt32(x)) -@constprop :aggressive AbstractChar(x::Number) = _Char(x) +@constprop :aggressive (::Type{T})(x::Number) where {T<:AbstractChar} = T(UInt32(x)) +@constprop :aggressive AbstractChar(x::Number) = Char(x) @constprop :aggressive (::Type{T})(x::AbstractChar) where {T<:Union{Number,AbstractChar}} = T(codepoint(x)) @constprop :aggressive (::Type{T})(x::AbstractChar) where {T<:Union{Int32,Int64}} = codepoint(x) % T (::Type{T})(x::T) where {T<:AbstractChar} = x @@ -189,7 +189,7 @@ end 0 ≤ b ≤ 0x7f ? bitcast(Char, (b % UInt32) << 24) : Char_cold(UInt32(b)) end -convert(::Type{AbstractChar}, x::Number) = _Char(x) # default to Char +convert(::Type{AbstractChar}, x::Number) = Char(x) # default to Char convert(::Type{T}, x::Number) where {T<:AbstractChar} = T(x)::T convert(::Type{T}, x::AbstractChar) where {T<:Number} = T(x)::T convert(::Type{T}, c::AbstractChar) where {T<:AbstractChar} = T(c)::T @@ -225,31 +225,31 @@ hash(x::Char, h::UInt) = hash_finalizer(((bitcast(UInt32, x) + UInt64(0xd4d64234)) << 32) ⊻ UInt64(h)) % UInt # fallbacks: -isless(x::AbstractChar, y::AbstractChar) = isless(_Char(x), _Char(y)) -==(x::AbstractChar, y::AbstractChar) = _Char(x) == _Char(y) -hash(x::AbstractChar, h::UInt) = hash(_Char(x), h) +isless(x::AbstractChar, y::AbstractChar) = isless(Char(x), Char(y)) +==(x::AbstractChar, y::AbstractChar) = Char(x) == Char(y) +hash(x::AbstractChar, h::UInt) = hash(Char(x), h) widen(::Type{T}) where {T<:AbstractChar} = T -@inline -(x::AbstractChar, y::AbstractChar) = _Int(x) - _Int(y) +@inline -(x::AbstractChar, y::AbstractChar) = Int(x) - Int(y) @inline function -(x::T, y::Integer) where {T<:AbstractChar} if x isa Char u = Int32((bitcast(UInt32, x) >> 24) % Int8) if u >= 0 # inline the runtime fast path z = u - y - return 0 <= z < 0x80 ? bitcast(Char, (z % UInt32) << 24) : Char(_UInt32(z)) + return 0 <= z < 0x80 ? bitcast(Char, (z % UInt32) << 24) : Char(UInt32(z)) end end - return T(_Int32(x) - _Int32(y)) + return T(Int32(x) - Int32(y)) end @inline function +(x::T, y::Integer) where {T<:AbstractChar} if x isa Char u = Int32((bitcast(UInt32, x) >> 24) % Int8) if u >= 0 # inline the runtime fast path z = u + y - return 0 <= z < 0x80 ? bitcast(Char, (z % UInt32) << 24) : Char(_UInt32(z)) + return 0 <= z < 0x80 ? bitcast(Char, (z % UInt32) << 24) : Char(UInt32(z)) end end - return T(_Int32(x) + _Int32(y)) + return T(Int32(x) + Int32(y)) end @inline +(x::Integer, y::AbstractChar) = y + x @@ -257,7 +257,7 @@ end # (Packages may implement other IO subtypes to specify different encodings.) # In contrast, `write(io, c)` outputs a `c` in an encoding determined by typeof(c). print(io::IO, c::Char) = (write(io, c); nothing) -print(io::IO, c::AbstractChar) = print(io, _Char(c)) # fallback: convert to output UTF-8 +print(io::IO, c::AbstractChar) = print(io, Char(c)) # fallback: convert to output UTF-8 const hex_chars = UInt8['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', diff --git a/base/client.jl b/base/client.jl index ddb7d5377a04f..8ff97328a74cb 100644 --- a/base/client.jl +++ b/base/client.jl @@ -93,7 +93,7 @@ function scrub_repl_backtrace(bt) if bt !== nothing && !(bt isa Vector{Any}) # ignore our sentinel value types bt = bt isa Vector{StackFrame} ? copy(bt) : stacktrace(bt) # remove REPL-related frames from interactive printing - eval_ind = findlast(frame -> !frame.from_c && startswith(_String(frame.func), "__repl_entry"), bt) + eval_ind = findlast(frame -> !frame.from_c && startswith(String(frame.func), "__repl_entry"), bt) eval_ind === nothing || deleteat!(bt, eval_ind:length(bt)) end return bt @@ -200,7 +200,7 @@ function parse_input_line(s::String; filename::String="none", depwarn=true) end return ex end -parse_input_line(s::AbstractString) = parse_input_line(_String(s)) +parse_input_line(s::AbstractString) = parse_input_line(String(s)) # detect the reason which caused an :incomplete expression # from the error message diff --git a/base/cmd.jl b/base/cmd.jl index 8dec5159400b4..14269183e4f61 100644 --- a/base/cmd.jl +++ b/base/cmd.jl @@ -507,6 +507,6 @@ Process(`echo 1`, ProcessExited(0)) ``` """ macro cmd(str::String) - cmd_ex = shell_parse(str, special=shell_special, filename=_String(__source__.file))[1] + cmd_ex = shell_parse(str, special=shell_special, filename=String(__source__.file))[1] return :(cmd_gen($(esc(cmd_ex)))) end diff --git a/base/deprecated.jl b/base/deprecated.jl index 6ed5861df6bb3..0ee6b6b790837 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -276,7 +276,7 @@ end Core # TODO: Is it reasonable to attribute callers without linfo to Core? end end, - _file=_String(caller.file), + _file=String(caller.file), _line=caller.line, _id=(frame,funcsym), _group=:depwarn, diff --git a/base/docs/Docs.jl b/base/docs/Docs.jl index 402aee6edf2eb..13a5b35a115da 100644 --- a/base/docs/Docs.jl +++ b/base/docs/Docs.jl @@ -68,7 +68,6 @@ include("bindings.jl") import .Base.Meta: quot, isexpr, unblock, unescape, uncurly import .Base: Callable, with_output_color using .Base: RefValue, mapany -using .._ConstructingFunctions import ..CoreDocs: lazy_iterpolate export doc, hasdoc, undocumented_names @@ -338,7 +337,7 @@ Fields that may be included in the returned `Dict`: function metadata(__source__, __module__, expr, ismodule) args = [] # Filename and linenumber of the docstring. - __file__ = isa(__source__.file, Symbol) ? _String(__source__.file) : "" + __file__ = isa(__source__.file, Symbol) ? String(__source__.file) : "" push!(args, Pair(:path, __file__)) push!(args, Pair(:linenumber, __source__.line)) # Module in which the docstring is defined. diff --git a/base/env.jl b/base/env.jl index 79b39765a0854..5472456e22885 100644 --- a/base/env.jl +++ b/base/env.jl @@ -181,7 +181,7 @@ if Sys.iswindows() isempty(s) && return s LOCALE_INVARIANT = 0x0000007f LCMAP_UPPERCASE = 0x00000200 - ws = transcode(UInt16, _String(s)) + ws = transcode(UInt16, String(s)) result = ccall(:LCMapStringW, stdcall, Cint, (UInt32, UInt32, Ptr{UInt16}, Cint, Ptr{UInt16}, Cint), LOCALE_INVARIANT, LCMAP_UPPERCASE, ws, length(ws), ws, length(ws)) systemerror(:LCMapStringW, iszero(result)) diff --git a/base/file.jl b/base/file.jl index ec73a772f1e23..c0139b73b2c70 100644 --- a/base/file.jl +++ b/base/file.jl @@ -1240,7 +1240,7 @@ function sendfile(src::AbstractString, dst::AbstractString) dst_open = true bytes = filesize(stat(src_file)) - sendfile(dst_file, src_file, Int64(0), _Int(bytes)) + sendfile(dst_file, src_file, Int64(0), Int(bytes)) finally if src_open && isopen(src_file) close(src_file) @@ -1436,8 +1436,8 @@ struct DiskStat end function Base.getproperty(stats::DiskStat, field::Symbol) - total = _Int64(getfield(stats, :bsize) * getfield(stats, :blocks)) - available = _Int64(getfield(stats, :bsize) * getfield(stats, :bavail)) + total = Int64(getfield(stats, :bsize) * getfield(stats, :blocks)) + available = Int64(getfield(stats, :bsize) * getfield(stats, :bavail)) field === :total && return total field === :available && return available field === :used && return total - available diff --git a/base/filesystem.jl b/base/filesystem.jl index ea2e6ae7a99aa..a5f1327b5cff1 100644 --- a/base/filesystem.jl +++ b/base/filesystem.jl @@ -145,8 +145,6 @@ import .Base: import .Base.RefValue -using .._ConstructingFunctions - if Sys.iswindows() import .Base: cwstring end @@ -392,7 +390,7 @@ function isexecutable(path::String) X_OK = 0x01 return ccall(:jl_fs_access, Cint, (Cstring, Cint), path, X_OK) == 0 end -isexecutable(path::AbstractString) = isexecutable(_String(path)) +isexecutable(path::AbstractString) = isexecutable(String(path)) """ isreadable(path::String) @@ -419,7 +417,7 @@ function isreadable(path::String) R_OK = 0x04 return ccall(:jl_fs_access, Cint, (Cstring, Cint), path, R_OK) == 0 end -isreadable(path::AbstractString) = isreadable(_String(path)) +isreadable(path::AbstractString) = isreadable(String(path)) """ iswritable(path::String) @@ -446,7 +444,7 @@ function iswritable(path::String) W_OK = 0x02 return ccall(:jl_fs_access, Cint, (Cstring, Cint), path, W_OK) == 0 end -iswritable(path::AbstractString) = iswritable(_String(path)) +iswritable(path::AbstractString) = iswritable(String(path)) end diff --git a/base/flfrontend.jl b/base/flfrontend.jl index ede02ad59edb8..86b291cf7328b 100644 --- a/base/flfrontend.jl +++ b/base/flfrontend.jl @@ -15,7 +15,7 @@ function fl_parse(text::Union{Core.SimpleVector,String}, end function fl_parse(text::AbstractString, filename::AbstractString, lineno, offset, options) - fl_parse(_String(text), _String(filename), lineno, offset, options) + fl_parse(String(text), String(filename), lineno, offset, options) end function fl_lower(ex, mod::Module, filename::Union{String,Ptr{UInt8}}="none", diff --git a/base/float.jl b/base/float.jl index d1fad001596cd..eaf17acfd4358 100644 --- a/base/float.jl +++ b/base/float.jl @@ -802,7 +802,7 @@ _precision_with_base_2(::Type{Float64}) = 53 function _precision(x, base::Integer) base > 1 || throw(DomainError(base, "`base` cannot be less than 2.")) p = _precision_with_base_2(x) - return base == 2 ? _Int(p) : floor(Int, p / log2(base)) + return base == 2 ? Int(p) : floor(Int, p / log2(base)) end precision(::Type{T}; base::Integer=2) where {T<:AbstractFloat} = _precision(T, base) precision(::T; base::Integer=2) where {T<:AbstractFloat} = precision(T; base) diff --git a/base/gmp.jl b/base/gmp.jl index 9d2c0a7fd308b..e4d9294766aaa 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -15,8 +15,6 @@ import .Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), xor, import Core: Signed, Float16, Float32, Float64 -using .._ConstructingFunctions - if Clong == Int32 const ClongMax = Union{Int8, Int16, Int32} const CulongMax = Union{UInt8, UInt16, UInt32} @@ -290,9 +288,9 @@ Signed(x::BigInt) = x function tryparse_internal(::Type{BigInt}, s::AbstractString, startpos::Int, endpos::Int, base_::Integer, raise::Bool) # don't make a copy in the common case where we are parsing a whole String - bstr = startpos == firstindex(s) && endpos == lastindex(s) ? _String(s) : _String(SubString(s,startpos,endpos)) + bstr = startpos == firstindex(s) && endpos == lastindex(s) ? String(s) : String(SubString(s,startpos,endpos)) - sgn, base, i = Base.parseint_preamble(true,_Int(base_),bstr,firstindex(bstr),lastindex(bstr)) + sgn, base, i = Base.parseint_preamble(true,Int(base_),bstr,firstindex(bstr),lastindex(bstr)) if !(2 <= base <= 62) raise && throw(ArgumentError("invalid base: base must be 2 ≤ base ≤ 62, got $base")) return nothing @@ -427,7 +425,7 @@ function Float64(x::BigInt, ::RoundingMode{:Nearest}) y += n > (precision(Float64) - 32) ? 0 : (unsafe_load(x.d, xsize-2) >> (10+n)) end y = (y + 1) >> 1 # round, ties up - y &= ~_UInt64(trailing_zeros(x) == (n-54 + (xsize-1)*BITS_PER_LIMB)) # fix last bit to round to even + y &= ~UInt64(trailing_zeros(x) == (n-54 + (xsize-1)*BITS_PER_LIMB)) # fix last bit to round to even d = ((n+1021) % UInt64) << 52 z = reinterpret(Float64, d+y) z = ldexp(z, (xsize-1)*BITS_PER_LIMB) @@ -449,7 +447,7 @@ function Float32(x::BigInt, ::RoundingMode{:Nearest}) y = (y1 >> (n - (precision(Float32)+1))) % UInt32 y += (n > precision(Float32) ? 0 : unsafe_load(x.d, xsize-1) >> (BITS_PER_LIMB - (25-n))) % UInt32 y = (y + one(UInt32)) >> 1 # round, ties up - y &= ~_UInt32(trailing_zeros(x) == (n-25 + (xsize-1)*BITS_PER_LIMB)) # fix last bit to round to even + y &= ~UInt32(trailing_zeros(x) == (n-25 + (xsize-1)*BITS_PER_LIMB)) # fix last bit to round to even d = ((n+125) % UInt32) << 23 z = reinterpret(Float32, d+y) z = ldexp(z, (xsize-1)*BITS_PER_LIMB) @@ -467,7 +465,7 @@ function Float16(x::BigInt, ::RoundingMode{:Nearest}) # load first 12(1 + 10 bits for fraction + 1 for rounding) y = (y1 >> (n - (precision(Float16)+1))) % UInt16 y = (y + one(UInt16)) >> 1 # round, ties up - y &= ~_UInt16(trailing_zeros(x) == (n-12)) # fix last bit to round to even + y &= ~UInt16(trailing_zeros(x) == (n-12)) # fix last bit to round to even d = ((n+13) % UInt16) << 10 z = reinterpret(Float16, d+y) end @@ -751,7 +749,7 @@ end show(io::IO, x::BigInt) = print(io, string(x)) function string(n::BigInt; base::Integer = 10, pad::Integer = 1) - base < 0 && return Base._base(_Int(base), n, pad, (base>0) & (n.size<0)) + base < 0 && return Base._base(Int(base), n, pad, (base>0) & (n.size<0)) 2 <= base <= 62 || throw(ArgumentError("base must be 2 ≤ base ≤ 62, got $base")) iszero(n) && pad < 1 && return "" nd1 = ndigits(n, base=base) @@ -804,7 +802,7 @@ function ndigits0zpb(x::BigInt, b::Integer) n = MPZ.sizeinbase(x, 2) lb = log2(b) # assumed accurate to <1ulp (true for openlibm) q,r = divrem(n,lb) - iq = _Int(q) + iq = Int(q) maxerr = q*eps(lb) # maximum error in remainder if r-1.0 < maxerr abs(x) >= big(b)^iq ? iq+1 : iq diff --git a/base/hashing.jl b/base/hashing.jl index bab151faf30d5..30a5e28447809 100644 --- a/base/hashing.jl +++ b/base/hashing.jl @@ -81,7 +81,7 @@ function _hash_integer( u = u0 # always left-pad to full byte - buflen = _UInt(max(cld(top_set_bit(u), 8), 1)) + buflen = UInt(max(cld(top_set_bit(u), 8), 1)) seed = seed ⊻ hash_mix(seed ⊻ secret[3], secret[2]) a = zero(UInt64) @@ -92,14 +92,14 @@ function _hash_integer( if buflen ≥ 4 seed ⊻= buflen if buflen ≥ 8 - a = (u % UInt64)::UInt64 - b = ((u >>> (8 * (buflen - 8))) % UInt64)::UInt64 + a = UInt64(u % UInt64) + b = UInt64((u >>> (8 * (buflen - 8))) % UInt64) else - a = UInt64((u % UInt32)::UInt32) - b = UInt64(((u >>> (8 * (buflen - 4))) % UInt32)::UInt32) + a = UInt64(u % UInt32) + b = UInt64((u >>> (8 * (buflen - 4))) % UInt32) end else # buflen > 0 - b0 = (u % UInt8)::UInt8 + b0 = u % UInt8 b1 = (u >>> (8 * div(buflen, 2))) % UInt8 b2 = (u >>> (8 * (buflen - 1))) % UInt8 a = (UInt64(b0) << 45) | UInt64(b2) @@ -213,8 +213,8 @@ function hash(x::Real, h::UInt) # 2^-1074 is the minimum Float64 so if the power is smaller, not a Float64 if -1074 <= pow if 0 <= pow # if pow is non-negative, it is an integer - left <= 63 && return hash(_Int64(num) << _Int(pow), h) - left <= 64 && !signbit(num) && return hash(_UInt64(num) << _Int(pow), h) + left <= 63 && return hash(Int64(num) << Int(pow), h) + left <= 64 && !signbit(num) && return hash(UInt64(num) << Int(pow), h) end # typemin(Int64) handled by Float64 case # 2^1024 is the maximum Float64 so if the power is greater, not a Float64 # Float64s only have 53 mantisa bits (including implicit bit) @@ -351,7 +351,7 @@ end result = zero(UInt64) for i in 0:7 byte = @inbounds arr[idx + i] - result |= _UInt64(byte) << (8 * i) + result |= UInt64(byte) << (8 * i) end return result end @@ -360,7 +360,7 @@ end result = zero(UInt32) for i in 0:3 byte = @inbounds arr[idx + i] - result |= _UInt32(byte) << (8 * i) + result |= UInt32(byte) << (8 * i) end return result end @@ -372,7 +372,7 @@ end ) # Adapted with gratitude from [rapidhash](https://github.com/Nicoshev/rapidhash) n = length(arr) - buflen = _UInt64(n) + buflen = UInt64(n) seed = seed ⊻ hash_mix(seed ⊻ secret[3], secret[2]) firstidx = firstindex(arr) @@ -387,12 +387,12 @@ end a = load_le_array(UInt64, arr, firstidx) b = load_le_array(UInt64, arr, firstidx + n - 8) else - a = _UInt64(load_le_array(UInt32, arr, firstidx)) - b = _UInt64(load_le_array(UInt32, arr, firstidx + n - 4)) + a = UInt64(load_le_array(UInt32, arr, firstidx)) + b = UInt64(load_le_array(UInt32, arr, firstidx + n - 4)) end elseif buflen > 0 - a = (_UInt64(@inbounds arr[firstidx]) << 45) | _UInt64(@inbounds arr[firstidx + n - 1]) - b = _UInt64(@inbounds arr[firstidx + div(n, 2)]) + a = (UInt64(@inbounds arr[firstidx]) << 45) | UInt64(@inbounds arr[firstidx + n - 1]) + b = UInt64(@inbounds arr[firstidx + div(n, 2)]) end else pos = 0 @@ -456,7 +456,7 @@ end next_result = iterate(iter, state) next_result === nothing && return value, state, UInt8(i - 1) byte, state = next_result - value |= _UInt64(byte) << ((i - 1) * 8) + value |= UInt64(byte) << ((i - 1) * 8) end return value, state, 0x8 end @@ -465,7 +465,7 @@ end next_result = iterate(iter) next_result === nothing && return nothing byte, state = next_result - value = _UInt64(byte) + value = UInt64(byte) @nexprs 7 i -> begin next_result = iterate(iter, state) next_result === nothing && return value, state, UInt8(i) @@ -588,11 +588,11 @@ end a = l0 b = t1 else - a = UInt64((l0 % UInt32)::UInt32) - b = UInt64(((l0 >>> ((0x8 * (bytes_chunk - 0x4)) % 0x3f)) % UInt32)::UInt32) + a = UInt64(l0 % UInt32) + b = UInt64((l0 >>> ((0x8 * (bytes_chunk - 0x4)) % 0x3f)) % UInt32) end elseif bytes_chunk > 0x0 - b0 = (l0 % UInt8)::UInt8 + b0 = l0 % UInt8 b1 = (l0 >>> ((0x8 * div(bytes_chunk, 0x2)) % 0x3f)) % UInt8 b2 = (l0 >>> ((0x8 * (bytes_chunk - 0x1)) % 0x3f)) % UInt8 a = (UInt64(b0) << 45) | UInt64(b2) diff --git a/base/io.jl b/base/io.jl index a8d9982e45686..71e4c404dfeac 100644 --- a/base/io.jl +++ b/base/io.jl @@ -813,7 +813,7 @@ unsafe_write(s::IO, p::Ptr, n::Integer) = unsafe_write(s, convert(Ptr{UInt8}, p) function write(s::IO, x::Ref{T}) where {T} x isa Ptr && error("write cannot copy from a Ptr") if isbitstype(T) - _Int(unsafe_write(s, x, Core.sizeof(T))) + Int(unsafe_write(s, x, Core.sizeof(T))) else write(s, x[]) end @@ -1112,7 +1112,7 @@ function copyuntil(out::IO, io::IO, target::AbstractString; keep::Bool=false) end # convert String to a utf8-byte-iterator if !(target isa String) && !(target isa SubString{String}) - target = _String(target) + target = String(target) end target = codeunits(target)::AbstractVector return copyuntil(out, io, target, keep=keep) @@ -1304,7 +1304,7 @@ function iterate(r::Iterators.Reverse{<:EachLine}, state) # extract the string from chunks[ichunk][inewline+1] to chunks[jchunk][jnewline] if ichunk == jchunk # common case: current and previous newline in same chunk chunk = chunks[ichunk] - s = _String(view(chunk, inewline+1:_stripnewline(r.itr.keep, jnewline, chunk))) + s = String(view(chunk, inewline+1:_stripnewline(r.itr.keep, jnewline, chunk))) else buf = IOBuffer(sizehint=max(128, length(chunks[ichunk])-inewline+jnewline)) write(buf, view(chunks[ichunk], inewline+1:length(chunks[ichunk]))) @@ -1533,7 +1533,7 @@ julia> rm("my_file.txt") """ function countlines(io::IO; eol::AbstractChar='\n') isascii(eol) || throw(ArgumentError("only ASCII line terminators are supported")) - aeol = _UInt8(eol) + aeol = UInt8(eol) a = Vector{UInt8}(undef, 8192) nl = nb = 0 while !eof(io) diff --git a/base/iobuffer.jl b/base/iobuffer.jl index 2d5064c06a54f..c58e1cde6829b 100644 --- a/base/iobuffer.jl +++ b/base/iobuffer.jl @@ -855,7 +855,7 @@ function takestring!(io::IOBuffer) end # Fallback methods -takestring!(io::GenericIOBuffer) = _String(take!(io)) +takestring!(io::GenericIOBuffer) = String(take!(io)) """ _unsafe_take!(io::IOBuffer) @@ -953,7 +953,7 @@ end return sizeof(UInt8) end -readbytes!(io::GenericIOBuffer, b::MutableDenseArrayType{UInt8}, nb=length(b)) = readbytes!(io, b, _Int(nb)) +readbytes!(io::GenericIOBuffer, b::MutableDenseArrayType{UInt8}, nb=length(b)) = readbytes!(io, b, Int(nb)) function readbytes!(io::GenericIOBuffer, b::MutableDenseArrayType{UInt8}, nb::Int) io.readable || _throw_not_readable() diff --git a/base/iterators.jl b/base/iterators.jl index 75fe28e50eb80..5909608709e36 100644 --- a/base/iterators.jl +++ b/base/iterators.jl @@ -32,9 +32,6 @@ import Base: getindex, setindex!, get, iterate, popfirst!, isdone, peek, intersect -using Base: _ConstructingFunctions -using ._ConstructingFunctions - export enumerate, zip, rest, countfrom, take, drop, takewhile, dropwhile, cycle, repeated, product, flatten, flatmap, partition, nth, findeach public accumulate, filter, map, peel, reverse, Stateful @@ -772,8 +769,8 @@ julia> collect(Iterators.take(a,3)) 5 ``` """ -take(xs, n::Integer) = Take(xs, _Int(n)) -take(xs::Take, n::Integer) = Take(xs.xs, min(_Int(n), xs.n)) +take(xs, n::Integer) = Take(xs, Int(n)) +take(xs::Take, n::Integer) = Take(xs.xs, min(Int(n), xs.n)) eltype(::Type{Take{I}}) where {I} = eltype(I) IteratorEltype(::Type{Take{I}}) where {I} = IteratorEltype(I) @@ -828,9 +825,9 @@ julia> collect(Iterators.drop(a,4)) 11 ``` """ -drop(xs, n::Integer) = Drop(xs, _Int(n)) -drop(xs::Take, n::Integer) = Take(drop(xs.xs, _Int(n)), max(0, xs.n - _Int(n))) -drop(xs::Drop, n::Integer) = Drop(xs.xs, _Int(n) + xs.n) +drop(xs, n::Integer) = Drop(xs, Int(n)) +drop(xs::Take, n::Integer) = Take(drop(xs.xs, Int(n)), max(0, xs.n - Int(n))) +drop(xs::Drop, n::Integer) = Drop(xs.xs, Int(n) + xs.n) eltype(::Type{Drop{I}}) where {I} = eltype(I) IteratorEltype(::Type{Drop{I}}) where {I} = IteratorEltype(I) @@ -1068,7 +1065,7 @@ julia> Iterators.cycle([1 2], 4) |> collect |> println [1, 2, 1, 2, 1, 2, 1, 2] ``` """ -repeated(x, n::Integer) = take(repeated(x), _Int(n)) +repeated(x, n::Integer) = take(repeated(x), Int(n)) eltype(::Type{Repeated{O}}) where {O} = O @@ -1385,7 +1382,7 @@ julia> collect(Iterators.partition([1,2,3,4,5], 2)) ``` """ function partition(c, n::Integer) n < 1 && throw(ArgumentError("cannot create partitions of length $n")) - return PartitionIterator(c, _Int(n)) + return PartitionIterator(c, Int(n)) end struct PartitionIterator{T} diff --git a/base/loading.jl b/base/loading.jl index 6a0533beb6316..c8662be9788af 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -45,7 +45,7 @@ elseif Sys.isapple() # getattrpath(path, &attr_list, &buf, sizeof(buf), FSOPT_NOFOLLOW); function isfile_casesensitive(path) isaccessiblefile(path) || return false - path_basename = _String(basename(path)) + path_basename = String(basename(path)) local casepreserved_basename header_size = 12 buf = Vector{UInt8}(undef, length(path_basename) + header_size + 1) @@ -243,7 +243,7 @@ function get_updated_dict(p::TOML.Parser, f::CachedTOMLDict) f.mtime = s.mtime f.size = s.size f.hash = new_hash - TOML.reinit!(p, _String(content); filepath=f.path) + TOML.reinit!(p, String(content); filepath=f.path) return f.d = TOML.parse(p) end end @@ -1759,9 +1759,9 @@ function parse_image_target(io::IO) feature_en = read(io, 4*nfeature) feature_dis = read(io, 4*nfeature) name_len = read(io, Int32) - name = _String(read(io, name_len)) + name = String(read(io, name_len)) ext_features_len = read(io, Int32) - ext_features = _String(read(io, ext_features_len)) + ext_features = String(read(io, ext_features_len)) ImageTarget(name, flags, ext_features, feature_en, feature_dis) end @@ -2263,7 +2263,7 @@ function _include_dependency!(dep_list::Vector{Any}, track_dependencies::Bool, if track_content hash = (isdir(path) ? _crc32c(join(readdir(path))) : open(_crc32c, path, "r"))::UInt32 # use mtime=-1.0 here so that fsize==0 && mtime==0.0 corresponds to a missing include_dependency - push!(dep_list, (mod, path, _UInt64(filesize(path)), hash, -1.0)) + push!(dep_list, (mod, path, UInt64(filesize(path)), hash, -1.0)) else push!(dep_list, (mod, path, UInt64(0), UInt32(0), mtime(path))) end @@ -3409,9 +3409,9 @@ function read_module_list(f::IO, has_buildid_hi::Bool) while true n = read(f, Int32) n == 0 && break - sym = _String(read(f, n)) # module name + sym = String(read(f, n)) # module name uuid = UUID((read(f, UInt64), read(f, UInt64))) # pkg UUID - build_id_hi = _UInt128(has_buildid_hi ? read(f, UInt64) : UInt64(0)) << 64 + build_id_hi = UInt128(has_buildid_hi ? read(f, UInt64) : UInt64(0)) << 64 build_id = (build_id_hi | read(f, UInt64)) # build id (checksum + time - not a UUID) push!(modules, PkgId(uuid, sym) => build_id) end @@ -3421,7 +3421,7 @@ end function _parse_cache_header(f::IO, cachefile::AbstractString) flags = read(f, UInt8) modules = read_module_list(f, false) - totbytes = _Int64(read(f, UInt64)) # total bytes for file dependencies + preferences + totbytes = Int64(read(f, UInt64)) # total bytes for file dependencies + preferences # read the list of requirements # and split the list into include and requires statements includes = CacheHeaderIncludes[] @@ -3432,7 +3432,7 @@ function _parse_cache_header(f::IO, cachefile::AbstractString) if n2 == 0 break end - depname = _String(read(f, n2)) + depname = String(read(f, n2)) totbytes -= n2 fsize = read(f, UInt64) totbytes -= 8 @@ -3453,7 +3453,7 @@ function _parse_cache_header(f::IO, cachefile::AbstractString) if n1 == 0 break end - push!(modpath, _String(read(f, n1))) + push!(modpath, String(read(f, n1))) totbytes -= n1 end end @@ -3470,7 +3470,7 @@ function _parse_cache_header(f::IO, cachefile::AbstractString) if n2 == 0 break end - push!(prefs, _String(read(f, n2))) + push!(prefs, String(read(f, n2))) totbytes -= n2 end prefs_hash = read(f, UInt64) @@ -3617,7 +3617,7 @@ function _read_dependency_src(io::IO, filename::AbstractString, includes::Vector while !eof(io) filenamelen = read(io, Int32) filenamelen == 0 && break - depotfn = _String(read(io, filenamelen)) + depotfn = String(read(io, filenamelen)) len = read(io, UInt64) fn = if !startswith(depotfn, string("@depot", Filesystem.pathsep())) depotfn @@ -3629,7 +3629,7 @@ function _read_dependency_src(io::IO, filename::AbstractString, includes::Vector isnothing(idx) ? depotfn : includes[idx].filename end if fn == filename - return _String(read(io, len)) + return String(read(io, len)) end seek(io, position(io) + len) end @@ -3653,7 +3653,7 @@ function srctext_files(f::IO, srctextpos::Int64, includes::Vector{CacheHeaderInc while !eof(f) filenamelen = read(f, Int32) filenamelen == 0 && break - filename = _String(read(f, filenamelen)) + filename = String(read(f, filenamelen)) len = read(f, UInt64) push!(files, filename) seek(f, position(f) + len) @@ -4023,7 +4023,7 @@ end return true end id_build = id.second - id_build = (_UInt128(checksum) << 64) | (id_build % UInt64) + id_build = (UInt128(checksum) << 64) | (id_build % UInt64) if build_id != UInt128(0) if id_build != build_id @debug "Ignoring cache file $cachefile for $modkey ($(UUID(id_build))) since it does not provide desired build_id ($((UUID(build_id))))" @@ -4079,7 +4079,7 @@ end for (req_key, req_build_id) in _concrete_dependencies build_id = get(modules, req_key, UInt64(0)) if build_id !== UInt64(0) - build_id |= _UInt128(checksum) << 64 + build_id |= UInt128(checksum) << 64 if build_id === req_build_id stalecheck = false break diff --git a/base/logging/ConsoleLogger.jl b/base/logging/ConsoleLogger.jl index 7b9d165359bdf..a2d05ec520c3c 100644 --- a/base/logging/ConsoleLogger.jl +++ b/base/logging/ConsoleLogger.jl @@ -125,7 +125,7 @@ function handle_message(logger::ConsoleLogger, level::LogLevel, message, _module # and reduce the risk of resulting method invalidations. message = string(message) msglines = if Base._isannotated(message) && !isempty(Base.annotations(message)) - message = Base.AnnotatedString(_String(message), Base.annotations(message)) + message = Base.AnnotatedString(String(message), Base.annotations(message)) @NamedTuple{indent::Int, msg::Union{SubString{Base.AnnotatedString{String}}, SubString{String}}}[ (indent=0, msg=l) for l in split(chomp(message), '\n')] else diff --git a/base/logging/logging.jl b/base/logging/logging.jl index c0688d30fbf8a..3d38163a8b403 100644 --- a/base/logging/logging.jl +++ b/base/logging/logging.jl @@ -519,7 +519,7 @@ function logmsg_shim(level, message, _module, group, id, file, line, kwargs) real_kws = Any[(kwargs[i], kwargs[i+1]) for i in 1:2:length(kwargs)] @logmsg(convert(LogLevel, level), message, _module=_module, _id=id, _group=group, - _file=_String(file), _line=line, real_kws...) + _file=String(file), _line=line, real_kws...) nothing end diff --git a/base/meta.jl b/base/meta.jl index 0873676935d43..ab20a71a417d4 100644 --- a/base/meta.jl +++ b/base/meta.jl @@ -349,7 +349,7 @@ julia> Meta.parse("(α, β) = 3, 5", 11, greedy=false) """ function parse(str::AbstractString, pos::Integer; filename="none", greedy::Bool=true, raise::Bool=true, depwarn::Bool=true) - ex, pos = _parse_string(str, _String(filename), 1, pos, greedy ? :statement : :atom) + ex, pos = _parse_string(str, String(filename), 1, pos, greedy ? :statement : :atom) if raise && isexpr(ex, :error) err = ex.args[1] if err isa String @@ -401,11 +401,11 @@ function parse(str::AbstractString; end function parseatom(text::AbstractString, pos::Integer; filename="none", lineno=1) - return _parse_string(text, _String(filename), lineno, pos, :atom) + return _parse_string(text, String(filename), lineno, pos, :atom) end function parseall(text::AbstractString; filename="none", lineno=1) - ex,_ = _parse_string(text, _String(filename), lineno, 1, :all) + ex,_ = _parse_string(text, String(filename), lineno, 1, :all) return ex end diff --git a/base/methodshow.jl b/base/methodshow.jl index 234d40b7fc35e..1470303a01bbc 100644 --- a/base/methodshow.jl +++ b/base/methodshow.jl @@ -7,7 +7,7 @@ function strip_gensym(sym) if sym === :var"#self#" || sym === :var"#unused#" return empty_sym end - return Symbol(replace(_String(sym), r"^(.*)#(.*#)?\d+$"sa => s"\1")) + return Symbol(replace(String(sym), r"^(.*)#(.*#)?\d+$"sa => s"\1")) end function argtype_decl(env, n, @nospecialize(sig::DataType), i::Int, nargs, isva::Bool) # -> (argname, argtype) @@ -138,7 +138,7 @@ function fixup_stdlib_path(path::String) path = npath == npath′ ? path : npath′ end if isdefined(@__MODULE__, :Core) && isdefined(Core, :Compiler) - compiler_folder = dirname(_String(Base.moduleloc(Core.Compiler).file)) + compiler_folder = dirname(String(Base.moduleloc(Core.Compiler).file)) if dirname(path) == compiler_folder return abspath(Sys.STDLIB, "..", "..", "Compiler", "src", basename(path)) end @@ -157,7 +157,7 @@ function updated_methodloc(m::Method)::Tuple{String, Int32} end end file = fixup_stdlib_path(string(file)) - return file, _Int32(line) + return file, Int32(line) end functionloc(m::Core.MethodInstance) = functionloc(m.def) @@ -202,7 +202,7 @@ function sym_to_string(sym) if sym === :var"..." return "..." end - s = _String(sym) + s = String(sym) if endswith(s, "...") return string(sprint(show_sym, Symbol(s[1:end-3])), "...") else diff --git a/base/multidimensional.jl b/base/multidimensional.jl index f33309d280573..9512d5d6dbe8b 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -1466,7 +1466,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra cind = pos_s lastind = pos_d + numbits - 1 @inbounds while bind ≤ lastind - unsafe_bitsetindex!(Bc, _Bool(C[cind]), bind) + unsafe_bitsetindex!(Bc, Bool(C[cind]), bind) bind += 1 cind += 1 end @@ -1507,7 +1507,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra @inbounds if ld0 > 0 c = UInt64(0) for j = ld0:lt0 - c |= (_UInt64(unchecked_bool_convert(C[ind])) << j) + c |= (UInt64(unchecked_bool_convert(C[ind])) << j) ind += 1 end Bc[kd0] = (Bc[kd0] & msk_d0) | (c & ~msk_d0) @@ -1518,7 +1518,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra @inbounds for i = 1:nc c = UInt64(0) for j = 0:63 - c |= (_UInt64(unchecked_bool_convert(C[ind])) << j) + c |= (UInt64(unchecked_bool_convert(C[ind])) << j) ind += 1 end Bc[bind] = c @@ -1529,7 +1529,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra @assert bind == kd1 c = UInt64(0) for j = 0:ld1 - c |= (_UInt64(unchecked_bool_convert(C[ind])) << j) + c |= (UInt64(unchecked_bool_convert(C[ind])) << j) ind += 1 end Bc[kd1] = (Bc[kd1] & msk_d1) | (c & ~msk_d1) @@ -1602,7 +1602,7 @@ function fill!(V::SubArray{Bool, <:Any, <:BitArray, <:Tuple{AbstractUnitRange{In I0 = V.indices[1] l0 = length(I0) l0 == 0 && return V - fill_chunks!(B.chunks, _Bool(x), first(I0), l0) + fill_chunks!(B.chunks, Bool(x), first(I0), l0) return V end @@ -1613,7 +1613,7 @@ fill!(V::SubArray{Bool, <:Any, <:BitArray, <:Tuple{AbstractUnitRange{Int}, Varar I0::AbstractUnitRange{Int}, I::Union{Int,AbstractUnitRange{Int}}...) N = length(I) quote - y = _Bool(x) + y = Bool(x) idxlens = @ncall $N index_lengths I0 d->I[d] f0 = indexoffset(I0)+1 diff --git a/base/multimedia.jl b/base/multimedia.jl index f9637f90ea7e3..883e4831a39fb 100644 --- a/base/multimedia.jl +++ b/base/multimedia.jl @@ -3,7 +3,6 @@ module Multimedia import .Base: show, print, convert, repr -using .._ConstructingFunctions export AbstractDisplay, display, pushdisplay, popdisplay, displayable, redisplay, MIME, @MIME_str, istextmime, @@ -161,9 +160,9 @@ repr(m::MIME, x; context=nothing) = istextmime(m) ? _textrepr(m, x, context) : _ repr(m::AbstractString, x; context=nothing) = repr(MIME(m), x; context=context) # strings are shown escaped for text/plain -_textrepr(m::MIME, x, context) = _String(__binrepr(m, x, context)) +_textrepr(m::MIME, x, context) = String(__binrepr(m, x, context)) _textrepr(::MIME, x::AbstractString, context) = x -_textrepr(m::MIME"text/plain", x::AbstractString, context) = _String(__binrepr(m, x, context)) +_textrepr(m::MIME"text/plain", x::AbstractString, context) = String(__binrepr(m, x, context)) function __binrepr(m::MIME, x, context) diff --git a/base/namedtuple.jl b/base/namedtuple.jl index 5043edb8473b7..37f3a3ef8436b 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -172,8 +172,8 @@ isempty(::NamedTuple{()}) = true isempty(::NamedTuple) = false empty(::NamedTuple) = NamedTuple() -prevind(@nospecialize(t::NamedTuple), i::Integer) = _Int(i)-1 -nextind(@nospecialize(t::NamedTuple), i::Integer) = _Int(i)+1 +prevind(@nospecialize(t::NamedTuple), i::Integer) = Int(i)-1 +nextind(@nospecialize(t::NamedTuple), i::Integer) = Int(i)+1 convert(::Type{NT}, nt::NT) where {names, NT<:NamedTuple{names}} = nt convert(::Type{NT}, nt::NT) where {names, T<:Tuple, NT<:NamedTuple{names,T}} = nt diff --git a/base/parse.jl b/base/parse.jl index e251a6cdccd58..7e6f35cf6b35a 100644 --- a/base/parse.jl +++ b/base/parse.jl @@ -110,7 +110,7 @@ end function tryparse_internal(::Type{T}, s::AbstractString, startpos::Int, endpos::Int, base_::Integer, raise::Bool) where T<:Integer - sgn, base, i = parseint_preamble(T<:Signed, _Int(base_), s, startpos, endpos) + sgn, base, i = parseint_preamble(T<:Signed, Int(base_), s, startpos, endpos) if sgn == 0 && base == 0 && i == 0 raise && throw(ArgumentError("input string is empty or only contains whitespace")) return nothing @@ -299,7 +299,7 @@ function tryparse_internal(::Type{Float32}, s::SubString{String}, startpos::Int, (Ptr{UInt8},Csize_t,Csize_t), s.string, s.offset+startpos-1, endpos-startpos+1) hasvalue ? val : nothing end -tryparse(::Type{T}, s::AbstractString) where {T<:Union{Float32,Float64}} = tryparse(T, _String(s)) +tryparse(::Type{T}, s::AbstractString) where {T<:Union{Float32,Float64}} = tryparse(T, String(s)) tryparse(::Type{Float16}, s::AbstractString) = convert(Union{Float16, Nothing}, tryparse(Float32, s)) tryparse_internal(::Type{Float16}, s::AbstractString, startpos::Int, endpos::Int) = @@ -366,7 +366,7 @@ end # the ±1 indexing above for ascii chars is specific to String, so convert: tryparse_internal(T::Type{Complex{S}}, s::AbstractString, i::Int, e::Int, raise::Bool) where S<:Real = - tryparse_internal(T, _String(s), i, e, raise) + tryparse_internal(T, String(s), i, e, raise) # fallback methods for tryparse_internal tryparse_internal(::Type{T}, s::AbstractString, startpos::Int, endpos::Int) where T<:Real = diff --git a/base/path.jl b/base/path.jl index 15799682035f5..4a3605dc398ed 100644 --- a/base/path.jl +++ b/base/path.jl @@ -53,7 +53,7 @@ elseif Sys.iswindows() function splitdrive(path::String) m = match(splitdrive_re, path)::AbstractMatch - _String(something(m.captures[1])), _String(something(m.captures[2])) + String(something(m.captures[1])), String(something(m.captures[2])) end else error("path primitives for this OS need to be defined") @@ -160,7 +160,7 @@ function _splitdir_nodrive(a::String, b::String) getcapture(cs, i) = cs[i]::AbstractString c1, c2, c3 = getcapture(cs, 1), getcapture(cs, 2), getcapture(cs, 3) a = string(a, isempty(c1) ? c2[1] : c1) - a, _String(c3) + a, String(c3) end """ @@ -227,7 +227,7 @@ function splitext(path::String) a, b = splitdrive(path) m = match(path_ext_splitter, b) m === nothing && return (path,"") - (a*something(m.captures[1])), _String(something(m.captures[2])) + (a*something(m.captures[1])), String(something(m.captures[2])) end # NOTE: deprecated in 1.4 @@ -253,7 +253,7 @@ julia> splitpath("/home/myuser/example.jl") "example.jl" ``` """ -splitpath(p::AbstractString) = splitpath(_String(p)) +splitpath(p::AbstractString) = splitpath(String(p)) function splitpath(p::String) drive, p = splitdrive(p) @@ -608,10 +608,10 @@ function relpath(path::String, startpath::String = ".") return isempty(relpath_) ? curdir : relpath_ end relpath(path::AbstractString, startpath::AbstractString) = - relpath(_String(path), _String(startpath)) + relpath(String(path), String(startpath)) for f in (:isdirpath, :splitdir, :splitdrive, :splitext, :normpath, :abspath) - @eval $f(path::AbstractString) = $f(_String(path)) + @eval $f(path::AbstractString) = $f(String(path)) end # RFC3986 Section 2.1 @@ -665,4 +665,4 @@ else end end -uripath(path::AbstractString) = uripath(_String(path)) +uripath(path::AbstractString) = uripath(String(path)) diff --git a/base/pcre.jl b/base/pcre.jl index c6cc482bc43e8..98215677a8aad 100644 --- a/base/pcre.jl +++ b/base/pcre.jl @@ -155,7 +155,7 @@ end function compile(pattern::AbstractString, options::Integer) if !(pattern isa Union{String,SubString{String}}) - pattern = _String(pattern) + pattern = String(pattern) end errno = RefValue{Cint}(0) erroff = RefValue{Csize_t}(0) @@ -266,8 +266,8 @@ function capture_names(re) offset = (i-1)*name_entry_size + 1 # The capture group index corresponding to name 'i' is stored as a # big-endian 16-bit value. - high_byte = _UInt16(unsafe_load(nametable_ptr, offset)) - low_byte = _UInt16(unsafe_load(nametable_ptr, offset+1)) + high_byte = UInt16(unsafe_load(nametable_ptr, offset)) + low_byte = UInt16(unsafe_load(nametable_ptr, offset+1)) idx = (high_byte << 8) | low_byte # The capture group name is a null-terminated string located directly # after the index. diff --git a/base/pointer.jl b/base/pointer.jl index 44d0dae84d267..72c567eaf2a85 100644 --- a/base/pointer.jl +++ b/base/pointer.jl @@ -55,8 +55,8 @@ See also [`cconvert`](@ref) function unsafe_convert end # convert strings to String etc. to pass as pointers -cconvert(::Type{Ptr{UInt8}}, s::AbstractString) = _String(s) -cconvert(::Type{Ptr{Int8}}, s::AbstractString) = _String(s) +cconvert(::Type{Ptr{UInt8}}, s::AbstractString) = String(s) +cconvert(::Type{Ptr{Int8}}, s::AbstractString) = String(s) unsafe_convert(::Type{Ptr{UInt8}}, x::Symbol) = ccall(:jl_symbol_name, Ptr{UInt8}, (Any,), x) unsafe_convert(::Type{Ptr{Int8}}, x::Symbol) = ccall(:jl_symbol_name, Ptr{Int8}, (Any,), x) @@ -80,7 +80,7 @@ function unsafe_convert(::Type{Ptr{Cvoid}}, a::GenericMemoryRef{<:Any,T,Core.CPU elsz = datatype_layoutsize(MemT) isboxed = 1; isunion = 2 if arrayelem == isunion || elsz == 0 - offset = _UInt(offset) * elsz + offset = UInt(offset) * elsz offset += unsafe_convert(Ptr{Cvoid}, mem) end return offset @@ -148,10 +148,10 @@ memory region allocated as different type may be valid provided that the types a See also: [`atomic`](@ref) """ -unsafe_load(p::Ptr, i::Integer=1) = pointerref(p, _Int(i), 1) +unsafe_load(p::Ptr, i::Integer=1) = pointerref(p, Int(i), 1) unsafe_load(p::Ptr, order::Symbol) = atomic_pointerref(p, order) function unsafe_load(p::Ptr, i::Integer, order::Symbol) - unsafe_load(p + (elsize(typeof(p)) * (_Int(i) - 1)), order) + unsafe_load(p + (elsize(typeof(p)) * (Int(i) - 1)), order) end """ @@ -174,11 +174,11 @@ different type may be valid provided that the types are compatible. See also: [`atomic`](@ref) """ -unsafe_store!(p::Ptr{Any}, @nospecialize(x), i::Integer=1) = pointerset(p, x, _Int(i), 1) -unsafe_store!(p::Ptr{T}, x, i::Integer=1) where {T} = pointerset(p, convert(T,x), _Int(i), 1) +unsafe_store!(p::Ptr{Any}, @nospecialize(x), i::Integer=1) = pointerset(p, x, Int(i), 1) +unsafe_store!(p::Ptr{T}, x, i::Integer=1) where {T} = pointerset(p, convert(T,x), Int(i), 1) unsafe_store!(p::Ptr{T}, x, order::Symbol) where {T} = atomic_pointerset(p, x isa T ? x : convert(T,x), order) function unsafe_store!(p::Ptr, x, i::Integer, order::Symbol) - unsafe_store!(p + (elsize(typeof(p)) * (_Int(i) - 1)), x, order) + unsafe_store!(p + (elsize(typeof(p)) * (Int(i) - 1)), x, order) end """ diff --git a/base/precompilation.jl b/base/precompilation.jl index bc38fef5660cf..45634d877115f 100644 --- a/base/precompilation.jl +++ b/base/precompilation.jl @@ -4,8 +4,6 @@ using Base: PkgId, UUID, SHA1, parsed_toml, project_file_name_uuid, project_name project_file_manifest_path, get_deps, preferences_names, isaccessibledir, isfile_casesensitive, base_project, isdefined -using .._ConstructingFunctions - # This is currently only used for pkgprecompile but the plan is to use this in code loading in the future # see the `kc/codeloading2.0` branch struct ExplicitEnv @@ -925,7 +923,7 @@ function _precompilepkgs(pkgs::Union{Vector{String}, Vector{PkgId}}, elseif started[pkg_config] # Offset each spinner animation using the first character in the package name as the seed. # If not offset, on larger terminal fonts it looks odd that they all sync-up - anim_char = anim_chars[(i + _Int(dep.name[1])) % length(anim_chars) + 1] + anim_char = anim_chars[(i + Int(dep.name[1])) % length(anim_chars) + 1] anim_char_colored = dep in project_deps ? anim_char : color_string(anim_char, :light_black) waiting = if haskey(pkgspidlocked, pkg_config) who_has_lock = pkgspidlocked[pkg_config] @@ -1045,7 +1043,7 @@ function _precompilepkgs(pkgs::Union{Vector{String}, Vector{PkgId}}, close(std_pipe.in) # close pipe to end the std output monitor wait(t_monitor) if err isa ErrorException || (err isa ArgumentError && startswith(err.msg, "Invalid header in cache file")) - errmsg = _String(take!(get(IOBuffer, std_outputs, pkg_config))) + errmsg = String(take!(get(IOBuffer, std_outputs, pkg_config))) delete!(std_outputs, pkg_config) # so it's not shown as warnings, given error report failed_deps[pkg_config] = (strict || is_project_dep) ? string(sprint(showerror, err), "\n", strip(errmsg)) : "" !fancyprint && @lock print_lock begin @@ -1129,7 +1127,7 @@ function _precompilepkgs(pkgs::Union{Vector{String}, Vector{PkgId}}, end # show any stderr output, even if Pkg.precompile has been interrupted (quick_exit=true), given user may be # interrupting a hanging precompile job with stderr output. julia#48371 - let std_outputs = Tuple{PkgConfig,SubString{String}}[(pkg_config, strip(_String(take!(io)))) for (pkg_config,io) in std_outputs] + let std_outputs = Tuple{PkgConfig,SubString{String}}[(pkg_config, strip(String(take!(io)))) for (pkg_config,io) in std_outputs] filter!(kv -> !isempty(last(kv)), std_outputs) if !isempty(std_outputs) local plural1 = length(std_outputs) == 1 ? "y" : "ies" @@ -1173,7 +1171,7 @@ function _precompilepkgs(pkgs::Union{Vector{String}, Vector{PkgId}}, truncate(err_str, position(err_str)) pluralde = n_direct_errs == 1 ? "y" : "ies" direct = strict ? "" : "direct " - err_msg = "The following $n_direct_errs $(direct)dependenc$(pluralde) failed to precompile:\n$(_String(take!(err_str)))" + err_msg = "The following $n_direct_errs $(direct)dependenc$(pluralde) failed to precompile:\n$(String(take!(err_str)))" if internal_call # aka. auto-precompilation if isinteractive() plural1 = length(failed_deps) == 1 ? "y" : "ies" diff --git a/base/regex.jl b/base/regex.jl index e42b29e5632d8..8adb8a8b63b30 100644 --- a/base/regex.jl +++ b/base/regex.jl @@ -29,8 +29,8 @@ mutable struct Regex <: AbstractPattern function Regex(pattern::AbstractString, compile_options::Integer, match_options::Integer) pattern = _String(pattern) - compile_options = _UInt32(compile_options) - match_options = _UInt32(match_options) + compile_options = UInt32(compile_options) + match_options = UInt32(match_options) if (compile_options & ~PCRE.COMPILE_MASK) != 0 throw(ArgumentError("invalid regex compile options: $compile_options")) end @@ -305,7 +305,7 @@ Dict(m::RegexMatch) = Dict(pairs(m)) function occursin(r::Regex, s::AbstractString; offset::Integer=0) compile(r) - return PCRE.exec_r(r.regex, _String(s), offset, r.match_options) + return PCRE.exec_r(r.regex, String(s), offset, r.match_options) end function occursin(r::Regex, s::SubString{String}; offset::Integer=0) @@ -337,7 +337,7 @@ true """ function startswith(s::AbstractString, r::Regex) compile(r) - return PCRE.exec_r(r.regex, _String(s), 0, r.match_options | PCRE.ANCHORED) + return PCRE.exec_r(r.regex, String(s), 0, r.match_options | PCRE.ANCHORED) end function startswith(s::SubString{String}, r::Regex) @@ -369,7 +369,7 @@ true """ function endswith(s::AbstractString, r::Regex) compile(r) - return PCRE.exec_r(r.regex, _String(s), 0, r.match_options | PCRE.ENDANCHORED) + return PCRE.exec_r(r.regex, String(s), 0, r.match_options | PCRE.ENDANCHORED) end function endswith(s::SubString{String}, r::Regex) @@ -495,7 +495,7 @@ function _findnext_re(re::Regex, str, idx::Integer, match_data::Ptr{Cvoid}) end if matched p = PCRE.ovec_ptr(data) - ans = (_Int(unsafe_load(p,1))+1):prevind(str,_Int(unsafe_load(p,2))+1) + ans = (Int(unsafe_load(p,1))+1):prevind(str,Int(unsafe_load(p,2))+1) else ans = nothing end @@ -725,9 +725,9 @@ struct RegexMatchIterator{S <: AbstractString} overlap::Bool RegexMatchIterator(regex::Regex, string::AbstractString, ovr::Bool=false) = - new{String}(regex, _String(string), ovr) + new{String}(regex, String(string), ovr) RegexMatchIterator(regex::Regex, string::AnnotatedString, ovr::Bool=false) = - new{AnnotatedString{String}}(regex, AnnotatedString(_String(string.string), string.annotations), ovr) + new{AnnotatedString{String}}(regex, AnnotatedString(String(string.string), string.annotations), ovr) end compile(itr::RegexMatchIterator) = (compile(itr.regex); itr) eltype(::Type{<:RegexMatchIterator}) = RegexMatch diff --git a/base/secretbuffer.jl b/base/secretbuffer.jl index 127d0528dbdd1..bf37c3caa6c23 100644 --- a/base/secretbuffer.jl +++ b/base/secretbuffer.jl @@ -51,7 +51,7 @@ Instead of starting with a string, either construct the `SecretBuffer` incrementally with `SecretBuffer()` and [`write`](@ref), or use a `Vector{UInt8}` with the `Base.SecretBuffer!(::AbstractVector{UInt8})` constructor. """ -SecretBuffer(str::AbstractString) = SecretBuffer(_String(str)) +SecretBuffer(str::AbstractString) = SecretBuffer(String(str)) function SecretBuffer(str::String) buf = codeunits(str) s = SecretBuffer(sizehint=length(buf)) @@ -61,7 +61,7 @@ function SecretBuffer(str::String) seek(s, 0) s end -convert(::Type{SecretBuffer}, s::AbstractString) = SecretBuffer(_String(s)) +convert(::Type{SecretBuffer}, s::AbstractString) = SecretBuffer(String(s)) """ SecretBuffer!(data::Vector{UInt8}) diff --git a/base/show.jl b/base/show.jl index ded310c86c3bc..a085de7e5597f 100644 --- a/base/show.jl +++ b/base/show.jl @@ -1070,7 +1070,7 @@ function check_world_bounded(tn::Core.TypeName) if isa(cval, Type) && cval <: tn.wrapper max_world = @atomic partition.max_world max_world == typemax(UInt) && return nothing - return _Int(partition.min_world):_Int(max_world) + return Int(partition.min_world):Int(max_world) end end isdefined(partition, :next) || return nothing diff --git a/base/sort.jl b/base/sort.jl index db7722a110e5e..bfa65d2459680 100644 --- a/base/sort.jl +++ b/base/sort.jl @@ -14,8 +14,6 @@ import Base: sortperm, to_indices -using .._ConstructingFunctions - export # also exported by Base # order-only: issorted, @@ -1438,7 +1436,7 @@ function radix_chunk_size_heuristic(lo::Integer, hi::Integer, bits::Unsigned) # We need iterations * chunk size ≥ bits, and these cld's # make an effort to get iterations * chunk size ≈ bits - _UInt8(cld(bits, cld(bits, guess))) + UInt8(cld(bits, cld(bits, guess))) end maybe_unsigned(x::Integer) = x # this is necessary to avoid calling unsigned on BigInt diff --git a/base/stat.jl b/base/stat.jl index 2f947c8ead680..fbab5126d39bc 100644 --- a/base/stat.jl +++ b/base/stat.jl @@ -91,7 +91,7 @@ end StatStruct() = StatStruct("", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Base.UV_ENOENT) StatStruct(buf::Union{Memory{UInt8},Vector{UInt8},Ptr{UInt8}}, ioerrno::Int32) = StatStruct("", buf, ioerrno) StatStruct(desc::Union{AbstractString, OS_HANDLE}, buf::Union{Memory{UInt8},Vector{UInt8},Ptr{UInt8}}, ioerrno::Int32) = StatStruct( - desc isa OS_HANDLE ? desc : _String(desc), + desc isa OS_HANDLE ? desc : String(desc), ioerrno != 0 ? zero(UInt32) : ccall(:jl_stat_dev, UInt32, (Ptr{UInt8},), buf), ioerrno != 0 ? zero(UInt32) : ccall(:jl_stat_ino, UInt32, (Ptr{UInt8},), buf), ioerrno != 0 ? zero(UInt32) : ccall(:jl_stat_mode, UInt32, (Ptr{UInt8},), buf), @@ -380,7 +380,7 @@ function ispath(path::String) end return r == 0 end -ispath(path::AbstractString) = ispath(_String(path)) +ispath(path::AbstractString) = ispath(String(path)) """ isfifo(path)::Bool diff --git a/base/stream.jl b/base/stream.jl index 58662d88eacc0..40106436ebd05 100644 --- a/base/stream.jl +++ b/base/stream.jl @@ -629,7 +629,7 @@ function notify_filled(buffer::IOBuffer, nread::Int) end function alloc_buf_hook(stream::LibuvStream, size::UInt) - throttle = _UInt(stream.throttle) + throttle = UInt(stream.throttle) return alloc_request(stream.buffer, (size > throttle) ? throttle : size) end @@ -711,7 +711,7 @@ function uv_readcb(handle::Ptr{Cvoid}, nread::Cssize_t, buf::Ptr{Cvoid}) end nothing end - readcb_specialized(stream_unknown_type, _Int(nread), _UInt(nrequested)) + readcb_specialized(stream_unknown_type, Int(nread), UInt(nrequested)) nothing end @@ -913,7 +913,7 @@ end # bulk read / write -readbytes!(s::LibuvStream, a::Vector{UInt8}, nb = length(a)) = readbytes!(s, a, _Int(nb)) +readbytes!(s::LibuvStream, a::Vector{UInt8}, nb = length(a)) = readbytes!(s, a, Int(nb)) function readbytes!(s::LibuvStream, a::Vector{UInt8}, nb::Int) iolock_begin() sbuf = s.buffer @@ -980,16 +980,16 @@ function unsafe_read(s::LibuvStream, p::Ptr{UInt8}, nb::UInt) end if nb <= SZ_UNBUFFERED_IO # Under this limit we are OK with copying the array from the stream's buffer - wait_locked(s, sbuf, _Int(nb)) + wait_locked(s, sbuf, Int(nb)) end if bytesavailable(sbuf) >= nb unsafe_read(sbuf, p, nb) else - newbuf = _truncated_pipebuffer(unsafe_wrap(Array, p, nb); maxsize=_Int(nb)) + newbuf = _truncated_pipebuffer(unsafe_wrap(Array, p, nb); maxsize=Int(nb)) try s.buffer = newbuf write(newbuf, sbuf) - wait_locked(s, newbuf, _Int(nb)) + wait_locked(s, newbuf, Int(nb)) finally s.buffer = sbuf end diff --git a/base/strings/annotated_io.jl b/base/strings/annotated_io.jl index c5e23e161efb3..9698fd5909b68 100644 --- a/base/strings/annotated_io.jl +++ b/base/strings/annotated_io.jl @@ -37,7 +37,7 @@ function write(io::AnnotatedIOBuffer, astr::Union{AnnotatedString, SubString{<:A offset = position(io.io) eof(io) || _clear_annotations_in_region!(io.annotations, offset+1:offset+ncodeunits(astr)) _insert_annotations!(io, astr.annotations) - write(io.io, _String(astr)) + write(io.io, String(astr)) end write(io::AnnotatedIOBuffer, c::AnnotatedChar) = @@ -211,7 +211,7 @@ using ..Base: eachregion, invoke_in_world, tls_world_age # Write -ansi_write(f::Function, io::IO, x::Any) = f(io, _String(x)) +ansi_write(f::Function, io::IO, x::Any) = f(io, String(x)) ansi_write_(f::Function, io::IO, @nospecialize(x::Any)) = invoke_in_world(tls_world_age(), ansi_write, f, io, x) diff --git a/base/strings/basic.jl b/base/strings/basic.jl index 5bbd252485dea..352d42eb3a40f 100644 --- a/base/strings/basic.jl +++ b/base/strings/basic.jl @@ -105,7 +105,7 @@ UInt8 See also [`ncodeunits`](@ref), [`checkbounds`](@ref). """ @propagate_inbounds codeunit(s::AbstractString, i::Integer) = i isa Int ? - throw(MethodError(codeunit, (s, i))) : codeunit(s, _Int(i)) + throw(MethodError(codeunit, (s, i))) : codeunit(s, Int(i)) """ isvalid(s::AbstractString, i::Integer)::Bool @@ -141,7 +141,7 @@ Stacktrace: ``` """ @propagate_inbounds isvalid(s::AbstractString, i::Integer) = i isa Int ? - throw(MethodError(isvalid, (s, i))) : isvalid(s, _Int(i)) + throw(MethodError(isvalid, (s, i))) : isvalid(s, Int(i)) """ iterate(s::AbstractString, i::Integer)::Union{Tuple{<:AbstractChar, Int}, Nothing} @@ -154,7 +154,7 @@ of the iteration protocol may assume that `i` is the start of a character in `s` See also [`getindex`](@ref), [`checkbounds`](@ref). """ @propagate_inbounds iterate(s::AbstractString, i::Integer) = i isa Int ? - throw(MethodError(iterate, (s, i))) : iterate(s, _Int(i)) + throw(MethodError(iterate, (s, i))) : iterate(s, Int(i)) ## basic generic definitions ## @@ -217,11 +217,11 @@ checkbounds(s::AbstractString, I::Union{Integer,AbstractArray}) = string() = "" string(s::AbstractString) = s -Vector{UInt8}(s::AbstractString) = unsafe_wrap(Vector{UInt8}, _String(s)) -Array{UInt8}(s::AbstractString) = unsafe_wrap(Vector{UInt8}, _String(s)) +Vector{UInt8}(s::AbstractString) = unsafe_wrap(Vector{UInt8}, String(s)) +Array{UInt8}(s::AbstractString) = unsafe_wrap(Vector{UInt8}, String(s)) Vector{T}(s::AbstractString) where {T<:AbstractChar} = collect(T, s) -Symbol(s::AbstractString) = Symbol(_String(s)) +Symbol(s::AbstractString) = Symbol(String(s)) Symbol(x...) = Symbol(string(x...)) convert(::Type{T}, s::T) where {T<:AbstractString} = s @@ -364,7 +364,7 @@ isless(a::Symbol, b::Symbol) = cmp(a, b) < 0 # hashing -hash(s::AbstractString, h::UInt) = hash(_String(s), h) +hash(s::AbstractString, h::UInt) = hash(String(s), h) ## character index arithmetic ## @@ -412,7 +412,7 @@ function length(s::AbstractString, i::Int, j::Int) end @propagate_inbounds length(s::AbstractString, i::Integer, j::Integer) = - length(s, _Int(i), _Int(j)) + length(s, Int(i), Int(j)) """ thisind(s::AbstractString, i::Integer)::Int @@ -446,7 +446,7 @@ ERROR: BoundsError: attempt to access 2-codeunit String at index [-1] [...] ``` """ -thisind(s::AbstractString, i::Integer) = thisind(s, _Int(i)) +thisind(s::AbstractString, i::Integer) = thisind(s, Int(i)) function thisind(s::AbstractString, i::Int) z = ncodeunits(s)::Int + 1 @@ -502,8 +502,8 @@ julia> prevind("α", 2, 3) -1 ``` """ -prevind(s::AbstractString, i::Integer, n::Integer) = prevind(s, _Int(i), _Int(n)) -prevind(s::AbstractString, i::Integer) = prevind(s, _Int(i)) +prevind(s::AbstractString, i::Integer, n::Integer) = prevind(s, Int(i), Int(n)) +prevind(s::AbstractString, i::Integer) = prevind(s, Int(i)) prevind(s::AbstractString, i::Int) = prevind(s, i, 1) function prevind(s::AbstractString, i::Int, n::Int) @@ -561,8 +561,8 @@ julia> nextind("α", 1, 2) 4 ``` """ -nextind(s::AbstractString, i::Integer, n::Integer) = nextind(s, _Int(i), _Int(n)) -nextind(s::AbstractString, i::Integer) = nextind(s, _Int(i)) +nextind(s::AbstractString, i::Integer, n::Integer) = nextind(s, Int(i), Int(n)) +nextind(s::AbstractString, i::Integer) = nextind(s, Int(i)) nextind(s::AbstractString, i::Int) = nextind(s, i, 1) function nextind(s::AbstractString, i::Int, n::Int) @@ -621,7 +621,7 @@ julia> replace("abcdeγfgh", !isascii=>' ') # replace non-ASCII chars with space """ isascii(c::Char) = bswap(reinterpret(UInt32, c)) < 0x80 isascii(s::AbstractString) = all(isascii, s) -isascii(c::AbstractChar) = _UInt32(c) < 0x80 +isascii(c::AbstractChar) = UInt32(c) < 0x80 @inline function _isascii(code_units::AbstractVector{CU}, first, last) where {CU} r = zero(CU) @@ -757,7 +757,7 @@ julia> repeat("ha", 3) "hahaha" ``` """ -repeat(s::AbstractString, r::Integer) = repeat(_String(s), r) +repeat(s::AbstractString, r::Integer) = repeat(String(s), r) """ ^(s::Union{AbstractString,AbstractChar}, n::Integer)::AbstractString diff --git a/base/strings/cstring.jl b/base/strings/cstring.jl index 5da0e6aee9421..56cf1c331651c 100644 --- a/base/strings/cstring.jl +++ b/base/strings/cstring.jl @@ -67,7 +67,7 @@ cconvert(::Type{Cstring}, s::AbstractString) = cconvert(Cstring, _String(s)) function cconvert(::Type{Cwstring}, s::AbstractString) - v = transcode(Cwchar_t, _String(s)) + v = transcode(Cwchar_t, String(s)) push!(v, 0) return cconvert(Cwstring, v) end @@ -117,7 +117,7 @@ same argument. This is only available on Windows. """ function cwstring(s::AbstractString) - bytes = codeunits(_String(s)) + bytes = codeunits(String(s)) 0 in bytes && throw(ArgumentError("embedded NULs are not allowed in C strings: $(repr(s))")) return push!(transcode(UInt16, bytes), 0) end @@ -163,9 +163,9 @@ function transcode end transcode(::Type{T}, src::AbstractVector{T}) where {T<:Union{UInt8,UInt16,UInt32,Int32}} = src transcode(::Type{T}, src::String) where {T<:Union{Int32,UInt32}} = T[T(c) for c in src] transcode(::Type{T}, src::AbstractVector{UInt8}) where {T<:Union{Int32,UInt32}} = - transcode(T, _String(Vector(src))) + transcode(T, String(Vector(src))) transcode(::Type{T}, src::CodeUnits{UInt8,String}) where {T<:Union{Int32,UInt32}} = - transcode(T, _String(src)) + transcode(T, String(src)) function transcode(::Type{UInt8}, src::Vector{<:Union{Int32,UInt32}}) buf = IOBuffer() @@ -176,7 +176,7 @@ function transcode(::Type{UInt8}, src::Vector{<:Union{Int32,UInt32}}) end transcode(::Type{String}, src::String) = src transcode(T, src::String) = transcode(T, codeunits(src)) -transcode(::Type{String}, src) = _String(transcode(UInt8, src)) +transcode(::Type{String}, src) = String(transcode(UInt8, src)) function transcode(::Type{UInt16}, src::AbstractVector{UInt8}) require_one_based_indexing(src) @@ -193,24 +193,24 @@ function transcode(::Type{UInt16}, src::AbstractVector{UInt8}) push!(dst, a) a = b; continue elseif a < 0xe0 # 2-byte UTF-8 - push!(dst, xor(0x3080, _UInt16(a) << 6, b)) + push!(dst, xor(0x3080, UInt16(a) << 6, b)) elseif i < n # 3/4-byte character c = src[i += 1] if -64 <= (c % Int8) # invalid UTF-8 (non-continuation) push!(dst, a, b) a = c; continue elseif a < 0xf0 # 3-byte UTF-8 - push!(dst, xor(0x2080, _UInt16(a) << 12, _UInt16(b) << 6, c)) + push!(dst, xor(0x2080, UInt16(a) << 12, UInt16(b) << 6, c)) elseif i < n d = src[i += 1] if -64 <= (d % Int8) # invalid UTF-8 (non-continuation) push!(dst, a, b, c) a = d; continue elseif a == 0xf0 && b < 0x90 # overlong encoding - push!(dst, xor(0x2080, _UInt16(b) << 12, _UInt16(c) << 6, d)) + push!(dst, xor(0x2080, UInt16(b) << 12, UInt16(c) << 6, d)) else # 4-byte UTF-8 - push!(dst, 0xe5b8 + (_UInt16(a) << 8) + (_UInt16(b) << 2) + (c >> 4), - xor(0xdc80, _UInt16(c & 0xf) << 6, d)) + push!(dst, 0xe5b8 + (UInt16(a) << 8) + (UInt16(b) << 2) + (c >> 4), + xor(0xdc80, UInt16(c & 0xf) << 6, d)) end else # too short push!(dst, a, b, c) diff --git a/base/strings/io.jl b/base/strings/io.jl index bbba16922cb64..6694becd7fad5 100644 --- a/base/strings/io.jl +++ b/base/strings/io.jl @@ -364,7 +364,7 @@ function _join_preserve_annotations(iterator, args...) seekstart(io) read(io, AnnotatedString{String}) else - _String(take!(io.io)) + String(take!(io.io)) end end end @@ -442,14 +442,14 @@ function escape_string(io::IO, s::AbstractString, esc=""; keep = (), ascii::Bool c == '\0' ? print(io, escape_nul(peek(a)::Union{AbstractChar,Nothing})) : c == '\e' ? print(io, "\\e") : c == '\\' ? print(io, "\\\\") : - '\a' <= c <= '\r' ? print(io, '\\', "abtnvfr"[_Int(c)-6]) : + '\a' <= c <= '\r' ? print(io, '\\', "abtnvfr"[Int(c)-6]) : isprint(c) ? print(io, c) : - print(io, "\\x", string(_UInt32(c), base = 16, pad = 2)) + print(io, "\\x", string(UInt32(c), base = 16, pad = 2)) elseif !isoverlong(c) && !ismalformed(c) !ascii && isprint(c) ? print(io, c) : - c <= '\x7f' ? print(io, "\\x", string(_UInt32(c), base = 16, pad = 2)) : - c <= '\uffff' ? print(io, "\\u", string(_UInt32(c), base = 16, pad = fullhex || need_full_hex(peek(a)::Union{AbstractChar,Nothing}) ? 4 : 2)) : - print(io, "\\U", string(_UInt32(c), base = 16, pad = fullhex || need_full_hex(peek(a)::Union{AbstractChar,Nothing}) ? 8 : 4)) + c <= '\x7f' ? print(io, "\\x", string(UInt32(c), base = 16, pad = 2)) : + c <= '\uffff' ? print(io, "\\u", string(UInt32(c), base = 16, pad = fullhex || need_full_hex(peek(a)::Union{AbstractChar,Nothing}) ? 4 : 2)) : + print(io, "\\U", string(UInt32(c), base = 16, pad = fullhex || need_full_hex(peek(a)::Union{AbstractChar,Nothing}) ? 8 : 4)) else # malformed or overlong u = bswap(reinterpret(UInt32, c)::UInt32) while true @@ -800,7 +800,7 @@ end function AnnotatedString(chars::AbstractVector{C}) where {C<:AbstractChar} str = if C <: AnnotatedChar - _String(getfield.(chars, :char)) + String(getfield.(chars, :char)) else sprint(sizehint=length(chars)) do io for c in chars diff --git a/base/strings/search.jl b/base/strings/search.jl index b02974406b2bd..89b01e2d52719 100644 --- a/base/strings/search.jl +++ b/base/strings/search.jl @@ -322,7 +322,7 @@ findfirst(pattern::AbstractVector{<:Union{Int8,UInt8}}, # AbstractString implementation of the generic findnext interface function findnext(testf::Function, s::AbstractString, i::Integer) - i = _Int(i) + i = Int(i) z = ncodeunits(s) + 1 1 ≤ i ≤ z || throw(BoundsError(s, i)) @inbounds i == z || isvalid(s, i) || string_index_err(s, i) @@ -378,7 +378,7 @@ function _searchindex(s::AbstractVector{<:Union{Int8,UInt8}}, sentinel = firstindex(s) - 1 n = length(t) m = length(s) - i = _Int(_i) - sentinel + i = Int(_i) - sentinel (i < 1 || i > m+1) && throw(BoundsError(s, _i)) if n == 0 @@ -478,7 +478,7 @@ julia> findnext("Lang", "JuliaLang", 2) 6:9 ``` """ -findnext(t::AbstractString, s::AbstractString, start::Integer) = _search(s, t, _Int(start)) +findnext(t::AbstractString, s::AbstractString, start::Integer) = _search(s, t, Int(start)) """ findnext(ch::AbstractChar, string::AbstractString, start::Integer) @@ -640,7 +640,7 @@ end # AbstractString implementation of the generic findprev interface function findprev(testf::Function, s::AbstractString, i::Integer) - i = _Int(i) + i = Int(i) z = ncodeunits(s) + 1 0 ≤ i ≤ z || throw(BoundsError(s, i)) i == z && return nothing @@ -696,7 +696,7 @@ function _rsearchindex(s::AbstractVector{<:Union{Int8,UInt8}}, t::AbstractVector sentinel = firstindex(s) - 1 n = length(t) m = length(s) - k = _Int(_k) - sentinel + k = Int(_k) - sentinel k < 0 && throw(BoundsError(s, _k)) if n == 0 @@ -792,7 +792,7 @@ julia> findprev("Julia", "JuliaLang", 6) 1:5 ``` """ -findprev(t::AbstractString, s::AbstractString, i::Integer) = _rsearch(s, t, _Int(i)) +findprev(t::AbstractString, s::AbstractString, i::Integer) = _rsearch(s, t, Int(i)) """ findprev(ch::AbstractChar, string::AbstractString, start::Integer) diff --git a/base/strings/string.jl b/base/strings/string.jl index 6bb2538b26f44..21f377cef3bfe 100644 --- a/base/strings/string.jl +++ b/base/strings/string.jl @@ -10,7 +10,7 @@ struct StringIndexError <: Exception index::Int end @noinline string_index_err((@nospecialize s::AbstractString), i::Integer) = - throw(StringIndexError(s, _Int(i))) + throw(StringIndexError(s, Int(i))) function Base.showerror(io::IO, exc::StringIndexError) s = exc.string print(io, "StringIndexError: ", "invalid index [$(exc.index)]") @@ -157,7 +157,7 @@ pointer(s::String, i::Integer) = pointer(s) + _Int(i) - 1 ncodeunits(s::String) = Core.sizeof(s) codeunit(s::String) = UInt8 -codeunit(s::String, i::Integer) = codeunit(s, _Int(i)) +codeunit(s::String, i::Integer) = codeunit(s, Int(i)) @assume_effects :foldable @inline function codeunit(s::String, i::Int) @boundscheck checkbounds(s, i) b = GC.@preserve s unsafe_load(pointer(s, i)) @@ -359,7 +359,7 @@ const _UTF8_DFA_TABLE = let # let block rather than function doesn't pollute bas row = _UTF8DFAState(0) for j in 1:num_states #Calculate the shift required for the next state - to_shift = _UInt8((state_shifts[state_arrays[i,j]+1]) ) + to_shift = UInt8((state_shifts[state_arrays[i,j]+1]) ) #Shift the next state into the position of the current state row = row | (_UTF8DFAState(to_shift) << state_shifts[j]) end @@ -453,7 +453,7 @@ is_valid_continuation(c) = c & 0xc0 == 0x80 @inline function iterate(s::String, i::Int=firstindex(s)) (i % UInt) - 1 < ncodeunits(s) || return nothing b = @inbounds codeunit(s, i) - u = _UInt32(b) << 24 + u = UInt32(b) << 24 between(b, 0x80, 0xf7) || return reinterpret(Char, u), i+1 return @noinline iterate_continued(s, i, u) end @@ -466,24 +466,24 @@ function iterate_continued(s, i::Int, u::UInt32) (i += 1) > n && @goto ret @inbounds b = codeunit(s, i) b & 0xc0 == 0x80 || @goto ret - u |= _UInt32(b) << 16 + u |= UInt32(b) << 16 # second continuation byte ((i += 1) > n) | (u < 0xe0000000) && @goto ret @inbounds b = codeunit(s, i) b & 0xc0 == 0x80 || @goto ret - u |= _UInt32(b) << 8 + u |= UInt32(b) << 8 # third continuation byte ((i += 1) > n) | (u < 0xf0000000) && @goto ret @inbounds b = codeunit(s, i) b & 0xc0 == 0x80 || @goto ret - u |= _UInt32(b); i += 1 + u |= UInt32(b); i += 1 @label ret return reinterpret(Char, u), i end @propagate_inbounds function getindex(s::String, i::Int) b = codeunit(s, i) - u = _UInt32(b) << 24 + u = UInt32(b) << 24 between(b, 0x80, 0xf7) || return reinterpret(Char, u) return getindex_continued(s, i, u) end @@ -500,22 +500,22 @@ function getindex_continued(s, i::Int, u::UInt32) (i += 1) > n && @goto ret @inbounds b = codeunit(s, i) # cont byte 1 b & 0xc0 == 0x80 || @goto ret - u |= _UInt32(b) << 16 + u |= UInt32(b) << 16 ((i += 1) > n) | (u < 0xe0000000) && @goto ret @inbounds b = codeunit(s, i) # cont byte 2 b & 0xc0 == 0x80 || @goto ret - u |= _UInt32(b) << 8 + u |= UInt32(b) << 8 ((i += 1) > n) | (u < 0xf0000000) && @goto ret @inbounds b = codeunit(s, i) # cont byte 3 b & 0xc0 == 0x80 || @goto ret - u |= _UInt32(b) + u |= UInt32(b) @label ret return reinterpret(Char, u) end -getindex(s::String, r::AbstractUnitRange{<:Integer}) = s[_Int(first(r)):_Int(last(r))] +getindex(s::String, r::AbstractUnitRange{<:Integer}) = s[Int(first(r)):Int(last(r))] @inline function getindex(s::String, r::UnitRange{Int}) isempty(r) && return "" diff --git a/base/strings/substring.jl b/base/strings/substring.jl index 71faa6f83c4b6..f1e89dea2efda 100644 --- a/base/strings/substring.jl +++ b/base/strings/substring.jl @@ -48,7 +48,7 @@ end @propagate_inbounds SubString(s::T, i::Int, j::Int) where {T<:AbstractString} = SubString{T}(s, i, j) @propagate_inbounds SubString(s::T, i::Int, j::Int, v::Val{:noshift}) where {T<:AbstractString} = SubString{T}(s, i, j, v) -@propagate_inbounds SubString(s::AbstractString, i::Integer, j::Integer=lastindex(s)) = SubString(s, _Int(i), _Int(j)) +@propagate_inbounds SubString(s::AbstractString, i::Integer, j::Integer=lastindex(s)) = SubString(s, Int(i), Int(j)) @propagate_inbounds SubString(s::AbstractString, r::AbstractUnitRange{<:Integer}) = SubString(s, first(r), last(r)) @propagate_inbounds function SubString(s::SubString, i::Int, j::Int) diff --git a/base/strings/unicode.jl b/base/strings/unicode.jl index ba698bcc7efd6..4e65585faf333 100644 --- a/base/strings/unicode.jl +++ b/base/strings/unicode.jl @@ -173,7 +173,7 @@ function utf8proc_map(str::Union{String,SubString{String}}, options::Integer, ch nwords = utf8proc_decompose(str, options, buffer, nwords, chartransform) nbytes = ccall(:utf8proc_reencode, Int, (Ptr{UInt8}, Int, Cint), buffer, nwords, options) nbytes < 0 && utf8proc_error(nbytes) - return _String(resize!(buffer, nbytes)) + return String(resize!(buffer, nbytes)) end """ @@ -193,7 +193,7 @@ const _julia_charmap = Dict{UInt32,UInt32}( 0x210F => 0x0127, # hbar -> small letter h with stroke (#48870) ) -utf8proc_map(s::AbstractString, flags::Integer, chartransform::F = identity) where F = utf8proc_map(_String(s), flags, chartransform) +utf8proc_map(s::AbstractString, flags::Integer, chartransform::F = identity) where F = utf8proc_map(String(s), flags, chartransform) # Documented in Unicode module function normalize( @@ -269,7 +269,7 @@ textwidth(c::AbstractChar) = textwidth(_Char(c)) function textwidth(c::Char) u = reinterpret(UInt32, c) b = bswap(u) # from isascii(c) - b < 0x7f && return _Int(b >= 0x20) # ASCII fast path + b < 0x7f && return Int(b >= 0x20) # ASCII fast path # We can't know a priori how terminals will render invalid UTF8 chars, # so we conservatively decide a width of 1. (ismalformed(c) || is_overlong_enc(u)) && return 1 @@ -362,7 +362,7 @@ titlecase(c::AnnotatedChar) = AnnotatedChar(titlecase(c.char), annotations(c)) # returns UTF8PROC_CATEGORY code in 0:30 giving Unicode category function category_code(c::AbstractChar) - !ismalformed(c) ? category_code(_UInt32(c)) : Cint(31) + !ismalformed(c) ? category_code(UInt32(c)) : Cint(31) end function category_code(x::Integer) diff --git a/base/strings/util.jl b/base/strings/util.jl index 70800b9c0320e..9aff1cf475447 100644 --- a/base/strings/util.jl +++ b/base/strings/util.jl @@ -96,7 +96,7 @@ function Base.startswith(io::IO, prefix::Union{String,SubString{String}}) reset(io) return s == codeunits(prefix) end -Base.startswith(io::IO, prefix::AbstractString) = startswith(io, _String(prefix)) +Base.startswith(io::IO, prefix::AbstractString) = startswith(io, String(prefix)) function endswith(a::Union{String, SubString{String}}, b::Union{String, SubString{String}}) @@ -557,7 +557,7 @@ julia> rtruncate("foo", 3) See also [`ltruncate`](@ref) and [`ctruncate`](@ref). """ function rtruncate(str::AbstractString, maxwidth::Integer, replacement::Union{AbstractString,AbstractChar} = '…') - ret = string_truncate_boundaries(str, _Int(maxwidth), replacement, Val(:right)) + ret = string_truncate_boundaries(str, Int(maxwidth), replacement, Val(:right)) if isnothing(ret) return string(str) else @@ -590,7 +590,7 @@ julia> ltruncate("foo", 3) See also [`rtruncate`](@ref) and [`ctruncate`](@ref). """ function ltruncate(str::AbstractString, maxwidth::Integer, replacement::Union{AbstractString,AbstractChar} = '…') - ret = string_truncate_boundaries(str, _Int(maxwidth), replacement, Val(:left)) + ret = string_truncate_boundaries(str, Int(maxwidth), replacement, Val(:left)) if isnothing(ret) return string(str) else @@ -624,7 +624,7 @@ julia> ctruncate("foo", 3) See also [`ltruncate`](@ref) and [`rtruncate`](@ref). """ function ctruncate(str::AbstractString, maxwidth::Integer, replacement::Union{AbstractString,AbstractChar} = '…'; prefer_left::Bool = true) - ret = string_truncate_boundaries(str, _Int(maxwidth), replacement, Val(:center), prefer_left) + ret = string_truncate_boundaries(str, Int(maxwidth), replacement, Val(:center), prefer_left) if isnothing(ret) return string(str) else @@ -996,7 +996,7 @@ function _replace_finish(io::IO, str, count::Int, j > e1 && break if i == a || i <= k # copy out preserved portion - GC.@preserve str unsafe_write(io, pointer(str, i), _UInt(j-i)) + GC.@preserve str unsafe_write(io, pointer(str, i), UInt(j-i)) # copy out replacement string _replace(io, replaces[p], str, r, patterns[p]) end @@ -1044,11 +1044,11 @@ end # note: leave str untyped here to make it easier for packages like StringViews to hook in function _replace_(str, pat_repl::NTuple{N, Pair}, count::Int) where N - count == 0 && return _String(str) + count == 0 && return String(str) e1, patterns, replaces, rs, notfound = _replace_init(str, pat_repl, count) if notfound foreach(_free_pat_replacer, patterns) - return _String(str) + return String(str) end out = IOBuffer(sizehint=floor(Int, 1.2sizeof(str))) return takestring!(_replace_finish(out, str, count, e1, patterns, replaces, rs)) @@ -1105,10 +1105,10 @@ julia> replace("abcabc", "a" => "b", "b" => "c", r".+" => "a") ``` """ replace(io::IO, s::AbstractString, pat_f::Pair...; count=typemax(Int)) = - _replace_(io, _String(s), pat_f, _Int(count)) + _replace_(io, String(s), pat_f, Int(count)) replace(s::AbstractString, pat_f::Pair...; count=typemax(Int)) = - _replace_(_String(s), pat_f, _Int(count)) + _replace_(String(s), pat_f, Int(count)) # TODO: allow transform as the first argument to replace? @@ -1195,7 +1195,7 @@ function hex2bytes!(dest::AbstractArray{UInt8}, itr) return dest end -@inline number_from_hex(c::AbstractChar) = number_from_hex(_Char(c)) +@inline number_from_hex(c::AbstractChar) = number_from_hex(Char(c)) @inline number_from_hex(c::Char) = number_from_hex(UInt8(c)) @inline function number_from_hex(c::UInt8) UInt8('0') <= c <= UInt8('9') && return c - UInt8('0') @@ -1246,7 +1246,7 @@ end function bytes2hex(io::IO, itr) eltype(itr) === UInt8 || throw(ArgumentError("eltype of iterator not UInt8")) for x in itr - print(io, _Char(hex_chars[1 + x >> 4]), _Char(hex_chars[1 + x & 0xf])) + print(io, Char(hex_chars[1 + x >> 4]), Char(hex_chars[1 + x & 0xf])) end end @@ -1278,7 +1278,7 @@ julia> ascii("abcdefgh") "abcdefgh" ``` """ -ascii(x::AbstractString) = ascii(_String(x)) +ascii(x::AbstractString) = ascii(String(x)) Base.rest(s::Union{String,SubString{String}}, i=1) = SubString(s, i) function Base.rest(s::AbstractString, st...) diff --git a/base/sysinfo.jl b/base/sysinfo.jl index 818965c8b7ec4..06e5cd298caf1 100644 --- a/base/sysinfo.jl +++ b/base/sysinfo.jl @@ -676,7 +676,7 @@ function which(program_name::String) # If we couldn't find anything, don't return anything nothing end -which(program_name::AbstractString) = which(_String(program_name)) +which(program_name::AbstractString) = which(String(program_name)) """ Sys.username()::String diff --git a/base/terminfo.jl b/base/terminfo.jl index 748279ec36382..be0dd53b1ac74 100644 --- a/base/terminfo.jl +++ b/base/terminfo.jl @@ -85,7 +85,7 @@ function read(data::IO, ::Type{TermInfoRaw}) name_bytes, flag_bytes, numbers_count, string_count, table_bytes = @ntuple 5 _->read(data, Int16) |> ltoh # Terminal Names - term_names = map(String, split(_String(read(data, name_bytes - 1)), '|')) + term_names = map(String, split(String(read(data, name_bytes - 1)), '|')) 0x00 == read(data, UInt8) || throw(ArgumentError("Terminfo data did not contain a null byte after the terminal names section")) # Boolean Flags @@ -131,7 +131,7 @@ function extendedterminfo(data::IO, NumInt::Union{Type{Int16}, Type{Int32}}) table_indices = map(ltoh, reinterpret(Int16, read(data, table_count * sizeof(Int16)))) table_data = read(data, table_bytes) strings = _terminfo_read_strings(table_data, table_indices[1:string_count]) - table_halfoffset = _Int16(get(table_indices, string_count, 0) + + table_halfoffset = Int16(get(table_indices, string_count, 0) + ncodeunits(something(get(strings, length(strings), ""), "")) + 1) for index in string_count+1:lastindex(table_indices) table_indices[index] += table_halfoffset @@ -183,7 +183,7 @@ function TermInfo(raw::TermInfoRaw) aliases[flag.capname] = flag.name end for (num, value) in zip(TERM_NUMBERS, raw.numbers) - numbers[num.name] = _Int(value) + numbers[num.name] = Int(value) aliases[num.capname] = num.name end for (str, value) in zip(TERM_STRINGS, raw.strings) @@ -250,7 +250,7 @@ taken to be the first entry of `@TERMINFO_DIRS@`. """ function find_terminfo_file(term::String) isempty(term) && return - chr, chrcode = string(first(term)), string(_Int(first(term)), base=16) + chr, chrcode = string(first(term)), string(Int(first(term)), base=16) terminfo_dirs = if haskey(ENV, "TERMINFO") [ENV["TERMINFO"]] elseif isdir(joinpath(homedir(), ".terminfo")) diff --git a/base/timing.jl b/base/timing.jl index 2db533a5c6326..998103d1e78bc 100644 --- a/base/timing.jl +++ b/base/timing.jl @@ -202,7 +202,7 @@ function format_bytes(bytes; binary=true) # also used by InteractiveUtils factor = binary ? 1024 : 1000 bytes, mb = prettyprint_getunits(bytes, length(units), Int64(factor)) if mb == 1 - return string(_Int(bytes), " ", _mem_units[mb], bytes==1 ? "" : "s") + return string(Int(bytes), " ", _mem_units[mb], bytes==1 ? "" : "s") else return string(Ryu.writefixed(Float64(bytes), 3), binary ? " $(units[mb])" : "$(units[mb])B") end @@ -223,7 +223,7 @@ function time_print(io::IO, elapsedtime, bytes=0, gctime=0, allocs=0, lock_confl if bytes != 0 || allocs != 0 allocs, ma = prettyprint_getunits(allocs, length(_cnt_units), Int64(1000)) if ma == 1 - print(io, _Int(allocs), _cnt_units[ma], allocs==1 ? " allocation: " : " allocations: ") + print(io, Int(allocs), _cnt_units[ma], allocs==1 ? " allocation: " : " allocations: ") else print(io, Ryu.writefixed(Float64(allocs), 2), _cnt_units[ma], " allocations: ") end diff --git a/base/toml_parser.jl b/base/toml_parser.jl index 94a6b5da032bf..bf13fc2b0617a 100644 --- a/base/toml_parser.jl +++ b/base/toml_parser.jl @@ -8,7 +8,6 @@ TOML.jl standard library instead (by `import TOML` or `using TOML`). module TOML using Base: IdSet -using .._ConstructingFunctions # we parse DateTime into these internal structs, # unless a different DateTime library is passed to the Parser constructor @@ -618,7 +617,7 @@ function _parse_key(l::Parser) c = eat_char(l) return ParserError(ErrInvalidBareKeyCharacter, c) end - _String(take_substring(l)) + String(take_substring(l)) else c = eat_char(l) return ParserError(ErrInvalidBareKeyCharacter, c) diff --git a/base/tuple.jl b/base/tuple.jl index d4d1e86e744f9..62a07f7ecf6a2 100644 --- a/base/tuple.jl +++ b/base/tuple.jl @@ -144,8 +144,8 @@ CartesianIndex(1, 3) """ function nextind end -prevind(@nospecialize(t::Tuple), i::Integer) = _Int(i)-1 -nextind(@nospecialize(t::Tuple), i::Integer) = _Int(i)+1 +prevind(@nospecialize(t::Tuple), i::Integer) = Int(i)-1 +nextind(@nospecialize(t::Tuple), i::Integer) = Int(i)+1 function keys(t::Tuple, t2::Tuple...) @inline diff --git a/base/twiceprecision.jl b/base/twiceprecision.jl index c7a889d73d848..920ba71eba24f 100644 --- a/base/twiceprecision.jl +++ b/base/twiceprecision.jl @@ -407,7 +407,7 @@ function (:)(start::T, step::T, stop::T) where T<:IEEEFloat rem(den, start_d) == 0 && rem(den, step_d) == 0 # check lcm overflow start_n = round(Int, start*den) step_n = round(Int, step*den) - len = max(0, _Int(div(den*stop_n - stop_d*start_n + step_n*stop_d, step_n*stop_d))) + len = max(0, Int(div(den*stop_n - stop_d*start_n + step_n*stop_d, step_n*stop_d))) # Integer ops could overflow, so check that this makes sense if isbetween(start, start + (len-1)*step, stop + step/2) && !isbetween(start, start + len*step, stop) diff --git a/base/util.jl b/base/util.jl index 2bc1e38e9ee9a..b11757b3d771a 100644 --- a/base/util.jl +++ b/base/util.jl @@ -496,7 +496,7 @@ if Sys.iswindows() # Done. passbuf_ = passbuf[1:passlen[]-1] - result = (_String(transcode(UInt8, usernamebuf[1:usernamelen[]-1])), + result = (String(transcode(UInt8, usernamebuf[1:usernamelen[]-1])), SecretBuffer!(transcode(UInt8, passbuf_))) securezero!(passbuf_) securezero!(passbuf) diff --git a/base/uuid.jl b/base/uuid.jl index 22209aa170c4f..4b9bae863d926 100644 --- a/base/uuid.jl +++ b/base/uuid.jl @@ -40,7 +40,7 @@ _crc32c(uuid::UUID, crc::UInt32=0x00000000) = _crc32c(uuid.value, crc) let @inline function uuid_kernel(s, i, u) - _c = _UInt32(@inbounds codeunit(s, i)) + _c = UInt32(@inbounds codeunit(s, i)) d = __convert_digit(_c, UInt32(16)) d >= 16 && return nothing u <<= 4 diff --git a/base/version.jl b/base/version.jl index b129d3a433490..aafd51b0cf85f 100644 --- a/base/version.jl +++ b/base/version.jl @@ -82,8 +82,8 @@ VersionNumber(major::Integer, minor::Integer = 0, patch::Integer = 0, pre::Tuple{Vararg{Union{Integer,AbstractString}}} = (), bld::Tuple{Vararg{Union{Integer,AbstractString}}} = ()) = VersionNumber(VInt(major), VInt(minor), VInt(patch), - map(x->x isa Integer ? _UInt64(x) : _String(x), pre), - map(x->x isa Integer ? _UInt64(x) : _String(x), bld)) + map(x->x isa Integer ? UInt64(x) : String(x), pre), + map(x->x isa Integer ? UInt64(x) : String(x), bld)) VersionNumber(v::Tuple) = VersionNumber(v...) VersionNumber(v::VersionNumber) = v @@ -122,7 +122,7 @@ $"ix function split_idents(s::AbstractString) idents = eachsplit(s, '.') - pidents = Union{UInt64,String}[occursin(r"^\d+$", ident) ? parse(UInt64, ident) : _String(ident) for ident in idents] + pidents = Union{UInt64,String}[occursin(r"^\d+$", ident) ? parse(UInt64, ident) : String(ident) for ident in idents] return tuple(pidents...)::VerTuple end