likely is a branch-probability hint indicating that a Boolean expression is expected to evaluate to True.
Syntax
(likely ⟨boolean-expr⟩)
Semantics
likelyis a function of type(Boolean -> Boolean)that returns the value of⟨boolean-expr⟩unchanged.- It annotates conditional tests (such as in
if,cond,when, orunless) to indicate that theTruebranch is the common fast path. - It does not alter program semantics or evaluation order.
Examples
(coalton-toplevel
(declare get-or-compute ((Optional Integer) * (Void -> Integer) -> Integer))
(define (get-or-compute cached compute)
(if (likely (some? cached))
(unwrap cached)
(compute))))
Other notes
likelyis defined as an identity function onBooleanincoalton(src/intrinsic-applications.lisp); the compiler does not currently emit host branch-prediction hints for it.- Use
unlikelyfor the complementary hint when a condition is expected to beFalse.