summary refs log tree commit diff stats
path: root/compiler/nir
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2023-12-12 16:54:50 +0100
committerGitHub <noreply@github.com>2023-12-12 16:54:50 +0100
commitdb603237c648a796ef7bff77641febd30b3999cd (patch)
tree13e693ac432b1542cab7f2b2bbe1b8c11ca258e0 /compiler/nir
parent8cc3c774c8925c3d21626d09b41ad352bd898e4a (diff)
downloadNim-db603237c648a796ef7bff77641febd30b3999cd.tar.gz
Types: Refactorings; step 1 (#23055)
Diffstat (limited to 'compiler/nir')
-rw-r--r--compiler/nir/ast2ir.nim16
-rw-r--r--compiler/nir/types2ir.nim22
2 files changed, 19 insertions, 19 deletions
diff --git a/compiler/nir/ast2ir.nim b/compiler/nir/ast2ir.nim
index 51dfcdb09..1730181f3 100644
--- a/compiler/nir/ast2ir.nim
+++ b/compiler/nir/ast2ir.nim
@@ -586,7 +586,7 @@ proc genIndex(c: var ProcCon; n: PNode; arr: PType; d: var Value) =
 
 proc rawGenNew(c: var ProcCon; d: Value; refType: PType; ninfo: TLineInfo; needsInit: bool) =
   assert refType.kind == tyRef
-  let baseType = refType.lastSon
+  let baseType = refType.elementType
 
   let info = toLineInfo(c, ninfo)
   let codegenProc = magicsys.getCompilerProc(c.m.graph,
@@ -611,7 +611,7 @@ proc genNew(c: var ProcCon; n: PNode; needsInit: bool) =
 proc genNewSeqOfCap(c: var ProcCon; n: PNode; d: var Value) =
   let info = toLineInfo(c, n.info)
   let seqtype = skipTypes(n.typ, abstractVarRange)
-  let baseType = seqtype.lastSon
+  let baseType = seqtype.elementType
   var a = c.genx(n[1])
   if isEmpty(d): d = getTemp(c, n)
   # $1.len = 0
@@ -639,7 +639,7 @@ proc genNewSeqOfCap(c: var ProcCon; n: PNode; d: var Value) =
   freeTemp c, a
 
 proc genNewSeqPayload(c: var ProcCon; info: PackedLineInfo; d, b: Value; seqtype: PType) =
-  let baseType = seqtype.lastSon
+  let baseType = seqtype.elementType
   # $1.p = ($4*) #newSeqPayload($2, sizeof($3), NIM_ALIGNOF($3))
   let payloadPtr = seqPayloadPtrType(c.m.types, c.m.nirm.types, seqtype)[0]
 
@@ -1597,7 +1597,7 @@ proc genDestroySeq(c: var ProcCon; n: PNode; t: PType) =
   let strLitFlag = 1 shl (c.m.graph.config.target.intSize * 8 - 2) # see also NIM_STRLIT_FLAG
 
   let x = c.genx(n[1])
-  let baseType = t.lastSon
+  let baseType = t.elementType
 
   let seqType = typeToIr(c.m, t)
   let p = fieldAt(x, 0, seqType)
@@ -1655,7 +1655,7 @@ proc genIndexCheck(c: var ProcCon; n: PNode; a: Value; kind: IndexFor; arr: PTyp
 
 proc addSliceFields(c: var ProcCon; target: var Tree; info: PackedLineInfo;
                     x: Value; n: PNode; arrType: PType) =
-  let elemType = arrayPtrTypeOf(c.m.nirm.types, typeToIr(c.m, arrType.lastSon))
+  let elemType = arrayPtrTypeOf(c.m.nirm.types, typeToIr(c.m, arrType.elementType))
   case arrType.kind
   of tyString, tySequence:
     let checkKind = if arrType.kind == tyString: ForStr else: ForSeq
@@ -1970,7 +1970,7 @@ proc genDeref(c: var ProcCon; n: PNode; d: var Value; flags: GenFlags) =
 
 proc addAddrOfFirstElem(c: var ProcCon; target: var Tree; info: PackedLineInfo; tmp: Value; typ: PType) =
   let arrType = typ.skipTypes(abstractVar)
-  let elemType = arrayPtrTypeOf(c.m.nirm.types, typeToIr(c.m, arrType.lastSon))
+  let elemType = arrayPtrTypeOf(c.m.nirm.types, typeToIr(c.m, arrType.elementType))
   case arrType.kind
   of tyString:
     let t = typeToIr(c.m, typ)
@@ -2079,7 +2079,7 @@ proc genRefObjConstr(c: var ProcCon; n: PNode; d: var Value) =
   if isEmpty(d): d = getTemp(c, n)
   let info = toLineInfo(c, n.info)
   let refType = n.typ.skipTypes(abstractInstOwned)
-  let objType = refType.lastSon
+  let objType = refType.elementType
 
   rawGenNew(c, d, refType, n.info, needsInit = nfAllFieldsSet notin n.flags)
   var deref = default(Value)
@@ -2092,7 +2092,7 @@ proc genSeqConstr(c: var ProcCon; n: PNode; d: var Value) =
 
   let info = toLineInfo(c, n.info)
   let seqtype = skipTypes(n.typ, abstractVarRange)
-  let baseType = seqtype.lastSon
+  let baseType = seqtype.elementType
 
   var b = default(Value)
   b.addIntVal c.lit.numbers, info, c.m.nativeIntId, n.len
diff --git a/compiler/nir/types2ir.nim b/compiler/nir/types2ir.nim
index 9c9513284..aa8bcc12f 100644
--- a/compiler/nir/types2ir.nim
+++ b/compiler/nir/types2ir.nim
@@ -171,7 +171,7 @@ proc nativeInt(c: TypesCon): TypeId =
   else: result = Int64Id
 
 proc openArrayPayloadType*(c: var TypesCon; g: var TypeGraph; t: PType): TypeId =
-  let e = lastSon(t)
+  let e = elementType(t)
   let elementType = typeToIr(c, g, e)
   let arr = g.openType AArrayPtrTy
   g.addType elementType
@@ -179,7 +179,7 @@ proc openArrayPayloadType*(c: var TypesCon; g: var TypeGraph; t: PType): TypeId
 
 proc openArrayToIr(c: var TypesCon; g: var TypeGraph; t: PType): TypeId =
   # object (a: ArrayPtr[T], len: int)
-  let e = lastSon(t)
+  let e = elementType(t)
   let mangledBase = mangle(c, e)
   let typeName = "NimOpenArray" & mangledBase
 
@@ -265,7 +265,7 @@ proc seqPayloadType(c: var TypesCon; g: var TypeGraph; t: PType): (string, TypeI
       cap: int
       data: UncheckedArray[T]
   ]#
-  let e = lastSon(t)
+  let e = elementType(t)
   result = (mangle(c, e), TypeId(-1))
   let payloadName = "NimSeqPayload" & result[0]
 
@@ -397,7 +397,7 @@ proc typeToIr*(c: var TypesCon; g: var TypeGraph; t: PType): TypeId =
   of tyChar: result = Char8Id
   of tyVoid: result = VoidId
   of tySink, tyGenericInst, tyDistinct, tyAlias, tyOwned, tyRange:
-    result = typeToIr(c, g, t.lastSon)
+    result = typeToIr(c, g, t.skipModifier)
   of tyEnum:
     if firstOrd(c.conf, t) < 0:
       result = Int32Id
@@ -410,7 +410,7 @@ proc typeToIr*(c: var TypesCon; g: var TypeGraph; t: PType): TypeId =
       else: result = Int32Id
   of tyOrdinal, tyGenericBody, tyGenericParam, tyInferred, tyStatic:
     if t.len > 0:
-      result = typeToIr(c, g, t.lastSon)
+      result = typeToIr(c, g, t.skipModifier)
     else:
       result = TypeId(-1)
   of tyFromExpr:
@@ -422,7 +422,7 @@ proc typeToIr*(c: var TypesCon; g: var TypeGraph; t: PType): TypeId =
     cached(c, t):
       var n = toInt64(lengthOrd(c.conf, t))
       if n <= 0: n = 1   # make an array of at least one element
-      let elemType = typeToIr(c, g, t[1])
+      let elemType = typeToIr(c, g, t.elementType)
       let a = openType(g, ArrayTy)
       g.addType(elemType)
       g.addArrayLen n
@@ -430,20 +430,20 @@ proc typeToIr*(c: var TypesCon; g: var TypeGraph; t: PType): TypeId =
       result = finishType(g, a)
   of tyPtr, tyRef:
     cached(c, t):
-      let e = t.lastSon
+      let e = t.elementType
       if e.kind == tyUncheckedArray:
-        let elemType = typeToIr(c, g, e.lastSon)
+        let elemType = typeToIr(c, g, e.elementType)
         let a = openType(g, AArrayPtrTy)
         g.addType(elemType)
         result = finishType(g, a)
       else:
-        let elemType = typeToIr(c, g, t.lastSon)
+        let elemType = typeToIr(c, g, t.elementType)
         let a = openType(g, APtrTy)
         g.addType(elemType)
         result = finishType(g, a)
   of tyVar, tyLent:
     cached(c, t):
-      let e = t.lastSon
+      let e = t.elementType
       if e.skipTypes(abstractInst).kind in {tyOpenArray, tyVarargs}:
         # skip the modifier, `var openArray` is a (ptr, len) pair too:
         result = typeToIr(c, g, e)
@@ -510,7 +510,7 @@ proc typeToIr*(c: var TypesCon; g: var TypeGraph; t: PType): TypeId =
   of tyUncheckedArray:
     # We already handled the `ptr UncheckedArray` in a special way.
     cached(c, t):
-      let elemType = typeToIr(c, g, t.lastSon)
+      let elemType = typeToIr(c, g, t.elementType)
       let a = openType(g, LastArrayTy)
       g.addType(elemType)
       result = finishType(g, a)