-
-
Notifications
You must be signed in to change notification settings - Fork 606
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
dmd.root.array: Add sort
method, wrapping qsort
#10896
Conversation
Thanks for your pull request, @Geod24! Bugzilla referencesYour 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 locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#10896" |
|
060fb7e
to
bfca2ce
Compare
|
assert(dstrcmp("Baguette", "Croissant") == -1); | ||
assert(dstrcmp("Croissant", "Baguette") == 1); | ||
|
||
static assert(dstrcmp("Baguette", "Croissant") == -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You just couldn't help yourself? :-)
While not used yet, it is useful as a predicate for 'Array(T).sort', and will be used by the ABI tags feature. It has been directly copied from druntime, with added tests.
dba480d
to
0f299c9
Compare
src/dmd/root/array.d
Outdated
int a; | ||
} | ||
|
||
Array!OtherStruct arr2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh dscanner complains about unused variable here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm maybe use
static assert (!is(typeof((){Array!OtherStruct arr2; arr2.sort()}();)));
``
We already have find, but no sort. This can potentially hidden behind a static if for types that don't support it (e.g. types with elaborate move semantics), but we don't have any in arrays ATM.
Satisfied the style checker. |
return this; | ||
} | ||
|
||
static if (is(typeof(this.data[0].opCmp(this.data[1])) : int)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would appear that this line triggers a silent forward reference bug when compiling frontend modules separately. The early forced semantic of typeof(this.data[0])
(a ClassDeclaration when compiling mtype.d) messes up the vtable calculation, and the offset is wrong (when calling isBaseOf).
This happens in at least the dmd-cxx implementation, a suitable reduction and testing 2.066 will need to be done as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reduced, any compiler older than 2.085.1 runs the risk of producing a corrupted compiler if you are using incremental/one module at a time compilation strategy (2.085.0 is the last broken release).
FYI @kinke, or ping any other LDC devs so you don't repeat the time I spent looking at this issue. I've already committed a fix to dmd-cxx branch, see the cross-referenced merged PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ibuclaw :
Could you check if using a template constraint would work around the problem ? And if not, we can move the static assert
in the body.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think template constraints would work just fine. The reduced test I added reports the correct offset at least...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, on further testing even if we fix the problematic static if, you cannot actually use this function anyway, as it relies on dual-context pointers, which is neither implemented in gdc nor ldc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see where it does ? Let's move the discussion to #10930 though.
This makes it way more user-friendly to work with.
Unfortunately I cannot use it in the backend because it is using
-betterC
.Will be useful when implementing GNU ABI Tags too.