mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-08 14:03:23 +00:00
adds =destroy T support for strings and seqs (#22167)
* adds =destroy T support for strings and seqs * fixes system * fixes tests
This commit is contained in:
@@ -1069,7 +1069,7 @@ proc symPrototype(g: ModuleGraph; typ: PType; owner: PSym; kind: TTypeAttachedOp
|
||||
let src = newSym(skParam, getIdent(g.cache, if kind == attachedTrace: "env" else: "src"),
|
||||
idgen, result, info)
|
||||
|
||||
if kind == attachedDestructor and typ.kind == tyRef:
|
||||
if kind == attachedDestructor and typ.kind in {tyRef, tyString, tySequence} and g.config.selectedGC in {gcArc, gcOrc, gcAtomicArc}:
|
||||
dest.typ = typ
|
||||
else:
|
||||
dest.typ = makeVarType(typ.owner, typ, idgen)
|
||||
@@ -1196,7 +1196,7 @@ proc patchBody(g: ModuleGraph; c: PContext; n: PNode; info: TLineInfo; idgen: Id
|
||||
if op != nil:
|
||||
if op.ast.isGenericRoutine:
|
||||
internalError(g.config, info, "resolved destructor is generic")
|
||||
if op.magic == mDestroy:
|
||||
if op.magic == mDestroy and t.kind != tyString:
|
||||
internalError(g.config, info, "patching mDestroy with mDestroy?")
|
||||
n[0] = newSymNode(op)
|
||||
for x in n: patchBody(g, c, x, info, idgen)
|
||||
|
||||
@@ -365,7 +365,13 @@ proc arrGet[I: Ordinal;T](a: T; i: I): T {.
|
||||
proc arrPut[I: Ordinal;T,S](a: T; i: I;
|
||||
x: S) {.noSideEffect, magic: "ArrPut".}
|
||||
|
||||
when defined(nimAllowNonVarDestructor):
|
||||
when defined(nimAllowNonVarDestructor) and arcLikeMem:
|
||||
proc `=destroy`*(x: string) {.inline, magic: "Destroy".} =
|
||||
discard
|
||||
|
||||
proc `=destroy`*[T](x: seq[T]) {.inline, magic: "Destroy".} =
|
||||
discard
|
||||
|
||||
proc `=destroy`*[T](x: ref T) {.inline, magic: "Destroy".} =
|
||||
discard
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ try:
|
||||
finally:
|
||||
`=destroy`(splitted)
|
||||
finally:
|
||||
`=destroy_1`(lan_ip)
|
||||
`=destroy`(lan_ip)
|
||||
-- end of expandArc ------------------------
|
||||
--expandArc: mergeShadowScope
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ data =
|
||||
:tmpD_2))
|
||||
:tmpD
|
||||
`=destroy`(:tmpD_2)
|
||||
`=destroy_1`(:tmpD_1)
|
||||
`=destroy_1`(data)
|
||||
`=destroy`(:tmpD_1)
|
||||
`=destroy`(data)
|
||||
-- end of expandArc ------------------------
|
||||
--expandArc: main1
|
||||
|
||||
@@ -37,8 +37,8 @@ data =
|
||||
:tmpD_1))
|
||||
:tmpD
|
||||
`=destroy`(:tmpD_1)
|
||||
`=destroy_1`(data)
|
||||
`=destroy_1`(s)
|
||||
`=destroy`(data)
|
||||
`=destroy`(s)
|
||||
-- end of expandArc ------------------------
|
||||
--expandArc: main2
|
||||
|
||||
@@ -54,7 +54,7 @@ data =
|
||||
:tmpD_1))
|
||||
:tmpD
|
||||
`=destroy`(:tmpD_1)
|
||||
`=destroy_1`(data)
|
||||
`=destroy`(data)
|
||||
`=destroy`(s)
|
||||
-- end of expandArc ------------------------
|
||||
--expandArc: main3
|
||||
@@ -73,7 +73,7 @@ data =
|
||||
:tmpD
|
||||
`=destroy`(:tmpD_2)
|
||||
`=destroy`(:tmpD_1)
|
||||
`=destroy_1`(data)
|
||||
`=destroy`(data)
|
||||
-- end of expandArc ------------------------
|
||||
'''
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user