dlang / phobos

The standard library of the D programming language
https://dlang.org
Boost Software License 1.0
1.18k stars 703 forks source link

@nogc std.algorithm.all #10053

Open dlangBugzillaToGithub opened 10 years ago

dlangBugzillaToGithub commented 10 years ago

bearophile_hugs reported this on 2014-05-12T08:13:22Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=12736

CC List

Description

void main() @nogc {
    import std.ascii: isDigit;
    import std.algorithm: all;
    auto b = "12".all!isDigit;
}

DMD 2.066alpha gives:

temp.d(4,18): Error: @nogc function 'D main' cannot call non-@nogc function 'std.algorithm.all!(isDigit).all!string.all'
dlangBugzillaToGithub commented 7 years ago

razvan.nitu1305 commented on 2017-07-12T10:28:21Z

Why is this an issue? all calls find which is non-nogc. Closing as invalid
dlangBugzillaToGithub commented 7 years ago

jrdemail2000-dlang commented on 2017-07-12T17:39:07Z

Seems a legitimate enhancement request, and in line with the longer term goal of having Phobos be @nogc when possible. In this particular case, there doesn't appear to be any reason why the functionality implemented by std.algorithm.all cannot be @nogc. And, std.algorithm.find could be @nogc as well in this case.

Personally though, I would hesitate to write an enhancement request against each individual function in Phobos for every attribute, and instead have a larger placeholder ticket for larger blocks of Phobos, for example, a ticket for all of std.algorithm. The above is a policy question of course, but if done this way then this ticket could be closed as a duplicate of the larger ticket, rather than closing it as invalid.

As aside: std.algorithm.find is @nogc for certain argument types. Example:

@nogc @safe nothrow pure unittest
{
    import std.algorithm : find;
    import std.range : iota;

    assert(find(iota(1,5), 3) == iota(3,5));
}
dlangBugzillaToGithub commented 7 years ago

jrdemail2000-dlang commented on 2017-07-13T14:19:28Z

Valid enhancement request, so reopening. If closed, should have a justification indicating the mechanism expected to eventually achieve the enhancement, or an explanation of why it the request is invalid at the API level.
dlangBugzillaToGithub commented 6 years ago

greensunny12 commented on 2018-02-09T12:15:54Z

the problem here is auto-decoding and that it can throw an exception,
The following works as expected:

---
void main() @nogc {
    import std.ascii: isDigit;
    import std.algorithm: all;
    import std.utf : byCodeUnit;
    auto b = "12".byCodeUnit.all!isDigit;
}
---

It has long being proposed to disable auto-decoding by introducing an RCString. I'm not sure whether this should be kept open, because the issue is not on `all`'s side - all it does is calling `popFront` of string - which happens to be @nogc (due to throwing UTF Exceptions).