# compiler/modulegraphs

Dark Mode

- Index

Search:
Group by:
Source Edit

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.

# Imports

ast, astalgo, options, lineinfos, idents, btrees, ropes, msgs, pathutils, packages, ic/packed_ast, ic/ic

# 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]
      interf: TStrTable
      interfHidden: TStrTable
      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

    LazySym = object
      id*: FullId
      sym*: PSym

  Source Edit

    LazyType = object
      id*: FullId
      typ*: PType

  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, PSym]]
      methodsPerType*: Table[ItemId, seq[(int, LazySym)]]
      enumToStringProcs*: Table[ItemId, LazySym]
      emittedTypeInfo*: Table[string, FileIndex]
      startupPackedConfig*: PackedConfig
      packageSyms*: TStrTable
      deps*: IntSet
      importDeps*: Table[FileIndex, seq[FileIndex]]
      suggestMode*: bool
      invalidTransitiveClosure: bool
      inclToMod*: Table[FileIndex, FileIndex]
      importStack*: seq[FileIndex]
      backend*: RootRef
      config*: ConfigRef
      cache*: IdentCache
      vm*: RootRef
      doStopCompile*: proc (): bool {.closure.}
      usageSym*: PSym
      owners*: seq[PSym]
      suggestSymbols*: Table[FileIndex, seq[SymInfoPair]]
      suggestErrors*: Table[FileIndex, seq[Suggest]]
      methods*: seq[tuple[methods: seq[PSym], dispatcher: PSym]]
      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]
      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

  Source Edit

    ModuleIter = object
      fromRod: bool
      modIndex: int
      ti: TIdentIter
      rodIt: RodIter
      importHidden: bool

  Source Edit

    Operators = object
      opNot*, opContains*, opLe*, opLt*, opAnd*, opOr*, opIsNil*, opEq*: PSym
      opAdd*, opSub*, opMul*, opDiv*, opLen*: PSym

  Source Edit

    PPassContext = ref TPassContext

  Source Edit

    SigHash = distinct MD5Digest

  Source Edit

    SymInfoPair = object
      sym*: PSym
      info*: TLineInfo

  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 `$`(u: SigHash): string {....raises: [], tags: [].}

  Source Edit

    proc `==`(a, b: SigHash): bool {....raises: [], tags: [].}

  Source Edit

    proc `==`(a, b: SymInfoPair): bool {....raises: [], tags: [].}

  Source Edit

    proc addDep(g: ModuleGraph; m: PSym; dep: FileIndex) {....raises: [], tags: [].}

  Source Edit

    proc addIncludeDep(g: ModuleGraph; module, includeFile: FileIndex) {....raises: [],
        tags: [].}

  Source Edit

    proc addMethodToGeneric(g: ModuleGraph; module: int; t: PType; col: int; m: PSym) {.
        ...raises: [], tags: [].}

  Source Edit

    func belongsToStdlib(graph: ModuleGraph; sym: PSym): bool {....raises: [], tags: [].}

  Check if symbol belongs to the 'stdlib' package. Source Edit

    proc closeRodFile(g: ModuleGraph; m: PSym) {.
        ...raises: [Exception, IOError, OSError, KeyError], tags: [RootEffect,
        WriteIOEffect, WriteDirEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect].}

  Source Edit

    proc completePartialOp(g: ModuleGraph; module: int; t: PType;
                           op: TTypeAttachedOp; value: PSym) {....raises: [], tags: [].}

  Source Edit

    proc configComplete(g: ModuleGraph) {....raises: [], tags: [].}

  Source Edit

    proc copyTypeProps(g: ModuleGraph; module: int; dest, src: PType) {....raises: [],
        tags: [].}

  Source Edit

    proc createMagic(g: ModuleGraph; idgen: IdGenerator; name: string; m: TMagic): PSym {.
        ...raises: [], tags: [].}

  Source Edit

    proc fileSymbols(graph: ModuleGraph; fileIdx: FileIndex): seq[SymInfoPair] {.
        ...raises: [], tags: [].}

  Source Edit

    proc getAttachedOp(g: ModuleGraph; t: PType; op: TTypeAttachedOp): PSym {.
        ...raises: [], tags: [].}

  returns the requested attached operation for type `t`. Can return nil if no such operation exists. Source Edit

    proc getBody(g: ModuleGraph; s: PSym): PNode {.inline,
        ...raises: [KeyError, Exception], tags: [ReadDirEffect, RootEffect].}

  Source Edit

    proc getModule(g: ModuleGraph; fileIdx: FileIndex): PSym {....raises: [], tags: [].}

  Source Edit

    proc getPackage(graph: ModuleGraph; fileIdx: FileIndex): PSym {.
        ...raises: [KeyError, OSError], tags: [ReadDirEffect].}

  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], tags: [ReadDirEffect, RootEffect].}

  Source Edit

    proc hasDisabledAsgn(g: ModuleGraph; t: PType): bool {....raises: [], tags: [].}

  Source Edit

    proc hash(u: SigHash): Hash {....raises: [], tags: [].}

  Source Edit

    proc hash(x: FileIndex): Hash {.borrow, ...raises: [], tags: [].}

  Source Edit

    proc initEncoder(g: ModuleGraph; module: PSym) {....raises: [IOError],
        tags: [ReadIOEffect].}

  Source Edit

    proc initModuleIter(mi: var ModuleIter; g: ModuleGraph; m: PSym; name: PIdent): PSym {.
        ...raises: [KeyError, Exception], tags: [ReadDirEffect, RootEffect].}

  Source Edit

    proc initOperators(g: ModuleGraph): Operators {....raises: [], tags: [].}

  Source Edit

    proc initStrTables(g: ModuleGraph; m: PSym) {....raises: [], tags: [].}

  Source Edit

    proc isDirty(g: ModuleGraph; m: PSym): bool {....raises: [], tags: [].}

  Source Edit

    proc loadCompilerProc(g: ModuleGraph; name: string): PSym {.
        ...raises: [KeyError, Exception], tags: [ReadDirEffect, RootEffect].}

  Source Edit

    proc loadPackedSym(g: ModuleGraph; s: var LazySym) {.
        ...raises: [KeyError, Exception], tags: [ReadDirEffect, RootEffect].}

  Source Edit

    proc markClientsDirty(g: ModuleGraph; fileIdx: FileIndex) {....raises: [], tags: [].}

  Source Edit

    proc markDirty(g: ModuleGraph; fileIdx: FileIndex) {....raises: [], tags: [].}

  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].}

  Returns 'nil' if the module needs to be recompiled. Source Edit

    proc moduleOpenForCodegen(g: ModuleGraph; m: FileIndex): bool {.inline,
        ...raises: [], tags: [].}

  Source Edit

    proc needsCompilation(g: ModuleGraph): bool {....raises: [], tags: [].}

  Source Edit

    proc needsCompilation(g: ModuleGraph; fileIdx: FileIndex): bool {....raises: [],
        tags: [].}

  Source Edit

    proc newModuleGraph(cache: IdentCache; config: ConfigRef): ModuleGraph {.
        ...raises: [], tags: [].}

  Source Edit

    proc nextModuleIter(mi: var ModuleIter; g: ModuleGraph): PSym {.
        ...raises: [KeyError, Exception], tags: [ReadDirEffect, RootEffect].}

  Source Edit

    proc onProcessing(graph: ModuleGraph; fileIdx: FileIndex; moduleStatus: string;
                      fromModule: PSym) {....raises: [Exception, KeyError, OSError,
        ValueError, IOError, ERecoverableError], tags: [RootEffect, ReadDirEffect,
        WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc parentModule(g: ModuleGraph; fileIdx: FileIndex): FileIndex {....raises: [],
        tags: [].}

  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],
        tags: [RootEffect].}

  Source Edit

    proc registerModuleById(g: ModuleGraph; m: FileIndex) {....raises: [Exception],
        tags: [RootEffect].}

  Source Edit

    proc rememberEmittedTypeInfo(g: ModuleGraph; m: FileIndex; ti: string) {.
        ...raises: [], tags: [].}

  Source Edit

    proc rememberFlag(g: ModuleGraph; m: PSym; flag: ModuleBackendFlag) {.
        ...raises: [], tags: [].}

  Source Edit

    proc resetAllModules(g: ModuleGraph) {....raises: [], tags: [].}

  Source Edit

    proc resetForBackend(g: ModuleGraph) {....raises: [], tags: [].}

  Source Edit

    proc setAttachedOp(g: ModuleGraph; module: int; t: PType; op: TTypeAttachedOp;
                       value: PSym) {....raises: [], tags: [].}

  we also need to record this to the packed module. Source Edit

    proc setAttachedOpPartial(g: ModuleGraph; module: int; t: PType;
                              op: TTypeAttachedOp; value: PSym) {....raises: [],
        tags: [].}

  we also need to record this to the packed module. Source Edit

    proc setToStringProc(g: ModuleGraph; t: PType; value: PSym) {....raises: [],
        tags: [].}

  Source Edit

    proc simulateCachedModule(g: ModuleGraph; moduleSym: PSym; m: PackedModule) {.
        ...raises: [KeyError, OSError, Exception], tags: [ReadDirEffect, RootEffect].}

  Source Edit

    proc someSym(g: ModuleGraph; m: PSym; name: PIdent): PSym {.
        ...raises: [KeyError, Exception], tags: [ReadDirEffect, RootEffect].}

  Source Edit

    proc stopCompile(g: ModuleGraph): bool {.inline, ...raises: [Exception],
        tags: [RootEffect].}

  Source Edit

    proc strTableAdds(g: ModuleGraph; m: PSym; s: PSym) {....raises: [], tags: [].}

  Source Edit

    proc systemModuleSym(g: ModuleGraph; name: PIdent): PSym {.
        ...raises: [KeyError, Exception], tags: [ReadDirEffect, RootEffect].}

  Source Edit

    proc unmarkAllDirty(g: ModuleGraph) {....raises: [], tags: [].}

  Source Edit

