www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - CTFE in coverage reports - I finally fixed it

reply Stefan Koch <uplink.coder googlemail.com> writes:
Hi Guys,

CTFE not being in coverage reports has made 100% coverage 
unattainable
for code which has if (__ctfe) branches.

Well fret no more.
A few hours ago I've gotten this result.

---
       4|int f(int n) { int acc;
      42|    foreach(i;0 .. n)
        |    {
      10|        acc += i;
        |    }
       4|    return acc;
        |}
        |
        |
        |pragma(msg, f2(4));
        |pragma(msg, f(4));
        |pragma(msg, f2(4));
        |
        |void main()
        |{
        |    import core.stdc.stdio;
       1|    printf("%d %d %d\n", f(1), f(2), f(3));
        |}
        |
        |int f2(int n)
        |{
       2|    int acc;
      30|    foreach(i;0 .. n)
        |    {
       8|        acc += i;
        |    }
       2|    return acc;}
test_ctfe.d is 100% covered
---

the function f2() is never called at runtime at yet we are 100% 
covered.

The way it works is quite simple.
During CTFE we keep an array which counts the lines we hit.
When it comes time to do codegen we simply initialize the hidden 
__coverge symbol.
Which is a uint[]  representing the coverage counts for line 
numbers with that information rather than filling it with zeros.

Therefore no modification to the runtime is necessary at all.

It's open as DMD pr: https://github.com/dlang/dmd/pull/11279

and hopefully passing on all platforms.

Cheers,

Stefan
Jun 15
next sibling parent reply Bruce Carneal <bcarneal gmail.com> writes:
On Monday, 15 June 2020 at 15:02:04 UTC, Stefan Koch wrote:
 Hi Guys,

 CTFE not being in coverage reports has made 100% coverage 
 unattainable
 for code which has if (__ctfe) branches.

 Well fret no more.
[snip of code demonstrating the improvement, better coverage stats]
 The way it works is quite simple.
 During CTFE we keep an array which counts the lines we hit.
 When it comes time to do codegen we simply initialize the 
 hidden __coverge symbol.
 Which is a uint[]  representing the coverage counts for line 
 numbers with that information rather than filling it with zeros.

 Therefore no modification to the runtime is necessary at all.

 It's open as DMD pr: https://github.com/dlang/dmd/pull/11279

 and hopefully passing on all platforms.

 Cheers,

 Stefan
Thanks for this Stefan. Another nice step towards "it all just works" and a commendably simple implementation.
Jun 15
parent reply Stefan Koch <uplink.coder googlemail.com> writes:
On Monday, 15 June 2020 at 16:49:16 UTC, Bruce Carneal wrote:
 On Monday, 15 June 2020 at 15:02:04 UTC, Stefan Koch wrote:
 Hi Guys,

 CTFE not being in coverage reports has made 100% coverage 
 unattainable
 for code which has if (__ctfe) branches.
 
 Fret no mre.

 Stefan
Thanks for this Stefan. Another nice step towards "it all just works" and a commendably simple implementation.
Thanks Bruce, it does help tremendously to get this kind of feedback. Cheers, Stefan P.S. let's meet at the online beerconf, if and when it happnes.
Jun 15
next sibling parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 6/15/20 10:11 AM, Stefan Koch wrote:

 it does help tremendously to get this kind of feedback.
Sorry for being quiet but I always appreciate your work. It's inspring how you never give up and continue going forward. :) Ali
Jun 15
parent reply Max Samukha <maxsamukha gmail.com> writes:
On Monday, 15 June 2020 at 18:49:01 UTC, Ali Çehreli wrote:
 On 6/15/20 10:11 AM, Stefan Koch wrote:

 it does help tremendously to get this kind of feedback.
Sorry for being quiet but I always appreciate your work. It's inspring how you never give up and continue going forward. :) Ali
Same here. Stefan rox.
Jun 15
parent Stefan Koch <uplink.coder googlemail.com> writes:
On Monday, 15 June 2020 at 20:00:55 UTC, Max Samukha wrote:
 On Monday, 15 June 2020 at 18:49:01 UTC, Ali Çehreli wrote:
 On 6/15/20 10:11 AM, Stefan Koch wrote:

 it does help tremendously to get this kind of feedback.
Sorry for being quiet but I always appreciate your work. It's inspring how you never give up and continue going forward. :) Ali
Same here. Stefan rox.
Thank you both Ali and Max.
Jun 15
prev sibling next sibling parent reply Faux Amis <faux amis.com> writes:
On 2020-06-15 19:11, Stefan Koch wrote:
 On Monday, 15 June 2020 at 16:49:16 UTC, Bruce Carneal wrote:
 On Monday, 15 June 2020 at 15:02:04 UTC, Stefan Koch wrote:
 Hi Guys,

 CTFE not being in coverage reports has made 100% coverage unattainable
 for code which has if (__ctfe) branches.

 Fret no mre.

 Stefan
Thanks for this Stefan.  Another nice step towards "it all just works" and a commendably simple implementation.
Thanks Bruce, it does help tremendously to get this kind of feedback. Cheers, Stefan P.S. let's meet at  the online beerconf, if and when it happnes.
Stefan, let me then add that I always look up to your work. Become one of the greats! ;)
Jun 15
parent reply Stefan Koch <uplink.coder googlemail.com> writes:
On Monday, 15 June 2020 at 20:51:13 UTC, Faux Amis wrote:
 On 2020-06-15 19:11, Stefan Koch wrote:
 On Monday, 15 June 2020 at 16:49:16 UTC, Bruce Carneal wrote:
 On Monday, 15 June 2020 at 15:02:04 UTC, Stefan Koch wrote:
 Hi Guys,

 CTFE not being in coverage reports has made 100% coverage 
 unattainable
 for code which has if (__ctfe) branches.

 Fret no mre.

 Stefan
Thanks for this Stefan.  Another nice step towards "it all just works" and a commendably simple implementation.
Thanks Bruce, it does help tremendously to get this kind of feedback. Cheers, Stefan P.S. let's meet at  the online beerconf, if and when it happnes.
Stefan, let me then add that I always look up to your work. Become one of the greats! ;)
Thanks. I am happy you think so.
Jun 16
parent reply aberba <karabutaworld gmail.com> writes:
On Tuesday, 16 June 2020 at 16:03:11 UTC, Stefan Koch wrote:
 On Monday, 15 June 2020 at 20:51:13 UTC, Faux Amis wrote:
 On 2020-06-15 19:11, Stefan Koch wrote:
 On Monday, 15 June 2020 at 16:49:16 UTC, Bruce Carneal wrote:
 On Monday, 15 June 2020 at 15:02:04 UTC, Stefan Koch wrote:
 [...]
Thanks for this Stefan.  Another nice step towards "it all just works" and a commendably simple implementation.
Thanks Bruce, it does help tremendously to get this kind of feedback. Cheers, Stefan P.S. let's meet at  the online beerconf, if and when it happnes.
Stefan, let me then add that I always look up to your work. Become one of the greats! ;)
Thanks. I am happy you think so.
Will you publish your tui library to dub? would like to try it.
Jun 16
parent reply Stefan Koch <uplink.coder googlemail.com> writes:
On Tuesday, 16 June 2020 at 18:25:27 UTC, aberba wrote:
 On Tuesday, 16 June 2020 at 16:03:11 UTC, Stefan Koch wrote:
 On Monday, 15 June 2020 at 20:51:13 UTC, Faux Amis wrote:
 On 2020-06-15 19:11, Stefan Koch wrote:
 On Monday, 15 June 2020 at 16:49:16 UTC, Bruce Carneal wrote:
 [...]
