Skip to content

Conversation

@atilaneves
Copy link
Contributor

I think this doesn't cover all of them given that I only had to change one test. There are a lot of checks for DIP1000 in the codebase but that don't immediately print out error messages.

I figured it was best to do this part first and investigate more later.

@dlang-bot
Copy link
Contributor

dlang-bot commented May 24, 2021

Thanks for your pull request and interest in making D better, @atilaneves! 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

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

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#12578"

src/dmd/escape.d Outdated
void unsafeAssign(VarDeclaration v, const char* desc)
{
if (global.params.useDIP1000 == FeatureState.enabled && sc.func.setUnsafe())
if (sc.func.setUnsafe())
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this (and the change at L1045) change the semantic of programs not using DIP1000 as well ?
setUnsafe has side effect. We had a bug related to it: https://github.com/dlang/dmd/pull/12127/files#diff-1a1c16e5ec319550bcd4ecb5d3f4ca6ca7ffad78af91f077603617117bb7d0c7R1037-R1038

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I hadn't considered the short-circuiting nature of the check. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After checking the code, I think this is fine, since it only has a side-effect when the compiler is determining safety anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

Some projects on buildkite are currently failing because formerly @safe functions are now inferred @system, probably because of this setUnsafe()

@Geod24
Copy link
Member

Geod24 commented May 25, 2021

I'm not sure I understand the purpose of that PR ? Turn DIP1000 on by default, but with errors as deprecations ?
Because if the aim is to just force people to use -preview=dip1000, a simple line in mars.d would do, but if the aim is to do something similar to what was done with DIP25 (which I hope it is), then perhaps "Turn DIP1000 on by default" would be a more accurate description.
However, what about the (multiple) bugs still present with DIP1000 ?

@atilaneves
Copy link
Contributor Author

if the aim is to do something similar to what was done with DIP25

The aim is indeed to to do what was done for DIP25. I don't think "turn on DIP1000" is accurate - the goal is first to annoy users with deprecation messages and force them to use -revert to make them go away. Once that's in place we can actually turn it on by default.

However, what about the (multiple) bugs still present with DIP1000 ?

  1. We need to fix all of them, post-haste
  2. The most that can happen with this PR is users get deprecation warnings that don't make sense
  3. -revert solves that

@Geod24
Copy link
Member

Geod24 commented May 27, 2021

The aim is indeed to to do what was done for DIP25.

👍 👍

  1. We need to fix all of them, post-haste

The point of -preview design's was to lower the barrier of entry of code in the compiler so a design could be ironed out and tried in the wild. If we start to make DIP1000 the default before the design has actually been ironed out, we're both failing at -preview and accepting code we wouldn't have otherwise.

  1. The most that can happen with this PR is users get deprecation warnings that don't make sense

IOW, something completely unacceptable.

  1. -revert solves that

-revert is a way to selectively disable a class of valid deprecations that might prove invasive for some user. Not an excuse to enable an incomplete preview switch.

@atilaneves
Copy link
Contributor Author

Am I missing something wrt DIP1000 design decisions? AFAIK we "only" have to fix bugs.

@RazvanN7
Copy link
Contributor

DIP1000 does suffer from some bugs, however, every feature does. What would be the point when we can safely say "now is the time to enable dip1000 by default"? Are there any glaring holes that need to be fix first? If not, I think that we can go ahead and merge this PR.

@dkorpel
Copy link
Contributor

dkorpel commented May 28, 2021

What would be the point when we can safely say "now is the time to enable dip1000 by default"?
Are there any glaring holes that need to be fix first?

Yes, issue 20150 is particularly egregious.

@Geod24
Copy link
Member

Geod24 commented May 28, 2021

What would be the point when we can safely say "now is the time to enable dip1000 by default"?

When DIP1000 allow to achieve its stated goal: @safe reference counting.

@atilaneves
Copy link
Contributor Author

What would be the point when we can safely say "now is the time to enable dip1000 by default"?
Are there any glaring holes that need to be fix first?

Yes, issue 20150 is particularly egregious.

I agree this is a blocker. It's one thing for DIP1000 to not catch all memory safety errors due to a bug, it's another entirely to start compiling code that it didn't before that isn't memory safe.

@dkorpel dkorpel added the dip1000 memory safety with scope, ref, return label Jul 21, 2021
@atilaneves atilaneves force-pushed the dip1000-deprecation-msgs branch from 7c7ce6c to 5670235 Compare November 8, 2021 18:42
@atilaneves
Copy link
Contributor Author

The blocking issue has been fixed, so I see no reason to not merge this.

@dkorpel
Copy link
Contributor

dkorpel commented Nov 9, 2021

There's still this: https://issues.dlang.org/show_bug.cgi?id=22221

@Geod24
Copy link
Member

Geod24 commented Nov 9, 2021

Also commit message / PR title needs an update

@atilaneves
Copy link
Contributor Author

Also commit message / PR title needs an update

Do they?

@atilaneves
Copy link
Contributor Author

There's still this: https://issues.dlang.org/show_bug.cgi?id=22221

That's... not ideal. But I wouldn't consider it a blocker. Definitely needs to be fixed, though.

@Geod24
Copy link
Member

Geod24 commented Nov 9, 2021

Do they?

Ah, reading again, I see what you mean. I thought it was the original idea of "Print a deprecation message if the user isn't using DIP1000", not "Start deprecating constructs that would error with -preview=dip1000". So I guess not.

@dkorpel
Copy link
Contributor

dkorpel commented Nov 9, 2021

But I wouldn't consider it a blocker. Definitely needs to be fixed, though.

The dmd fix is easy (#12989), the hard part is not breaking Phobos (dlang/phobos#8214). It turns out that fixing scope errors in range code is really cumbersome. You can't explicitly mark every parameter scope since it's generic code, so you want to rely on inference. Without pure and nothrow, scope inference is really bad however (issue 20674), and the error messages don't help either: Instead of saying 'scope inference failed because of line X', functions just fail to be inferred @safe, resulting in e.g.:

std/array.d(1817): Error: @safe delegate std.array.split!string.split.__foreachbody5 cannot call @system function std.range.primitives.put!(Appender!(string[]), string).put

If you annotate put or doPut @safe, then it results in failing __traits(compiles, ) or is(typeof()) tests, giving unhelpful errors like:

std/range/primitives.d(430): Error: static assert: "Cannot put a const(char)[] into a void delegate(scope const(char)[])."

So what do I fear happens when this PR is merged? People upgrade to dmd 2.099 and are presented with a flood of inscrutable deprecation errors, lots of them based on false positives because of bad scope inference. They want to fix them, but after asking how to do that in the forums they receive the answer "nobody knows". That's why I want to get DIP1000 in a good, well-documented state before making it the default.

@atilaneves atilaneves force-pushed the dip1000-deprecation-msgs branch from fbb4685 to 33341ee Compare April 15, 2022 10:03
@atilaneves atilaneves requested a review from ibuclaw as a code owner April 15, 2022 11:19
@atilaneves
Copy link
Contributor Author

Woohoo, green!

@atilaneves
Copy link
Contributor Author

I addressed the latest review comments.

@dkorpel dkorpel added the Review:Needs Changelog A changelog entry needs to be added to /changelog label Apr 15, 2022

As an incentive to transition to -preview=dip1000 by default, now the
compiler prints what would have been error messages if the flag had
been on as deprecation messages. This new behaviour can be disabled
Copy link
Contributor

Choose a reason for hiding this comment

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

Only in explicit @safe functions, function with inference may still silently be @safe while having scope violations.

@dkorpel
Copy link
Contributor

dkorpel commented Apr 15, 2022

The bigger problem with the changelog entry is that it leaves users clueless: what is DIP1000? What does this mean for my code? Where can I find documentation?

There's no tutorial, and the spec is not up to date (dlang/dlang.org#3262 for one, but there's more). While I approve the PR for what is does, I would say it's "blocked" by the lack of documentation.

@dkorpel dkorpel added Merge:Blocked and removed Review:Needs Changelog A changelog entry needs to be added to /changelog labels Apr 15, 2022
@atilaneves atilaneves force-pushed the dip1000-deprecation-msgs branch from 5ec7ffb to 5dd5d5d Compare April 18, 2022 08:03
@atilaneves
Copy link
Contributor Author

I agree we need more documentation, but I don't think that this PR is the place to do it - I can't link to something outdated. What do you suggest to make the changelog entry better?

@atilaneves atilaneves force-pushed the dip1000-deprecation-msgs branch from 5dd5d5d to 8020446 Compare April 18, 2022 08:08
@dkorpel
Copy link
Contributor

dkorpel commented Apr 18, 2022

What do you suggest to make the changelog entry better?

I'm working on writing documentation for DIP1000. What we could do is already merge this, and then improve the changelog in a subsequent PR, since there is still time before the next release. This way you don't have to keep rebasing this PR in the meantime.

@atilaneves atilaneves added Merge:72h no objection -> merge The PR will be merged if there are no objections raised. and removed Merge:Blocked labels Apr 18, 2022
@atilaneves atilaneves merged commit 49d44fa into dlang:master Apr 21, 2022
@@ -0,0 +1,6 @@
Print warning messages unless -revert=dip1000 is used
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 the little detail of adding this option was overlooked? :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, unfortunately: #14019

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

Labels

dip1000 memory safety with scope, ref, return Merge:72h no objection -> merge The PR will be merged if there are no objections raised.

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants