# compiler/types

Dark Mode

- Index

Search:
Group by:
Source Edit

code owner: Arne Döring e-mail: arne.doering@gmx.net included from types.nim

# Imports

ast, astalgo, trees, msgs, platform, renderer, options, lineinfos, int128, modulegraphs, astmsgs

# Types

    EffectsCompat = enum
      efCompat, efRaisesDiffer, efRaisesUnknown, efTagsDiffer, efTagsUnknown,
      efLockLevelsDiffer, efEffectsDelayed

  Source Edit

    OrdinalType = enum
      NoneLike, IntLike, FloatLike

  Source Edit

    ProcConvMismatch = enum
      pcmNoSideEffect, pcmNotGcSafe, pcmLockDifference, pcmNotIterator,
      pcmDifferentCallConv

  Source Edit

    TDistinctCompare = enum
      dcEq,                     ## a and b should be the same type
      dcEqIgnoreDistinct,       ## compare symmetrically: (distinct a) == b, a == b
                                 ## or a == (distinct b)
      dcEqOrDistinctOf           ## a equals b or a is distinct of b

  how distinct types are to be compared Source Edit

    TParamsEquality = enum
      paramsNotEqual, paramsEqual, paramsIncompatible

  Source Edit

    TPreferedDesc = enum
      preferName, preferDesc, preferExported, preferModuleInfo, preferGenericArg,
      preferTypeName, preferResolved, preferMixed

  Source Edit

    TTypeCmpFlag = enum
      IgnoreTupleFields,        ## NOTE: Only set this flag for backends!
      IgnoreCC, ExactTypeDescValues, ExactGenericParams, ExactConstraints,
      ExactGcSafety, AllowCommonBase, PickyCAliases

  Source Edit

    TTypeCmpFlags = set[TTypeCmpFlag]

  Source Edit

    TTypeFieldResult = enum
      frNone, frHeader, frEmbedded

  Source Edit

    TTypeIter = proc (t: PType; closure: RootRef): bool {.nimcall.}

  Source Edit

    TTypeMutator = proc (t: PType; closure: RootRef): PType {.nimcall.}

  Source Edit

    TTypePredicate = proc (t: PType): bool {.nimcall.}

  Source Edit

    TTypeRelation = enum
      isNone, isConvertible, isIntConv, isSubtype, isSubrange,
      isBothMetaConvertible, isInferred, isInferredConvertible, isGeneric,
      isFromIntLit, isEqual

  Source Edit

# Consts

    abstractInstOwned = {tyAlias, tyTypeDesc, tyGenericInst, tyDistinct, tyOrdinal,
                         tyOwned..tySink, tyInferred}

  Source Edit

    abstractPtrs = {tyVar, tyPtr, tyRef, tyGenericInst, tyDistinct, tyOrdinal,
                    tyTypeDesc, tyAlias, tyInferred, tySink, tyLent, tyOwned}

  Source Edit

    abstractRange = {tyGenericInst, tyRange, tyDistinct, tyOrdinal, tyTypeDesc,
                     tyAlias, tyInferred, tySink, tyOwned}

  Source Edit

    abstractVar = {tyVar, tyGenericInst, tyDistinct, tyOrdinal, tyTypeDesc, tyAlias,
                   tyInferred, tySink, tyLent, tyOwned}

  Source Edit

    skipPtrs = {tyVar, tyPtr, tyRef, tyGenericInst, tyTypeDesc, tyAlias, tyInferred,
                tySink, tyLent, tyOwned}

  Source Edit

    szIllegalRecursion = -2

  Source Edit

    szTooBigSize = -4

  Source Edit

    szUncomputedSize = -1

  Source Edit

    szUnknownSize = -3

  Source Edit

    typedescInst = {tyAlias, tyTypeDesc, tyGenericInst, tyDistinct, tyOrdinal,
                    tyOwned..tySink, tyUserTypeClass, tyInferred}

  Source Edit

    typedescPtrs = {tyAlias, tyTypeDesc, tyGenericInst, tyDistinct, tyOrdinal,
                    tyPtr..tyVar, tyOwned..tyLent, tyInferred}

  Source Edit

