compiler/ast/types

    Dark Mode
Search:
  Source   Edit

this module contains routines for accessing and iterating over typescode owner: Arne Döring e-mail: arne.doering@gmx.net included from types.nim

Types

BackendViewKind = enum
  bvcNone,                  ## no view
  bvcSingle,                ## single-location view
  bvcSequence                ## view of contiguous locations
  Source   Edit
OrdinalType = enum
  NoneLike, IntLike, FloatLike
  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
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
ViewTypeKind = enum
  noView, immutableView, mutableView
  Source   Edit

Procs

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: [KeyError, Exception], tags: [ReadDirEffect, RootEffect].}
  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 classifyBackendView(t: PType): BackendViewKind {....raises: [], tags: [].}
For the resolved type t, computes and returns what kind of view the type represents. This is meant to be used during the backend phase.   Source   Edit
proc classifyViewType(t: PType): ViewTypeKind {....raises: [Exception],
    tags: [RootEffect].}
  Source   Edit
proc commonSuperclass(a, b: PType): PType {....raises: [], tags: [].}
  Source   Edit
proc compareTypes(x, y: PType; cmp: TDistinctCompare = dcEq;
                  flags: TTypeCmpFlags = {}): bool {.
    ...raises: [Exception, ERecoverableError], tags: [RootEffect].}
compares two type for equality (modulo type distinction)   Source   Edit
proc compatibleEffects(formal, actual: PType): EffectsCompat {....raises: [],
    tags: [].}
  Source   Edit
proc computeSize(conf: ConfigRef; typ: PType): BiggestInt {.
    ...raises: [Exception, ERecoverableError], tags: [RootEffect].}
  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 directViewType(t: PType): ViewTypeKind {....raises: [], tags: [].}
  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],
    tags: [RootEffect].}
  Source   Edit
proc firstFloat(t: PType): BiggestFloat {....raises: [], tags: [].}
  Source   Edit
proc firstOrd(conf: ConfigRef; t: PType): Int128 {....raises: [], tags: [].}
computes the first ordinal value of a concrete type, taking into account:
  • int bit-width via the conf param (a nil conf assumes 64 bits)
  • the ordinal value set of the first enum element
  Source   Edit
proc floatRangeCheck(x: BiggestFloat; t: PType): bool {....raises: [], tags: [].}
  Source   Edit
proc getAlign(conf: ConfigRef; typ: PType): BiggestInt {.
    ...raises: [Exception, ERecoverableError], tags: [RootEffect].}
  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 getReturnType(s: PSym): PType {....raises: [], tags: [].}
  Source   Edit
proc getSize(conf: ConfigRef; typ: PType): BiggestInt {.
    ...raises: [Exception, ERecoverableError], tags: [RootEffect].}
  Source   Edit
proc inheritanceDiff(a, b: PType): int {....raises: [], tags: [].}
  Source   Edit
proc invalidGenericInst(f: PType): bool {....raises: [], tags: [].}
  Source   Edit
proc isCharArrayPtr(t: PType; allowPointerToChar: bool): bool {....raises: [],
    tags: [].}
  Source   Edit
proc isCompileTimeOnly(t: PType): bool {.inline, ...raises: [], tags: [].}
  Source   Edit
proc isCyclePossible(typ: PType; g: ModuleGraph): bool {.
    ...raises: [Exception, ERecoverableError, KeyError],
    tags: [RootEffect, ReadDirEffect].}

Analyses and returns whether typ can possibly be the root of a reference cycle, or in other words, whether a heap cell of type typ can keep itself alive.

The analysis is conservative: if a location of typ can have shared ownership (ref or closure) of a heap location with a dynamic type that might not match the static one (i.e. a polymorphic ref or closure, the latter uses type erasure), typ is treated as possibly cyclic.

  Source   Edit
proc isDefectException(t: PType): bool {....raises: [], tags: [].}
  Source   Edit
proc isEmptyContainer(t: PType): bool {....raises: [], tags: [].}
true if the type is considered a container and is empty, otherwise false. container types are untyped, nil, array/seq/set/etc[T] with an emtpy type for T.   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 isImportedException(t: PType; conf: ConfigRef): bool {....raises: [], tags: [].}
true of the Exception described by type t was imported   Source   Edit
proc isIntLit(t: PType): bool {.inline, ...raises: [], tags: [].}
  Source   Edit
