Issue 13054 - pure nothrow @safe std.algorithm.schwartzSort
Summary: pure nothrow @safe std.algorithm.schwartzSort
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-07-06 12:19 UTC by bearophile_hugs
Modified: 2024-12-01 16:21 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2014-07-06 12:19:22 UTC
In dmd 2.066beta1 this compiles and works correctly:

void main() pure nothrow @safe @nogc {
    import std.algorithm: sort;
    import std.math: abs;
    int[3] data = [-2, 1, 3];
    auto r = data[].sort!q{a.abs < b.abs};
}



But schwartzSort doesn't support each of those tags:


void main() pure nothrow @safe @nogc {
    import std.algorithm: schwartzSort;
    import std.math: abs;
    int[3] data = [-2, 1, 3];
    auto r = data[].schwartzSort!abs;
}


temp.d(5,20): Error: pure function 'D main' cannot call impure function 'std.algorithm.schwartzSort!(abs, "a < b", cast(SwapStrategy)0, int[]).schwartzSort'
temp.d(5,20): Error: safe function 'D main' cannot call system function 'std.algorithm.schwartzSort!(abs, "a < b", cast(SwapStrategy)0, int[]).schwartzSort'
temp.d(5,20): Error: @nogc function 'D main' cannot call non-@nogc function 'std.algorithm.schwartzSort!(abs, "a < b", cast(SwapStrategy)0, int[]).schwartzSort'
temp.d(5,20): Error: 'std.algorithm.schwartzSort!(abs, "a < b", cast(SwapStrategy)0, int[]).schwartzSort' is not nothrow
temp.d(1,6): Error: function 'D main' is nothrow yet may throw


A schwartzSort has to allocate the mapped items, so perhaps it can't be @nogc (unless you allocate them on the C heap), but I think it can support the other tags.
Comment 1 Walter Bright 2016-06-07 11:23:10 UTC
Partial fix: https://github.com/dlang/phobos/pull/4415
Comment 2 Walter Bright 2016-06-13 01:09:13 UTC
(In reply to Walter Bright from comment #1)
> Partial fix: https://github.com/dlang/phobos/pull/4415

Which was pulled, and the Schwartz is now @safe.
Comment 3 Stanislav Blinov 2021-12-08 18:54:42 UTC
Nowadays schwartzSort infers nothrow @safe and @nogc, but not pure as it seems to rely on its own "trustedMalloc" and "trustedFree" instead of core.memory.pure{Malloc,Free}.
Comment 4 Stanislav Blinov 2021-12-08 21:37:13 UTC
Another partial fix:

https://github.com/dlang/phobos/pull/8329

If GC.add/removeRange could be fake pure, then this enhancement would be fulfilled.
Comment 5 dlangBugzillaToGithub 2024-12-01 16:21:44 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/10068

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB