feat: replace Cranelift JIT with C backend

Remove Cranelift JIT compiler and expose the existing C backend as the
compilation target. Generated C code can be compiled with GCC/Clang.

Changes:
- Remove cranelift-* dependencies from Cargo.toml
- Delete src/compiler.rs (565 lines of Cranelift code)
- Add compile_to_c() function with -o and --run flags
- Fix C backend name mangling (main -> main_lux) to avoid conflicts
- Update CLI help text and documentation

Usage:
  lux compile <file.lux>           # Output C to stdout
  lux compile <file.lux> -o out.c  # Write to file
  lux compile <file.lux> --run     # Compile and execute

C backend supports: functions, basic types, operators, if/then/else,
records, enums, Console.print. Future work: closures, lists, patterns.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-14 03:37:35 -05:00
parent 8c7354131e
commit 67437b8273
8 changed files with 132 additions and 999 deletions

View File

@@ -181,7 +181,7 @@ fn processAny(x: Int @latest): Int = x // any version
### Planned (Not Yet Fully Implemented)
- **Full Compilation**: JIT works for numeric code, strings/lists/ADTs missing
- **Full C Backend**: Basic functions work, closures/lists/pattern variables pending
- **Auto-migration Generation**: Migration bodies stored, execution pending
---
@@ -234,7 +234,7 @@ Quick iteration with type inference and a REPL.
| Limitation | Description |
|------------|-------------|
| **Limited JIT** | Cranelift JIT works for numeric code only |
| **Limited C Backend** | Basic functions work, closures/lists pending |
| **No Package Manager** | Can't share/publish packages yet |
| **New Paradigm** | Effects require learning new concepts |
| **Small Ecosystem** | No community packages yet |
@@ -297,7 +297,7 @@ Quick iteration with type inference and a REPL.
### Not a Good Fit (Yet)
- Large production applications (early stage)
- Performance-critical code (JIT limited to numeric)
- Performance-critical code (C backend still basic)
- Web frontend development (no JS compilation)
- Systems programming (no low-level control)
@@ -348,13 +348,12 @@ Source Code
├─────────────────────────┐
▼ ▼
┌─────────────┐ ┌──────────────┐
│ Interpreter │ │ JIT Compiler
│ (default) │ │ (Cranelift)
│ Interpreter │ │ C Backend
│ (default) │ │ (compile)
└─────────────┘ └──────────────┘
│ │
▼ ▼
Values + Effects Native Code
(~160x speedup)
Values + Effects C Code → GCC/Clang
```
---
@@ -370,12 +369,12 @@ Values + Effects Native Code
- ✅ HTTP Server Effect (listen, accept, respond, stop)
- ✅ Test Effect (native testing framework)
- ✅ Console.readLine and Console.readInt
-JIT Compiler for numeric code (~160x speedup)
-C Backend (basic functions, Console.print)
- ✅ Watch mode / hot reload
- ✅ Formatter
**In Progress:**
1. **Behavioral Type Verification** - Total, idempotent, deterministic checking
1. **C Backend Extensions** - Closures, lists, pattern variable binding
2. **Schema Evolution** - Type system integration, auto-migration
3. **Error Message Quality** - Context lines shown, suggestions partial
@@ -383,4 +382,4 @@ Values + Effects Native Code
4. **SQL Effect** - Database access
5. **Package Manager** - Share code (manifest parsing exists)
6. **JavaScript Backend** - Run in browsers
7. **Full JIT** - Strings, lists, ADTs, effects
7. **Behavioral Type Verification** - Total, idempotent, deterministic checking

View File

@@ -67,10 +67,10 @@
| Task | Priority | Effort | Status |
|------|----------|--------|--------|
| Elm-quality error messages | P1 | 2 weeks | ⚠️ Partial (context shown, suggestions missing) |
| Full JS compilation | P2 | 4 weeks | ⚠️ JIT for numeric code only |
| Full JS compilation | P2 | 4 weeks | ❌ Missing |
| Hot reload / watch mode | P2 | — | ✅ Complete |
| Debugger improvements | P3 | 2 weeks | ✅ Basic |
| JIT CLI integration | P1 | — | ✅ Complete (`lux compile`) |
| C backend CLI integration | P1 | — | ✅ Complete (`lux compile`) |
### Success Criteria for Use Case 1
- [ ] Can build a REST API with database access
@@ -220,7 +220,8 @@
| Task | Priority | Effort | Status |
|------|----------|--------|--------|
| Extend JIT (strings, lists) | P1 | 2 weeks | ❌ Missing |
| C backend (basic) | P1 | — | ✅ Complete (functions, Console.print) |
| Extend C backend (closures, lists) | P1 | 2 weeks | ❌ Missing |
| JS backend | P2 | 4 weeks | ❌ Missing |
| WASM backend | P3 | 4 weeks | ❌ Missing |
@@ -296,7 +297,7 @@
- ✅ JSON parsing/serialization (parse, stringify, get, object, array)
**Tooling:**
-JIT compiler (~160x speedup, CLI: `lux compile`)
-C backend (functions, Console.print, CLI: `lux compile`)
- ✅ REPL with history
- ✅ Basic LSP server
- ✅ Formatter