Skip to content

Commit

Permalink
fixup! code-coverage: report coverage for effect-free lines
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Jan 13, 2020
1 parent f718a66 commit 202efeb
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 28 deletions.
3 changes: 2 additions & 1 deletion base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,8 @@ function typeinf_local(frame::InferenceState)
if isa(fname, Slot)
changes = StateUpdate(fname, VarState(Any, false), changes)
end
elseif hd === :inbounds || hd === :meta || hd === :loopinfo
elseif hd === :inbounds || hd === :meta || hd === :loopinfo || hd == :code_coverage_effect
# these do not generate code
else
t = abstract_eval(stmt, changes, frame)
t === Bottom && break
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/ssair/driver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function convert_to_ircode(ci::CodeInfo, code::Vector{Any}, coverage::Bool, narg
codeloc = ci.codelocs[idx]
if coverage && codeloc != prevloc && codeloc != 0
# insert a side-effect instruction before the current instruction in the same basic block
insert!(code, idx, Expr(:gc_preserve_begin))
insert!(code, idx, Expr(:code_coverage_marker))
insert!(ci.codelocs, idx, codeloc)
insert!(ci.ssavaluetypes, idx, Nothing)
changemap[oldidx] += 1
Expand Down
3 changes: 2 additions & 1 deletion base/compiler/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const VALID_EXPR_HEADS = IdDict{Any,Any}(
:foreigncall => 5:typemax(Int), # name, RT, AT, nreq, cconv, args..., roots...
:cfunction => 5:5,
:isdefined => 1:1,
:code_coverage_effect => 0:0,
:loopinfo => 0:typemax(Int),
:gc_preserve_begin => 0:typemax(Int),
:gc_preserve_end => 0:typemax(Int),
Expand Down Expand Up @@ -144,7 +145,7 @@ function validate_code!(errors::Vector{>:InvalidCodeError}, c::CodeInfo, is_top_
head === :const || head === :enter || head === :leave || head === :pop_exception ||
head === :method || head === :global || head === :static_parameter ||
head === :new || head === :splatnew || head === :thunk || head === :loopinfo ||
head === :throw_undef_if_not || head === :unreachable
head === :throw_undef_if_not || head === :unreachable || head === :code_coverage_effect
validate_val!(x)
else
# TODO: nothing is actually in statement position anymore
Expand Down
3 changes: 2 additions & 1 deletion src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jl_sym_t *nospecialize_sym; jl_sym_t *macrocall_sym;
jl_sym_t *colon_sym; jl_sym_t *hygienicscope_sym;
jl_sym_t *throw_undef_if_not_sym; jl_sym_t *getfield_undefref_sym;
jl_sym_t *gc_preserve_begin_sym; jl_sym_t *gc_preserve_end_sym;
jl_sym_t *escape_sym;
jl_sym_t *coverageeffect_sym; jl_sym_t *escape_sym;
jl_sym_t *aliasscope_sym; jl_sym_t *popaliasscope_sym;

static uint8_t flisp_system_image[] = {
Expand Down Expand Up @@ -365,6 +365,7 @@ void jl_init_frontend(void)
throw_undef_if_not_sym = jl_symbol("throw_undef_if_not");
getfield_undefref_sym = jl_symbol("##getfield##");
do_sym = jl_symbol("do");
coverageeffect_sym = jl_symbol("code_coverage_marker");
aliasscope_sym = jl_symbol("aliasscope");
popaliasscope_sym = jl_symbol("popaliasscope");
}
Expand Down
27 changes: 6 additions & 21 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4026,7 +4026,8 @@ static void emit_stmtpos(jl_codectx_t &ctx, jl_value_t *expr, int ssaval_result)
jl_expr_t *ex = (jl_expr_t*)expr;
jl_value_t **args = (jl_value_t**)jl_array_data(ex->args);
jl_sym_t *head = ex->head;
if (head == meta_sym || head == inbounds_sym || head == aliasscope_sym || head == popaliasscope_sym) {
if (head == meta_sym || head == inbounds_sym || head == coverageeffect_sym
|| head == aliasscope_sym || head == popaliasscope_sym) {
// some expression types are metadata and can be ignored
// in statement position
return;
Expand Down Expand Up @@ -4307,26 +4308,10 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaval)
I->setMetadata("julia.loopinfo", MD);
return jl_cgval_t();
}
else if (head == goto_ifnot_sym) {
jl_error("Expr(:goto_ifnot) in value position");
}
else if (head == leave_sym) {
jl_error("Expr(:leave) in value position");
}
else if (head == pop_exception_sym) {
jl_error("Expr(:pop_exception) in value position");
}
else if (head == enter_sym) {
jl_error("Expr(:enter) in value position");
}
else if (head == inbounds_sym) {
jl_error("Expr(:inbounds) in value position");
}
else if (head == aliasscope_sym) {
jl_error("Expr(:aliasscope) in value position");
}
else if (head == popaliasscope_sym) {
jl_error("Expr(:popaliasscope) in value position");
else if (head == goto_ifnot_sym || head == leave_sym || head == coverageeffect_sym
|| head == pop_exception_sym || head == enter_sym || head == inbounds_sym
|| head == aliasscope_sym || head == popaliasscope_sym) {
jl_errorf("Expr(:%s) in value position", jl_symbol_name(head));
}
else if (head == boundscheck_sym) {
return mark_julia_const(bounds_check_enabled(ctx, jl_true) ? jl_true : jl_false);
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ static jl_value_t *eval_value(jl_value_t *e, interpreter_state *s)
else if (head == boundscheck_sym) {
return jl_true;
}
else if (head == meta_sym || head == inbounds_sym || head == loopinfo_sym) {
else if (head == meta_sym || head == coverageeffect_sym || head == inbounds_sym || head == loopinfo_sym) {
return jl_nothing;
}
else if (head == gc_preserve_begin_sym || head == gc_preserve_end_sym) {
Expand Down
2 changes: 1 addition & 1 deletion src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ extern jl_sym_t *colon_sym; extern jl_sym_t *hygienicscope_sym;
extern jl_sym_t *throw_undef_if_not_sym; extern jl_sym_t *getfield_undefref_sym;
extern jl_sym_t *gc_preserve_begin_sym; extern jl_sym_t *gc_preserve_end_sym;
extern jl_sym_t *failed_sym; extern jl_sym_t *done_sym; extern jl_sym_t *runnable_sym;
extern jl_sym_t *escape_sym;
extern jl_sym_t *coverageeffect_sym; extern jl_sym_t *escape_sym;

struct _jl_sysimg_fptrs_t;

Expand Down
3 changes: 2 additions & 1 deletion src/method.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ static jl_value_t *resolve_globals(jl_value_t *expr, jl_module_t *module, jl_sve
jl_toplevel_eval_flex(module, expr, 0, 1);
expr = jl_nothing;
}
if (jl_is_toplevel_only_expr(expr) || e->head == const_sym || e->head == copyast_sym ||
if (jl_is_toplevel_only_expr(expr) || e->head == const_sym ||
e->head == coverageeffect_sym || e->head == copyast_sym ||
e->head == quote_sym || e->head == inert_sym ||
e->head == meta_sym || e->head == inbounds_sym ||
e->head == boundscheck_sym || e->head == loopinfo_sym ||
Expand Down

0 comments on commit 202efeb

Please sign in to comment.