News for hackers. Stuff that matters.
Re:Integrating “safe” languages into OpenBSD? by liveoneggs on Monday December 04, 2017 @09:27AM (#15844008)
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...

Re:Integrating “safe” languages into OpenBSD? by cesarb on Monday December 04, 2017 @09:31AM (#15844038)
> 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.

Re:Integrating “safe” languages into OpenBSD? by rbehrends on Monday December 04, 2017 @11:15AM (#15844943)
But 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.

Re:Integrating “safe” languages into OpenBSD? by cat199 on Monday December 04, 2017 @11:32AM (#15845091)
> 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.

Re:Integrating “safe” languages into OpenBSD? by steveklabnik on Monday December 04, 2017 @11:44AM (#15845202)
To 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.
Re:Integrating “safe” languages into OpenBSD? by rbehrends on Monday December 04, 2017 @01:03PM (#15845961)
Sorry, I didn't mean to imply that Rust did. For me, it's primarily a problem with some JVM-related tools.
Re:Integrating “safe” languages into OpenBSD? by steveklabnik on Monday December 04, 2017 @01:35PM (#15846263)
It's all good!
Re:Integrating “safe” languages into OpenBSD? by bluGill on Monday December 04, 2017 @10:10AM (#15844355)
C 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)

Re:Integrating “safe” languages into OpenBSD? by stepik777 on Monday December 04, 2017 @11:43AM (#15845199)
> large advantage

How is this a large advantage? When was the last time someone actually did this?

Re:Integrating “safe” languages into OpenBSD? by qznc on Monday December 04, 2017 @05:50PM (#15848297)
Re:Integrating “safe” languages into OpenBSD? by kelnos on Monday December 04, 2017 @09:43PM (#15849370)
Sure, 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.
Re:Integrating “safe” languages into OpenBSD? by pjmlp on Monday December 04, 2017 @05:54PM (#15848340)
That so called advantage is how Niklaus Wirth did all his compilers, and many other language designers, it is not unique to C.
Re:Integrating “safe” languages into OpenBSD? by bluGill on Tuesday December 05, 2017 @10:24AM (#15852238)
I didn't mean to imply it was unique to C, though in hindsight I did. This can be done in many languages.

I believe that Niklaus Wirth created his first self hosting implementation in a small subset of the language and expanded from there. Anyone thinking about doing this for a non-trivial language should consider following that example.

Re:Integrating “safe” languages into OpenBSD? by progman on Monday December 04, 2017 @10:00AM (#15844282)
> 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

Re:Integrating “safe” languages into OpenBSD? by steveklabnik on Monday December 04, 2017 @10:09AM (#15844352)
Rust'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.

Re:Integrating “safe” languages into OpenBSD? by progman on Monday December 04, 2017 @10:31AM (#15844547)
I 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.
Re:Integrating “safe” languages into OpenBSD? by steveklabnik on Monday December 04, 2017 @10:36AM (#15844600)
It's not a significant issue if you can accept cross-compiling. This is how most platforms get their start.
Re:Integrating “safe” languages into OpenBSD? by npsimons on Tuesday December 05, 2017 @07:03PM (#15857383)
> 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.

Re:Integrating “safe” languages into OpenBSD? by cesarb on Monday December 04, 2017 @10:08AM (#15844340)
> 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_e...

Re:Integrating “safe” languages into OpenBSD? by kccqzy on Monday December 04, 2017 @06:06PM (#15848423)
GHC 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.
Re:Integrating “safe” languages into OpenBSD? by progman on Monday December 04, 2017 @10:26AM (#15844504)
> 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.

Re:Integrating “safe” languages into OpenBSD? by xfer on Monday December 04, 2017 @10:20AM (#15844451)
> 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.

Re:Integrating “safe” languages into OpenBSD? by progman on Monday December 04, 2017 @10:28AM (#15844520)
> 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.

Re:Integrating “safe” languages into OpenBSD? by xfer on Monday December 04, 2017 @07:18PM (#15848793)
Yes, 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))
Re:Integrating “safe” languages into OpenBSD? by liveoneggs on Monday December 04, 2017 @10:33AM (#15844569)
haskell 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. :)

Re:Integrating “safe” languages into OpenBSD? by masklinn on Monday December 04, 2017 @11:15AM (#15844939)
GHC 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.

Re:Integrating “safe” languages into OpenBSD? by liveoneggs on Monday December 04, 2017 @12:14PM (#15845474)
so GHC can generate C code to bootstrap GHC?
Re:Integrating “safe” languages into OpenBSD? by masklinn on Monday December 04, 2017 @12:40PM (#15845724)
GHC 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)

Re:Integrating “safe” languages into OpenBSD? by alexbakker on Monday December 04, 2017 @10:05AM (#15844321)
>go needs go

No it doesn't. You can use gccgo to bootstrap go.