-
Notifications
You must be signed in to change notification settings - Fork 157
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
Add array constant folding #725
Conversation
Hi thanks so much for this bug fix! You should be able to find a clang-format file here: https://github.com/Rust-GCC/gccrs/blob/master/contrib/clang-format You should be able to copy this to the root directory and name it .clang-format and it can be picked up if your using language server modes like lsp-mode in emacs for example. |
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.
This looks good so far but we need to add a test case to the testsuite for this before we can merge it. I would suggest adding this:
const TEST: [i32; 16] = [2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8];
to gcc/testsuite/rust/compile/torture/array_const_fold_1.rs you may need to add a dg_warning annotation for unused but you can find examples for that in the testsuite.
This PR serves as the first basis for folding arrays and array index expression which is really cool. Did you have any issues with make-check-rust?
Thanks
edit: i just read your message below the template, just wish to say thanks and great work. When we merge this you will need to update your PR comment to remove the PR template stuff otherwise bors will add it to the merge commit message.
elems.iterate([&](HIR::Expr* inner) { | ||
indices.push_back(index++); | ||
Bexpression* bexpr = ConstFoldExpr::fold(inner); | ||
if (bexpr) { |
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.
There is also an open issue about mixing error_mark_node and nullptr here: #692
We should really not have to do a nullptr check here if we are correctly using error_mark_node but this could be fine for now in this PR.
@CohenArthur or @dkm how do you invoke clang-format? |
I usually do this:
With debian, the clang-format packages come with the git command installed correctly. You can also install several versions of clang-format, each package installs the corresponding git command: HTH |
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.
Super cool work :) Looking forward to the tests. Regarding clang-format, I downloaded a clang-format-10 binary from the CI's clang-format action which keeps a list of them. We have been having issues with clang-format versions, and I believe the repo is still using clang-format-10. I think @dkm's solution is really good, and especially if your git package comes with different binaries like his. This is what I would recommend.
4979a7d
to
0471803
Compare
Hi! Thanks for all of the feedback and help with this PR, I added the test and managed to get clang format working the way dkm described. I think the remaining clang format failures don't seem related to the lines of code that I changed? I addressed the following in the new changes:
|
@rodrigovalle Regarding the clang-format failures, I had that happen as well. As you point out, they are not part of your changes, but you still clang-formatted the rest of the code. I think there are some weird edge cases with our .clang-format file and the versions we use, between clang-format11 and 10, which might also happen or not happen because of our different distros, etc. I know I've had that issue in the past and now only run clang-format on my changes. You could try running |
void | ||
ConstFoldArrayElems::visit (HIR::ArrayElemsCopied &elems) | ||
{ | ||
// TODO |
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 think I missed this in my first review. Is this something you plan on doing in this PR or no?
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.
Oh I forgot to mention this, yes I have an implementation for this on a different branch locally. It doesn't work yet, I got stuck because after calling ConstFoldExpr::fold() I have a Bexpression* that I need to convert into a size_t so that I can populate the indices vector to pass into array_constructor_expression.
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 was thinking it might make sense to do add that later in a different PR, it seems like it might need a new type of array_constructor_expression method. I was looking at VEC_DUPLICATE_EXPR in the GCC GENERIC docs but my knowledge there is limited.
Happy to be wrong about this though, maybe there is a way to directly pull a size_t out :)
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.
Yeah this is a perfect thing to do in a separate PR. I prefer lots of smaller PR's so long as we don't regress the testsuite.
I will experiment some more with clang-format tomorrow, I just ran this from HEAD = 0471803
And I had no output, status code 0. |
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.
LGTM, thanks!
And fwiw, I have also been running into the same clang-format issues in #726
Also, there's still the copyright assignment / DCO to be checked. What are you planning on using @rodrigovalle ? |
I opted for DCO by adding the Signed-off-by: tag to my commit message. Let me know if there's anything else I should clean up. I noticed that the first commit here (1fe5af2) duplicates some of the work in 727; I don't mind waiting for that one to land first and then rebasing the second patch on top of master if that works out better. I'll keep looking at folding ArrayElemsCopied in the meantime. |
{ | ||
indices.push_back (index++); | ||
Bexpression *bexpr = ConstFoldExpr::fold (value.get ()); | ||
if (bexpr) |
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.
we have an open issue here about this ideally we should not be checking for nullptr and instead checking for error_mark_node.
The idea is that the constant folding can continue on with errors.
I think you should remove the gcc_unreachable() branch and check. The #692 should be the issue to fix this.
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 think to merge this you just need to remove that gcc_unreachable branch otherwise this LGTM
bors try |
tryMerge conflict. |
@rodrigovalle I think you likely just need to drop the first commit from your PR since this ended up getting merged in #727. I can fix up this for you if you like so we can include this contribution on the Monday status report. |
Ok thanks! I've removed the nullptr check and the first commit so it should merge nicely onto master. I also have a patch to fold ArrayElemsCopied but I will PR that separately. |
Create a new ConstFoldArrayElems folder to visit ArrayElemsValues while holding onto the original ArrayExpr object that we recurse into. Fixes Rust-GCC#681 Signed-off-by: Rodrigo Valle <rdan.valle@gmail.com>
This second push was to remove the nullptr check after we call ConstFoldArrayElems::fold since we use error_expression as the default return value. |
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.
Awesome work
bors r+ |
@rodrigovalle this is fantastic thanks for rebasing this :D |
Build succeeded: |
Fixes #681
I created a new ConstFoldArrayElems folder to visit ArrayElemsCopied and ArrayElemsValues while holding onto the original ArrayExpr object that we recurse into.