Skip to content

Commit

Permalink
fix some 1.5 compatibility issues (#35965)
Browse files Browse the repository at this point in the history
- restore some `copyto!` methods that Knet assumed existed
- allow `findfirst` to work on InfiniteArrays again
- allow constructing a LineNumberNode from a String
  • Loading branch information
JeffBezanson authored May 21, 2020
1 parent 8c64789 commit 853fe04
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,15 @@ Copy `N` elements from collection `src` starting at offset `so`, to array `dest`
offset `do`. Return `dest`.
"""
function copyto!(dest::Array, doffs::Integer, src::Array, soffs::Integer, n::Integer)
return _copyto_impl!(dest, doffs, src, soffs, n)
end

# this is only needed to avoid possible ambiguities with methods added in some packages
function copyto!(dest::Array{T}, doffs::Integer, src::Array{T}, soffs::Integer, n::Integer) where T
return _copyto_impl!(dest, doffs, src, soffs, n)
end

function _copyto_impl!(dest::Array, doffs::Integer, src::Array, soffs::Integer, n::Integer)
n == 0 && return dest
n > 0 || _throw_argerror()
if soffs < 1 || doffs < 1 || soffs+n-1 > length(src) || doffs+n-1 > length(dest)
Expand All @@ -339,6 +348,9 @@ end

copyto!(dest::Array, src::Array) = copyto!(dest, 1, src, 1, length(src))

# also to avoid ambiguities in packages
copyto!(dest::Array{T}, src::Array{T}) where {T} = copyto!(dest, 1, src, 1, length(src))

# N.B: The generic definition in multidimensional.jl covers, this, this is just here
# for bootstrapping purposes.
function fill!(dest::Array{T}, x) where T
Expand Down Expand Up @@ -1762,8 +1774,8 @@ CartesianIndex(1, 1)
```
"""
function findnext(testf::Function, A, start)
i = oftype(first(keys(A)), start)
l = last(keys(A))
i = oftype(l, start)
i > l && return nothing
while true
testf(A[i]) && return i
Expand Down
1 change: 1 addition & 0 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ _new(:QuoteNode, :Any)
_new(:SSAValue, :Int)
eval(Core, :(LineNumberNode(l::Int) = $(Expr(:new, :LineNumberNode, :l, nothing))))
eval(Core, :(LineNumberNode(l::Int, @nospecialize(f)) = $(Expr(:new, :LineNumberNode, :l, :f))))
LineNumberNode(l::Int, f::String) = LineNumberNode(l, Symbol(f))
eval(Core, :(GlobalRef(m::Module, s::Symbol) = $(Expr(:new, :GlobalRef, :m, :s))))
eval(Core, :(SlotNumber(n::Int) = $(Expr(:new, :SlotNumber, :n))))
eval(Core, :(TypedSlot(n::Int, @nospecialize(t)) = $(Expr(:new, :TypedSlot, :n, :t))))
Expand Down

0 comments on commit 853fe04

Please sign in to comment.