Skip to content

Commit 003dc9d

Browse files
yuyichaoararslan
authored andcommitted
Drop 0.4 and 0.7 fixes
* Drop remaining 0.4 support code * Deprecate remaining 0.4 Compat bindings * Remove tests for 0.4 Compat * Do not run deprecated tests on 0.6 * Recover one test that's incorrectly moved to deprecated (StringVector) * Add compat for at-nospecialize with tests * Add compat for `read(..., String)` with tests
1 parent 93cc1fc commit 003dc9d

File tree

5 files changed

+185
-1536
lines changed

5 files changed

+185
-1536
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ Currently, the `@compat` macro supports the following syntaxes:
172172
`Sys.islinux`, `Sys.isunix`, and `Sys.iswindows`, respectively. These are available in the `Compat.Sys`
173173
submodule. ([#22182])
174174

175+
* `readstring` is replaced by methods of `read`. ([#22864])
176+
177+
`read(::IO, ::Type{String})`, `read(::AbstractString, ::Type{String})`,
178+
and `read(::Cmd, ::Type{String})` are defined for 0.6 and below.
179+
180+
175181
## New macros
176182

177183
* `@__DIR__` has been added ([#18380])
@@ -186,6 +192,8 @@ Currently, the `@compat` macro supports the following syntaxes:
186192
vectorized function have migrated. These macros will be dropped when the
187193
support for `0.6` is dropped from `Compat`.
188194

195+
* `@nospecialize` has been added ([#22666]).
196+
189197
## Other changes
190198

191199
* On versions of Julia that do not contain a Base.Threads module, Compat defines a Threads module containing a no-op `@threads` macro.
@@ -309,3 +317,5 @@ includes this fix. Find the minimum version from there.
309317
[#22475]: https://github.com/JuliaLang/julia/issues/22475
310318
[#22633]: https://github.com/JuliaLang/julia/issues/22633
311319
[#22629]: https://github.com/JuliaLang/julia/issues/22629
320+
[#22666]: https://github.com/JuliaLang/julia/pull/22666
321+
[#22864]: https://github.com/JuliaLang/julia/pull/22864

src/Compat.jl

Lines changed: 26 additions & 205 deletions
Original file line numberDiff line numberDiff line change
@@ -4,126 +4,31 @@ module Compat
44

55
using Base.Meta
66

7+
if !isdefined(Base, Symbol("@nospecialize"))
8+
# 0.7
9+
macro nospecialize(arg)
10+
earg = esc(arg)
11+
if isa(arg, Symbol)
12+
return :($earg::ANY)
13+
end
14+
return earg
15+
end
16+
export @nospecialize
17+
end
18+
719
"""Get just the function part of a function declaration."""
820
withincurly(ex) = isexpr(ex, :curly) ? ex.args[1] : ex
921

1022
if VERSION < v"0.6.0-dev.2043"
1123
Base.take!(t::Task) = consume(t)
1224
end
1325

14-
function rewrite_show(ex)
15-
if isexpr(ex, :call)
16-
Expr(:call, rewrite_show(ex.args[1]), ex.args[2:end]...)
17-
elseif isexpr(ex, :curly)
18-
Expr(:curly, rewrite_show(ex.args[1]), ex.args[2:end]...)
19-
else
20-
:(Base.writemime)
21-
end
22-
end
23-
24-
function rewrite_dict(ex)
25-
length(ex.args) == 1 && return ex
26-
27-
f = ex.args[1]
28-
if isexpr(f, :curly)
29-
newex = Expr(:typed_dict, :($(f.args[2])=>$(f.args[3])))
30-
else
31-
newex = Expr(:dict)
32-
end
33-
34-
for i = 2:length(ex.args)
35-
pair = ex.args[i]
36-
!isexpr(pair, :(=>)) && return ex
37-
push!(newex.args, pair)
38-
end
39-
newex
40-
end
41-
42-
function rewrite_ordereddict(ex)
43-
length(ex.args) == 1 && return ex
44-
45-
f = ex.args[1]
46-
newex = Expr(:call, f, :[])
47-
48-
for i = 2:length(ex.args)
49-
pair = ex.args[i]
50-
!isexpr(pair, :(=>)) && return ex
51-
push!(newex.args[2].args, Expr(:tuple, pair.args...))
52-
end
53-
54-
newex
55-
end
56-
57-
# rewrites all subexpressions of the form `a => b` to `(a, b)`
58-
function rewrite_pairs_to_tuples!(expr::Expr)
59-
if expr.head == :(=>)
60-
expr.head = :tuple
61-
end
62-
for subexpr in expr.args
63-
isa(subexpr, Expr) && rewrite_pairs_to_tuples!(subexpr)
64-
end
65-
return expr
66-
end
67-
68-
function is_quote_symbol(ex::ANY, val::Symbol)
69-
if isa(ex, QuoteNode)
70-
return (ex::QuoteNode).value === val
71-
elseif isa(ex, Expr)
72-
ex = ex::Expr
73-
return ex.head === :quote && length(ex.args) == 1 && ex.args[1] === val
74-
end
75-
return false
76-
end
77-
7826
is_index_style(ex::Expr) = ex == :(Compat.IndexStyle) || ex == :(Base.IndexStyle) ||
7927
(ex.head == :(.) && (ex.args[1] == :Compat || ex.args[1] == :Base) &&
8028
ex.args[2] == Expr(:quote, :IndexStyle))
8129

8230
is_index_style(arg) = false
8331

84-
# rewrites accesses to IOContext dicts
85-
function rewrite_iocontext!(expr::Expr)
86-
args = expr.args
87-
nargs = length(args)
88-
if nargs == 4 && expr.head === :call && args[1] === :get && args[4] === false
89-
key = args[3]
90-
if is_quote_symbol(key, :limit) || is_quote_symbol(key, :compact)
91-
if VERSION >= v"0.5.0-dev+1936" && VERSION < v"0.5.0-dev+4305"
92-
args[1] = :(Base.limit_output)
93-
deleteat!(args, 3:4)
94-
elseif VERSION < v"0.5.0-dev+1936"
95-
expr.head = :quote
96-
args[1] = false
97-
deleteat!(args, 3:4)
98-
end
99-
elseif is_quote_symbol(key, :multiline)
100-
if VERSION < v"0.5.0-dev+4305"
101-
expr.head = :quote
102-
args[1] = false
103-
deleteat!(args, 3:4)
104-
end
105-
end
106-
end
107-
end
108-
109-
# JuliaLang/julia#10543
110-
if !isdefined(Base, :tryparse)
111-
function tryparse{T}(::Type{T}, args...)
112-
try
113-
Nullable(Base.parse(T, args...))
114-
catch
115-
Nullable{T}()
116-
end
117-
end
118-
end
119-
120-
import Base.unsafe_convert
121-
122-
function new_style_call_overload(ex::Expr)
123-
Base.depwarn("new_style_call_overload is deprecated.", :new_style_call_overload)
124-
false
125-
end
126-
12732
istopsymbol(ex, mod, sym) = ex in (sym, Expr(:(.), mod, Expr(:quote, sym)))
12833

12934
if VERSION < v"0.6.0-dev.2782"
@@ -145,18 +50,13 @@ function _compat(ex::Expr)
14550
end
14651
elseif ex.head === :curly
14752
f = ex.args[1]
148-
if ex == :(Ptr{Void})
149-
# Do not change Ptr{Void} to Ptr{Nothing}: 0.4.0-dev+768
150-
return ex
151-
elseif VERSION < v"0.6.0-dev.2575" #20414
53+
if VERSION < v"0.6.0-dev.2575" #20414
15254
ex = Expr(:curly, map(a -> isexpr(a, :call, 2) && a.args[1] == :(<:) ?
15355
:($TypeVar($(QuoteNode(gensym(:T))), $(a.args[2]), false)) :
15456
isexpr(a, :call, 2) && a.args[1] == :(>:) ?
15557
:($TypeVar($(QuoteNode(gensym(:T))), $(a.args[2]), $Any, false)) : a,
15658
ex.args)...)
15759
end
158-
elseif ex.head === :macrocall
159-
f = ex.args[1]
16060
elseif ex.head === :quote && isa(ex.args[1], Symbol)
16161
# Passthrough
16262
return ex
@@ -240,98 +140,7 @@ macro compat(ex...)
240140
esc(_compat(ex[1]))
241141
end
242142

243-
export @compat, @inline, @noinline
244-
245-
import Base.@irrational
246-
247-
import Base: remotecall, remotecall_fetch, remotecall_wait, remote_do
248-
249-
import Base.Filesystem
250-
251-
if !isdefined(Base, :istextmime)
252-
export istextmime
253-
istextmime(m::@compat(Union{MIME,AbstractString})) = istext(m)
254-
end
255-
256-
function primarytype(t::ANY)
257-
tn = t.name
258-
if isdefined(tn, :primary)
259-
return tn.primary
260-
else
261-
return tn.wrapper
262-
end
263-
end
264-
265-
if !isdefined(Base, :Threads)
266-
@eval module Threads
267-
macro threads(expr)
268-
return esc(expr)
269-
end
270-
threadid() = 1
271-
nthreads() = 1
272-
export @threads, threadid, nthreads
273-
end
274-
export Threads
275-
end
276-
277-
if !isdefined(Base, :normalize)
278-
function normalize!(v::AbstractVector, p::Real=2)
279-
nrm = norm(v, p)
280-
__normalize!(v, nrm)
281-
end
282-
283-
@inline function __normalize!(v::AbstractVector, nrm::AbstractFloat)
284-
#The largest positive floating point number whose inverse is less than
285-
#infinity
286-
δ = inv(prevfloat(typemax(nrm)))
287-
if nrm δ #Safe to multiply with inverse
288-
invnrm = inv(nrm)
289-
scale!(v, invnrm)
290-
else # scale elements to avoid overflow
291-
εδ = eps(one(nrm))/δ
292-
scale!(v, εδ)
293-
scale!(v, inv(nrm*εδ))
294-
end
295-
v
296-
end
297-
298-
copy_oftype{T,N}(A::AbstractArray{T,N}, ::Type{T}) = copy(A)
299-
copy_oftype{T,N,S}(A::AbstractArray{T,N}, ::Type{S}) = convert(AbstractArray{S,N}, A)
300-
301-
function normalize(v::AbstractVector, p::Real = 2)
302-
nrm = norm(v, p)
303-
if !isempty(v)
304-
vv = copy_oftype(v, typeof(v[1]/nrm))
305-
return __normalize!(vv, nrm)
306-
else
307-
T = typeof(zero(eltype(v))/nrm)
308-
return T[]
309-
end
310-
end
311-
312-
export normalize, normalize!
313-
end
314-
315-
import Base.AsyncCondition
316-
import Base: srand, rand, rand!
317-
318-
319-
if !isdefined(Base, :pointer_to_string)
320-
321-
function pointer_to_string(p::Ptr{UInt8}, len::Integer, own::Bool=false)
322-
a = ccall(:jl_ptr_to_array_1d, Vector{UInt8},
323-
(Any, Ptr{UInt8}, Csize_t, Cint), Vector{UInt8}, p, len, own)
324-
ccall(:jl_array_to_string, Ref{String}, (Any,), a)
325-
end
326-
327-
pointer_to_string(p::Ptr{UInt8}, own::Bool=false) =
328-
pointer_to_string(p, ccall(:strlen, Csize_t, (Cstring,), p), own)
329-
330-
end
331-
332-
import Base.promote_eltype_op
333-
334-
import Base.LinAlg.BLAS.@blasfunc
143+
export @compat
335144

336145
import Base: redirect_stdin, redirect_stdout, redirect_stderr
337146
if VERSION < v"0.6.0-dev.374"
@@ -412,20 +221,23 @@ end
412221

413222
# julia#18977
414223
if !isdefined(Base, :xor)
224+
# 0.6
415225
const xor = $
416226
const = xor
417227
export xor,
418228
end
419229

420230
# julia#19246
421231
if !isdefined(Base, :numerator)
232+
# 0.6
422233
const numerator = num
423234
const denominator = den
424235
export numerator, denominator
425236
end
426237

427238
# julia #19950
428239
if !isdefined(Base, :iszero)
240+
# 0.6
429241
iszero(x) = x == zero(x)
430242
iszero(x::Number) = x == 0
431243
iszero(x::AbstractArray) = all(iszero, x)
@@ -434,6 +246,7 @@ end
434246

435247
# julia #20407
436248
if !isdefined(Base, :(>:))
249+
# 0.6
437250
const >: = let
438251
_issupertype(a::ANY, b::ANY) = issubtype(b, a)
439252
end
@@ -568,6 +381,7 @@ end
568381

569382
# https://github.com/JuliaLang/julia/pull/22064
570383
if !isdefined(Base, Symbol("@__MODULE__"))
384+
# 0.7
571385
export @__MODULE__
572386
macro __MODULE__()
573387
return current_module()
@@ -582,6 +396,7 @@ end
582396

583397
# https://github.com/JuliaLang/julia/pull/19784
584398
if isdefined(Base, :invokelatest)
399+
# 0.6
585400
import Base.invokelatest
586401
else
587402
invokelatest(f, args...) = eval(current_module(), Expr(:call, f, map(QuoteNode, args)...))
@@ -667,6 +482,12 @@ if VERSION < v"0.7.0-DEV.892"
667482
export fieldcount
668483
end
669484

485+
if VERSION < v"0.7.0-DEV.1053"
486+
Base.read(obj::IO, ::Type{String}) = readstring(obj)
487+
Base.read(obj::AbstractString, ::Type{String}) = readstring(obj)
488+
Base.read(obj::Cmd, ::Type{String}) = readstring(obj)
489+
end
490+
670491
include("deprecated.jl")
671492

672493
end # module Compat

src/deprecated.jl

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ end
143143
using .CompatCartesian
144144
export @ngenerate, @nsplat
145145

146+
function primarytype(@nospecialize(t))
147+
tn = t.name
148+
if isdefined(tn, :primary)
149+
return tn.primary
150+
else
151+
return tn.wrapper
152+
end
153+
end
154+
146155
export @functorize
147156
macro functorize(f)
148157
code = f === :scalarmax ? :(Base.scalarmax) :
@@ -160,13 +169,22 @@ if VERSION >= v"0.6.0"
160169
Base.@deprecate_binding KERNEL Sys.KERNEL
161170
Base.@deprecate_binding UTF8String Core.String
162171
Base.@deprecate_binding ASCIIString Core.String
172+
Base.@deprecate_binding unsafe_convert Base.unsafe_convert
173+
Base.@deprecate_binding remote_do Base.remote_do
174+
Base.@deprecate_binding Filesystem Base.Filesystem
175+
Base.@deprecate_binding AsyncCondition Base.AsyncCondition
176+
Base.@deprecate_binding promote_eltype_op Base.promote_eltype_op
177+
@eval Base.@deprecate_binding $(Symbol("@irrational")) Base.$(Symbol("@irrational"))
178+
@eval Base.@deprecate_binding $(Symbol("@blasfunc")) Base.LinAlg.BLAS.$(Symbol("@blasfunc"))
163179
else
164180
const KERNEL = Sys.KERNEL
165181
const UTF8String = Core.String
166182
const ASCIIString = Core.String
183+
import Base.unsafe_convert
184+
import Base.remote_do
185+
import Base.Filesystem
186+
import Base.AsyncCondition
187+
import Base.promote_eltype_op
188+
import Base.@irrational
189+
import Base.LinAlg.BLAS.@blasfunc
167190
end
168-
169-
# More things that could be removed in Compat.jl
170-
# - new_style_call_overload
171-
# - import Base.Filesystem
172-
# - import Base.LinAlg.BLAS.@blasfunc

0 commit comments

Comments
 (0)