D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7115 - sort function is broken with large arrays
Summary: sort function is broken with large arrays
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: Other Linux
: P2 normal
Assignee: No Owner
URL:
Keywords: bootcamp
Depends on:
Blocks:
 
Reported: 2011-12-15 13:38 UTC by deadalnix
Modified: 2016-12-08 16:23 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description deadalnix 2011-12-15 13:38:40 UTC
See sample code :

module fail;

import std.algorithm;
import std.random;

void main() {
	Mt19937 gen;
	
	byte[] v;
	v.length = 65536 * 1024;
	
	foreach(ref byte t; v) {
		t = cast(byte) gen.front;
		gen.popFront;
	}
	
	v.sort;
	
	assert(isSorted(v));
}
Comment 1 timon.gehr 2011-12-15 13:52:00 UTC
This would be a great opportunity to finally deprecate that abomination.
Also, I think this only happens when the element type is byte?
Comment 2 deadalnix 2011-12-15 13:58:57 UTC
(In reply to comment #1)
> This would be a great opportunity to finally deprecate that abomination.
> Also, I think this only happens when the element type is byte?

I did put byte for performances reasons, but it is true that it works with int and short (I just checked). Anyway, not sure it will nto fail for bigger values.

BTW, phobos provide nice way to sort, so this feature is not really needed and can be deprecated.
Comment 3 Don 2011-12-16 03:51:42 UTC
Perhaps a duplicate of bug 2819?
(I think it may be overflowing the stack, and generating wrong results instead of segfaulting).
Comment 4 hsteoh 2015-06-30 23:39:35 UTC
Can no longer reproduce this bug on git HEAD. Tested on Linux/64. I'm guessing .sort has been replaced with the Phobos sort by now (IIRC)? If so, we should resolve this bug.
Comment 5 Andrei Alexandrescu 2016-10-15 01:28:09 UTC
Can a bootcamper look into this, thanks.
Comment 6 RazvanN 2016-11-30 09:37:11 UTC
I looked into it and it seems the built-in sort for arrays has been deprecated and the program won't compile on git HEAD (Linux/64). I don't know if there is a way to force the compilation to succeed even though deprecated functions are used, but using the phobos sort function completes the job gracefully.

As for bug 2819, it seems that the code which caused the error has been removed.
I suggest we close this Issue.