compiler/modules/modulegraphs

    Dark Mode
Search:
  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.

Types

FullId = object
  module*: int
  packed*: PackedItemId
  Source   Edit
Iface = object
  module*: PSym              ## module this "Iface" belongs to
  converters*: seq[LazySym]
  patterns*: seq[LazySym]    ## patterns for term rewriting macros -- ick
  pureEnums*: seq[LazySym]
  interf: TStrTable
  interfHidden: TStrTable    ## xxx: unexported or internal interface?
  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
represents a symbol that maybe in a module that may be loaded or not yet fully defined. This is handy when we want to declare some symbols who's definitions refer to each other first and then process the definitions with lazy symbol resolution -- as in type sections.   Source   Edit
LazyType = object
  id*: FullId
  typ*: PType
represents a type that maybe in a module that may be loaded or not yet fully defined. This is handy when we want to declare some symbols who's definitions refer to each other first and then process the definitions with lazy type resolution -- as in type sections.   Source   Edit
ModuleGraph = 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]]
  methodsPerType*: Table[ItemId, seq[(int, LazySym)]]
  enumToStringProcs*: Table[ItemId, LazySym]
  emittedTypeInfo*: Table[string, FileIndex]
  libs*: seq[seq[TLib]]      ## indexed by ``LibId``
  transformed*: seq[Table[int32, PNode]] ## the cached transformed routine
                                         ## bodies for all modules
  startupPackedConfig*: PackedConfig
  packageSyms*: TStrTable
  deps*: IntSet
  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]
  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]
  idgen*: IdGenerator
  operators*: Operators
  noreturnType*: PType ## special type used for marking statements as not returning. Currently
                       ## only used in mid-end
  when defined(nimsuggest):
      onMarkUsed*: SuggestCallback ## callback decouples regular compiler code `markUsed` from suggest
    
  onSymImport*: SuggestCallback ## callback decouples regular compiler code `importer` from suggest
  
  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
SigHash = distinct MD5Digest
  Source   Edit
SuggestCallback = proc (graph: ModuleGraph; info: TLineInfo; s: PSym;
                        usageSym: var PSym; isDecl: bool)
callback is used to decouple regular compiler code from suggest tool   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 addDep(g: ModuleGraph; m: PSym; dep: FileIndex) {....raises: [], tags: [].}
  Source   Edit
proc addIncludeDep(g: ModuleGraph; module, includeFile: FileIndex) {....raises: [],
    tags: [].}
  Source   Edit
proc addLib(g: ModuleGraph; module: int; lib: sink TLib): LibId {....raises: [],
    tags: [].}
Registers (adds) lib with the given module and returns the ID through which the instance can be accessed from now on.   Source   Edit
proc addMethodToGeneric(g: ModuleGraph; module: int; t: PType; col: int; m: PSym) {.
    ...raises: [], tags: [].}
  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: [KeyError, Exception], tags: [ReadDirEffect, RootEffect].}
  Source   Edit
proc createMagic(g: ModuleGraph; idgen: IdGenerator; name: string; m: TMagic): PSym {.
    ...raises: [], tags: [].}
  Source   Edit
proc getAttachedOp(g: ModuleGraph; t: PType; op: TTypeAttachedOp): PSym {.
    ...raises: [KeyError, Exception], tags: [ReadDirEffect, RootEffect].}
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
func getLib(g: ModuleGraph; id: LibId): var TLib {....raises: [], tags: [].}
  Source   Edit
proc getModule(g: ModuleGraph; fileIdx: FileIndex): PSym {....raises: [], tags: [].}
  Source   Edit
proc getToStringProc(g: ModuleGraph; t: PType): PSym {.
    ...raises: [KeyError, Exception], tags: [ReadDirEffect, RootEffect].}
  Source   Edit
proc getTransformed(g: ModuleGraph; prc: PSym): PNode {....raises: [], tags: [].}
Retrieves the cached tranformed body for prc. If none exists, 'nil' is returned.   Source   Edit
proc hasDisabledAsgn(g: ModuleGraph; t: PType): bool {.
    ...raises: [KeyError, Exception], tags: [ReadDirEffect, RootEffect].}
  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 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: [].}
we need to mark its dependent modules D as dirty right away because after nimsuggest is done with this module, the module's dirty flag will be cleared but D still needs to be remembered as 'dirty'.   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, KeyError, Exception, ERecoverableError], tags: [
    ReadEnvEffect, ReadIOEffect, WriteDirEffect, ReadDirEffect, RootEffect].}
Returns 'nil' if the module needs to be recompiled.   Source   Edit
proc moduleOpenForCodegen(g: ModuleGraph; m: FileIndex): bool {.inline,
    ...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, ERecoverableError],
                                      tags: [RootEffect].}
  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: [].}
  Source   Edit
proc setAttachedOpPartial(g: ModuleGraph; module: int; t: PType;
                          op: TTypeAttachedOp; value: PSym) {....raises: [],
    tags: [].}
  Source   Edit
proc setToStringProc(g: ModuleGraph; t: PType; value: PSym) {....raises: [],
    tags: [].}
  Source   Edit
proc setTransformed(g: ModuleGraph; prc: PSym; body: PNode) {....raises: [],
    tags: [].}
Sets the transformed body for prc, overwriting the previously cached version, if one exists.   Source   Edit
proc simulateCachedModule(g: ModuleGraph; moduleSym: PSym; m: PackedModule) {.
    ...raises: [KeyError, 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 storeLibs(g: ModuleGraph; module: int) {....raises: [Exception],
    tags: [RootEffect].}
Writes the TLib instances associated with module to the module's packed representation. Only relevant for IC.   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

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 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