Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add invokelatest from Julia 0.6 #352

Merged
merged 2 commits into from
Apr 28, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ Currently, the `@compat` macro supports the following syntaxes:

* `bswap` is supported for `Complex` arguments on 0.5 and below. ([#21346])

* `Compat.invokelatest` is equivalent to `Base.invokelatest` in Julia 0.6,
but works Julia 0.4+, and allows you to guarantee that a function call
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"works on Julia 0.4+" (or "in"?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, fixed.

invokes the latest version of a function ([#19784]).

* `Compat.StringVector` is supported on 0.5 and below. On 0.6 and later, it aliases `Base.StringVector`. This function allocates a `Vector{UInt8}` whose data can be made into a `String` in constant time; that is, without copying. On 0.5 and later, use `String(...)` with the vector allocated by `StringVector` as an argument to create a string without copying. Note that if 0.4 support is needed, `Compat.UTF8String(...)` should be used instead. ([#19449])

## Renamed functions
Expand Down Expand Up @@ -343,16 +347,19 @@ includes this fix. Find the minimum version from there.
[#17323]: https://github.com/JuliaLang/julia/issues/17323
[#17510]: https://github.com/JuliaLang/julia/issues/17510
[#17623]: https://github.com/JuliaLang/julia/issues/17623
[#18086]: https://github.com/JuliaLang/julia/issues/18086
[#18082]: https://github.com/JuliaLang/julia/issues/18082
[#18380]: https://github.com/JuliaLang/julia/issues/18380
[#18484]: https://github.com/JuliaLang/julia/issues/18484
[#18510]: https://github.com/JuliaLang/julia/issues/18510
[#18629]: https://github.com/JuliaLang/julia/issues/18629
[#18727]: https://github.com/JuliaLang/julia/issues/18727
[#18839]: https://github.com/JuliaLang/julia/issues/18839
[#18977]: https://github.com/JuliaLang/julia/issues/18977
[#19088]: https://github.com/JuliaLang/julia/issues/19088
[#19246]: https://github.com/JuliaLang/julia/issues/19246
[#19449]: https://github.com/JuliaLang/julia/issues/19449
[#19635]: https://github.com/JuliaLang/julia/issues/19635
[#19784]: https://github.com/JuliaLang/julia/issues/19784
[#19841]: https://github.com/JuliaLang/julia/issues/19841
[#19950]: https://github.com/JuliaLang/julia/issues/19950
[#20022]: https://github.com/JuliaLang/julia/issues/20022
Expand All @@ -363,6 +370,5 @@ includes this fix. Find the minimum version from there.
[#20414]: https://github.com/JuliaLang/julia/issues/20414
[#20418]: https://github.com/JuliaLang/julia/issues/20418
[#20500]: https://github.com/JuliaLang/julia/issues/20500
[#18629]: https://github.com/JuliaLang/julia/pull/18629
[#21346]: https://github.com/JuliaLang/julia/pull/21346
[#21257]: https://github.com/JuliaLang/julia/pull/21257
[#21257]: https://github.com/JuliaLang/julia/issues/21257
[#21346]: https://github.com/JuliaLang/julia/issues/21346
7 changes: 7 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,13 @@ else
using Base: StringVector
end

# https://github.com/JuliaLang/julia/pull/19784
if isdefined(Base, :invokelatest)
import Base.invokelatest
else
invokelatest(f, args...) = eval(Expr(:call, f, map(QuoteNode, args)...))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this surely is the correct definition for invokelatest, prior to JuliaLang/julia#17057 just f(args...) would often also work and be more performant. I'd surely have use for a function that does just f(args...) in older Julia and invokelatest (or eval(...)) in newer Julia. Should we include this in Compat?

Copy link
Member Author

@stevengj stevengj Apr 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martinholters, that's not true. Prior to that PR, you might get some random obsolete version of a function. See, for example JuliaLang/julia#7884 ... we had to add something like this in IJulia long before 17057.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know. But I use eval to create anonymous functions for which there cannot be obsolete versions. But that might be a very specific use case of mine.

Copy link
Member Author

@stevengj stevengj Apr 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point is, this seems to be about the simplest correct definition of invokelatest on earlier Julia versions. Your suggestion above would not work in general, hence it is not appropriate for Compat.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the misunderstanding: I didn't want to propose replacing what you have done, merely suggest to consider the simplified definition in addition. But admittedly, it doesn't really fit into Compat and I have no API proposal, so let's forget about it.

end

# https://github.com/JuliaLang/julia/pull/21257
if v"0.5.0-rc1+46" <= VERSION < v"0.6.0-pre.beta.28"
collect(A) = collect_indices(indices(A), A)
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1840,6 +1840,15 @@ if VERSION >= v"0.5.0-rc1+46"
@test b == [1,2,3]
end

# invokelatest
issue19774(x) = 1
let foo() = begin
eval(:(issue19774(x::Int) = 2))
return Compat.invokelatest(issue19774, 0)
end
@test foo() == 2
end

include("to-be-deprecated.jl")

nothing