Skip to content

Commit 077debe

Browse files
committed
docs: freeze bootstrap contract and lock ABI tests (#24)
1 parent 1b1d942 commit 077debe

10 files changed

Lines changed: 281 additions & 8 deletions

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/), and this
1414
- Added `docs/COMPONENT_OWNERSHIP.md`.
1515
- Defined canonical logical boundaries for `Frontend`, `Middle-End`, `Backend`, `Driver`, and `Support`.
1616
- Documented allowed dependency directions between those components.
17+
- **Bootstrap contract freeze summary (v0.5.1 sidecar)**:
18+
- Added `docs/BOOTSTRAP_CONTRACT.md`.
19+
- Published the frozen bootstrap-facing contract for the current language surface, stdlib signatures, ABI rules, and IR/verifier guarantees.
20+
- Declared the currently unsupported bootstrap surface that remains intentionally frozen as unsupported.
1721
- **Component-owned public header surfaces**:
1822
- Added `src/frontend/lexer.h`, `src/frontend/ast.h`, `src/frontend/parser.h`, and `src/frontend/analysis.h` as the frontend-owned public declarations split out of the old shared surface.
1923
- Added `src/support/version.h`, `src/support/read_file.h`, `src/support/diagnostics.h`, `src/support/updater.h`, and `src/support/target_contract.h` for support-owned cross-cutting contracts.
@@ -29,6 +33,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/), and this
2933
- File I/O failures now include Arabic-first diagnostics with the underlying system error reason.
3034
- Fatal read-path diagnostics consistently terminate with `EXIT_FAILURE` via `stderr`.
3135

36+
- **Bootstrap freeze documentation sync**:
37+
- `docs/LANGUAGE.md`, `docs/INTERNALS.md`, and `docs/BAA_IR_SPECIFICATION.md` now point to `docs/BOOTSTRAP_CONTRACT.md` as the bootstrap-facing summary of the frozen contracts.
38+
- `stdlib/baalib.baahd` now explicitly declares itself as the canonical stdlib signature surface for the freeze.
39+
- **Bootstrap regression locking**:
40+
- Added focused integration coverage for Windows x64 call-register/shadow-space emission, SysV varargs `AL=0` emission, and verifier-safe CFG/phi compilation.
3241
- **QA orchestration**:
3342
- `scripts/qa_run.py` now runs the module-size guard before `full` and `stress` QA work, and stops early on hard-cap violations.
3443
- **CI gating**:

ROADMAP.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Baa Roadmap (Updated)
22

33
> Track the development progress of the Baa programming language.
4-
> **Current Status:** Phase 4.5 - Bootstrap Readiness (v0.5.x) ← IN PROGRESS
4+
> **Current Status:** Phase 4.5 - Bootstrap Readiness (v0.5.3) ← IN PROGRESS
55
66
---
77

@@ -1330,10 +1330,12 @@ Partial status update (2026-03-06):
13301330

13311331
### v0.5.1: Language + ABI Freeze 🔒
13321332

1333-
- [ ] **Freeze grammar surface** — avoid syntax churn before bootstrap.
1334-
- [ ] **Freeze stdlib signatures** — lock callable contracts used by compiler-in-Baa.
1335-
- [ ] **Freeze target ABI contracts** — Windows x64 + SystemV AMD64 invariants.
1336-
- [ ] **Freeze IR invariants** — verifier-enforced guarantees documented.
1333+
- [x] **Freeze grammar surface** — avoid syntax churn before bootstrap.
1334+
- [x] **Freeze stdlib signatures** — lock callable contracts used by compiler-in-Baa.
1335+
- [x] **Freeze target ABI contracts** — Windows x64 + SystemV AMD64 invariants.
1336+
- [x] **Freeze IR invariants** — verifier-enforced guarantees documented.
1337+
1338+
✅ COMPLETED (2026-03-22)
13371339

13381340
### v0.5.2: Module & Multi-File Hardening 📦
13391341

