From f16bed1ba4f7125e9da9ea7a8c6fc496d143ac9b Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Fri, 7 Feb 2025 08:20:06 +0000 Subject: [PATCH] Add explicit imports for types and fix bugs I was playing with strengthening the semantics around #57290. However, the particular change I was trying turned out too breaking (I may try a weaker version of it). Still, there were a number of good changes found in two categories: 1. We should explicitly import types when defining constructors. This has been allowed for a long time, but we may want to consider removing it, especially given the new binding semantics which make it more confusing as in #57290. 2. There were a couple of places where I don't think it was intended for generic functions in question not to extend Base. --- Compiler/src/Compiler.jl | 2 +- base/Base_compiler.jl | 1 + base/bool.jl | 2 ++ base/char.jl | 2 ++ base/coreir.jl | 2 +- base/deprecated.jl | 1 + base/filesystem.jl | 6 +++--- base/float.jl | 3 +++ base/gmp.jl | 2 ++ base/hamt.jl | 10 +++++----- base/mpfr.jl | 5 ++++- base/multidimensional.jl | 4 +++- base/namedtuple.jl | 2 ++ base/refpointer.jl | 2 ++ base/strings/basic.jl | 2 ++ base/tuple.jl | 2 ++ 16 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Compiler/src/Compiler.jl b/Compiler/src/Compiler.jl index ba6d1607ded55..2c68729ee1dc2 100644 --- a/Compiler/src/Compiler.jl +++ b/Compiler/src/Compiler.jl @@ -72,7 +72,7 @@ using Base.Order import Base: ==, _topmod, append!, convert, copy, copy!, findall, first, get, get!, getindex, haskey, in, isempty, isready, iterate, iterate, last, length, max_world, - min_world, popfirst!, push!, resize!, setindex!, size + min_world, popfirst!, push!, resize!, setindex!, size, intersect const getproperty = Core.getfield const setproperty! = Core.setfield! diff --git a/base/Base_compiler.jl b/base/Base_compiler.jl index 4ec6bae171d8f..20aa1f5a793ef 100644 --- a/base/Base_compiler.jl +++ b/base/Base_compiler.jl @@ -224,6 +224,7 @@ function cld end function fld end # Lazy strings +import Core: String include("strings/lazy.jl") # array structures diff --git a/base/bool.jl b/base/bool.jl index 3a5c36b09ae2c..3658318d158e5 100644 --- a/base/bool.jl +++ b/base/bool.jl @@ -1,5 +1,7 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +import Core: Bool + # promote Bool to any other numeric type promote_rule(::Type{Bool}, ::Type{T}) where {T<:Number} = T diff --git a/base/char.jl b/base/char.jl index 2e8410f6903e2..c089262ebf779 100644 --- a/base/char.jl +++ b/base/char.jl @@ -1,5 +1,7 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +import Core: AbstractChar, Char + """ The `AbstractChar` type is the supertype of all character implementations in Julia. A character represents a Unicode code point, and can be converted diff --git a/base/coreir.jl b/base/coreir.jl index 5199dfd35f028..59422afb44add 100644 --- a/base/coreir.jl +++ b/base/coreir.jl @@ -49,5 +49,5 @@ while processing a call, then `Conditional` everywhere else. """ Core.InterConditional -InterConditional(var::SlotNumber, @nospecialize(thentype), @nospecialize(elsetype)) = +Core.InterConditional(var::SlotNumber, @nospecialize(thentype), @nospecialize(elsetype)) = InterConditional(slot_id(var), thentype, elsetype) diff --git a/base/deprecated.jl b/base/deprecated.jl index f72698ad47008..eeb7c0e60638e 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -353,6 +353,7 @@ end @deprecate one(i::CartesianIndex) oneunit(i) @deprecate one(I::Type{CartesianIndex{N}}) where {N} oneunit(I) +import .MPFR: BigFloat @deprecate BigFloat(x, prec::Int) BigFloat(x; precision=prec) @deprecate BigFloat(x, prec::Int, rounding::RoundingMode) BigFloat(x, rounding; precision=prec) @deprecate BigFloat(x::Real, prec::Int) BigFloat(x; precision=prec) diff --git a/base/filesystem.jl b/base/filesystem.jl index bc1f4942877e8..87b3552c80a2f 100644 --- a/base/filesystem.jl +++ b/base/filesystem.jl @@ -137,11 +137,11 @@ export File, S_IROTH, S_IWOTH, S_IXOTH, S_IRWXO import .Base: - IOError, _UVError, _sizeof_uv_fs, check_open, close, eof, eventloop, fd, isopen, - bytesavailable, position, read, read!, readavailable, seek, seekend, show, + IOError, _UVError, _sizeof_uv_fs, check_open, close, closewrite, eof, eventloop, fd, isopen, + bytesavailable, position, read, read!, readbytes!, readavailable, seek, seekend, show, skip, stat, unsafe_read, unsafe_write, write, transcode, uv_error, setup_stdio, rawhandle, OS_HANDLE, INVALID_OS_HANDLE, windowserror, filesize, - isexecutable, isreadable, iswritable, MutableDenseArrayType + isexecutable, isreadable, iswritable, MutableDenseArrayType, truncate import .Base.RefValue diff --git a/base/float.jl b/base/float.jl index faded5cd5978c..54e232a01b8cb 100644 --- a/base/float.jl +++ b/base/float.jl @@ -2,6 +2,9 @@ const IEEEFloat = Union{Float16, Float32, Float64} +import Core: Float16, Float32, Float64, AbstractFloat +import Core: Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128 + ## floating point traits ## """ diff --git a/base/gmp.jl b/base/gmp.jl index 4d2b4b66ac41b..97488551f60f6 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -13,6 +13,8 @@ import .Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), xor, sign, hastypemax, isodd, iseven, digits!, hash, hash_integer, top_set_bit, clamp, unsafe_takestring +import Core: Signed, Float16, Float32, Float64 + if Clong == Int32 const ClongMax = Union{Int8, Int16, Int32} const CulongMax = Union{UInt8, UInt16, UInt32} diff --git a/base/hamt.jl b/base/hamt.jl index e3e4b4bd03ba9..c77c592b17e58 100644 --- a/base/hamt.jl +++ b/base/hamt.jl @@ -239,11 +239,11 @@ or grows the HAMT by inserting a new trie instead. end end -length(::Leaf) = 1 -length(trie::HAMT) = sum((length(trie.data[i]) for i in eachindex(trie.data)), init=0) +Base.length(::Leaf) = 1 +Base.length(trie::HAMT) = sum((length(trie.data[i]) for i in eachindex(trie.data)), init=0) -isempty(::Leaf) = false -function isempty(trie::HAMT) +Base.isempty(::Leaf) = false +function Base.isempty(trie::HAMT) if islevel_empty(trie) return true end @@ -251,7 +251,7 @@ function isempty(trie::HAMT) end # DFS -function iterate(trie::HAMT, state=nothing) +function Base.iterate(trie::HAMT, state=nothing) if state === nothing state = (;parent=nothing, trie, i=1) end diff --git a/base/mpfr.jl b/base/mpfr.jl index 1e39f52b9d1a3..e8380577190aa 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -20,12 +20,15 @@ import sinpi, cospi, sincospi, tanpi, sind, cosd, tand, asind, acosd, atand, uinttype, exponent_max, exponent_min, ieee754_representation, significand_mask +import .Core: AbstractFloat +import .Base: Rational, Float16, Float32, Float64, Bool + using .Base.Libc import ..Rounding: Rounding, rounding_raw, setrounding_raw, rounds_to_nearest, rounds_away_from_zero, tie_breaker_is_to_even, correct_rounding_requires_increment -import ..GMP: ClongMax, CulongMax, CdoubleMax, Limb, libgmp +import ..GMP: ClongMax, CulongMax, CdoubleMax, Limb, libgmp, BigInt import ..FastMath.sincos_fast diff --git a/base/multidimensional.jl b/base/multidimensional.jl index ba08f0679590b..40fff7243cd55 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -4,10 +4,12 @@ module IteratorsMD import .Base: eltype, length, size, first, last, in, getindex, setindex!, min, max, zero, oneunit, isless, eachindex, - convert, show, iterate, promote_rule, to_indices, copy + convert, show, iterate, promote_rule, to_indices, copy, + isassigned import .Base: +, -, *, (:) import .Base: simd_outer_range, simd_inner_length, simd_index, setindex + import Core: Tuple using .Base: to_index, fill_to_length, tail, safe_tail using .Base: IndexLinear, IndexCartesian, AbstractCartesianIndex, ReshapedArray, ReshapedArrayLF, OneTo, Fix1 diff --git a/base/namedtuple.jl b/base/namedtuple.jl index 991c4d35da52f..f71b13852b953 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -1,5 +1,7 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +import Core: NamedTuple + """ NamedTuple diff --git a/base/refpointer.jl b/base/refpointer.jl index 5027462eeb6b6..c5968934aa748 100644 --- a/base/refpointer.jl +++ b/base/refpointer.jl @@ -1,5 +1,7 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +import Core: Ref + """ Ref{T} diff --git a/base/strings/basic.jl b/base/strings/basic.jl index bf11199143c1e..3f26aed736b8d 100644 --- a/base/strings/basic.jl +++ b/base/strings/basic.jl @@ -1,5 +1,7 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +import Core: Symbol + """ The `AbstractString` type is the supertype of all string implementations in Julia. Strings are encodings of sequences of [Unicode](https://unicode.org/) diff --git a/base/tuple.jl b/base/tuple.jl index ee3174d783531..2ff8a1185a007 100644 --- a/base/tuple.jl +++ b/base/tuple.jl @@ -1,5 +1,7 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +import Core: Tuple + # Document NTuple here where we have everything needed for the doc system """ NTuple{N, T}