Skip to content

Commit 83e99fe

Browse files
KenoKristofferC
authored andcommitted
Add explicit imports for types and fix bugs (#57302)
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. (cherry picked from commit 778e079)
1 parent 5518d11 commit 83e99fe

16 files changed

+36
-12
lines changed

Compiler/src/Compiler.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ using Base.Order
7272

7373
import Base: ==, _topmod, append!, convert, copy, copy!, findall, first, get, get!,
7474
getindex, haskey, in, isempty, isready, iterate, iterate, last, length, max_world,
75-
min_world, popfirst!, push!, resize!, setindex!, size
75+
min_world, popfirst!, push!, resize!, setindex!, size, intersect
7676

7777
const getproperty = Core.getfield
7878
const setproperty! = Core.setfield!

base/Base_compiler.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ function cld end
227227
function fld end
228228

229229
# Lazy strings
230+
import Core: String
230231
include("strings/lazy.jl")
231232

232233
# array structures

base/bool.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3+
import Core: Bool
4+
35
# promote Bool to any other numeric type
46
promote_rule(::Type{Bool}, ::Type{T}) where {T<:Number} = T
57

base/char.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3+
import Core: AbstractChar, Char
4+
35
"""
46
The `AbstractChar` type is the supertype of all character implementations
57
in Julia. A character represents a Unicode code point, and can be converted

base/coreir.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ while processing a call, then `Conditional` everywhere else.
4949
"""
5050
Core.InterConditional
5151

52-
InterConditional(var::SlotNumber, @nospecialize(thentype), @nospecialize(elsetype)) =
52+
Core.InterConditional(var::SlotNumber, @nospecialize(thentype), @nospecialize(elsetype)) =
5353
InterConditional(slot_id(var), thentype, elsetype)

base/deprecated.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ end
353353
@deprecate one(i::CartesianIndex) oneunit(i)
354354
@deprecate one(I::Type{CartesianIndex{N}}) where {N} oneunit(I)
355355

356+
import .MPFR: BigFloat
356357
@deprecate BigFloat(x, prec::Int) BigFloat(x; precision=prec)
357358
@deprecate BigFloat(x, prec::Int, rounding::RoundingMode) BigFloat(x, rounding; precision=prec)
358359
@deprecate BigFloat(x::Real, prec::Int) BigFloat(x; precision=prec)

base/filesystem.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ export File,
137137
S_IROTH, S_IWOTH, S_IXOTH, S_IRWXO
138138

139139
import .Base:
140-
IOError, _UVError, _sizeof_uv_fs, check_open, close, eof, eventloop, fd, isopen,
141-
bytesavailable, position, read, read!, readavailable, seek, seekend, show,
140+
IOError, _UVError, _sizeof_uv_fs, check_open, close, closewrite, eof, eventloop, fd, isopen,
141+
bytesavailable, position, read, read!, readbytes!, readavailable, seek, seekend, show,
142142
skip, stat, unsafe_read, unsafe_write, write, transcode, uv_error,
143143
setup_stdio, rawhandle, OS_HANDLE, INVALID_OS_HANDLE, windowserror, filesize,
144-
isexecutable, isreadable, iswritable, MutableDenseArrayType
144+
isexecutable, isreadable, iswritable, MutableDenseArrayType, truncate
145145

146146
import .Base.RefValue
147147

base/float.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
const IEEEFloat = Union{Float16, Float32, Float64}
44

5+
import Core: Float16, Float32, Float64, AbstractFloat
6+
import Core: Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128
7+
58
## floating point traits ##
69

710
"""

base/gmp.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import .Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), xor,
1313
sign, hastypemax, isodd, iseven, digits!, hash, hash_integer, top_set_bit,
1414
clamp, unsafe_takestring
1515

16+
import Core: Signed, Float16, Float32, Float64
17+
1618
if Clong == Int32
1719
const ClongMax = Union{Int8, Int16, Int32}
1820
const CulongMax = Union{UInt8, UInt16, UInt32}

base/hamt.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,19 +239,19 @@ or grows the HAMT by inserting a new trie instead.
239239
end
240240
end
241241

242-
length(::Leaf) = 1
243-
length(trie::HAMT) = sum((length(trie.data[i]) for i in eachindex(trie.data)), init=0)
242+
Base.length(::Leaf) = 1
243+
Base.length(trie::HAMT) = sum((length(trie.data[i]) for i in eachindex(trie.data)), init=0)
244244

245-
isempty(::Leaf) = false
246-
function isempty(trie::HAMT)
245+
Base.isempty(::Leaf) = false
246+
function Base.isempty(trie::HAMT)
247247
if islevel_empty(trie)
248248
return true
249249
end
250250
return all(isempty(trie.data[i]) for i in eachindex(trie.data))
251251
end
252252

253253
# DFS
254-
function iterate(trie::HAMT, state=nothing)
254+
function Base.iterate(trie::HAMT, state=nothing)
255255
if state === nothing
256256
state = (;parent=nothing, trie, i=1)
257257
end

base/mpfr.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ import
2020
sinpi, cospi, sincospi, tanpi, sind, cosd, tand, asind, acosd, atand,
2121
uinttype, exponent_max, exponent_min, ieee754_representation, significand_mask
2222

23+
import .Core: AbstractFloat
24+
import .Base: Rational, Float16, Float32, Float64, Bool
25+
2326
using .Base.Libc
2427
import ..Rounding: Rounding,
2528
rounding_raw, setrounding_raw, rounds_to_nearest, rounds_away_from_zero,
2629
tie_breaker_is_to_even, correct_rounding_requires_increment
2730

28-
import ..GMP: ClongMax, CulongMax, CdoubleMax, Limb, libgmp
31+
import ..GMP: ClongMax, CulongMax, CdoubleMax, Limb, libgmp, BigInt
2932

3033
import ..FastMath.sincos_fast
3134

base/multidimensional.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
module IteratorsMD
55
import .Base: eltype, length, size, first, last, in, getindex, setindex!,
66
min, max, zero, oneunit, isless, eachindex,
7-
convert, show, iterate, promote_rule, to_indices, copy
7+
convert, show, iterate, promote_rule, to_indices, copy,
8+
isassigned
89

910
import .Base: +, -, *, (:)
1011
import .Base: simd_outer_range, simd_inner_length, simd_index, setindex
12+
import Core: Tuple
1113
using .Base: to_index, fill_to_length, tail, safe_tail
1214
using .Base: IndexLinear, IndexCartesian, AbstractCartesianIndex,
1315
ReshapedArray, ReshapedArrayLF, OneTo, Fix1

base/namedtuple.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3+
import Core: NamedTuple
4+
35
"""
46
NamedTuple
57

base/refpointer.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3+
import Core: Ref
4+
35
"""
46
Ref{T}
57

base/strings/basic.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3+
import Core: Symbol
4+
35
"""
46
The `AbstractString` type is the supertype of all string implementations in
57
Julia. Strings are encodings of sequences of [Unicode](https://unicode.org/)

base/tuple.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3+
import Core: Tuple
4+
35
# Document NTuple here where we have everything needed for the doc system
46
"""
57
NTuple{N, T}

0 commit comments

Comments
 (0)