Skip to content

Commit

Permalink
Support convert(LineNumberNode, ::LineInfoNode) (#50676)
Browse files Browse the repository at this point in the history
xref timholy/CodeTracking.jl#113. It
looks like that method might not even be important anymore for
CodeTracking and the Revise stack, but because we have lots of packages
that dive into internals, having this seems to make sense.
  • Loading branch information
timholy authored Jul 31, 2023
1 parent 441fcb1 commit 382ba35
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ macro gensym(names...)
return blk
end

## line numbers ##
convert(::Type{LineNumberNode}, lin::Core.LineInfoNode) = LineNumberNode(Int(lin.line), lin.file)

## expressions ##

isexpr(@nospecialize(ex), head::Symbol) = isa(ex, Expr) && ex.head === head
Expand Down
4 changes: 4 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8044,3 +8044,7 @@ end
# `SimpleVector`-operations should be concrete-eval eligible
@test Core.Compiler.is_foldable(Base.infer_effects(length, (Core.SimpleVector,)))
@test Core.Compiler.is_foldable(Base.infer_effects(getindex, (Core.SimpleVector,Int)))

let lin = Core.LineInfoNode(Base, first(methods(convert)), :foo, Int32(5), Int32(0))
@test convert(LineNumberNode, lin) == LineNumberNode(5, :foo)
end

0 comments on commit 382ba35

Please sign in to comment.