Skip to content

Turn array.sort and array.reverse into errors.#6554

Closed
quickfur wants to merge 1 commit intodlang:masterfrom
quickfur:builtin-sort-error
Closed

Turn array.sort and array.reverse into errors.#6554
quickfur wants to merge 1 commit intodlang:masterfrom
quickfur:builtin-sort-error

Conversation

@quickfur
Copy link
Member

Continuing the deprecation process, as array.sort and array.reverse have been warnings / deprecations since before the C++ to D switchover in Aug 2015. It's high time we moved forward.

After the next release, this code can be removed altogether and we will no longer need to invoke array.sort() with the empty parentheses in order to get std.algorithm.sort.

@wilzbach
Copy link
Contributor

I think you need to update a couple of tests:

../src/dmd -conf= -m32 -Irunnable   -odgenerated/runnable -ofgenerated/runnable/test20_0 runnable/test20.d
runnable/test20.d(734): Error: use std.algorithm.reverse instead of .reverse property
runnable/test20.d(739): Error: use std.algorithm.reverse instead of .reverse property
runnable/test20.d(753): Error: use std.algorithm.reverse instead of .reverse property
runnable/test20.d(759): Error: use std.algorithm.reverse instead of .reverse property


==============================
Test failed: expected rc == 0, exited with rc == 1

@UplinkCoder
Copy link
Member

If we want go forward with this the tests have to be removed.
dmd tests shall not import phobos

@quickfur
Copy link
Member Author

Oops, forgot to run the tests before submitting the PR :D Will do that right now.

@quickfur
Copy link
Member Author

Hmm. I'm not sure it's a good idea to just remove these tests. Should they be moved to phobos instead?

@wilzbach
Copy link
Contributor

Hmm. I'm not sure it's a good idea to just remove these tests. Should they be moved to phobos instead?

Good idea! (assuming that Phobos reverse behaves equivalently in these cases )

@quickfur
Copy link
Member Author

Hmm. The dmd testsuite has stress tests that use .reverse. What should be done in this case? I can't move these to phobos since they're supposed to be stress testing the compiler.

@DmitryOlshansky
Copy link
Member

Hmm. The dmd testsuite has stress tests that use .reverse.

What is so special about reverse? It's just a call to runtime library, any other call should do.

@quickfur
Copy link
Member Author

The result of calling reverse is explicitly checked for.

@quickfur
Copy link
Member Author

@wilzbach I'd say it would be a bug if Phobos reverse didn't behave the same way.

@DmitryOlshansky
Copy link
Member

The result of calling reverse is explicitly checked for.

Then it doesn't check anything other then that reverse is callable as runtime function and it's result is such and such. What is compiler stress-test about it?

@quickfur
Copy link
Member Author

@DmitryOlshansky Honestly I've no idea. I'm just trying to get the testsuite to pass. :-D

@DmitryOlshansky
Copy link
Member

I'm just trying to get the testsuite to pass. :-D

The simplest way is to actually admit they are no longer applicable and delete them ;)

@quickfur
Copy link
Member Author

Haha, OK!

@quickfur
Copy link
Member Author

Whoa, that file (test/runnable/stress.d) has tons of copy-pasta. Is this dating from before D had templates or what?! With today's language this file could easily be condensed to 10% of its size!

@DmitryOlshansky
Copy link
Member

Is this dating from before D had templates or what?!

Given the simple name I'd expect it to be as old as early D1 so no templates totally expected. Another point is that you don't want to complicate matters with templates as these have to be tested in the compiler as well.

@quickfur
Copy link
Member Author

Bah... test/runnable/wc2.d is an entire program that depends on sort. Not sure why this is part of the dmd testsuite, and what's the point of testing this if we can't import Phobos?

@quickfur
Copy link
Member Author

(Though I suppose I could just take out the sort call and let the output be unsorted, but it sorta begs the question of what's the point of this test in the first place.)

@quickfur
Copy link
Member Author

Actually, test/runnable/test12.d blatantly imports std.algorithm. Maybe I should do that instead of deleting all these tests!

alias T3 = const ubyte[this.sizeof]; // ok <- error
}

/***************************************************/
Copy link
Member Author

Choose a reason for hiding this comment

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

I deleted this test instead of importing std.algorithm, because bug 13481 is specific to built-in attributes, and now that .sort is gone, the bug no longer applies.

@quickfur
Copy link
Member Author

