Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

core.demangle: add support for type, identifer and symbol back references #1830

Merged
merged 13 commits into from
Jul 16, 2017

Conversation

rainers
Copy link
Member

@rainers rainers commented May 27, 2017

support for dlang/dmd#5855 and a couple of fixes.

@ibuclaw
Copy link
Member

ibuclaw commented May 28, 2017

Notably missing unittests, but I guess these will be added after compiler support is in.

@rainers
Copy link
Member Author

rainers commented May 28, 2017

Notably missing unittests, but I guess these will be added after compiler support is in.

The demangling is tested with the compiler test suite as I changed some of the mangling tests to just compare the result of demangling.

I guess I should some tests here, though, so we'll get some coverage locally before merging.

@rainers rainers force-pushed the mangle_backrefs branch 3 times, most recently from 23972c9 to 78d946f Compare May 28, 2017 20:45
@rainers
Copy link
Member Author

rainers commented May 29, 2017

Added some test cases.

Trying to demangle all symbols from phobos unittest, I'm hitting the amgibuity on Pascal function types, see dlang/dmd#6702. The current implementation runs into a stack overflow. I should add some sanity checks anyway...

@rainers
Copy link
Member Author

rainers commented Jun 2, 2017

As a test field to work on I have extracted all D symbols from the map file of the phobos unittest. For a build with master, there are 127172 symbols with a maximum length of 416133 characters and an average length of 369 characters.

With back references the same symbols have a maximum length of 1114 characters with an average of 117.

I updated demangling to properly support back references, but a number of failures for demangling symbols with back references also affected symbols as emitted by master, so I fixed these, too.

Results:

branch failed incomplete max time average time
master 4192 19042 19 min 32 s 140 ms
shiftopt 4192 19042 19 ms 33 us
this_pr 0 25 36 ms 21 us
  • shiftopt: master with 99ae2c5
  • failed: core.demangle reports error (does not include bad results)
  • incomplete: __T still found in demangled name (indicating a template is left mangled)
  • max time: maximum time to decode one symbol

I cancelled the master test after about 3 hours when it was about half done (timings taken from that run).
The optimization for branch shiftopt didn't change results of demangling, so the number of failed/incomplete demanglings is copied to the master results.

For the back reference symbols, results only change a little:

branch failed incomplete max time average time
this_pr 21 0 43 ms 23 us

Edit: failed demanglings for symbols with back references reduced from 36 to 21 by update to dmd PR.

