Skip to content

Commit

Permalink
Remove at-compat for type declarations
Browse files Browse the repository at this point in the history
Was added in #325, now obsolete as no longer required on minimum 
supported Julia version 0.6.
  • Loading branch information
martinholters committed Aug 27, 2018
1 parent 89fc03f commit aa33054
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 61 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ Currently, the `@compat` macro supports the following syntaxes:
correct order of evaluation. Also, `x .+= y` converts to `x .= (x .+ y)`, and similarly for the other updating
assignment operators (`.*=` and so on).

* `@compat abstract type T end` and `@compat primitive type T 8 end`
to declare abstract and primitive types. [#20418]
This only works when `@compat` is applied directly on the declaration.

* `Compat.collect(A)` returns an `Array`, no matter what indices the array `A` has. [#21257]

* `@compat foo(::CartesianRange{N})` to replace the former
Expand Down Expand Up @@ -537,7 +533,6 @@ includes this fix. Find the minimum version from there.
[#20164]: https://github.com/JuliaLang/julia/issues/20164
[#20321]: https://github.com/JuliaLang/julia/issues/20321
[#20407]: https://github.com/JuliaLang/julia/issues/20407
[#20418]: https://github.com/JuliaLang/julia/issues/20418
[#20974]: https://github.com/JuliaLang/julia/issues/20974
[#21197]: https://github.com/JuliaLang/julia/issues/21197
[#21257]: https://github.com/JuliaLang/julia/issues/21257
Expand Down
49 changes: 2 additions & 47 deletions src/compatmacro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,51 +52,6 @@ end

_compat(ex) = ex

function _get_typebody(ex::Expr)
args = ex.args
if ex.head !== :type || length(args) != 3 || args[1] !== true
throw(ArgumentError("Invalid usage of @compat: $ex"))
end
name = args[2]
if !isexpr(args[3], :block)
throw(ArgumentError("Invalid type declaration: $ex"))
end
body = (args[3]::Expr).args
filter!(body) do e
if isa(e, LineNumberNode) || isexpr(e, :line)
return false
end
return true
end
return name, body
end

function _compat_primitive(typedecl)
name, body = _get_typebody(typedecl)
if length(body) != 1
throw(ArgumentError("Invalid primitive type declaration: $typedecl"))
end
return Expr(:bitstype, body[1], name)
end

function _compat_abstract(typedecl)
name, body = _get_typebody(typedecl)
if length(body) != 0
throw(ArgumentError("Invalid abstract type declaration: $typedecl"))
end
return Expr(:abstract, name)
end

macro compat(ex...)
if VERSION < v"0.6.0-dev.2746" && length(ex) == 2 && ex[1] === :primitive
return esc(_compat_primitive(ex[2]))
elseif length(ex) != 1
throw(ArgumentError("@compat called with wrong number of arguments: $ex"))
elseif (VERSION < v"0.6.0-dev.2746" && isexpr(ex[1], :abstract) &&
length(ex[1].args) == 1 && isexpr(ex[1].args[1], :type))
# This can in principle be handled in nested case but we do not
# do that to be consistent with primitive types.
return esc(_compat_abstract(ex[1].args[1]))
end
esc(_compat(ex[1]))
macro compat(ex)
esc(_compat(ex))
end
10 changes: 1 addition & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ for x in (3.1, -17, 3//4, big(111.1), Inf)
end

# julia#20006
@compat abstract type AbstractFoo20006 end
abstract type AbstractFoo20006 end
eval(Expr(
struct_sym, false,
Expr(:(<:), :(ConcreteFoo20006{T<:Int}), :AbstractFoo20006),
Expand Down Expand Up @@ -426,14 +426,6 @@ let x = [1,2,3]
@test f(x) == [1,4,9]
end

# PR #20418
@compat abstract type Abstract20418{T} <: Ref{T} end
@test Compat.TypeUtils.isabstract(Abstract20418)
@compat primitive type Primitive20418{T} <: Ref{T} 16 end
@test !Compat.TypeUtils.isabstract(Primitive20418)
@test isbitstype(Primitive20418{Int})
@test sizeof(Primitive20418{Int}) == 2

if VERSION < v"0.6.0-dev.1653"
for (A,val) in ((zeros(1:5, Float32, 3, 2), 0),
(ones(1:5, Float32, 3, 2), 1),
Expand Down

0 comments on commit aa33054

Please sign in to comment.