Nagging coverage question

Ok, so, compare the following two macros:

macro adds_more_lines_1()
    quote
    nothing
    end
end
macro adds_more_lines_2()
    result = 
        quote
        nothing
        end
    result.args[1] = __source__
    result
end

@adds_more_lines_1 inserts additional lines of code. @adds_more_lines_2 not only inserts them, but changes the line numbering to point to the call site, rather than the definition site.

Naive experimentation seems to show to me that renumbering lines is necessary if you want filled out stacktraces and accurate coverage results. See here for an example. I’m honestly struggling to formulate my questions about this, but they basically boil down to:

a) Is this actually a good idea? If so, maybe we should mention it in the docs somewhere?
b) Should this be really necessary? Can coverage just keep tabs on new lines introduced by macros? If not, should renumbering maybe be done automatically as part of macro hygiene?

2 Likes

Ref Document renumbering lines in macros by bramtayl · Pull Request #40955 · JuliaLang/julia · GitHub