Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make D great again #15568

Merged
merged 5 commits into from Oct 1, 2023
Merged

make D great again #15568

merged 5 commits into from Oct 1, 2023

Conversation

adamdruppe
Copy link
Contributor

No description provided.

@dlang-bot
Copy link
Contributor

dlang-bot commented Sep 1, 2023

Thanks for your pull request and interest in making D better, @adamdruppe! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
10532 enhancement Silence some unreachable statement warnings when in a static foreach
14835 major Constant folding should not affect front end flow analysis
20522 enhancement Spurious statement unreachable warning caused by undefined variable

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#15568"

@maxhaton maxhaton added the Trivial typos, formatting, comments label Sep 1, 2023
@thewilsonator
Copy link
Contributor

Description + changelog/issue# please.

@adamdruppe
Copy link
Contributor Author

https://issues.dlang.org/show_bug.cgi?id=14835
https://issues.dlang.org/show_bug.cgi?id=10532

less directly:

https://issues.dlang.org/show_bug.cgi?id=16201
https://issues.dlang.org/show_bug.cgi?id=20522

It is hard to use D's metaprogramming capabilities without this warning issuing a false positive and forcing you to degrade the code to work around it.

@thewilsonator
Copy link
Contributor

So if this fixes any of those, the commit message should say so, you know the drill.

@rikkimax
Copy link
Contributor

Alternative: disable it for scopes that use static if and static foreach.

@0xEAB
Copy link
Contributor

0xEAB commented Sep 10, 2023

This warning sounds great and useful in theory, but:
Practice shows it’s an obstacle most of the time. (Even when we ignore the false positives!)

I can think of maybe one occasion where it actually helped me prevent a buggy program from compiling. On the other hand I could regularly tell tales how it gets in my way.

Unlike with bigger C projects (at least a bunch that I’ve run into), most D projects are written in a “no warnings” way. This is established well enough that even DUB defaults to emitting the -w flag (“Treat warnings as errors”). So, false positive or not, what happens when you run into the “statement not reachable” warning? Yeah, you go and edit your build recipe. Inconvenient :/


When it’s not a false positive, it’s still often useless, because code works as intended.

So, let’s say, I’ve hit the warning because I’ve added temporary debugging code to my program. Maybe a quick assert(false); to stop execution from going beyond a certain point, a patchy throw statement with a different msg or a return statement to short-circuit things with a different return value. Or whatever… I know what I’m doing here (hopefully), I won’t forget to remove the temp code. But I’ll trigger the warning.
Well, time to interrupt my flow. Gotta add -wi for the debugging session. Just to remove it later (or forget to do so).

Bonus points if you know the DUB equivalent for -wi by heart. I don’t. I’ll sit there and have to look it up; again and again.

@pbackus
Copy link
Contributor

pbackus commented Sep 10, 2023

This isn't just a problem with static foreach and static if. One of the most annoying instances of this warning I've run into was in code of the form

unittest
{
    assert(cond1);
    assert(cond2);
}

If the compiler is able to constant-fold cond1 to false, it will declare the second assertion unreachable. Under default dub settings, this halts compilation, which makes it impossible to run the rest of the test suite until that specific assertion is fixed.

@0xEAB
Copy link
Contributor

0xEAB commented Sep 10, 2023

Another interesting finding is that the warning is not emitted for code like this:

return;
assert(false);

You wouldn’t (have to) special case this if the thing weren’t kinda low-value in the first place.

@ljmf00
Copy link
Member

ljmf00 commented Sep 11, 2023

This is pretty much a linting rule that we are forced to use without just disabling all the warnings. I think this is worth keeping, if we have a way to select which rule to warn us.

@tgehr
Copy link
Contributor

tgehr commented Sep 15, 2023

Test suite has to be updated.

@dkorpel dkorpel force-pushed the sanity branch 2 times, most recently from cd3cb7e to ce11c37 Compare September 21, 2023 11:35
Copy link
Contributor

@dkorpel dkorpel left a comment

Choose a reason for hiding this comment

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

Discussed in the September monthly meeting, remove warning but leave code in for now

@thewilsonator
Copy link
Contributor

again, changelog entry or issues fixed please.

@thewilsonator
Copy link
Contributor

merge conflict

@ibuclaw
Copy link
Member

ibuclaw commented Sep 21, 2023

Third commit does more than convert tabs to spaces.

Maybe squash the commits and make use of the Co-Authored-By trailer?

@dkorpel
Copy link
Contributor

dkorpel commented Sep 21, 2023

Third commit does more than convert tabs to spaces.

Yeah something went wrong when rebasing on top of #15623

@ljmf00
Copy link
Member

ljmf00 commented Oct 1, 2023

Don't forget to merge with squash.

@dkorpel dkorpel merged commit d5993f9 into dlang:master Oct 1, 2023
40 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Fix Enhancement Trivial typos, formatting, comments
Projects
None yet