Contributing to the LLVM
I should probably have spend a little more time on the featured image but searching for LLVM on Unsplash just shows Pokémon and 3D printed Pokémon. What's up with that?
Recently and with recently I mean more like 3 month ago I noticed that the Rust compiler can create undefined behaviour for its PlayStation 1 target. Yeah, Yeah who cares? I do! Because that bug kept breaking my controller code... So I used all my bravery and opened an issue about it. I surely was very nervous about it! Usually I'm not very active on Git and I was very worried about the outcome of this. However, all in all, people were incredible supportive! They raised many interesting points or explanation attempts and stayed committed to the issue. Especially one user encouraged us (my partner and myself) to focus on creating a minimal example that can reproduce the issue. A very valuable thing to do! It helped us tremendously to isolate the issue in a small example. My partner then used Godbolt to understand better at what point in time the issue occurred - it helps a lot to not have to face these issues alone! Eventually we could prove that the issue was not caused by Rust itself but the LLVM, which is used by Rust to deliver us the machine code we want so much.
Woah! The LLVM, a collection of tools, SDKs and what not to make compilers! The people working on this must all be the top of the smartest, how could I think to ever contribute to this?!
Not overly motivating, what I was thinking there. Together with my partner we raised the issue again, but decided quite quickly that no one else, except us is going to fix this issue. The PlayStation 1 is not the most famous or demanded platform these days. The first big challenge was to locate the code that is involved in causing the issue. Maybe I should explain this a bit better, but it is already quite well explained in the mentioned issues and I kinda want to keep these posts short and simple. So yeah... We took a few LLVM IR files that reproduce the load delay issue and run the llc tool on them. This tool from the LLVM compiles from the LLVM IR code to actual machine code. My partner did great work on identifying that the issue is in the LLVM and not with Rust. With llc I could reproduce the issue. And after some printfs and the PR which introduced the PlayStation 1 support to the LLVM, I was able to somewhat understand the flow of the code and could work on a fix.
Writing the fix took quite some time, mostly because I did not understood everything in the beginning and often had to overly motivated ideas. Initially we wanted to go for a very simple fix but eventually we reached a better, more smart solution. However, getting the changes back to the LLVM was not easy!
The LLVM is running a style check on every PR, which is totally fair! They have their rules and I have to follow them! But I didn't know that it is not enough to just format the last commit... So here is an advise to myself:
1. Always format all commits - or just squash them all together
But that was not all... I focused on having my changes only affect the PlayStation 1 target - but the way I did, just meant that the platform needs to be at least the PlayStation 1 so all the other MIPS targets where effected. That made all automated test fail.
2. Run the test suites before committing - all of them!
So I limited the changes to actually only really effect the PlayStation 1. Pushing the changes I hoped I would be done - but no! Failed test again! Apparently the automated tests are running with assertions turned on. And indeed, there was a violation of an assertion in my code!
3. Do development with assertions being turned on
Finally! The tests passed but, I could not merge them - despite my changes being approved. I have no permissions to merge the PR myself... Luckily my reviewer was so nice to do it.
So... was it fun? Kinda, yeah, maybe... I'm happy that - with a lot of help from my partner - was able to fix this issue, now I just need to get it into Rust... Well... what am I thinking about this post? Not good! Who is the audience for this? I don't know... maybe it is a dairy page? But rather short? I think my next post will not be as rushed as this post but I really wanted to get this out of me c: