-
-
Notifications
You must be signed in to change notification settings - Fork 706
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
Make assumeUTF nothrow #7337
Make assumeUTF nothrow #7337
Conversation
|
Thanks for your pull request and interest in making D better, @berni44! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
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 referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + phobos#7337" |
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.
I dont think removing these checks is the best approach to resolve this issue. A better ffix would be to make validate @nogc which would provide additional value.
EDIT: Why does this function even throw an UTFException instead of using assert like e.g. assumeWontThrow as passing non-UTF strings should be considered an programming error?
EDIT 2: Then assumeUTF would be @nogc and nothrow and still ensure correct assumptions
|
But, the behaviour in debug mode would still differ from the behaviour in normal mode, which, at least in my oppinion, is still a bug. IMHO it should be the user who decides, what should be debugged and what not, not the designer of a library. If the user wants to make sure, that the return value from assertUTF is valid, he can add a |
|
Another reason why this should be checked along the lines of If thats not desired then he can use a simple cast .... |
|
Anyway, the real culprit for the missmatched attributes is a dmd bug which infers not- |
|
Not sure, how to continue. Can we decide on debug in Phobos or in/out or not here, or should we ask that in that forum? IMHO it's a broader question... What do you think? |
|
Not entirely sure about this either but I think it might be favourable to split this problem in its independent parts -
I wouldn't exptect the forum post to reach a consenus but considering other views on this topic won't be detrimental either. PS: Removing these checks also makes it questionable whether |
|
I changed the PR to throw an error in case of an invalid UTF provided. This still uses I'm aware, that this change is the opposite of the desired one: Now it's never |
There is already #4012 to introduce
Then lets keep it behind Otherwise we could resort to |
std/string.d
Outdated
| auto asUTF = cast(ModifyTypePreservingTQ!(ToUTFType, T)[])arr; | ||
| debug validate(asUTF); | ||
| auto asUTF = cast(ModifyTypePreservingTQ!(ToUTFType, T)[]) arr; | ||
| assumeWontThrow(validate(asUTF)); |
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.
assumeWontThrow produces the following message (which hides the real issue):
assumeWontThrow failed: Expression did throw
The assert should probably contain the exceptions message:
| assumeWontThrow(validate(asUTF)); | |
| scope ex = collectException!UTFException(validate(asUTF)); | |
| assert(!ex, ex.msg); |
Not sure, if I got that right: You want me to not add |
No, keep the call to |
I started to implement this this morning, but realised, that I do not commit to this PR anymore. It's neither closing an issue nor removing a |
This changes fixes the original issue that
Do however you like, |
No, that's not the original issue. It complains about Anyway I changed the PR now to address the throwing stuff. |
|
The issue title refers to attributes in general, the description just mentions But lets not waste time bikeshedding, I think this PR is a good change for the better. |
|
|
||
| debug | ||
| { | ||
| scope ex = collectException(validate(asUTF)); |
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.
On a side note, it would be great to have a version of validate that calls a user-provided routine on invalid UTF, instead of throwing. It'd be useful here, and it'd be useful in places where performance is important (e.g. Vibe.d HTTP handling).
I subscribe to the view of the author of the bug (and the people in the corresponding forum thread) that
debugshould not be used inside Phobos.I also sligthly changed the example unittest as the current output
writeln(a) // cis somewhat confusing.