Live data from Hacker News

Rust GCC backend: Why and how

blog.guillaume-gomez.fr

121–130 of 138 posts

Re: Rust GCC backend: Why and how

#121

Earlier quoted context omitted.

NB: I'm not the person you were responding to. > I am strongly adverse to package managers This has nothing to do with Rust the language, other than the incidental fact that cargo happens to be bundled with Rust. There are no cargo-specific concepts whatsoever in the Rust language, just like there are no Cmake-specific concepts in C++. I know you alluded to this in your post; I just want to make sure it's crystal cle…

I do write a lot of Rust. Without cargo, it can be a pain in the ass, because nobody designed it to be used without cargo. Generate a random number.

How is it any harder than using C? Sure, the C standard library gives you random numbers, but it doesn't, for example, give you any containers (hash maps, vectors etc.) which are needed even more often.

> Generate a random number.

Well, obviously, I would use cargo and pull in the `rand` package, because I'm not an anti-dependencies ideologue. Cargo makes it easier to depend on third-party code; that's the whole point. But the OP explicitly doesn't want that, so presumably he'd write his own RNG from scratch, or download a tarball of the `rand` package and build it manually without cargo. None of this is any harder in Rust than it would be in C or C++.

Re: Rust GCC backend: Why and how

#122

Earlier quoted context omitted.

> the entire point of Free Software is to allow end users to modify the software in the ways it serves them best Yes? > completely counter to his own supposed raison d'etre I can't follow your argument. You said yourself, that his point is the freedom of the *end user* , not the compiler vendor. He has no leverage on the random middle man between him and the end user other than adjusting his release conditions (aka.…

I'm speaking here as an end user of gcc, who might want e.g. to make a nice code formatting plugin which has to parse the AST to work properly. For a long time, Stallman's demand was that gcc's codebase be as difficult, impenetrable, and non-modular as possible, to prevent companies from bolting a closed-source frontend to the backend, and he specifically opposed exporting the AST, which makes a whole bunch of useful…

> Either way, I as a gcc user can't modify the code if I find it unfit for purpose.

...What? It's licensed under the GPL, of course you can modify the code if you find it unfit for purpose. If it weren't Free Software you might not have been able to do so as the source code might be kept from you.

Re: Rust GCC backend: Why and how

#123

Earlier quoted context omitted.

NB: I'm not the person you were responding to. > I am strongly adverse to package managers This has nothing to do with Rust the language, other than the incidental fact that cargo happens to be bundled with Rust. There are no cargo-specific concepts whatsoever in the Rust language, just like there are no Cmake-specific concepts in C++. I know you alluded to this in your post; I just want to make sure it's crystal cle…

I do write a lot of Rust. Without cargo, it can be a pain in the ass, because nobody designed it to be used without cargo. Generate a random number.

> Generate a random number.

Working on adding that to the standard library, along with a handful of other "you should be able to do this without a dependency" things. We're being very cautious to not fall into the trap of "the standard library is where code goes to die", which is the problem some languages' standard libraries have had. But there are more things we should add, nonetheless.

Re: Rust GCC backend: Why and how

#124

Earlier quoted context omitted.

There's nothing wrong with disliking something. It's more that your dislike alone is not going to convince anyone else. Supporting arguments might either result in one or more of 1) people agreeing with you, or 2) you learning something that helps address your concern, or 3) Rust being improved to address your concern.

Of the three options you presented as being potential results of putting forward arguments supporting my dislike of Rust, the third is interesting. I am quite sure that a vast majority of actual Rust programmers would consider addressing my concerns to be an active degradation of the language. Somewhat related is that I'm not particularly concerned with people (particularly Rust users) agreeing with me, nor do I thin…

In (2), I'm surprised to hear your description of Rust's generics as "ad-hoc polymorphism". I tend to hear that term used to describe non-trait based systems, like C++ generics (in the absence of "concepts"), which act like a compile-time version of duck typing. I think of Rust's generics as trait-based polymorphism, not ad-hoc polymorphism, and I prefer the former over the latter. To a first approximation, I see Rust's generics system as somewhat related to Haskell's. I would be interested to better understand how you see the differences.

