Skip to content
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

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

Merged
merged 2 commits into from
Jun 18, 2023

Conversation

dukc
Copy link
Contributor

@dukc dukc commented Jun 14, 2023

No description provided.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @dukc! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
23361 major std.uni.normalize should be pure

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + phobos#8763"

Comment on lines -8828 to -8839
// check example

// any encoding works
wstring greet = "Hello world";
// test with dstring
dstring greet = "Hello world";
assert(normalize(greet) is greet); // the same exact slice

// An example of a character with all 4 forms being different:
// Greek upsilon with acute and hook symbol (code point 0x03D3)
assert(normalize!NFC("ϓ") == "\u03D3");
assert(normalize!NFD("ϓ") == "\u03D2\u0301");
assert(normalize!NFKC("ϓ") == "\u038E");
assert(normalize!NFKD("ϓ") == "\u03A5\u0301");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed these while here because they are duplicating the documentation unittest for no reason.

changelog/normalization_pure.dd Outdated Show resolved Hide resolved
// 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.
(cast(void delegate() pure nothrow) {decomposed.assumeSafeAppend();})();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assumeSafeAppend is already nothrow so there's no need to also cast it to it.

Copy link
Contributor Author

@dukc dukc Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, but a cast needs to designate the new type as whole, including those attributes the original lambda had.

I could avoid this by using std.traits.SetFunctionAttributes instead but using it would be uglier IMO, besides being a needless dependency.

EDIT: I could also just leave the function throwing, since I didn't actually make normalize nothrow... but at least it's one step less for someone else.

// 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.
(cast(void delegate() pure nothrow) {decomposed.assumeSafeAppend();})();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(cast(void delegate() pure nothrow) {decomposed.assumeSafeAppend();})();
(cast(void delegate() pure) { decomposed.assumeSafeAppend(); })();

ccc.length = 0;
ccc.assumeSafeAppend();
(cast(void delegate() pure nothrow) {ccc.assumeSafeAppend();})();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

@dkorpel dkorpel merged commit 623a2af into dlang:master Jun 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants