-
-
Notifications
You must be signed in to change notification settings - Fork 743
Make some of std.utf and std.array functions pure @safe #80
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
Conversation
The std.array commit is fine. The std.utf commit replaces reuse with local workarounds. I think we should fix issues at the stem instead of addressing them in many places. |
We really need to add conditional attributes in general - not just purity. At minimum, should be possible to use @safe, @trusted, pure, and nothrow with templates in a manner that applies them either if a particular condition is true or if all of the functions used within that function have that attribute. I know that there's an enhancement request on it somewhere, but I can't find it at the moment. Regardless, until we have conditional attributes, a large portion of Phobos (and therefore a large portion of the D code in existance) cannot be pure, nothrow, @safe, or @trusted because templates frequently can't assume that all of the functons that they call are pure, nothrow, @safe, or @trusted. Conditional attributes and making deprecated have a message along with the ability to have soft deprecation for scheduling something for deprecation are the two biggest features that I'd like to see added to D at this point. They would both have a huge impact (particularly conditional attributes) to what we can do with Phobos. |
I have mixed feelings about the utf bit. We really do need to fix the language/compiler rather than duplicating stuff in order to get around the lack of conditional attributes, but without the utf commit, I don't think that the array commit works, because the utf functions get in the way of the array functions being @safe or pure for strings. So, it may be worth having the code duplication in std.utf for the moment just so that we can get the array improvements. But if that's not acceptable, then we may just have to throw the whole pull request out for now. |
We'll improve the language to detect purity for templates automatically. I don't know when, though. The question is whether we should pull this or not until then. Thoughts? |
@andralex: We could revert to use |
I'm a bit divided on this. With these changes, a lot more can be pure (particularly anything which uses arrays but not templated functions) - including a fair bit of std.string, I believe. But there's still a lot which couldn't be pure anyway, thanks to other template functions (even if they're just using arrays), so I don't know how much is really gained by it, and it is annoying to have that code duplication. And most of Phobos can't be pure until the more general problem is fixed anyway. So, I could see it going either way. There's no question though that there is code that these changes would allow to be pure which can't currently be pure. And that would be really nice. |
Oo! |
(pure) function can not have (lazy) arguments : in now time with dmd * |
Thank you! I have missed that jmdavis has already noticed about. |
The recent addition of pure deduction to D seems to supersede this pull request. Nevertheless, thanks for the work. All participants - please let me know if it's okay to close this without pulling, and retry achieving the same effects by using the language feature. Thanks! |
It's going to have to be revisted and reworked, so I see no reason to keep it around. If a new set of changes are required to get the appropriate result, then we can have a separate pull request for those. |
Add ddemangle to win32.mak.
Changes:
std.utf.decode
is changed from@trusted
topure @safe
std.utf.toUTF8
,toUTF16
andtoUTF32
are changed from@trusted
topure @trusted
(they cannot be@safe
because ofassumeUnique
.)std.array.popFront
,popBack
,front
andback
are madepure nothrow @safe
for normal arrays. In fact, I don't know why they aren't so in the first place.std.array.popFront
,popBack
,front
andback
are madepure @safe
for narrow strings.std.utf.count
is still impure due to use ofwalkLength
.