From the way you're describing it, it sounds like you might not fundamentally object to generics in general, just to the idea of doing it through monomorphization rather than "dyn Trait"-style vtables? If so, then that's understandable. I like that Rust has both options, but I can absolutely appreciate preferring to do everything via vtables, which has both advantages (code size, one kind of conceptual simplicity) and disadvantages (more difficult to do per-implementation optimization, without doing devirtualization which amounts to monomorphization anyway).

We do have some forms of first-class "type functions" or "type constructors" or "rank-2 polymorphism", in the style of Haskell, so that you can be generic over something like `Vec`. It's a little indirect at the moment, going through traits with associated types, and I'd love to see a more direct version where you can literally write `Something` or `Something` and have those be type functions of one parameter (Haskell "kind" star -> star).

In any case, we have talked many many times about the idea of having more global options to say "don't monomorphize by default, do everything with trait objects". We also are likely to build a stable ABI atop trait objects and vtables eventually, so that it's possible to pass around pointers to data structures and their associated functions, without relying on the layout of the structure.

For (1), I do think we need some mechanism to integrate dependencies. I can appreciate the aversion to the default of "get things from the network". We do try to have good support for vendoring and similar, and this is critical for many projects (e.g. Rust in the Linux kernel, or Rust in CPython, are not going to allow downloading dependencies from the network). All that said, there is a tradeoff between "one first-class package manager and build system" and "lackluster support for various build systems", and Rust picked the former deliberately. We do like being able to implement things in rustc and plumb them through Cargo, so that they're available through the whole stack when that's necessary to make a feature useful. But we also have many users who need to use rustc without cargo, and who ensure that rustc features work with other build systems, notably large corporate monorepo build systems.

As for (3), fair enough, that is very much a philosophical difference between you and Rust, and Rust isn't likely to change that. I do think we're going to make ever more sophisticated ownership semantics in the future (e.g. making self-referential data structures possible), but I doubt Rust's model will stop fundamentally being based around ownership and borrowing.

Re: Rust GCC backend: Why and how

#125

Earlier quoted context omitted.

Woah! Thank you for taking the time to explain your perspective and thoughts! It's a lot of food for thought. I wish I had the background and knowledge to discuss things on equal footing :( Just a few additional questions/comments: > Specifically, Haskell, the language as defined, achieves ad-hoc polymorphism by passing a dictionary parameter to functions using overloaded function names. This is done using the standa…

Swift is a good reference point in this area because Swift essentially took the dictionary-passing approach of Haskell and added the ‘low level’ type information like bit-width, offsets, etc as a Type Metadata parameter. The big upside is that Swift gets a good deal of performance boost compared to Haskell and other languages that have uniform datatypes (boxed values). So to extend the concept I was describing from H…

> I’m generally opposed to generic functions

I'd be interested to know how, in your preferred model, you'd handle things like `Vec` or `HashMap`, without duplicating code.

Re: Rust GCC backend: Why and how

#126

Earlier quoted context omitted.

Thanks, that's actually helpful (your entire reply). What's your preference about copyleft about? Is it that you don't want corporations to keep leeching off of open source? But they do that already! And of course will do their best to hide it. What some license somewhere says bears nearly zero significance. Even if you catch them red-handed and can prove it in court (a very unlikely and rare combination) it would st…

I’ll answer what I think is the more interesting topic first (i.e. licensing is discussed at the bottom): To start, for Rust to a larger degree than Scala, I certainly don’t think the language lacks merit. I am convinced the hype around Rust and its momentum in conversation did it a tremendous favor as it was coming up to 1.0 and as it went through ~2021. I do have some serious technical issues with choices Rust as a…

Thanks for entertaining the discussion, the civility and your willingness to expand is very welcome.

> while I believe a change in direction for Rust would be beneficial, the ecosystem advancement and entrenchment of Rust makes it basically a non-starter as of 2025

