# `Dmn.Compiler.Unit`
[🔗](https://github.com/FeeJai/BDM/blob/dmn-v0.1.0/apps/dmn/lib/dmn/compiler/unit.ex#L1)

The unit of a DRG element: what is prepared of it, and what it reads.

| Field | Is |
| ----- | -- |
| `key` | `{kind, id}`, or the name if the element has no `id` |
| `kind` | `:decision`, `:input`, `:knowledge` (a business knowledge model) or `:service` (a decision service) |
| `name` | the name of the element, as the model has it |
| `id` | the `id` of the element, or its name, and, for an element of an imported model, the namespace of the model and U+0001 before it, which no `id` or name in a document can have, so that no element can take the key of another |
| `namespace` | the namespace of the model the element is in |
| `expression` | the prepared `Feel.Expression`, or `nil` for an element that has none (an input) or whose logic could not be prepared |
| `source` | the virtual source of the expression and its parts (`Dmn.Compiler.Source`) |
| `reads` | `{canonical name, key}` of the units whose values the expression reads, bound under that name when it runs. Those that are in the unit's `group` are bound to links instead (`Feel.Recursion`) |
| `group` | the key of the **recursion group** the unit is in (the first of the keys that `Dmn.Compiled.groups` has for it), or `nil`: knowledge units that read each other, or themselves, when `Dmn.compile/2` was told `recursion: true` |
| `diagnostics` | what was found when it was prepared, `Dmn.Diagnostic`s |
| `faults` | the errors among them that make the value wrong, whatever the data: a text that could not be read and is `null` in the expression. Every run of the unit reports them |
| `strict_faults` | confirmed unresolved-name diagnostics, including those inherited by a service from its decisions. Only strict runs reject these; lenient runs keep FEEL's warning behavior |
| `callback_free` | `true` if what a worker is given of `expression` (its executable, linked peers and extensions, not its syntax tree, IR or scope) holds no function value, host callback or generated code that could bring a text of another element into a run, `false` if it may, `nil` if that was not looked at. Set once by the compiler (DD-44) so that a run in a worker need not walk the expression again; whoever changes `expression` sets it to `nil` |

An input has no expression: its value is the one the caller gives, and is converted and verified in the units that read it.

# `kind`

```elixir
@type kind() :: :decision | :input | :knowledge | :service
```

# `t`

```elixir
@type t() :: %Dmn.Compiler.Unit{
  callback_free: boolean() | nil,
  diagnostics: [Dmn.Diagnostic.t()],
  expression: Feel.Expression.t() | nil,
  faults: [Dmn.Diagnostic.t()],
  group: {kind(), String.t()} | nil,
  id: String.t(),
  key: {kind(), String.t()},
  kind: kind(),
  name: String.t(),
  namespace: String.t() | nil,
  reads: [{String.t(), {kind(), String.t()}}],
  source: Dmn.Compiler.Source.finished() | nil,
  strict_faults: [Dmn.Diagnostic.t()]
}
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
