# types

Theme:

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

# Types

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

  Source Edit

    OffsetAccum = object
      maxAlign*: int32
      offset*: int32

  Source Edit

    OrdinalType = enum
      NoneLike, IntLike, FloatLike

  Source Edit

    ProcConvMismatch = enum
      pcmNoSideEffect, pcmNotGcSafe, 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, preferInlayHint,
      preferInferredEffects

  Source Edit

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

  Source Edit

    TTypeCmpFlags = set[TTypeCmpFlag]

  Source Edit

    TTypeFieldResult = enum
      frNone, frHeader, frEmbedded

  Source Edit

    TTypeIter = proc (t: PType; closure: RootRef): bool {.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

    arrPutGetMagicApplies = {tyArray, tyOpenArray, tyString, tySequence, tyCstring,
                             tyTuple}

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

  Source Edit

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

  Source Edit

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

  Source Edit

    proc align(arg: var OffsetAccum; value: int32) {.
        ...raises: [IllegalTypeRecursionError], tags: [], forbids: [].}

  Source Edit

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

  Source Edit

    proc baseOfDistinct(t: PType; g: ModuleGraph; idgen: IdGenerator): PType {.
        ...raises: [KeyError, ValueError, OSError, Exception],
        tags: [ReadDirEffect, RootEffect], forbids: [].}

  Source Edit

    proc canFormAcycle(g: ModuleGraph; typ: PType): bool {.
        ...raises: [Exception, KeyError, ValueError, OSError],
        tags: [RootEffect, ReadDirEffect], forbids: [].}

  Source Edit

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

  for convenient type checking: Source Edit

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

  Source Edit

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

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

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

    proc genericAliasDepth(t: PType): int {....raises: [], tags: [], forbids: [].}

  Source Edit

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

  gets the root generic type (`tyGenericBody`) from `t`, if `t` is a generic type or the body of a generic instantiation Source Edit

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

  Source Edit

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

  Source Edit

    proc getOrdValue(n: PNode): Int128 {....raises: [], tags: [], forbids: [].}

  Source Edit

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

  Source Edit

    proc getOrdValueAux(n: PNode; err: var bool): Int128 {....raises: [], tags: [],
        forbids: [].}

  Source Edit

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

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

  Source Edit

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

  Source Edit

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

  Source Edit

    proc inc(arg: var OffsetAccum; value: int32) {.
        ...raises: [IllegalTypeRecursionError], tags: [], forbids: [].}

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Returns true if the type is an object that lacks a type field. Object types that store type headers are not final or pure and have inheritable root types, which are not pure, neither. Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Returns true if the type is an object that lacks a m_type field. It doesn't check base classes. Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  the "name" type of a given instance of a nominal type, i.e. the type directly associated with the symbol where the root nominal type of `t` was defined, skipping things like generic instances, aliases, `var`/`sink`/`typedesc` modifiers

  instead of returning the uninstantiated body of a generic type, returns the type of the symbol instead (with tyGenericBody type)

  Source Edit

    proc normalizeKind(conf: ConfigRef; k: TTypeKind): TTypeKind {....raises: [],
        tags: [], forbids: [].}

  Source Edit

    proc reduceToBase(f: PType): PType {....raises: [], tags: [], forbids: [].}

  Source Edit

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

  Source Edit

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

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

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

    proc setImportedTypeSize(conf: ConfigRef; t: PType; size: int) {....raises: [],
        tags: [], forbids: [].}

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

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

  Source Edit

    proc skipHiddenSubConv(n: PNode; g: ModuleGraph; idgen: IdGenerator): PNode {.
        ...raises: [KeyError, ValueError, OSError, Exception],
        tags: [ReadDirEffect, RootEffect], forbids: [].}

  Source Edit

    proc takeType(formal, arg: PType; g: ModuleGraph; idgen: IdGenerator): PType {.
        ...raises: [KeyError, ValueError, OSError, Exception],
        tags: [ReadDirEffect, RootEffect], forbids: [].}

  Source Edit

    proc targetSizeSignedToKind(conf: ConfigRef): TTypeKind {....raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc targetSizeUnsignedToKind(conf: ConfigRef): TTypeKind {....raises: [],
        tags: [], forbids: [].}

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

  Source Edit

    proc typeNameAndDesc(t: PType): string {.
        ...raises: [Exception, KeyError, ValueError], tags: [RootEffect], forbids: [].}

  Source Edit

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

  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