-
-
Notifications
You must be signed in to change notification settings - Fork 731
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
Eliminate redundant allocation in to!string for types with toString #10664
base: master
Are you sure you want to change the base?
Conversation
Thanks for your pull request and interest in making D better, @deveshidwivedi! 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 references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#10664" |
Please note that the commit message is wrong. This is not Bugzilla issue no.10560, but issue #10560 here on GitHub. |
Please add a unittest similar to the assertion outlined in the bug report. |
Sorry for the confusion, I'll update it |
…or structs with toString
Looks like we need to test whether the return type of |
I'll test this and update as needed |
This is the test that's failing in Looks like the problem is that we're attempting to call To fix it, if |
I made three key changes to address the failing test cases:
the failing test cases:
Please let me know if any of my changes have issues or could be improved. |
Current failing test is here: https://github.com/dlang-community/libdparse/blob/master/src/dparse/lexer.d#L2856 I'll be honest, this one is complex enough that it's not obvious to me what the problem is. |
I'm reluctant to approve this for three reasons:
|
As I suspected, there are several cases where this PR does not preserve the behavior of the original implementation, and would introduce regressions. The current implementation relies on In order to avoid regressions, any new code we introduce for calling For structs, this is not terribly difficult, but for classes, it would require a large amount of code duplication. So for now, it may be a better idea to limit this fix to structs, and leave classes the way they are. |
Thank you @pbackus, updated to align with |
Co-authored-by: Paul Backus <snarwin@gmail.com>
Co-authored-by: Paul Backus <snarwin@gmail.com>
Edited to fix a mistake in one of my suggestions (missing |
Failure is an |
The test failure appears to have been introduced in dlang/dmd#21010. |
That PR only touches dead code (the |
Well, the test itself was introduced in commit dlang/dmd@4261907, and the earliest instance I could find of that test failing was in the linked PR, which was merged as commit dlang/dmd@0312e82. So either the test itself has been (nondeterministically) broken since its introduction, or the failure was introduced in some commit between those two. Looking through |
The failure is nondeterministic, since several PRs have been green since then. I also only see it on Windows x64 with LDC 1.40 as host compiler. That suggests it's more than a simple logic bug in dmd, but something much more devious like undefined behavior. |
This PR fixes the issue where
to!string
creates an unnecessary allocation when used on types that already have atoString()
method. By adding a specialized implementation for these types, we directly use the string returned bytoString()
instead of creating a new allocation. This improves performance and reduces memory usage in common type conversion scenarios.