refactor: replace elemSupportsCopyMem with supportsCopyMem for clarity and consistency

This commit is contained in:
ringabout
2026-04-01 19:15:00 +08:00
parent 8290f6dc12
commit 9182c03d47
3 changed files with 8 additions and 11 deletions

View File

@@ -620,12 +620,6 @@ proc checkSelfAssignment(c: var TLiftCtx; t: PType; body, x, y: PNode) =
cond.typ = getSysType(c.g, c.info, tyBool)
body.add genIf(c, cond, newTreeI(nkReturnStmt, c.info, newNodeI(nkEmpty, c.info)))
proc elemSupportsCopyMem(t: PType): bool =
## Returns true if the element type of seq `t` supports bulk memory copy
## (i.e., has no GC refs and no destructors).
let elemType = t.elementType.skipTypes({tyVar, tyLent, tyGenericInst, tyAlias, tySink, tyInferred})
result = not containsGarbageCollectedRef(elemType) and not hasDestructor(elemType)
proc genBulkCopySeq(c: var TLiftCtx; t: PType; body, x, y: PNode) =
## Generates a call to nimCopySeqPayload for bulk memcpy of seq data.
let elemType = t.elementType
@@ -650,7 +644,7 @@ proc fillSeqOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
case c.kind
of attachedDup:
body.add setLenSeqCall(c, t, x, y)
if elemSupportsCopyMem(t):
if supportsCopyMem(t):
genBulkCopySeq(c, t, body, x, y)
else:
forallElements(c, t, body, x, y)
@@ -665,7 +659,7 @@ proc fillSeqOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
# For trivially copyable types, use bulk copyMem instead of element loop.
checkSelfAssignment(c, t, body, x, y)
body.add setLenSeqCall(c, t, x, y)
if elemSupportsCopyMem(t):
if supportsCopyMem(t):
genBulkCopySeq(c, t, body, x, y)
else:
forallElements(c, t, body, x, y)

View File

@@ -232,9 +232,7 @@ proc evalTypeTrait(c: PContext; traitCall: PNode, operand: PType, context: PSym)
of "stripGenericParams":
result = uninstantiate(operand).toNode(traitCall.info)
of "supportsCopyMem":
let t = operand.skipTypes({tyVar, tyLent, tyGenericInst, tyAlias, tySink, tyInferred})
let complexObj = containsGarbageCollectedRef(t) or
hasDestructor(t)
let complexObj = supportsCopyMem(operand)
result = newIntNodeT(toInt128(ord(not complexObj)), traitCall, c.idgen, c.graph)
of "canFormCycles":
result = newIntNodeT(toInt128(ord(types.canFormAcycle(c.graph, operand))), traitCall, c.idgen, c.graph)

View File

@@ -1779,3 +1779,8 @@ proc reduceToBase*(f: PType): PType =
result = f.elementType
else:
result = f
proc supportsCopyMem*(t: PType): bool =
let t = t.skipTypes({tyVar, tyLent, tyGenericInst, tyAlias, tySink, tyInferred})
result = containsGarbageCollectedRef(t) or
hasDestructor(t)