# Iterators

    iterator allSyms(g: ModuleGraph; m: PSym): PSym {....raises: [KeyError, Exception],
        tags: [ReadDirEffect, RootEffect].}

  Source Edit

    iterator methodsForGeneric(g: ModuleGraph; t: PType): (int, PSym) {.
        ...raises: [KeyError, Exception], tags: [ReadDirEffect, RootEffect].}

  Source Edit

    iterator procInstCacheItems(g: ModuleGraph; s: PSym): PInstantiation {.
        ...raises: [KeyError, Exception], tags: [ReadDirEffect, RootEffect].}

  Source Edit

    iterator suggestErrorsIter(g: ModuleGraph): Suggest {....raises: [], tags: [].}

  Source Edit

    iterator suggestSymbolsIter(g: ModuleGraph): SymInfoPair {....raises: [], tags: [].}

  Source Edit

    iterator systemModuleSyms(g: ModuleGraph; name: PIdent): PSym {.
        ...raises: [KeyError, Exception], tags: [ReadDirEffect, RootEffect].}

  Source Edit

    iterator typeInstCacheItems(g: ModuleGraph; s: PSym): PType {.
        ...raises: [KeyError, Exception], tags: [ReadDirEffect, RootEffect].}

  Source Edit

# Templates

    template onDef(info: TLineInfo; s: PSym)

  Source Edit

    template onDefResolveForward(info: TLineInfo; s: PSym)

  Source Edit

    template onUse(info: TLineInfo; s: PSym)

  Source Edit

    template semtabAll(g: ModuleGraph; m: PSym): TStrTable

  Source Edit