code cleanup: there is no tyOptRef
This commit is contained in:
parent
15c208cd29
commit
721bf7188b
14 changed files with 36 additions and 47 deletions
|
|
@ -365,7 +365,7 @@ type
|
||||||
tyInt, tyInt8, tyInt16, tyInt32, tyInt64, # signed integers
|
tyInt, tyInt8, tyInt16, tyInt32, tyInt64, # signed integers
|
||||||
tyFloat, tyFloat32, tyFloat64, tyFloat128,
|
tyFloat, tyFloat32, tyFloat64, tyFloat128,
|
||||||
tyUInt, tyUInt8, tyUInt16, tyUInt32, tyUInt64,
|
tyUInt, tyUInt8, tyUInt16, tyUInt32, tyUInt64,
|
||||||
tyOptAsRef, tySink, tyLent,
|
tyOwned, tySink, tyLent,
|
||||||
tyVarargs,
|
tyVarargs,
|
||||||
tyUncheckedArray
|
tyUncheckedArray
|
||||||
# An array with boundaries [0,+∞]
|
# An array with boundaries [0,+∞]
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,8 @@ proc scopeMangledParam(p: BProc; param: PSym) =
|
||||||
|
|
||||||
const
|
const
|
||||||
irrelevantForBackend = {tyGenericBody, tyGenericInst, tyGenericInvocation,
|
irrelevantForBackend = {tyGenericBody, tyGenericInst, tyGenericInvocation,
|
||||||
tyDistinct, tyRange, tyStatic, tyAlias, tySink, tyInferred}
|
tyDistinct, tyRange, tyStatic, tyAlias, tySink,
|
||||||
|
tyInferred, tyOwned}
|
||||||
|
|
||||||
proc typeName(typ: PType): Rope =
|
proc typeName(typ: PType): Rope =
|
||||||
let typ = typ.skipTypes(irrelevantForBackend)
|
let typ = typ.skipTypes(irrelevantForBackend)
|
||||||
|
|
@ -145,7 +146,7 @@ proc mapType(conf: ConfigRef; typ: PType): TCTypeKind =
|
||||||
doAssert typ.isResolvedUserTypeClass
|
doAssert typ.isResolvedUserTypeClass
|
||||||
return mapType(conf, typ.lastSon)
|
return mapType(conf, typ.lastSon)
|
||||||
of tyGenericBody, tyGenericInst, tyGenericParam, tyDistinct, tyOrdinal,
|
of tyGenericBody, tyGenericInst, tyGenericParam, tyDistinct, tyOrdinal,
|
||||||
tyTypeDesc, tyAlias, tySink, tyInferred:
|
tyTypeDesc, tyAlias, tySink, tyInferred, tyOwned:
|
||||||
result = mapType(conf, lastSon(typ))
|
result = mapType(conf, lastSon(typ))
|
||||||
of tyEnum:
|
of tyEnum:
|
||||||
if firstOrd(conf, typ) < 0:
|
if firstOrd(conf, typ) < 0:
|
||||||
|
|
@ -158,7 +159,7 @@ proc mapType(conf: ConfigRef; typ: PType): TCTypeKind =
|
||||||
of 8: result = ctInt64
|
of 8: result = ctInt64
|
||||||
else: result = ctInt32
|
else: result = ctInt32
|
||||||
of tyRange: result = mapType(conf, typ.sons[0])
|
of tyRange: result = mapType(conf, typ.sons[0])
|
||||||
of tyPtr, tyVar, tyLent, tyRef, tyOptAsRef:
|
of tyPtr, tyVar, tyLent, tyRef:
|
||||||
var base = skipTypes(typ.lastSon, typedescInst)
|
var base = skipTypes(typ.lastSon, typedescInst)
|
||||||
case base.kind
|
case base.kind
|
||||||
of tyOpenArray, tyArray, tyVarargs, tyUncheckedArray: result = ctPtrToArray
|
of tyOpenArray, tyArray, tyVarargs, tyUncheckedArray: result = ctPtrToArray
|
||||||
|
|
@ -633,7 +634,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
|
||||||
excl(check, t.id)
|
excl(check, t.id)
|
||||||
return
|
return
|
||||||
case t.kind
|
case t.kind
|
||||||
of tyRef, tyOptAsRef, tyPtr, tyVar, tyLent:
|
of tyRef, tyPtr, tyVar, tyLent:
|
||||||
var star = if t.kind == tyVar and tfVarIsPtr notin origTyp.flags and
|
var star = if t.kind == tyVar and tfVarIsPtr notin origTyp.flags and
|
||||||
compileToCpp(m): "&" else: "*"
|
compileToCpp(m): "&" else: "*"
|
||||||
var et = origTyp.skipTypes(abstractInst).lastSon
|
var et = origTyp.skipTypes(abstractInst).lastSon
|
||||||
|
|
@ -844,7 +845,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
|
||||||
of 1, 2, 4, 8: addf(m.s[cfsTypes], "typedef NU$2 $1;$n", [result, rope(s*8)])
|
of 1, 2, 4, 8: addf(m.s[cfsTypes], "typedef NU$2 $1;$n", [result, rope(s*8)])
|
||||||
else: addf(m.s[cfsTypes], "typedef NU8 $1[$2];$n",
|
else: addf(m.s[cfsTypes], "typedef NU8 $1[$2];$n",
|
||||||
[result, rope(getSize(m.config, t))])
|
[result, rope(getSize(m.config, t))])
|
||||||
of tyGenericInst, tyDistinct, tyOrdinal, tyTypeDesc, tyAlias, tySink,
|
of tyGenericInst, tyDistinct, tyOrdinal, tyTypeDesc, tyAlias, tySink, tyOwned,
|
||||||
tyUserTypeClass, tyUserTypeClassInst, tyInferred:
|
tyUserTypeClass, tyUserTypeClassInst, tyInferred:
|
||||||
result = getTypeDescAux(m, lastSon(t), check)
|
result = getTypeDescAux(m, lastSon(t), check)
|
||||||
else:
|
else:
|
||||||
|
|
@ -1219,7 +1220,7 @@ proc genTypeInfo(m: BModule, t: PType; info: TLineInfo): Rope =
|
||||||
if m.config.selectedGC >= gcMarkAndSweep:
|
if m.config.selectedGC >= gcMarkAndSweep:
|
||||||
let markerProc = genTraverseProc(m, origType, sig)
|
let markerProc = genTraverseProc(m, origType, sig)
|
||||||
addf(m.s[cfsTypeInit3], "$1.marker = $2;$n", [result, markerProc])
|
addf(m.s[cfsTypeInit3], "$1.marker = $2;$n", [result, markerProc])
|
||||||
of tyRef, tyOptAsRef:
|
of tyRef:
|
||||||
genTypeInfoAux(m, t, t, result, info)
|
genTypeInfoAux(m, t, t, result, info)
|
||||||
if m.config.selectedGC >= gcMarkAndSweep:
|
if m.config.selectedGC >= gcMarkAndSweep:
|
||||||
let markerProc = genTraverseProc(m, origType, sig)
|
let markerProc = genTraverseProc(m, origType, sig)
|
||||||
|
|
|
||||||
|
|
@ -194,14 +194,13 @@ proc mapType(typ: PType): TJSTypeKind =
|
||||||
tyAnd, tyOr, tyNot, tyAnything, tyVoid:
|
tyAnd, tyOr, tyNot, tyAnything, tyVoid:
|
||||||
result = etyNone
|
result = etyNone
|
||||||
of tyGenericInst, tyInferred, tyAlias, tyUserTypeClass, tyUserTypeClassInst,
|
of tyGenericInst, tyInferred, tyAlias, tyUserTypeClass, tyUserTypeClassInst,
|
||||||
tySink:
|
tySink, tyOwned:
|
||||||
result = mapType(typ.lastSon)
|
result = mapType(typ.lastSon)
|
||||||
of tyStatic:
|
of tyStatic:
|
||||||
if t.n != nil: result = mapType(lastSon t)
|
if t.n != nil: result = mapType(lastSon t)
|
||||||
else: result = etyNone
|
else: result = etyNone
|
||||||
of tyProc: result = etyProc
|
of tyProc: result = etyProc
|
||||||
of tyCString: result = etyString
|
of tyCString: result = etyString
|
||||||
of tyOptAsRef: doAssert(false, "mapType")
|
|
||||||
|
|
||||||
proc mapType(p: PProc; typ: PType): TJSTypeKind =
|
proc mapType(p: PProc; typ: PType): TJSTypeKind =
|
||||||
result = mapType(typ)
|
result = mapType(typ)
|
||||||
|
|
|
||||||
|
|
@ -269,9 +269,8 @@ proc liftBodyAux(c: var TLiftCtx; t: PType; body, x, y: PNode) =
|
||||||
tyTypeDesc, tyGenericInvocation, tyForward:
|
tyTypeDesc, tyGenericInvocation, tyForward:
|
||||||
internalError(c.graph.config, c.info, "assignment requested for type: " & typeToString(t))
|
internalError(c.graph.config, c.info, "assignment requested for type: " & typeToString(t))
|
||||||
of tyOrdinal, tyRange, tyInferred,
|
of tyOrdinal, tyRange, tyInferred,
|
||||||
tyGenericInst, tyStatic, tyVar, tyLent, tyAlias, tySink:
|
tyGenericInst, tyStatic, tyVar, tyLent, tyAlias, tySink, tyOwned:
|
||||||
liftBodyAux(c, lastSon(t), body, x, y)
|
liftBodyAux(c, lastSon(t), body, x, y)
|
||||||
of tyOptAsRef: internalError(c.graph.config, "liftBodyAux")
|
|
||||||
|
|
||||||
proc newProcType(info: TLineInfo; owner: PSym): PType =
|
proc newProcType(info: TLineInfo; owner: PSym): PType =
|
||||||
result = newType(tyProc, owner)
|
result = newType(tyProc, owner)
|
||||||
|
|
|
||||||
|
|
@ -1854,6 +1854,7 @@ proc processMagicType(c: PContext, m: PSym) =
|
||||||
case m.name.s
|
case m.name.s
|
||||||
of "lent": setMagicType(c.config, m, tyLent, c.config.target.ptrSize)
|
of "lent": setMagicType(c.config, m, tyLent, c.config.target.ptrSize)
|
||||||
of "sink": setMagicType(c.config, m, tySink, szUncomputedSize)
|
of "sink": setMagicType(c.config, m, tySink, szUncomputedSize)
|
||||||
|
of "owned": setMagicType(c.config, m, tyOwned, c.config.target.ptrSize)
|
||||||
else: localError(c.config, m.info, errTypeExpected)
|
else: localError(c.config, m.info, errTypeExpected)
|
||||||
else: localError(c.config, m.info, errTypeExpected)
|
else: localError(c.config, m.info, errTypeExpected)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1054,7 +1054,7 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
|
||||||
result = a.sym.position == b.sym.position
|
result = a.sym.position == b.sym.position
|
||||||
of tyGenericInvocation, tyGenericBody, tySequence,
|
of tyGenericInvocation, tyGenericBody, tySequence,
|
||||||
tyOpenArray, tySet, tyRef, tyPtr, tyVar, tyLent, tySink, tyUncheckedArray,
|
tyOpenArray, tySet, tyRef, tyPtr, tyVar, tyLent, tySink, tyUncheckedArray,
|
||||||
tyArray, tyProc, tyVarargs, tyOrdinal, tyTypeClasses, tyOpt:
|
tyArray, tyProc, tyVarargs, tyOrdinal, tyTypeClasses, tyOpt, tyOwned:
|
||||||
cycleCheck()
|
cycleCheck()
|
||||||
if a.kind == tyUserTypeClass and a.n != nil: return a.n == b.n
|
if a.kind == tyUserTypeClass and a.n != nil: return a.n == b.n
|
||||||
result = sameChildrenAux(a, b, c)
|
result = sameChildrenAux(a, b, c)
|
||||||
|
|
@ -1077,7 +1077,6 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
|
||||||
cycleCheck()
|
cycleCheck()
|
||||||
result = sameTypeAux(a.lastSon, b.lastSon, c)
|
result = sameTypeAux(a.lastSon, b.lastSon, c)
|
||||||
of tyNone: result = false
|
of tyNone: result = false
|
||||||
of tyOptAsRef: result = false
|
|
||||||
|
|
||||||
proc sameBackendType*(x, y: PType): bool =
|
proc sameBackendType*(x, y: PType): bool =
|
||||||
var c = initSameTypeClosure()
|
var c = initSameTypeClosure()
|
||||||
|
|
@ -1275,7 +1274,11 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
|
||||||
# for now same as error node; we say it's a valid type as it should
|
# for now same as error node; we say it's a valid type as it should
|
||||||
# prevent cascading errors:
|
# prevent cascading errors:
|
||||||
result = nil
|
result = nil
|
||||||
of tyOptAsRef: result = t
|
of tyOwned:
|
||||||
|
if t.len == 1 and t.sons[0].kind in {tyRef, tyPtr}:
|
||||||
|
result = typeAllowedAux(marker, t.lastSon, skVar, flags+{taHeap})
|
||||||
|
else:
|
||||||
|
result = t
|
||||||
|
|
||||||
proc typeAllowed*(t: PType, kind: TSymKind; flags: TTypeAllowedFlags = {}): PType =
|
proc typeAllowed*(t: PType, kind: TSymKind; flags: TTypeAllowedFlags = {}): PType =
|
||||||
# returns 'nil' on success and otherwise the part of the type that is
|
# returns 'nil' on success and otherwise the part of the type that is
|
||||||
|
|
|
||||||
|
|
@ -294,7 +294,7 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
|
||||||
result.add atomicType("static", mNone)
|
result.add atomicType("static", mNone)
|
||||||
if t.n != nil:
|
if t.n != nil:
|
||||||
result.add t.n.copyTree
|
result.add t.n.copyTree
|
||||||
of tyOptAsRef: assert(false, "mapTypeToAstX")
|
of tyOwned: result = mapTypeToBracket("owned", mBuiltinType, t, info)
|
||||||
|
|
||||||
proc opMapTypeToAst*(cache: IdentCache; t: PType; info: TLineInfo): PNode =
|
proc opMapTypeToAst*(cache: IdentCache; t: PType; info: TLineInfo): PNode =
|
||||||
result = mapTypeToAstX(cache, t, info, inst=false, allowRecursionX=true)
|
result = mapTypeToAstX(cache, t, info, inst=false, allowRecursionX=true)
|
||||||
|
|
|
||||||
|
|
@ -104,19 +104,6 @@ proc genericAssignAux(dest, src: pointer, mt: PNimType, shallow: bool) =
|
||||||
cast[pointer](s +% i *% mt.base.size), mt.base, shallow)
|
cast[pointer](s +% i *% mt.base.size), mt.base, shallow)
|
||||||
of tyRef:
|
of tyRef:
|
||||||
unsureAsgnRef(cast[PPointer](dest), cast[PPointer](s)[])
|
unsureAsgnRef(cast[PPointer](dest), cast[PPointer](s)[])
|
||||||
of tyOptAsRef:
|
|
||||||
let s2 = cast[PPointer](src)[]
|
|
||||||
let d = cast[PPointer](dest)
|
|
||||||
if s2 == nil:
|
|
||||||
unsureAsgnRef(d, s2)
|
|
||||||
else:
|
|
||||||
when declared(usrToCell):
|
|
||||||
let realType = usrToCell(s2).typ
|
|
||||||
else:
|
|
||||||
let realType = if mt.base.kind == tyObject: cast[ptr PNimType](s2)[]
|
|
||||||
else: mt.base
|
|
||||||
var z = newObj(realType, realType.base.size)
|
|
||||||
genericAssignAux(d, addr z, mt.base, shallow)
|
|
||||||
else:
|
else:
|
||||||
copyMem(dest, src, mt.size) # copy raw bits
|
copyMem(dest, src, mt.size) # copy raw bits
|
||||||
|
|
||||||
|
|
@ -143,7 +130,6 @@ when false:
|
||||||
of tyPtr: k = "ptr"
|
of tyPtr: k = "ptr"
|
||||||
of tyRef: k = "ref"
|
of tyRef: k = "ref"
|
||||||
of tyVar: k = "var"
|
of tyVar: k = "var"
|
||||||
of tyOptAsRef: k = "optref"
|
|
||||||
of tySequence: k = "seq"
|
of tySequence: k = "seq"
|
||||||
of tyProc: k = "proc"
|
of tyProc: k = "proc"
|
||||||
of tyPointer: k = "range"
|
of tyPointer: k = "range"
|
||||||
|
|
@ -219,7 +205,7 @@ proc genericReset(dest: pointer, mt: PNimType) =
|
||||||
var d = cast[ByteAddress](dest)
|
var d = cast[ByteAddress](dest)
|
||||||
sysAssert(mt != nil, "genericReset 2")
|
sysAssert(mt != nil, "genericReset 2")
|
||||||
case mt.kind
|
case mt.kind
|
||||||
of tyString, tyRef, tyOptAsRef, tySequence:
|
of tyString, tyRef, tySequence:
|
||||||
unsureAsgnRef(cast[PPointer](dest), nil)
|
unsureAsgnRef(cast[PPointer](dest), nil)
|
||||||
of tyTuple:
|
of tyTuple:
|
||||||
genericResetAux(dest, mt.node)
|
genericResetAux(dest, mt.node)
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ proc storeAux(dest, src: pointer, mt: PNimType, t: PRawChannel,
|
||||||
for i in 0..(mt.size div mt.base.size)-1:
|
for i in 0..(mt.size div mt.base.size)-1:
|
||||||
storeAux(cast[pointer](d +% i*% mt.base.size),
|
storeAux(cast[pointer](d +% i*% mt.base.size),
|
||||||
cast[pointer](s +% i*% mt.base.size), mt.base, t, mode)
|
cast[pointer](s +% i*% mt.base.size), mt.base, t, mode)
|
||||||
of tyRef, tyOptAsRef:
|
of tyRef:
|
||||||
var s = cast[PPointer](src)[]
|
var s = cast[PPointer](src)[]
|
||||||
var x = cast[PPointer](dest)
|
var x = cast[PPointer](dest)
|
||||||
if s == nil:
|
if s == nil:
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ proc genericDeepCopyAux(dest, src: pointer, mt: PNimType; tab: var PtrTable) =
|
||||||
for i in 0..(mt.size div mt.base.size)-1:
|
for i in 0..(mt.size div mt.base.size)-1:
|
||||||
genericDeepCopyAux(cast[pointer](d +% i *% mt.base.size),
|
genericDeepCopyAux(cast[pointer](d +% i *% mt.base.size),
|
||||||
cast[pointer](s +% i *% mt.base.size), mt.base, tab)
|
cast[pointer](s +% i *% mt.base.size), mt.base, tab)
|
||||||
of tyRef, tyOptAsRef:
|
of tyRef:
|
||||||
let s2 = cast[PPointer](src)[]
|
let s2 = cast[PPointer](src)[]
|
||||||
if s2 == nil:
|
if s2 == nil:
|
||||||
unsureAsgnRef(cast[PPointer](dest), s2)
|
unsureAsgnRef(cast[PPointer](dest), s2)
|
||||||
|
|
|
||||||
|
|
@ -295,7 +295,7 @@ proc forAllSlotsAux(dest: pointer, n: ptr TNimNode, op: WalkOp) {.benign.} =
|
||||||
for i in 0..n.len-1:
|
for i in 0..n.len-1:
|
||||||
# inlined for speed
|
# inlined for speed
|
||||||
if n.sons[i].kind == nkSlot:
|
if n.sons[i].kind == nkSlot:
|
||||||
if n.sons[i].typ.kind in {tyRef, tyOptAsRef, tyString, tySequence}:
|
if n.sons[i].typ.kind in {tyRef, tyString, tySequence}:
|
||||||
doOperation(cast[PPointer](d +% n.sons[i].offset)[], op)
|
doOperation(cast[PPointer](d +% n.sons[i].offset)[], op)
|
||||||
else:
|
else:
|
||||||
forAllChildrenAux(cast[pointer](d +% n.sons[i].offset),
|
forAllChildrenAux(cast[pointer](d +% n.sons[i].offset),
|
||||||
|
|
@ -312,7 +312,7 @@ proc forAllChildrenAux(dest: pointer, mt: PNimType, op: WalkOp) =
|
||||||
if dest == nil: return # nothing to do
|
if dest == nil: return # nothing to do
|
||||||
if ntfNoRefs notin mt.flags:
|
if ntfNoRefs notin mt.flags:
|
||||||
case mt.kind
|
case mt.kind
|
||||||
of tyRef, tyOptAsRef, tyString, tySequence: # leaf:
|
of tyRef, tyString, tySequence: # leaf:
|
||||||
doOperation(cast[PPointer](d)[], op)
|
doOperation(cast[PPointer](d)[], op)
|
||||||
of tyObject, tyTuple:
|
of tyObject, tyTuple:
|
||||||
forAllSlotsAux(dest, mt.node, op)
|
forAllSlotsAux(dest, mt.node, op)
|
||||||
|
|
@ -325,13 +325,13 @@ proc forAllChildren(cell: PCell, op: WalkOp) =
|
||||||
gcAssert(cell != nil, "forAllChildren: cell is nil")
|
gcAssert(cell != nil, "forAllChildren: cell is nil")
|
||||||
gcAssert(isAllocatedPtr(gch.region, cell), "forAllChildren: pointer not part of the heap")
|
gcAssert(isAllocatedPtr(gch.region, cell), "forAllChildren: pointer not part of the heap")
|
||||||
gcAssert(cell.typ != nil, "forAllChildren: cell.typ is nil")
|
gcAssert(cell.typ != nil, "forAllChildren: cell.typ is nil")
|
||||||
gcAssert cell.typ.kind in {tyRef, tyOptAsRef, tySequence, tyString}, "forAllChildren: unknown GC'ed type"
|
gcAssert cell.typ.kind in {tyRef, tySequence, tyString}, "forAllChildren: unknown GC'ed type"
|
||||||
let marker = cell.typ.marker
|
let marker = cell.typ.marker
|
||||||
if marker != nil:
|
if marker != nil:
|
||||||
marker(cellToUsr(cell), op.int)
|
marker(cellToUsr(cell), op.int)
|
||||||
else:
|
else:
|
||||||
case cell.typ.kind
|
case cell.typ.kind
|
||||||
of tyRef, tyOptAsRef: # common case
|
of tyRef: # common case
|
||||||
forAllChildrenAux(cellToUsr(cell), cell.typ.base, op)
|
forAllChildrenAux(cellToUsr(cell), cell.typ.base, op)
|
||||||
of tySequence:
|
of tySequence:
|
||||||
var d = cast[ByteAddress](cellToUsr(cell))
|
var d = cast[ByteAddress](cellToUsr(cell))
|
||||||
|
|
@ -406,7 +406,7 @@ proc rawNewObj(typ: PNimType, size: int, gch: var GcHeap): pointer =
|
||||||
# generates a new object and sets its reference counter to 0
|
# generates a new object and sets its reference counter to 0
|
||||||
incTypeSize typ, size
|
incTypeSize typ, size
|
||||||
sysAssert(allocInv(gch.region), "rawNewObj begin")
|
sysAssert(allocInv(gch.region), "rawNewObj begin")
|
||||||
gcAssert(typ.kind in {tyRef, tyOptAsRef, tyString, tySequence}, "newObj: 1")
|
gcAssert(typ.kind in {tyRef, tyString, tySequence}, "newObj: 1")
|
||||||
collectCT(gch)
|
collectCT(gch)
|
||||||
var res = cast[PCell](rawAlloc(gch.region, size + sizeof(Cell)))
|
var res = cast[PCell](rawAlloc(gch.region, size + sizeof(Cell)))
|
||||||
#gcAssert typ.kind in {tyString, tySequence} or size >= typ.base.size, "size too small"
|
#gcAssert typ.kind in {tyString, tySequence} or size >= typ.base.size, "size too small"
|
||||||
|
|
@ -452,7 +452,7 @@ proc newObjRC1(typ: PNimType, size: int): pointer {.compilerRtl.} =
|
||||||
# generates a new object and sets its reference counter to 1
|
# generates a new object and sets its reference counter to 1
|
||||||
incTypeSize typ, size
|
incTypeSize typ, size
|
||||||
sysAssert(allocInv(gch.region), "newObjRC1 begin")
|
sysAssert(allocInv(gch.region), "newObjRC1 begin")
|
||||||
gcAssert(typ.kind in {tyRef, tyOptAsRef, tyString, tySequence}, "newObj: 1")
|
gcAssert(typ.kind in {tyRef, tyString, tySequence}, "newObj: 1")
|
||||||
collectCT(gch)
|
collectCT(gch)
|
||||||
sysAssert(allocInv(gch.region), "newObjRC1 after collectCT")
|
sysAssert(allocInv(gch.region), "newObjRC1 after collectCT")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -268,7 +268,7 @@ proc forAllChildrenAux(dest: pointer, mt: PNimType, op: WalkOp) =
|
||||||
if dest == nil: return # nothing to do
|
if dest == nil: return # nothing to do
|
||||||
if ntfNoRefs notin mt.flags:
|
if ntfNoRefs notin mt.flags:
|
||||||
case mt.kind
|
case mt.kind
|
||||||
of tyRef, tyOptAsRef, tyString, tySequence: # leaf:
|
of tyRef, tyString, tySequence: # leaf:
|
||||||
doOperation(cast[PPointer](d)[], op)
|
doOperation(cast[PPointer](d)[], op)
|
||||||
of tyObject, tyTuple:
|
of tyObject, tyTuple:
|
||||||
forAllSlotsAux(dest, mt.node, op)
|
forAllSlotsAux(dest, mt.node, op)
|
||||||
|
|
@ -281,13 +281,13 @@ proc forAllChildren(cell: PCell, op: WalkOp) =
|
||||||
gcAssert(cell != nil, "forAllChildren: 1")
|
gcAssert(cell != nil, "forAllChildren: 1")
|
||||||
gcAssert(isAllocatedPtr(gch.region, cell), "forAllChildren: 2")
|
gcAssert(isAllocatedPtr(gch.region, cell), "forAllChildren: 2")
|
||||||
gcAssert(cell.typ != nil, "forAllChildren: 3")
|
gcAssert(cell.typ != nil, "forAllChildren: 3")
|
||||||
gcAssert cell.typ.kind in {tyRef, tyOptAsRef, tySequence, tyString}, "forAllChildren: 4"
|
gcAssert cell.typ.kind in {tyRef, tySequence, tyString}, "forAllChildren: 4"
|
||||||
let marker = cell.typ.marker
|
let marker = cell.typ.marker
|
||||||
if marker != nil:
|
if marker != nil:
|
||||||
marker(cellToUsr(cell), op.int)
|
marker(cellToUsr(cell), op.int)
|
||||||
else:
|
else:
|
||||||
case cell.typ.kind
|
case cell.typ.kind
|
||||||
of tyRef, tyOptAsRef: # common case
|
of tyRef: # common case
|
||||||
forAllChildrenAux(cellToUsr(cell), cell.typ.base, op)
|
forAllChildrenAux(cellToUsr(cell), cell.typ.base, op)
|
||||||
of tySequence:
|
of tySequence:
|
||||||
var d = cast[ByteAddress](cellToUsr(cell))
|
var d = cast[ByteAddress](cellToUsr(cell))
|
||||||
|
|
@ -328,7 +328,7 @@ proc initGC() =
|
||||||
proc rawNewObj(typ: PNimType, size: int, gch: var GcHeap): pointer =
|
proc rawNewObj(typ: PNimType, size: int, gch: var GcHeap): pointer =
|
||||||
# generates a new object and sets its reference counter to 0
|
# generates a new object and sets its reference counter to 0
|
||||||
sysAssert(allocInv(gch.region), "rawNewObj begin")
|
sysAssert(allocInv(gch.region), "rawNewObj begin")
|
||||||
gcAssert(typ.kind in {tyRef, tyOptAsRef, tyString, tySequence}, "newObj: 1")
|
gcAssert(typ.kind in {tyRef, tyString, tySequence}, "newObj: 1")
|
||||||
collectCT(gch)
|
collectCT(gch)
|
||||||
var res = cast[PCell](rawAlloc(gch.region, size + sizeof(Cell)))
|
var res = cast[PCell](rawAlloc(gch.region, size + sizeof(Cell)))
|
||||||
gcAssert((cast[ByteAddress](res) and (MemAlign-1)) == 0, "newObj: 2")
|
gcAssert((cast[ByteAddress](res) and (MemAlign-1)) == 0, "newObj: 2")
|
||||||
|
|
|
||||||
|
|
@ -236,7 +236,7 @@ proc forAllChildrenAux(dest: pointer, mt: PNimType, op: WalkOp) =
|
||||||
if dest == nil: return # nothing to do
|
if dest == nil: return # nothing to do
|
||||||
if ntfNoRefs notin mt.flags:
|
if ntfNoRefs notin mt.flags:
|
||||||
case mt.kind
|
case mt.kind
|
||||||
of tyRef, tyOptAsRef, tyString, tySequence: # leaf:
|
of tyRef, tyString, tySequence: # leaf:
|
||||||
doOperation(cast[PPointer](d)[], op)
|
doOperation(cast[PPointer](d)[], op)
|
||||||
of tyObject, tyTuple:
|
of tyObject, tyTuple:
|
||||||
forAllSlotsAux(dest, mt.node, op)
|
forAllSlotsAux(dest, mt.node, op)
|
||||||
|
|
@ -248,13 +248,13 @@ proc forAllChildrenAux(dest: pointer, mt: PNimType, op: WalkOp) =
|
||||||
proc forAllChildren(cell: PCell, op: WalkOp) =
|
proc forAllChildren(cell: PCell, op: WalkOp) =
|
||||||
gcAssert(cell != nil, "forAllChildren: 1")
|
gcAssert(cell != nil, "forAllChildren: 1")
|
||||||
gcAssert(cell.typ != nil, "forAllChildren: 2")
|
gcAssert(cell.typ != nil, "forAllChildren: 2")
|
||||||
gcAssert cell.typ.kind in {tyRef, tyOptAsRef, tySequence, tyString}, "forAllChildren: 3"
|
gcAssert cell.typ.kind in {tyRef, tySequence, tyString}, "forAllChildren: 3"
|
||||||
let marker = cell.typ.marker
|
let marker = cell.typ.marker
|
||||||
if marker != nil:
|
if marker != nil:
|
||||||
marker(cellToUsr(cell), op.int)
|
marker(cellToUsr(cell), op.int)
|
||||||
else:
|
else:
|
||||||
case cell.typ.kind
|
case cell.typ.kind
|
||||||
of tyRef, tyOptAsRef: # common case
|
of tyRef: # common case
|
||||||
forAllChildrenAux(cellToUsr(cell), cell.typ.base, op)
|
forAllChildrenAux(cellToUsr(cell), cell.typ.base, op)
|
||||||
of tySequence:
|
of tySequence:
|
||||||
when not defined(gcDestructors):
|
when not defined(gcDestructors):
|
||||||
|
|
@ -269,7 +269,7 @@ proc forAllChildren(cell: PCell, op: WalkOp) =
|
||||||
proc rawNewObj(typ: PNimType, size: int, gch: var GcHeap): pointer =
|
proc rawNewObj(typ: PNimType, size: int, gch: var GcHeap): pointer =
|
||||||
# generates a new object and sets its reference counter to 0
|
# generates a new object and sets its reference counter to 0
|
||||||
incTypeSize typ, size
|
incTypeSize typ, size
|
||||||
gcAssert(typ.kind in {tyRef, tyOptAsRef, tyString, tySequence}, "newObj: 1")
|
gcAssert(typ.kind in {tyRef, tyString, tySequence}, "newObj: 1")
|
||||||
collectCT(gch, size + sizeof(Cell))
|
collectCT(gch, size + sizeof(Cell))
|
||||||
var res = cast[PCell](rawAlloc(gch.region, size + sizeof(Cell)))
|
var res = cast[PCell](rawAlloc(gch.region, size + sizeof(Cell)))
|
||||||
gcAssert((cast[ByteAddress](res) and (MemAlign-1)) == 0, "newObj: 2")
|
gcAssert((cast[ByteAddress](res) and (MemAlign-1)) == 0, "newObj: 2")
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ type
|
||||||
tyUInt16,
|
tyUInt16,
|
||||||
tyUInt32,
|
tyUInt32,
|
||||||
tyUInt64,
|
tyUInt64,
|
||||||
tyOptAsRef, tyUnused1, tyUnused2,
|
tyOwned, tyUnused1, tyUnused2,
|
||||||
tyVarargsHidden,
|
tyVarargsHidden,
|
||||||
tyUncheckedArray,
|
tyUncheckedArray,
|
||||||
tyProxyHidden,
|
tyProxyHidden,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue