Skip to content

Conversation

kennytm
Copy link
Contributor

@kennytm kennytm commented Jun 5, 2011

Changes:

  • std.utf.decode is changed from @trusted to pure @safe
  • std.utf.toUTF8, toUTF16 and toUTF32 are changed from @trusted to pure @trusted (they cannot be @safe because of assumeUnique.)
  • std.array.popFront, popBack, front and back are made pure 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 and back are made pure @safe for narrow strings.

std.utf.count is still impure due to use of walkLength.

@andralex
Copy link
Member

andralex commented Jun 6, 2011

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.

@jmdavis
Copy link
Member

jmdavis commented Jun 9, 2011

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.

@jmdavis
Copy link
Member

jmdavis commented Jun 9, 2011

@andrei

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.

@andralex
Copy link
Member

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?

@kennytm
Copy link
Contributor Author

kennytm commented Jun 15, 2011

@andralex: We could revert to use text once that is really implemented (just like staticLength...).

@jmdavis
Copy link
Member

jmdavis commented Jun 19, 2011

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.

@9il
Copy link
Member

9il commented Jun 19, 2011

Oo!
I am sorry, my English is bad.
(pure) function can not have (lazy) arguments. But why, If (lazy) arguments can be compile time determined as (pure) or they is other (pure) functions.

@9il
Copy link
Member

9il commented Jun 19, 2011

(pure) function can not have (lazy) arguments : in now time with dmd *

@kennytm
Copy link
Contributor Author

kennytm commented Jun 19, 2011

@9il: That's basically bug 5750. Perhaps @donc could make a pull request?

@9il
Copy link
Member

9il commented Jun 19, 2011

Thank you! I have missed that jmdavis has already noticed about.

@andralex
Copy link
Member

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!

@jmdavis
Copy link
Member

jmdavis commented Jun 21, 2011

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.

@jmdavis jmdavis closed this Jun 21, 2011
@kennytm
Copy link
Contributor Author

kennytm commented Jun 22, 2011

@andralex: OK. I'll re-pull once bug 5750 is fixed, or it could just be integrated to pull #101.

kuettler pushed a commit to kuettler/phobos that referenced this pull request Feb 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants