Learn R Programming

SpaDES.core (version 3.2.1)

.fnsReachableFrom: Transitive closure of module-local functions reachable from a starting function

Description

Walks the call graph of startName within a single module's namespace environment, following references to other functions defined in that same environment (helpers in the main module file or in R/ sub-files), to any depth. Used to scope the .inputObjects cache digest: the cacheId must change when any function that .inputObjects actually calls is edited, but not when unrelated module functions (e.g., doEvent, Init) change. Digesting only .inputObjects lets a helper fix be silently masked by a stale cache entry (most visibly on restartSimInit(), whose rewind reproduces the exact state the stale entry was keyed under); digesting the whole module env over-invalidates.

Usage

.fnsReachableFrom(startName, env)

Value

Character vector of function names (always including any of startName

that exist in env); cycle-safe.

Arguments

startName

Character. Name(s) of the function(s) to start the walk from.

env

The module's namespace environment (sim@.xData$.mods[[module]]).

Details

Only module-local functions are followed; package functions are out of scope (handled via reqdPkgs, which is already part of the digested metadata, not by walking package bodies). String-based dynamic dispatch (do.call("helperA", ), get("helperA")()) is invisible to codetools::findGlobals(), so as a supplement any string literal in a reached function that matches a module function name is also followed. This is precise (a benign do.call(rbind, ) with a function symbol is already caught by findGlobals, and triggers no extra invalidation) rather than a blanket whole-module fallback.