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

Fix Issue 9433 - Deprecate delete #7342

Merged
merged 1 commit into from Feb 12, 2018
Merged

Fix Issue 9433 - Deprecate delete #7342

merged 1 commit into from Feb 12, 2018

Conversation

JinShil
Copy link
Contributor

@JinShil JinShil commented Nov 21, 2017

See:
https://dlang.org/deprecate.html
https://dlang.org/deprecate.html#delete
http://forum.dlang.org/post/jzldqlkxgewtxjyffekb@forum.dlang.org
http://forum.dlang.org/post/gqgnquwhmykvpafwpemr@forum.dlang.org

Spec and Documentation Update: dlang/dlang.org#1941.

There are only 5 lines of code change in this PR, and 4 of them are comments. The rest are mostly line number changes for the test suite, as many of the tests now emit a deprecation warning in addition to their other output.

@dlang-bot
Copy link
Contributor

dlang-bot commented Nov 21, 2017

Thanks for your pull request, @JinShil!

Bugzilla references

Auto-close Bugzilla Severity Description
9433 normal Deprecate delete

@JinShil JinShil added the WIP Work In Progress - not ready for review or pulling label Nov 21, 2017
@rracariu
Copy link

delete is still required for cases like https://issues.dlang.org/show_bug.cgi?id=17230

@JinShil JinShil removed the WIP Work In Progress - not ready for review or pulling label Nov 21, 2017
@JinShil
Copy link
Contributor Author

JinShil commented Nov 25, 2017

delete is still required for cases like https://issues.dlang.org/show_bug.cgi?id=17230

That is due to a separate bug: https://issues.dlang.org/show_bug.cgi?id=17267. Once that bug is fixed, you should be able to use destroy.

Copy link
Member

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

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

While it was planned for 2.072, there's a real chance we might see this deprecation for 2.078 🎉

src/ddmd/parse.d Outdated
@@ -7770,6 +7770,10 @@ final class Parser(AST) : Lexer
case TOKdelete:
nextToken();
e = parseUnaryExp();
// 1. Deprecation for 1 year
// 2. Error for 1 year
// 3. Removal, "delete" can be used for other identities
Copy link
Member

Choose a reason for hiding this comment

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

How about using a similar deprecated pattern as in Phobos?

// @@@DEPRECATED_2017-12@@@

In any case, it would be good to start using easily greppable years into the source code, s.t. these deprecations don't get forgotten.

Copy link
Contributor Author

@JinShil JinShil Dec 5, 2017

Choose a reason for hiding this comment

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

// @@@DEPRECATED_2017-12@@@

How can I be sure that this will be merged this month? Maybe just add @@@DEPRECATED@@@

Copy link
Member

Choose a reason for hiding this comment

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

The trick is to annoy @andralex and @WalterBright daily ;-)
Okay all jokes aside, at Phobos these deprecation strings are put in a PR and this has never been a huge problem as at least for Phobos deprecation PRs are merged rather quickly. Yep, there have been cases in which a PR has been merged later, but it hasn't been a big deal whether a deprecation lasted for 23 or 24 months. On the contrary (1) with Martin's polished release two months release cycle, it's still 9 or 10 releases (compared to 3-4 releases two or three years ago) and people are now complaining that the deprecation periods are too long. And secondly (2) the obvious advantage is that someone will actually switch the deprecation to an error.
Anyhow, the deprecation cycle is rather ill-defined as of now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I added @@@DEPRECATED_2017-12@@@.

@wilzbach
Copy link
Member

wilzbach commented Dec 5, 2017

Btw could you also send a respective PR to dlang.org, s.t. the update of the deprecation page doesn't get lost? (Unfortunately this tends to happen too often).

@JinShil
Copy link
Contributor Author

JinShil commented Dec 5, 2017

Btw could you also send a respective PR to dlang.org, s.t. the update of the deprecation page doesn't get lost?

I would be happy to, but I need to know what version I can expect this PR to land in.
dlang/dlang.org#1941 Betting on 2.078

@JinShil
Copy link
Contributor Author

JinShil commented Dec 12, 2017

@WalterBright and @andralex Can I please get a ruling on this? I think time is running out for the 2.078.0 release.

@wilzbach
Copy link
Member

@WalterBright and @andralex Can I please get a ruling on this? I think time is running out for the 2.078.0 release.

