Effect lattice and feature flags for static effect inference.
:pure < :local < :mutation < :io
The join (least upper bound) of two effects is their maximum. Effect inference propagates the join through the call graph.
Feature flags capture properties that are independent of the state effect ordering:
Flags propagate via set union through the call graph. Compilation targets can declare which flags they tolerate.
Effect lattice and feature flags for static effect inference.
## State effect lattice (total order)
:pure < :local < :mutation < :io
- :pure — no side effects, safe for AD, CSE, GPU, parallelization
- :local — thread-local mutation (transients, volatiles, loop scratch)
safe for parallelization/GPU, not for AD/CSE
- :mutation — global mutable state (atoms, refs, vars)
only safe for sequential execution
- :io — external I/O (println, file ops, network, system calls)
only safe for sequential, cannot reorder
The join (least upper bound) of two effects is their maximum.
Effect inference propagates the join through the call graph.
## Feature flags (orthogonal to state effects)
Feature flags capture properties that are independent of the state
effect ordering:
- :throws — may throw exceptions (partial function)
- :random — uses randomness (nondeterministic)
- :reflects — uses reflection (cannot AOT / cannot optimize)
- :allocates — heap allocates (relevant for real-time / GPU scratch)
Flags propagate via set union through the call graph.
Compilation targets can declare which flags they tolerate.(<=effect a b)True if effect a is at most as effectful as b.
True if effect a is at most as effectful as b.
(budget-for target)Return the maximum allowed effect level for a compilation target.
Return the maximum allowed effect level for a compilation target.
(compilable? target desc)(compilable? target desc custom-unsupported)True if an effect descriptor is compatible with a compilation target. Checks both the state effect budget and feature flag support.
True if an effect descriptor is compatible with a compilation target. Checks both the state effect budget and feature flag support.
(effect level)(effect level flags)Create an effect descriptor: {:effect level, :flags #{...}}. Shorthand: (effect :pure) or (effect :local #{:throws}).
Create an effect descriptor: {:effect level, :flags #{...}}.
Shorthand: (effect :pure) or (effect :local #{:throws}).(effect-join a b)Join two effect descriptors (component-wise max / union).
Join two effect descriptors (component-wise max / union).
(effect-join-all descs)(effect-join-all init descs)Join a collection of effect descriptors.
Join a collection of effect descriptors.
(join a b)Least upper bound of two effects (their maximum).
Least upper bound of two effects (their maximum).
(join-all effs)(join-all init effs)Least upper bound of a collection of effects.
Least upper bound of a collection of effects.
(level-index eff)Return the ordinal index of an effect level.
Return the ordinal index of an effect level.
The pure effect descriptor (no effects, no flags).
The pure effect descriptor (no effects, no flags).
(unsupported-flags-for target)(unsupported-flags-for target custom-map)Return the set of feature flags unsupported by a compilation target. Can be overridden by providing a custom map.
Return the set of feature flags unsupported by a compilation target. Can be overridden by providing a custom map.
(valid-flag? flag)True if flag is a recognized feature flag.
True if flag is a recognized feature flag.
(within-budget? budget eff)True if the given effect level is within the budget. A budget is an effect level; anything at or below it is acceptable.
Common budgets: :pure — only pure code (AD, CSE) :local — allow thread-local mutation (GPU, parallel) :mutation — allow global mutation (sequential, inlining) :io — allow everything
True if the given effect level is within the budget. A budget is an effect level; anything at or below it is acceptable. Common budgets: :pure — only pure code (AD, CSE) :local — allow thread-local mutation (GPU, parallel) :mutation — allow global mutation (sequential, inlining) :io — allow everything
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |