From aa33054519ef0e3c1b84f1db647292bb1adbcf6b Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Mon, 27 Aug 2018 12:06:31 +0200 Subject: [PATCH] Remove at-compat for type declarations Was added in #325, now obsolete as no longer required on minimum supported Julia version 0.6. --- README.md | 5 ----- src/compatmacro.jl | 49 ++-------------------------------------------- test/runtests.jl | 10 +--------- 3 files changed, 3 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 60ed52581..2762447d9 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/src/compatmacro.jl b/src/compatmacro.jl index 69c149040..31786e3d9 100644 --- a/src/compatmacro.jl +++ b/src/compatmacro.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index c6cc296c9..1bd72db7d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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), @@ -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),