Skip to content

Conversation

@carblue
Copy link
Contributor

@carblue carblue commented Feb 1, 2018

…preparation for -dip1000, issues #17961, #18110.

Changes apply to function signatures only and are trivial except referring to return attribute: Seems to be undocumented in DIP25/DIP1000, similar to https://dlang.org/spec/function.html#return-ref-parameters;
It's what template inference does for opSlice: "return attribute ensures the returned object will not outlive the Grapheme instance".
Without return, there are "-dip1000 errors" like this one: returning sliceOverIndexed(a, b, &this) escapes a reference to parameter this, perhaps annotate with return.

…sted by @safe; preparation for -dip1000, issues #17961, #18110
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @carblue! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.

Some tips to help speed things up:

  • smaller, focused PRs are easier to review than big ones

  • try not to mix up refactoring or style changes with bug fixes or feature enhancements

  • provide helpful commit messages explaining the rationale behind each change

Bear in mind that large or tricky changes may require multiple rounds of review and revision.

Please see CONTRIBUTING.md for more information.

Bugzilla references

Auto-close Bugzilla Description
17961 std.uni does not compile with -unittest -dip1000
18110 most of phobos should be @Safe-ly useable

Copy link
Contributor

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

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

I would suggest to cleanup the code to use stdx.allocator instead of slapping ugly @trusted over it.

dchar opIndex(size_t index) const pure nothrow @nogc @trusted
{
assert(index < length);
return read24(isBig ? ptr_ : small_.ptr, index);
Copy link
Contributor

Choose a reason for hiding this comment

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

While it doesn't help here, are you aware of https://dlang.org/changelog/pending.html#ptr-safe-end-of-deprecation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep!

ref opOpAssign(string op)(dchar ch) @trusted
{
static if (op == "~")
{
Copy link
Contributor

Choose a reason for hiding this comment

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

It we can use stdx.checked in general - it's just not @safe by default atm, but there's #5928

}

this(this) pure @nogc nothrow
this(this) pure @nogc nothrow @trusted
Copy link
Contributor

Choose a reason for hiding this comment

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

This should use stdx.allocator.makeArray - it's @safe

import std.experimental.allocator.mallocator : Mallocator;
import std.experimental.allocator : makeArray;

auto p = Mallocator.instance.makeArray!ubyte(20);

https://run.dlang.io/is/iZGDzT

Copy link
Member

Choose a reason for hiding this comment

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

Can't use it here because it's not pure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use PR #6041 instead (this PR is included there and should be closed but isn't yet).
When I inject behind } on line 7579
pragma(msg, "std.uni.d:Grapheme.this(this):", LINE, " ", typeof(&Grapheme.__postblit));
the compiler emits: std.uni.d:Grapheme.this(this):7579 void function() pure nothrow @nogc @trusted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pragma(msg, "std.uni.d:Grapheme.this(this):", __LINE__, " ", typeof(&Grapheme.__postblit));

~this() pure @nogc nothrow
~this() pure @nogc nothrow @trusted
{
import core.memory : pureFree;
Copy link
Contributor

Choose a reason for hiding this comment

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

Go with dispose, instead:

import std.experimental.allocator.mallocator : Mallocator;
import std.experimental.allocator : makeArray, dispose;
alias alloc = Mallocator.instance;
auto p = alloc.makeArray!ubyte(20);
alloc.dispose(p);

https://run.dlang.io/is/t2IMq2

but it needs to be fixed first (https://issues.dlang.org/show_bug.cgi?id=18347)

}

void convertToBig() pure @nogc nothrow
void convertToBig() pure @nogc nothrow @trusted
Copy link
Contributor

Choose a reason for hiding this comment

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

stdx.allocator to the help!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for Your review and helpful hints!
Currently I won't touch function bodies and be focussed on function/struct signatures for -dip1000 compliance.
@wilzbach Please close this PR, it will be integrated in an update for PR #6041 as there are overlaps.

@carblue carblue closed this Feb 6, 2018
@carblue carblue deleted the std_uni_struct_grapheme branch February 6, 2018 11:22
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