Skip to content

Commit be25367

Browse files
docs: update TODO to reflect Milestone E.27 completion
1 parent 6f31c85 commit be25367

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

.claude/TODO-pandoc.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ north-star integration target for BHC's real-world Haskell compatibility.
1818
## Current State
1919

2020
BHC compiles real Haskell programs to native executables via LLVM:
21-
- 83 native E2E tests passing (including monad transformers, file IO, markdown parser, JSON parser)
21+
- 85 native E2E tests passing (including monad transformers, file IO, markdown parser, JSON parser)
2222
- Monad transformers: StateT, ReaderT, ExceptT, WriterT all working
2323
- Nested transformer stacks: `StateT s (ReaderT r IO)` with cross-transformer `ask` working
2424
- MTL typeclasses registered: MonadReader, MonadState, MonadError, MonadWriter
@@ -50,11 +50,13 @@ BHC compiles real Haskell programs to native executables via LLVM:
5050
- Polymorphic compare and comparison operators for derived Ord (E.24)
5151
- String methods: fromString, read, readMaybe (E.25)
5252
- Data.List: sortOn, nubBy, groupBy, deleteBy, unionBy, intersectBy, stripPrefix, insert, mapAccumL, mapAccumR (E.26)
53-
- All intermediate milestones A–E.26 done
53+
- Data.Function: succ, pred, (&) reverse application (E.27)
54+
- Data.Tuple: swap, curry, uncurry + fst/snd as first-class closures (E.27)
55+
- All intermediate milestones A–E.27 done
5456

5557
### Gap to Pandoc
5658

57-
**Completed:** Self-contained programs with transformers, parsing, file IO, Text, ByteString, Text.IO, Data.Char, show for compound types, numeric conversions, IORef, exceptions, multi-package imports, Data.Maybe/Either utilities, extensive Data.List operations, when/unless/guard/any/all, monadic combinators (filterM/foldM/replicateM/zipWithM), Ordering ADT with compare, System.FilePath + System.Directory, Data.Map complete (update/alter/unions/keysSet), fixed DefId misalignment for Text/ByteString/exceptions (E.20), Bool ADT for container predicates (E.21), Data.Set/IntMap/IntSet full type support + codegen completions (E.22), stock deriving Eq/Show/Ord for user ADTs (E.23, E.24), String read/readMaybe/fromString (E.25), sortOn/nubBy/groupBy/deleteBy/unionBy/intersectBy/stripPrefix/insert/mapAccumL/mapAccumR (E.26)
59+
**Completed:** Self-contained programs with transformers, parsing, file IO, Text, ByteString, Text.IO, Data.Char, show for compound types, numeric conversions, IORef, exceptions, multi-package imports, Data.Maybe/Either utilities, extensive Data.List operations, when/unless/guard/any/all, monadic combinators (filterM/foldM/replicateM/zipWithM), Ordering ADT with compare, System.FilePath + System.Directory, Data.Map complete (update/alter/unions/keysSet), fixed DefId misalignment for Text/ByteString/exceptions (E.20), Bool ADT for container predicates (E.21), Data.Set/IntMap/IntSet full type support + codegen completions (E.22), stock deriving Eq/Show/Ord for user ADTs (E.23, E.24), String read/readMaybe/fromString (E.25), sortOn/nubBy/groupBy/deleteBy/unionBy/intersectBy/stripPrefix/insert/mapAccumL/mapAccumR (E.26), succ/pred/(&)/swap/curry/uncurry + fst/snd as first-class closures (E.27)
5860
**Missing for Pandoc:**
5961
1. **Full package system** — Basic import paths work (E.6), but no Hackage .cabal parsing yet
6062
2. **Lazy Text/ByteString** — Only strict variants implemented
@@ -280,7 +282,7 @@ compiled from Hackage source.
280282

281283
### 3.1 Remaining Codegen Builtins
282284

283-
**Status:** ~480+ of 587 builtins lowered (E.13–E.26 added ~70+ functions + derived dispatches)
285+
**Status:** ~490+ of 587 builtins lowered (E.13–E.27 added ~80+ functions + derived dispatches)
284286
**Scope:** Small-Medium (ongoing)
285287

