semantic: avoid runtime _d_arraysetlength call when .length = 0#11912
semantic: avoid runtime _d_arraysetlength call when .length = 0#11912dlang-bot merged 2 commits intodlang:masterfrom
Conversation
|
Thanks for your pull request and interest in making D better, @ljmf00! 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 run digger -- build "master + dmd#11912" |
|
tests? |
The behavior of I'm new to dmd compiler contributions, so, if there's any way to test the behavior of semantic analysis phase, could you guide me, if possible? |
|
That test that the behaviour has not changed, not that the implementation is different. You probably want a codegen test here, but those are not very nice to write. @UplinkCoder , @rainers , anyone else, any better ideas? |
How about verifying the output of compilation with -vcg-ast? |
|
Isn't this what |
I done a test case for that using |
|
Maybe I'm missing something obvious, but the testcase runs locally with success. |
aabb2bc to
597dc5a
Compare
|
I solved the issue, the test case was malformed because it was testing only 64bit literals. |
|
| # Test if a slice expr is applied for the above case | ||
| grep "arr = arr\[0..0\]" "${TEST_DIR}/${TEST_NAME}.d.cg" | ||
|
|
||
| rm_retry "${TEST_DIR}/${TEST_NAME}.d.cg" |
There was a problem hiding this comment.
I have no idea why that isn't working.
There was a problem hiding this comment.
It seems an heisenberg issue. I don't know either.
Signed-off-by: Luís Ferreira <contact@lsferreira.net>
597dc5a to
26d377a
Compare
|
You might need to remove the generated file manually , see Lines 151 to 152 in 33cde05 |
Signed-off-by: Luís Ferreira <contact@lsferreira.net>
26d377a to
ff3f007
Compare
Done. I'll try to fix this later. I don't see a reason for this being hardcoded. |
|
could you rebase now that dlang/ci#436 is in. I think that should be it. |
|
restarted build kite, added auto merge. |
|
This introduced a regression: https://issues.dlang.org/show_bug.cgi?id=21678 The problem is that the value of the expression changed from the new length (0) to the array slice. Two possible solutions:
a.length = 0;
(a = a[0 .. 0], 0) // Doesn't work for standalone assignments |
Signed-off-by: Luís Ferreira contact@lsferreira.net
This simple code
Produces this code with a runtime call on semantic analysis:
The runtime call
_d_arraysetlengthTdoes internally slicing ifnew_length <= current_lengthFor
0as new length, this expression will always be true, no matter what, so this should bea = a[0 .. 0]instead of_d_arraysetlengthT(a, 0LU)I'm not quite sure if this optimization should be made on the semantic analysis but I assumed it because the
ArrayLengthExprassignment is converted to_d_arraysetlengthTthere.