Commit Graph

102 Commits

Author SHA1 Message Date
3cdde02eb2 feat: add Int.toFloat/Float.toInt JS backend support and fix Map C codegen
- JS backend: Add Int/Float module dispatch in both Call and EffectOp paths
  for toFloat, toInt, and toString operations
- C backend: Fix lux_strdup → lux_string_dup in Map module codegen

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 02:05:40 -05:00
a5762d0397 feat: add built-in Map type with String keys
Add Map<String, V> as a first-class built-in type for key-value storage,
needed for self-hosting the compiler (parser/typechecker/interpreter all
rely heavily on hashmaps).

- types.rs: Type::Map(K,V) variant, all match arms (unify, apply, etc.)
- interpreter.rs: Value::Map, 12 BuiltinFn variants (new/set/get/contains/
  remove/keys/values/size/isEmpty/fromList/toList/merge), immutable semantics
- typechecker.rs: Map<K,V> resolution in resolve_type
- js_backend.rs: Map as JS Map with emit_map_operation()
- c_backend.rs: LuxMap struct (linear-scan), runtime fns, emit_map_operation()
- main.rs: 12 tests covering all Map operations
- validate.sh: now checks all projects/ directories too

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 01:45:13 -05:00
1132c621c6 fix: allow newlines before then in if/then/else expressions
The parser now skips newlines between the condition and `then` keyword,
enabling multiline if expressions like:
  if long_condition
    then expr1
    else expr2

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 01:38:05 -05:00
a0fff1814e fix: JS backend scoping for let/match/if inside closures
Three related bugs fixed:
- BUG-009: let bindings inside lambdas hoisted to top-level
- BUG-011: match expressions inside lambdas hoisted to top-level
- BUG-012: variable name deduplication leaked across function scopes

Root cause: emit_expr() uses writeln() for statements, but lambdas
captured only the return value, not the emitted statements. Also,
var_substitutions from emit_function() leaked to subsequent code.

Fix: Lambda handler now captures all output emitted during body
evaluation and places it inside the function body. Both emit_function
and Lambda save/restore var_substitutions to prevent cross-scope leaks.
Lambda params are registered as identity substitutions to override any
outer bindings with the same name.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 01:10:55 -05:00
4e9e823246 fix: record spread works with named type aliases
Resolve type aliases (e.g. Player -> { pos: Vec2, speed: Float })
before checking if spread expression is a record type. Previously
{ ...p, field: val } failed with "must be a record type, got Player"
when the variable had a named type annotation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 00:01:20 -05:00
3d706cb32b feat: add record spread syntax { ...base, field: val }
Adds spread operator for records, allowing concise record updates:
  let p2 = { ...p, x: 5.0 }

Changes across the full pipeline:
- Lexer: new DotDotDot (...) token
- AST: optional spread field on Record variant
- Parser: detect ... at start of record expression
- Typechecker: merge spread record fields with explicit overrides
- Interpreter: evaluate spread, overlay explicit fields
- JS backend: emit native JS spread syntax
- C backend: copy spread into temp, assign overrides
- Formatter, linter, LSP, symbol table: propagate spread

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 23:05:27 -05:00
7c3bfa9301 feat: add Math.sin, Math.cos, Math.atan2 trig functions
Adds trigonometric functions to the Math module across interpreter,
type system, and C backend. JS backend already supported them.
Also adds #include <math.h> to C preamble and handles Math module
calls through both Call and EffectOp paths in C backend.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 23:05:12 -05:00
b56c5461f1 fix: JS const _ duplication and hardcoded version string
- JS backend now emits wildcard let bindings as side-effect statements
  instead of const _ declarations, fixing SyntaxError on multiple let _ = ...
- Version string now uses env!("CARGO_PKG_VERSION") to auto-sync with Cargo.toml
- Add -lm linker flag for math library support

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 23:05:03 -05:00
61e1469845 feat: add ++ concat operator and auto-invoke main
BUG-004: Add ++ operator for string and list concatenation across all
backends (interpreter, C, JS) with type checking and formatting support.

BUG-001: Auto-invoke top-level `let main = fn () => ...` when main is
a zero-parameter function, instead of just printing the function value.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 22:01:41 -05:00
d05b13d840 fix: JS backend compiles print() to console.log()
Bare `print()` calls in Lux now emit `console.log()` in JS output
instead of undefined `print()`. Fixes BUG-006.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 21:09:07 -05:00
bd843d2219 fix: record type aliases now work for unification and field access
Expand type aliases via unify_with_env() everywhere in the type checker,
not just in a few places. This fixes named record types like
`type Vec2 = { x: Float, y: Float }` — they now properly unify with
anonymous records and support field access (v.x, v.y).

Also adds scripts/validate.sh for automated full-suite regression
testing (Rust tests + all 5 package test suites + type checking).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 20:21:29 -05:00
c23d9c7078 fix: test runner now supports module imports
The `lux test` command used Parser::parse_source() and
check_program() directly, which meant test files with `import`
statements would fail with type errors. Now uses ModuleLoader
and check_program_with_modules() to properly resolve imports,
and run_with_modules() for execution.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 17:11:16 -05:00
fffacd2467 feat: C backend module import support, Int/Float.toString, Test.assertEqualMsg
The C backend can now compile programs that import user-defined modules.
Module-qualified calls like `mymodule.func(args)` are resolved to prefixed
C functions (e.g., `mymodule_func_lux`), with full support for transitive
imports and effect-passing. Also adds Int.toString/Float.toString to type
system, interpreter, and C backend, and Test.assertEqualMsg for labeled
test assertions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 16:35:24 -05:00
2ae2c132e5 docs: add language philosophy document and compiler integration
Write comprehensive PHILOSOPHY.md covering Lux's six core principles
(explicit over implicit, composition over configuration, safety without
ceremony, practical over academic, one right way, tools are the language)
with detailed comparisons against JS/TS, Python, Rust, Go, Java/C#,
Haskell/Elm, and Gleam/Elixir. Includes tooling audit and improvement
suggestions.

Add `lux philosophy` command to the compiler, update help screen with
abbreviated philosophy, and link from README.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 10:19:29 -05:00
8e788c8a9f fix: embed C compiler path at build time for self-contained binary
build.rs captures the absolute path to cc/gcc/clang during compilation
and bakes it into the binary. On Nix systems this embeds the full
/nix/store path so `lux compile` works without cc on PATH.

Lookup order: $CC env var > embedded build-time path > PATH search.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 08:12:18 -05:00
6bedd37ac7 fix: show help menu when running lux with no arguments
Previously `lux` with no args entered the REPL. Now it shows the help
menu. Use `lux repl` to start the REPL explicitly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 07:34:09 -05:00
2909bf14b6 fix: eliminate all non-json C backend errors (79→0)
Second round of C backend fixes, building on d8871ac which reduced
errors from 286 to 111. This eliminates all 79 non-json errors:

- Fix function references as values (wrap in LuxClosure*)
- Fix fold/map/filter with type-aware calling conventions
- Add String.indexOf/lastIndexOf emission and C runtime functions
- Add File.readDir with dirent.h implementation
- Fix string concat in closure bodies
- Exclude ADT constructors from closure free variable capture
- Fix match result type inference (prioritize pattern binding types)
- Fix Option inner type inference (usage-based for List.head)
- Fix void* to struct cast (dereference through pointer)
- Handle constructors in emit_expr_with_env

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 05:56:21 -05:00
d8871acf7e fix: improve C backend robustness, reduce compilation errors by 61%
- Fix closure captured variable types: look up actual types from var_types
  instead of hardcoding LuxInt for all captured variables
- Register function parameters in var_types so closures can find their types
- Replace is_string_expr() with infer_expr_type() for more accurate string
  detection in binary ops (concat, comparison)
- Add missing String operations to infer_expr_type (substring, indexOf, etc.)
- Add module method call type inference (String.*, List.*, Int.*, Float.*)
- Add built-in Result type (Ok/Err) to C prelude alongside Option
- Register Ok/Err/Some/None in variant_to_type and variant_field_types
- Fix variable scoping: use if-statement pattern instead of ternary when
  branches emit statements (prevents redefinition of h2/h3 etc.)
- Add RC scope management for if-else branches and match arms to prevent
  undeclared variable errors from cleanup code
- Add infer_pattern_binding_type for better match result type inference
- Add expr_emits_statements helper to detect statement-emitting expressions
- Add infer_option_inner_type for String.indexOf (returns Option<Int>)

Reduces blu-site compilation errors from 286 to 111 (remaining are mostly
unsupported json effect and function-as-value references).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 17:56:27 -05:00
542255780d feat: add tuple index access, multiline args, and effect unification fix
- Tuple index: `pair.0`, `pair.1` syntax across parser, typechecker,
  interpreter, C/JS backends, formatter, linter, and symbol table
- Multi-line function args: allow newlines inside argument lists
- Fix effect unification for callback parameters (empty expected
  effects means "no constraint", not "must be pure")

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 16:21:48 -05:00
bac63bab2a feat: add blu-site static site generator and fix language issues
Build a complete static site generator in Lux that faithfully clones
blu.cx (elmstatic). Generates 14 post pages, section indexes, tag pages,
and a home page with snippets grid from markdown content.

Language fixes discovered during development:
- Add \{ and \} escape sequences in string literals (lexer)
- Register String.indexOf and String.lastIndexOf in type checker
- Fix formatter to preserve brace escapes in string literals
- Improve LSP hover to show documentation for let bindings and functions

ISSUES.md documents 15 Lux language limitations found during the project.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 15:43:05 -05:00
db82ca1a1c fix: improve LSP hover to show function info when cursor is on fn keyword
When hovering on declaration keywords (fn, type, effect, let, trait),
look ahead to find the declaration name and show that symbol's full
info from the symbol table instead of generic keyword documentation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 08:32:01 -05:00
e3b6f4322a fix: add Char pattern matching and Char comparison operators
- Parser: support Char literals in match patterns (e.g., 'x' => ...)
- Interpreter: add Char comparison for <, <=, >, >= operators
  Previously only Int, Float, and String supported ordering comparisons.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 08:25:15 -05:00
d26fd975d1 feat: enhance LSP with inlay hints, parameter hints, and improved hover
Add inlay type hints for let bindings, parameter name hints at call sites,
behavioral property documentation in hover, and long signature wrapping.

