by dkarapetyan · 9y ago · 0 comments
So it's more than just sufficient cleverness. It is also about the language providing you the tools to express certain invariants that the compiler can mechanically verify and then use in an optimization pipeline.
Edit: This is mostly out of context now and can be ignored.
Oh, nm. I can edit.
It means that it's not a reply anymore, it's at the top level, on its own, usually at the bottom of the page. Think of comments as a tree: this was a leaf, then was detached from its sub-tree.
(See also: partial evaluation, Futamura projection)
> It is also about the language providing you the tools to express certain invariants that the compiler can use.
Compiled code is useless if it is never called. The moment it's called, whether the caller is known during compilation or not, the caller can pass down any additional information it has, whether for that call or to help the callee optimize future calls. Heck, if it really wants to, the compiler could simply let the "compiled" code be the AST or source code itself (plus a JITter), and make the program generate code on the fly when the caller calls it, optimized using whatever information the caller is willing to provide. Again, nothing fundamentally in a language preventing this. It a tradeoff between implementation difficulty, execution latency, program size, and the like.
Compilers, optimizations, type systems, and proof systems are all very closely related and if you want correct optimizations then you must annotate your code with types that the compiler can verify and use as assumptions in an optimization pipeline. These things are not easy to engineer. Saying just JIT it doesn't make much sense.
This is just trivially wrong. You can always add checks that it is a thing that lets you optimize better. You can always just JIT in addition to static compilation.
Guess I can also solve all pointer aliasing problems by just adding "if p != q {...}".
Note: I'm one of these compiler writers. In fact, i'm one of the compiler writers who wrote the current aliasing implementations for the two major compilers everyone uses, among other things. If you are going to disagree, please be concrete. I'm stating that good enough aliasing algorithms exist to do what you want, and where you can't, you can do runtime checks.
People who truly care about performance hand the compiler the whole program, and want it to do a great job. It can and will. Your counter argument is what, exactly.
That because people spend time getting type systems right, this must be false?
If so, that's just silly. People spend time on getting type systems right to make it easier to reason about for people. Not because it's impossible at the compiler level. But because they'd rather not have to do it if they can avoid it. That doesn't mean it can't be done, and isn't done.
Seems like all I need to do is bone up on alias analysis, JITing, and inlining and I'm good to go.
Yeah.
> I wonder then why all these compiler writers spend so much time on getting the type system right if all they need to do is just add some if statements then add a JIT.
Because (1) JIT has a latency hit users like to avoid, and (2) you still have to solve the same problem during JIT time, it doesn't magically go away.
You can often inline it. Now that may or not yield improvements in speed, but more to the point: It's quite possible that it's used in a context where x is bounded sensibly, and you can optimize further from there.