sigmatch

This module implements the signature matching for resolving the call to overloaded procs, generic procs and operators.

This file implements features required for IDE support.

Due to Nim's nature and the fact that system.nim is always imported, there are lots of potential symbols. Furthermore thanks to templates and macros even context based analysis does not help much: In a context like let x: | where a type has to follow, that type might be constructed from a template like extractField(MyObject, fieldName). We deal with this problem by smart sorting so that the likely symbols come first. This sorting is done this way:

  • If there is a prefix (foo|), symbols starting with this prefix come first.
  • If the prefix is part of the name (but the name doesn't start with it), these symbols come second.
  • If we have a prefix, only symbols matching this prefix are returned and nothing else.
  • If we have no prefix, consider the context. We currently distinguish between type and non-type contexts.
  • Finally, sort matches by relevance. The relevance is determined by the number of usages, so strutils.replace comes before strutils.wordWrap.
  • In any case, sorting also considers scoping information. Local variables get high priority.

Imports

ast, astalgo, semdata, types, msgs, renderer, lookups, semtypinst, magicsys, idents, lexer, options, parampatterns, trees, linter, lineinfos, lowerings, modulegraphs, prefixmatches, lineinfos, linter, wordrecg

Types

MismatchKind = enum
  kUnknown, kAlreadyGiven, kUnknownNamedParam, kTypeMismatch, kVarNeeded,
  kMissingParam, kExtraArg, kPositionalAlreadyGiven
Source Edit
MismatchInfo = object
  kind*: MismatchKind
  arg*: int
  formal*: PSym
Source Edit
TCandidateState = enum
  csEmpty, csMatch, csNoMatch
Source Edit
CandidateError = object
  sym*: PSym
  firstMismatch*: MismatchInfo
  diagnostics*: seq[string]
  enabled*: bool
Source Edit
CandidateErrors = seq[CandidateError]
Source Edit
TCandidate = object
  c*: PContext
  exactMatches*: int
  genericMatches: int
  subtypeMatches: int
  intConvMatches: int
  convMatches: int
  state*: TCandidateState
  callee*: PType
  calleeSym*: PSym
  calleeScope*: int
  call*: PNode
  bindings*: TIdTable
  magic*: TMagic
  baseTypeMatch: bool
  fauxMatch*: TTypeKind
  genericConverter*: bool
  coerceDistincts*: bool
  typedescMatched*: bool
  isNoCall*: bool
  inferredTypes: seq[PType]
  diagnostics*: seq[string]
  inheritancePenalty: int
  firstMismatch*: MismatchInfo
  diagnosticsEnabled*: bool
Source Edit
TTypeRelFlag = enum
  trDontBind, trNoCovariance, trBindGenericParam
Source Edit
TTypeRelFlags = set[TTypeRelFlag]
Source Edit
TTypeRelation = enum
  isNone, isConvertible, isIntConv, isSubtype, isSubrange,
  isBothMetaConvertible, isInferred, isInferredConvertible, isGeneric,
  isFromIntLit, isEqual
Source Edit
TCheckPointResult = enum
  cpNone, cpFuzzy, cpExact
Source Edit

Procs

proc initCandidate(ctx: PContext; c: var TCandidate; callee: PType) {...}{.
    raises: [], tags: [].}
Source Edit
proc initCandidate(ctx: PContext; c: var TCandidate; callee: PSym;
                   binding: PNode; calleeScope = -1; diagnosticsEnabled = false) {...}{.
    raises: [], tags: [].}
Source Edit
proc newCandidate(ctx: PContext; callee: PSym; binding: PNode; calleeScope = -1): TCandidate {...}{.
    raises: [], tags: [].}
Source Edit
proc newCandidate(ctx: PContext; callee: PType): TCandidate {...}{.raises: [],
    tags: [].}
Source Edit
proc writeMatches(c: TCandidate) {...}{.raises: [], tags: [].}
Source Edit
proc cmpCandidates(a, b: TCandidate): int {...}{.raises: [Exception],
    tags: [RootEffect].}
Source Edit
proc describeArgs(c: PContext; n: PNode; startIdx = 1; prefer = preferName): string {...}{.
    raises: [Exception, ValueError], tags: [RootEffect].}
Source Edit
proc matchUserTypeClass(m: var TCandidate; ff, a: PType): PType {...}{.
    raises: [Exception, ValueError, IOError, ERecoverableError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}
Source Edit
proc inferStaticParam(c: var TCandidate; lhs: PNode; rhs: BiggestInt): bool {...}{.
    raises: [], tags: [].}
Source Edit
proc typeRel(c: var TCandidate; f, aOrig: PType; flags: TTypeRelFlags = {}): TTypeRelation {...}{.
    raises: [Exception, ValueError, IOError, ERecoverableError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}
Source Edit
proc cmpTypes(c: PContext; f, a: PType): TTypeRelation {...}{.
    raises: [Exception, ValueError, IOError, ERecoverableError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}
Source Edit
proc paramTypesMatch(m: var TCandidate; f, a: PType; arg, argOrig: PNode): PNode {...}{.
    raises: [Exception, ValueError, IOError, ERecoverableError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}
Source Edit
proc semFinishOperands(c: PContext; n: PNode) {...}{.raises: [Exception],
    tags: [RootEffect].}
Source Edit
proc partialMatch(c: PContext; n, nOrig: PNode; m: var TCandidate) {...}{.
    raises: [Exception, ValueError, IOError, ERecoverableError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}
Source Edit
proc matches(c: PContext; n, nOrig: PNode; m: var TCandidate) {...}{.
    raises: [Exception, ValueError, IOError, ERecoverableError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}
Source Edit
proc argtypeMatches(c: PContext; f, a: PType; fromHlo = false): bool {...}{.
    raises: [Exception, ValueError, IOError, ERecoverableError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}
Source Edit
proc instTypeBoundOp(c: PContext; dc: PSym; t: PType; info: TLineInfo;
                     op: TTypeAttachedOp; col: int): PSym {...}{.nosinks,
    raises: [Exception, ValueError, IOError, ERecoverableError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}
Source Edit
proc `$`(suggest: Suggest): string {...}{.raises: [], tags: [].}
Source Edit
proc fieldVisible(c: PContext; f: PSym): bool {...}{.inline, raises: [], tags: [].}
Source Edit
proc inCheckpoint(current, trackPos: TLineInfo): TCheckPointResult {...}{.raises: [],
    tags: [].}
Source Edit
proc isTracked(current, trackPos: TLineInfo; tokenLen: int): bool {...}{.raises: [],
    tags: [].}
Source Edit
proc suggestSym(conf: ConfigRef; info: TLineInfo; s: PSym; usageSym: var PSym;
                isDecl = true) {...}{.inline, raises: [], tags: [].}
misnamed: should be 'symDeclared' Source Edit
proc markOwnerModuleAsUsed(c: PContext; s: PSym) {...}{.raises: [], tags: [].}
Source Edit
proc markUsed(c: PContext; info: TLineInfo; s: PSym) {...}{.
    raises: [Exception, ValueError, IOError, ERecoverableError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}
Source Edit
proc safeSemExpr(c: PContext; n: PNode): PNode {...}{.raises: [Exception],
    tags: [RootEffect].}
Source Edit
proc suggestExprNoCheck(c: PContext; n: PNode) {...}{.
    raises: [Exception, ValueError, IOError, ERecoverableError, ESuggestDone],
    tags: [RootEffect, ReadIOEffect, WriteIOEffect, ReadEnvEffect].}
Source Edit
proc suggestExpr(c: PContext; n: PNode) {...}{.
    raises: [Exception, ValueError, IOError, ERecoverableError, ESuggestDone],
    tags: [RootEffect, ReadIOEffect, WriteIOEffect, ReadEnvEffect].}
Source Edit
proc suggestDecl(c: PContext; n: PNode; s: PSym) {...}{.
    raises: [Exception, ValueError, IOError, ERecoverableError, ESuggestDone],
    tags: [RootEffect, ReadIOEffect, WriteIOEffect, ReadEnvEffect].}
Source Edit
proc suggestStmt(c: PContext; n: PNode) {...}{.
    raises: [Exception, ValueError, IOError, ERecoverableError, ESuggestDone],
    tags: [RootEffect, ReadIOEffect, WriteIOEffect, ReadEnvEffect].}
Source Edit
proc suggestEnum(c: PContext; n: PNode; t: PType) {...}{.
    raises: [Exception, ValueError, IOError, ESuggestDone],
    tags: [RootEffect, ReadIOEffect, WriteIOEffect].}
Source Edit
proc suggestSentinel(c: PContext) {...}{.raises: [Exception, ValueError, IOError], tags: [
    RootEffect, ReadIOEffect, WriteIOEffect].}
Source Edit

Templates

template hasFauxMatch(c: TCandidate): bool
Source Edit

© 2006–2021 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/compiler/sigmatch.html