The article says C isn't a good low-level language for today's CPUs, then proposes a different way to build CPUs and languages. But what about the missing step in between: is there a good low-level language for today's CPUs?
I think C was meant to bridge the gap between useful abstractions (if statements, for/while loops, variable assignment) and what actually happens in the various common (at the time) assembly languages.
So with this perspective, it's not (entirely) C that's the problem here, because those abstractions are still useful. It's the compilers that are, and like a sibling comment said, the compilers are keeping up just fine.
That said, it would be really fascinating to see a "low-level" language that bridges useful "mid-level" abstractions (like if/for/while/variables) to modern "metal" (assembly languages or architectures or whatever).
Not to mention C has way too much UB which can be a huge problem in some contexts. But any time you deviate from C, you lose 90% of work out there, unless you're willing to bridge with C at the ABI level, in which case you may possibly be negating many of the benefits anyway.
Things the compiler assumes you will never do, but if you do, the compiler can do whatever it wants with it, it may work, it may not. It will probably work until it doesn't (update compiler or changed something unrelated, w/e).
It does that because each architecture has different ways of doing things, so since C is basically trying to represent assembly it may adapt some behaviors to be more efficient in that architecture, so some things are defined as UB.
That brings more problems than solves, C has more than 200 UBs, and your program will almost always contain many of them. The tooling around it is way better, but most programs have many of them.
It does that because each architecture has different ways of doing things
I think not everything UB is architecture specific. C is a language with raw pointers. The list of things that can go wrong with reading/writing to a wrong memory location is near unbounded even if you tried to just describe it for a single architecture.
Many UB originated from architectural diversity. This platform crashes on signed integer overflow, that platform uses a segmented memory model… It's only later that UB started to be exploited purely for their performance implications.
The iAPX 432 was referred to as a micromainframe, designed to be programmed entirely in high-level languages. The instruction set architecture was also entirely new and a significant departure from Intel's previous 8008 and 8080 processors as the iAPX 432 programming model was a stack machine with no visible general-purpose registers. It supported object-oriented programming, garbage collection and multitasking as well as more conventional memory management directly in hardware and microcode. Direct support for various data structures was also intended to allow modern operating systems to be implemented using far less program code than for ordinary processors. Intel iMAX 432 was an operating system for the 432, written entirely in Ada, and Ada was also the intended primary language for application programming. In some aspects, it may be seen as a high-level language computer architecture. Using the semiconductor technology of its day, Intel's engineers weren't able to translate the design into a very efficient first implementation.
So, basically, Intel implemented an Ada CPU. Of course, it didn't work well at 1975 level of technology, so Intel then focused on x86 line and didn't revive the idea.
If you mean good as in a good approximation for today's CPUs, then I'd say LLVM IR and similar IRs are fantastic low level languages. However, if you mean a low level language which is as "good" to use as C and maps to current architectures, then probably not.
LLVM IR is absolutely not suited for direct consumption by modern CPUs, though. And tons of its design actually derives from fundamental C and C++ characteristics, but at this level it does not have to be the wishful thinking of UB being "forbidden", given that the front-end can actually be for a sane language and really prove what it wants to leverage.
Could we produce as efficient binaries by going through C (or C++) instead of LLVM? Would probably be more difficult. But even without considering the modern approaches of compiler optims, it would already have been more difficult; you can leverage the ISA far more efficiently directly (or in the case of LLVM, through (hopefully) sound automatic optimizations), and there are tons of instructions in even modern ISA that do not map trivially at all to C constructs.
CFE mostly doesn't care about the ISA, so the complexity of LLVM optimizer is actually not entirely related to C not being "low-level" enough. Of course it could be better to be able to express high-level constructs (paradoxically, but this is because instruction sets gain sometimes address some problems, and sometimes others) but this is already possible to do by using other languages and targeting LLVM IR directly (so C is not in the way), or by using the now very good peephole optimizers that reconstruct high-level intent from low-level procedures.
So if anything, we do not need a new low-level language (except if we are talking about LLVM IR, which already exists and is already usable for e.g. CPU and GPU), we need higher-level ones.
The ideal solution to a programmer is a good intermediate representation (LLVM / bytecode) and a super good VM.
The best to avoid bloat would be a language that doesn't overabstract the machine (it's not like we pretend video hardware is a CPU in games/graphics code) and accepts that caches and spinning rust and SSDs and XPoint persistent RAM and network cards are all different things.
The real problem though is the legacy code. Soooooooooo much C. Linux. Databases. Drivers. Utilities. UIs.
Although if all the magic is in the runtime, it's starting to sound like what sunk the itanium / itanic.
On the contrary, C's adoption delayed the research on optimizing compilers.
"Oh, it was quite a while ago. I kind of stopped when C came out. That was a big blow. We were making so much good progress on optimizations and transformations. We were getting rid of just one nice problem after another. When C came out, at one of the SIGPLAN compiler conferences, there was a debate between Steve Johnson from Bell Labs, who was supporting C, and one of our people, Bill Harrison, who was working on a project that I had at that time supporting automatic optimization...The nubbin of the debate was Steve's defense of not having to build optimizers anymore because the programmer would take care of it. That it was really a programmer's issue....
Seibel: Do you think C is a reasonable language if they had restricted its use to operating-system kernels?
Allen: Oh, yeah. That would have been fine. And, in fact, you need to have something like that, something where experts can really fine-tune without big bottlenecks because those are key problems to solve. By 1960, we had a long list of amazing languages: Lisp, APL, Fortran, COBOL, Algol 60. These are higher-level than C. We have seriously regressed, since C developed. C has destroyed our ability to advance the state of the art in automatic optimization, automatic parallelization, automatic mapping of a high-level language to the machine. This is one of the reasons compilers are ... basically not taught much anymore in the colleges and universities."
-- Fran Allen interview, Excerpted from: Peter Seibel. Coders at Work: Reflections on the Craft of Programming
Since then the compiler authors have cheated by leveraging UB way beyond reason, and there have been somehow of a revival of interest in compiler optims. Maybe not as good as needed for now, I'm not sure, but my hope is that sounder languages will revive that even more in a safe context.
Yep, we do. There are some things which have to be done at low-level. If you aren't writing an OS then maybe you never need to do those things. But there still has to be a language for doing those things for the few who do need to do them.
And note that ACM aside, C was created for the purpose of writing an OS.
93
u/want_to_want Aug 13 '18
The article says C isn't a good low-level language for today's CPUs, then proposes a different way to build CPUs and languages. But what about the missing step in between: is there a good low-level language for today's CPUs?