This module implements the module graph data structure. The module graph represents a complete Nim project. Single modules can either be kept in RAM or stored in a rod-file.
Types
FullId = object module*: int packed*: PackedItemId
- Source Edit
Iface = object module*: PSym ## module this "Iface" belongs to converters*: seq[LazySym] patterns*: seq[LazySym] pureEnums*: seq[LazySym] uniqueName*: Rope
- data we don't want to store directly in the ast.PSym type for s.kind == skModule Source Edit
LazyInstantiation = object module*: int sym*: FullId concreteTypes*: seq[FullId] inst*: PInstantiation
- Source Edit
ModuleGraph {.acyclic.} = ref object ifaces*: seq[Iface] ## indexed by int32 fileIdx packed*: PackedModuleGraph encoders*: seq[PackedEncoder] typeInstCache*: Table[ItemId, seq[LazyType]] procInstCache*: Table[ItemId, seq[LazyInstantiation]] attachedOps*: array[TTypeAttachedOp, Table[ItemId, LazySym]] opsLog*: seq[LogEntry] methodsPerGenericType*: Table[ItemId, seq[(int, LazySym)]] memberProcsPerType*: Table[ItemId, seq[PSym]] initializersPerType*: Table[ItemId, PNode] enumToStringProcs*: Table[ItemId, LazySym] emittedTypeInfo*: Table[string, FileIndex] startupPackedConfig*: PackedConfig packageSyms*: TStrTable deps*: IntSet importDeps*: Table[FileIndex, seq[FileIndex]] suggestMode*: bool interactive*: bool withinSystem*: bool inclToMod*: Table[FileIndex, FileIndex] importStack*: seq[FileIndex] backend*: RootRef config*: ConfigRef cache*: IdentCache vm*: RootRef repl*: RootRef doStopCompile*: proc (): bool {.closure.} usageSym*: PSym owners*: seq[PSym] suggestSymbols*: SuggestSymbolDatabase suggestErrors*: Table[FileIndex, seq[Suggest]] methods*: seq[tuple[methods: seq[PSym], dispatcher: PSym]] bucketTable*: CountTable[ItemId] objectTree*: Table[ItemId, seq[tuple[depth: int, value: PType]]] methodsPerType*: Table[ItemId, seq[LazySym]] dispatchers*: seq[LazySym] systemModule*: PSym sysTypes*: array[TTypeKind, PType] compilerprocs*: TStrTable exposed*: TStrTable packageTypes*: TStrTable emptyNode*: PNode canonTypes*: Table[SigHash, PType] symBodyHashes*: Table[int, SigHash] importModuleCallback*: proc (graph: ModuleGraph; m: PSym; fileIdx: FileIndex): PSym {. nimcall.} includeFileCallback*: proc (graph: ModuleGraph; m: PSym; fileIdx: FileIndex): PNode {. nimcall.} cacheSeqs*: Table[string, PNode] cacheCounters*: Table[string, BiggestInt] cacheTables*: Table[string, BTree[string, PNode]] passes*: seq[TPass] pipelinePass*: PipelinePass onDefinition*: proc (graph: ModuleGraph; s: PSym; info: TLineInfo) {.nimcall.} onDefinitionResolveForward*: proc (graph: ModuleGraph; s: PSym; info: TLineInfo) {.nimcall.} onUsage*: proc (graph: ModuleGraph; s: PSym; info: TLineInfo) {.nimcall.} globalDestructors*: seq[PNode] strongSemCheck*: proc (graph: ModuleGraph; owner: PSym; body: PNode) {.nimcall.} compatibleProps*: proc (graph: ModuleGraph; formal, actual: PType): bool {. nimcall.} idgen*: IdGenerator operators*: Operators cachedFiles*: StringTableRef procGlobals*: seq[PNode] nifReplayActions*: Table[int32, seq[PNode]]
- Source Edit
ModuleIter = object
- Source Edit
Operators = object opNot*, opContains*, opLe*, opLt*, opAnd*, opOr*, opIsNil*, opEq*: PSym opAdd*, opSub*, opMul*, opDiv*, opLen*: PSym
- Source Edit
PipelinePass = enum NonePass, SemPass, JSgenPass, CgenPass, NifgenPass, EvalPass, InterpreterPass, GenDependPass, Docgen2TexPass, Docgen2JsonPass, Docgen2Pass
- Source Edit
PPassContext = ref TPassContext
- Source Edit
TPass = tuple[open: TPassOpen, process: TPassProcess, close: TPassClose, isFrontend: bool]
- Source Edit
TPassClose = proc (graph: ModuleGraph; p: PPassContext; n: PNode): PNode {. nimcall.}
- Source Edit
TPassContext = object of RootObj idgen*: IdGenerator
- Source Edit
TPassOpen = proc (graph: ModuleGraph; module: PSym; idgen: IdGenerator): PPassContext {. nimcall.}
- Source Edit
TPassProcess = proc (p: PPassContext; topLevelStmt: PNode): PNode {.nimcall.}
- Source Edit
Procs
proc addDispatchers(g: ModuleGraph; value: PSym) {....raises: [], tags: [], forbids: [].}
- Source Edit
proc addIncludeDep(g: ModuleGraph; module, includeFile: FileIndex) {....raises: [], tags: [], forbids: [].}
- Source Edit
proc addMethodToGeneric(g: ModuleGraph; module: int; t: PType; col: int; m: PSym) {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc addNifReplayAction(g: ModuleGraph; module: int32; n: PNode) {....raises: [], tags: [], forbids: [].}
- Stores a replay action for NIF-based incremental compilation. Source Edit
proc belongsToStdlib(graph: ModuleGraph; sym: PSym): bool {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Check if symbol belongs to the 'stdlib' package. Source Edit
proc closeRodFile(g: ModuleGraph; m: PSym) {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect, WriteDirEffect], forbids: [].}
- Source Edit
proc completePartialOp(g: ModuleGraph; module: int; t: PType; op: TTypeAttachedOp; value: PSym) {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc configComplete(g: ModuleGraph) {....raises: [], tags: [], forbids: [].}
- Source Edit
proc copyTypeProps(g: ModuleGraph; module: int; dest, src: PType) {. ...raises: [KeyError, Exception, OSError, ValueError, IOError], tags: [ ReadDirEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect], forbids: [].}
- Source Edit
proc createMagic(g: ModuleGraph; idgen: IdGenerator; name: string; m: TMagic): PSym {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc fileSymbols(graph: ModuleGraph; fileIdx: FileIndex): SuggestFileSymbolDatabase {. ...raises: [], tags: [], forbids: [].}
- Source Edit
proc getAttachedOp(g: ModuleGraph; t: PType; op: TTypeAttachedOp): PSym {. ...raises: [KeyError, Exception, OSError, ValueError, IOError], tags: [ ReadDirEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect], forbids: [].}
- returns the requested attached operation for type t. Can return nil if no such operation exists. Source Edit
proc getPackage(graph: ModuleGraph; fileIdx: FileIndex): PSym {. ...raises: [KeyError], tags: [ReadDirEffect], forbids: [].}
- Returns a package symbol for yet to be defined module for fileIdx. The package symbol is added to the graph if it doesn't exist. Source Edit
proc getToStringProc(g: ModuleGraph; t: PType): PSym {. ...raises: [KeyError, Exception, OSError, ValueError, IOError], tags: [ ReadDirEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect], forbids: [].}
- Source Edit
proc hasDisabledAsgn(g: ModuleGraph; t: PType): bool {. ...raises: [KeyError, Exception, OSError, ValueError, IOError], tags: [ ReadDirEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect], forbids: [].}
- Source Edit
proc initEncoder(g: ModuleGraph; module: PSym) {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc initModuleIter(mi: var ModuleIter; g: ModuleGraph; m: PSym; name: PIdent): PSym {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc initOperators(g: ModuleGraph): Operators {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc initStrTables(g: ModuleGraph; m: PSym) {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc isCachedModule(g: ModuleGraph; m: PSym): bool {.inline, ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc isDirty(g: ModuleGraph; m: PSym): bool {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc loadCompilerProc(g: ModuleGraph; name: string): PSym {. ...raises: [Exception, OSError, ValueError, KeyError, IOError], tags: [ RootEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect, WriteIOEffect], forbids: [].}
- Source Edit
proc loadPackedSym(g: ModuleGraph; s: var LazySym) {. ...raises: [KeyError, Exception, OSError, ValueError, IOError], tags: [ ReadDirEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect], forbids: [].}
- Source Edit
proc logGenericInstance(g: ModuleGraph; inst: PSym) {....raises: [], tags: [], forbids: [].}
- Log a generic instance so it gets written to the NIF file. This is needed when generic instances are created during compile-time evaluation and may be referenced from other modules compiled in the same run. Source Edit
proc markClientsDirty(g: ModuleGraph; fileIdx: FileIndex) {....raises: [], tags: [], forbids: [].}
- Source Edit
proc markDirty(g: ModuleGraph; fileIdx: FileIndex) {....raises: [], tags: [], forbids: [].}
- Source Edit
proc moduleFromNifFile(g: ModuleGraph; fileIdx: FileIndex; cachedModules: var seq[FileIndex]; loadFullAst: bool = false): PSym {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ ReadDirEffect, RootEffect, ReadEnvEffect, ReadIOEffect, WriteIOEffect], forbids: [].}
- Returns 'nil' if the module needs to be recompiled. Loads module from NIF file when optCompress is enabled. When loadFullAst is true, loads the complete module AST for code generation. Source Edit
proc moduleFromRodFile(g: ModuleGraph; fileIdx: FileIndex; cachedModules: var seq[FileIndex]): PSym {....raises: [ OSError, IOError, Exception, KeyError, ValueError, ERecoverableError], tags: [ ReadEnvEffect, ReadIOEffect, WriteDirEffect, ReadDirEffect, RootEffect, WriteIOEffect], forbids: [].}
- Returns 'nil' if the module needs to be recompiled. Source Edit
proc moduleOpenForCodegen(g: ModuleGraph; m: FileIndex): bool {.inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc needsCompilation(g: ModuleGraph): bool {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc needsCompilation(g: ModuleGraph; fileIdx: FileIndex): bool {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc newModuleGraph(cache: IdentCache; config: ConfigRef): ModuleGraph {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc nextModuleIter(mi: var ModuleIter; g: ModuleGraph): PSym {. ...raises: [KeyError, Exception, OSError, ValueError, IOError], tags: [ ReadDirEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect], forbids: [].}
- Source Edit
proc onProcessing(graph: ModuleGraph; fileIdx: FileIndex; moduleStatus: string; fromModule: PSym) {....raises: [Exception, KeyError, ValueError, IOError, ERecoverableError], tags: [RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect], forbids: [].}
- Source Edit
proc parentModule(g: ModuleGraph; fileIdx: FileIndex): FileIndex {....raises: [], tags: [], forbids: [].}
- returns 'fileIdx' if the file belonging to this index is directly used as a module or else the module that first references this include file. Source Edit
proc registerModule(g: ModuleGraph; m: PSym) {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc registerModuleById(g: ModuleGraph; m: FileIndex) {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc rememberEmittedTypeInfo(g: ModuleGraph; m: FileIndex; ti: string) {. ...raises: [], tags: [], forbids: [].}
- Source Edit
proc rememberFlag(g: ModuleGraph; m: PSym; flag: ModuleBackendFlag) {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc resetAllModules(g: ModuleGraph) {....raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc resetForBackend(g: ModuleGraph) {....raises: [], tags: [], forbids: [].}
- Source Edit
proc resolveAttachedOp(g: ModuleGraph; t: var LazySym): PSym {. ...raises: [KeyError, Exception, OSError, ValueError, IOError], tags: [ ReadDirEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect], forbids: [].}
- Source Edit
proc setAttachedOp(g: ModuleGraph; module: int; t: PType; op: TTypeAttachedOp; value: PSym) {....raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- we also need to record this to the packed module. Source Edit
proc setAttachedOp(g: ModuleGraph; module: int; typeId: ItemId; op: TTypeAttachedOp; value: PSym) {....raises: [], tags: [], forbids: [].}
- Overload that takes ItemId directly, useful for registering hooks from NIF index. Source Edit
proc setAttachedOpPartial(g: ModuleGraph; module: int; t: PType; op: TTypeAttachedOp; value: PSym) {....raises: [], tags: [], forbids: [].}
- we also need to record this to the packed module. Source Edit
proc setMethodsPerType(g: ModuleGraph; id: ItemId; methods: seq[LazySym]) {. ...raises: [], tags: [], forbids: [].}
- Source Edit
proc setToStringProc(g: ModuleGraph; t: PType; value: PSym) {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc someSymAmb(g: ModuleGraph; m: PSym; name: PIdent; amb: var bool): PSym {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc stopCompile(g: ModuleGraph): bool {.inline, ...raises: [Exception], tags: [RootEffect], forbids: [].}
- Source Edit
proc strTableAdds(g: ModuleGraph; m: PSym; s: PSym) {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc systemModuleSym(g: ModuleGraph; name: PIdent): PSym {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc uniqueModuleName(conf: ConfigRef; m: PSym): string {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- The unique module name is guaranteed to only contain {'A'..'Z', 'a'..'z', '0'..'9', '_'} so that it is useful as a C identifier snippet. Source Edit
proc unmarkAllDirty(g: ModuleGraph) {....raises: [], tags: [], forbids: [].}
- Source Edit
Iterators
iterator getDispatchers(g: ModuleGraph): PSym {. ...raises: [KeyError, Exception, OSError, ValueError, IOError], tags: [ ReadDirEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect], forbids: [].}
- Source Edit
iterator getMethodsPerType(g: ModuleGraph; t: PType): PSym {. ...raises: [KeyError, Exception, OSError, ValueError, IOError], tags: [ ReadDirEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect], forbids: [].}
- Source Edit
iterator methodsForGeneric(g: ModuleGraph; t: PType): (int, PSym) {. ...raises: [KeyError, Exception, OSError, ValueError, IOError], tags: [ ReadDirEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect], forbids: [].}
- Source Edit
iterator procInstCacheItems(g: ModuleGraph; s: PSym): PInstantiation {. ...raises: [KeyError, Exception, OSError, ValueError, IOError], tags: [ ReadDirEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect], forbids: [].}
- Source Edit
iterator suggestErrorsIter(g: ModuleGraph): Suggest {....raises: [], tags: [], forbids: [].}
- Source Edit
iterator suggestSymbolsIter(g: ModuleGraph): SymInfoPair {....raises: [], tags: [], forbids: [].}
- Source Edit
iterator systemModuleSyms(g: ModuleGraph; name: PIdent): PSym {. ...raises: [Exception, OSError, KeyError, ValueError, IOError], tags: [ RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
iterator typeInstCacheItems(g: ModuleGraph; s: PSym): PType {. ...raises: [KeyError, Exception, OSError, ValueError, IOError], tags: [ ReadDirEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadIOEffect], forbids: [].}
- Source Edit