OK, updated the test suite, mostly just by importing std.algorithm. I'm not sure where the idea came from that we're not allowed to use Phobos in the test suite; I've seen at least a handful of places that explicitly imports std.algorithm.

Isn't it only in the compiler code itself that we're refraining from importing Phobos? The test suite should be exempt, right?

@UplinkCoder
Copy link
Member

UplinkCoder commented Feb 21, 2017 via email

@quickfur
Copy link
Member Author

But what about the existing compiler tests that import Phobos?

@UplinkCoder
Copy link
Member

those should be reevaluated sometime.

assert(a.array[1] == 82);

foreach (uint u; &a.reverse)
foreach (uint u; &a.forward)
Copy link
Member Author

Choose a reason for hiding this comment

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

Changed this to forward instead of reverse, because it seems that the idea was to test the uint index type, but the result of the operation is ignored. Besides, Phobos reverse does not return the array, so it can't be substituted here.

@WalterBright
Copy link
Member

std.algorithm.sort and .reverse needs to be checked to see if the dmd tests are covered there. If so, delete the tests in dmd. If not, add the tests to the phobos unit tests, and delete them from dmd's tests.

@yebblies
Copy link
Contributor

But what about the existing compiler tests that import Phobos?

They should not be there, and their existence is not a reason to add more phobos imports.

@quickfur
Copy link
Member Author

Fair enough, I'll move the tests to phobos instead.

@wilzbach wilzbach added this to the 2.074.0 milestone Mar 4, 2017
arguments.push(e);
e = new CallExp(e.loc, ec, arguments);
e.type = next.arrayOf();
error(e.loc, "use std.algorithm.reverse instead of .reverse property");
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is a unique error message and not the generic "undefined identifier". Shouldn't there be a test for that, make sure it fails correctly?

Copy link
Member

Choose a reason for hiding this comment

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

Ideally all diagnostics should have a fail test, yes.

@MartinNowak MartinNowak removed this from the 2.074.0 milestone Mar 20, 2017
@@ -4542,103 +4542,23 @@ extern (C++) class TypeArray : TypeNext
}
if (ident == Id.reverse && (n.ty == Tchar || n.ty == Twchar))
Copy link
Member

Choose a reason for hiding this comment

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

Are these the only places where Id.reverse and Id.sort are used?

Perhaps add a comment to set a future date for error -> gone.

Copy link
Member

Choose a reason for hiding this comment

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

In fact, these first two branches can be removed, as the error is the same for both strings and arrays in this PR.

import std.algorithm : sort;

void test45()
{
Copy link
Member

Choose a reason for hiding this comment

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

Put these imports inside the function scope.

@ibuclaw
Copy link
Member

ibuclaw commented Apr 6, 2017

@quickfur, can you please rebase?

@andralex
Copy link
Member

@MartinNowak has the time for this come?

Copy link
Member

@andralex andralex left a comment

Choose a reason for hiding this comment

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

all involved, please let's take this home thx!

Continuing the deprecation process.  After the next release, this code
can be removed altogether and we will no longer need to invoke
array.sort() with parentheses in order to get std.algorithm.sort.
@quickfur
Copy link
Member Author

Would somebody like to take over this PR? I currently don't have enough time to sort through the various tests in the testsuite to update them. The compiler code itself is finished, but some of the tests need to be moved to Phobos, some need to be reevaluated, etc..

@quickfur quickfur force-pushed the builtin-sort-error branch from 205d4af to 1833371 Compare May 23, 2017 16:42
@quickfur
Copy link
Member Author

P.S. I rebased the code on the latest git HEAD so it should be easy for somebody to take over now.

@andralex
Copy link
Member

cc @somzzz got time?

@UplinkCoder
Copy link
Member

@andralex I can take this one :)

e = new CallExp(e.loc, ec, arguments);
e.type = next.arrayOf();
error(e.loc, "use std.algorithm.sort instead of .sort property");
goto Lerror;
Copy link
Member

Choose a reason for hiding this comment

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

These first two branches can be removed, as the error is the same for both strings and arrays in this PR.

@UplinkCoder
Copy link
Member

@andralex a few a tests are failing when we turn this into errors.
They showed deprecations warnings all the time but we never check for deprecations on successful tests.
If you want the expected behavior we have to remove the property checks.

@UplinkCoder
Copy link
Member

e.g. we just throw an error that the property was not found.

@ibuclaw
Copy link
Member

ibuclaw commented Jan 10, 2018

This was done in #6827

@ibuclaw ibuclaw closed this Jan 10, 2018
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.