static if (__traits(compiles, __traits(externDmangle, "foo", void function())))
{
alias _wrap(alias T) = T; // fool the parser
alias externDFunc = _wrap!(__traits(externDmangle, fqn, FT));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be fixing mangleFunc!T(fqn) instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately the qualified name in mangleFunc is a runtime parameter. No luck using a trait there...

@rainers
Copy link
Member Author

rainers commented Jun 18, 2017

Unfortunately the qualified name in mangleFunc is a runtime parameter.

As mangleFunc is a public documented function this quite a bummer. If we want to keep the runtime argument as is I don't see an alternative to actually implementing the mangler in druntime, too.

I'm not sure if this is possible with the recently added traits, but would be rather pretty pessimistic with respect to template arguments. As the qualified name didn't support these so far, it might not be a large breaking change to restrict the function type to non-template types, too.

@dlang-bot
Copy link
Contributor

dlang-bot commented Jun 22, 2017

Thanks for your pull request, @rainers!

Bugzilla references

Auto-close Bugzilla Description
14319 core.demangle does not support member function attributes
14563 core.demangle: Does not demangle type modifers
14576 [ddemangle] core.demangle unable to handle ambiguity in symbols
16664 core.demangle functions are not callable from @safe or pure code
17609 core.demangle demangles delegate variables as functions
17610 core.demangle shows return type of template alias parameter
17611 core.demangle cannot demangle delegates with function attributes

@wilzbach
Copy link
Member

wilzbach commented Jun 22, 2017

Thanks for your pull request, @rainers! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.

FYI: this is a newly deployed feature on the dlang-bot and it will only post once for each PR and then update its comment with (hopefully) helpful messages, see e.g.

Bugs or feature requests can be reported dlang-bot's repo.

@rainers rainers force-pushed the mangle_backrefs branch 2 times, most recently from 3e13966 to e7e567c Compare June 22, 2017 07:04
@rainers
Copy link
Member Author

rainers commented Jun 22, 2017

Planning to throw out symbol back references and just go with type and symbol back references, I've now implemented mangleFunc with the help of the demangler and a little bit of DbI.

I had to add some pure and @safe hacks, though. The latter can be narrowed to a number of places if required.

@rainers rainers force-pushed the mangle_backrefs branch 2 times, most recently from 75eba5e to a2a30ae Compare June 23, 2017 09:26
@rainers
Copy link
Member Author

rainers commented Jun 23, 2017

Rebased with symbol back references removed.

@rainers rainers force-pushed the mangle_backrefs branch 3 times, most recently from 848ea8b to d123511 Compare June 28, 2017 06:33
@dlang-bot dlang-bot added the Enhancement New functionality label Jul 3, 2017
@rainers
Copy link
Member Author

rainers commented Jul 3, 2017

I've restricted the trusted code to a few small functions, so the demangler can be annotated safe. Apart from adding support for back references this PR now fixes some other issues, too:

@wilzbach
Copy link
Member

wilzbach commented Jul 5, 2017

Apart from adding support for back references this PR now fixes some other issues, too:

FYI: you can tag as many issues as you want to the dlang-bot / changelog in one commit.
See also: the regex used by Bugzilla and the bot.

@rainers
Copy link
Member Author

rainers commented Jul 15, 2017

@wilzbach @CyberShadow I think its pretty demotivating seeing almost every PR in the overview marked with a red cross, even though these are caused by spurious or unrelated failures of coverage and jenkins builds. Maybe the resulting build state should be evaluated from the required tests only. Is this possible?

@CyberShadow
Copy link
Member

@rainers I agree completely, and I've been complaining about this since forever to anyone who can listen, but I'm not sure what I can do at this point. If you have time to spare, tracking down and fixing the causes of the random failures or coverage fluctuations would be much appreciated.

@wilzbach What is the significance of "74.92% of diff hit (target 75.38%)"? Is it to say that of the lines added in this PR, only 74% are covered? If so, why the oddly specific 75.38% threshold?

@CyberShadow
Copy link
Member

Maybe the resulting build state should be evaluated from the required tests only. Is this possible?

Unfortunately I don't think it's possible. It would be nice if we could get rid of the codecov statuses and only use their bot's comments or integrate them with dlang-bot's comments, though.

@wilzbach
Copy link
Member

I think its pretty demotivating seeing almost every PR in the overview marked with a red cross, even though these are caused by spurious or unrelated failures of coverage and jenkins builds.

I fully agree.

Maybe the resulting build state should be evaluated from the required tests only. Is this possible?

Well actually Jenkins is supposed to be required, but we had quite some issues with it over the last few weeks.
And as @CyberShadow mentioned it's not possible to exclude status checks on the GitHub summary. Sadly if one check is red, the PR is marked as red.
At least for Jenkins I have good news as Martin and Sönke are tracking down the issues and have already fixed two.

but I'm not sure what I can do at this point. If you have time to spare, tracking down and fixing the causes of the random failures or coverage fluctuations would be much appreciated.

Yeah, I took us quite a long time to fix all spots at Phobos.

@wilzbach What is the significance of "74.92% of diff hit (target 75.38%)"? Is it to say that of the lines added in this PR, only 74% are covered?

Yes.

If so, why the oddly specific 75.38% threshold?

Target is the overall coverage that the project had before. I think the motivation is that you want to avoid decreasing the overall coverage with every PR.

Unfortunately I don't think it's possible. It would be nice if we could get rid of the codecov statuses and only use their bot's comments or integrate them with dlang-bot's comments, though.

This shouldn't be too difficult, but I am not sure whether people would really care about the bot's comment. CodeCov's solution is to send a new comment for every new coverage event which is quite noisy. Unfortunately the GH status API really sucks and we can't automatically receive the status hook and remove it, but would have to crawl CodeCov for updates.

@CyberShadow
Copy link
Member

This shouldn't be too difficult, but I am not sure whether people would really care about the bot's comment.

It seems that it boils down to one of the following:

  • Red X means "sometimes it's OK to merge" instead of "DO NOT MERGE";
  • We adjust CodeCov settings so that no reasonable PR would ever have a "failed" status.

IMO the second one has more value, as lack of trust in CI is not a problem we want to have, and seems more important than the artificial coverage metric.

I understand that even if we were to set the target to a very low value or even 0, codecov will still continue creating the status updates, and thus it should still be possible to see the difference in coverage at a glance, right? If so, then to me that seems like the preferable option.

@wilzbach
Copy link
Member

We adjust CodeCov settings so that no reasonable PR would ever have a "failed" status.

I don't know how that would be possible, the only thing that comes to my mind that we can do for now is #1874 (disable the status notifications).

I understand that even if we were to set the target to a very low value or even 0, codecov will still continue creating the status updates, and thus it should still be possible to see the difference in coverage at a glance, right? If so, then to me that seems like the preferable option.

AFAICT is the target the current project coverage. We could try to manually set the target coverage to 0 (see e.g. https://github.com/codecov/support/wiki/Codecov-Yaml), but at least for the next two or three weeks I don't have the time to play around with this. However, I just saw that CodeCov allows to specify an arbitrary webhook URL, so I can use the opportunity to plugin the bot, s.t. it can repost things (with a green status) in the future.

@rainers
Copy link
Member Author

rainers commented Jul 16, 2017

I don't know how that would be possible, the only thing that comes to my mind that we can do for now is #1874 (disable the status notifications).

Thanks for working on this. Is that supposed to make a difference for new builds already?

I have tried to avoid some indeterministic results here: #1875

@wilzbach wilzbach changed the base branch from master to mangle July 16, 2017 12:52
}
if (len + val.length > dst.length)
overflow();
size_t v = &val[0] - &dst[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

char peek( size_t n )
{
if( pos + n < buf.length )
return buf[pos + n];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I speculate speed is important here - perhaps you can make this trusted and skip bounds checking.

@andralex
Copy link
Member

I'll boldly go where only @rainers has gone and merge this.

@dlang-bot dlang-bot merged commit bcadc98 into dlang:mangle Jul 16, 2017
@rainers
Copy link
Member Author

rainers commented Jul 16, 2017

@andralex Thanks for merging
@wilzbach This is now merged to branch mangle, not master. Is that as expected?

@wilzbach
Copy link
Member

wilzbach commented Jul 16, 2017

Thanks for working on this. Is that supposed to make a difference for new builds already?

Yes, but only if they are based on a master commit that contains these changes (unfortunately codecov.yml is rather stupid).
For example:

image

#1877

CodeCov doesn't show up anymore, but it's built and analyzed:

https://codecov.io/gh/dlang/druntime/commit/d4015f4d403bd22ecee8b81bb61378d33e7df7df

I have tried to avoid some indeterministic results here: #1875

Thanks a lot.

@wilzbach This is now merged to branch mangle, not master. Is that as expected?

Yes, I didn't anticipate that this would be merged so quickly (it could have been rechanged to master), but luckily @MartinNowak helped out with #1877

@rainers
Copy link
Member Author

rainers commented Jul 16, 2017

CodeCov doesn't show up anymore, but it's built and analyzed:

Thanks, looks good.

https://codecov.io/gh/dlang/druntime/commit/d4015f4d403bd22ecee8b81bb61378d33e7df7df

Can the link be displayed somewhere? Or will it be necessary to build it manually or copy it from circleCI's output?

Yes, I didn't anticipate that this would be merged so quickly

Nor did I ;-)

@wilzbach
Copy link
Member

Can the link be displayed somewhere? Or will it be necessary to build it manually or copy it from circleCI's output?

dlang/dlang-bot#142 (for now we will just hard-code it to success and display it in the status bar). In the future, we might also show the message in the comment, but that's slightly more complicated as we would need to parse the existing comment when try to modify it)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Enhancement New functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants