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

Fix some ChainRulesCore invalidations #530

Merged
merged 2 commits into from
Mar 17, 2022
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
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(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