News for hackers. Stuff that matters.
Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by lmm on Thursday June 22, 2017 @09:14AM (#14611975)
What we need is not to drop the optimising compiler entirely, but make the parts compilers are good at available for programers to use in a more controlled way. Something along the lines of what https://www.confluent.io/blog/turning-the-database-inside-ou... does to the database.
Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by nickpsecurity on Thursday June 22, 2017 @10:16AM (#14612368)
One might do something similar to what's done in high-assurance development. Namely, they do source-to-object code checks that ensure compiler optimizations haven't broken. Some of the IDE's will even pull up the code for you side-by-side. There's also CompSci and industrial work on verification tools that verify properties of C or SPARK; verify assembly properties or equivalence of two pieces of code. A short-cut might be to do a certified compilation to get code that definitely works, then do full-optimization of same function, and run the results of each through equivalence checks (formal or thorough testing).

I was already looking to doing something similar after seeing VeLLVM project and KLEE. Idea was to make an optimizing compiler generate each intermediate step in C code so KLEE can equivalence check it. Once low-level enough, do that in KLEE and/or VeLLVM. Naturally, this is so time-consuming that one would do it for code that doesn't change much or is just really critical. The component handling the commits in your link would be a candidate.

Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by lmm on Thursday June 22, 2017 @10:44AM (#14612571)
My hope is that giving the programmer more control over optimization, and keeping better track of program properties, would together allow more optimizations that are correct by construction. Like, give the developer visibility into whether an operation is going to be hoisted out of a loop by requiring them to express the fact that it doesn't change (or at least showing them why this was/wasn't inferred). And then a change that makes that stop working could (in the cases where the programmer expressed that they cared about the performance) become a compilation failure rather than a silent performance regression. As a thoroughly trivial example, scala's @tailrec works like this. At the moment it's only really possible because TRO is applied in Scala as a near-syntactic-level transformation rather than a low-level optimization, but if the transformation from syntax to machine code was more gradual and visible, maybe the same kind of thing could be applied more generally, and we could e.g. incorporate performance characteristics into the type system under understandable composition rules.
Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by chubot on Thursday June 22, 2017 @01:51PM (#14613994)
Yes I think this would be useful for solving the "order of optimization passes" problem. Right now I just treat my compiler as a black box. But if the guts were exposed a little bit, the compiler and I could work together to optimize a piece of code.

I could give it a few hints about what order might work, and it could show me what the intermediate representations are so that I can keep them in mind while writing code. There are patterns in C/C++ that trip up compilers, like unintentional aliasing or out params, and I could try to avoid them to help the optimizer. On the other hand, if the optimizer doesn't are, I will use them for my own convenience.

I suppose Clang has a pretty well-defined interface between passes, in the LLVM IR, so you can do this to some degree now. But it is a little obscure and probably version-dependent.

Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by DerSaidin on Thursday June 22, 2017 @06:40PM (#14615869)
For a human reading LLVM IR, it hasn't changed much between versions since at least 2.6.
Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by ChickeNES on Thursday June 22, 2017 @08:28PM (#14616317)
The problem is that there's no guarantee of stability in the IR, so either your stuck pinned to an old version of LLVM, or scrambling to keep up with each breaking change.
Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by mhh__ on Thursday June 22, 2017 @01:22PM (#14613790)
Optimizing compilers are purely an implementation detail of a language: This shouldn't leak into the language (If that's what you meant)
Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by lmm on Thursday June 22, 2017 @06:49PM (#14615909)
I used to think that, but I no longer do. Most code is plenty fast enough already, sure, but for the cases where performance is a requirement, it needs to be exposed and accessible in a way that the developer can work with it, the same way as for any other feature. Compare what's happened with 3D graphics APIs - OpenGL tried to abstract over the hardware capabilities and give the illusion that your card was always capable of everything, but actually that just resulted in developers having to almost reverse engineer what the OpenGL implementation was doing so that they could find out what the actual hardware fast path was and use it. So newer APIs concentrate on exposing more of the hardware details and giving the developer more precise control over what's going on.
Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by mhh__ on Thursday June 22, 2017 @08:17PM (#14616275)
That's the language design/philosophy, not specific details of how it was implemented.
Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by lmm on Friday June 23, 2017 @06:04AM (#14618070)
What distinction are you drawing? I think concerns like "this operation is O(n^2) in the length of the passed list" are absolutely the responsibility of the language, and probably even lower-level details. I'm not sure how to expose "this operation takes n machine-code instructions" without sacrificing cross-platformness, but I do think that's something we're going to need for important use cases (e.g. cryptographic libraries need to be able to do various things in constant time, which no existing language really has first-class support for).
Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by steveklabnik on Thursday June 22, 2017 @01:43PM (#14613944)
This is true in many cases, but there's subtleties.

Rust was designed to be optimized; this means unoptimized Rust code can easily be 2x-100x slower than optimized code. Given that speed is one of Rust's goals, yeah, you could implement a Rust compiler with no optimization, and that's fine. But it won't be usable to a significant chunk of users who rely on the speed.

Another way this can affect language design: Rust supports enums, which are a sum type. The memory layout of the enum is undefined at the language level. This is specifically so that compilers can do optimizations to make layout more compact than a naive implementation. In some sense, this is leaking optimization concerns out into language design.

Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by mhh__ on Thursday June 22, 2017 @02:24PM (#14614237)
I was imagining direct language ties to (say) LLVM passes, and things like that.

Designing the language around optimizability is a good thing, e.g. C++'s "as if" rule (in [intro.execution] in standards after C++11 (or near there)). Some of these options, which may or may not be used for optimization, can also be very useful for code quality/correctness: e.g. Language enforced purity (of functions) (in D) can be very useful for optimization (It's inferred in most compilers, but it can at least save a trip) and being able to trust (even a D function pointer) to be pure.

Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by pcvarmint on Wednesday June 28, 2017 @03:51AM (#14652405)
Fortran is better in this regard.
Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by cwzwarich on Thursday June 22, 2017 @02:51PM (#14614401)
If you have a fixed size stack, then it's impossible for optimizations to not leak into the language, because stack overflow is an observable failure.
Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by ACow_Adonis on Thursday June 22, 2017 @09:55PM (#14616662)
Doesn't that make the assumption that there is a hard and fast distinction between compiler and language?

That the compiler isn't fundamentally part of the language or integrated into the language itself?

I don't think that has to hold for all possible language designs...