@@ -1395,7 +1397,7 @@ Partial status update (2026-03-06):
13951397
#### Phase 4.5 Required Artifacts
13961398

13971399
- [x] `docs/COMPONENT_OWNERSHIP.md` — boundaries + owners + allowed dependencies.
1398-
- [ ] `docs/BOOTSTRAP_CONTRACT.md` — frozen ABI/IR/language requirements for v0.9.
1400+
- [x] `docs/BOOTSTRAP_CONTRACT.md` — frozen ABI/IR/language requirements for v0.9.
13991401
- [ ] `docs/BAA0_SPEC.md` — bootstrap subset definition and exclusions.
14001402
- [ ] `scripts/qa_bootstrap_gate.py` — one-command admission checks for Phase 5.
14011403
- [ ] `tests/bootstrap/` — parity corpus dedicated to migration from C → Baa slices.

docs/BAA_IR_SPECIFICATION.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
55
This document specifies the Intermediate Representation (IR) for the Baa compiler. The IR uses Arabic naming conventions throughout, creating a culturally authentic yet technically robust design.
66

7+
> **Bootstrap freeze note (v0.5.1):** The verifier-backed IR invariants in this document are part
8+
> of the frozen bootstrap contract. See [BOOTSTRAP_CONTRACT.md](BOOTSTRAP_CONTRACT.md) for the
9+
> bootstrap-facing summary.
10+
711
---
812

913
## Table of Contents
@@ -145,6 +149,9 @@ The `فاي` instruction selects a value based on which predecessor block was ex
145149
- **IR well-formedness verifier (v0.3.2.6.5):** The compiler provides `--verify-ir` to validate general IR invariants (operand counts, type consistency, terminator rules, phi placement, and intra-module call signature checks).
146150
- **All verifiers (v0.3.2.9.1):** The compiler provides `--verify` to run `--verify-ir` + `--verify-ssa` together (requires `-O1`/`-O2`).
147151

152+
These currently enforced verifier guarantees are the IR portion of the bootstrap freeze; this
153+
freeze does not promise additional IR features beyond the implemented verifier surface.
154+
148155
### 3.4 Memory Model
149156

150157
Stack allocations create addressable memory:

docs/BOOTSTRAP_CONTRACT.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Baa Bootstrap Contract
2+
3+
> **Version:** v0.5.1 freeze contract (bootstrap-facing) | [Language Spec →](LANGUAGE.md)
4+
5+
This document freezes the current Baa language, stdlib, ABI, and IR contracts that later
6+
bootstrap work must treat as stable inputs.
7+
8+
It is intentionally conservative:
9+
10+
- no new syntax is introduced here,
11+
- no ABI behavior is widened here,
12+
- no IR guarantees are promised beyond what the current compiler already implements and verifies.
13+
14+
## Canonical Sources
15+
16+
The freeze is defined by these sources of truth:
17+
18+
- Language surface: `docs/LANGUAGE.md`
19+
- Standard library callable signatures: `stdlib/baalib.baahd`
20+
- IR semantics and verifier-backed invariants: `docs/BAA_IR_SPECIFICATION.md`
21+
- Target/ABI implementation contract: `src/backend/target.h` and `src/backend/target.c`
22+
23+
If detailed docs drift from these surfaces, this document and the files above win for bootstrap
24+
planning.
25+
26+
## Frozen Language Surface
27+
28+
The following source-language surface is frozen for bootstrap readiness:
29+
30+
- UTF-8 source files with `.baa` extension
31+
- `الرئيسية` as the only program entry-point name
32+
- current preprocessor directives:
33+
- `#تضمين`
34+
- `#تعريف`
35+
- `#إذا_عرف`
36+
- `#وإلا`
37+
- `#نهاية`
38+
- `#الغاء_تعريف`
39+
- `#خطأ`
40+
- current core type spellings, including:
41+
- signed/unsigned integer families
42+
- `منطقي`
43+
- `حرف`
44+
- `نص`
45+
- `عشري`
46+
- `عشري٣٢` as a source-level alias that still lowers as `f64`
47+
- `عدم`
48+
- function-pointer syntax `دالة(...) -> ...`
49+
- current control-flow and declaration syntax
50+
- current function-pointer syntax and semantics
51+
- current variadic function syntax with `...`
52+
- current inline-assembly syntax through `مجمع`
53+
54+
The only frozen entry-point signatures are:
55+
56+
```baa
57+
صحيح الرئيسية()
58+
صحيح الرئيسية(صحيح عدد، نص[] معاملات)
59+
```
60+
61+
Bootstrap work must not assume additional accepted entry-point shapes.
62+
63+
## Frozen Standard Library Surface
64+
65+
`stdlib/baalib.baahd` is the canonical stdlib signature surface for bootstrap work.
66+
67+
The current frozen modules are:
68+
69+
- string APIs
70+
- dynamic memory APIs
71+
- file I/O APIs
72+
- math APIs
73+
- system APIs
74+
- time APIs
75+
- error-handling APIs
76+
- variadic intrinsics
77+
78+
Freeze rules:
79+
80+
- exact callable signatures come from `stdlib/baalib.baahd`
81+
- ownership rules documented there are part of the contract
82+
- heap-returning APIs remain heap-returning APIs and must be freed by the caller as documented
83+
- no new stdlib signatures should be introduced under the bootstrap freeze without explicitly
84+
revising this contract
85+
86+
## Frozen Target / ABI Surface
87+
88+
Only these targets are in scope for the freeze:
89+
90+
- `x86_64-windows`
91+
- `x86_64-linux`
92+
93+
Windows x64 ABI contract:
94+
95+
- integer/pointer argument registers: `RCX`, `RDX`, `R8`, `R9`
96+
- return register: `RAX`
97+
- 32-byte shadow space at call boundaries
98+
- object format: COFF/PE
99+
- executable suffix default: `.exe`
100+
101+
SystemV AMD64 ABI contract:
102+
103+
- integer/pointer argument registers: `RDI`, `RSI`, `RDX`, `RCX`, `R8`, `R9`
104+
- return register: `RAX`
105+
- no shadow space
106+
- varargs path currently emits `AL=0` when no XMM arguments are used
107+
- object format: ELF
108+
- executable suffix default: empty
109+
110+
Shared target limits:
111+
112+
- x86-64 only
113+
- current data layout stays 64-bit and identical across the two supported x86-64 targets
114+
- cross-target assembly generation is supported; bootstrap work must not assume broader host/toolchain
115+
guarantees than the current compiler documents
116+
117+
## Frozen IR / Verifier Surface
118+
119+
The bootstrap freeze relies on the current Baa IR contract, not a future generalized IR.
120+
121+
Frozen guarantees:
122+
123+
- SSA-form IR before Out-of-SSA
124+
- verifier-backed single-definition SSA discipline
125+
- verifier-backed dominance and phi incoming-edge checks
126+
- verifier-backed well-formedness for:
127+
- operand counts
128+
- type consistency
129+
- terminator rules
130+
- phi placement
131+
- intra-module call signature checks
132+
- current x86-64 data-layout assumptions
133+
- current typed-memory model for `حجز` / `حمل` / `خزن`
134+
135+
Non-guarantees:
136+
137+
- no promise of new IR opcodes for bootstrap
138+
- no promise of new alias-analysis precision
139+
- no promise of non-x86-64 data layouts in this freeze
140+
141+
## Frozen Unsupported Surface
142+
143+
The following remain intentionally unsupported under the freeze and must stay unsupported unless a
144+
later milestone explicitly reopens them:
145+
146+
- variadic function-pointer calls
147+
- advanced inline-assembly constraints and clobber lists beyond the currently documented subset
148+
- additional entry-point signatures beyond the two frozen forms
149+
- new bootstrap-relevant syntax churn in grammar/type spelling
150+
- new target families or ABI contracts beyond current Windows x64 and SystemV AMD64 support
151+
152+
## Enforcement Expectations
153+
154+
The freeze is locked by:
155+
156+
- documentation synchronization against the canonical sources above
157+
- existing verifier paths: `--verify-ir`, `--verify-ssa`, and `--verify`
158+
- focused integration tests that lock:
159+
- stdlib short include behavior
160+
- entry-point argument lowering
161+
- SysV register-argument behavior
162+
- Windows shadow-space/register-call behavior
163+
- verifier-safe CFG/phi compilation
164+
165+
This document is the bootstrap-facing summary, but it does not replace the detailed language,
166+
stdlib, ABI, and IR references that define exact syntax and declarations.

