<!-- SPDX-License-Identifier: CC-BY-4.0 -->
<!-- seo-title: The HoldFast Effect System -->
<!-- description: Learn how HoldFast checks read, write, and call bounds across functions and packages, with examples of inference, named effect sets, and confinement. -->

# Effect system in HoldFast

An effect bound tells callers which places a function may read or write and
which named operations it may invoke. HoldFast checks that the function body
and the effects it inherits through calls fit that bound.

[Try the native checker](#try-the-native-checker) ·
[Open the Playground](../#playground)

## Read, write, and call bounds

Write a closed effect bound after a signature with `~>`. A closed bound
enumerates the effects allowed at that interface. It is an upper bound, so a
function can do less on a particular path.

| Entry | Allows |
| --- | --- |
| `reads(input)` | Reading the caller-visible place bound to `input`. |
| `writes(destination)` | Writing or reading the place bound to `destination`. An explicit `!reads(destination)` can forbid the read. |
| `calls(step)` | Invoking the resolved callable or callable parameter `step`. Memory effects still need coverage. |
| `none` | No caller-visible reads, writes or call effects. Pure helper calls can meet this bound. |

The checker combines the effects of operations and calls. It maps each
callee's receiver and parameters to the actual places at the call site.
Passing a loan to a helper contributes a read only if the helper's footprint
includes that read. Assigning a fresh value writes the place. A compound
assignment also reads it, and restoring the original value still counts as a
write. [Language reference](../language/reference/#contracts)

For named calls, an explicit `calls(Step)` entry can cover a direct call to
`Step`. Otherwise the checker uses the callee's published or inferred call
footprint. It checks mapped reads, writes, and callback effects separately.
[Package effect contracts](../language/first-release/#package-effect-contracts)

The parameter mode supplies access to the place. The effect bound limits how
the function can use that access. For example, a write bound still needs a
writable view such as `ref` or `out`. An `ensures` clause can establish the
value left behind. Source operation counts and compiled costs require their
own evidence. [Borrow checking](../borrow-checking/) ·
[Authority rules](../language/core-design/#kinded-authority) ·
[Compiled artifact evidence](../formal-verification/#compiled-artifacts)

## Follow effects through helpers

`CopyValue` reads `input` through `Inspect` and writes `destination` through
`Store`. The checker infers the private helper footprints and applies them
at the call sites. The public signature exposes the resulting bound to callers.

```hf
module EffectCopy;

private u32 Inspect(ref u32 value) => value;

private Unit Store(ref u32 target, u32 value)
{
    target = value;
    return;
}

public bool CopyValue(ref u32 input, ref u32 destination)
    ~> reads(input), writes(destination)
{
    let value = Inspect(ref input);
    Store(ref destination, value);
    return true;
}
```

In a release package, every exported runtime function publishes a bound.
A record can supply a shared default for its runtime methods, such as
`~> reads(this)`. A method's own clause takes precedence. Eligible private
helpers and methods, and `internal` helpers in the same locked package, can
use inferred footprints.

Calling a callback parameter `visit` contributes `calls(visit)`. A helper
that forwards it to another helper that invokes it carries the same effect.
At the outer call, a checked pure callback contributes an empty footprint.
An effectful callback carries its checked effects through the call. A helper
that only receives the callback without invoking or forwarding it to an
invoker adds no invocation effect.
[Inference, callbacks, and record defaults](../language/first-release/#package-effect-contracts)

## Name and confine effects

Name a set with `effect Name = ...;` and combine sets with `|`.
Inside a function, `effect (...) { ... }` limits the enclosed code.
Use `!` to forbid a read, write, call, or named set.

Here `RawCalls` names calls to `RawStep`, and `canceled by` exempts paths
through `ReviewedStep` from that prohibition. Both functions return their
input so the example can illustrate call identity with no external service.

```hf
module EffectConfinement;

public Nat RawStep(Nat code) ~> none => code;
public Nat ReviewedStep(Nat code) ~> calls(RawStep) => RawStep(code);

effect RawCalls = calls(RawStep) canceled by calls(ReviewedStep);

public Nat UseReviewedStep(Nat code) ~> calls(ReviewedStep)
{
    effect (!RawCalls)
    {
        return ReviewedStep(code);
    }
}
```

The checker follows prohibited calls through helpers, even when the named
operation has an empty footprint. The exemption applies to each call path
through the named wrapper. A direct call to `RawStep` or a path through a
different helper remains forbidden inside the block. Memory effects still
propagate through the wrapper.
Locked packages can apply the same restrictions to public callables through
manifest policy, including `forbid_calls`, `forbid_effects`, and
`require_explicit_effects`.
[Named sets, confinement, and package policy](../language/first-release/#package-effect-contracts)

## Try the native checker

Start the local Playground and open the URL it prints. The **Local compiler**
label confirms you are using the native checker. Paste the complete
`EffectCopy` module above and select **Compile**. Remove `reads(input),` from
`CopyValue`'s bound and compile again. The checker reports the uncovered read
of `input` through `Inspect`. [Local Playground setup](../tooling/playground/#scope-and-launch)

Load the complete `EffectConfinement` module and compile it. In
`UseReviewedStep`, change the bound to `~> calls(ReviewedStep, RawStep)` and
replace `ReviewedStep(code)` inside the block with `RawStep(code)`. The
`!RawCalls` prohibition still rejects that direct call.

To try the same check from the repository root, save the first module as
`effect-copy.hf` and run the first command. The second command runs the
release qualification cases, including the copy service and a caller in a
separate locked package. Use `python3` on Linux or in WSL.

```shell
python tools/run.py holdfast-parser elaborate effect-copy.hf
python tools/run.py holdfast-parser check-release-effects
```

Across a locked package boundary, clients check against the published bound.
Widening it can force clients to widen their own bounds. For a particular
locked closure, `check-release-effects WORKSPACE LOCK` binds the checked
footprints to the source, lock, and emitted Gallina and replays the Gallina in
Rocq. [Release effect checks](../language/first-release/#package-effect-contracts) ·
[Copy service example](https://github.com/symbiogenesis/HoldFast/blob/main/examples/copy_service.hf)

## Release boundary

The first-release effect system covers closed synchronous bounds. Its core
excludes allocation. Lexical effect handlers, structured async, and
effect-row polymorphism have their own extension designs.
[Synchronous core](../language/core-design/#refinement-effects-and-staging) ·
[Handlers and async](../extensions/handlers-async/) ·
[Effect-row polymorphism](../extensions/modal-staged-polymorphism/#two-level-compile-time-mode-and-effect-row-polymorphism)
