Thread overview
[Issue 23361] std.uni.normalize should be pure
Oct 30, 2022
Imperatorn
Oct 30, 2022
Imperatorn
Dec 17, 2022
Iain Buclaw
Jun 14, 2023
Dlang Bot
Jun 14, 2023
Ate Eskola
Jun 18, 2023
Dlang Bot
October 30, 2022
https://issues.dlang.org/show_bug.cgi?id=23361

Imperatorn <johan_forsberg_86@hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |johan_forsberg_86@hotmail.c
                   |                            |om

--- Comment #1 from Imperatorn <johan_forsberg_86@hotmail.com> ---
I took a look at this.

If you mark the following as pure:
normalize
decompose
decomposeHangul

Then there's only this that needs to be pure (in normalize)

() @trusted {
    decomposed.assumeSafeAppend();
    ccc.length = 0;
    ccc.assumeSafeAppend();
} ();

To cheat and not make the appenders pure but the block pure we can just add pure:

() @trusted pure {
    decomposed.assumeSafeAppend();
    ccc.length = 0;
    ccc.assumeSafeAppend();
} ();

But, we still need some way there to allow calling the impure append from the pure block.

Maybe we could cast some function pointer to pure, I don't know.

I tested wrapping it in a debug block and that makes it work, but I'm not sure what the "real" solution would look like.

() @trusted pure {
    debug {
        decomposed.assumeSafeAppend();
        ccc.length = 0;
        ccc.assumeSafeAppend();
    }
} ();

--
October 30, 2022
https://issues.dlang.org/show_bug.cgi?id=23361

--- Comment #2 from Imperatorn <johan_forsberg_86@hotmail.com> ---
One way I guess is to cast the function to pure.
The other is to actually mark _d_arrayshrinkfit as pure.

Which of those seems most reasonable?

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=23361

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P2

--
June 14, 2023
https://issues.dlang.org/show_bug.cgi?id=23361

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #3 from Dlang Bot <dlang-bot@dlang.rocks> ---
@dukc created dlang/phobos pull request #8763 "fix issue 23361 - std.uni.normalize made pure" fixing this issue:

- fix issue 23361 - std.uni.normalize made pure

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

--
June 14, 2023
https://issues.dlang.org/show_bug.cgi?id=23361

--- Comment #4 from Ate Eskola <Ajieskola@gmail.com> ---
Oh, it seems I have missed your comment - I just figured all this out myself creating a fix for this when I could just have read your message.

I solved the assumeSafeAppend thing by marking the calls pure.

(But with a cast - does simply marking the lambda pure really work? I thought even `@trusted` code lets to treat impure calls as pure only with an explicit cast.)

I think it's okay because... well let me copy my comment from the code as explaination:

---
// assumeSafeAppend isn't considered pure as of writing, hence the
// cast. It isn't pure in the sense that the elements after
// the array in question are affected, but we don't use those
// making the call pure for our purposes.
---

--
June 18, 2023
https://issues.dlang.org/show_bug.cgi?id=23361

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/phobos pull request #8763 "fix issue 23361 - std.uni.normalize made pure" was merged into master:

- e6ed40182187ea4f3caf1127102136f9aa5fd0ac by Ate Eskola:
  fix issue 23361 - std.uni.normalize made pure

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

--