Spurious debugger breakpoints when using MLStyle
jonathan-laurent opened this issue · comments
When using the VSCode debugger on code that uses MLStyle, the debugger sometimes stops on spurious breakpoints before reaching the user-specified breakpoints.
Any idea what's causing this? Has anyone else experienced this? Should I file an issue with VSCode or Debugger instead?
Replication instructions
Create a file with the following content. Open it in VSCode and set a breakpoint at the specified place.
using MLStyle
@data Expr begin
Const(value::Int)
Add(lhs::Expr, rhs::Expr)
end
function eval_expr(e::Expr)
return @match e begin
Const(v) => v
Add(lhs, rhs) => eval_expr(lhs) + eval_expr(rhs)
end
end
function evaluate_sum(exprs::Vector{<:Expr})
s = 0 # add breakpoint here
for e in exprs
s += eval_expr(e)
end
return s
end
evaluate_sum([Add(Const(2), Const(3))])
Then, start the debugger on the current file by pressing F5.
Instead of stopping at the user specified breakpoint, the debugger first stops within the source code of MLStyle (line 91 in MLStyle/.../Record.jl
):
function record_def(@nospecialize(Struct), line::LineNumberNode, ::Module)
quote
$line
function $MLStyle.pattern_uncall( # the debugger stops here
t::Type{<:$Struct},
self::Function,
type_params::Any,
type_args::Any,
args::Any,
)
$line
$_compile_record_pattern(t, self, type_params, type_args, args)
end
end
end
Sorry, this is because generated code takes line numbers from the macro caller inside the package.
It could be possible for us to clean them up in the future.