Module that contains code to replay global VM state changes and pragma state like {.compile: "foo.c".}. For IC (= Incremental compilation) support.
Consts
BackendActionsExt = ".cflags"
- Sidecar written by a module's cg stage next to its .c, carrying the C compile/link directives that module's {.passL.}/{.compile.}/… pragmas recorded. See writeBackendActions. Source Edit
Procs
proc applyBackendActions(g: ModuleGraph; infile: string) {....raises: [IOError, OSError, ValueError, Exception, KeyError, ERecoverableError, EOFError], tags: [ ReadDirEffect, ReadIOEffect, ReadEnvEffect, RootEffect, WriteIOEffect, WriteDirEffect], forbids: [].}
- Apply one module's recorded C directives (see writeBackendActions). The link stage's replacement for loading that module and replaying its AST. Source Edit
proc replayBackendActions(g: ModuleGraph; module: PSym; list: PNode) {....raises: [ OSError, ValueError, IOError, Exception, KeyError, ERecoverableError, EOFError], tags: [ReadEnvEffect, ReadIOEffect, RootEffect, ReadDirEffect, WriteIOEffect, WriteDirEffect], forbids: [].}
- Applies the backend-relevant replay actions (C compile/link directives) found in a NIF-loaded module's top-level statement list. The nifc backend loads modules without going through sem's replayStateChanges, so e.g. math's {.passL: "-lm".} was lost and the final link failed with undefined references. VM cache actions are deliberately NOT replayed here — codegen does not run macros. Source Edit
proc replayStateChanges(module: PSym; g: ModuleGraph; list: PNode) {....raises: [ Exception, ValueError, OSError, KeyError, IOError, ERecoverableError, EOFError], tags: [RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect, WriteDirEffect], forbids: [].}
- list is an nkStmtList of nkReplayAction nodes (macro-cache puts/incs/ adds/incls and a few pragmas) recorded for module. Under the NIF backend a loaded module's ast is never reconstructed, so the caller passes the replay actions it parsed out of the module's NIF directly. Source Edit
proc writeBackendActions(g: ModuleGraph; module: PSym; list: PNode; outfile: string) {. ...raises: [KeyError, OSError, Exception, ValueError, IOError], tags: [ ReadEnvEffect, ReadIOEffect, ReadDirEffect, RootEffect, WriteIOEffect], forbids: [].}
-
Serialize the backend-relevant replay actions of ONE module to outfile, one tab-separated action per line.
The link stage used to recover these by loading the whole import closure as PrecompiledModules and re-running replayBackendActions over each — a 3.7s whole-program graph load, per link, purely to recover a handful of strings and the modules' .c paths. The producing cg process already has them in hand, so it writes them down instead and link reads them back (applyBackendActions). Written unconditionally, even when empty: it is a declared nifmake output of the cg rule, and a missing output re-fires the rule for ever.
localpassc needs the module's own source path, which only the writer can resolve, so it is baked in here as a third field.
Source Edit