-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Open
Labels
parserLanguage parsing and surface syntaxLanguage parsing and surface syntax
Description
Defining code like:
macros.jl:
macro foo()
esc(:(x += 1))
end
macro bar()
esc(quote
x += 1
error()
end)
endscratch.jl:
include("macros.jl")
function f(x)
@foo()
@bar()
endgives (as expected) Symbol("macro expansion") in the linetable:
julia> include("scratch.jl");
julia> ci = Base.uncompressed_ast(@which f(1));
julia> ci.linetable
4-element Vector{Any}:
Core.LineInfoNode(Main, :f, Symbol(".../scratch.jl"), 2, 0)
Core.LineInfoNode(Main, Symbol("macro expansion"), Symbol(".../macros.jl"), 3, 1)
Core.LineInfoNode(Main, :f, Symbol(".../scratch.jl"), 3, 0)
Core.LineInfoNode(Main, Symbol("macro expansion"), Symbol(".../macros.jl"), 9, 3)However, if the content of macros.jl is pasted into scratch.jl we instead get:
julia> ci.linetable
4-element Vector{Any}:
Core.LineInfoNode(Main, :f, Symbol(".../scratch.jl"), 15, 0)
Core.LineInfoNode(Main, :f, Symbol(".../scratch.jl"), 3, 0)
Core.LineInfoNode(Main, :f, Symbol(".../scratch.jl"), 16, 0)
Core.LineInfoNode(Main, :f, Symbol(".../scratch.jl"), 9, 0)This also means that the "macro expansion" stack frame is lost in case there is an error in the macro. For example, running the first case:
julia> f(1)
ERROR:
Stacktrace:
[1] error()
@ Base ./error.jl:44
[2] macro expansion
@ ~.../macros.jl:8 [inlined]
[3] f(x::Int64)
@ Main ~.../scratch.jl:5
[4] top-level scope
@ REPL[4]:1However, in the second case there is no macro expansion frame:
julia> f(1)
ERROR:
Stacktrace:
[1] error()
@ Base ./error.jl:44
[2] f(x::Int64)
@ Main ~.../scratch.jl:8
[3] top-level scope
@ REPL[6]:1Metadata
Metadata
Assignees
Labels
parserLanguage parsing and surface syntaxLanguage parsing and surface syntax