Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bunch of stuff for 0.7 #435

Merged
merged 8 commits into from
Dec 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ Currently, the `@compat` macro supports the following syntaxes:
* `using Compat.Unicode` is provided on versions older than 0.7, where this library is not
yet a part of the standard library. ([#25021])

* `using Compat.Printf` is provided on versions older than 0.7, where this library is not
yet a part of the standard library. ([#25056])

* `using Compat.IterativeEigensolvers` is provided on versions older than 0.7, where this
library is not yet a part of the standard library. ([#24714])

* `using Compat.SuiteSparse` is provided on versions older than 0.7, where this library is
not yet part of the standard library ([#24648]).

## New functions, macros, and methods

* `@views` takes an expression and converts all slices to views ([#20164]), while
Expand Down Expand Up @@ -208,6 +217,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `get` do-block syntax supported when using `ENV` ([#23412]).

* `Some{T}` wraps `T` to signify that a result of `T<:Void` is expected ([#23642]).

## Renaming


Expand Down Expand Up @@ -244,6 +255,12 @@ Currently, the `@compat` macro supports the following syntaxes:
* `Complex32`, `Complex64`, and `Complex128` are now `ComplexF16`, `ComplexF32`, and
`ComplexF64`, respectively ([#24647]).

* `Associative` is now `AbstractDict` ([#25012]).

* `indices` is now `axes` ([#25057]).

* `Void` is now `Nothing` with an alias `Cvoid` for C interop ([#25162]).

## New macros

* `@__DIR__` has been added ([#18380])
Expand Down Expand Up @@ -378,6 +395,7 @@ includes this fix. Find the minimum version from there.
[#23412]: https://github.com/JuliaLang/julia/issues/23412
[#23427]: https://github.com/JuliaLang/julia/issues/23427
[#23570]: https://github.com/JuliaLang/julia/issues/23570
[#23642]: https://github.com/JuliaLang/julia/issues/23642
[#23666]: https://github.com/JuliaLang/julia/issues/23666
[#23757]: https://github.com/JuliaLang/julia/issues/23757
[#23812]: https://github.com/JuliaLang/julia/issues/23812
Expand All @@ -389,7 +407,13 @@ includes this fix. Find the minimum version from there.
[#24459]: https://github.com/JuliaLang/julia/issues/24459
[#24605]: https://github.com/JuliaLang/julia/issues/24605
[#24647]: https://github.com/JuliaLang/julia/issues/24647
[#24648]: https://github.com/JuliaLang/julia/issues/24648
[#24652]: https://github.com/JuliaLang/julia/issues/24652
[#24657]: https://github.com/JuliaLang/julia/issues/24657
[#24714]: https://github.com/JuliaLang/julia/issues/24714
[#24785]: https://github.com/JuliaLang/julia/issues/24785
[#25012]: https://github.com/JuliaLang/julia/issues/25012
[#25021]: https://github.com/JuliaLang/julia/issues/25021
[#25056]: https://github.com/JuliaLang/julia/issues/25056
[#25057]: https://github.com/JuliaLang/julia/issues/25057
[#25162]: https://github.com/JuliaLang/julia/issues/25162
90 changes: 90 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,35 @@ else
import Dates
end

if VERSION < v"0.7.0-DEV.3052"
const Printf = Base.Printf
else
import Printf
end

if VERSION < v"0.7.0-DEV.2655"
@eval module IterativeEigensolvers
using Base: eigs, svds
export eigs, svds
end
elseif VERSION < v"0.7.0-DEV.3019"
import IterativeEigenSolvers
const IterativeEigensolvers = IterativeEigenSolvers
else
import IterativeEigensolvers
end

if VERSION < v"0.7.0-DEV.2609"
@eval module SuiteSparse
if Base.USE_GPL_LIBS
using Base.SparseArrays: CHOLMOD, SPQR, UMFPACK
end
using Base.SparseArrays: increment, increment!, decrement, decrement!
end
else
import SuiteSparse
end

# 0.7.0-DEV.1993
@static if !isdefined(Base, :EqualTo)
if VERSION >= v"0.6.0"
Expand Down Expand Up @@ -953,6 +982,67 @@ module Unicode
end
end

# 0.7.0-DEV.2951
@static if !isdefined(Base, :AbstractDict)
const AbstractDict = Associative
export AbstractDict
end

# 0.7.0-DEV.2978
@static if !isdefined(Base, :axes)
const axes = Base.indices
export axes
end
Copy link
Member

Choose a reason for hiding this comment

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

This should have

else
    import Base.axes
end

such that you can overload Compat.axes on 0.6 too.

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind... I confused myself.


# 0.7.0-DEV.3137
@static if !isdefined(Base, :Nothing)
const Nothing = Void
const Cvoid = Void
export Nothing, Cvoid
end

@static if !isdefined(Base, :Some)
import Base: promote_rule, convert
if VERSION >= v"0.6.0"
include_string(@__MODULE__, """
struct Some{T}
value::T
end
promote_rule(::Type{Some{S}}, ::Type{Some{T}}) where {S,T} = Some{promote_type(S, T)}
promote_rule(::Type{Some{T}}, ::Type{Nothing}) where {T} = Union{Some{T}, Nothing}
convert(::Type{Some{T}}, x::Some) where {T} = Some{T}(convert(T, x.value))
convert(::Type{Union{Some{T}, Nothing}}, x::Some) where {T} = convert(Some{T}, x)
convert(::Type{Union{T, Nothing}}, x::Any) where {T} = convert(T, x)
""")
else
include_string(@__MODULE__, """
immutable Some{T}
value::T
end
promote_rule{S,T}(::Type{Some{S}}, ::Type{Some{T}}) = Some{promote_type(S, T)}
promote_rule{T}(::Type{Some{T}}, ::Type{Nothing}) = Union{Some{T}, Nothing}
convert{T}(::Type{Some{T}}, x::Some) = Some{T}(convert(T, x.value))
convert{T}(::Type{Union{Some{T}, Nothing}}, x::Some) = convert(Some{T}, x)
convert{T}(::Type{Union{T, Nothing}}, x::Any) = convert(T, x)
""")
end
convert(::Type{Nothing}, x::Any) = throw(MethodError(convert, (Nothing, x)))
convert(::Type{Nothing}, x::Nothing) = nothing
coalesce(x::Any) = x
coalesce(x::Some) = x.value
coalesce(x::Nothing) = nothing
#coalesce(x::Missing) = missing
coalesce(x::Any, y...) = x
coalesce(x::Some, y...) = x.value
coalesce(x::Nothing, y...) = coalesce(y...)
#coalesce(x::Union{Nothing, Missing}, y...) = coalesce(y...)
notnothing(x::Any) = x
notnothing(::Nothing) = throw(ArgumentError("nothing passed to notnothing"))
export Some, coalesce
else
import Base: notnothing
end

include("deprecated.jl")

end # module Compat
158 changes: 106 additions & 52 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,58 +213,60 @@ mktemp() do fname, f
end
end

types = [
Bool,
Float16,
Float32,
Float64,
Int128,
Int16,
Int32,
Int64,
Int8,
UInt16,
UInt32,
UInt64,
UInt8,
]
for T in types
# julia#18510, Nullable constructors
x = @compat Nullable(one(T), true)
@test isnull(x) === false
@test isa(x.value, T)
@test eltype(x) === T

x = @compat Nullable{T}(one(T), true)
y = @compat Nullable{Any}(one(T), true)
@test isnull(x) === false
@test isnull(y) === false
@test isa(x.value, T)
@test eltype(x) === T
@test eltype(y) === Any

x = @compat Nullable{T}(one(T), false)
y = @compat Nullable{Any}(one(T), false)
@test isnull(x) === true
@test isnull(y) === true
@test eltype(x) === T
@test eltype(y) === Any

x = @compat Nullable(one(T), false)
@test isnull(x) === true
@test eltype(x) === T

x = @compat Nullable{T}()
@test isnull(x) === true
@test eltype(x) === T

# julia#18484, generic isnull, unsafe_get
a = one(T)
x = @compat Nullable(a, true)
@test isequal(unsafe_get(x), a)

x = @compat Nullable{Array{T}}()
@test_throws UndefRefError unsafe_get(x)
if VERSION < v"0.7.0-DEV.3017"
types = [
Bool,
Float16,
Float32,
Float64,
Int128,
Int16,
Int32,
Int64,
Int8,
UInt16,
UInt32,
UInt64,
UInt8,
]
for T in types
# julia#18510, Nullable constructors
x = @compat Nullable(one(T), true)
@test isnull(x) === false
@test isa(x.value, T)
@test eltype(x) === T

x = @compat Nullable{T}(one(T), true)
y = @compat Nullable{Any}(one(T), true)
@test isnull(x) === false
@test isnull(y) === false
@test isa(x.value, T)
@test eltype(x) === T
@test eltype(y) === Any

x = @compat Nullable{T}(one(T), false)
y = @compat Nullable{Any}(one(T), false)
@test isnull(x) === true
@test isnull(y) === true
@test eltype(x) === T
@test eltype(y) === Any

x = @compat Nullable(one(T), false)
@test isnull(x) === true
@test eltype(x) === T

x = @compat Nullable{T}()
@test isnull(x) === true
@test eltype(x) === T

# julia#18484, generic isnull, unsafe_get
a = one(T)
x = @compat Nullable(a, true)
@test isequal(unsafe_get(x), a)

x = @compat Nullable{Array{T}}()
@test_throws UndefRefError unsafe_get(x)
end
end

@test xor(1,5) == 4
Expand Down Expand Up @@ -902,6 +904,34 @@ module Test24459
@test isdefined(@__MODULE__, :Dates)
end

# 0.7
module Test25056
using Compat
using Compat.Test
using Compat.Printf
@test isdefined(@__MODULE__, :Printf)
@test isdefined(@__MODULE__, Symbol("@printf"))
@test isdefined(@__MODULE__, Symbol("@sprintf"))
end

# 0.7
module Test24714
using Compat
using Compat.Test
using Compat.IterativeEigensolvers
@test isdefined(@__MODULE__, :IterativeEigensolvers)
@test isdefined(@__MODULE__, :eigs)
@test isdefined(@__MODULE__, :svds)
end

# 0.7
module Test24648
using Compat
using Compat.Test
using Compat.SuiteSparse
@test isdefined(@__MODULE__, :SuiteSparse)
end

let a = [0,1,2,3,0,1,2,3]
@test findfirst(equalto(3), [1,2,4,1,2,3,4]) == 6
@test findfirst(!equalto(1), [1,2,4,1,2,3,4]) == 2
Expand Down Expand Up @@ -997,6 +1027,30 @@ module Test25021
@test titlecase("firstname lastname") == "Firstname Lastname"
end

# 0.7.0-DEV.2951
@test AbstractDict === (isdefined(Base, :AbstractDict) ? Base.AbstractDict : Base.Associative)

# 0.7.0-DEV.2978
@test axes === (isdefined(Base, :axes) ? Base.axes : Base.indices)
@test axes(1) == ()
@test axes(1,1) == 1:1

# 0.7.0-DEV.3137
@test Nothing === (isdefined(Base, :Nothing) ? Base.Nothing : Base.Void)
@test Nothing === Cvoid

# 0.7.0-DEV.3017
@test isa(Some(1), Some{Int})
@test convert(Some{Float64}, Some(1)) == Some(1.0)
@test convert(Void, nothing) == nothing
@test_throws MethodError convert(Void, 1)
@test Some(nothing) != nothing
@test coalesce(Some(1)) == 1
@test coalesce(nothing) == nothing
@test coalesce(nothing, Some(1), Some(2)) == 1
@test Compat.notnothing(1) == 1
@test_throws ArgumentError Compat.notnothing(nothing)

if VERSION < v"0.6.0"
include("deprecated.jl")
end
Expand Down