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

Work On Issue 18172 - add scope to pointers in getopt to allow @safe #6281

Closed
wants to merge 1 commit into from

Conversation

JackStouffer
Copy link
Member

No description provided.

@JackStouffer JackStouffer requested a review from andralex as a code owner March 15, 2018 18:14
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @JackStouffer!

Bugzilla references

Auto-close Bugzilla Severity Description
18172 enhancement std.getopt should allow taking parameters by ref (like std.format.formattedRead), s.t. it can be used in @safe

@JackStouffer JackStouffer changed the title Work On Issue 18172 - add scope to pointers to allow @safe Work On Issue 18172 - in getopt add scope to pointers to allow @safe Mar 15, 2018
@@ -459,6 +459,19 @@ GetoptResult getopt(T...)(ref string[] args, T opts)
}
}

version(DIP1000)
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure how we want to handle DIP1000 regressions, but we need a way to ensure things stay @safe

Copy link
Member

Choose a reason for hiding this comment

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

By #6278 and thus gradually enabling -dip1000?

Copy link
Member Author

Choose a reason for hiding this comment

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

But this unittest needs to be annotated with @safe when -dip1000 is passed and @system when it's not to prevent any DIP1000 regressions. #6278 Doesn't have a mechanism for that.

Copy link
Member

Choose a reason for hiding this comment

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

Argh fair enough - there still might be issues as long as -deps compiles all unittests of its dependencies :/
Anyhow, for the time being #6278 (or similar could set DIP1000 by hand).

std/getopt.d Outdated
{
// allocate a new string so as to remove the
// scope restriction
string option = "" ~ opts[0];
Copy link
Member Author

Choose a reason for hiding this comment

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

this is due to the fact that to!(string)(string) acts as a pass through.

Copy link
Member

Choose a reason for hiding this comment

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

.idup?

@JackStouffer JackStouffer changed the title Work On Issue 18172 - in getopt add scope to pointers to allow @safe Work On Issue 18172 - add scope to pointers in getopt to allow @safe Mar 15, 2018
static if (is(typeof(opts[0]) == string))
{
// allocate a new string so as to remove the
// scope restriction
Copy link
Member

Choose a reason for hiding this comment

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

That really sucks. Safety shouldn't result in a performance overhead :/
Especially because in this case

  • getoptImpl doesn't store anything, but modifies configuration and rslt
  • it's a GC allocated string

@wilzbach
Copy link
Member

wilzbach commented Mar 22, 2018

Here's an idea how to programmatically detect -dip1000:

void main()
{
    enum isDIP1000 = __traits(compiles, () @safe {
         int x;
         int* p;
         p = &x;
    });
    pragma(msg, isDIP1000);
}

normal: https://run.dlang.io/is/RID7vh
-dip1000: https://run.dlang.io/is/1yJfVQ

Of course that could be fancier.

(based on the recent forum thread: https://forum.dlang.org/post/ayemvxctmpqqsokbmqeb@forum.dlang.org)

@JackStouffer
Copy link
Member Author

If people want to tackle the DIP1000 returning a struct issue, I'd be glad to see their solution. Until then, I'm closing this as this isn't going to go anywhere.

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