Is Google Closure a true compiler?

This question is inspired by the debate in the comments on this Stack Overflow question. The Google Closure Compiler documentation states the following (emphasis added):

The Closure Compiler is a tool for making JavaScript download and run faster. It is a true compiler for JavaScript. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript.

However, Wikipedia gives the following definition of a “compiler”:

A compiler is a computer program (or set of programs) that transforms source code written in a programming language (the source language) into another computer language… A language rewriter is usually a program that translates the form of expressions without a change of language.

Based on that, I would say that Google Closure is not a compiler. But the fact that Google explicitly state that it is in fact a “true compiler” makes me wonder if there’s more to it. Is Google Closure really a JavaScript compiler?

1

The Closure Compiler is a minifier, an optimiser and a validator all-in-one. That kind of puts it in its own category, because you’re correct that a compiler should at least take something that won’t run in its current form and turn it into something that will (take TypeScript for an ECMAScript-based example).

But do you blame Google for stretching the terminology? What else were they going to call it? Google Minifier? No, it’s more than that, and there are hundreds of those out there. Google Optimiser? It’s way more than that. Google Validator? No, it’s way more than that too.

So the choice is

  • Call it Google Closure Foogle and introduce a whole new otherwise-meaningless word into the lexicon.
  • Call it Google Closure Minoptivalidator, which is clearer in intent but harder to remember.
  • Call it Google Closure Compiler, which is pretty close to the truth.

It does everything you would expect a compiler to do, with only a semantic difference. And, in the end, all words are defined by their usage, to some extent. So if Google can convince people to call this a compiler, the definition of compiler changes slightly. Certainly not in any way that will cause a problem.

Or, to come back to the earlier example, can you find anything significant about TypeScript that allows it to be called a “true compiler”, while Google Closure Compiler should be restricted to “almost a compiler”?

6

Based on that, I would say that Google Closure is not a compiler.

Well yes … but that assumes that Wikipedia is authoritative on this point.

And as a counter to the Wikipedia definition, consider some dictionary definitions (from http://www.thefreedictionary.com/compiler):

2) (Computer Science) – A program that translates another program written in a high-level language into machine language so that it can be executed.

2) (Electronics & Computer Science / Computer Science) a computer program by which a high-level programming language, such as COBOL or FORTRAN, is converted into machine language that can be acted upon by a computer.

A computer program associated with certain programming languages that converts the instructions written in those languages into machine code that can later be executed directly by a computer.

Granted these definitions are all a bit old-fashioned, but it does illustrate that there is no “one true meaning” … and indeed that meanings of terms like “compiler” change over time. (And, IMO that is just fine, because we don’t really need a precise definition for this case.)

Debating whether the Closure compiler is a “true compiler” or not is (IMO) not a fruitful activity. It would be more useful to understand what the Google folks mean by “true compiler” … in that context.

2

I think the reason why it can be called “a real compiler” is because it builds a complete AST (abstract semantic tree) out of your programs, and uses it to generate a new text.

The fact that both the original and resultant texts are valid JavaScript is mere coincidence.

This is important because there are many tools that only do text manipulations of the code (minifiers, prettifiers, etc) but doesn’t do any AST handling, much less code re-generation. Even if those tools are more and more powerful, they’re not the same kind of software, and the limitations are different.

3

It’s semantics in my opinion. In the traditional sense, it is not a compiler. However, in the same Wikipedia link, it says

A compiler is likely to perform many or all of the following
operations: lexical analysis, preprocessing, parsing, semantic
analysis (Syntax-directed translation), code generation, and code
optimization.

Closure performs some or all of those operations.

A little farther down in the Wikipedia article

However, in practice there is rarely anything about a language that
requires it to be exclusively compiled or exclusively interpreted,
although it is possible to design languages that rely on
re-interpretation at run time.

That being said, my guess is that it was easier to call it the “Closure Compiler” rather than the “Closure Optimizer” because really it is just optimizing JavaScript for browsers, not necessary translating it into another language or bytecode.

Closure Compiler as a noun is a non-sequitur.

1

First, lets get this out of the way source-to-source compiler exists. You cannot say something isn’t a compiler because the end result isn’t a code of lower level.

While it is correct that Closure Compiler generate AST and have code generation phrase, many Javascript minimizer out there already does that and I would probably not call them compilers neither.

What truly sets Closure Compiler apart is it’s application of many well known compiler techniques in error detection and optimization. Here are some examples:

Type system:

Closure Compiler defines an annotated type system. It utilizes type inference techniques that many compiler uses to check your program for errors.

Interprocedural optimizations

Closure Compiler builds call graphs to rename and remove dead code in a whole program level.

Intraprocedural optimizations

Closure Compiler optimizes Javascript by apply different Control Flow Analysis as well as Data Flow analysis. Classic compiler techniques such as: Inlining, Register Allocation, Live Variable Analysis.. and many more are all utilized to squeeze that last byte out of the output Javascript.

Module System

A lesser known part of Closure Compiler that can be used to divide your code into seperate download for faster start-up time. It utilizes many graph algorithms as well. Something is also very common in “traditional” compilers.

All these compiler and static analysis techniques is what sets Closure Compiler apart from other Javascript minimizer. Taking away from the fact that the targeted input and output language is the same, I don’t see why it isn’t classified as a “true compiler”.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật