This module contains the data structures for the semantic checking phase.
Types
BodyTask = object key*: uint64 ## §2.3: `(module, ordinal)`, ordinal = the ## declaration's position in the header pass. ## Dispatch order is key order, which is what ## makes the output scheduling-independent. state*: BodyTaskState owner*: PSym ## the routine def*: PNode ## its definition; `owner.ast`, except that ## forward-decl reconciliation can rebind ## `owner`, so keep the node explicitly resultType*: PType isInlineIterator*: bool scope*: PScope procCon*: PProcCon optionStack*: seq[POptionEntry] options*: TOptions notes*, warningAsErrors*: TNoteKinds features*: set[Feature]
-
One deferred routine body — doc/parallel_compiler.md's unit of work (§2.2), and later the unit of parallelism. Stage 1 runs these on one thread, so what the record carries is not "state to ship to a worker" but state the header pass is about to move past: everything a body sem reads from PContext that is POSITIONAL. That is the same list tryExpr snapshots (semexprs), plus the option stack.
scope and procCon are the interesting ones. A routine's parameters live in a scope opened by semProcAux and its result in a PProcCon; deferring the body means detaching both from PContext's stacks rather than closing them, and re-attaching them at drain. The scope object survives because this record holds it, and its parent chain still ends at the module's top-level scope, which does not move.
Source Edit BodyTaskState = enum btPending, ## enqueued by the header pass, not started btRunning, ## being semmed right now (recursion guard, §2.3) btDone
- Source Edit
ImportedModule = object m*: PSym case mode*: ImportMode of importAll: nil of importSet: imported*: IntSet of importExcept: exceptSet*: IntSet
- Source Edit
ImportMode = enum importAll, importSet, importExcept
- Source Edit
POptionEntry = ref TOptionEntry
- Source Edit
TBorrowState = enum bsNone, bsReturnNotMatch, bsNoDistinct, bsGeneric, bsNotSupported, bsMatch
- Source Edit
TContext = object of TPassContext enforceVoidContext*: PType voidType*: PType module*: PSym currentScope*: PScope moduleScope*: PScope imports*: seq[ImportedModule] topLevelScope*: PScope p*: PProcCon intTypeCache*: array[-5 .. 32, PType] nilTypeCache*: PType matchedConcept*: ptr TMatchedConcept friendModules*: seq[PSym] instCounter*: int templInstCounter*: ref int inGenericContext*: int inStaticContext*: int inUnrolledContext*: int compilesContextId*: int compilesContextIdGenerator*: int inGenericInst*: int converters*: seq[PSym] patterns*: seq[PSym] optionStack*: seq[POptionEntry] libs*: seq[PLib] semConstExpr*: proc (c: PContext; n: PNode; expectedType: PType = nil): PNode {. nimcall.} semExpr*: proc (c: PContext; n: PNode; flags: TExprFlags = {}; expectedType: PType = nil): PNode {.nimcall.} semExprWithType*: proc (c: PContext; n: PNode; flags: TExprFlags = {}; expectedType: PType = nil): PNode {.nimcall.} semTryExpr*: proc (c: PContext; n: PNode; flags: TExprFlags = {}): PNode {. nimcall.} semTryConstExpr*: proc (c: PContext; n: PNode; expectedType: PType = nil): PNode {. nimcall.} computeRequiresInit*: proc (c: PContext; t: PType): bool {.nimcall.} hasUnresolvedArgs*: proc (c: PContext; n: PNode): bool semOperand*: proc (c: PContext; n: PNode; flags: TExprFlags = {}): PNode {. nimcall.} semConstBoolExpr*: proc (c: PContext; n: PNode): PNode {.nimcall.} semOverloadedCall*: proc (c: PContext; n, nOrig: PNode; filter: TSymKinds; flags: TExprFlags; expectedType: PType = nil): PNode {. nimcall.} semTypeNode*: proc (c: PContext; n: PNode; prev: PType): PType {.nimcall.} semInferredLambda*: proc (c: PContext; pt: LayeredIdTable; n: PNode): PNode semGenerateInstance*: proc (c: PContext; fn: PSym; pt: LayeredIdTable; info: TLineInfo): PSym instantiateOnlyProcType*: proc (c: PContext; pt: LayeredIdTable; prc: PSym; info: TLineInfo): PType fitDefaultNode*: proc (c: PContext; n: var PNode; expectedType: PType) includedFiles*: IntSet pureEnumFields*: TStrTable userPragmas*: TStrTable evalContext*: PEvalContext unknownIdents*: IntSet generics*: seq[TInstantiationPair] topStmts*: int lastGenericIdx*: int inParallelStmt*: int instTypeBoundOp*: proc (c: PContext; dc: PSym; t: PType; info: TLineInfo; op: TTypeAttachedOp; col: int): PSym {.nimcall.} cache*: IdentCache graph*: ModuleGraph signatures*: TStrTable recursiveDep*: string suggestionsMade*: bool isAmbiguous*: bool features*: set[Feature] inTypeContext*, inConceptDecl*: int unusedImports*: seq[(PSym, TLineInfo)] exportIndirections*: HashSet[(int, int)] importModuleMap*: Table[int, int] lastTLineInfo*: TLineInfo sideEffects*: Table[int, seq[(TLineInfo, PSym)]] inUncheckedAssignSection*: int inUncheckedAccess*: int importModuleLookup*: Table[int, seq[int]] forwardTypeUpdates*: seq[(PSym, PType, PNode)] forwardFieldUpdates*: seq[(PType, PNode, PType)] forwardFlagUpdates*: seq[(PType, PType)] staleTypeFlags*: IntSet inTypeofContext*: int semAsgnOpr*: proc (c: PContext; n: PNode; k: TNodeKind): PNode {.nimcall.} shadowDiscardedDefs*: IntSet realizedDefs*: IntSet hasSymRedefs*: bool bodyTasks*: seq[BodyTask] bodyTaskIndex*: Table[ItemId, int] prevDemandRoutineBody*: proc (prc: PSym) {.closure.} deferAllBodies*: bool cyclePartners*: seq[PContext]
- Source Edit
TExprFlag = enum efLValue, efWantIterator, efWantIterable, efPreferIteratorForIterable, efInTypeof, efNeedStatic, efPreferStatic, efPreferNilResult, efWantStmt, efAllowStmt, efDetermineType, efExplain, efWantValue, efOperand, efNoSemCheck, efNoEvaluateGeneric, efInCall, efFromHlo, efNoSem2Check, efNoUndeclared, efIsDotCall, efCannotBeDotCall, efTypeAllowed, efWantNoDefaults, efIgnoreDefaults, efAllowSymChoice
- Source Edit
TExprFlags = set[TExprFlag]
- Source Edit
TInstantiationPair = object genericSym*: PSym inst*: PInstantiation
- Source Edit
TMatchedConcept = object candidateType*: PType prev*: ptr TMatchedConcept depth*: int
- Source Edit
TOptionEntry = object options*: TOptions defaultCC*: TCallingConvention dynlib*: PLib notes*: TNoteKinds features*: set[Feature] otherPragmas*: PNode warningAsErrors*: TNoteKinds
- Source Edit
Procs
proc addConverter(c: PContext; conv: PSym) {. ...raises: [KeyError, OSError, Exception, ValueError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, RootEffect], forbids: [].}
- Source Edit
proc addConverterDef(c: PContext; conv: PSym) {. ...raises: [KeyError, OSError, Exception, ValueError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, RootEffect], forbids: [].}
- Source Edit
proc addImportFileDep(c: PContext; f: FileIndex) {. ...raises: [KeyError, OSError, Exception, ValueError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, RootEffect], forbids: [].}
- Source Edit
proc addIncludeFileDep(c: PContext; f: FileIndex) {....raises: [], tags: [], forbids: [].}
- Source Edit
proc addPattern(c: PContext; p: PSym) {....raises: [KeyError, OSError, Exception, ValueError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, RootEffect], forbids: [].}
- Source Edit
proc addPragmaComputation(c: PContext; n: PNode) {. ...raises: [KeyError, OSError, Exception, ValueError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, RootEffect], forbids: [].}
- Source Edit
proc addPureEnum(c: PContext; e: PSym) {. ...raises: [KeyError, OSError, Exception, ValueError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, RootEffect], forbids: [].}
- Source Edit
proc addToGenericProcCache(c: PContext; s: PSym; inst: PInstantiation) {. ...raises: [], tags: [], forbids: [].}
- Source Edit
proc analyseIfAddressTakenInCall(c: PContext; n: PNode; isConverter = false) {....raises: [ Exception, ValueError, OSError, KeyError, IOError, ERecoverableError], tags: [ RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect], forbids: [].}
- Source Edit
proc checkMinSonsLen(n: PNode; length: int; conf: ConfigRef) {....raises: [ Exception, ValueError, OSError, KeyError, IOError, ERecoverableError], tags: [ RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect], forbids: [].}
- Source Edit
proc checkSonsLen(n: PNode; length: int; conf: ConfigRef) {....raises: [Exception, ValueError, OSError, KeyError, IOError, ERecoverableError], tags: [ RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect], forbids: [].}
- Source Edit
proc considerGenSyms(c: PContext; n: PNode) {. ...raises: [KeyError, OSError, Exception, ValueError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, RootEffect], forbids: [].}
- Source Edit
proc getCurrOwner(c: PContext): PSym {....raises: [], tags: [], forbids: [].}
- Source Edit
proc illFormedAst(n: PNode; conf: ConfigRef) {....raises: [Exception, ValueError, OSError, KeyError, IOError, ERecoverableError], tags: [RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect], forbids: [].}
- Source Edit
proc illFormedAstLocal(n: PNode; conf: ConfigRef) {....raises: [Exception, ValueError, OSError, KeyError, IOError, ERecoverableError], tags: [ RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect], forbids: [].}
- Source Edit
proc isSsoStringIndex(conf: ConfigRef; n: PNode): bool {. ...raises: [KeyError, OSError, Exception, ValueError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, RootEffect], forbids: [].}
- Source Edit
proc isTopLevel(c: PContext): bool {.inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc isTopLevelInsideDeclaration(c: PContext; sym: PSym): bool {.inline, ...raises: [KeyError, OSError, Exception, ValueError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, RootEffect], forbids: [].}
- Source Edit
proc lastOptionEntry(c: PContext): POptionEntry {....raises: [], tags: [], forbids: [].}
- Source Edit
proc makeInstPair(s: PSym; inst: PInstantiation): TInstantiationPair {. ...raises: [], tags: [], forbids: [].}
- Source Edit
proc makePtrType(c: PContext; baseType: PType): PType {. ...raises: [KeyError, OSError, Exception, ValueError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, RootEffect], forbids: [].}
- Source Edit
proc makePtrType(owner: PSym; baseType: PType; idgen: IdGenerator): PType {. ...raises: [KeyError, OSError, Exception, ValueError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, RootEffect], forbids: [].}
- Source Edit
proc markIndirect(c: PContext; s: PSym) {.inline, ...raises: [KeyError, OSError, Exception, ValueError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, RootEffect], forbids: [].}
- Source Edit
proc newContext(graph: ModuleGraph; module: PSym): PContext {....raises: [], tags: [], forbids: [].}
- Source Edit
proc newOptionEntry(conf: ConfigRef): POptionEntry {....raises: [], tags: [], forbids: [].}
- Source Edit
proc ownedRefsEnabled(c: PContext): bool {.inline, ...raises: [], tags: [], forbids: [].}
- owned is a real type constructor (rather than erased) under the old --newruntime switch or --experimental:ownedRefs. Source Edit
proc popCaseContext(c: PContext) {....raises: [], tags: [], forbids: [].}
- Source Edit
proc popOptionEntry(c: PContext) {....raises: [], tags: [], forbids: [].}
- Source Edit
proc popProcCon(c: PContext) {.inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc pushCaseContext(c: PContext; caseNode: PNode) {....raises: [], tags: [], forbids: [].}
- Source Edit
proc pushOptionEntry(c: PContext): POptionEntry {....raises: [], tags: [], forbids: [].}
- Source Edit
proc reexportSym(c: PContext; s: PSym) {. ...raises: [KeyError, OSError, Exception, ValueError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, RootEffect], forbids: [].}
- Source Edit
proc rememberExpansion(c: PContext; info: TLineInfo; expandedSym: PSym) {. ...raises: [KeyError, OSError, Exception, ValueError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, RootEffect], forbids: [].}
-
Templates and macros are inlined and leave no trace in the sem'checked AST, and generic procs do not leave enough information referencing the generic definition for tools to use for definitions and usages, since they are instantiated by the compiler. This is pecial logic that helps remember macro/template/generic proc expansions, saving the data for the "NIF" file mechanism to handle.
We only bother when a NIF file is actually going to be written (IC / nim m, --compress, semantic BIF output, or a running suggestion engine); a plain nim c throws the record away, so recording it would be pure overhead.
Source Edit proc renderNotLValue(n: PNode): string {. ...raises: [Exception, KeyError, OSError, ValueError], tags: [RootEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc replaceHookMagic(c: PContext; n: PNode; kind: TTypeAttachedOp): PNode {....raises: [ KeyError, OSError, Exception, ValueError, IOError, ERecoverableError], tags: [ ReadEnvEffect, ReadIOEffect, ReadDirEffect, RootEffect, WriteIOEffect], forbids: [].}
- Replaces builtin generic hooks with lifted hooks. Source Edit
proc scopeDepth(c: PContext): int {.inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc sealRodFile(c: PContext) {....raises: [KeyError, OSError, Exception, ValueError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, RootEffect], forbids: [].}
- Source Edit
proc setCaseContextIdx(c: PContext; idx: int) {....raises: [], tags: [], forbids: [].}
- Source Edit
proc setIntLitType(c: PContext; result: PNode) {....raises: [KeyError, OSError, Exception, ValueError, IOError, ERecoverableError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, RootEffect, WriteIOEffect], forbids: [].}
- Source Edit