May I ask why? I think I am gathering from your comment that you think the language is too big (which I don't understand, could you please clarify?) and that maybe we as an area become too dependent on too few PLs / frameworks? Is your worry an increasing centralization perhaps?

> If every company was use to and had to invent at a minimum their own dialect of a broadly defined language types and then train employees to function within their language environment I would be thrilled.

I was not there but I heard from folks on HN that during the LISP era a good amount of companies did this: they built their own DSL that described their business perfectly (on top of LISP) and then even taught business people how to modify parts of the system by giving them access to only some modules. Result was reported to be a crushing success.

But if we go by your reservations, would you then say LISP is too big and at a risk to entrench itself everywhere (I mean if you were there back then)?

> The above would do a considerable amount to stop corporations from treating programmer like replaceable/disposable cogs in a machine

I would really _love_ for that to be true but I remain skeptical. In my 24 years of career I have only always noticed how businesses always work hard trying to replace us. It's a constant tug of war and we are more or less tolerated because they can't do without us. The moment they feel that they could, most of us would be fired in a heartbeat -- and some of that, in a much smaller scale than they wanted, already happened with the advent of good-ish coding LLM agents.

> where it really hurts for me is that Rust’s pervasiveness prevents moving to a better option in the space due to moneyed interest and cultural buyin

Here we agree at 100%. I do like Rust a lot (though I don't work with it for a while now, I keep using it for personal projects and a little bit of portfolio work) but I believe it's a local maxima that we would all be stuck with for a while.

But that's not an indictment on Rust in particular IMO; it's a judgement towards the risk-averse nature of the area and something I personally don't blame people for (you should not rewrite your business code once every 5 years after all).

--

All that being said, to me Rust is an objective improvement of the state of affairs. It's going to be the new C++ and maybe even the new C, we'll see. And I agree with you that it's not without faults (`async` could have been done better; it's a huge slog to learn it properly and that really did not need to be the case).

Re: Rust GCC backend: Why and how

#127

Earlier quoted context omitted.

Swift is a good reference point in this area because Swift essentially took the dictionary-passing approach of Haskell and added the ‘low level’ type information like bit-width, offsets, etc as a Type Metadata parameter. The big upside is that Swift gets a good deal of performance boost compared to Haskell and other languages that have uniform datatypes (boxed values). So to extend the concept I was describing from H…

> I’m generally opposed to generic functions I'd be interested to know how, in your preferred model, you'd handle things like `Vec ` or `HashMap `, without duplicating code.

Both of the example things you picked are generic types, and container-esque types at that. I think that my opposition to generics in general is a scale of dislike for different uses of generics. So, an off the cuff scale from (well founded and acceptable in certain cases) to (a strict negative in nearly all cases) would be:

Polymorphic Types Parametricly Polynorphic functions ‘Well Motivated’ Ad-hoc Polymorphism Basic Function overloading Basic ‘Operator Overloading’ Function overloading for symbols that are treated as ‘special’ by the compiler

I think the hashmap case is illustrative for my general perspective. I do see the value in being able to have polymorphism for function arguments which are generic in a type parameter. However, consider that the ideal/most performant hashing function for keys differs not just based on general types (int vs string) but can differ based on something like string length or bit width or signededness. My position is that a language should prioritize the ability to encode those exact requirements in a data structure and difficulties for achieving generic-ness be damned. Each function taking a hashmap as argument should be tied to the optimizations and low level considerations intended by the developer.

I am not opposed to some duplication of code where it produces the appropriate code for the problem being solved. My generalized dislike of ‘generics’ is there, but in my comment above I was mostly discussing ad-hoc polymorphism as a means of enforcing some general reasoning ability onto function name overloading. And as I implied in my scale above I find it particularly distasteful (basic function name overloading), if not actively harmful.

For generics there are two areas often conflated in conversation that I find to be wildly different in formalizations of type theories and languages: first, there is static phase type application associated with System F and higher order polymorphic lambda calculus more broadly. I obviously would like to see a more specific and limited implementation of generics at all levels of abstraction, but the higher the abstraction goes the more ‘sense’ generic-ness makes. Second, there is generics as a name for function name overloading, which is distinct from parametricly polymorphic function as well as distinct from generic types. I really dislike this usage of generics and do not think it is a good practice for developing quality software or for readability, maintainability, or efficient optimization. Obviously this is a scale as well. I would put Swift in the lead with Witness Table semantics for generics, then typeclasses and traits, then any less structured implementations at the bottom.

Re: Rust GCC backend: Why and how

#128

Earlier quoted context omitted.

Of the three options you presented as being potential results of putting forward arguments supporting my dislike of Rust, the third is interesting. I am quite sure that a vast majority of actual Rust programmers would consider addressing my concerns to be an active degradation of the language. Somewhat related is that I'm not particularly concerned with people (particularly Rust users) agreeing with me, nor do I thin…

In (2), I'm surprised to hear your description of Rust's generics as "ad-hoc polymorphism". I tend to hear that term used to describe non-trait based systems, like C++ generics (in the absence of "concepts"), which act like a compile-time version of duck typing. I think of Rust's generics as trait-based polymorphism, not ad-hoc polymorphism, and I prefer the former over the latter. To a first approximation, I see Rus…

I just wanted to drop a quick comment to clear up your first question. The term ad-hoc polymorphism to describe both Haskell and Rust’s typeclasses/traits is taken directly from Wadler and Blott’s paper which introduces the idea/concepts of type classes to Haskell. The name of that paper is ‘How to make Ad-Hoc Polymorphism less Ad-hoc’. This paper laid the groundwork for the implementation Rust uses and it is a mechanism for restraining ad-hoc polymorphism. But I think the term still applies to both Haskell and Rust’s typeclasses. Ad-hoc polymorphism is not a derisive term (when used as a term of art in discussions of implementations of programming languages), it is merely the PLT way of saying function name overloading. Rust and Haskell use very similar system to impose restrictions and semantic guiderails on ad-hoc polymorphism, but both languages still have it. To sum, I certainly do not mean any negative connotation with the term, I feel I am using it appropriately and as intended in this domain of discourse.

PS. I intend to write a more substantive reply to your comment, but didn’t think I should leave this unsaid.

Re: Rust GCC backend: Why and how

#129

Earlier quoted context omitted.

I do write a lot of Rust. Without cargo, it can be a pain in the ass, because nobody designed it to be used without cargo. Generate a random number.

> Generate a random number. Working on adding that to the standard library, along with a handful of other "you should be able to do this without a dependency" things. We're being very cautious to not fall into the trap of "the standard library is where code goes to die", which is the problem some languages' standard libraries have had. But there are more things we should add, nonetheless.

From the outside looking in, it seems that despite trends in language development to the contrary, Rust has taken an extremely conservative stance on the inclusions into and the evolution of its standard library. I applaud the decision and the will of the core teams for sticking to their guns in this area. I had assumed that the reasons you give above were the motivating factors for being vigilant about the slower cadence of development and smaller ‘size’ of additions/alterations/removals to the standard library . But having it confirmed makes it very comfortable for me to think it is a nearly unqualified positive stance for the language to take.

I have seen your talk about the long future of Rust and I think there is the implication that you and the other Rust language developers are looking toward a 25-30 year timeframe (which encompasses nearly every language in wide spread use today) as the minimum expected lifespan of the language, with a view to be responsive and flexible enough to see the language continue to adapt and evolve throughout a longer period as well. With that type of longevity as an active consideration in planning the language’s growth/evolution I think Rust is setting a good precedent for non-BDFL style governance and stewardship of programming languages. I would hope a more long term compatible view takes hold in programming language development particularly, but general software development could probably stand to benefit if the time horizon was lengthened well beyond what seems to be standard today.

Re: Rust GCC backend: Why and how

#130
post #26

When I studied compiler theory, a large part of the compilation involved a lexical analyser (e.g. `flex`) and a syntax analyser (e.g. `bison`), that would produce an internal representation of the input code (the AST), used to generate the compiled files. It seems that the terminology as evolved, as we speak more broadly of frontends and backends. So, I'm wondering if Bison and Flex (or equivalent tools) are still in…

The other answers are great, but let me just add that C++ cannot be parsed with conventional LL/LALR/LR parsers, because the syntax is ambiguous and requires disambiguation via type checking (i.e., there may be multiple parse trees but at most one will type check). There was some research on parsing C++ with GLR but I don't think it ever made it into production compilers. Other, more sane languages with unambiguous g…

Not just C++. Even C parsing is context-dependent because of typedef. Requires a bit of hackery to parse in a conventional LL/LARL/LR parser.
Post reply on HN