Skip to content

Commit

Permalink
Drop compat code for at-nospecialize (from #385 and #409)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Sep 29, 2019
1 parent 2543a7f commit 306bf6e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 45 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,6 @@ Currently, the `@compat` macro supports the following syntaxes:

## New macros

* `@nospecialize` has been added ([#22666]).

* The logging macros `@error`, `@warn`, `@info` and `@debug` can be used as
`Compat.@error`, `Compat.@warn`, `Compat.@info` and `Compat.@debug` on Julia 0.6 ([#24490]).
Note that the behavior do not mirror the logging macros in Julia 0.7, instead on Julia 0.6:
Expand Down
26 changes: 0 additions & 26 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,6 @@ import Sockets

include("compatmacro.jl")

@static if !isdefined(Base, Symbol("@nospecialize"))
# 0.7
macro nospecialize(arg)
if isa(arg, Symbol)
# @nospecialize(arg)
return :($(esc(arg))::ANY)
elseif isa(arg, Expr) && arg.head == :(::)
# @nospecialize(arg::typ)
# unsupported: needs ::ANY which would change dispatch as determined by ::typ
elseif isa(arg, Expr) && arg.head == :(=)
# @nospecialize(arg=val)
arg, val = arg.args
if isa(arg, Expr) && arg.head == :(::)
# @nospecialize(arg::typ=val)
# unsupported (see above), but generate a kw arg
arg, typ = arg.args
return Expr(:kw, :($(esc(arg))::$(esc(typ))), esc(val))
else
return Expr(:kw, :($(esc(arg))::ANY), esc(val))
end
end
return esc(arg)
end
export @nospecialize
end

# https://github.com/JuliaLang/julia/pull/22064
@static if !isdefined(Base, Symbol("@__MODULE__"))
# 0.7
Expand Down
17 changes: 17 additions & 0 deletions test/old.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,20 @@ end
@test stdout === STDOUT
@test stderr === STDERR
end

# @nospecialize
# 0.7
no_specialize(@nospecialize(x)) = sin(1)
no_specialize(@nospecialize(x::Integer)) = sin(2)
@test no_specialize(1.0) == sin(1)
@test no_specialize(1) == sin(2)
no_specialize_kw1(@nospecialize(x=0)) = sin(1)
no_specialize_kw1(@nospecialize(x::Integer)) = sin(2)
@test no_specialize_kw1(1.0) == sin(1)
@test no_specialize_kw1(1) == sin(2)
@test no_specialize_kw1() == sin(2)
no_specialize_kw2(@nospecialize(x)) = sin(1)
no_specialize_kw2(@nospecialize(x::Integer=0)) = sin(2)
@test no_specialize_kw2(1.0) == sin(1)
@test no_specialize_kw2(1) == sin(2)
@test no_specialize_kw2() == sin(2)
17 changes: 0 additions & 17 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -265,23 +265,6 @@ end
@test @inferred(ntuple(x->x, Val(0))) == ()
@test @inferred(ntuple(x->x, Val(5))) == (1,2,3,4,5)

# @nospecialize
# 0.7
no_specialize(@nospecialize(x)) = sin(1)
no_specialize(@nospecialize(x::Integer)) = sin(2)
@test no_specialize(1.0) == sin(1)
@test no_specialize(1) == sin(2)
no_specialize_kw1(@nospecialize(x=0)) = sin(1)
no_specialize_kw1(@nospecialize(x::Integer)) = sin(2)
@test no_specialize_kw1(1.0) == sin(1)
@test no_specialize_kw1(1) == sin(2)
@test no_specialize_kw1() == sin(2)
no_specialize_kw2(@nospecialize(x)) = sin(1)
no_specialize_kw2(@nospecialize(x::Integer=0)) = sin(2)
@test no_specialize_kw2(1.0) == sin(1)
@test no_specialize_kw2(1) == sin(2)
@test no_specialize_kw2() == sin(2)

# 0.7
@test read(IOBuffer("aaaa"), String) == "aaaa"
@test occursin("read(@__FILE__, String)", read(@__FILE__, String))
Expand Down

0 comments on commit 306bf6e

Please sign in to comment.