Commit graph

36624 commits

Author SHA1 Message Date
Richard Feldman
13926dfdd3
Merge pull request #8724 from roc-lang/langref-more
More langref
2025-12-22 22:25:59 -05:00
Richard Feldman
eaac14cd43
Merge branch 'main' into langref-more 2025-12-22 22:25:52 -05:00
Richard Feldman
e5f0942b63
Update langref some more 2025-12-22 22:18:23 -05:00
Richard Feldman
35da162c5b
Merge pull request #8705 from roc-lang/cor-mono2
Expand monomorphization + tests
2025-12-22 22:09:45 -05:00
Richard Feldman
ee0c3bb2ba
Merge origin/main into cor-mono2
Resolved conflicts in:
- Monomorphizer.zig: Keep deletion of monomorphize() function
- RocEmitter.zig: Use cleaner e_lookup_external handling without capture
- roc_emitter_test.zig: Use undefined with comments for type vars

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-22 21:12:34 -05:00
Richard Feldman
ca2ba309c2
Merge pull request #8712 from roc-lang/fix-issue-8710
Fix memory leak with tag union payloads in decrefLayoutPtr
2025-12-22 17:02:42 -05:00
Richard Feldman
df08c27076
Workaround for Zig ar archive padding bug
Zig's archive generator doesn't add the required padding byte after
odd-sized members, causing lld to reject the archive. This adds a
build step that appends the missing padding byte when needed.

See https://codeberg.org/ziglang/zig/issues/30572

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-22 16:14:54 -05:00
Jared Ramirez
62d87db2ad
Merge pull request #8719 from roc-lang/jared/push-vltosqzkwqzk
Add newlines to where clause printing & use `addCodeblock`
2025-12-22 14:03:59 -05:00
Jared Ramirez
d60d8c1ff2
Fix CI 2025-12-22 13:28:06 -05:00
Jared Ramirez
fb45ff9bd5
Regenerate snapshots & move fns around in writer 2025-12-22 13:27:21 -05:00
Jared Ramirez
476df9c899
Add line breaks in type printing 2025-12-22 11:53:30 -05:00
Anton-4
d9d55b70db
fix #8646 (#8718) 2025-12-22 17:48:31 +01:00
Richard Feldman
4b857fa1cd
Merge pull request #8655 from roc-lang/gc-cache
Clean up cache files periodically
2025-12-21 22:24:03 -05:00
Richard Feldman
9bb77328a6
Add tag_union handling to decrefLayoutPtr to fix memory leak
The increfLayoutPtr function properly handled .tag_union layouts by
reading the discriminant and incrementing the reference count of the
active variant's payload. However, decrefLayoutPtr was missing this
handling entirely, causing memory leaks when tag union values with
heap-allocated payloads were freed.

This fix adds symmetric .tag_union handling to decrefLayoutPtr that
reads the discriminant and decrefs the active variant's payload.

Fixes #8710

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 21:57:49 -05:00
Richard Feldman
f71bf4bd0a Expand langref 2025-12-21 20:30:27 -05:00
Richard Feldman
c6415d8dc9
Merge pull request #8715 from roc-lang/langref-expressions
Langref: expressions
2025-12-21 18:34:38 -05:00
Richard Feldman
03359e613d Update outline to split out statements.md 2025-12-21 17:40:08 -05:00
Richard Feldman
2f1500a41a Finish expression.md 2025-12-21 17:34:14 -05:00
Richard Feldman
7be6ae4be6 Add expressions.md 2025-12-21 17:07:26 -05:00
Richard Feldman
221b1839bf
Merge origin/main into gc-cache
Resolved conflicts in src/cli/main.zig:
- Updated createUniqueTempDir to use ctx: *CliContext instead of allocs
- Kept cache cleanup via CacheConfig.getVersionTempDir approach
- Added background cache cleanup thread with new Io.init() pattern
- Updated exe_cache_dir to use ctx.arena with getExeCacheDir helper
- Fixed deleteTempDir calls to use ctx.arena

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 16:39:49 -05:00
Jared Ramirez
7dfb689652
Merge pull request #8713 from roc-lang/jared/push-txuwvknxkyzp 2025-12-21 16:20:59 -05:00
Richard Feldman
5028116939
Merge pull request #8714 from roc-lang/langref
Initial langref
2025-12-21 16:20:06 -05:00
Richard Feldman
667085624f Add a note about completeness of the langref 2025-12-21 15:13:20 -05:00
Richard Feldman
5d125e884e Update langref md to match outline 2025-12-21 15:07:34 -05:00
Richard Feldman
db84d06071 Add outline to readme 2025-12-21 15:02:30 -05:00
Richard Feldman
6faab6ca1e Add langref/ 2025-12-21 14:44:24 -05:00
Jared Ramirez
3972c989f5
Add list_append_unsafe 2025-12-21 11:48:09 -05:00
Jared Ramirez
8fd256d220
Add list.map snapshot and use mutable var in impl 2025-12-21 11:48:09 -05:00
Jared Ramirez
44bf01d518
Add try.map_ok and try.map_err 2025-12-21 11:48:09 -05:00
Richard Feldman
a14665e377
Merge pull request #8711 from roc-lang/fix-issue-8708
Fix TypeContainedMismatch when using type alias inside Try
2025-12-20 22:02:02 -05:00
Richard Feldman
c5895f7388
Fix TypeContainedMismatch when using type alias inside Try
The layout store was incorrectly adding alias types to in_progress_vars,
but aliases just continue to their backing type without ever being
"completed" (removed from in_progress_vars). This caused spurious cycle
detection when the same alias was encountered again during layout
computation for a nominal type like Try.

The fix is to skip adding aliases to in_progress_vars since they are
transparent wrappers that immediately continue to their backing type.

