Show that a variable is cursor in --expandArc (#15002)

This commit is contained in:
Clyybber
2020-07-17 10:56:17 +02:00
committed by GitHub
parent 9fb7467fda
commit 1355b461aa
5 changed files with 23 additions and 23 deletions

View File

@@ -73,7 +73,7 @@ proc cursorId(c: Con; x: PSym): int =
if c.cursors[i].s == x: return i
return -1
proc getCursors(c: Con): IntSet =
proc getCursors(c: Con) =
#[
Question: if x depends on y and y depends on z then also y depends on z.
@@ -86,7 +86,6 @@ proc getCursors(c: Con): IntSet =
y.s = "mutate"
]#
result = initIntSet()
for cur in c.cursors:
if not c.mayOwnData.contains(cur.s.id) and
cur.s.typ.skipTypes({tyGenericInst, tyAlias}).kind != tyOwned:
@@ -97,7 +96,7 @@ proc getCursors(c: Con): IntSet =
#echo "bah, not a cursor ", cur.s, " bad dependency ", d
break doAdd
when true:
result.incl cur.s.id
cur.s.flags.incl sfCursor
when false:
echo "computed as a cursor ", cur.s, " ", cur.deps, " ", c.config $ cur.s.info
@@ -294,7 +293,7 @@ proc analyse(c: var Con; n: PNode) =
else:
for child in n: analyse(c, child)
proc computeCursors*(n: PNode; config: ConfigRef): IntSet =
proc computeCursors*(n: PNode; config: ConfigRef) =
var c = Con(config: config)
analyse(c, n)
result = getCursors c
getCursors c

View File

@@ -35,7 +35,6 @@ type
Con = object
owner: PSym
g: ControlFlowGraph
cursors: IntSet
graph: ModuleGraph
otherRead: PNode
inLoop, inSpawn: int
@@ -152,13 +151,13 @@ proc isLastRead(location: PNode; cfg: ControlFlowGraph; otherRead: var PNode; pc
proc isCursor(n: PNode; c: Con): bool =
case n.kind
of nkSym:
result = sfCursor in n.sym.flags or c.cursors.contains(n.sym.id)
sfCursor in n.sym.flags
of nkDotExpr:
result = sfCursor in n[1].sym.flags
isCursor(n[1], c)
of nkCheckedFieldExpr:
result = isCursor(n[0], c)
isCursor(n[0], c)
else:
result = false
false
proc isLastRead(n: PNode; c: var Con): bool =
# first we need to search for the instruction that belongs to 'n':
@@ -1043,7 +1042,7 @@ proc injectDestructorCalls*(g: ModuleGraph; owner: PSym; n: PNode): PNode =
echoCfg(c.g)
echo n
c.cursors = computeCursors(n, g.config)
computeCursors(n, g.config)
var scope: Scope
let body = p(n, c, scope, normal)

View File

@@ -865,6 +865,8 @@ proc gident(g: var TSrcGen, n: PNode) =
if localId != 0 and n.sym.magic == mNone:
s.add '_'
s.addInt localId
if sfCursor in n.sym.flags:
s.add "_cursor"
elif n.kind == nkSym and (renderIds in g.flags or sfGenSym in n.sym.flags or n.sym.kind == skTemp):
s.add '_'
s.addInt n.sym.id

View File

@@ -8,14 +8,14 @@ var
:tmpD_1
:tmpD_2
try:
var x = ("hi", 5)
x = if cond:
var x_cursor = ("hi", 5)
x_cursor = if cond:
:tmpD = ("different", 54)
:tmpD else:
:tmpD_1 = ("string here", 80)
:tmpD_1
echo [
:tmpD_2 = `$`(x)
:tmpD_2 = `$`(x_cursor)
:tmpD_2]
finally:
`=destroy`(:tmpD_2)

View File

@@ -3,19 +3,19 @@ discard """
cmd: '''nim c --gc:arc --expandArc:traverse --hint:Performance:off $file'''
nimout: '''--expandArc: traverse
var it = root
var it_cursor = root
block :tmp:
while (
not (it == nil)):
echo [it.s]
it = it.ri
var jt = root
not (it_cursor == nil)):
echo [it_cursor.s]
it_cursor = it_cursor.ri
var jt_cursor = root
block :tmp_1:
while (
not (jt == nil)):
let ri_1 = jt.ri
echo [jt.s]
jt = ri_1
not (jt_cursor == nil)):
let ri_1_cursor = jt_cursor.ri
echo [jt_cursor.s]
jt_cursor = ri_1_cursor
-- end of expandArc ------------------------'''
"""