66f11d1869
Multi-field variants use Enum_Variant_Payload nested types (avoids tag name clash). Sema resolves data.Variant.Variant_i; enum field types fully resolve tuples. Selfhost parses full type exprs in enum payloads; emit structs/tuples before enums. Example: examples/nested_patterns.bux (Pair::Two, Box::Val((a,c)), Shape::Dot).
17 KiB
17 KiB
Bux — План към „добър“ език (v0.5 → v1.0)
Дата: 2026-07-18
Текущо: v0.5.x — selfhost loop, gradual ownership, green threads, 41+ examples, match + pattern bindings +f"..."interp bootstrap+selfhost ✅
Цел: Език, с който се пишат реални проекти комфортно, безопасно (по избор) и с надежден toolchain.
Диагноза (къде сме)
| Слой | Състояние | Оценка |
|---|---|---|
| Frontend (lex/parse) | Пълен Pratt parser, recovery | ★★★★☆ |
| Sema / generics | Monomorphization, trait bounds basic | ★★★★☆ |
| HIR → C | Tuples + fat func ABI в bootstrap и selfhost |
★★★★☆ |
Selfhost (src/) |
~12k LOC, binary-identical loop, closures+tuples | ★★★★★ |
| Gradual ownership | @[Checked], &/&mut, move, Drop |
★★★☆☆ (basic) |
| Concurrency | M:N tasks + channels + async | ★★★★☆ |
| Stdlib | Array/Map/Set/String/Iter HOF разширени | ★★★★☆ |
| Tooling | test-errors, LSP diagnostics + hover/def/outline |
★★★★☆ |
| Ecosystem / registry | path+git deps; няма централен registry | ★☆☆☆☆ |
| Документация | README + QUALITY_PLAN синхронизирани (2026-07-15) | ★★★★☆ |
Силна ниша: gradual ownership (C-скорост на писане + opt-in Rust-safety).
Слабо място: ergonomics на stdlib + maturity на tooling + пълнота на borrow checker.
Какво значи „добър“ за Bux
- Ежедневен DX — колекции, string, assert, грешки, които разбираш за секунди.
- Предвидима безопасност —
@[Checked]да хваща 80% от UAF/double-borrow без lifetime hell. - Selfhost като dogfood — компилаторът и apps (
nexus,boko) са proof. - Инструменти — fmt, test, LSP, package install без ръчна магия.
- Стабилна спецификация — LanguageRef = реалното поведение.
Не целим „по-добър Rust“. Целим единствения език с gradual safety + Go-стил concurrency без GC.
Фази
A — Ergonomics & Stdlib (P0) ✅ (core done)
| # | Задача | Защо | Статус |
|---|---|---|---|
| A.1 | Array: Pop, Clear, IsEmpty, First, Last, Cap, Reserve | Без това колекциите са неудобни | ✅ (тази сесия) |
| A.2 | String: IsEmpty, ReplaceAll | Чести операции; само first-replace досега | ✅ (тази сесия) |
| A.3 | Os_Exit + Test_AssertEqString / richer asserts | Тестове и CLI без raw bux_exit |
✅ (тази сесия) |
| A.4 | Map_Remove / Set polish | Completeness на колекциите | ✅ (тази сесия) |
| A.5 | Iter: map/filter/fold върху closures | Higher-order без boilerplate | ✅ generic Iter_Map/Filter/Fold + Int aliases |
| A.6 | Result helpers: Expect, UnwrapErr, Or | По-малко match boilerplate | ✅ (тази сесия) |
B — Compiler Correctness (P0)
| # | Задача | Защо | Статус |
|---|---|---|---|
| B.1 | Proper tuple types в C backend | (T,U) → Tuple_T_U struct + .0/.1 |
✅ bootstrap + selfhost |
| B.2 | Function pointer types | func(T)->U fat ABI |
✅ bootstrap + selfhost |
| B.3 | Match expression lowering (literals, ranges, enums) | Expression-context match → if-else | ✅ bootstrap + selfhost |
| B.3b | Pattern bindings (Some(value) => value) |
Payload idents bound in arm body | ✅ bootstrap + selfhost |
| B.4 | Closures multi-instance | Fat BuxFn + heap env |
✅ bootstrap + selfhost |
| B.4b | Closures: || empty params + loop/return body |
Lexer || vs empty closure; while/break/return |
✅ bootstrap + selfhost |
| B.5 | По-добри diagnostics (snippet + hint) | DX #1 за нови потребители | ✅ |
| B.6 | Bootstrap ↔ selfhost feature parity | empty ||, match-as-expr, string interp f"..." bootstrap+selfhost |
✅ |
C — Gradual Ownership 2.0 (P1)
| # | Задача | Защо |
|---|---|---|
| C.1 | Lifetime elision за common cases | Без 'a в 90% от API-тата |
| C.2 | Exclusive &mut vs shared & data-flow |
По-малко false negatives |
| C.3 | Auto-drop edge cases (early return, branches) | RAII да е надежден |
| C.4 | @[Release] zero-cost path документация + golden tests |
Killer story: safe default, free hot path |
D — Tooling (P1)
| # | Задача | Защо | Статус |
|---|---|---|---|
| D.1 | LSP: hover, go-to-def, diagnostics | IDE = adoption | ✅ hover/def/outline + buxc diags (lightweight index; full sema later) |
| D.2 | bux fmt стабилен + CI check |
Единен style | ⏳ |
| D.3 | bux test с --filter, exit codes, summary table |
CI-friendly | ⏳ partial (bux test exists) |
| D.4 | bux doc от /// comments |
Самодокументиращ се stdlib | ⏳ |
| D.5 | Golden tests за stdlib modules | Регресии без изненади | ⏳ |
E — Ecosystem & v1.0 (P2)
| # | Задача | Защо |
|---|---|---|
| E.1 | Package registry protocol (git/HTTP) | bux add foo без path hacks |
| E.2 | 3–5 production-quality apps в apps/ |
Showcase |
| E.3 | Language freeze + semver policy | Trust |
| E.4 | Debugger/DWARF basics | Systems audience |
| E.5 | Benchmarks vs C/Zig/Nim (micro + nexus) | Marketing + regression |
Препоръчан ред на работа
A (stdlib ergonomics) → B (compiler holes) → C (ownership depth)
↓ ↓
D (tooling) ←────────── dogfood apps
↓
E (v1.0 ecosystem)
Правило: всяка сесия ship-ва нещо runnable (stdlib API, fix, example), не само docs.
Acceptance criteria за „добър v1.0“
- Всички examples + selfhost-loop + 3 apps минават на CI
- Array/Map/String/Test API покрива 90% от ежедневните нужди
@[Checked]хваща use-after-move + double&mutв documented subsetbux test+bux fmt+bux checkса default developer loop- LanguageRef синхронизиран с компилатора
- Поне един външен проект (не в monorepo) build-ва с git dep
Сесия 1 (stdlib ergonomics)
Array_Pop,Array_Clear,Array_IsEmpty,Array_First,Array_Last,Array_Cap,Array_ReserveString_IsEmpty,String_ReplaceAllOs_ExitTest_AssertEqString,Test_AssertNeqInt,Test_AssertEqBool- Example + docs update
Сесия 2 (collections + tuples)
Map_Remove/Map_Clear/Map_IsEmpty(+ StringMap)Set_Remove/Set_Clear/Set_IsEmptyResult_Expect/Result_UnwrapErr/Result_OrOption_Expect/Option_Or- Tuples:
(T, U)→typedef struct { T _0; U _1; } Tuple_T_U+ field access.0/.1 - Examples:
tuples,func_ptr,map_remove
Сесия 3 (diagnostics + collections)
- Rust-style errors in bootstrap CLI:
--> file:line:col, source snippet,^caret,= help:hints SourceLocation.filepropagated from lexer- Better caret for type-mismatch on
let(points at initializer) Array_Contains/Array_IndexOf/Array_ExtendIter_AnyEq/Iter_AllEq/Iter_Collect- Selfhost
Diagnostic_Hintfor common messages
Сесия 4 (diagnostics depth + LSP + strings)
- Multi-char underlines (
^^^^^^^under tokens/strings/idents) - Quoted-name highlighting for
undeclared identifier 'x' - Golden error tests (
tests/error_golden/,make test-errors) - LSP runs
buxc checkand publishes real diagnostics String_IsBlank/String_Repeat
Сесия 5 (multi-instance closures)
- Fat function pointers for all
func(...)types:BuxFn { code(env, args...), env } - Capturing closures: heap-allocate env per creation site (independent instances)
- Capture-less closures + named funcs: adapters with
env = NULL - Calls through func values:
f.code(f.env, args...) - Example
multi_closure.bux— MakeAdder(10)/MakeAdder(20) yield 11 and 21 - Selfhost parity: same fat ABI in
src/hir_lower.bux+src/c_backend.bux(makers, adapters)
Сесия 6 (selfhost tuples)
- Parser:
(T, U)types,(a, b)exprs, field access.0/.1 - Sema: tekTuple / ekTuple
- HIR lower →
hStructInitofTuple_int_int - C backend:
typedef struct Tuple_int_int { int _0; int _1; } - Verified with
buxc2onexamples/tuples.bux
Сесия 7 (Iter HOF)
Iter_MapInt/FilterInt/FoldInt/ForEachInt/AnyInt/AllInt/SumInt- Named funcs + capturing closures (fat ABI)
- Example
iter_hof.bux(sum=15, product=120) - Selfhost fix: pointer
->field access; no bogus bounds check onarr.data[len](Push)
Сесия 8 (match expression + error goldens)
- Match expression lowering (B.3):
pkLiteral,pkRange(a..b/a..=b), enum tags, wildcard- Bugfix: literal arms were always-true (
elsebranch) →match 1 { 1=>10, 2=>20 }returned 10 for all skMatchnow also lowers vialowerMatch(void result)
- Bugfix: literal arms were always-true (
- Expanded
examples/pattern_matching.bux(enums + classify ranges + string arms) - Error golden cases (
tests/error_golden/):parse_error— incompletelet x = ;use_after_move—@[Checked]+own Stringdouble_mut_borrow— two&mutof same var
run.shnormalize: absolute paths in "parse errors in …" lines
Сесия 9 (selfhost match — B.6 parity)
- AST:
MatchArmlinked list;Pattern.patChild1/2for ranges;Expr.matchArms - Parser: full
parserParsePattern/parserParseMatchExpr(was skip-arms stub)- literals,
_, ident,Enum::Variant/Enum::Variant(...), ranges - statement
match→skExpr+ekMatch
- literals,
- Sema: type-check subject + arms; propagate first-arm type to
expr.refType - HIR lower:
Lcx_LowerMatch→ alloca result + if-else stores (enum.tag/ simple / literal / range) - Last-expr return:
Lcx_LowerBlockconverts finalskExprintoreturn(needed forfunc F() -> T { match ... }) - Verified:
pattern_matchingvia buxc2; simple enum + ranges; selfhost-loop IDENTICAL ✓
Сесия 10 (pattern bindings — B.3b)
- Bootstrap sema:
extractPatternBindingsresolves enum payload field types from variant decl - Bootstrap HIR:
matchPatternBindings→alloca name; name = subject.data.Variant_ibefore arm body - Match result type: fall back to
currentFuncRetTypewhen arm bodies only use bindings - Multi-field enum layout: positional
fields.len > 1→ nested struct in_Dataunion (no overlay) - Selfhost: parse
patArgslinked list;Sema_BindPattern;Lcx_PatternBindingsin match arms - Example:
pattern_matching.buxusesOption::Some(value) => value(real binding, notopt.data.Some_0) - Verified: bootstrap + buxc2 + all examples + error goldens + selfhost-loop IDENTICAL ✓
Сесия 11 (empty || closures + match-as-expr — B.4b)
- Bug:
|| -> int { ... }lexed astkPipePipe(logical-or), not twotkPipe→ empty-param closures failed to parse - Fix bootstrap: primary
of tkPipePipe:→ zero-paramekClosure - Fix selfhost:
parserParseEmptyClosurefortkPipePipe - Match-as-expr: expression-form match now skips newlines (same as statement form) →
let x = match n { ... }works - Verified control-flow in closure body: while/break, early return from loop, multi-return if-chain
- Pattern bind reuse: one alloca per binding name per function (
patternBoundNames) so two matches can both usev - Selfhost match-as-expr: let-init + binary operands expand yield blocks (
Lcx_IsMatchYield/__binop_N) - Examples:
closure_control.bux,match_let.bux - Verified: bootstrap + buxc2 + all examples + error goldens + selfhost-loop IDENTICAL ✓
Сесия 12 (string interpolation selfhost — B.6)
- Selfhost parser:
parserParseStringInterp— interleaved lit/expr parts incallArgs, nested fragment parse viaLexer_Tokenize+ sub-parser - Selfhost sema/HIR:
ekStringInterp→String_Concat+String_FromInt/FromBool/FromFloat - Bootstrap fix:
f"plain"no longer keeps thefprefix in the literal;\{/\}preserved by lexer and unescaped by interp parser - Lexer:
\{/\}allowed (bootstrap + selfhost) so LanguageRef escape rules work - Compiler hygiene: original dense
&&/||in the large interp loop caused bootstrap OOM (~27 GB) when compilingparser.bux— rewrite with simpler control flow - Example:
examples/string_interp.bux(name/int/bool/plain/escaped braces) - Verified: bootstrap + buxc2 + all 41 examples + error goldens + selfhost-loop IDENTICAL ✓
Сесия 13 (LSP hover / go-to-def / outline — D.1)
- Richer symbol index:
funcsignatures (params+-> Ret),let/var/constwith types,struct/enum/union/interface/type/module - Skip comments/strings during scan (no false
funchits) - Hover: markdown
bux signature+ kind; accurate word range - Go-to-definition: current file + workspace index (scan
.buxunder rootUri) - Document symbols (outline) via
textDocument/documentSymbol - didChange refreshes symbols immediately; didSave/didOpen still run
buxc checkdiagnostics - Fix: responses write to stdout (was writing to stdin stream → broken pipe)
- Version
bux-lsp0.2.0; smoke-tested via JSON-RPC
Сесия 14 (generic Iter map/filter/fold)
Iter_Map<T,U>/Filter<T>/Fold<T,Acc>/Any/All/ForEach— fatfuncparams + monomorphization- Int aliases keep working:
Iter_MapInt→Iter_Map<int,int>, … - Bootstrap fixes:
- call return type for local fat-func (
f: func(T)->U) after mono (was alwaysint→ String map truncated pointers) - generic call
Foo<T>(…)now type-checks args (closures get capture analysis)
- call return type for local fat-func (
- Selfhost fixes:
Lcx_SubstituteTyperecurses intotekFunc(was leavingBuxFn_U_T)- fat typedef emit covers cstr shapes +
#ifndefguards
- Example:
examples/iter_generic.bux(int↔String map, filter, fold, closures) - Verified: bootstrap + buxc2 + selfhost-loop IDENTICAL ✓
Сесия 15 (struct/tuple patterns)
- Tuple patterns:
match t { (a, b) => a + b }— bindsubject._0/._1 - Struct patterns:
Point { x: px, y: py }+ shorthandPoint { x, y } - Bootstrap:
matchPatternBindingsfor pkTuple/pkStruct; field types from struct decl; range registration of local tuple typedefs - Selfhost: parse
()/Name { … }patterns;Sema_BindPattern+Lcx_PatternBindingswith Scope_Define - Fix: operator-overload path treated
String_Eq(null, "")as non-empty → crash ona + bafter pattern bind - Example:
examples/struct_tuple_pat.bux - Verified: bootstrap + buxc2 + selfhost-loop IDENTICAL ✓
Сесия 16 (match block arms + block expressions)
- Block-as-expression:
let r = { let x = 1; x + 2 }— last skExpr is the value - Multi-stmt match arms:
1 => { PrintLine("…"); let a = 10; a + 1 } - Bootstrap:
lowerBlock(..., asExpr)promotes last expression; nested enum/struct pattern bindings - Selfhost: parse
{ … }asekBlock; yield temps__blk_N; fixIsMatchYieldnull-strValue false positive; retTypeKind-2for expr blocks - Nested:
Shape::Dot(Point { x, y })works on bootstrap; selfhost covers struct/tuple/enum + block arms - Example:
examples/match_block.bux - Verified: bootstrap + buxc2 + selfhost-loop IDENTICAL ✓
Сесия 17 (deeper nested patterns + multi-field enum layout)
- Multi-field payload type: nested struct
Enum_Variant_Payload(suffix avoids clash with tagEnum_Variant) - Bootstrap: full
resolveTypeExprfor enum field types (tuples/pointers); sema synthetic field lookup on payload types;data.Two.Two_0construction - LIR C backend: emit tuple typedefs before enums that embed them; topo deps for
*_Payload - Selfhost: enum variants parse full types (
parserParseType) — fixesVal((int,int)); storefieldTypeName*; structs before enums (e.g.Dot(Point)) - Patterns:
Pair::Two(a, b),Box::Val((a, c)),Shape::Dot(Point { x, y })+ block arms - Example:
examples/nested_patterns.bux - Verified: bootstrap + buxc2 + selfhost-loop IDENTICAL ✓
Следващи стъпки
- LSP: wire hover types from real sema
- Generic type inference for
Iter_Mapwithout explicit<T,U> - Match arm guards (
p if cond => …) - Pattern binding name shadowing (C locals are function-scoped)