6 ms·
The bootstrap problem is real and getting worse: go needs go, haskell needs haskell, rust needs rust; it's nasty. There are already "better" and "safer" langua
by liveoneggs 9y ago
The bootstrap problem is real and getting worse: go needs go, haskell needs haskell, rust needs rust; it's nasty.
There are already "better" and "safer" languages that could easily replace the entire unix userland. Heck, awk can do half of it, but all of that C code is already written...
- cesarb 9y ago> go needs go, haskell needs haskell, rust needs rust And C needs C, or for more recent compilers, C++ needs C++. You just don't notice it because these two languages are already part of the base system.
- progman 9y ago> go needs go, haskell needs haskell, rust needs rust That's painful. It's one big point which Nim [1] does better. It compiles to C and bootstraps from C. That makes porting to other platforms much easier. I don't understand why Haskell and Rust don't provide bootstrapping from C. Did they write the first compilers with Assembler? > You just don't notice it because these two languages are already part of the base system. C (not C++) has become the essential foundation on any platform. You will likely not be able to sell your embedded system unless it supports C. [1] https://nim-lang.org https://nim-lang.org
- cesarb 9y ago> I don't understand why Haskell and Rust don't provide bootstrapping from C. Did they write the first compilers with Assembler? I don't know about Haskell, but the first Rust compiler was written in OCaml. See for instance the comments at https://www.reddit.com/r/rust/comments/6nt2j1/is_there_any_existing_literature_on_the_old_ocaml/ https://www.reddit.com/r/rust/comments/6nt2j1/is_there_any_e...
- progman 9y ago> See for instance the comments ... Interesting! So, it should basically be possible to bootstrap from source using OCaml and the old source from the Git repository. It's interesting that OCaml was used to develop Rust since OCaml is also used for formal verification of SPARK (a dialect of Ada) which is another language for safety critical applications. OCaml seems to be a good choice to invent new big languages.
- kccqzy 9y agoGHC has a special mode (not available in released builds) that compiles Haskell to plain old C, which can then be compiled by any other C compiler. Of course when compiled in such manner, Haskell code runs very slowly but it works.
- steveklabnik 9y agoRust's first compilers were written with OCaml. We don't provide bootstrapping from C because no C-based toolchain has ever existed. However, it may in the future; see my link upthread.
- deleted 9y ago[deleted]
- progman 9y agoI think bootstrap with OCaml is ok - if just bootstrap from source becomes possible at all. Binary-only dependency is awful when Rust is wanted on yet unsupported systems.
- steveklabnik 9y agoIt's not a significant issue if you can accept cross-compiling. This is how most platforms get their start.
- npsimons 9y ago> This is how most platforms get their start. The key word here is 'start'. I don't like to arbitrarily constrain tools, but I've always felt that cross-compilers were sort of a last resort, ie, you don't have a native compiler (you're writing the compiler or operating system), or are really pressed for time. Once you've got a native compiler, that should be it: self-hosted from there on.
- xfer 9y ago> That's painful. It's one big point which Nim [1] does better. It compiles to C and bootstraps from C. That makes porting to other platforms much easier. Unless you are talking about an architecture which doesn't have llvm backend, it takes the same effort as nim to port rust and haskell. > Did they write the first compilers with Assembler? Rust was written in Ocaml first, bootstrapping from C need decent amount of effort. I don't know the origins of haskell.
- progman 9y ago> Unless you are talking about an architecture which doesn't have llvm backend Nim doesn't depend on LLVM. It works also with GNU C.
- xfer 9y agoYes, i was talking about rust and haskell. How many architectures out there that don't have llvm backend but only gcc?(excluding the microcontrollers with very little RAM(<1M))
- liveoneggs 9y agohaskell was C-bootstrap-able many versions ago, but you need the previous version to build the next from that point forward so it's quite a dance. There is also no effort to maintain the "old" version as a strict "bootstrap" since everyone just has binaries of the previous version lying around. :)
- masklinn 9y agoGHC is still C-boostrap-able. That's literally the only reason why the C backend still exists: > The C code generator is only supported when GHC is built in unregisterised mode, a mode where GHC produces 'portable' C code as output to facilitate porting GHC itself to a new platform.
- liveoneggs 9y agoso GHC can generate C code to bootstrap GHC?
- masklinn 9y agoGHC can compile GHC (or Haskell in general) to C, the main use case being bootstrapping GHC without cross-compilation, as the latter has historically been lacking: > Support for cross-compilation works reasonably well in 7.8.1. Previous versions had various issues which are usually work-aroundable. (7.8.1 was released in 2014, GHC itself is 25 years old)
- bluGill 9y agoC has a large advantage: you can write a compiler in machine language (not assembly, raw machine language) in a week. Not a good compiler: it will produce horrid, unoptimized code. You just need enough to build a good C compiler. From there you can build a c++ compiler, which in turn can build the C++ compiler you want. Every time you add a new language feature you increase them time to write your bootstrapping compiler. Garbage collection means you will spend a few more months building a garbage collector. (remember we are writing in machine language so most of the abstractions you are used to dealing with - even in assembly - are missing. Thus complexity is growing exponentially)
- stepik777 9y ago> large advantage How is this a large advantage? When was the last time someone actually did this?
- qznc 9y agoIn my experience, a new toy c compiler pops up roughly once a year. https://github.com/Wilfred/babyc https://github.com/Wilfred/babyc http://www.sigbus.info/how-i-wrote-a-self-hosting-c-compiler-in-40-days.html http://www.sigbus.info/how-i-wrote-a-self-hosting-c-compiler... http://zserge.com/blog/cucu-part1.html http://zserge.com/blog/cucu-part1.html https://c9x.me/qcc/ https://c9x.me/qcc/ https://github.com/alexfru/SmallerC https://github.com/alexfru/SmallerC
- kelnos 9y agoSure, and most people do this as an exercise, whether it's to learn how to write a compiler, or to see how small they can make the compiler, or something like that. No one does it because they really have a strong practical need to.
- pjmlp 9y agoThat so called advantage is how Niklaus Wirth did all his compilers, and many other language designers, it is not unique to C.
- rbehrends 9y agoBut a C compiler is part of basically every Unix system. That matters. For example, one of the perks of my job is that I do occasionally get to play with real nice hardware (such as a Cray with a couple thousand nodes at one point). The downside of that is that the owners won't give me root access and because there are lots of other people working with it, stability of the system is more important than getting the newest software installed. Oh, and this also sometimes means restricted internet access. So, bootstrapping matters to me, and the bootstrapping story for anything involving LLVM isn't very good (I'm actually having some problems with a language other than Rust in this regard). Interpreters you can generally build fairly easily from source (Lua, Ruby, Python, Tcl, for example). But when it comes to compilers, bootstrapping is generally a much bigger obstacle. There are a few notable exceptions that only require a C compiler, no internet access during their build, and build in an acceptably short time: * OCaml bootstraps from C via a bytecode interpreter, which is then used to build the native compiler. On my laptop (using four cores), I can actually do that in under a minute (two minutes if I want flambda). * Nim compiles to C and hence builds in half a minute on the same machine from C sources. * LuaJIT builds in a few seconds, assuming a dynamically typed language with a JIT compiler is sufficient for you.
- cat199 9y ago> There are a few notable exceptions that only require a C compiler, no internet access during their build, and build in an acceptably short time: most any scheme/lisp compiler as well requiring internet access and binary bootstrap toolkits thing for the core piece of an ecosystem (e.g. the language compiler) is decidedly new-school, rooted in overly commercial projects, and for the worst, imho. ps: lawn.
- steveklabnik 9y agoTo be clear, rustc and Rust projects generally do not require the internet to build. It's a hard requirement of many projects, like Debian or Firefox.
- rbehrends 9y ago
- alexbakker 9y ago>go needs go No it doesn't. You can use gccgo to bootstrap go.