Skip to content

Commit

Permalink
rename None to Union(), and Nothing to Void. fixes #8423
Browse files Browse the repository at this point in the history
I also use Bottom === Union() some places in Base.

remove a couple redundant show methods that snuck in somehow.
remove some missed 0.3 deprecations in cconvert.
  • Loading branch information
JeffBezanson committed Sep 25, 2014
1 parent 6d7c7c6 commit 2ef8d31
Showing 46 changed files with 229 additions and 237 deletions.
6 changes: 3 additions & 3 deletions base/LineEdit.jl
Original file line number Diff line number Diff line change
@@ -711,7 +711,7 @@ end
# If we ever actually want to match \0 in input, this will have to be reworked
function normalize_keymap(keymap::Dict)
ret = Dict{Char,Any}()
direct_keys = filter((k,v) -> isa(v, Union(Function, Nothing)), keymap)
direct_keys = filter((k,v) -> isa(v, Union(Function, Void)), keymap)
# first direct entries
for key in keys(direct_keys)
add_nested_key!(ret, key, keymap[key])
@@ -726,7 +726,7 @@ function normalize_keymap(keymap::Dict)
end

match_input(k::Function, s, cs) = (update_key_repeats(s, cs); return keymap_fcn(k, s, last(cs)))
match_input(k::Nothing, s, cs) = (s,p) -> return :ok
match_input(k::Void, s, cs) = (s,p) -> return :ok
function match_input(keymap::Dict, s, cs=Char[])
c = read(terminal(s), Char)
push!(cs, c)
@@ -735,7 +735,7 @@ function match_input(keymap::Dict, s, cs=Char[])
return match_input(get(keymap, k, nothing), s, cs)
end

keymap_fcn(f::Nothing, s, c) = (s, p) -> return :ok
keymap_fcn(f::Void, s, c) = (s, p) -> return :ok
function keymap_fcn(f::Function, s, c::Char)
return (s, p) -> begin
r = f(s, p, c)
2 changes: 1 addition & 1 deletion base/REPLCompletions.jl
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ function complete_symbol(sym, ffunc)

