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
safe pure nothrow sort and sum #2075
Conversation
Review? This is pretty trivial... |
@@ -9366,9 +9361,13 @@ unittest | |||
sort(array); | |||
assert(array == [ 1, 2, 3, 4 ]); | |||
// sort with a delegate | |||
bool myComp(int x, int y) { return x > y; } | |||
bool myComp(int x, int y) @safe pure nothrow { return x > y; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't these attributes already be getting inferred? If not, does this need to be marked with a bug number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it is not within a template, neither directly or indirectly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, woops, must have misread a changelog at some point. I just never noticed because I always mark mine explicitly anyways.
LGTM. Maybe the error handling code could be ported to nothrow quite neatly by using |
Maybe. But even then, we'd also need to tag on assumePure, assumeSafe and assume NOGC too. Not impossible, but it is a lot of code overhead for what is just a diagnostic. or, we could extend asserts to not be considered for inference? |
Auto-merge toggled on |
Perhaps I am doing something wrong, but this code doesn't compile to me, giving a "Error: 'std.algorithm.sort!("a < b", cast(SwapStrategy)0, int[]).sort' is not nothrow":
|
Are you correctly rebased? It's working for me. |
I have updated all the dmd/Phobos/druntime files with GIT, but I still see the nothrow problem. I don't know why. |
Please rebase again, it works fine locally with commits: DMD: dlang/dmd@c5ebee1 |
Now it compiles and I have found the cause of my error, I was compiling using the "-debug" switch. |
Hmm if it fails with |
I'll look into it. I'd argue the root issue though is that anything in debug should be marked nothrow, and silently caught, to concede for useability. It's already pure... https://issues.dlang.org/show_bug.cgi?id=8464 But in the meantime, yeah, there's an issue somewhere I'll look into. |
|
Since @9rnsr fixed 12542, it is now possible to have pure/nothrow/safe
sort
andsum
.sum
needed no work done, so I just went and made the marked unittests so as to cover the inference.sort
was a bit harder. I had to strip some formatting in error handling, so as to make the code nothrow (no big loss here I think). I also had to work a bit around 12410.I'm not sure
sort
is quite as safe/pure/nothrow as it could be for every type (I haven't done too much checks), but at the very least, it is for PODs inside arrays, with predicates. That's already pretty good.That's it.
@9rnsr: Do you know about https://issues.dlang.org/show_bug.cgi?id=12410 ?