proc isObjLackingTypeField(typ: PType): bool {.inline, ...raises: [], tags: [].}
Tests if typ has no type field (header). The only types that store a type header are non-final object types where the inheritance root is not marked as .pure (the sfPure flags is not present on it)   Source   Edit
proc isOrdinalType(t: PType; allowEnumWithHoles: bool = false): bool {.
    ...raises: [], tags: [].}
  Source   Edit
proc isPassByRef(conf: ConfigRef; s: PSym; retType: PType): bool {.
    ...raises: [Exception, ERecoverableError], tags: [RootEffect].}
  Source   Edit
proc isPureObject(typ: PType): bool {....raises: [], tags: [].}
  Source   Edit
proc isSinkTypeForParam(t: PType): bool {....raises: [], tags: [].}
Returns whether t is considered to be a sink-like type when used in a parameter context.   Source   Edit
proc isTupleRecursive(t: PType): bool {....raises: [], tags: [].}
  Source   Edit
func isUnsigned(t: PType): bool {.inline, ...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: [].}
Tests if typ has a type field itself . Doesn't consider base types   Source   Edit
proc lastFloat(t: PType): BiggestFloat {....raises: [], tags: [].}
  Source   Edit
proc lastOrd(conf: ConfigRef; t: PType): Int128 {....raises: [], tags: [].}
computes the last ordinal value of a concrete type, taking into account:
  • int bit-width via the conf param (a nil conf assumes 64 bits)
  • the ordinal value set of the last enum element
  Source   Edit
proc lengthOrd(conf: ConfigRef; t: PType): Int128 {....raises: [], tags: [].}
Computes the length, or rather cardinality, of concrete ordinal type (including distincts with ordinal type bases). The cardinality of a type is the total number of possible values that may represent by it.   Source   Edit
proc lookupFieldAgain(ty: PType; field: PSym): PSym {....raises: [], tags: [].}
  Source   Edit
proc lookupInType(ty: PType; position: int): PSym {....raises: [], tags: [].}
Looks up and returns the field with the given position in ty. Returns nil if there's no such field. ty is expected to be a fully resolved object or ref object/ptr object type.   Source   Edit
proc matchType(a: PType; pattern: openArray[tuple[k: TTypeKind, i: int]];
               last: TTypeKind): bool {....raises: [], tags: [].}
  Source   Edit
proc mutableSkipConv(n: var PNode): var PNode {....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: [], tags: [].}
  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: [Exception, ERecoverableError], tags: [RootEffect].}
  Source   Edit
proc sameDistinctTypes(a, b: PType): bool {.inline, ...raises: [], tags: [].}
  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 sameLocationType(x, y: PType): bool {.
    ...raises: [Exception, ERecoverableError], tags: [RootEffect].}
Tests and returns whether x and y are the same when used as the type for locations   Source   Edit
proc sameObjectTypes(a, b: PType): bool {....raises: [], tags: [].}
  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 searchTypeNodeFor(n: PNode; predicate: TTypePredicate): bool {.
    ...raises: [Exception], tags: [RootEffect].}
  Source   Edit
proc semDiagTypeMismatch(node: PNode; expected: set[TTypeKind]; received: PType): PAstDiag {.
    ...raises: [], tags: [].}
  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 skipToObject(t: PType; numIndirectsAllowed = 1): PType {.inline,
    ...raises: [], tags: [].}

Tries to skip to the underlying tyObject of a type that is used as an object's base type. Unresolved generic invocations are traversed in simple cases. Either the tyObject type or the first encountered type that couldn't be traversed is returned.

numIndirectsAllowed specifies the number of ptr and ref types to skip before bailing out.

  Source   Edit
proc typeMismatch(conf: ConfigRef; info: TLineInfo; formal, actual: PType;
                  n: PNode): PNode {....raises: [], tags: [].}
If formal and actual types are not tyError, create a new wrapper nkError node and construct type mismatch report for it.   Source   Edit
proc typeMismatch(formal, actual: PType): SemTypeMismatch {....raises: [], tags: [].}
  Source   Edit
proc typeMismatch(formal: set[TTypeKind]; actual: PType): SemTypeMismatch {.
    ...raises: [], tags: [].}
  Source   Edit

Templates

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