mod = context_module
lookup_module = true
t = None
t = Union()
for name in strs[1:(end-1)]
s = symbol(name)
if lookup_module
15 changes: 7 additions & 8 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
@@ -200,7 +200,6 @@ function copy!(dest::AbstractArray, doffs::Integer, src::AbstractArray, soffs::I
end

copy(a::AbstractArray) = copy!(similar(a), a)
copy(a::AbstractArray{None}) = a # cannot be assigned into so is immutable

function copy!{R,S}(B::AbstractMatrix{R}, ir_dest::Range{Int}, jr_dest::Range{Int}, A::AbstractMatrix{S}, ir_src::Range{Int}, jr_src::Range{Int})
if length(ir_dest) != length(ir_src) || length(jr_dest) != length(jr_src)
@@ -502,14 +501,14 @@ get(A::AbstractArray, I::RangeVecIntList, default) = get!(similar(A, typeof(defa

## Concatenation ##

promote_eltype() = None
promote_eltype() = Bottom
promote_eltype(v1, vs...) = promote_type(eltype(v1), promote_eltype(vs...))

#TODO: ERROR CHECK
cat(catdim::Integer) = Array(None, 0)
cat(catdim::Integer) = Array(Bottom, 0)

vcat() = Array(None, 0)
hcat() = Array(None, 0)
vcat() = Array(Bottom, 0)
hcat() = Array(Bottom, 0)

## cat: special cases
hcat{T}(X::T...) = T[ X[j] for i=1, j=1:length(X) ]
@@ -518,15 +517,15 @@ vcat{T}(X::T...) = T[ X[i] for i=1:length(X) ]
vcat{T<:Number}(X::T...) = T[ X[i] for i=1:length(X) ]

function vcat(X::Number...)
T = None
T = Bottom
for x in X
T = promote_type(T,typeof(x))
end
hvcat_fill(Array(T,length(X)), X)
end

function hcat(X::Number...)
T = None
T = Bottom
for x in X
T = promote_type(T,typeof(x))
end
@@ -1287,7 +1286,7 @@ function promote_to!{T}(f::Callable, offs, dest::AbstractArray{T}, A::AbstractAr
end

function map_promote(f::Callable, A::AbstractArray)
if isempty(A); return similar(A, None); end
if isempty(A); return similar(A, Bottom); end
first = f(A[1])
dest = similar(A, typeof(first))
dest[1] = first
8 changes: 4 additions & 4 deletions base/array.jl
Original file line number Diff line number Diff line change
@@ -450,7 +450,7 @@ const _grow_none_errmsg =
"[] cannot grow. Instead, initialize the array with \"T[]\", where T is the desired element type."

function push!{T}(a::Array{T,1}, item)
if is(T,None)
if is(T,Bottom)
error(_grow_none_errmsg)
end
# convert first so we don't grow the array if the assignment won't work
@@ -467,7 +467,7 @@ function push!(a::Array{Any,1}, item::ANY)
end

function append!{T}(a::Array{T,1}, items::AbstractVector)
if is(T,None)
if is(T,Bottom)
error(_grow_none_errmsg)
end
n = length(items)
@@ -477,7 +477,7 @@ function append!{T}(a::Array{T,1}, items::AbstractVector)
end

function prepend!{T}(a::Array{T,1}, items::AbstractVector)
if is(T,None)
if is(T,Bottom)
error(_grow_none_errmsg)
end
n = length(items)
@@ -518,7 +518,7 @@ function pop!(a::Vector)
end

function unshift!{T}(a::Array{T,1}, item)
if is(T,None)
if is(T,Bottom)
error(_grow_none_errmsg)
end
item = convert(T, item)
9 changes: 2 additions & 7 deletions base/base.jl
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ const NonTupleType = Union(DataType,UnionType,TypeConstructor)

typealias Callable Union(Function,DataType)

const Bottom = Union()

convert(T, x) = convert_default(T, x, convert)

convert(::(), ::()) = ()
@@ -31,13 +33,6 @@ ptr_arg_convert(::Type{Ptr{Void}}, x) = x

# conversion used by ccall
cconvert(T, x) = convert(T, x)
# the following 3 definitions implement a 0.3 deprecation
cconvert{T}(::Type{Ptr{T}}, x::Array{T}) = convert(Ptr{T}, x)
cconvert(::Type{Ptr{None}}, x::Array) = convert(Ptr{None}, x)
function cconvert{T}(::Type{Ptr{T}}, x::Array)
depwarn("ccall Ptr argument types must now match exactly, or be Ptr{Void}.", :cconvert)
convert(Ptr{T}, pointer(x))
end
# use the code in ccall.cpp to safely allocate temporary pointer arrays
cconvert{T}(::Type{Ptr{Ptr{T}}}, a::Array) = a
# convert strings to ByteString to pass as pointers
13 changes: 6 additions & 7 deletions base/boot.jl
Original file line number Diff line number Diff line change
@@ -32,8 +32,6 @@
# types::Tuple
#end

#None = Union()

#type TypeVar
# name::Symbol
# lb::Type
@@ -45,6 +43,10 @@
# body
#end

#immutable Void
#end
#const nothing = Void()

#abstract AbstractArray{T,N}
#abstract DenseArray{T,N} <: AbstractArray{T,N}

@@ -115,12 +117,12 @@ import Core.Intrinsics.ccall

export
# key types
Any, DataType, Vararg, ANY, NTuple, None, Top,
Any, DataType, Vararg, ANY, NTuple, Top,
Tuple, Type, TypeConstructor, TypeName, TypeVar, Union, UnionType, Void,
AbstractArray, DenseArray,
# special objects
Box, Function, IntrinsicFunction, LambdaStaticData, Method, MethodTable,
Module, Nothing, Symbol, Task, Array,
Module, Symbol, Task, Array,
# numeric types
Bool, FloatingPoint, Float16, Float32, Float64, Number, Integer, Int, Int8, Int16,
Int32, Int64, Int128, Ptr, Real, Signed, Uint, Uint8, Uint16, Uint32,
@@ -164,9 +166,6 @@ export
#ule_int, ult_int, unbox, urem_int, xor_int, sext_int, zext_int


immutable Nothing; end
const nothing = Nothing()

const (===) = is

abstract Number
2 changes: 1 addition & 1 deletion base/cartesian.jl
Original file line number Diff line number Diff line change
@@ -152,7 +152,7 @@ function get_splatinfo(ex::Expr, itersym::Symbol)
end
end
end
"", Nothing
"", Void
end

# Replace splatted with desplatted for a specific number of arguments
8 changes: 7 additions & 1 deletion base/deprecated.jl
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ function depwarn(msg, funcsym)
warn(msg, once=(caller!=C_NULL), key=caller, bt=bt)
end

function firstcaller(bt::Array{Ptr{None},1}, funcsym::Symbol)
function firstcaller(bt::Array{Ptr{Void},1}, funcsym::Symbol)
# Identify the calling line
i = 1
while i <= length(bt)
@@ -179,3 +179,9 @@ const IpAddr = IPAddr
@deprecate isblank(s::String) all(c -> c == ' ' || c == '\t', s)

@deprecate randbool! rand!

export Nothing
const Nothing = Void

export None
const None = Union()
4 changes: 2 additions & 2 deletions base/error.jl
Original file line number Diff line number Diff line change
@@ -25,8 +25,8 @@ macro unexpected()
:(error("unexpected branch reached"))
end

rethrow() = ccall(:jl_rethrow, Void, ())::None
rethrow(e) = ccall(:jl_rethrow_other, Void, (Any,), e)::None
rethrow() = ccall(:jl_rethrow, Void, ())::Bottom
rethrow(e) = ccall(:jl_rethrow_other, Void, (Any,), e)::Bottom
backtrace() = ccall(:jl_backtrace_from_here, Array{Ptr{Void},1}, ())
catch_backtrace() = ccall(:jl_get_backtrace, Array{Ptr{Void},1}, ())

2 changes: 1 addition & 1 deletion base/expr.jl
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ astcopy(x) = x
==(x::QuoteNode, y::QuoteNode) = x.value == y.value

function show(io::IO, tv::TypeVar)
if !is(tv.lb, None)
if !is(tv.lb, Bottom)
show(io, tv.lb)
print(io, "<:")
end
Loading

13 comments on commit 2ef8d31

@johnmyleswhite
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Party time!

Why'd you also use Bottom in addition to an empty Union?

@StefanKarpinski
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really think renaming Nothing to Void is shitty and I've said so several times, so I'm kind of miffed that you just decided to commit it to master without a PR. The change to Union() is nice though.

@StefanKarpinski
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about not exporting it?

@johnmyleswhite
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of not exporting those names a lot. It's not clear to me why most users would need to work with Nothing/Void, especially now that we have Nullable for use in lieu of Union(Nothing, T).

@jey
Copy link
Contributor

@jey jey commented on 2ef8d31 Sep 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type theorists everywhere will be crying into their cornflakes if we don't export those names.

@johnmyleswhite
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would they care about Nothing? It seems only Union() matters for the soundness of the type system.

@StefanKarpinski
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good reason.

@jey
Copy link
Contributor

@jey jey commented on 2ef8d31 Sep 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnmyleswhite: I was mostly joking -- I don't actually have a solid opinion, but it does seem odd for typeof(nothing) to be something that's not exported from Base.

@johnmyleswhite
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying. I thought you might be employing my favorite strategy of using a joke to make a serious statement.

I was assuming nothing might also not be exported.

@simonster
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern

function f(a::T, b::T, c::Union(Void, T)=nothing)
...
end

still seems useful in cases where you can't compute the default within the function declaration. You will avoid heap-allocating a Nullable object if T is not a bits type and the compiler will generate code specialized on the presence or absence of c. The syntax to call said function will also be nicer.

@johnmyleswhite
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a really good point. I wonder how often that occurs.

@JeffBezanson
Copy link
Member Author

@JeffBezanson JeffBezanson commented on 2ef8d31 Sep 26, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@StefanKarpinski
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's stick with this for a while. If I (and others) still hate it after a few weeks, we can revisit the issue.

Please sign in to comment.