Skip to content

Commit 7a64c3f

Browse files
authored
Merge pull request #435 from JuliaLang/aa/0.7
A bunch of stuff for 0.7
2 parents 7695d5c + 9ffecc0 commit 7a64c3f

File tree

3 files changed

+220
-52
lines changed

3 files changed

+220
-52
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ Currently, the `@compat` macro supports the following syntaxes:
9898
* `using Compat.Unicode` is provided on versions older than 0.7, where this library is not
9999
yet a part of the standard library. ([#25021])
100100

101+
* `using Compat.Printf` is provided on versions older than 0.7, where this library is not
102+
yet a part of the standard library. ([#25056])
103+
104+
* `using Compat.IterativeEigensolvers` is provided on versions older than 0.7, where this
105+
library is not yet a part of the standard library. ([#24714])
106+
107+
* `using Compat.SuiteSparse` is provided on versions older than 0.7, where this library is
108+
not yet part of the standard library ([#24648]).
109+
101110
## New functions, macros, and methods
102111

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

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

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

213224

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

258+
* `Associative` is now `AbstractDict` ([#25012]).
259+
260+
* `indices` is now `axes` ([#25057]).
261+
262+
* `Void` is now `Nothing` with an alias `Cvoid` for C interop ([#25162]).
263+
247264
## New macros
248265

249266
* `@__DIR__` has been added ([#18380])
@@ -378,6 +395,7 @@ includes this fix. Find the minimum version from there.
378395
[#23412]: https://github.com/JuliaLang/julia/issues/23412
379396
[#23427]: https://github.com/JuliaLang/julia/issues/23427
380397
[#23570]: https://github.com/JuliaLang/julia/issues/23570
398+
[#23642]: https://github.com/JuliaLang/julia/issues/23642
381399
[#23666]: https://github.com/JuliaLang/julia/issues/23666
382400
[#23757]: https://github.com/JuliaLang/julia/issues/23757
383401
[#23812]: https://github.com/JuliaLang/julia/issues/23812
@@ -389,7 +407,13 @@ includes this fix. Find the minimum version from there.
389407
[#24459]: https://github.com/JuliaLang/julia/issues/24459
390408
[#24605]: https://github.com/JuliaLang/julia/issues/24605
391409
[#24647]: https://github.com/JuliaLang/julia/issues/24647
410+
[#24648]: https://github.com/JuliaLang/julia/issues/24648
392411
[#24652]: https://github.com/JuliaLang/julia/issues/24652
393412
[#24657]: https://github.com/JuliaLang/julia/issues/24657
413+
[#24714]: https://github.com/JuliaLang/julia/issues/24714
394414
[#24785]: https://github.com/JuliaLang/julia/issues/24785
415+
[#25012]: https://github.com/JuliaLang/julia/issues/25012
395416
[#25021]: https://github.com/JuliaLang/julia/issues/25021
417+
[#25056]: https://github.com/JuliaLang/julia/issues/25056
418+
[#25057]: https://github.com/JuliaLang/julia/issues/25057
419+
[#25162]: https://github.com/JuliaLang/julia/issues/25162

src/Compat.jl

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,35 @@ else
763763
import Dates
764764
end
765765

766+
if VERSION < v"0.7.0-DEV.3052"
767+
const Printf = Base.Printf
768+
else
769+
import Printf
770+
end
771+
772+
if VERSION < v"0.7.0-DEV.2655"
773+
@eval module IterativeEigensolvers
774+
using Base: eigs, svds
775+
export eigs, svds
776+
end
777+
elseif VERSION < v"0.7.0-DEV.3019"
778+
import IterativeEigenSolvers
779+
const IterativeEigensolvers = IterativeEigenSolvers
780+
else
781+
import IterativeEigensolvers
782+
end
783+
784+
if VERSION < v"0.7.0-DEV.2609"
785+
@eval module SuiteSparse
786+
if Base.USE_GPL_LIBS
787+
using Base.SparseArrays: CHOLMOD, SPQR, UMFPACK
788+
end
789+
using Base.SparseArrays: increment, increment!, decrement, decrement!
790+
end
791+
else
792+
import SuiteSparse
793+
end
794+
766795
# 0.7.0-DEV.1993
767796
@static if !isdefined(Base, :EqualTo)
768797
if VERSION >= v"0.6.0"
@@ -953,6 +982,67 @@ module Unicode
953982
end
954983
end
955984

985+
# 0.7.0-DEV.2951
986+
@static if !isdefined(Base, :AbstractDict)
987+
const AbstractDict = Associative
988+
export AbstractDict
989+
end
990+
991+
# 0.7.0-DEV.2978
992+
@static if !isdefined(Base, :axes)
993+
const axes = Base.indices
994+
export axes
995+
end
996+
997+
# 0.7.0-DEV.3137
998+
@static if !isdefined(Base, :Nothing)
999+
const Nothing = Void
1000+
const Cvoid = Void
1001+
export Nothing, Cvoid
1002+
end
1003+
1004+
@static if !isdefined(Base, :Some)
1005+
import Base: promote_rule, convert
1006+
if VERSION >= v"0.6.0"
1007+
include_string(@__MODULE__, """
1008+
struct Some{T}
1009+
value::T
1010+
end
1011+
promote_rule(::Type{Some{S}}, ::Type{Some{T}}) where {S,T} = Some{promote_type(S, T)}
1012+
promote_rule(::Type{Some{T}}, ::Type{Nothing}) where {T} = Union{Some{T}, Nothing}
1013+
convert(::Type{Some{T}}, x::Some) where {T} = Some{T}(convert(T, x.value))
1014+
convert(::Type{Union{Some{T}, Nothing}}, x::Some) where {T} = convert(Some{T}, x)
1015+
convert(::Type{Union{T, Nothing}}, x::Any) where {T} = convert(T, x)
1016+
""")
1017+
else
1018+
include_string(@__MODULE__, """
1019+
immutable Some{T}
1020+
value::T
1021+
end
1022+
promote_rule{S,T}(::Type{Some{S}}, ::Type{Some{T}}) = Some{promote_type(S, T)}
1023+
promote_rule{T}(::Type{Some{T}}, ::Type{Nothing}) = Union{Some{T}, Nothing}
1024+
convert{T}(::Type{Some{T}}, x::Some) = Some{T}(convert(T, x.value))
1025+
convert{T}(::Type{Union{Some{T}, Nothing}}, x::Some) = convert(Some{T}, x)
1026+
convert{T}(::Type{Union{T, Nothing}}, x::Any) = convert(T, x)
1027+
""")
1028+
end
1029+
convert(::Type{Nothing}, x::Any) = throw(MethodError(convert, (Nothing, x)))
1030+
convert(::Type{Nothing}, x::Nothing) = nothing
1031+
coalesce(x::Any) = x
1032+
coalesce(x::Some) = x.value
1033+
coalesce(x::Nothing) = nothing
1034+
#coalesce(x::Missing) = missing
1035+
coalesce(x::Any, y...) = x
1036+
coalesce(x::Some, y...) = x.value
1037+
coalesce(x::Nothing, y...) = coalesce(y...)
1038+
#coalesce(x::Union{Nothing, Missing}, y...) = coalesce(y...)
1039+
notnothing(x::Any) = x
1040+
notnothing(::Nothing) = throw(ArgumentError("nothing passed to notnothing"))
1041+
export Some, coalesce
1042+
else
1043+
import Base: notnothing
1044+
end
1045+
9561046
include("deprecated.jl")
9571047

9581048
end # module Compat

test/runtests.jl

Lines changed: 106 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -213,58 +213,60 @@ mktemp() do fname, f
213213
end
214214
end
215215

216-
types = [
217-
Bool,
218-
Float16,
219-
Float32,
220-
Float64,
221-
Int128,
222-
Int16,
223-
Int32,
224-
Int64,
225-
Int8,
226-
UInt16,
227-
UInt32,
228-
UInt64,
229-
UInt8,
230-
]
231-
for T in types
232-
# julia#18510, Nullable constructors
233-
x = @compat Nullable(one(T), true)
234-
@test isnull(x) === false
235-
@test isa(x.value, T)
236-
@test eltype(x) === T
237-
238-
x = @compat Nullable{T}(one(T), true)
239-
y = @compat Nullable{Any}(one(T), true)
240-
@test isnull(x) === false
241-
@test isnull(y) === false
242-
@test isa(x.value, T)
243-
@test eltype(x) === T
244-
@test eltype(y) === Any
245-
246-
x = @compat Nullable{T}(one(T), false)
247-
y = @compat Nullable{Any}(one(T), false)
248-
@test isnull(x) === true
249-
@test isnull(y) === true
250-
@test eltype(x) === T
251-
@test eltype(y) === Any
252-
253-
x = @compat Nullable(one(T), false)
254-
@test isnull(x) === true
255-
@test eltype(x) === T
256-
257-
x = @compat Nullable{T}()
258-
@test isnull(x) === true
259-
@test eltype(x) === T
260-
261-
# julia#18484, generic isnull, unsafe_get
262-
a = one(T)
263-
x = @compat Nullable(a, true)
264-
@test isequal(unsafe_get(x), a)
265-
266-
x = @compat Nullable{Array{T}}()
267-
@test_throws UndefRefError unsafe_get(x)
216+
if VERSION < v"0.7.0-DEV.3017"
217+
types = [
218+
Bool,
219+
Float16,
220+
Float32,
221+
Float64,
222+
Int128,
223+
Int16,
224+
Int32,
225+
Int64,
226+
Int8,
227+
UInt16,
228+
UInt32,
229+
UInt64,
230+
UInt8,
231+
]
232+
for T in types
233+
# julia#18510, Nullable constructors
234+
x = @compat Nullable(one(T), true)
235+
@test isnull(x) === false
236+
@test isa(x.value, T)
237+
@test eltype(x) === T
238+
239+
x = @compat Nullable{T}(one(T), true)
240+
y = @compat Nullable{Any}(one(T), true)
241+
@test isnull(x) === false
242+
@test isnull(y) === false
243+
@test isa(x.value, T)
244+
@test eltype(x) === T
245+
@test eltype(y) === Any
246+
247+
x = @compat Nullable{T}(one(T), false)
248+
y = @compat Nullable{Any}(one(T), false)
249+
@test isnull(x) === true
250+
@test isnull(y) === true
251+
@test eltype(x) === T
252+
@test eltype(y) === Any
253+
254+
x = @compat Nullable(one(T), false)
255+
@test isnull(x) === true
256+
@test eltype(x) === T
257+
258+
x = @compat Nullable{T}()
259+
@test isnull(x) === true
260+
@test eltype(x) === T
261+
262+
# julia#18484, generic isnull, unsafe_get
263+
a = one(T)
264+
x = @compat Nullable(a, true)
265+
@test isequal(unsafe_get(x), a)
266+
267+
x = @compat Nullable{Array{T}}()
268+
@test_throws UndefRefError unsafe_get(x)
269+
end
268270
end
269271

270272
@test xor(1,5) == 4
@@ -902,6 +904,34 @@ module Test24459
902904
@test isdefined(@__MODULE__, :Dates)
903905
end
904906

907+
# 0.7
908+
module Test25056
909+
using Compat
910+
using Compat.Test
911+
using Compat.Printf
912+
@test isdefined(@__MODULE__, :Printf)
913+
@test isdefined(@__MODULE__, Symbol("@printf"))
914+
@test isdefined(@__MODULE__, Symbol("@sprintf"))
915+
end
916+
917+
# 0.7
918+
module Test24714
919+
using Compat
920+
using Compat.Test
921+
using Compat.IterativeEigensolvers
922+
@test isdefined(@__MODULE__, :IterativeEigensolvers)
923+
@test isdefined(@__MODULE__, :eigs)
924+
@test isdefined(@__MODULE__, :svds)
925+
end
926+
927+
# 0.7
928+
module Test24648
929+
using Compat
930+
using Compat.Test
931+
using Compat.SuiteSparse
932+
@test isdefined(@__MODULE__, :SuiteSparse)
933+
end
934+
905935
let a = [0,1,2,3,0,1,2,3]
906936
@test findfirst(equalto(3), [1,2,4,1,2,3,4]) == 6
907937
@test findfirst(!equalto(1), [1,2,4,1,2,3,4]) == 2
@@ -997,6 +1027,30 @@ module Test25021
9971027
@test titlecase("firstname lastname") == "Firstname Lastname"
9981028
end
9991029

1030+
# 0.7.0-DEV.2951
1031+
@test AbstractDict === (isdefined(Base, :AbstractDict) ? Base.AbstractDict : Base.Associative)
1032+
1033+
# 0.7.0-DEV.2978
1034+
@test axes === (isdefined(Base, :axes) ? Base.axes : Base.indices)
1035+
@test axes(1) == ()
1036+
@test axes(1,1) == 1:1
1037+
1038+
# 0.7.0-DEV.3137
1039+
@test Nothing === (isdefined(Base, :Nothing) ? Base.Nothing : Base.Void)
1040+
@test Nothing === Cvoid
1041+
1042+
# 0.7.0-DEV.3017
1043+
@test isa(Some(1), Some{Int})
1044+
@test convert(Some{Float64}, Some(1)) == Some(1.0)
1045+
@test convert(Void, nothing) == nothing
1046+
@test_throws MethodError convert(Void, 1)
1047+
@test Some(nothing) != nothing
1048+
@test coalesce(Some(1)) == 1
1049+
@test coalesce(nothing) == nothing
1050+
@test coalesce(nothing, Some(1), Some(2)) == 1
1051+
@test Compat.notnothing(1) == 1
1052+
@test_throws ArgumentError Compat.notnothing(nothing)
1053+
10001054
if VERSION < v"0.6.0"
10011055
include("deprecated.jl")
10021056
end

0 commit comments

Comments
 (0)