- Inlay hints: show inferred types for let bindings without annotations
- Parameter hints: show param names at call sites for multi-arg functions
- Hover: wrap long signatures, show behavioral property docs (pure, total, etc.)
- Rich docs: detailed hover for keywords like pure, total, idempotent, run, with
- TypeChecker: expose get_inferred_type() for LSP consumption
- Symbol table: include behavioral properties in function type signatures

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 08:06:36 -05:00
1fa599f856 fix: support comma-separated behavioral properties without repeating 'is'
Allows `is pure, commutative` syntax in addition to `is pure is commutative`.
After the initial `is`, comma-separated properties no longer require repeating
the `is` keyword (though it's still accepted for compatibility).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 07:44:18 -05:00
19068ead96 feat: add lux lint command with Lux-specific static analysis
Implements a linter with 21 lint rules across 6 categories (correctness,
suspicious, idiom, performance, style, pedantic). Lux-specific lints include
could-be-pure, could-be-total, unnecessary-effect-decl, and single-arm-match.
Integrates lints into `lux check` for unified type+lint checking. Available
standalone via `lux lint` (alias: `lux l`) with --explain for detailed help.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 07:35:36 -05:00
8c90d5a8dc feat: CLI UX overhaul with colored output, timing, shorthands, and fuzzy suggestions
Add polished CLI output across all commands: colored help text, green/red
pass/fail indicators (✓/✗), elapsed timing on compile/check/test/fmt,
command shorthands (c/t/f/s/k), fuzzy "did you mean?" on typos, and
smart port-in-use suggestions for serve. Respects NO_COLOR/TERM=dumb.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 06:52:36 -05:00
bc60f1c8f1 fix: improve error message for bare 'run' expressions at top level
When users write `run main() with {}` at top level instead of
`let _ = run main() with {}`, provide a helpful error message
explaining the correct syntax instead of the generic "Expected
declaration" error.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-16 23:40:15 -05:00
7e76acab18 feat: rebuild website with full learning funnel
Website rebuilt from scratch based on analysis of 11 beloved language
websites (Elm, Zig, Gleam, Swift, Kotlin, Haskell, OCaml, Crystal, Roc,
Rust, Go).

New website structure:
- Homepage with hero, playground, three pillars, install guide
- Language Tour with interactive lessons (hello world, types, effects)
- Examples cookbook with categorized sidebar
- API documentation index
- Installation guide (Nix and source)
- Sleek/noble design (black/gold, serif typography)

Also includes:
- New stdlib/json.lux module for JSON serialization
- Enhanced stdlib/http.lux with middleware and routing
- New string functions (charAt, indexOf, lastIndexOf, repeat)
- LSP improvements (rename, signature help, formatting)
- Package manager transitive dependency resolution
- Updated documentation for effects and stdlib
- New showcase example (task_manager.lux)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-16 23:05:35 -05:00
5a853702d1 fix: C backend string comparison, underscore patterns, and list memory
1. String == comparison now uses strcmp instead of pointer comparison
   - Added check in emit_expr() for BinaryOp::Eq/Ne on strings
   - Also fixed in emit_expr_with_env() for closures

2. Support `let _ = expr` pattern to discard values
   - Parser now accepts underscore in let bindings (both blocks and expressions)
   - C backend emits (void)expr; for underscore patterns

3. Fix list head/tail/get memory management
   - Added lux_incref() when extracting elements from lists
   - Prevents use-after-free when original list is freed

4. String.startsWith was already implemented (verified working)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-16 07:14:02 -05:00
4b553031fd fix: parser newline handling in lists and stdlib exports
- Fix parse_list_expr to skip newlines between list elements
- Add `pub` keyword to all exported functions in stdlib/html.lux
- Change List.foldl to List.fold (matching built-in name)
- Update weaknesses document with fixed issues

The module import system now works correctly. This enables:
- import stdlib/html to work as expected
- html.div(), html.render() etc. to be accessible
- Multi-line list expressions in Lux source files

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-16 06:51:37 -05:00
8a001a8f26 fix: C backend struct ordering enables native compilation
The LuxList struct body was defined after functions that used it,
causing "invalid use of incomplete typedef" errors. Moved struct
definition earlier, right after the forward declaration.

Compiled Lux now works and achieves C-level performance:
- Lux (compiled): 0.030s
- C (gcc -O3): 0.028s
- Rust: 0.041s
- Zig: 0.046s

Updated benchmark documentation with accurate measurements for
both compiled and interpreted modes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-16 05:14:49 -05:00
3ee3529ef6 feat: improve REPL with syntax highlighting and documentation
REPL improvements:
- Syntax highlighting for keywords (magenta), types (blue),
  strings (green), numbers (yellow), comments (gray)
- :doc command to show documentation for functions
- :browse command to list module exports
- Added docs for List, String, Option, Result, Console,
  Random, File, Http, Time, Sql, Postgres, Test modules

Example usage:
  lux> :doc List.map
  lux> :browse String
  lux> :doc fn

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-16 04:43:33 -05:00
87c1fb1bbd feat: add PostgreSQL driver with Postgres effect
Implements full PostgreSQL support through the Postgres effect:
- connect(connStr): Connect to PostgreSQL database
- close(conn): Close connection
- execute(conn, sql): Execute INSERT/UPDATE/DELETE, return affected rows
- query(conn, sql): Execute SELECT, return all rows as records
- queryOne(conn, sql): Execute SELECT, return first row as Option
- beginTx(conn): Start transaction
- commit(conn): Commit transaction
- rollback(conn): Rollback transaction

Includes:
- Connection tracking with connection IDs
- Row mapping to Lux records with field access
- Transaction support
- Example: examples/postgres_demo.lux
- Documentation in docs/guide/11-databases.md

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-16 04:30:44 -05:00
3a46299404 feat: Elm-quality error messages with error codes
- Add ErrorCode enum with categorized codes (E01xx parse, E02xx type,
  E03xx name, E04xx effect, E05xx pattern, E06xx module, E07xx behavioral)
- Extend Diagnostic struct with error code, expected/actual types, and
  secondary spans
- Add format_type_diff() for visual type comparison in error messages
- Add help URLs linking to lux-lang.dev/errors/{code}
- Update typechecker, parser, and interpreter to use error codes
- Categorize errors with specific codes and helpful hints

Error messages now show:
- Error code in header: -- ERROR[E0301] ──
- Clear error category title
- Visual type diff for type mismatches
- Context-aware hints
- "Learn more" URL for documentation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-16 04:11:15 -05:00
33b4f57faf fix: C backend String functions, record type aliases, docs cleanup
- Add String.fromChar, chars, substring, toUpper, toLower, replace,
  startsWith, endsWith, join to C backend
- Fix record type alias unification by adding expand_type_alias and
  unify_with_env functions
- Update docs to reflect current implementation status
- Clean up outdated roadmap items and fix inconsistencies
- Add comprehensive language comparison document

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-16 01:06:20 -05:00
c6d7f5cffb refactor: interpreter and type system improvements
- Parser and typechecker updates for new features
- Schema evolution refinements
- Type system enhancements

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-15 03:54:23 -05:00
ccd335c80f feat: improve CLI with auto-discovery and JS target
- Auto-discover .lux files for fmt and check commands
- Add --target js flag for JavaScript compilation
- Improve help text for new features

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-15 03:54:11 -05:00
40c9b4d894 feat: complete JS backend with Dom effect and Html module
- Add full Dom effect: querySelector, createElement, addEventListener,
  setAttribute, classList, styles, forms, scrolling, etc.
- Add Html module for type-safe HTML construction (Elm-style)
- Add TEA (The Elm Architecture) runtime for browser apps
- Add view dependency analysis for Svelte-style optimizations
- Support both browser and Node.js environments

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-15 03:54:04 -05:00
c13d322342 feat: integrate package manager with module loader
- Auto-add .lux_packages/ to module search paths
- Find project root by looking for lux.toml
- Enable importing modules from installed packages

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-15 03:53:56 -05:00
6511c289f0 feat: add unicode escape sequences to lexer
Support \xNN (hex) and \u{NNNN} (unicode) escape sequences in strings.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-15 03:53:49 -05:00
f33ea5f7f7 fix: implement complete RC memory safety in C backend
- Add magic number system (LUX_RC_MAGIC) to distinguish RC-managed
  allocations from static string literals, preventing crashes on decref
- Convert string helpers (trim, lines, split) to use lux_rc_alloc
- Track inline RC temps from effect operations (Process.exec, File.read,
  Console.readLine, Http ops, String ops) by creating temp variables
- Implement ownership transfer: when RC temp is bound to a variable,
  unregister temp and only track bound variable to avoid double-free
- Result: grapho runs with 0 memory leaks

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-15 03:53:42 -05:00
38bf825134 feat: add effects to JS backend and fix code generation bugs
Phase 2 of JS backend: implement effect handlers in runtime

Effects added:
- Console: print, readLine, readInt
- Random: int, bool, float
- Time: now, sleep
- Http: get, post, postJson (async with fetch)

Bug fixes:
- Fix if-else with blocks executing both branches (use if-else
  statement instead of ternary for branches with statements)
- Fix main function being called twice when top-level let binding
  already invokes it
- Fix List module operations incorrectly treated as effect operations

New tests:
- test_js_random_int
- test_js_random_bool
- test_js_random_float
- test_js_time_now

All 19 JS backend tests pass.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 21:34:07 -05:00
ce4344810d test: add comprehensive integration tests for JS backend
Add 10 integration tests that compile Lux to JavaScript and verify
correct execution in Node.js:

- test_js_factorial: Recursion and effects
- test_js_fibonacci: Classic recursive algorithm
- test_js_adt_and_pattern_matching: Custom ADTs with match
- test_js_option_type: Built-in Option type handling
- test_js_closures: Closure creation and variable capture
- test_js_higher_order_functions: Functions as values
- test_js_list_operations: List.map, List.foldl
- test_js_pipe_operator: Pipe (|>) operator
- test_js_records: Record literal and field access
- test_js_string_concatenation: String operations

Also fix List module operations being incorrectly treated as effects
by adding special-case handling in EffectOp emission.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 21:28:07 -05:00
10ff8dc6ad feat: add JavaScript backend for browser/Node.js compilation
Implement Phase 1 of the browser/frontend plan with a complete JS
code generator that compiles Lux programs to JavaScript:

- Basic types: Int, Float, Bool, String, Unit → JS primitives
- Functions and closures → native JS functions with closure capture
- Pattern matching → if/else chains with tag checks
- ADT definitions → tagged object constructors
- Built-in types (Option, Result) → Lux.Some/None/Ok/Err helpers
- Effects → handler objects passed as parameters
- List operations → Array methods (map, filter, reduce, etc.)
- Top-level let bindings and run expressions

CLI usage:
  lux compile app.lux --target js -o app.js
  lux compile app.lux --target js --run

Tested with factorial, datatypes, functional, tailcall, and hello
examples - all producing correct output when run in Node.js.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 21:22:43 -05:00
f099b9fc90 fix: resolve all cargo compiler warnings
- Fix unused import std::io::Read in interpreter.rs by using qualified call
- Add #[allow(dead_code)] to CGenError.span (kept for future error reporting)
- Add #[allow(dead_code)] to local_vars field (planned for free variable analysis)
- Add #[allow(dead_code)] to unbox_value and emit_all_scope_cleanup methods

All 263 tests pass.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 15:26:21 -05:00
2960dd6538 feat: add benchmarks and enhance LSP completions/hover
Benchmarks:
- Add fib, list_ops, primes benchmarks comparing Lux vs Node.js vs Rust
- Lux matches Rust performance and is 8-30x faster than Node.js
- Add docs/benchmarks.md documenting results

LSP improvements:
- Context-aware completions (module access vs general)
- Add List, String, Option, Result, Console, Math method completions
- Add type and builtin completions
- Hover now shows type signatures and documentation for known symbols
- Hover returns formatted markdown with code blocks

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 15:23:35 -05:00
1ca31fe985 fix: track temporary strings from toString and concat for RC cleanup
- toString now stores result in temp variable and registers for RC
- String concatenation stores result and registers for RC
- Immediately decref temporary input strings after concat to avoid leaks
- Add is_rc_temp() helper to identify RC temporary variables

This fixes the memory leak where dynamically created strings from
toString() and string concatenation were not being freed.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 15:00:29 -05:00
bba94b534d feat: add FBIP debug counters to prove optimization effectiveness
Add runtime counters tracking FBIP reuse vs copy operations:
- lux_fbip_reuse_count: incremented when rc=1 allows in-place mutation
- lux_fbip_copy_count: incremented when rc>1 forces allocation

Output now shows both memory stats and FBIP stats:
  [RC] No leaks: 13 allocs, 13 frees
  [FBIP] 3 reuses, 0 copies

Rename test_no_fbip.lux to test_ownership_transfer.lux to better
reflect that ownership transfer enables FBIP even with aliases.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 14:52:35 -05:00
4d5a975b79 feat: implement FBIP (Functional But In-Place) reuse analysis
When rc=1 at update sites, mutate in-place instead of allocating new:

List.reverse:
- Swap element pointers in-place instead of creating new list

List.take:
- Truncate list in-place, decref dropped elements

List.drop:
- Shift elements to front in-place, decref dropped elements

List.map:
- Mutate elements in-place, decref old values before storing new

List.filter:
- Filter in-place by shifting kept elements, decref filtered-out elements

All operations check LUX_RC_HEADER(list)->rc == 1 at runtime and
fall back to allocation when rc > 1 (list is shared).

This completes Phase B performance optimizations:
- B1: Last-use optimization (ownership transfer) 
- B2: Reuse analysis (FBIP) 
- B3: Drop specialization 

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 14:37:15 -05:00
3a22ae089f feat: add drop specialization and ownership transfer optimizations
Phase B Performance Optimizations:

Drop Specialization:
- Add specialized decref functions: lux_decref_list, lux_decref_closure,
  lux_decref_string, lux_decref_boxed
- Inline drop logic eliminates polymorphic dispatch through lux_drop
- Forward type declarations (typedef struct X_s X) for proper C ordering

Ownership Transfer (Last-Use Optimization):
- Track variable types in var_types HashMap for type inference
- When assigning let b = a where a is RC-tracked:
  - Unregister source variable from RC cleanup
  - Register destination variable instead
- Prevents double-free and eliminates unnecessary incref/decref pairs

Also:
- Fix type inference for variable references in infer_expr_type
- Add is_rc_tracked() and unregister_rc_var() helper functions
- Update REFERENCE_COUNTING.md with Phase B progress

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 14:33:50 -05:00