Thanks Bruce, it does help tremendously to get this kind of feedback. Cheers, Stefan P.S. let's meet at  the online beerconf, if and when it happnes.
Stefan, let me then add that I always look up to your work. Become one of the greats! ;)
Thanks. I am happy you think so.
Will you publish your tui library to dub? would like to try it.
Which one do you mean? d-tui? That's not actually mine, I just forked it.
Jun 16
parent reply aberba <karabutaworld gmail.com> writes:
On Tuesday, 16 June 2020 at 18:30:49 UTC, Stefan Koch wrote:
 On Tuesday, 16 June 2020 at 18:25:27 UTC, aberba wrote:
 On Tuesday, 16 June 2020 at 16:03:11 UTC, Stefan Koch wrote:
 On Monday, 15 June 2020 at 20:51:13 UTC, Faux Amis wrote:
 On 2020-06-15 19:11, Stefan Koch wrote:
 On Monday, 15 June 2020 at 16:49:16 UTC, Bruce Carneal 
 wrote:
 [...]
Thanks Bruce, it does help tremendously to get this kind of feedback. Cheers, Stefan P.S. let's meet at  the online beerconf, if and when it happnes.
Stefan, let me then add that I always look up to your work. Become one of the greats! ;)
Thanks. I am happy you think so.
Will you publish your tui library to dub? would like to try it.
Which one do you mean? d-tui? That's not actually mine, I just forked it.
Ok ok, so its the same as qui in dub repo? What I'm doing is trying out D package so write posts/demo about them. A tour kind of...D's ecosystem.
Jun 16
parent Stefan Koch <uplink.coder googlemail.com> writes:
On Tuesday, 16 June 2020 at 20:23:50 UTC, aberba wrote:
 On Tuesday, 16 June 2020 at 18:30:49 UTC, Stefan Koch wrote:
 On Tuesday, 16 June 2020 at 18:25:27 UTC, aberba wrote:
 On Tuesday, 16 June 2020 at 16:03:11 UTC, Stefan Koch wrote:
 On Monday, 15 June 2020 at 20:51:13 UTC, Faux Amis wrote:
 On 2020-06-15 19:11, Stefan Koch wrote:
 On Monday, 15 June 2020 at 16:49:16 UTC, Bruce Carneal 
 wrote:
 [...]
Thanks Bruce, it does help tremendously to get this kind of feedback. Cheers, Stefan P.S. let's meet at  the online beerconf, if and when it happnes.
Stefan, let me then add that I always look up to your work. Become one of the greats! ;)
Thanks. I am happy you think so.
Will you publish your tui library to dub? would like to try it.
Which one do you mean? d-tui? That's not actually mine, I just forked it.
Ok ok, so its the same as qui in dub repo? What I'm doing is trying out D package so write posts/demo about them. A tour kind of...D's ecosystem.
No it's not. It's a d port of borlands tvision library. Originally by https://github.com/klamonte I just fixed it up a little, and after he deleted his repo, it now looks like I am maintaining it, but I don't really :p
Jun 16
prev sibling parent Stanislav Blinov <stanislav.blinov gmail.com> writes:
On Monday, 15 June 2020 at 17:11:25 UTC, Stefan Koch wrote:
 On Monday, 15 June 2020 at 16:49:16 UTC, Bruce Carneal wrote:
 Thanks for this Stefan.  Another nice step towards "it all 
 just works" and a commendably simple implementation.
Thanks Bruce, it does help tremendously to get this kind of feedback.
How to know that you did great work: nobody is saying anything, everybody's just using it ;) Keep rocking!
Jun 15
prev sibling parent Jesse Phillips <Jesse.K.Phillips+D gmail.com> writes:
On Monday, 15 June 2020 at 15:02:04 UTC, Stefan Koch wrote:
 Hi Guys,

 CTFE not being in coverage reports has made 100% coverage 
 unattainable
 for code which has if (__ctfe) branches.

 Well fret no more.
 A few hours ago I've gotten this result.
D has no much potential to take on so many different domains. Moving programming challenges to compile time creates some unique opportunity. It is nice to hear about your progress.
Jun 15