5 ms·
I know there are many benefits to self-hosting, but I’ve wondered in the past if it biases language design towards compiler-writing. Depending on the language’s
by brundolf 5y ago
I know there are many benefits to self-hosting, but I’ve wondered in the past if it biases language design towards compiler-writing. Depending on the language’s primary domain (maybe with Rust it’s less of a concern), compilers as a usecase can be fairly unusual, in terms of both requirements and what makes them ergonomic to write. So if self-hosting inspires you to shape the language to make early accommodations for writing the compiler, that may not necessarily be the best thing in the long run.
- capableweb 5y agoIndeed, building a programming language that is supposed to be for systems programming then it makes sense for it to be able to be ergonomic to write compilers in. But if you're building a programming language for building UIs (or any other specific use case), then making it bootstrapping it's own compiler in it's own language seems like a waste of time.
- brundolf 5y agoI'm not sure I'd say "waste of time", just that it might pull the language in some directions it might not ought to go in. It would still benefit from the battle-testing, but there might be other "dogfooding" projects that would be more appropriate; the compiler is just a convenient one since you're already doing that work.
- pdpi 5y agoI don’t think it’s a waste of time. Compilers are demanding projects where you need to be intimately familiar with both target and host languages. A self-hosting compiler means that target and host are the same language, and reduces that source of friction.
- wk_end 5y agoThis makes sense in the abstract - in practice, what compiler-specific features or biases do you think might not be suited for any given general-purpose language?
- brundolf 5y agoCompilers are biased, among other things, towards: - Having a rich, complicated internal model (and having minimal contact with external data; mostly just the code being ingested) - Recursion - Being stateless (at the top level anyway; code goes in code comes out) - Having an enormous amount of semi-regular code (favoring macros and related features) - Dispatch/polymorphism among very broad type groups (favoring enums and ways of discriminating enums) Not that any of these things are bad to support in any given language, but every language is a big bag of trade-offs, and focusing on compilers might cause you to choose certain tradeoffs that aren’t as relevant to the way the language will typically be used later on No specific judgements on Rust (in fact, Rust has ended up seeing a lot of use for compilers and compiler-adjacent projects), just something I’ve been thinking about in general
- jcranmer 5y agoThe most common criticism in practice tends to be a strong aversion to mutability. Compilers can be thought of as a series of pure functions transforming a large immutable data structure, and given the practical issues of mutability (reasoning about it is legitimately hard), this can give a lot of languages a strong aversion to mutability. However, there are some domains where you can't transform the problem space into consume-and-produce-immutable data structures and expect anything close to performant--databases are a good example here.
- jcranmer 5y agoI think there's definitely an unconscious bias towards compiler design in PL design because of self-hosting; one of the other things that helped Rust immensely was that it also had Servo as an early-language design goal.
- geodel 5y ago> Depending on the language’s primary domain .. Well yeah most languages do not do that. Besides if any language claiming to be general purpose language to be useful in varied use cases, leaving out compiler, runtime, or GC etc would reflect important shortcomings in language. > So if self-hosting inspires you to shape the language to make early accommodations for writing the compiler, that may not necessarily be the best thing in the long run. This is applicable to almost any situation. If a language is designed for say asynchronous web services of 2020s, will be necessarily best thing in long run? With the benefit of hindsight I can say a SOAP programming language designed in 2000 would not have many takers today.
- avgcorrection 5y agoThe intended use for Rust was to write a browser engine. So the point still stands.
- mamcx 5y ago> I’ve wondered in the past if it biases language design towards compiler-writing. Yeah this a "well know" problem. In fact, you will ALWAYS bias the language for what is your ACTUAL first "major" project. However, I think that "make langs" is in itself a very good thing to be able to do in any lang, even if is high-level, business oriented (a lot of work is alike!) and is only when you wanna to mimic the C-abi or marry with C/C++ (like full integrate LLVM) where things will go sideways (and I bet: Is more a fault of C here, than "making compilers")
- phkahler 5y ago>> I know there are many benefits to self-hosting, but I’ve wondered in the past if it biases language design towards compiler-writing Well I've been waiting for ANY language to embrace 2d, 3d, and 4d vectors as basic types (probably the wrong word). They map perfectly to modern vector registers in SIMD hardware and they are fundamental to all forms of graphics, from text rendering to 3d games, to CAD and any type of physical simulation software. It just seems like language designers figure "anyone can create a type like that with our generic building blocks" and somehow, if we're lucky the compiler will figure out and generate optimal code for it. Oh never mind that different code bases will call these fundamental data types different thing - Vec3, vec3, vector, and have different implemntations, making modules non-reusable across projects... Yes, language designers and compiler writers are usually very smart people but they do have biases and blind spots just like everyone else. It think Rust is turning out so good because they really spent like 10 years getting it "right".
- emteycz 5y ago> basic types (probably the wrong word) Not too wrong... I think the proper term is "primitive" (as in language primitives), but basic works too.
- skavi 5y agoZig is working on a SIMD primitive IIRC.
- sidpatil 5y agoGenerally you'll find built-in vector and matrix types in languages designed for technical computing, such as FORTRAN, MATLAB/Octave, Julia, Chapel, etc.
- avgcorrection 5y agoRust was first implemented in Ocaml. Given that choice and the influence it has had I would say that it was inevitable that Rust would get compiler writer PL features, self-hosting or not.
- saghm 5y agoI'm not sure if there's a better alternative, to be honest. Given how large a portion of the time compiler authors will be writing code for the compiler, many of them might not spend any time working in the language they're designing if it isn't what the compiler itself is written in. If the people who maintained Rust spent all their time writing OCaml and little to none writing Rust, I think that would likely cause far more and worse blind spots than writing Rust all the time but only in a specific domain.