News for hackers. Stuff that matters.
Re:Why Learn Compilers by mfranc42 on Monday May 29, 2023 @08:51PM (#36119956)
He probably meant that a compiler is a pure function for a given source file and a set of flags. Of course, if you change a compiler or flags, you can get something radically different, but you shouldn't get something radically different because it's Tuesday, midnight, your username starts with n, you have more than 3 hard drives, or because it reads some bytes from /dev/urandom.

It's bit of a stretch, sure, but I don't expect my performance problems to go away by recompiling stuff over and over again without changing either the code or flags and expecting the optimizer to make a better decision next time. It doesn't work that way.

Re:Why Learn Compilers by UncleMeat on Monday May 29, 2023 @09:40PM (#36120257)
Optimizing compilers often have budgets so you can get different outcomes if performance jitter happens to mean that it bails from some optimization stratagies.
Re:Why Learn Compilers by jcranmer on Monday May 29, 2023 @09:58PM (#36120366)
The budgets I've seen have less been "if it's taken N seconds, bail" and more "if we've processed X million instructions, bail." At least in the compilers I work on, nondeterminism is considered a bug, although it can be harder to avoid nondeterminism than you'd think.
Re:Why Learn Compilers by mathisfun123 on Monday May 29, 2023 @09:21PM (#36120138)
>and expecting the optimizer to make a better decision next time. It doesn't work that way

But in practice it does work exactly that way because of PGO and if we're precluding PGO then the observation is as banal as "programs that have no side-effects are pure". Like I get that the post is trying to paint some beautiful picture about how compiler passes are abstract beautiful transformations of representations of programs but it's not a useful picture at all.

Re:Why Learn Compilers by slavapestov on Monday May 29, 2023 @10:37PM (#36120566)
> Like I get that the post is trying to paint some beautiful picture about how compiler passes are abstract beautiful transformations of representations of programs but it's not a useful picture at all.

It is actually a very useful picture especially to a beginner.

PGO is an edge case and not used a whole lot in practice. Many compilers do not support it at all, even production compilers. Someone learning to write a compiler does not need to think about PGO. And besides, a compiler with PGO is still a pure function of source + flags + profile.

Re:Why Learn Compilers by mathisfun123 on Monday May 29, 2023 @11:00PM (#36120678)
>PGO is an edge case and not used a whole lot in practice. Many compilers do not support it at all, even production compilers.

Both clang and gcc support `-fprofile-generate`. Beyond that generic infrastructure, in my area (DL compilers) if you're not doing PGO/autotuning you're not serious.

>Someone learning to write a compiler does not need to think about PGO.

That's like saying someone learning to write a compiler doesn't need to think about optimization at all - sure maybe the first time. But then every time after that it should be at the forefront of your mind.

Re:Why Learn Compilers by slavapestov on Monday May 29, 2023 @11:35PM (#36120853)
> Both clang and gcc support `-fprofile-generate`. Beyond that generic infrastructure, in my area (DL compilers) if you're not doing PGO/autotuning you're not serious.

How many binaries in a typical Linux distro are built with PGO for example? The answer is approximately zero.

Re:Why Learn Compilers by mathisfun123 on Monday May 29, 2023 @11:57PM (#36120981)
Your point? Because your first goalpost was "most compilers don't even support PGO". And now the goalpost is Linux distros? How about this one - how many binaries at FB/G are built with PGO? Answer: a great deal (llvm/bolt is a FB project and MLGO is a G project).
Re:Why Learn Compilers by slavapestov on Tuesday May 30, 2023 @12:04AM (#36121010)
My point is that the view of a compiler as a series of transformation passes from a source program to machine code, implemented as pure functions, is an entirely appropriate way to describe how they work in a random introductory blog post?

Congratulations on your recent PhD in quantum machine learning or whatever -- I hope you find some way to speed up FB/G's ad serving algorithms by 1% and land that promotion. I'm sure you're very smart.

Re:Why Learn Compilers by mathisfun123 on Tuesday May 30, 2023 @12:09AM (#36121027)
>My point is that the view of a compiler...

Your point in bringing up Linux was to reiterate your original point? Interesting.

> I hope you find some way to speed up FB/G's ad serving algorithms by 1% and land that promotion. I'm sure you're very smart.

lol

Re:Why Learn Compilers by mfranc42 on Monday May 29, 2023 @10:39PM (#36120577)
I don't remember using PGO like ever. And even if you do use it, isn't it like breaking compilation into two phases that are themselves deterministic?

It is pretty useful picture in my eyes, because that's what I've been observing since like forever. Non-deterministic compiler would be pretty hard to test or reason about.

It might be a banal observation, but an important one if you want to contrast a compiler with something like an OS kernel or most modern programming projects that interact heavily with outside world. When you throw hardware, network traffic, or users into the mix, it gets crazy.

Re:Why Learn Compilers by cxr on Tuesday May 30, 2023 @08:40AM (#36124124)
* * *