Skip to content

Latest commit

 

History

History
52 lines (37 loc) · 3.44 KB

Bootstrappable-vs-Self-Hosting-Compilers.md

File metadata and controls

52 lines (37 loc) · 3.44 KB

please explain the difference between bootstrappable and self-hosting compilers

The terms bootstrappable compiler and self-hosting compiler are related to compiler design, but they refer to different concepts. Here's an explanation of each:

1. Bootstrappable Compiler

A bootstrappable compiler is one that can be used to compile itself, but achieving this requires an intermediate process. The term generally implies that the compiler does not yet exist in a usable form for the target platform but can be "bootstrapped" into existence.

Key Characteristics:

  • Initial Stage: A bootstrappable compiler often starts with a simpler version or cross-compiled version, written in a different language or for a different platform.
  • Multi-Stage Process: It might require compiling an initial version of the compiler using another compiler, then using that output to compile the final version.
  • Purpose: It ensures that the compiler can eventually compile its own source code on the target platform.

Example: Suppose you want a new compiler for a language called Foo on a platform where it doesn't exist:

  1. Write a minimal Foo compiler in a different language (e.g., C).
  2. Use an existing C compiler to build this initial version of the Foo compiler.
  3. Use the resulting Foo compiler to compile its full-featured source code.

This process "bootstraps" the system.


2. Self-Hosting Compiler

A self-hosting compiler is one that is written in the language it compiles. For example, a C compiler written in C or a Python interpreter written in Python.

Key Characteristics:

  • Self-Sufficiency: The compiler is mature enough to compile its own source code directly.
  • Ease of Maintenance: Since the compiler is written in its own language, developers working on the language itself can easily use the compiler to make changes or improvements.
  • No External Dependencies: Once a self-hosting compiler is operational, it doesn't rely on other languages or compilers.

Example:

  • The GNU C Compiler (GCC) was originally written in C, and once it became capable of compiling itself, it became self-hosting.
  • The Rust compiler (rustc) is written in Rust.

Key Differences

Aspect Bootstrappable Compiler Self-Hosting Compiler
Definition A compiler that can be built in stages to eventually compile itself. A compiler written in the same language it compiles.
Dependencies Often requires an external or simpler compiler for the initial stage. Requires no external language after becoming self-hosting.
Purpose To bootstrap a compiler for a language on a target platform. To maintain and evolve the language using itself.
Example Process Using a C compiler to build a minimal Foo compiler, then using it to compile Foo. A C compiler written in C compiling itself directly.

Relation Between the Two

  • A compiler must often be bootstrapped before it can become self-hosting.
  • For example, the Rust compiler was initially developed using OCaml but was eventually rewritten in Rust and became self-hosting after being bootstrapped.

Let me know if you'd like more examples or technical details!