-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[Kaleidoscope] Fix ForExprAST::codegen #88207
base: main
Are you sure you want to change the base?
[Kaleidoscope] Fix ForExprAST::codegen #88207
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@Logikable @aeubanks @MaskRay @EugeneZelenko @Endilll Please take a look whenever you find time. Thanks! |
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.
Great catch :) I made the same fix when doing the tutorial, so I was able to compare it with yours for correctness (yours is cleaner!)
I left a couple of ideas for things you could change. Thanks for contributing to the tutorial.
…rast-codegen-patch
@@ -447,8 +447,7 @@ from a starting value, while the condition ("i < n" in this case) is | |||
true, incrementing by an optional step value ("1.0" in this case). If | |||
the step value is omitted, it defaults to 1.0. While the loop is true, | |||
it executes its body expression. Because we don't have anything better | |||
to return, we'll just define the loop as always returning 0.0. In the | |||
future when we have mutable variables, it will get more useful. |
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 removed the final sentence of this paragraph because I realized that the tutorial never actually does anything with the for-loop return value in future chapters.
@Logikable Please take a look at the changes I've made, as per your instructions. The build is failing, but I see that the Kaleidoscope tests are passing, so I assume it was because I merged main into my branch before pushing and there is an issue with some of the code in main. Could you take a look at the build logs to confirm I am interpreting them correctly? Also as a quick question, do you know by any chance why when running the Kaleidoscope tests on my machine, it says they are
Let me know if there are any other issues with my PR! 🙂 |
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 PR is to address issue #13638.
Background
The Kaleidoscope tutorial has a bug in its approach to generate LLVM IR for for-loops introduced in Chapter 5.
Given input
the tutorial explains that we should be generating the following IR.
However, the IR above has a logic error. In particular, we enter the loop even if we are not supposed to. For instance, if we call
printstar(0);
, we still print a star because the loop condition is not checked until the end of the loop body.Solution
This PR proposes a fix for this error, and the following IR dump demonstrates the changes.
With this LLVM IR, here's some example output.
In addition to how the for-loop IR is generated, I've updated the tutorial RST files for Chapter 5 and 7 with commentary on my implementation of the
ForExprAST::codegen
method.