I've always wondered how compiled languages are written in their own language. Asked AI about it today. Asked because Rust is written in Rust and I'm like "how the fugg".
Here it is...
AI Quote: Great question. This gets to the heart of how programming languages actually come into existence*.
Short version: they “bootstrap” themselves.
## The core idea: bootstrapping
A programming language doesn’t start by magically compiling itself.
It starts like this:
1. Version 0 of the compiler is written in some *other language
2. That compiler can compile simple programs in the new language
3. One of those programs is a new compiler written in the new language
4. From then on, the language can compile itself
That’s it. No paradox.
## Step-by-step example (simplified)
Let’s imagine creating a language called `Foo`.
### Step 1: Write the first compiler in another language
You write:
`foo-compiler-v0` in C (or OCaml, etc.)
This compiler:
Is very basic Maybe slow
Supports only part of Foo
But it works.
### Step 2: Write a better compiler in Foo
Now you write:
`foo-compiler-v1` in Foo
You use:
`foo-compiler-v0` to compile it
Now you have:
A compiler written in Foo
Running as a native executable
### Step 3: Replace the old compiler
Once you trust it:
Use `foo-compiler-v1` to compile itself
Throw away the original C compiler (or keep it for bootstrapping new machines)
Now Foo is self-hosting.
## Why this works logically
There is no infinite loop because:
The *first compiler is external Self-hosting happens after the language already exists
At runtime, compilers are just programs, not magical objects
It’s like:
> You learn English from a teacher,
> then later you teach English in English*.
## Real-world examples
### Rust
Early compiler written in OCaml Gradually rewritten in Rust
Today: `rustc` compiles `rustc`
### C
Early C compiler written in assembly
Later rewritten in C Compiles itself on every platform
### Go
Originally written in C Now written in Go
### Python
CPython is written in C But tools like PyPy are written in Python
## The “trusting trust” problem (important nuance)
Ken Thompson famously pointed out:
If the original compiler is malicious It can insert hidden backdoors into all future compilers
Even if the source looks clean
This is why:
Reproducible builds
Multiple independent compilers Formal verification
matter in serious language ecosystems.
## Bottom line
> A language is not born self-aware.
It starts:
as a compiler written in another language becomes powerful enough to reimplement itself
then maintains itself forever after
That’s how Rust, C, Go, Swift, and most serious languages work.
If you want, I can also explain:
how bootstrapping works across different CPU architectures
how you build the first compiler on a brand-new machine
* or how interpreters differ from compilers in this process
I think that's pretty cool. Just make an initial compiler, create new lang, compile a new compiler in the new lang, and that's it. Simple but works.
Here it is...
AI Quote: Great question. This gets to the heart of how programming languages actually come into existence*.
Short version: they “bootstrap” themselves.
## The core idea: bootstrapping
A programming language doesn’t start by magically compiling itself.
It starts like this:
1. Version 0 of the compiler is written in some *other language
2. That compiler can compile simple programs in the new language
3. One of those programs is a new compiler written in the new language
4. From then on, the language can compile itself
That’s it. No paradox.
## Step-by-step example (simplified)
Let’s imagine creating a language called `Foo`.
### Step 1: Write the first compiler in another language
You write:
`foo-compiler-v0` in C (or OCaml, etc.)
This compiler:
Is very basic Maybe slow
Supports only part of Foo
But it works.
### Step 2: Write a better compiler in Foo
Now you write:
`foo-compiler-v1` in Foo
You use:
`foo-compiler-v0` to compile it
Now you have:
A compiler written in Foo
Running as a native executable
### Step 3: Replace the old compiler
Once you trust it:
Use `foo-compiler-v1` to compile itself
Throw away the original C compiler (or keep it for bootstrapping new machines)
Now Foo is self-hosting.
## Why this works logically
There is no infinite loop because:
The *first compiler is external Self-hosting happens after the language already exists
At runtime, compilers are just programs, not magical objects
It’s like:
> You learn English from a teacher,
> then later you teach English in English*.
## Real-world examples
### Rust
Early compiler written in OCaml Gradually rewritten in Rust
Today: `rustc` compiles `rustc`
### C
Early C compiler written in assembly
Later rewritten in C Compiles itself on every platform
### Go
Originally written in C Now written in Go
### Python
CPython is written in C But tools like PyPy are written in Python
## The “trusting trust” problem (important nuance)
Ken Thompson famously pointed out:
If the original compiler is malicious It can insert hidden backdoors into all future compilers
Even if the source looks clean
This is why:
Reproducible builds
Multiple independent compilers Formal verification
matter in serious language ecosystems.
## Bottom line
> A language is not born self-aware.
It starts:
as a compiler written in another language becomes powerful enough to reimplement itself
then maintains itself forever after
That’s how Rust, C, Go, Swift, and most serious languages work.
If you want, I can also explain:
how bootstrapping works across different CPU architectures
how you build the first compiler on a brand-new machine
* or how interpreters differ from compilers in this process
I think that's pretty cool. Just make an initial compiler, create new lang, compile a new compiler in the new lang, and that's it. Simple but works.




![[Image: 3.gif]](https://i.ibb.co/zH0GQ122/3.gif)
