# rille

This manual documents the `0.0.2` release of `Luna-Flow/rille`.

## Overview

`rille` draws the decision graph of a MoonBit function from its source: the
tests the function makes, its early exits and its calls, in the order the
flow meets them, each with the text as written and its position. Calls into
functions of the same module are followed to a depth limit. The graph is a
JSON document with stable ids, and the same graph can be printed as a list
of tests, Mermaid, Graphviz DOT or a plain text tree. Every output names its
producer: the version and commit of rille and the commit of the module it
read.

The tool reads syntax only. It never guesses: a call it cannot resolve from
what is written stays in the graph, marked unresolved, with the reason.

## Install

`rille` runs from the Mooncakes registry under `moonx`, sandboxed by a
policy that allows reading the module (see the
[command line tutorial](tutorial/cmd/rille.md)):

```bash
moonx --experimental-policy policy.json Luna-Flow/rille/cmd/rille@<version> help
```

or from a checkout:

```bash
git clone https://github.com/Luna-Flow/rille
cd rille
moon run src/cmd/rille -- help
```

The module needs the MoonBit toolchain with `moonc` 1.0.0-rc1 or later.

## Layers

| Layer | Package | Responsibility |
| --- | --- | --- |
| Vocabulary | `source` | `SourceFile`, `Span` |
| Syntax | `syntax` | the only importer of `moonbitlang/parser`: diagnostics and rille's view of a file |
| Configuration | `config` | `moon.mod` and `moon.pkg`: module name and version, imports, target files |
| Model | `graph` | node and edge kinds, `FnKey`, `SiteId`, `NodeId`, `Graph`, `GraphBuilder`, `Producer`, JSON form |
| Resolution | `resolve` | names to definitions; unresolved as a value with its reason |
| Walk | `walk` | the view of a body to a graph, through `GraphBuilder` |
| Rendering | `render` | text tree, test list, Mermaid and DOT, from the graph alone |
| Edge | `cmd/rille` | arguments, files (the module, its git commit), printing |

Dependencies point downward: `source` depends on nothing; `syntax`,
`config` and `graph` on `source` at most; `resolve` on `syntax` and
`graph`; `walk` on `resolve`; `render` on `graph`; only `cmd/rille` reads files or
prints.

## Pages

| Package | Tutorial | API | Design |
| --- | --- | --- | --- |
| `source`: files and spans | [tutorial](tutorial/source.md) | [API](api/source.md) | [design](design/source.md) |
| `syntax`: the parser, behind rille's own values | [tutorial](tutorial/syntax.md) | [API](api/syntax.md) | [design](design/syntax.md) |
| `config`: `moon.mod` and `moon.pkg` | [tutorial](tutorial/config.md) | [API](api/config.md) | [design](design/config.md) |
| `graph`: the decision graph and its JSON form | [tutorial](tutorial/graph.md) | [API](api/graph.md) | [design](design/graph.md) |
| `resolve`: names to definitions | [tutorial](tutorial/resolve.md) | [API](api/resolve.md) | [design](design/resolve.md) |
| `walk`: a function's decision graph | [tutorial](tutorial/walk.md) | [API](api/walk.md) | [design](design/walk.md) |
| `render`: text, Mermaid and DOT | [tutorial](tutorial/render.md) | [API](api/render.md) | [design](design/render.md) |
| `cmd/rille`: the command line | [tutorial](tutorial/cmd/rille.md) | [API](api/cmd/rille.md) | [design](design/cmd/rille.md) |

Guide: [verification against hand-drawn graphs](verification.md), the
acceptance of v0 on two decision graphs of floating, re-run when arm guards
became tests.

## Exported items

- `source`: `SourceFile`, `Span`
- `syntax`: `parse`, `ParsedFile`, `Item`, `FunctionDef`, `Owner`, `Body`,
  `TypeName`, `Binder`, `Expr`, `Callee`, `Arm`, `Guarded`, `Diagnostic`,
  `diagnostics`
- `config`: `module_info`, `ModuleInfo`, `package_config`, `PackageConfig`,
  `TargetCondition`, `is_code_file`, `ConfigError`
- `graph`: `FnKey`, `SiteId`, `NodeId`, `NodeKind`, `EdgeKind`,
  `Resolution`, `Unresolved`, `TargetChoice`, `Node`, `Edge`, `Graph`,
  `GraphBuilder`, `GraphError`, `Producer`, `Commit`, `schema_version`
- `resolve`: `Workspace`, `PackageSource`, `Resolver`, `Definition`,
  `WrittenType`
- `walk`: `draw`, `DrawError`
- `render`: `text_tree`, `test_list`, `mermaid`, `dot`, `default_width`

## Where to read next

- To read a graph in a program: the [graph tutorial](tutorial/graph.md).
- To see how ids are made and which invariants hold: the
  [graph design](design/graph.md).
- To draw a function in a program: the [walk tutorial](tutorial/walk.md).
- To see which calls rille follows: the [resolve design](design/resolve.md).
- To see how rille was checked against hand-drawn graphs: the
  [verification](verification.md).
- To run the tool and cite what produced a graph: the
  [command line](tutorial/cmd/rille.md).

## Validation

```bash
moon check --target all
moon test
```

`just ready` runs these together with formatting, `moon info` and coverage.
