Skip to content

Commit 345f404

Browse files
committed
Merge pull request #10452 from JuliaLang/jb/rmlowercase
remove lowercase conversions
2 parents 768401c + c5e73bb commit 345f404

File tree

181 files changed

+2052
-2157
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+2052
-2157
lines changed

NEWS.md

+13
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ Language changes
6868
macro. Instead, the string is first unindented and then `x_str` is invoked,
6969
as if the string had been single-quoted ([#10228]).
7070

71+
* Numeric conversion functions whose names are lower-case versions of type
72+
names have been removed. To convert a scalar, use the type name, e.g.
73+
`Int32(x)`. To convert an array to a different element type, use
74+
`Array{T}(x)`, `map(T,x)`, or `round(T,x)`. To parse a string as an integer
75+
or floating-point number, use `parseint` or `parsefloat` ([#1470], [#6211]).
76+
7177
Compiler improvements
7278
---------------------
7379

@@ -963,6 +969,7 @@ Too numerous to mention.
963969
[#987]: https://github.com/JuliaLang/julia/issues/987
964970
[#1195]: https://github.com/JuliaLang/julia/issues/1195
965971
[#1268]: https://github.com/JuliaLang/julia/issues/1268
972+
[#1470]: https://github.com/JuliaLang/julia/issues/1470
966973
[#1484]: https://github.com/JuliaLang/julia/issues/1484
967974
[#1539]: https://github.com/JuliaLang/julia/issues/1539
968975
[#1571]: https://github.com/JuliaLang/julia/issues/1571
@@ -1131,6 +1138,7 @@ Too numerous to mention.
11311138
[#6169]: https://github.com/JuliaLang/julia/issues/6169
11321139
[#6179]: https://github.com/JuliaLang/julia/issues/6179
11331140
[#6197]: https://github.com/JuliaLang/julia/issues/6197
1141+
[#6211]: https://github.com/JuliaLang/julia/issues/6211
11341142
[#6212]: https://github.com/JuliaLang/julia/issues/6212
11351143
[#6270]: https://github.com/JuliaLang/julia/issues/6270
11361144
[#6273]: https://github.com/JuliaLang/julia/issues/6273
@@ -1235,10 +1243,15 @@ Too numerous to mention.
12351243
[#9734]: https://github.com/JuliaLang/julia/issues/9734
12361244
[#9745]: https://github.com/JuliaLang/julia/issues/9745
12371245
[#9779]: https://github.com/JuliaLang/julia/issues/9779
1246+
[#9862]: https://github.com/JuliaLang/julia/issues/9862
12381247
[#9957]: https://github.com/JuliaLang/julia/issues/9957
12391248
[#10024]: https://github.com/JuliaLang/julia/issues/10024
12401249
[#10031]: https://github.com/JuliaLang/julia/issues/10031
12411250
[#10075]: https://github.com/JuliaLang/julia/issues/10075
12421251
[#10117]: https://github.com/JuliaLang/julia/issues/10117
1252+
[#10150]: https://github.com/JuliaLang/julia/issues/10150
12431253
[#10180]: https://github.com/JuliaLang/julia/issues/10180
12441254
[#10228]: https://github.com/JuliaLang/julia/issues/10228
1255+
[#10332]: https://github.com/JuliaLang/julia/issues/10332
1256+
[#10333]: https://github.com/JuliaLang/julia/issues/10333
1257+
[#10400]: https://github.com/JuliaLang/julia/issues/10400

base/Enums.jl

+9-5
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ macro enum(T,syms...)
3636
throw(ArgumentError("invalid type expression for enum $T"))
3737
end
3838
vals = Array((Symbol,Integer),0)
39-
lo = typemax(Int)
40-
hi = typemin(Int)
39+
lo = hi = 0
4140
i = -1
4241
enumT = typeof(i)
4342
hasexpr = false
@@ -65,9 +64,14 @@ macro enum(T,syms...)
6564
end
6665
push!(vals, (s,i))
6766
I = typeof(i)
68-
enumT = length(vals) == 1 ? I : promote_type(enumT,I)
69-
lo = min(lo, i)
70-
hi = max(hi, i)
67+
if length(vals) == 1
68+
enumT = I
69+
lo = hi = i
70+
else
71+
enumT = promote_type(enumT,I)
72+
lo = min(lo, i)
73+
hi = max(hi, i)
74+
end
7175
end
7276
if !hasexpr
7377
n = length(vals)

base/LineEdit.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ write_prompt(terminal, s::ASCIIString) = write(terminal, s)
662662
### Keymap Support
663663

664664
normalize_key(key::Char) = string(key)
665-
normalize_key(key::Integer) = normalize_key(char(key))
665+
normalize_key(key::Integer) = normalize_key(Char(key))
666666
function normalize_key(key::AbstractString)
667667
'\0' in key && error("Matching \\0 not currently supported.")
668668
buf = IOBuffer()
@@ -944,7 +944,7 @@ function keymap{D<:Dict}(keymaps::Array{D})
944944
end
945945

946946
const escape_defaults = merge!(
947-
AnyDict([char(i) => nothing for i=vcat(1:26, 28:31)]), # Ignore control characters by default
947+
AnyDict([Char(i) => nothing for i=vcat(1:26, 28:31)]), # Ignore control characters by default
948948
AnyDict( # And ignore other escape sequences by default
949949
"\e*" => nothing,
950950
"\e[*" => nothing,

base/Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ all: pcre_h.jl errno_h.jl build_h.jl.phony fenv_constants.jl file_constants.jl u
1616

1717
pcre_h.jl:
1818
ifeq ($(USE_SYSTEM_PCRE), 1)
19-
@$(call PRINT_PERL, $(CPP) -dM $(shell $(PCRE_CONFIG) --prefix)/include/pcre.h | perl -nle '/^\s*#define\s+PCRE_(\w*)\s*\(?($(PCRE_CONST))\)?\s*$$/ and print "const $$1 = int32($$2)"' | sort > $@)
19+
@$(call PRINT_PERL, $(CPP) -dM $(shell $(PCRE_CONFIG) --prefix)/include/pcre.h | perl -nle '/^\s*#define\s+PCRE_(\w*)\s*\(?($(PCRE_CONST))\)?\s*$$/ and print "const $$1 = Int32($$2)"' | sort > $@)
2020
else
21-
@$(call PRINT_PERL, $(CPP) -dM $(build_includedir)/pcre.h | perl -nle '/^\s*#define\s+PCRE_(\w*)\s*\(?($(PCRE_CONST))\)?\s*$$/ and print "const $$1 = int32($$2)"' | sort > $@)
21+
@$(call PRINT_PERL, $(CPP) -dM $(build_includedir)/pcre.h | perl -nle '/^\s*#define\s+PCRE_(\w*)\s*\(?($(PCRE_CONST))\)?\s*$$/ and print "const $$1 = Int32($$2)"' | sort > $@)
2222
endif
2323

2424
errno_h.jl:
25-
@$(call PRINT_PERL, echo '#include "errno.h"' | $(CPP) -dM - | perl -nle 'print "const $$1 = int32($$2)" if /^#define\s+(E\w+)\s+(\d+)\s*$$/' | sort > $@)
25+
@$(call PRINT_PERL, echo '#include "errno.h"' | $(CPP) -dM - | perl -nle 'print "const $$1 = Int32($$2)" if /^#define\s+(E\w+)\s+(\d+)\s*$$/' | sort > $@)
2626

2727
fenv_constants.jl: ../src/fenv_constants.h
2828
@$(PRINT_PERL) $(CPP_STDOUT) -DJULIA -I../deps/openlibm/include ../src/fenv_constants.h | tail -n 8 | perl -ple 's/\sFE_UN\w+/ 0x10/g; s/\sFE_O\w+/ 0x08/g; s/\sFE_DI\w+/ 0x04/g; s/\sFE_INV\w+/ 0x01/g; s/\sFE_TON\w+/ 0x00/g; s/\sFE_UP\w+/ 0x800/g; s/\sFE_DO\w+/ 0x400/g; s/\sFE_TOW\w+/ 0xc00/g' > $@

base/Terminals.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ end
144144
else
145145
ccall(:jl_tty_set_mode,
146146
Int32, (Ptr{Void},Int32),
147-
t.in_stream.handle, int32(raw)) != -1
147+
t.in_stream.handle, raw) != -1
148148
end
149149
end
150150
end : begin
151151
raw!(t::TTYTerminal, raw::Bool) = ccall(:uv_tty_set_mode,
152152
Int32, (Ptr{Void},Int32),
153-
t.in_stream.handle, int32(raw)) != -1
153+
t.in_stream.handle, raw) != -1
154154
end
155155
enable_bracketed_paste(t::UnixTerminal) = write(t.out_stream, "$(CSI)?2004h")
156156
disable_bracketed_paste(t::UnixTerminal) = write(t.out_stream, "$(CSI)?2004l")
@@ -161,7 +161,7 @@ let s = zeros(Int32, 2)
161161
function Base.size(t::TTYTerminal)
162162
@windows_only if ispty(t.out_stream)
163163
try
164-
h,w = int(split(readall(open(`stty size`, "r", t.out_stream)[1])))
164+
h,w = map(parseint,split(readall(open(`stty size`, "r", t.out_stream)[1])))
165165
w > 0 || (w = 80)
166166
h > 0 || (h = 24)
167167
return h,w
@@ -175,7 +175,7 @@ let s = zeros(Int32, 2)
175175
w,h = s[1],s[2]
176176
w > 0 || (w = 80)
177177
h > 0 || (h = 24)
178-
(int(h),int(w))
178+
(Int(h),Int(w))
179179
end
180180
end
181181

base/abstractarray.jl

+25-78
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ function squeeze(A::AbstractArray, dims::Dims)
206206
reshape(A, d::typeof(_sub(size(A), dims)))
207207
end
208208

209-
squeeze(A::AbstractArray, dim::Integer) = squeeze(A, (int(dim),))
209+
squeeze(A::AbstractArray, dim::Integer) = squeeze(A, (Int(dim),))
210210

211211
function copy!(dest::AbstractArray, src)
212212
i = 1
@@ -347,73 +347,15 @@ isempty(a::AbstractArray) = (length(a) == 0)
347347

348348
## Conversions ##
349349

350-
for (f,t) in ((:char, Char),
351-
(:int, Int),
352-
(:int8, Int8),
353-
(:int16, Int16),
354-
(:int32, Int32),
355-
(:int64, Int64),
356-
(:int128, Int128),
357-
(:uint, UInt),
358-
(:uint8, UInt8),
359-
(:uint16, UInt16),
360-
(:uint32, UInt32),
361-
(:uint64, UInt64),
362-
(:uint128,UInt128))
363-
@eval begin
364-
($f)(x::AbstractArray{$t}) = x
365-
($f)(x::AbstractArray{$t}) = x
366-
367-
function ($f)(x::AbstractArray)
368-
y = similar(x,$t)
369-
i = 1
370-
for e in x
371-
y[i] = ($f)(e)
372-
i += 1
373-
end
374-
y
375-
end
376-
end
377-
end
378-
379-
for (f,t) in ((:integer, Integer),
380-
(:unsigned, Unsigned))
381-
@eval begin
382-
($f){T<:$t}(x::AbstractArray{T}) = x
383-
($f){T<:$t}(x::AbstractArray{T}) = x
384-
385-
function ($f)(x::AbstractArray)
386-
y = similar(x,typeof(($f)(one(eltype(x)))))
387-
i = 1
388-
for e in x
389-
y[i] = ($f)(e)
390-
i += 1
391-
end
392-
y
393-
end
394-
end
395-
end
396-
397-
big{T<:FloatingPoint,N}(x::AbstractArray{T,N}) = convert(AbstractArray{BigFloat,N}, x)
398-
big{T<:FloatingPoint,N}(x::AbstractArray{Complex{T},N}) = convert(AbstractArray{Complex{BigFloat},N}, x)
399-
big{T<:Integer,N}(x::AbstractArray{T,N}) = convert(AbstractArray{BigInt,N}, x)
400-
401-
bool(x::AbstractArray{Bool}) = x
402-
bool(x::AbstractArray) = copy!(similar(x,Bool), x)
403-
404350
convert{T,N }(::Type{AbstractArray{T,N}}, A::AbstractArray{T,N}) = A
405351
convert{T,S,N}(::Type{AbstractArray{T,N}}, A::AbstractArray{S,N}) = copy!(similar(A,T), A)
406352
convert{T,S,N}(::Type{AbstractArray{T }}, A::AbstractArray{S,N}) = convert(AbstractArray{T,N}, A)
407353

408354
convert{T,N}(::Type{Array}, A::AbstractArray{T,N}) = convert(Array{T,N}, A)
409355

410-
for (f,T) in ((:float16, Float16),
411-
(:float32, Float32),
412-
(:float64, Float64),
413-
(:complex64, Complex64),
414-
(:complex128, Complex128))
415-
@eval ($f){S,N}(x::AbstractArray{S,N}) = convert(AbstractArray{$T,N}, x)
416-
end
356+
big{T<:FloatingPoint,N}(x::AbstractArray{T,N}) = convert(AbstractArray{BigFloat,N}, x)
357+
big{T<:FloatingPoint,N}(x::AbstractArray{Complex{T},N}) = convert(AbstractArray{Complex{BigFloat},N}, x)
358+
big{T<:Integer,N}(x::AbstractArray{T,N}) = convert(AbstractArray{BigInt,N}, x)
417359

418360
float{T<:FloatingPoint}(x::AbstractArray{T}) = x
419361
complex{T<:Complex}(x::AbstractArray{T}) = x
@@ -434,17 +376,20 @@ end
434376

435377
full(x::AbstractArray) = x
436378

379+
map(::Type{Integer}, a::Array) = map!(Integer, similar(a,typeof(Integer(one(eltype(a))))), a)
380+
map(::Type{Signed}, a::Array) = map!(Signed, similar(a,typeof(Signed(one(eltype(a))))), a)
381+
map(::Type{Unsigned}, a::Array) = map!(Unsigned, similar(a,typeof(Unsigned(one(eltype(a))))), a)
382+
437383
## range conversions ##
438384

439-
for fn in _numeric_conversion_func_names
385+
map{T<:Real}(::Type{T}, r::StepRange) = T(r.start):T(r.step):T(last(r))
386+
map{T<:Real}(::Type{T}, r::UnitRange) = T(r.start):T(last(r))
387+
map{T<:FloatingPoint}(::Type{T}, r::FloatRange) = FloatRange(T(r.start), T(r.step), r.len, T(r.divisor))
388+
389+
for fn in (:float,:big)
440390
@eval begin
441391
$fn(r::StepRange) = $fn(r.start):$fn(r.step):$fn(last(r))
442392
$fn(r::UnitRange) = $fn(r.start):$fn(last(r))
443-
end
444-
end
445-
446-
for fn in (:float,:float16,:float32,:float64,:big)
447-
@eval begin
448393
$fn(r::FloatRange) = FloatRange($fn(r.start), $fn(r.step), r.len, $fn(r.divisor))
449394
end
450395
end
@@ -502,7 +447,7 @@ function flipdim(A::AbstractArray, d::Integer)
502447
B = similar(A)
503448
nnd = 0
504449
for i = 1:nd
505-
nnd += int(size(A,i)==1 || i==d)
450+
nnd += Int(size(A,i)==1 || i==d)
506451
end
507452
if nnd==nd
508453
# flip along the only non-singleton dimension
@@ -521,7 +466,7 @@ end
521466
flipud(A::AbstractArray) = flipdim(A, 1)
522467
fliplr(A::AbstractArray) = flipdim(A, 2)
523468

524-
circshift(a::AbstractArray, shiftamt::Real) = circshift(a, [integer(shiftamt)])
469+
circshift(a::AbstractArray, shiftamt::Real) = circshift(a, [Integer(shiftamt)])
525470
function circshift{T,N}(a::AbstractArray{T,N}, shiftamts)
526471
I = ()
527472
for i=1:N
@@ -1031,24 +976,24 @@ function repmat(a::AbstractVector, m::Int)
1031976
end
1032977

1033978
sub2ind(dims) = 1
1034-
sub2ind(dims, i::Integer) = int(i)
1035-
sub2ind(dims, i::Integer, j::Integer) = sub2ind(dims, int(i), int(j))
979+
sub2ind(dims, i::Integer) = Int(i)
980+
sub2ind(dims, i::Integer, j::Integer) = sub2ind(dims, Int(i), Int(j))
1036981
sub2ind(dims, i::Int, j::Int) = (j-1)*dims[1] + i
1037-
sub2ind(dims, i0::Integer, i1::Integer, i2::Integer) = sub2ind(dims, int(i0),int(i1),int(i2))
982+
sub2ind(dims, i0::Integer, i1::Integer, i2::Integer) = sub2ind(dims, Int(i0),Int(i1),Int(i2))
1038983
sub2ind(dims, i0::Int, i1::Int, i2::Int) =
1039984
i0 + dims[1]*((i1-1) + dims[2]*(i2-1))
1040985
sub2ind(dims, i0::Integer, i1::Integer, i2::Integer, i3::Integer) =
1041-
sub2ind(dims, int(i0),int(i1),int(i2),int(i3))
986+
sub2ind(dims, Int(i0),Int(i1),Int(i2),Int(i3))
1042987
sub2ind(dims, i0::Int, i1::Int, i2::Int, i3::Int) =
1043988
i0 + dims[1]*((i1-1) + dims[2]*((i2-1) + dims[3]*(i3-1)))
1044989

1045990
function sub2ind(dims, I::Integer...)
1046991
ndims = length(dims)
1047-
index = int(I[1])
992+
index = Int(I[1])
1048993
stride = 1
1049994
for k=2:ndims
1050995
stride = stride * dims[k-1]
1051-
index += (int(I[k])-1) * stride
996+
index += (Int(I[k])-1) * stride
1052997
end
1053998
return index
1054999
end
@@ -1084,7 +1029,7 @@ function ind2sub(dims::(Integer,Integer...), ind::Int)
10841029
return tuple(ind, sub...)
10851030
end
10861031

1087-
ind2sub(dims::(Integer...), ind::Integer) = ind2sub(dims, int(ind))
1032+
ind2sub(dims::(Integer...), ind::Integer) = ind2sub(dims, Int(ind))
10881033
ind2sub(dims::(), ind::Integer) = ind==1 ? () : throw(BoundsError())
10891034
ind2sub(dims::(Integer,), ind::Int) = (ind,)
10901035
ind2sub(dims::(Integer,Integer), ind::Int) =
@@ -1369,7 +1314,9 @@ function map_to!{T}(f, offs, dest::AbstractArray{T}, A::AbstractArray)
13691314
end
13701315

13711316
function map(f, A::AbstractArray)
1372-
if isempty(A); return similar(A); end
1317+
if isempty(A)
1318+
return isa(f,Type) ? similar(A,f) : similar(A)
1319+
end
13731320
first = f(A[1])
13741321
dest = similar(A, typeof(first))
13751322
dest[1] = first

base/array.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function copy(a::Array)
9090
end
9191

9292
function reinterpret{T,S}(::Type{T}, a::Array{S,1})
93-
nel = int(div(length(a)*sizeof(S),sizeof(T)))
93+
nel = Int(div(length(a)*sizeof(S),sizeof(T)))
9494
# TODO: maybe check that remainder is zero?
9595
return reinterpret(T, a, (nel,))
9696
end
@@ -251,7 +251,7 @@ linspace(start::Integer, stop::Integer, n::Integer) =
251251
function linspace(start::Real, stop::Real, n::Integer)
252252
(start, stop) = promote(start, stop)
253253
T = typeof(start)
254-
a = Array(T, int(n))
254+
a = Array(T, Int(n))
255255
if n == 1
256256
a[1] = start
257257
return a
@@ -960,7 +960,7 @@ function flipdim{T}(A::Array{T}, d::Integer)
960960

961961
nnd = 0
962962
for i = 1:nd
963-
nnd += int(size(A,i)==1 || i==d)
963+
nnd += Int(size(A,i)==1 || i==d)
964964
end
965965
if nnd==nd
966966
# flip along the only non-singleton dimension

base/ascii.jl

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
## required core functionality ##
99

1010
endof(s::ASCIIString) = length(s.data)
11-
getindex(s::ASCIIString, i::Int) = (x=s.data[i]; x < 0x80 ? char(x) : '\ufffd')
11+
getindex(s::ASCIIString, i::Int) = (x=s.data[i]; x < 0x80 ? Char(x) : '\ufffd')
1212

1313
## overload methods for efficiency ##
1414

@@ -17,8 +17,8 @@ sizeof(s::ASCIIString) = sizeof(s.data)
1717
getindex(s::ASCIIString, r::Vector) = ASCIIString(getindex(s.data,r))
1818
getindex(s::ASCIIString, r::UnitRange{Int}) = ASCIIString(getindex(s.data,r))
1919
getindex(s::ASCIIString, indx::AbstractVector{Int}) = ASCIIString(s.data[indx])
20-
search(s::ASCIIString, c::Char, i::Integer) = c < char(0x80) ? search(s.data,uint8(c),i) : 0
21-
rsearch(s::ASCIIString, c::Char, i::Integer) = c < char(0x80) ? rsearch(s.data,uint8(c),i) : 0
20+
search(s::ASCIIString, c::Char, i::Integer) = c < Char(0x80) ? search(s.data,c%UInt8,i) : 0
21+
rsearch(s::ASCIIString, c::Char, i::Integer) = c < Char(0x80) ? rsearch(s.data,c%UInt8,i) : 0
2222

2323
function string(c::ASCIIString...)
2424
if length(c) == 1
@@ -58,10 +58,10 @@ end
5858
function uppercase(s::ASCIIString)
5959
d = s.data
6060
for i = 1:length(d)
61-
if 'a' <= char(d[i]) <= 'z'
61+
if 'a' <= Char(d[i]) <= 'z'
6262
td = copy(d)
6363
for j = i:length(td)
64-
if 'a' <= char(td[j]) <= 'z'
64+
if 'a' <= Char(td[j]) <= 'z'
6565
td[j] -= 32
6666
end
6767
end
@@ -73,10 +73,10 @@ end
7373
function lowercase(s::ASCIIString)
7474
d = s.data
7575
for i = 1:length(d)
76-
if 'A' <= char(d[i]) <= 'Z'
76+
if 'A' <= Char(d[i]) <= 'Z'
7777
td = copy(d)
7878
for j = i:length(td)
79-
if 'A' <= char(td[j]) <= 'Z'
79+
if 'A' <= Char(td[j]) <= 'Z'
8080
td[j] += 32
8181
end
8282
end

0 commit comments

Comments
 (0)