docs/INTERNALS.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This document details the internal architecture, data structures, and algorithms
1313
## Table of Contents
1414

1515
- [Pipeline Architecture](#1-pipeline-architecture)
16+
- [Bootstrap Contract](#11-bootstrap-contract-v051)
1617
- [Component Boundaries & Size Guard](#121-component-boundaries--size-guard-v050-sidecar)
1718
- [Lexical Analysis](#2-lexical-analysis)
1819
- [Syntactic Analysis](#3-syntactic-analysis)
@@ -80,6 +81,17 @@ flowchart LR
8081

8182
> **Note (v0.3.2.4+):** The compiler uses the full IR-based backend pipeline end-to-end: AST → IR → Optimizer → ISel → RegAlloc → Emit → Assembly.
8283
84+
## 1.1. Bootstrap Contract (v0.5.1)
85+
86+
For bootstrap planning, the current language/stdlib/ABI/IR surface is frozen and summarized in
87+
[BOOTSTRAP_CONTRACT.md](BOOTSTRAP_CONTRACT.md).
88+
89+
Practical rule:
90+
91+
- bootstrap work consumes the frozen contracts as inputs,
92+
- later milestones may extend them only through explicit roadmap work,
93+
- ad-hoc syntax or ABI churn is out of scope under the freeze.
94+
8395
### 1.1.1. Component Map
8496

8597
```mermaid
@@ -2375,7 +2387,9 @@ The emitter translates Arabic function names to their C runtime equivalents:
23752387

23762388
#### 6.21.8. ABI Compliance (Windows x64 + SystemV AMD64)
23772389

2378-
This backend is being refactored to support multiple ABIs via `BaaTarget` (`src/target.h`).
2390+
The current backend ABI contract is frozen for bootstrap via `BaaTarget`
2391+
([`src/backend/target.h`](../src/backend/target.h)) and summarized in
2392+
[BOOTSTRAP_CONTRACT.md](BOOTSTRAP_CONTRACT.md).
23792393

23802394
- **Windows x64 ABI:** shadow space (32 bytes) around calls; first 4 args in RCX/RDX/R8/R9; return in RAX.
23812395
- **SystemV AMD64 (Linux):** no shadow space; first 6 args in RDI/RSI/RDX/RCX/R8/R9; return in RAX; varargs require `AL=0` when no XMM args.

docs/LANGUAGE.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
55
Baa (باء) is a compiled systems programming language using Arabic syntax. It compiles to native code via Assembly + host GCC/Clang on Windows and Linux.
66

7+
> **Bootstrap freeze note (v0.5.1):** The current language surface is frozen for bootstrap
8+
> readiness. See [BOOTSTRAP_CONTRACT.md](BOOTSTRAP_CONTRACT.md) for the canonical summary of the
9+
> frozen language, stdlib, ABI, and IR expectations.
10+
711
---
812

913
## Table of Contents
@@ -719,6 +723,12 @@ Every program **must** have a main function:
719723

720724
**Important:** The entry point **must** be named `الرئيسية` (ar-ra'īsīyah). It is exported as `main` in the generated assembly.
721725

726+
**Bootstrap freeze rule (v0.5.1):** Only the two currently supported entry-point signatures are in
727+
scope for bootstrap:
728+
729+
- `صحيح الرئيسية()`
730+
- `صحيح الرئيسية(صحيح عدد، نص[] معاملات)`
731+
722732
**Command Line Arguments [Implemented v0.3.12.5]:**
723733
The main function can optionally accept arguments:
724734

@@ -1290,6 +1300,10 @@ Baa includes a minimal standard library. To use it, you must include its header
12901300

12911301
**Syntax:** `#تضمين "baalib.baahd"` (also supported: `#تضمين "stdlib/baalib.baahd"`)
12921302

1303+
**Bootstrap freeze rule (v0.5.1):** The exact callable signature surface is defined by
1304+
`stdlib/baalib.baahd`. This document describes that surface, but the header remains the canonical
1305+
declaration source for bootstrap-facing stdlib contracts.
1306+
12931307
### 9.1. String Operations (`نص`)
12941308

12951309
Strings in Baa are UTF-8 arrays of `حرف` terminated by a null character. The standard library provides C-like string manipulation functions.

stdlib/baalib.baahd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// واجهات مكتبة باء القياسية (v0.4.0.0)
1+
// واجهات مكتبة باء القياسية
2+
// هذا الملف هو السطح المرجعي المجمّد لتواقيع stdlib ضمن عقد التمهيد v0.5.1.
23
// ملاحظة الملكية:
34
// - نسخ_نص ودمج_نص يعيدان نصاً مخصصاً على heap.
45
// - يجب تحرير النتيجة لاحقاً عبر حرر_نص.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: compile-only
2+
// FLAGS: -S --target=x86_64-linux
3+
// EXPECT-ASM: xorl %eax, %eax
4+
5+
#تضمين "stdlib/baalib.baahd"
6+
7+
صحيح جمع_متغير(صحيح عدد, ...) {
8+
قائمة_معاملات قائمة = عدم.
9+
بدء_معاملات(قائمة، عدد).
10+
11+
صحيح مجموع = ٠.
12+
لكل (صحيح ف = ٠؛ ف < عدد؛ ف++) {
13+
مجموع = مجموع + معامل_تالي(قائمة، صحيح).
14+
}
15+
16+
نهاية_معاملات(قائمة).
17+
إرجع مجموع.
18+
}
19+
20+
صحيح الرئيسية() {
21+
صحيح أ = جمع_متغير(٢، ١، ٢).
22+
صحيح ب = جمع_متغير(٢، ٣، ٤).
23+
إرجع أ - ب.
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: compile-only
2+
3+
صحيح دمج_شرطي(صحيح س) {
4+
صحيح ن = س.
5+
6+
إذا (س > ١٠) {
7+
ن = س + ١.
8+
} وإلا {
9+
ن = س - ١.
10+
}
11+
12+
إرجع ن.
13+
}
14+
15+
صحيح الرئيسية() {
16+
صحيح أ = دمج_شرطي(١٢).
17+
صحيح ب = دمج_شرطي(٣).
18+
إرجع أ - ب.
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: compile-only
2+
// FLAGS: -S --target=x86_64-windows
3+
// EXPECT-ASM: subq $32, %rsp
4+
// EXPECT-ASM: movq $1, %rcx
5+
// EXPECT-ASM: movq $2, %rdx
6+
// EXPECT-ASM: movq $3, %r8
7+
// EXPECT-ASM: movq $4, %r9
8+
9+
صحيح اجمع4(صحيح أ, صحيح ب, صحيح ج, صحيح د) {
10+
إرجع أ + ب + ج + د.
11+
}
12+
13+
صحيح الرئيسية() {
14+
صحيح أ = اجمع4(1, 2, 3, 4).
15+
صحيح ب = اجمع4(5, 6, 7, 8).
16+
إرجع أ - ب.
17+
}

0 commit comments

Comments
 (0)