Skip to content

Commit

Permalink
Fix some ChainRulesCore invalidations (#530)
Browse files Browse the repository at this point in the history
Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>
  • Loading branch information
timholy and aviatesk authored Mar 17, 2022
1 parent 79e3d2b commit a8e450c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/commands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function maybe_step_through_wrapper!(@nospecialize(recurse), frame::Frame)
end
end

has_selfarg = isexpr(last, :call) && any(isequal(SlotNumber(1)), last.args)
has_selfarg = isexpr(last, :call) && any(@nospecialize(x) -> isa(x, SlotNumber) && x.id == 1, last.args) # isequal(SlotNumber(1)) vulnerable to invalidation
issplatcall, _callee = unpack_splatcall(last)
if is_kw || has_selfarg || (issplatcall && is_bodyfunc(_callee))
# If the last expr calls #self# or passes it to an implementation method,
Expand Down
9 changes: 6 additions & 3 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,15 @@ function statementnumbers(framecode::FrameCode, line::Integer, file::Symbol)
offset = if scope isa Method
method = scope
_, line1 = whereis(method)
line1 - method.line
Int(line1 - method.line)
else
0
end

lt = linetable(framecode)

# Check if the exact line number exist
idxs = findall(entry -> entry.line + offset == line && entry.file == file, lt)
idxs = findall(entry::Union{LineInfoNode,LineNumberNode} -> entry.line + offset == line && entry.file == file, lt)
locs = codelocs(framecode)
if !isempty(idxs)
stmtidxs = Int[]
Expand Down Expand Up @@ -427,6 +427,7 @@ function statementnumbers(framecode::FrameCode, line::Integer, file::Symbol)
closest = nothing
closest_idx = nothing
for (i, entry) in enumerate(lt)
entry = entry::Union{LineInfoNode,LineNumberNode}
if entry.file == file && entry.line in range && entry.line >= line
if closest === nothing
closest = entry
Expand All @@ -440,7 +441,9 @@ function statementnumbers(framecode::FrameCode, line::Integer, file::Symbol)
end
end
if closest_idx !== nothing
idx = findfirst(i-> i==closest_idx, locs)
idx = let closest_idx=closest_idx # julia #15276
findfirst(i-> i==closest_idx, locs)
end
return idx === nothing ? nothing : Int[idx]
end
end
Expand Down

0 comments on commit a8e450c

Please sign in to comment.