6 ms·
Building the Rust Compiler with GCC
- dwheeler 1y agoIt may not seem like it, but this is impressive progress. Getting a compiler to bootstrap at all is an accomplishment, especially for Rust since that depends on so many things working. Once it can reliably bootstrap, a lot of performance-improving steps can begin. Congrats!
- ramon156 1y agoI'm not that deep into gcc. Would it really add a lot of performance gain?
- mijoharas 1y agoI don't think the goal is performance (and I don't think a well optimised gcc implementation will improve performance). I think the comment you are replying to is speaking about performance because of things like this line from the article: > ...with the emphasis on limp. At some points, we are using over 100 GB of RAM... not ideal. (so performance will be the next thing to be worked on to make this useable). I think the goals of using gcc for rust is that it can provide a parallel implementation, which can help uncover bugs and provide more stability to the entire language, and because if there is a large gcc project already, they may be reticent to introduce LLVM as a dependency as well.
- tucnak 1y ago> reticent That is a $200 word right there, and you're using it wrong.
- mijoharas 1y agohttps://en.wiktionary.org/wiki/reticent https://en.wiktionary.org/wiki/reticent (2) https://www.merriam-webster.com/grammar/can-reticent-mean-reluctant https://www.merriam-webster.com/grammar/can-reticent-mean-re... You're correct that some people recommend against it, and it's only been in use since the second world war.
- echelon 1y agoI only knew of the "reluctant" meaning. Languages mutate quickly.
- mijoharas 1y agoYep, it's what I've heard most often too (I only just learnt the other meaning from the kind person prompting me look up the definition). I also don't think of it as that much of an unusual word, but hey.
- trelane 1y agoIt's also Merriam-Webster, a descriptivist dictionary. Others are of a prescriptionist bent. For example, Cambridge: https://dictionary.cambridge.org/us/dictionary/english/reticent https://dictionary.cambridge.org/us/dictionary/english/retic... More on prescriptive vs descriptive: https://twominenglish.com/prescriptivist-vs-descriptivist/ https://twominenglish.com/prescriptivist-vs-descriptivist/ I personally am more descriptivist when it comes to English. It is also a lot of fun to bring some M-W citations in order to "Well, actually" someone who is "Well, actually"-ing.
- nartho 1y agoReticent is a valid synonym of reluctant.
- johnklos 1y agoAnd let's not forget that bootstrapping rust using something other than rust is quite useful.
- pornel 1y agoYou can't use this implementation to bootstrap Rust (in the sense of bootstrapping from non-Rust language or a compiler that isn't the rustc). This GCC support here is only a backend in the existing Rust compiler written in Rust. The existing Rust compiler is using GCC as a language-agnostic assembler and optimizer, not as a Rust compiler. The GCC part doesn't even know what Rust code looks like. There is a different project meant to reimplement Rust (front end) from scratch in C++ in GCC itself, but that implementation is far behind and can't compile non-toy programs yet.
- aswanson 1y agoI just started playing with rust again today. Godspeed.
- Cogito 1y agoReally great read. Someone mentioned recently that the slowness of rustc is in large part due to llvm. I know that is probably orthogonal to the work here, but I do like the idea of building the compiler with different toolchains, and that there may be follow on effects down the line.
- deleted 1y ago[deleted]
- torstenvl 1y agoIt's slow because the borrow checker is NP complete. LLVM may or may not generate slower code than GCC would for rustc, but I doubt it's anywhere close to the primary cause of the lack of snappy.
- almostgotcaught 1y agoYou're wrong it's been debunked that the borrow checker is any appreciable part of the compile time - Steve Klabnik actually verified it on here somewhere. Edit: found it https://news.ycombinator.com/item?id=44391240 https://news.ycombinator.com/item?id=44391240
- Cogito 1y agoThanks, I'm pretty sure I was thinking of this whole discussion when I made my original comment :)
- resurrectedcyb 1y agoI don't see that debunking it. Instead, it says "usually". That means that it depends on the project. There is definitely Rust code that takes exponential time to compile, borrow checker or not. https://play.rust-lang.org/?version=stable&mode=release&edition=2024&gist=78e690239386398a7677fd76b4099dc7 https://play.rust-lang.org/?version=stable&mode=release&edit... https://github.com/rust-lang/rust/issues/75992 https://github.com/rust-lang/rust/issues/75992 Some people used async in ways that surfaced these problems. Upgraded rustc, then the project took forever to compile.
- deleted 1y ago[deleted]
- saagarjha 1y ago> Normally, debuing the compiler is fairly straightforward: it is more or less a run of the mill executable. > In the bootstrap process, the entire thing becomes way more complex. You see, rustc is not invoked directly. The bootstrap script calls a wrapper around the compiler. > Running that wrapped rustc is not easy to run either: it requires a whole lot of complex, environment flags to be set. > All that is to say: I don’t know how to debug the Rust compiler. I am 99.9 % sure there is an easy way to do this, documented somewhere I did not think to look. After I post this, somebody will tell me "oh, you just need to do X". > Still, at the time of writing, I did not know how to do this. > So, can we attach gdb to the running process? Nope, it crashes way to quickly for that. It's kind of funny how often this problem crops up and the variety of tricks I have in my back to deal with it. Sometimes I patch the script to invoke gdb --args [the original command] instead, but this is only really worthwhile if it's a simple shell script and also I can track where stdin/stdout are going. Otherwise I might patch the code to sleep a bit before actually running anything to give me a chance to attach GDB. On some platforms you can get notified of process execs and sometimes even intercept that (e.g. as an EDR solution) and sometimes I will use that to suspend the process before it gets a chance to launch. But I kind of wish there was a better way to do this in general…LLDB has a "wait for launch" flag but it just spins in a loop waiting for new processes and it can't catch anything that dies too early.
- o11c 1y agoOther ideas: * Run the whole tree of processes under `gdb` with `set detach-on-fork off`. * LD_PRELOAD a library that inserts the sleeps for you, maybe on startup or maybe on signal/exit. Ideally, we'd have some kind of infrastructure to name and identify particular processes recursively.
- jcranmer 1y agoI have a LD_PRELOAD library that hooks SIGSEGV into spawning gdb on the process using the best guess for the process's terminal (which currently isn't very smart because I haven't yet needed to debug processes that do a lot of stdio redirection).
- 1y ago
- dtgriscom 1y agoI love vicarious engineering.
- Rogach 1y agoSounds like attempting to always inline a recursive function should be an error instead. But it's probably undesirable to make that change because it would likely break existing crates and thus backwards compatibility as well?
- dwattttt 1y ago"inline(always)" I expect matches Clang's "always_inline", and Clang's documentation makes what it does clearer: > Inlining heuristics are disabled and inlining is always attempted regardless of optimization level. So it should be interpreted as "always attempt to inline", as opposed to "this must be inlined", or other attributes that instead influence the "should this be inlined" heuristic. EDIT: as curious an attribute as it might be, I didn't mean to be talking about inclines
- j16sdiz 1y agorecursive function can be inline when unrolled. This is a valid optimization. Google "llvm inline recursion". It exists. It should works. Fibonacci is the standard test case.
- 1718627440 1y agoBut not every recursive function can be inlined (without a secondary stack).
- 1718627440 1y agoWouldn't the best way to check whether something is inlineable to just try it? Why can't GCC be let to try to inline it and if it encounters that it isn't possible it can be instructed to just not inline it?
- pornel 1y agoMy guess is that the public library interface of GCC doesn't support it this way. This back-end uses the confusingly-named libgccjit (not as JIT), which gives access only to a subset of GCC's functionality. If something isn't already exposed, it might take a while to get patches to GCC and libgccjit accepted and merged.
- juxhindb 1y ago> Really, think about it. How often do you see somebody inexperienced use ifs instead of a switch? This pattern is common enough for most compilers to recognize, and more importantly, optimize it. This made me chuckle. Playing dumb so that gcc optimizes you away is both hilarious and genius
- 1718627440 1y agoActually the compiler converts the switch to ifs not the other way around.