286288
- [ ] Monadic codegen: general `>>=`, `>>`, `return` via dictionary dispatch
@@ -549,6 +551,20 @@ Rather than jumping straight to Pandoc, build toward it incrementally:
549551
- [x] E2E test: list_by_ops (13 assertions covering all 10 functions)
550552
- [x] 83 total E2E tests pass
551553

554+
### Milestone E.27: Data.Function + Data.Tuple Builtins ✅
555+
- [x] `succ`/`pred` via inline LLVM add/sub (Int → Int)
556+
- [x] `(&)` reverse application operator (a → (a → b) → b)
557+
- [x] `swap` for tuples: extract fields, allocate reversed tuple via `allocate_ptr_pair_tuple()`
558+
- [x] `curry`: allocate tuple from (x, y), call f(tuple) via 1-arg closure
559+
- [x] `uncurry`: extract fst/snd from pair, flat 3-arg call fn(env, fst, snd)
560+
- [x] `fst`/`snd` added to `lower_builtin_direct` for first-class closure use (e.g., `map fst pairs`)
561+
- [x] `succ`/`pred`/`swap` added to `lower_builtin_direct` for first-class closure use
562+
- [x] Fixed DefIds 11500-11505, arity + dispatch entries
563+
- [x] Show inference: succ/pred added to `expr_returns_int()`
564+
- [x] Key pitfall: BHC compiles multi-arg functions as FLAT `fn(env, x, y)`, not curried — uncurry must use 3-arg call
565+
- [x] E2E tests: data_function (succ/pred/(&)/map succ/map pred), tuple_functions (fst/snd/swap/curry/uncurry/map fst/map snd/map swap)
566+
- [x] 85 total E2E tests pass (83 existing + 2 new, 0 failures)
567+
552568
### Milestone F: Pandoc (Minimal)
553569
- [ ] Compile Pandoc with a subset of readers/writers (e.g., Markdown → HTML only)
554570
- [ ] Skip optional dependencies (skylighting, texmath, etc.)
@@ -587,6 +603,19 @@ Rather than jumping straight to Pandoc, build toward it incrementally:
587603

588604
## Recent Progress
589605

606+
### 2026-02-12: Milestone E.27 Data.Function + Data.Tuple Builtins
607+
- 6 new builtins: succ, pred, (&), swap, curry, uncurry
608+
- `succ`/`pred`: inline LLVM `build_int_add`/`build_int_sub` with `coerce_to_int``int_to_ptr`
609+
- `(&)`: reverse application — mirror of `lower_builtin_apply` with args swapped
610+
- `swap`: extract fst/snd via `extract_adt_field`, allocate reversed tuple via new `allocate_ptr_pair_tuple()` helper
611+
- `curry`: allocate tuple from (x, y) via `allocate_ptr_pair_tuple`, call f(tuple) via 1-arg closure
612+
- `uncurry`: extract fst/snd from pair, flat 3-arg call `fn_ptr(f_env, fst, snd)` — BHC uses flat calling convention, NOT curried
613+
- Added 5 entries to `lower_builtin_direct` for first-class closure use: fst, snd, succ, pred, swap
614+
- Fixed DefIds 11500-11505, arity entries in `builtin_info()`, dispatch in `lower_builtin()`
615+
- Key pitfall: uncurry initially used curried 2-step calls causing segfault — BHC compiles multi-arg user functions as FLAT `fn(env, x, y) -> result`
616+
- E2E tests: data_function (7 assertions), tuple_functions (10 assertions)
617+
- 85 E2E tests pass (83 existing + 2 new, 0 failures)
618+
590619
### 2026-02-11: Milestone E.26 More List Operations
591620
- 10 new RTS functions in `stdlib/bhc-base/src/list.rs`: sortOn, nubBy, groupBy, deleteBy, unionBy, intersectBy, stripPrefix, insert, mapAccumL, mapAccumR
592621
- Internal helpers: `extract_bool()` (handles both tagged-int-as-pointer and Bool ADT), `call_eq_closure()`, `alloc_nothing/just/tuple()`

0 commit comments

Comments
 (0)