Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds =destroy T support for strings and seqs #22167

Merged
merged 3 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/liftdestructors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
ringabout marked this conversation as resolved.
Show resolved Hide resolved

proc `=destroy`*[T](x: seq[T]) {.inline, magic: "Destroy".} =
discard

proc `=destroy`*[T](x: ref T) {.inline, magic: "Destroy".} =
discard

Expand Down
2 changes: 1 addition & 1 deletion tests/arc/topt_no_cursor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ try:
finally:
`=destroy`(splitted)
finally:
`=destroy_1`(lan_ip)
`=destroy`(lan_ip)
-- end of expandArc ------------------------
--expandArc: mergeShadowScope

Expand Down
12 changes: 6 additions & 6 deletions tests/destructor/tv2_cast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -54,7 +54,7 @@ data =
:tmpD_1))
:tmpD
`=destroy`(:tmpD_1)
`=destroy_1`(data)
`=destroy`(data)
`=destroy`(s)
-- end of expandArc ------------------------
--expandArc: main3
Expand All @@ -73,7 +73,7 @@ data =
:tmpD
`=destroy`(:tmpD_2)
`=destroy`(:tmpD_1)
`=destroy_1`(data)
`=destroy`(data)
-- end of expandArc ------------------------
'''
"""
Expand Down