News for hackers. Stuff that matters.
Re:Introducing the B3 JIT compiler by munificent on Monday February 15, 2016 @11:35AM (#11104225)
Really cool article. Posts like this always make me wonder what the state of the programming would be if browsers hadn't sucked up almost all of the world's compiler optimizers.
Re:Introducing the B3 JIT compiler by beagle3 on Monday February 15, 2016 @02:25PM (#11105313)
Look at what Mike Pall did with LuaJIT2 - I assume if the world wasn't so focused on the web, we would see more of it in other languages. But really, things aren't that bad. Microsoft has enough good people working on RyuJIT, PyPy has some of the best people advancing metatracing JITs, and Mike Pall is a god among men.
Re:Introducing the B3 JIT compiler by eyan on Tuesday February 16, 2016 @05:52AM (#11109044)
The Father, The Son, The Holy Ghost, and Mike Pall.
Re:Introducing the B3 JIT compiler by ajross on Monday February 15, 2016 @11:43AM (#11104270)
To be fair, GPU vendors sucked up a ton too.

But considering that optimized scalar code performance has moved, what, maybe 40% over the last two decades, I'm going to say "not much". Compilers are sexy, but they're very much a solved problem. If we were all forced to get by with the optimized performance we saw from GCC 2.7.2, I think we'd all survive. Most of us wouldn't even notice the change.

Re:Introducing the B3 JIT compiler by kannanvijayan on Monday February 15, 2016 @01:57PM (#11105166)
I'd disagree. Classical compiler work is very mature, yes - and new progress in things like register allocation and backend IR-based optimization stuff is well trod ground.

But in the context of JIT compilers for dynamically typed languages, in particular the space involving runtime inferred hidden type models, there is a TON of work left on the table.

It hasn't been paid much attention to in academia, IMHO largley because of a historical perspective on optimizing dynamic languages as "not classy" work among language theorists. I hope that perspective changes over time.

Re:Introducing the B3 JIT compiler by munificent on Monday February 15, 2016 @12:04PM (#11104406)
> Compilers are sexy, but they're very much a solved problem.

Not for all of the other widely-used languages that still have incredibly simple interpreters. Think how much energy could have been saved if Ruby, Python, and PHP were all as fast as your average JS engine.

Re:Introducing the B3 JIT compiler by seanwilson on Monday February 15, 2016 @02:44PM (#11105434)
> Think how much energy could have been saved if Ruby, Python, and PHP

I would think we'd see even better improvements if developers would move towards statically typed languages as well.

Re:Introducing the B3 JIT compiler by VeejayRampay on Monday February 15, 2016 @12:18PM (#11104511)
Exactly. Ruby would probably have massive adoption with JS-like speed.
Re:Introducing the B3 JIT compiler by chrisseaton on Monday February 15, 2016 @01:45PM (#11105104)
My implementation of Ruby, JRuby+Truffle, is as fast as V8

http://stefan-marr.de/downloads/crystal.html

Re:Introducing the B3 JIT compiler by pizlonator on Monday February 15, 2016 @02:44PM (#11105436)
Note that usually being "as fast as" a production JSVM means also proving that you can start up as fast as JSVMs do. Have you done this?
Re:Introducing the B3 JIT compiler by ehsanu1 on Monday February 15, 2016 @03:22PM (#11105658)
Search around for "Substrate VM". I see it referenced in some slide decks, and it's designed to make JVM startup much faster.

Here's an old slidedeck that talks about it: http://www.oracle.com/technetwork/java/jvmls2013wimmer-20140...

Re:Introducing the B3 JIT compiler by ksec on Monday February 15, 2016 @05:04PM (#11106401)
Wow thx for the reminder, I have forgotten about it already. I remember the promise of Truffle + Graal + Substrate VM.

My god can't believe it was 3 years ago i read about it on HN.

Re:Introducing the B3 JIT compiler by pizlonator on Monday February 15, 2016 @03:25PM (#11105681)
I know about it. I'm not concerned with future hypotheticals, but current actual measurements.

That's the currency I deal in.

Re:Introducing the B3 JIT compiler by ehsanu1 on Monday February 15, 2016 @08:56PM (#11107426)
There seem to be measurements in the slides I reference, so it wasn't exactly "future work". But of course it sucks that this work is not yet publicly available (AFAIK), probably due to not being 100% production ready yet. But I'm sure it's getting there.
Re:Introducing the B3 JIT compiler by ajross on Monday February 15, 2016 @12:29PM (#11104595)
Ruby has massive adoption, as do Python and Perl and PHP. Environments with objectively better performance like the JVM and .NET have not, in fact, done all that well comparatively in this environment (which is to say they've done fine too and achieved "massive" adoption, just not that much better than their slower competitors).

In fact, looking at the market as it stands right now I'd say that performance concerns are almost entirely uncorrelated with programming environment adoption.

Re:Introducing the B3 JIT compiler by yxhuvud on Monday February 15, 2016 @01:14PM (#11104912)
Considering the massive speed improvements we have been seeing in Javascript, but also languages like Ruby, I'd say compilers is a solved problem for staticly compiled languages, but perhaps not as much for interpreted highly expressive languages.
Re:Introducing the B3 JIT compiler by abecedarius on Monday February 15, 2016 @01:48PM (#11105119)
Sort of. Lisp had a good combo of expressiveness and speed in the 80s, but it reached that point on the efficiency frontier by different techniques, like heavier use of macros. The newer techniques like trace compilation can make life even better, but the language design decisions in Ruby/Python/etc. that made that sort of thing necessary if you want speed, they didn't really pay for themselves from the perspective of smug Lisp weenies like me who were happy enough with our language and just wanted pragmatics like libraries.
Re:Introducing the B3 JIT compiler by sklogic on Monday February 15, 2016 @02:47PM (#11105454)
Did you just call Javascript a "highly expressive" language? Really?!?
Re:Introducing the B3 JIT compiler by pizlonator on Monday February 15, 2016 @03:34PM (#11105735)
LOL! It is expressive though. It's got really powerful first-class functions. It's got classes. It's got prototypes. It's got generators. It's got other things that I don't even remember (but will probably have to learn, to implement them, make them fast, and then fix the bugs).

I actually think that the reason why JS is so odd is that it is so expressive. That tends to happen with kitchen sink languages like C++.

Relevant: "There are only two kinds of programming languages: those people always bitch about and those nobody uses."

Re:Introducing the B3 JIT compiler by raattgift on Tuesday February 16, 2016 @06:08AM (#11109109)
Cool. "We took a dynamic language and made it fast(er again)".

And you're gonna apply that to the darkest corners of ES6? Whee, language theory nerd paradise!

I can't wait for the compilers targeting that using all sorts of really odd idioms that in effect work like fuzz testing.

https://www.destroyallsoftware.com/talks/the-birth-and-death...

Re:Introducing the B3 JIT compiler by sklogic on Monday February 15, 2016 @05:07PM (#11106417)
More expressive than a less imaginative subset of C. More expressive than assembler. Much less expressive than any decent high-level language.

Javascript is low level, primitive and clumsy. There is absolutely no excuse for it being so crappy.

If you still think it is "expressive", you never seen an expressive language.

Re:Introducing the B3 JIT compiler by pcwalton on Monday February 15, 2016 @06:48PM (#11106945)
> If you still think it is "expressive", you never seen an expressive language.

Are you aware who Filip Pizlo is?

Re:Introducing the B3 JIT compiler by sklogic on Monday February 15, 2016 @07:36PM (#11107129)
Of course - a low level guy. It is quite likely that he is either not exposed at all to any expressive languages or reject them out of ideological reasons (JikesRVM is quite a strong symptom of the latter case).
Re:Introducing the B3 JIT compiler by pcwalton on Monday February 15, 2016 @07:53PM (#11107212)
I have no idea what the Jikes RVM has to do with "ideology". The point is that you're trying to tell someone who has a significant academic and industrial PL pedigree that they don't know what an expressive language is.

You seem to have an intense dislike of JavaScript. I'll the first one to admit that JavaScript has a lot of problems. But not being expressive enough is not one of them. JS is, if anything, too dynamic and expressive.

Re:Introducing the B3 JIT compiler by sklogic on Monday February 15, 2016 @10:41PM (#11107758)
Yes, if he thinks that JS is expressive he does not know what is expressive. And his track record clearly lacks anything related to any expressive language. I can only explain it with an ideology, because ignorance is not an option here.

And, no, JS is not expressive. It got strict limits on an available level of abstraction (unless you go into eval, of course).

Re:Introducing the B3 JIT compiler by pizlonator on Monday February 15, 2016 @12:35PM (#11104652)
ajross is right. People choose the languages they like regardless of performance.

JS perf is important to users though. Faster execution means fewer watts spent rendering and interacting with your favorite web page.

(Fun fact: B3's backend contains a machine description language that gets compiled to C++ code by a ruby script, opcode_generator.rb. We use Ruby a lot.)

Re:Introducing the B3 JIT compiler by cosinusoidally on Monday February 15, 2016 @03:56PM (#11105892)
Why didn't you use JavaScript for that purpose (in a similar vein to how LuaJIT uses Lua for dynasm)?
Re:Introducing the B3 JIT compiler by pizlonator on Monday February 15, 2016 @04:19PM (#11106082)
I'm not a big fan of self-hosting. I like that you can build JavaScriptCore without using JavaScriptCore.
Re:Introducing the B3 JIT compiler by cosinusoidally on Monday February 15, 2016 @08:39PM (#11107376)
I wasn't really referring to self hosting. I was wondering whether it made sense to write tools like JavaScriptCore's offlineasm in JavaScript rather than Ruby (as LuaJIT does by using Lua for its dynasm tool). The LuaJIT build process actually builds a cut down copy for Lua for the purposes of running dynasm, which is then used to build parts of LuaJIT.
Re:Introducing the B3 JIT compiler by pizlonator on Tuesday February 16, 2016 @12:22AM (#11108045)
We spend time optimizing JavaScriptCore's build time. It's a hard problem and it's important when managing such a large project. People inevitably have to do clean builds and that sucks when you have >400k lines of C++ code.

So, naturally, we want to avoid building JSC twice. ;-)

Re:Introducing the B3 JIT compiler by iso-8859-1 on Monday February 15, 2016 @07:42PM (#11107163)
Suppose that you are developing not to push this platform, but to simple do better on this platform. What does self-hosting gain you in that case?
Re:Introducing the B3 JIT compiler by geodel on Monday February 15, 2016 @12:27PM (#11104577)
Lately quite a few apps are saving energy by moving from Ruby/Python/PHP to Go.
Re:Introducing the B3 JIT compiler by pcwalton on Monday February 15, 2016 @01:25PM (#11104985)
And Go proves munificent's point: it doesn't have many compiler optimizations either. (This may change with the WIP SSA backend, but the point remains that Go gained huge popularity in spite of having a non-optimizing compiler.)
Re:Introducing the B3 JIT compiler by pjmlp on Monday February 15, 2016 @02:23PM (#11105295)
Yeah, more interesting is having them rediscovering Turbo Pascal compile speeds.

EDIT: I wonder why the positive effect to re-discovering that not all compilers need to be like C and C++ compile speeds and that it was once upon a time mainstream, is worthy of downvotes.

Re:Introducing the B3 JIT compiler by nickpsecurity on Monday February 15, 2016 @03:15PM (#11105615)
Can't critique this one: Go was an attempt to re-create the Oberon experience in modern setting with some additions from other languages. Rather than accidental re-discovery, getting Oberon (not Pascal) speed out of the compiler was an explicit design goal. One of few examples of modern IT really learning from the past.

Unfortunately, they didn't learn about the stuff between Oberon and 2007 that would've been nice to have in a modern, app language. ;)

Re:Introducing the B3 JIT compiler by pjmlp on Monday February 15, 2016 @03:38PM (#11105767)
It is not a critic, apparently it was understood as such.

The remark is tailored to those that think compiled languages can only be slow as C and C++ compilers, since they never used anything else, and then jump of joy when they use Go.

Yet if it wasn't for the VM detour of the last 20 years, that experience would probably be a current one, instead of being re-discovered.

Re:Introducing the B3 JIT compiler by nickpsecurity on Monday February 15, 2016 @04:04PM (#11105955)
"The remark is tailored to those..."

Ahh. Ok.

"Yet if it wasn't for the VM detour of the last 20 years"

You mean the C++ and VM detours? ;)

Re:Introducing the B3 JIT compiler by pjmlp on Monday February 15, 2016 @04:37PM (#11106214)
I mean having the JVM not adopt the tooling model of Eiffel, OCaml and others where you get to choose bytecode/JIT for developing and AOT compilation for release builds.
Re:Introducing the B3 JIT compiler by nickpsecurity on Monday February 15, 2016 @05:11PM (#11106438)
Oh i hear you. That makes sense. I wanted all of them to do incremental compilation or interactive development for build then AOT for deploy. We're on same page there.
Re:Introducing the B3 JIT compiler by srean on Tuesday February 16, 2016 @09:28AM (#11109980)
For the curious (I am sure pjmlp is well aware of this) D and Go compile speeds are pretty neck and neck. DMD was faster, then Go caught on, not sure which one is faster now, depends on the nod. If I may add, D is a lot less impoverished than Go, although its coroutines story is not that strong.
Re:Introducing the B3 JIT compiler by geodel on Monday February 15, 2016 @03:19PM (#11105640)
Are you claiming Go runs at the speed of Ruby/Python/PHP etc? Because from what I read, migration to Go from above mentioned language led to lot of hardware / memory saving. I'd think Java can certainly be considered having highly optimized compiler / runtime. But it has almost same performance as Go and much higher memory usage compared to Go.

http://benchmarksgame.alioth.debian.org/u64q/go.html

Re:Introducing the B3 JIT compiler by pcwalton on Monday February 15, 2016 @03:25PM (#11105683)
> Are you claiming Go runs at the speed of Ruby/Python/PHP etc?

No. I'm claiming it doesn't perform anywhere near the level of optimization of GCC and LLVM.

> I'd think Java can certainly be considered having highly optimized compiler / runtime. But it has almost same performance as Go and much higher memory usage compared to Go.

I disagree with what seems to be your implication that compiler optimizations don't matter (and almost everyone else who works on compilers would also disagree), but I don't really want to turn this thread into a critique of the benchmarks game, so let's just leave it at that.

Re:Introducing the B3 JIT compiler by igouy on Monday February 15, 2016 @07:39PM (#11107146)
> … and much higher memory usage compared to Go.

Please don't jump to the conclusion that huge differences in the default memory allocation of tiny 100 line programs means there will be similar huge differences between ordinary large programs.

Notice that even for those tiny 100 line programs, the difference can be more like 2x when memory actually needs to allocated for the task.

Re:Introducing the B3 JIT compiler by derefr on Monday February 15, 2016 @04:37PM (#11106222)
"Compiler optimization" in this thread is referring to speeding up compilation time†, not runtime of generated code. Go produces fast code, but the go compiler does not generate that code particularly quickly.

† Which can be seen as a runtime cost for interpreter+JIT languages, but that's a different issue. We're talking time-to-steady-state when the interpreter is fed a file (which is something Javascript engine devs worry about a lot), not benchmark-speed-at-steady-state.

Re:Introducing the B3 JIT compiler by pcwalton on Monday February 15, 2016 @05:03PM (#11106392)
No, it's the opposite. The Go compiler generates medium quality code but compiles fast.
Re:Introducing the B3 JIT compiler by sklogic on Monday February 15, 2016 @02:46PM (#11105441)
If Ruby, Python and PHP would suddenly disappear, even more effort and energy would have been saved.
Re:Introducing the B3 JIT compiler by mafribe on Monday February 15, 2016 @01:47PM (#11105112)

    Compilers are sexy, but they're very much a solved problem.
This may be true for sequential languages, but is very much false for the compilation of concurrency and parallelism. It's basically not known how to do this well. Part of the problem is that CPU architectures with parallel features have not yet stabilised.

For sequential languages the problem has shifted: how can I get a performant compiler easily. The most interesting answer to this question is PyPy's meta-tracing, and that's work is from 2009, and far from played out.

Re:Introducing the B3 JIT compiler by pcwalton on Monday February 15, 2016 @01:23PM (#11104973)
> Most of us wouldn't even notice the change.

A 40% decrease in optimization is enough to drop framerates from 60fps to 30fps easily, so I'm pretty sure we would notice it.

Re:Introducing the B3 JIT compiler by nly on Monday February 15, 2016 @05:34PM (#11106561)
> optimized scalar code performance has moved, what, maybe 40% over the last two decades

I'm not convinced. Raw single-thread number crunching performance is somewhere around _two to three fold_, clock-for-clock, on Intel x86, over that of 10-15 years ago. What methodology do you use to attribute only a fraction of those gains to language optimizers? And even if you are correct, why is it meaningful? Who is going to have invested energy in optimising the shit out of mundane codegen when hardware performance will have just come and stolen your thunder a few months later?

The problem we have now is that CPUs are gaining ever more complex behaviour, peculiarities, and sensitivities. I'd say compiler engineering is far from a "solved problem", even for statically-typed languages.

Re:Introducing the B3 JIT compiler by rayiner on Monday February 15, 2016 @06:30PM (#11106870)
> The problem we have now is that CPUs are gaining ever more complex behaviour, peculiarities, and sensitivities.

With mainstream CPUs, exactly the opposite is happening. CPUs are getting more complex under the hood, but less sensitive to code quality. For example, a lot of the scheduling hazards in the P6 microarchitecture have been eliminated in subsequent iterations. Branch delay slots are a thing of the distant past, so are pipeline bubbles for taken branches, indirect branch prediction is extremely capable, even the penalty on unaligned accesses is minimal.

Re:Introducing the B3 JIT compiler by pcwalton on Monday February 15, 2016 @06:54PM (#11106971)
Well, sure, but SIMD more than compensates for all of that, given how hard autovectorization is. In fact, I think with things like AVX and NEON becoming ubiquitous, you can get more benefit out of writing in assembly (or intrinsics) than any time I can think of in the past 10 years.
Re:Introducing the B3 JIT compiler by Joky on Monday February 15, 2016 @08:22PM (#11107327)
> Compilers are sexy, but they're very much a solved problem

No they're not, and won't be for long (ever?). However it does not matter because they are "good enough".

Compilers are driven by heuristics which provide "reasonable" results in most cases for common architectures. But they still leave a lot on the table. Compiler writers have to trade compile-time with execution-time. Now we're not talking about an order of magnitude, but rather ~20%-30% in some workloads. When it matters (I guess for people like Google/Facebook/Amazon/... it translates in electricity bill and a number of racks to add to the datacenter) people may have to get down to the assembly level for a very small (and hot) part of the program.

Re:Introducing the B3 JIT compiler by mrspeaker on Monday February 15, 2016 @01:45PM (#11105106)
That seems a bit chicken-and-the-egg-y though: if the web didn't become a global phenomenon then there would be far less interest in improving the browsers, far less business need for programmers, and far fewer people working on whatever they'd be working on if they weren't working on browsers.
Re:Introducing the B3 JIT compiler by sklogic on Monday February 15, 2016 @01:21PM (#11104957)
They're solving a non-issue. The rest of the world is perfectly fine with the statically typed, well designed languages that are easy to compile. And only the web world is so obssessed with smart compilers compensating (impressively, but still far from being sufficient) for multiple deficiencies in the language design.
Re:Introducing the B3 JIT compiler by pcwalton on Monday February 15, 2016 @01:27PM (#11105003)
> The rest of the world is perfectly fine with the statically typed, well designed languages that are easy to compile.

Python, Ruby, PHP, and Perl aren't "the rest of the world"? As far as compilers are concerned, all of those languages have more troublesome semantics than JavaScript does.

> And only the web world is so obssessed with smart compilers compensating (impressively, but still far from being sufficient) for multiple deficiencies in the language design.

You have no idea how much compilers have to compensate for the deficiencies in C and C++'s design.

Re:Introducing the B3 JIT compiler by sklogic on Monday February 15, 2016 @02:41PM (#11105418)
Nobody really cares about their performance. They're just fine with their simple interpreters. Web is different, there is no choice, no fallback to C.

And no, thank you kind sir, but I've got a very good idea of what compilers are doing wrt. C deficiencies, I was writing OpenCL compilers for 6 years at least. Besides aliasing stupidity and byte-addressing there is nothing really bad to compensate for.

Re:Introducing the B3 JIT compiler by pcwalton on Monday February 15, 2016 @03:20PM (#11105648)
> Web is different, there is no choice, no fallback to C.

asm.js and Web Assembly.

> Besides aliasing stupidity and byte-addressing there is nothing really bad to compensate for.

Aliasing issues, C++ heavy reliance on virtual methods, too many levels of indirection in the STL, overuse of signed integers due to "int" being easier to type interfering with loop analysis, const being useless for optimization, slow parsing of header files...

Re:Introducing the B3 JIT compiler by pizlonator on Monday February 15, 2016 @06:35PM (#11106896)
All of this!

For example in JS, once you prove that "o.f = v" is not going to hit a setter (or you put a speculative check to that effect), then you know that this effect does not interfere with "v = o.g" (provided you check that it's not a getter). JS VMs are really good at speculating about getters and setters. The result is that alias analysis, and its clients like common subexpression elimination, are super effective. It's only a matter of time before we're creating function summaries that list all of the abstract heaps that a procedure can clobber so even a function call has bounded interference.

This is totally different from C. There, making sure that accesses to o->f and o->g don't interfere is like pulling teeth. And the user can force you to assume that they always interfere by using -fno-strict-aliasing, which is hugely popular.

The fallback-to-C paths on the web aren't that great, though. At least not yet. Once you fall back to C, you're sandboxed into a linear heap with limited access to the DOM and JS heap. But we'll fix that eventually. :-)

Re:Introducing the B3 JIT compiler by sklogic on Monday February 15, 2016 @06:47PM (#11106941)
Web Assembly is not even there yet, asm.js up until recent was more a toy and a standalone runtime, I have not seen it being routinely used for a fallback, nothing like, say, python with C modules.

As for virtual methods, it is a problem of a bad C++, devirtualisation may help, but nobody cares in general. We have a cool curiously recurring template pattern instead.

But for the integers you're right. And signedness is still the most annoying source of bugs in the infamous LLVM instcombine.

Headers are a frontend issue, nothing to do with the optimisations.

Re:Introducing the B3 JIT compiler by pcwalton on Monday February 15, 2016 @07:59PM (#11107241)
> Web Assembly is not even there yet, asm.js up until recent was more a toy and a standalone runtime, I have not seen it being routinely used for a fallback, nothing like, say, python with C modules.

That's because (a) page performance is frequently gated on things other than JavaScript, so people don't go through a lot of trouble to write C++; (b) many modules that would be written in C in Python are provided by the browser itself; (c) JS itself is usually fast enough, since the gap between JS and C++ is much less than the gap between Python and C++.

> As for virtual methods, it is a problem of a bad C++, devirtualisation may help, but nobody cares in general.

Huh? Tons of people care about devirtualization! Much of the reason Firefox builds go to the trouble of PGO (and it is a huge amount of trouble) is to get devirtualization.

> As for virtual methods, it is a problem of a bad C++

So I could say the same thing about JavaScript: if it's slow, you're writing "bad JS". But you would rightly reject that as invalid: if the code people write in practice is slow, then the problem is with the language encouraging people to write slow code. The point is that the same thing applies to C++.

Re:Introducing the B3 JIT compiler by sklogic on Tuesday February 16, 2016 @07:58AM (#11109509)
See? The evolution of the language and its ecosystem was driven by the peculiar web needs. No surprise the language became what it is now. No surprise it sucks shit every time it spills out of its native domain.

As for C++ - there is a choice. With JS the choice is much more limited. You either rely on non-standard asm.js behaviour, lose DOM access with web assembly, or tolerate the stupidity and limitations of the language that far overgrown its tiny niche.

Btw., I am yet to hear how a language with a fixed syntax and no macros can be perceived as "highly expressive".

Re:Introducing the B3 JIT compiler by gpderetta on Tuesday February 16, 2016 @05:23AM (#11108943)
Re: int, isn't it the reverse? I.e. don't compilers find loops using ints easier to optimise because they can assume the counter does not wrap?

Also, what do you mean by level of indirection in the STL? Pointer chasing or, I suspect, layers of layers of tiny functions that need to be inlined for reasonable performance?

Re:Introducing the B3 JIT compiler by geofft on Monday February 15, 2016 @02:17PM (#11105266)
> statically typed, well designed languages that are easy to compile

Which ones are these? All of the statically-typed and well-designed languages I can think of are, at the least, hard to compile well, if not hard to compile in the first place. (Haskell and Rust both come to mind; there are few Haskell compilers other than GHC, and no Rust compilers other than rustc.) The languages that are easier to compile are either not statically-typed in a useful way, or not well-designed, or both.

Re:Introducing the B3 JIT compiler by gsg on Monday February 15, 2016 @02:32PM (#11105354)
SML? Pascal?

Edit: I was really referring to language families, so including things like OCaml, Modula, etc.

Re:Introducing the B3 JIT compiler by sklogic on Monday February 15, 2016 @02:43PM (#11105429)
Rust is actually quite easy to compile. Ada is easy to compile. ML-like languages are easy to compile. Oberon is trivial to compile.
Re:Introducing the B3 JIT compiler by nickpsecurity on Monday February 15, 2016 @03:17PM (#11105627)
I've never heard anyone say Ada was easy to compile. Also, I heard its uptake was slowed by how hard it was to get the early compilers working. So, where did you see an easy one? Seriously, because Ada still needs a CompCert (or at least FLINT) style certified compiler. An easy Ada compiler would be a nice start on that.
Re:Introducing the B3 JIT compiler by pizlonator on Monday February 15, 2016 @03:29PM (#11105697)
I always thought that Ada was easy to compile in the backend (i.e. the moral equivalent of what B3 does) but challenging on the frontend because of how large the language is. Could be wrong though.

The frontend is usually the hard part IMO. In WebKit, we have 100,000 lines of code for our "frontend" (i.e. the DFG compiler) and 50,000 lines of code for our "backend" (i.e. B3). That split is really interesting.

Re:Introducing the B3 JIT compiler by nickpsecurity on Monday February 15, 2016 @04:03PM (#11105949)
It's what I thought, too. The split may come from the fact that the front-end is more complex, richer in information, harder to analyze, and harder to transform. The more you can do with it the more code it takes to represent. That's my hypothesis.

Far as Ada, I figured it would be difficult due to the large number of language features and complexities of analyzing a program for safety w/ all its rules. And any interactions that might emerge in that between features and rules. Could be easier than I think but my default belief is that it's not easy.

Re:Introducing the B3 JIT compiler by sklogic on Monday February 15, 2016 @06:48PM (#11106944)
I am talking about the backend optimisations, not the frontend parts. Ada frontend got tons of sweet static information for the backend to consume.
Re:Introducing the B3 JIT compiler by nickpsecurity on Monday February 15, 2016 @07:43PM (#11107170)
That makes more sense. Did you ever work on any Ada compiler I might have heard of?
Re:Introducing the B3 JIT compiler by sklogic on Tuesday February 16, 2016 @07:51AM (#11109478)
Nothing fancy, I was simply implementing a subset of Ada for fun. I find it is the quickest way to learn or explore a language - write a compiler for a subset of it.

Frontend was awful and I never finished it, but the LLVM-style backend wad very easy to build.

Re:Introducing the B3 JIT compiler by killercup on Monday February 15, 2016 @03:27PM (#11105690)
You are probably right, assuming input programs are correct. Rust (and Haskell) is not easy to _type-check_ though.
Re:Introducing the B3 JIT compiler by eddyb on Monday February 15, 2016 @04:58PM (#11106356)
You can't compile Rust without types and inside functions, most types come from inference and coercions, so "type checking" is really "type resolution".
Re:Introducing the B3 JIT compiler by chriswarbo on Tuesday February 16, 2016 @05:34AM (#11108978)
> Rust (and Haskell) is not easy to _type-check_ though.

Is that really the case? It seems to me that a Prolog-like resolution system, coupled with a constraint solver, would get most of the job done with little effort.

There are certainly many rules to keep track of, but in some cases the newer rules are strict generalisations of the older rules. For example, Haskell's original type classes are just a special-case of modern multi-parameter, flexible instances/contexts, etc. type classes. Likewise, we can implement constraint kinds, type class instance resolution and type equalities using one constraint solver.

Re:Introducing the B3 JIT compiler by sklogic on Tuesday February 16, 2016 @07:48AM (#11109460)
Hindley-Milner is already quite Prolog-like. But you're right, CLP(fd) rocks for typing.

My usual approach to implementing a type system is to derive a flat list of Prolog equations out of the AST and leave it to Prolog for solving. If you ask what to do with error messages, I've got a comprehensive answer, but it is not for a mobile phone typing.

Re:Introducing the B3 JIT compiler by another_user on Wednesday February 17, 2016 @10:44AM (#11118555)
I'd really appreciate further comments on what to do with type errors for prolog/minikanren-like tools as typecheckers
Re:Introducing the B3 JIT compiler by sklogic on Thursday February 18, 2016 @04:39AM (#11124660)
Ok, I've got a proper keyboard now.

My approach to the typing error reporting is quite compatible with the Prolog codegen. What I do: for each AST node which produce one or more type equations I record the location data (cache it and give it an index), and then issue a Prolog term like this: with_location(Id, Term), for each of the terms generated by this location.

with_location semantics is simple, but may depend on the presence of a backtracking. If it's a plain Hindley-Milner, there is no backtracking, and it simply do call/1(Term), continue if true, store Id and the failed term with all the current bindings and fail/0() if false.

If there is a backtracking, I store a stack of location ids and failure reasons instead, but this required patching the Prolog execution engine a little bit (luckily, I'm using my own Prolog for this).

Now, the next step is to decipher the failed term. Most of the equations are in a trivial form: equals(A, B), so I simply report that prolog_to_type(A) failed to unify with prolog_to_type(B). For the other (rare) kinds of equations I define custom pretty-printing rules.

Re:Introducing the B3 JIT compiler by another_user on Thursday February 18, 2016 @07:57AM (#11125382)
Thanks, looks nice and pretty straightforward, will try it out
Re:Introducing the B3 JIT compiler by bluejekyll on Monday February 15, 2016 @08:54PM (#11107423)
I don't understand this perspective. Is the point that JavaScript just works such that you don't have to worry about it compiling at runtime?

To me this is the difference between knowing that your program will probably work after it compiles, vs not knowing until after its deployed.

What I think people really enjoy in dynamic languages like JavaScript is the instant feedback, just reloading the browser. This can be accomplished with decent IDEs for most statically typed languages.

Re:Introducing the B3 JIT compiler by geofft on Monday February 15, 2016 @09:24PM (#11107523)
I don't believe anyone's arguing that the overhead of static checking is not worthwhile, merely that it involves serious work on the part of the compiler developers that should not be dismissed.
Re:Introducing the B3 JIT compiler by yxhuvud on Monday February 15, 2016 @01:06PM (#11104859)
While they have sucked up a lot, it is far from certain all would have been employed optimizing compilers if that hadn't happened. Demand tend to create the supply.

Also, many of the improvements done for JS will certainly trickle down to Python, Ruby, PHP eventually.