Fixes #8708

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-20 21:45:07 -05:00
Jared Ramirez
3691a92d99
Merge pull request #8709 from roc-lang/jared/push-kykmksrrkvvs
Move rank check to before annotation generation + adjustRank fixes
2025-12-20 19:10:35 -05:00
Jared Ramirez
648757e33a
Remove test file 2025-12-20 17:13:06 -05:00
Jared Ramirez
aa9e7bd71d
Add some comments 2025-12-20 17:13:06 -05:00
Jared Ramirez
4af41808b7
Move rank check to before annotation generation 2025-12-20 17:13:06 -05:00
Richard Feldman
3cc81a3055
Delete unused fn 2025-12-19 22:02:47 -05:00
Richard Feldman
2678128bbc
Use "#" for Closure prefix 2025-12-19 21:54:05 -05:00
Richard Feldman
7ae2aa1333
Merge pull request #8704 from roc-lang/cor-mono
Add Roc emitter and monomorphization infrastructure
2025-12-19 20:19:25 -05:00
Richard Feldman
7e5d219cdb
Fix unused variable suppressions and forbidden @enumFromInt(0)
- Remove unused `self` parameter from Monomorphizer.monomorphize placeholder
- Remove unused `lookup` capture in RocEmitter e_lookup_external handler
- Replace @enumFromInt(0) with undefined for variant_var/ext_var in test

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-19 18:30:48 -05:00
Richard Feldman
b93e9e15eb
Fix lint issues for minici
- Remove separator comments (// ====) from mono_emit_test.zig
- Use _ parameter instead of _ = self for unused self in Monomorphizer
- Use |_| pattern for unused lookup in RocEmitter
- Replace @enumFromInt(0) with undefined in roc_emitter_test.zig

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-19 16:26:12 -05:00
Richard Feldman
e47e2ae524
Add roundtrip tests for pure lambdas and nested closures
- Pure lambda test: validates closures with no captures work correctly
- Nested closure test: validates closures that return closures with
  captures (currying pattern) work correctly

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-19 16:05:00 -05:00
Richard Feldman
936980cca2
Fix tag syntax and add roundtrip verification tests
- Changed closure tag names from backtick syntax (`f) to capitalized
  tags (Closure_f) for valid Roc parsing
- Added roundtrip tests that verify transformed code evaluates to
  the same result as the original source
- Updated all tests to expect new Closure_ tag prefix

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-19 16:03:46 -05:00
Richard Feldman
cf973f2e68
Add dispatch match generation for closure calls
Completes the core of Slice 2 by implementing:

1. Closure binding tracking: The transformer now tracks which patterns
   are bound to closures via pattern_closures map.

2. Dispatch match generation: When a call is made to a closure variable,
   the transformer generates an inline match expression that:
   - Pattern matches on the closure tag to extract captures
   - Creates a block that binds call arguments to lambda parameters
   - Executes the original lambda body with both captures and args in scope

Example transformation:
```roc
# Input
{
    x = 42
    f = |y| x + y
    f(10)
}

# Output
{
    x = 42
    f = `f({x: x})
    match f {
        `f({x}) => {
            y = 10
            (x + y)
        },
    }
}
```

This completes the closure-to-defunctionalized-form transformation,
which is the foundation for lambda set specialization.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-19 15:54:51 -05:00
Richard Feldman
7c6ba3e843
Add ClosureTransformer to convert closures to tagged values
This implements the first part of Slice 2 (closures with captures) from the
monomorphization plan. The ClosureTransformer:

- Transforms closures with captures into tagged values with capture records
  e.g., `|y| x + y` with captured `x` becomes `` `f({x: x}) ``
- Transforms pure lambdas (no captures) into tags with empty records
- Generates unique tag names based on binding hints or counters
- Recursively transforms all expression types in the CIR

Tests verify transformation of:
- Pure lambdas to tags with empty records
- Closures with single capture
- Closures with multiple captures

Next step: implement dispatch function generation for call sites.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-19 15:46:05 -05:00
Richard Feldman
24dc77ab16
Add roundtrip verification tests for emitted Roc code
This adds tests that verify emitted Roc code produces the same results
as the original when run through the interpreter:

- evalToInt/evalToBool helpers for evaluating expressions
- Roundtrip tests for:
  - Integer literals
  - Arithmetic expressions
  - If expressions
  - Boolean True/False
  - Complex arithmetic

The tests parse source, emit it as Roc code, re-parse the emitted code,
run both through the interpreter, and verify they produce identical results.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-19 14:15:22 -05:00
Richard Feldman
7b42571799
Add Roc emitter and monomorphization infrastructure
This adds the foundation for the monomorphizing compiler:

- RocEmitter: Converts CIR (Canonical IR) to valid Roc source code
  - Handles all expression types (numbers, lambdas, records, tags, etc.)
  - Handles patterns and statements
  - Unit tests for basic expression emission

- Monomorphizer: Infrastructure for specializing polymorphic functions
  - Type hash computation for specialization keys
  - Specialized name generation
  - Integration with type system

- End-to-end tests in eval module:
  - Parse -> Canonicalize -> Type Check -> Emit pipeline
  - Tests for identity function, blocks, and basic expressions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-19 14:10:47 -05:00
Fabian Schmalzried
21c4cd5dfc
Improve render helper to render lists of tags correctly (#8702)
Improve render helper to render list content correctly
2025-12-19 10:32:33 +01:00
Luke Boswell
576feb3b26
Merge pull request #8629 from roc-lang/implement-box
Implement `Box` builtin
2025-12-19 13:10:16 +11:00
Jared Ramirez
54f0045112
Update snapshots 2025-12-18 12:42:33 -05:00
Jared Ramirez
ee9a76d80c
Add nice error messages 2025-12-18 12:11:03 -05:00