feat(WP-0016/C5): compilation layers docs and -fwrite-interface flag

- CLAUDE.md: add "Compilation Layers" section (C5) — layer map,
  compile-check tool usage, cache location, error-fix discipline
- .ghci: add -fwrite-interface so interface files are cached even
  on partial-success builds (completes C4 spec)
- WP-0016: mark C5 done; annotate C4 ✓ note in workplan

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-10 20:03:54 +00:00
parent 64a9d4eeb4
commit 563983fa7f
3 changed files with 49 additions and 4 deletions

2
.ghci
View File

@@ -7,4 +7,6 @@
-- Report errors from all modules in one pass (don't stop at first failure).
-- Critical for batch error fixing — see IHUB-WP-0016 C4.
:set -fkeep-going
-- Write interface files even on partial success so cached modules are not re-compiled.
:set -fwrite-interface
import IHP.Prelude

View File

@@ -50,6 +50,43 @@ deploy-to-nixos production # NixOS deploy
Schema editing: use the IHP IDE at `localhost:8001` or edit `Application/Schema.sql` directly. Code generation via `localhost:8001/Generators`.
## Compilation Layers
IHP compiles ~180 Haskell modules as one GHC target. Module changes are incremental — only changed modules and their dependents recompile. **Never modify Layer 1 during error-fix loops** — a change to `Web/Types.hs` or `Generated/Types.hs` invalidates all 59 controllers and 120 views simultaneously.
```
Layer 1 — stable core (compile once):
build/Generated/Types.hs IHP auto-generated from Schema.sql
Web/Types.hs controller type definitions
Layer 2 — helpers (only touch if Layer 1 is clean):
Application/Helper/*.hs 12 helper modules
Layer 3 — working surface (most errors live here):
Web/Controller/*.hs 59 controllers
Web/View/**/*.hs 120 views
Layer 4 — wiring (fix last):
Web/FrontController.hs
Web/Routes.hs
```
**Compile tools** (run inside `devenv shell`):
```bash
scripts/compile-check # full build via ghcid (all layers), log → /tmp/ihub-compile-errors.txt
scripts/compile-check --bg # same, background-friendly (no colour/title)
scripts/compile-check-core # Layer 1+2 only — verify clean base before touching Layer 3
```
**GHC object cache**: compiled `.o`/`.hi` files persist in `.devenv/` between restarts. After the first full build (2060 min on constrained hardware), subsequent single-module rebuilds take 530 seconds. Cache location:
```bash
find /home/tegwick/inter-hub -name "*.hi" 2>/dev/null | head -5
```
**Error-fix discipline**: fix bottom-up (Layer 1 → 4). Fix one module at a time; wait for ghcid to reload before moving on. See `workplans/IHUB-WP-0016-build-infrastructure-and-error-loop.md` for the full SOP.
## Architecture
### Core Domain Model (Phase 1)

View File

@@ -71,6 +71,10 @@ skips the database startup, port binding, and service orchestration overhead.
### C1 — Create `scripts/compile-check` script ✓
Also created `scripts/compile-check-core` and `.ghci-core` to compile Layer 1+2
in isolation (no Main.hs, no Layer 3). Resolves the architecture gap where Layer
2 correctness could not be verified independently.
A shell script at `scripts/compile-check` that runs ghcid in isolation (no postgres, no tailwind):
```bash
@@ -124,7 +128,7 @@ Configure a ralph-workplan loop:
- Do NOT make speculative changes to stable layers while fixing working-surface errors
- Maximum 3 fix attempts per module before escalating to user
### C4 — Add GHC `-fwrite-interface` and `-keep-going` flags to `.ghci`
### C4 — Add GHC `-fwrite-interface` and `-keep-going` flags to `.ghci`
```
-- Continue past errors in other modules (report all errors in one pass)
@@ -136,12 +140,14 @@ Configure a ralph-workplan loop:
`-fkeep-going` lets GHC report errors from all modules in one pass rather than
stopping at the first failure — critical for batch error fixing.
### C5 — Document module surface constraints in CLAUDE.md
### C5 — Document module surface constraints in CLAUDE.md
Add a "Compilation Layers" section to CLAUDE.md noting:
- Never modify Layer 1 during error-fix loops
Added "Compilation Layers" section to CLAUDE.md covering:
- Never modify Layer 1 during error-fix loops (and why — cascade invalidation)
- Layer breakdown with file counts
- Each layer's expected compile time after first build
- Cache location and how to verify it's warm
- References to `scripts/compile-check` and `scripts/compile-check-core`
## Error-Fix Loop SOP (Standard Operating Procedure)