# Procs

    proc addPragmaAndCallConvMismatch(message: var string; formal, actual: PType;
                                      conf: ConfigRef) {....raises: [ValueError],
        tags: [].}

  Source Edit

    proc addTypeDeclVerboseMaybe(result: var string; conf: ConfigRef; typ: PType) {.
        ...raises: [Exception, ValueError, KeyError, OSError],
        tags: [RootEffect, ReadDirEffect].}

  Source Edit

    proc addTypeHeader(result: var string; conf: ConfigRef; typ: PType;
                       prefer: TPreferedDesc = preferMixed;
                       getDeclarationPath = true) {.
        ...raises: [Exception, ValueError, KeyError, OSError],
        tags: [RootEffect, ReadDirEffect].}

  Source Edit

    proc analyseObjectWithTypeField(t: PType): TTypeFieldResult {.
        ...raises: [Exception], tags: [RootEffect].}

  Source Edit

    proc base(t: PType): PType {....raises: [], tags: [].}

  Source Edit

    proc baseOfDistinct(t: PType; g: ModuleGraph; idgen: IdGenerator): PType {.
        ...raises: [], tags: [].}

  Source Edit

    proc canFormAcycle(typ: PType): bool {....raises: [Exception], tags: [RootEffect].}

  Source Edit

    proc classify(t: PType): OrdinalType {....raises: [], tags: [].}

  for convenient type checking: Source Edit

    proc commonSuperclass(a, b: PType): PType {....raises: [Exception],
        tags: [RootEffect].}

  Source Edit

    proc compareTypes(x, y: PType; cmp: TDistinctCompare = dcEq;
                      flags: TTypeCmpFlags = {}): bool {.
        ...raises: [KeyError, Exception, ERecoverableError], tags: [RootEffect].}

  compares two type for equality (modulo type distinction) Source Edit

    proc compatibleEffects(formal, actual: PType): EffectsCompat {.
        ...raises: [Exception], tags: [RootEffect].}

  Source Edit

    proc computeSize(conf: ConfigRef; typ: PType): BiggestInt {....raises: [Exception,
        ValueError, KeyError, OSError, IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc containsCompileTimeOnly(t: PType): bool {....raises: [], tags: [].}

  Source Edit

    proc containsGarbageCollectedRef(typ: PType): bool {....raises: [Exception],
        tags: [RootEffect].}

  Source Edit

    proc containsGenericType(t: PType): bool {....raises: [Exception],
        tags: [RootEffect].}

  Source Edit

    proc containsHiddenPointer(typ: PType): bool {....raises: [Exception],
        tags: [RootEffect].}

  Source Edit

    proc containsManagedMemory(typ: PType): bool {....raises: [Exception],
        tags: [RootEffect].}

  Source Edit

    proc containsObject(t: PType): bool {....raises: [Exception], tags: [RootEffect].}

  Source Edit

    proc containsTyRef(typ: PType): bool {....raises: [Exception], tags: [RootEffect].}

  Source Edit

    proc elemType(t: PType): PType {....raises: [], tags: [].}

  Source Edit

    proc enumHasHoles(t: PType): bool {....raises: [], tags: [].}

  Source Edit

    proc equalParams(a, b: PNode): TParamsEquality {....raises: [Exception, KeyError],
        tags: [RootEffect].}

  Source Edit

    proc firstFloat(t: PType): BiggestFloat {....raises: [Exception, ValueError,
        KeyError, OSError, IOError, ERecoverableError], tags: [RootEffect,
        ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc firstOrd(conf: ConfigRef; t: PType): Int128 {....raises: [Exception,
        ValueError, KeyError, OSError, IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc floatRangeCheck(x: BiggestFloat; t: PType): bool {....raises: [Exception,
        ValueError, KeyError, OSError, IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc getAlign(conf: ConfigRef; typ: PType): BiggestInt {....raises: [Exception,
        ValueError, KeyError, OSError, IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc getFloatValue(n: PNode): BiggestFloat {....raises: [], tags: [].}

  Source Edit

    proc getOrdValue(n: PNode; onError = high(Int128)): Int128 {....raises: [],
        tags: [].}

  Source Edit

    proc getProcConvMismatch(c: ConfigRef; f, a: PType; rel = isNone): (
        set[ProcConvMismatch], TTypeRelation) {....raises: [], tags: [].}

  Returns a set of the reason of mismatch, and the relation for conversion. Source Edit

    proc getProcHeader(conf: ConfigRef; sym: PSym;
                       prefer: TPreferedDesc = preferName; getDeclarationPath = true): string {.
        ...raises: [Exception, KeyError, ValueError, OSError],
        tags: [RootEffect, ReadDirEffect].}

  Source Edit

    proc getReturnType(s: PSym): PType {....raises: [], tags: [].}

  Source Edit

    proc getSize(conf: ConfigRef; typ: PType): BiggestInt {....raises: [Exception,
        ValueError, KeyError, OSError, IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc inheritanceDiff(a, b: PType): int {....raises: [Exception], tags: [RootEffect].}

  Source Edit

    proc invalidGenericInst(f: PType): bool {....raises: [], tags: [].}

  Source Edit

    proc isCharArrayPtr(t: PType; allowPointerToChar: bool): bool {....raises: [
        Exception, ValueError, KeyError, OSError, IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc isCompileTimeOnly(t: PType): bool {.inline, ...raises: [], tags: [].}

  Source Edit

    proc isDefectException(t: PType): bool {....raises: [], tags: [].}

  Source Edit

    proc isEmptyContainer(t: PType): bool {....raises: [], tags: [].}

  Source Edit

    proc isException(t: PType): bool {....raises: [], tags: [].}

  Source Edit

    proc isFinal(t: PType): bool {....raises: [], tags: [].}

  Source Edit

    proc isFloatLit(t: PType): bool {.inline, ...raises: [], tags: [].}

  Source Edit

    proc isGenericAlias(t: PType): bool {....raises: [], tags: [].}

  Source Edit

    proc isIntLit(t: PType): bool {.inline, ...raises: [], tags: [].}

  Source Edit

    proc isOrdinalType(t: PType; allowEnumWithHoles: bool = false): bool {.
        ...raises: [], tags: [].}

  Source Edit

    proc isPureObject(typ: PType): bool {....raises: [], tags: [].}

  Source Edit

    proc isSinkTypeForParam(t: PType): bool {....raises: [], tags: [].}

  Source Edit

    proc isTupleRecursive(t: PType): bool {....raises: [], tags: [].}

  Source Edit

    proc isUnsigned(t: PType): bool {....raises: [], tags: [].}

  Source Edit

    proc iterOverType(t: PType; iter: TTypeIter; closure: RootRef): bool {.
        ...raises: [Exception], tags: [RootEffect].}

  Source Edit

    proc lacksMTypeField(typ: PType): bool {.inline, ...raises: [], tags: [].}

  Source Edit

    proc lastFloat(t: PType): BiggestFloat {....raises: [Exception, ValueError,
        KeyError, OSError, IOError, ERecoverableError], tags: [RootEffect,
        ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc lastOrd(conf: ConfigRef; t: PType): Int128 {....raises: [Exception,
        ValueError, KeyError, OSError, IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc lengthOrd(conf: ConfigRef; t: PType): Int128 {....raises: [Exception,
        ValueError, KeyError, OSError, IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc lookupFieldAgain(ty: PType; field: PSym): PSym {....raises: [], tags: [].}

  Source Edit

    proc matchType(a: PType; pattern: openArray[tuple[k: TTypeKind, i: int]];
                   last: TTypeKind): bool {....raises: [], tags: [].}

  Source Edit

    proc mutateType(t: PType; iter: TTypeMutator; closure: RootRef): PType {.
        ...raises: [Exception, KeyError], tags: [RootEffect].}

  Source Edit

    proc safeInheritanceDiff(a, b: PType): int {....raises: [Exception],
        tags: [RootEffect].}

  Source Edit

    proc safeSkipTypes(t: PType; kinds: TTypeKinds): PType {....raises: [], tags: [].}

  same as 'skipTypes' but with a simple cycle detector. Source Edit

    proc sameBackendType(x, y: PType): bool {.
        ...raises: [KeyError, Exception, ERecoverableError], tags: [RootEffect].}

  Source Edit

    proc sameDistinctTypes(a, b: PType): bool {.inline, ...raises: [Exception],
        tags: [RootEffect].}

  Source Edit

    proc sameEnumTypes(a, b: PType): bool {.inline, ...raises: [], tags: [].}

  Source Edit

    proc sameFlags(a, b: PType): bool {.inline, ...raises: [], tags: [].}

  Source Edit

    proc sameObjectTypes(a, b: PType): bool {....raises: [Exception],
        tags: [RootEffect].}

  Source Edit

    proc sameType(a, b: PType; flags: TTypeCmpFlags = {}): bool {.
        ...raises: [Exception], tags: [RootEffect].}

  Source Edit

    proc sameTypeOrNil(a, b: PType; flags: TTypeCmpFlags = {}): bool {.
        ...raises: [Exception], tags: [RootEffect].}

  Source Edit

    proc searchTypeFor(t: PType; predicate: TTypePredicate): bool {.
        ...raises: [Exception], tags: [RootEffect].}

  Source Edit

    proc skipConv(n: PNode): PNode {....raises: [], tags: [].}

  Source Edit

    proc skipConvTakeType(n: PNode): PNode {....raises: [], tags: [].}

  Source Edit

    proc skipGenericAlias(t: PType): PType {....raises: [], tags: [].}

  Source Edit

    proc skipHidden(n: PNode): PNode {....raises: [], tags: [].}

  Source Edit

    proc skipHiddenSubConv(n: PNode; g: ModuleGraph; idgen: IdGenerator): PNode {.
        ...raises: [KeyError], tags: [].}

  Source Edit

    proc takeType(formal, arg: PType; g: ModuleGraph; idgen: IdGenerator): PType {.
        ...raises: [], tags: [].}

  Source Edit

    proc typeMismatch(conf: ConfigRef; info: TLineInfo; formal, actual: PType;
                      n: PNode) {....raises: [Exception, KeyError, ValueError, OSError,
                                           IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc typeToString(typ: PType; prefer: TPreferedDesc = preferName): string {.
        ...raises: [Exception, KeyError, ValueError], tags: [RootEffect].}

  Source Edit

# Templates

    template `$`(typ: PType): string

  Source Edit

    template bindConcreteTypeToUserTypeClass(tc, concrete: PType)

  Source Edit

    template foldAlignOf(conf: ConfigRef; n: PNode; fallback: PNode): PNode

  Source Edit

    template foldOffsetOf(conf: ConfigRef; n: PNode; fallback: PNode): PNode

  Returns an int literal node of the given offsetof expression in `n`. Falls back to `fallback`, if the `offsetof` expression can't be processed. Source Edit

    template foldSizeOf(conf: ConfigRef; n: PNode; fallback: PNode): PNode

  Source Edit

    template isResolvedUserTypeClass(t: PType): bool

  Source Edit