This is an archive of the discontinued LLVM Phabricator instance.

[Kaleidoscope] Update code snippets in text to match full code listings
ClosedPublic

Authored by 0xdc03 on Jan 22 2023, 8:12 PM.

Details

Summary

There were quite a few places in the tutorial where the snippets were not up to date with the full code listings given. I have updated all of the ones I could find, which mostly involves changing . to -> when accessing through a std::unique_ptr, changing while (1) to while (true), and other such small changes.

There are still however a few places where I am not sure what to do, such as:

  • Chapter 4: ParseTopLevelExpr() in chapter 3 sets the ProtoTypeAST name to "", however it is referred to as "__anon_expr" in chapter 4. Would it be required to mention this change in chapter 4?
  • Chapter 9: The code snippets refer to the top level expression as "main", however the full code listing refers to it as "__anon_expr". I think given the context of the chapter it makes sense to refer to it as "main", so I have updated the code listing to reflect that.
  • Chapter 9: In chapter 9 the diff given for HandleTopLevelExpression() deletes code that is not mentioned anywhere else, so I am not sure what is to be done there.
  • Miscellaneous: I don't think this is very important, however the casing used for the first word of error messages tends to vary between upper and lower case between chapters and I do not know if it is worth reconciling these differences.

Diff Detail

Event Timeline

0xdc03 created this revision.Jan 22 2023, 8:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 22 2023, 8:12 PM
0xdc03 requested review of this revision.Jan 22 2023, 8:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 22 2023, 8:12 PM
0xdc03 edited the summary of this revision. (Show Details)Jan 22 2023, 8:17 PM
xgupta accepted this revision.Jan 29 2023, 11:25 AM
xgupta added reviewers: kazu, aaron.ballman.
xgupta added subscribers: kazu, xgupta.

Thank you for the patch!

I went through all the changes, they look good to me.

llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl04.rst
300

we may remove this line.

llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl07.rst
582

Not sure about this, why not use static_cast then by default? @kazu might better review this.

llvm/examples/Kaleidoscope/Chapter9/toy.cpp
802–803
// Make an anonymous proto.

This comment is better suited for __anon_expr. we should keep it.

This revision is now accepted and ready to land.Jan 29 2023, 11:25 AM
0xdc03 added inline comments.Jan 29 2023, 8:21 PM
llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl04.rst
300

I thought it would be more useful to know what the type of ExitOnErr was, as this variable has never been referenced before, and it would help not having to scroll to the very end for that

llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl07.rst
582

Yeah, I was a little confused at this point so I decided to stick with what the tutorial had before and mention how the code listing did it

llvm/examples/Kaleidoscope/Chapter9/toy.cpp
802–803

Oh, I completely missed this comment! This was also one of the points where I wasn't sure what to do. Given that the start of the chapter explicitly says

First we make our anonymous function that contains our top level statement be our “main”:

under section 9.3, I feel it'd be better to update the comment to say something like // Make the top level expression be our "main" function

0xdc03 updated this revision to Diff 493484.Jan 30 2023, 10:06 PM
  • Update the comment in the code listing to match the code below it

@xgupta I have updated the comment in the code listing to match the code that creates the function. I think it is better to keep the ExitOnError variable as I was quite confused as to what ExitOnErr was when reading the tutorial and I only realized it once I scrolled to the end and found the declaration. If this seems correct to you, can you land this patch for me as I do not have commit access? Please use "Dhruv Chawla <dhruv263.dc@gmail.com>" to commit the change.

Thanks!

PS: I am a little concerned if I updated my revision correctly: I used arc diff --update to commit my second change, and I am not sure if that is correct as phabricator is only showing the diff against the second commit...

xgupta added inline comments.Jan 31 2023, 6:36 AM
llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl04.rst
300

Fine, I agree.

llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl07.rst
582

I think the code listing is using static_cast, you should change dynamic_cast here to static_cast imo.

llvm/examples/Kaleidoscope/Chapter9/toy.cpp
802–803

Yeah, then it sounds reasonable to update it to main.

@xgupta I have updated the comment in the code listing to match the code that creates the function. I think it is better to keep the ExitOnError variable as I was quite confused as to what ExitOnErr was when reading the tutorial and I only realized it once I scrolled to the end and found the declaration. If this seems correct to you, can you land this patch for me as I do not have commit access? Please use "Dhruv Chawla <dhruv263.dc@gmail.com>" to commit the change.

Thanks!

PS: I am a little concerned if I updated my revision correctly: I used arc diff --update to commit my second change, and I am not sure if that is correct as phabricator is only showing the diff against the second commit...

I used to do arc diff to update review. It works fine.

0xdc03 updated this revision to Diff 493620.Jan 31 2023, 7:54 AM
  • [Kaleidoscope]: Update code to address review comments

Okay, I have fixed the code and I think the patch is ready now. It turns out you have to specify the number of commits to push to the patch, arc doesn't pick up on it automatically. Also, in my case it didn't pick up on the fact that I already had a patch (or is it revision?) made, so I had to use the command arc diff HEAD~~ --update D142323 and everything seems fine.

Thank you so much for reviewing my first patch :>

This revision was landed with ongoing or failed builds.Jan 31 2023, 10:01 AM
This revision was automatically updated to reflect the committed changes.

Okay, I have fixed the code and I think the patch is ready now. It turns out you have to specify the number of commits to push to the patch, arc doesn't pick up on it automatically. Also, in my case it didn't pick up on the fact that I already had a patch (or is it revision?) made, so I had to use the command arc diff HEAD~~ --update D142323 and everything seems fine.

I use arc diff to upload and update the patch every time (I heard people saying arcanist is smart) and arc patch D142323 to review the author's patch.

Thank you so much for reviewing my first patch :>

Congratulations! Thank you very much for contributing. Hope a lot more patches will come soon :)