;;;; Three edges of Reach's walk, each the only route to one function. ;;;; ;;;; A release build is pruned: a function nothing reachable from main or from ;;;; a global initialiser calls is not emitted at all. So an edge the walk ;;;; forgets does not produce a wrong answer — it produces a program that does ;;;; not link, with a message about a symbol nobody wrote. Each of the three ;;;; functions below is called from exactly one place, and that place is an ;;;; edge no other program in the corpus exercises: ;;;; ;;;; index-expr the index expression of a place, (set (at a (f)) v) ;;;; through a place under (addr ...), here a (deref ...) so that it is ;;;; the addr edge and not the index one again ;;;; placeholder a restart-case clause body, which is reached by a transfer ;;;; and never by a call the walk can see from the body ;;;; ;;;; Nothing here is about the values; the values are how the test notices that ;;;; the program was built and ran at all. (defvar cells [4 i32]) (defvar slot i32) (defstruct Nope [id i32]) (defn index-expr [] i32 2) (defn through [] (Ptr i32) (addr slot)) (defn placeholder [] i32 42) ;;; Signals with nothing to return, so the clause body is the only way past. (defn missing [] i32 (error (Nope {.id 1}))) (defn pick [] i32 (restart-case (missing) (use-placeholder [] (placeholder)))) (defn main [] i32 ;; The index of a place is an expression, and it can call. (set (at cells (index-expr)) 10) (print (at cells 2)) (println "") ;; (addr (deref p)) is p, so this is the addr edge over a place whose own ;; walk is Pderef rather than Pindex — the index case above cannot stand in ;; for it. (let [q (addr (deref (through)))] (set (deref q) 20)) (print slot) (println "") ;; The clause body, reached only because the handler transfers into it. (handler-bind [(Nope [c] (invoke-restart 'use-placeholder))] (print (pick)) (println "")) 0)