I had a short chat with @andralex about this last week and the only thing he was worried about was that no drop-in replacement for delete exists.

However, after looking at it for a bit, I don't see any reason why people if destroy and GC.free doesn't work for them, couldn't use _d_delclass directly:

extern (C) void _d_delclass(Object* p);

void main() {
    class B { int a; }
    B b = new B();
    b.a = 10;

    import std.stdio;
    b.writeln; // test.main.B
    _d_delclass(cast(Object*) &b);
    b.writeln; // null
}

@JinShil
Copy link
Contributor Author

JinShil commented Dec 12, 2017

I had a short chat with @andralex about this last week and the only thing he was worried about was that no drop-in replacement for delete exists.

Why does a drop-in replacement need to exist if it's deprecated?

However, after looking at it for a bit, I don't see any reason why people if destroy and GC.free doesn't work for them, couldn't use _d_delclass directly:

Clever! 👍

@andralex
Copy link
Member

Why does a drop-in replacement need to exist if it's deprecated?

The idea here is purely operational - someone who has a codebase using delete on their hands needs a quick way to upgrade the compiler whilst keeping the code unchanged. So we need to have a simple recipe "for legacy code using delete e; please replace with xxx(e);.

src/ddmd/parse.d Outdated
// 1. Deprecation for 1 year
// 2. Error for 1 year
// 3. Removal, "delete" can be used for other identities
deprecation("The `delete` keyword has been deprecated. Use `object.destroy()` instead.");
Copy link
Member

Choose a reason for hiding this comment

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

destroy is not a pound-for-pound replacement for delete.


See the $(LINK2 $(ROOT_DIR)deprecate.html#delete, Deprecated Features) for more information.

Starting with this release, using the `delete` keyword will result in a deprecation warning. The warning is scheduled to remain for 1 year, after which it will be changed to an error. The error is then to remain for 1 year, after which `delete` will be removed as a keyword.
Copy link
Member

Choose a reason for hiding this comment

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

The changelog should specify the replacement function.

@andralex
Copy link
Member

@wilzbach _d_delclass would be suitable. It's not an easy replacement, but probably we don't want to make it too easy.

@JinShil
Copy link
Contributor Author

JinShil commented Dec 12, 2017

So we need to have a simple recipe "for legacy code using delete e; please replace with xxx(e);.

How long would such a recipe need to be maintained? I understand the value of having such a recipe to make for smoother transition, but don't we eventually want to usher users away from such things and encourage them to refactor their code so they can make use of destroy?

I'll do the legwork, but I need to a more concrete roadmap.

@andralex
Copy link
Member

How long would such a recipe need to be maintained? I understand the value of having such a recipe to make for smoother transition, but don't we eventually want to usher users away from such things and encourage them to refactor their code so they can make use of destroy?

There's no significant burden to having a function in the standard library that does what delete does. It will be marked as unsafe and documented as such.

@andralex
Copy link
Member

@JinShil just spoke to @wilzbach, he'll write the function. Thanks to both!

@JinShil
Copy link
Contributor Author

JinShil commented Dec 13, 2017

just spoke to @wilzbach, he'll write the function.

Ok. Thanks. What's our recommendation to users, then? "Prefer object.destroy(), but if that's not suitable, resort to the {insert function name} library function"?

@andralex
Copy link
Member

@JinShil yes, something along these lines.

@JinShil
Copy link
Contributor Author

JinShil commented Dec 13, 2017

@wilzbach I'll make changes as soon as I know what function to direct users to.

@JinShil
Copy link
Contributor Author

JinShil commented Dec 28, 2017

just spoke to @wilzbach, he'll write the function.

@wilzbach, is this statement true?

@wilzbach
Copy link
Member

wilzbach commented Dec 29, 2017

@wilzbach, is this statement true?

Yes. I'm sorry that you missed 2.078 :/
I will get to it ASAP.

@MartinNowak MartinNowak removed this from the 2.078.0 milestone Dec 29, 2017
@wilzbach
Copy link
Member

Yes. I'm sorry that you missed 2.078 :/
I will get to it ASAP.

Finally managed to get to it:

dlang/druntime#2037

Sorry for the long delay

@JinShil
Copy link
Contributor Author

JinShil commented Feb 8, 2018

This is ready for additional scrutiny and potential merge, now that dlang/druntime#2037 is in.

warning is scheduled to remain for 1 year, after which it will be changed to an error. The
error is then to remain for 1 year, after which `delete` will be removed as a keyword.

As a replacement, users are encouraged to use $(LINK2 $(ROOT_DIR)phobos/object.html#.destroy),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be phobos in the link?

@JinShil JinShil added this to the 2.079.0 milestone Feb 8, 2018
@JinShil
Copy link
Contributor Author

JinShil commented Feb 8, 2018

The links to object.destroy and core.memory.__delete don't resolve. __delete doesn't even seem to be in the docs I could use some help on that.

Copy link
Member

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

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

FYI: there are plans to use scheduled versions instead of scheduled date. The upcoming DIP also mentions a few other things - I am not saying that you need to apply them hear, but I think it doesn't hurt to have a look at what could be the mandatory soon.


Starting with this release, using the `delete` keyword will result in a deprecation warning. The
warning is scheduled to remain for 1 year, after which it will be changed to an error. The
error is then to remain for 1 year, after which `delete` will be removed as a keyword.
Copy link
Member

Choose a reason for hiding this comment

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

Are you aware of Jack's new deprecation DIP?
dlang/DIPs#108
One of the things that are on the list is instead of having a fixed date, a fixed version is better for users because it's important which version will stop supporting it (there might be a few delay of publishing a version, e.g. LDC or distros in general)

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, I've seen the DIP, but it needs to go through a review and approval process which I think will take time. Given the the fact that we don't have a well-defined deprecation process, I made something up, and that's what you see here. Feel free to suggest an alternative wording, or maybe I should just omit the schedule altogether so we don't have to commit to anything. I don't have an opinion either way.

Copy link
Member

@wilzbach wilzbach Feb 8, 2018

Choose a reason for hiding this comment

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

Yes, please omit the schedule from the changelog.
In my experience, we most likely won't stick to it anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@wilzbach
Copy link
Member

wilzbach commented Feb 8, 2018

Nothing to worry about - __delete hasn't been released yet and is only visible on the preview pages: http://dtest.dlang.io/artifact/website-f9fb5f80bc0b4127acd5d08058b245ed9a9cabb3-677d592a5d032c630664b91a89c8a0af/web/phobos-prerelease/core_memory.html#.__delete

@JinShil
Copy link
Contributor Author

JinShil commented Feb 8, 2018

Nothing to worry about - __delete hasn't been released yet and is only visible on the preview pages:

What about object.destroy? That gives me a 404. Will that be resolved at publication time too?

@wilzbach
Copy link
Member

wilzbach commented Feb 8, 2018

From https://github.com/dlang/dlang.org/blob/master/dlang.org.ddoc#L353

The REF1 variants work around DDoc limitations and allow linking to
modules not inside packages (i.e. object.)

Argh...

-> $(REF1 destroy, object) works. I will update DRuntime and Phobos too. Good catch!

@wilzbach wilzbach closed this Feb 8, 2018
@wilzbach wilzbach reopened this Feb 8, 2018
wilzbach added a commit to wilzbach/dlang.org that referenced this pull request Feb 8, 2018
REF1 is currently only used once in entire DRuntime and Phobos, so maybe
a special OBJECTREF macro would have been better?
Anyhow, have a look at the only use of `REF1` to understand the
motivation for this PR:

https://dlang.org/phobos/std_file.html#.thisExePath

Also there are three other PRs being blocked on this:

- dlang/dmd#7342
- dlang/druntime#2082
- dlang/phobos#6140
Copy link
Member

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

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

Looks all good to me. Thanks for pushing this!

@wilzbach wilzbach added the 72h no objection -> merge The PR will be merged if there are no objections raised. label Feb 8, 2018
@wilzbach wilzbach dismissed andralex’s stale review February 12, 2018 21:33

__delete has been added

@dlang-bot dlang-bot merged commit 11daae8 into dlang:master Feb 12, 2018
@JinShil JinShil mentioned this pull request Feb 14, 2018
@JinShil JinShil deleted the deprecate_delete branch May 28, 2018 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
72h no objection -> merge The PR will be merged if there are no objections raised. auto-merge Bug Fix Easy Review
Projects
None yet
7 participants