News for hackers. Stuff that matters.
Re:A New Bytecode Format for JavaScriptCore by wahern on Friday June 21, 2019 @03:41PM (#20245707)
* Adding a new field or method to an object at runtime doesn't change the AST.

* You don't translate from bytecode to AST.

* In tiered JIT architectures--typical for dynamically-typed languages like JavaScript where as you point out effective types can mutate at runtime--most code is executed by an interpreter, not as compiled machine code.[1] Interpreters are more efficient when executing a bytecode than walking an AST.

* Translating an AST straight to machine code is much more difficult than translating a low-level intermediate representation, and such representations are often easy to express as simple bytecodes. Compilers like GCC and LLVM use intermediate representations: RTL and IR. Both are effectively assembly languages, and like all assembly languages trivial to express as bytecode. GCC also has GIMPLE, a higher-level intermediate representation earlier in the pipeline which expresses a generic AST. The fact that GIMPLE and RTL coexist drives home the point that you don't want to be translating tree-like representations straight to machine code.

* You don't need to take my word for this, or the word of anyone else. Every programmer should have experience writing parsers, compilers, and interpreters, regardless of whether they took a class or even went to university. By doing this most of the reasons for the way things are done will become immediately clear to you. Note that splitting strings with regular expressions does not count as parsing, not for these purposes. A good project, however, would be to write a regular expression parser, compiler, and interpreter. There are many examples to follow and you can copy their designs exactly; just don't copy+paste as actually going through the motions and understanding the complexities inherent in the implementations is how everything will become clear.

[1] How this mutation is handled and why tiered architectures are preferable is another topic entirely.

Re:A New Bytecode Format for JavaScriptCore by TheAceOfHearts on Friday June 21, 2019 @05:38PM (#20246508)
Definitely agree that most programmers would benefit from studying these topics. They have broader applications than many realize.

You can use tools like jscodeshift [0] to refactor code! I've previously written codemods to migrate away from a bad design decisions. The React team has also used codemods to introduce breaking changes. AST Explorer [1] is the best tool I've found for writing codemods since it gives you nearly instant feedback and allows for a good amount of exploration.

[0] https://github.com/facebook/jscodeshift/

[1] https://astexplorer.net/

Re:A New Bytecode Format for JavaScriptCore by eridius on Friday June 21, 2019 @04:26PM (#20246033)
Swift and Rust also have their own higher-level intermediate representations that they translate their AST to before even going to LLVM IR (SIL and MIR respectively). Rust used to translate their AST directly into LLVM IR but they switched to going through MIR first because it unlocks a lot of optimizations as well as improved user-facing functionality such as non-lexical lifetimes in the borrow checker.
Re:A New Bytecode Format for JavaScriptCore by steveklabnik on Friday June 21, 2019 @05:44PM (#20246539)
Rust has AST -> HIR -> MIR -> LLVM-IR. Two internal IRs and a third external one!
Re:A New Bytecode Format for JavaScriptCore by eridius on Friday June 21, 2019 @06:32PM (#20246805)
Good point, I forgot about HIR, though isn't HIR largely just a desugared representation of the AST?
Re:A New Bytecode Format for JavaScriptCore by steveklabnik on Friday June 21, 2019 @07:19PM (#20247045)
Yes, but also post macro expansion and name resolution.
Re:A New Bytecode Format for JavaScriptCore by monocasa on Saturday June 22, 2019 @12:13AM (#20247984)
And compcert has at least seven different IRs, several of which are ASTs. http://compcert.inria.fr/diagram.png

That being said, consistency of internal data structures is probably one of those areas that separates a JIT from an offline compiler. I can see the benefit of switching to a bytecode representation pretty early in that circumstance.

Re:A New Bytecode Format for JavaScriptCore by scarface74 on Saturday June 22, 2019 @01:26AM (#20248177)
Every programmer should have experience writing parsers, compilers, and interpreters, regardless of whether they took a class or even went to university.

The majority of developers doing yet another software as a service CRUD app or your typical “dark matter developer” who will write software that will never see the light of day outside of the company they work for would never benefit from writing a compiler or interpreter.

Re:A New Bytecode Format for JavaScriptCore by pjmlp on Saturday June 22, 2019 @02:51AM (#20248370)
If they feel like calling themselves engineers, then they must know this stuff, as it is part of any proper engineering degree.

Now if they followed other path into programming, then by all means.

Re:A New Bytecode Format for JavaScriptCore by scarface74 on Saturday June 22, 2019 @04:02AM (#20248542)
See “No True Scotsman”....

What next they aren’t a “true engineer” unless they can reverse a b-tree on the whiteboard?

Re:A New Bytecode Format for JavaScriptCore by pjmlp on Saturday June 22, 2019 @04:18AM (#20248580)
For sure they aren't one if they don't have the degree from an university acknowledged by the Engineers Order.

Which most likely will have a good class in algorithms and data structures.

So while I don't expect every engineer to actually be able to do it, I expect him/her to be able to explain how to attack the problem.

Re:A New Bytecode Format for JavaScriptCore by scarface74 on Saturday June 22, 2019 @04:22AM (#20248592)
And you personally have studied the curriculum of every single computer science/computer engineering degree and can say that every single one required writing a compiler or interpreter and that no person who hasn’t written one can call themselves an engineer?
Re:A New Bytecode Format for JavaScriptCore by pjmlp on Saturday June 22, 2019 @04:23AM (#20248594)
The engineering Order has taken that job twice.

When they certify the university and then when they issue the professional titles exam.

Re:A New Bytecode Format for JavaScriptCore by scarface74 on Saturday June 22, 2019 @04:31AM (#20248614)
So they “certify universities” worldwide?
Re:A New Bytecode Format for JavaScriptCore by pjmlp on Saturday June 22, 2019 @05:01AM (#20248706)
Each one certifies the universities of the respective country, naturally.

I am well aware that US doesn't seem to value proper engineering education, and everyone is allowed to call themselves engineers.

Thankfully not every country sees it that way.

Re:A New Bytecode Format for JavaScriptCore by scarface74 on Saturday June 22, 2019 @08:42AM (#20249310)
Yes I guess that’s why the US is such a backwater when it comes to innovation and why we have so few successful technology startups....
Re:A New Bytecode Format for JavaScriptCore by pjmlp on Saturday June 22, 2019 @10:02AM (#20249593)
Should we do an exercise of which US tech was actually researched by immigrants with a proper engineering degree, and how much of that tech is actually built on US?
Re:A New Bytecode Format for JavaScriptCore by scarface74 on Saturday June 22, 2019 @10:24AM (#20249727)
Should we do an exercise in how much knowing how to write compilers helps in the day to day life of your average SAAS CRUD developer or bespoke app developer - my original statement?
Re:A New Bytecode Format for JavaScriptCore by pjmlp on Saturday June 22, 2019 @12:08PM (#20250307)
It depends if the bespoke develop ever needs to parse some kind of data file to import into their CRUD application, provide customization points to their customers or configuration file parser.

Then there is the whole point if HR is hiring actual engineers.