Skip to content

Conversation

@mihails-strasuns
Copy link

Makes it more obvious that any failed assertion is a compiler
bug to be reported. Inspired by http://forum.dlang.org/thread/[email protected]

@quickfur
Copy link
Member

quickfur commented Sep 2, 2016

Strange, tested this locally but asserts don't seem to trigger the custom error message?

@quickfur
Copy link
Member

quickfur commented Sep 2, 2016

Ah, nevermind, the problem is that the backend code uses a different assert function (the one from C/C++). Any way to redirect those asserts as well?

@mihails-strasuns
Copy link
Author

Will have to look into that, my C has got a bit rusty :)

@PetarKirov
Copy link
Member

I was just about to ask if it works in practice (obviously can't be unittested reliably). IIRC, dmd is built with -release, so calls to the assert handler would be replaced with halt instructions?

@mihails-strasuns
Copy link
Author

mihails-strasuns commented Sep 2, 2016

IIRC, dmd is built with -release

That shouldn't be the case, otherwise one wouldn't see the assertion message, just the immediate segfault.

EDIT: ah, forgot that C code is compiled differently, yes, this needs to be taken into account

@quickfur
Copy link
Member

quickfur commented Sep 2, 2016

I'm testing a debug build, but it seems that every ICE I can find on bugzilla either comes from the backend, or involves a segfault (so doesn't go through this code). I'm having trouble actually seeing the new error message appear. :-P

@mihails-strasuns
Copy link
Author

@quickfur looks like with C assert it is tricky. Would exposing extern(C) wrapper from D and switching C sources to use it instead be a viable option?

@quickfur
Copy link
Member

quickfur commented Sep 2, 2016

haha, finally found an ICE that triggers this error: https://issues.dlang.org/show_bug.cgi?id=16284

It seems that you need a \n at the end of the message. :-)

@quickfur
Copy link
Member

quickfur commented Sep 2, 2016

@Dicebot Is it because the C assert is a macro?

@quickfur
Copy link
Member

quickfur commented Sep 2, 2016

There's also util_assert in backend/util2.c, which might be a bit easier to work with. In fact, why isn't util_assert used consistently?

@quickfur
Copy link
Member

quickfur commented Sep 2, 2016

Another idea: assert.h is explicitly #include'd by several dmd source files; possibly we can hack it by redirecting it to a custom header file that forwards assert to the D assert handler?

@jacob-carlborg
Copy link
Contributor

It would be nice to get a stack trace for the assertions in the C code. Using the platform supplied assert, at least on OS X, will print a stack trace.

@AndrejMitrovic
Copy link
Contributor

I was going to suggest adding a test-case, but we want to get rid of compiler bugs that trigger these. 😄

@codecov-io
Copy link

codecov-io commented Sep 3, 2016

Current coverage is 87.41% (diff: 14.28%)

No coverage report found for master at fb2fa43.

Powered by Codecov. Last update fb2fa43...d4b055c

@mihails-strasuns
Copy link
Author

Ok, I decided initially to simply go for ensuring built-in assert is never used and adding same bugzilla reference to custom assert function. Using D assert feels tempting but I am not sure what will happen if one attempts to throw an exception/error from C code.

Dicebot added 3 commits September 3, 2016 15:29
@mihails-strasuns
Copy link
Author

Green apart from code coverage checks.

fflush(stdout);
printf("Internal error: %s %d\n",file,line);
printf("This is a compiler bug, please report it via "
"https://issues.dlang.org/enter_bug.cgi\n");
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. How about pre-filling some selections?
    e.g. https://issues.dlang.org/enter_bug.cgi?component=dmd&bug_severity=critical&keywords=ice

(we could make a short URL or short domain (e.g. https://bugs.dlang.io/ice out of this, if that's too long)

  1. As someone on the NG proposed: What about a link to the DWiki instead which describes further steps? (e.g. how to dustmite, what to mention in the bug report, ...)
  • Just an empty bug report page can be quite intimidating for a user.
  • We don't seem to have such a page as of now, but maybe we can take a bit of information from Get involved and start a new one?
  • the issue writing guidelines seems to be a generic page from Bugzilla

Copy link
Contributor

@AndrejMitrovic AndrejMitrovic Sep 3, 2016

Choose a reason for hiding this comment

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

Just an empty bug report page can be quite intimidating for a user.

If they start typing out the title they might find a duplicate one listed which could show a way to work around the bug. Even if they end up submitting a duplicate report this would get attention from bugzilla lurkers and they would get feedback pretty soon.

It would really suck if bugs like this went unreported. Bugzilla seems like a good first choice, but an ICE should be rare enough that adding two links to the diagnostics isn't such an overwhelming idea. Something like:

This is an unexpected internal compiler bug, please submit a 
bug report via https://issues.dlang.org/enter_bug.cgi?
  component=dmd&bug_severity=critical&keywords=ice

For more info on internal compiler errors see <this wiki page>

Copy link
Member

Choose a reason for hiding this comment

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

  1. should be major, not critical.
  2. I wonder if having this link would encourage spammers to post on bugzilla by raising the visibility of it

Copy link
Contributor

Choose a reason for hiding this comment

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

Because the URL will be in the source code? Perhaps obfuscate it using base64 encoding or similar.

Copy link
Contributor

Choose a reason for hiding this comment

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

Bugzilla URLs are already in various parts of our website (and therefore on github), so I'm not sure how adding it to the source code makes it different?

Copy link
Member

Choose a reason for hiding this comment

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

I guess we'll see! So far we haven't had any trouble with abusive bugzilla postings.

Copy link
Member

Choose a reason for hiding this comment

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

But still, it should be major, not critical. Critical would be things like silently generating bad code, which is much worse than an assert.

@mihails-strasuns
Copy link
Author

FYI: I will be travelling for next 1.5 weeks and will only get back to this PR after. Feel free to take it over if you want to merge it faster.

@mathias-lang-sociomantic
Copy link
Contributor

I was just about to ask if it works in practice (obviously can't be unittested reliably). IIRC, dmd is built with -release, so calls to the assert handler would be replaced with halt instructions?

It isn't built with -release locally, but shipped with -release, so the assertHandler will never be used.
See the release script enable those lines.

It's the case since the switch DDMD, I'll open a discussion on dmd-internals.

@mihails-strasuns
Copy link
Author

It's the case since the switch DDMD, I'll open a discussion on dmd-internals.

Yes, this is a blocker. I'll wait for the thread to resolve before updating this.

@wilzbach
Copy link
Contributor

It isn't built with -release locally, but shipped with -release, so the assertHandler will never be used.
It's the case since the switch DDMD, I'll open a discussion on dmd-internals.
Yes, this is a blocker. I'll wait for the thread to resolve before updating this.

So is it possible to release dmd with asserts enabled or are the better options?

@wilzbach
Copy link
Contributor

So is it possible to release dmd with asserts enabled or are the better options?

Sounds to me like DIP1006 would solve this problem (compiling dmd in release mode, but with asserts enabled).

@dnadlinger
Copy link
Contributor

dnadlinger commented Mar 22, 2017

Or we could use a signal handler to detect the assert(0)s. (LDC already supports selective toggling of asserts and other contract-type features, if that is where the holdup is.)

@wilzbach
Copy link
Contributor

wilzbach commented Apr 5, 2018

Revived this in #8138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants