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
commit 1355b461aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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 if c.cursors[i].s == x: return i
return -1 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. 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" y.s = "mutate"
]# ]#
result = initIntSet()
for cur in c.cursors: for cur in c.cursors:
if not c.mayOwnData.contains(cur.s.id) and if not c.mayOwnData.contains(cur.s.id) and
cur.s.typ.skipTypes({tyGenericInst, tyAlias}).kind != tyOwned: 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 #echo "bah, not a cursor ", cur.s, " bad dependency ", d
break doAdd break doAdd
when true: when true:
result.incl cur.s.id cur.s.flags.incl sfCursor
when false: when false:
echo "computed as a cursor ", cur.s, " ", cur.deps, " ", c.config $ cur.s.info 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: else:
for child in n: analyse(c, child) 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) var c = Con(config: config)
analyse(c, n) analyse(c, n)
result = getCursors c getCursors c

View file

@ -35,7 +35,6 @@ type
Con = object Con = object
owner: PSym owner: PSym
g: ControlFlowGraph g: ControlFlowGraph
cursors: IntSet
graph: ModuleGraph graph: ModuleGraph
otherRead: PNode otherRead: PNode
inLoop, inSpawn: int inLoop, inSpawn: int
@ -152,13 +151,13 @@ proc isLastRead(location: PNode; cfg: ControlFlowGraph; otherRead: var PNode; pc
proc isCursor(n: PNode; c: Con): bool = proc isCursor(n: PNode; c: Con): bool =
case n.kind case n.kind
of nkSym: of nkSym:
result = sfCursor in n.sym.flags or c.cursors.contains(n.sym.id) sfCursor in n.sym.flags
of nkDotExpr: of nkDotExpr:
result = sfCursor in n[1].sym.flags isCursor(n[1], c)
of nkCheckedFieldExpr: of nkCheckedFieldExpr:
result = isCursor(n[0], c) isCursor(n[0], c)
else: else:
result = false false
proc isLastRead(n: PNode; c: var Con): bool = proc isLastRead(n: PNode; c: var Con): bool =
# first we need to search for the instruction that belongs to 'n': # 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) echoCfg(c.g)
echo n echo n
c.cursors = computeCursors(n, g.config) computeCursors(n, g.config)
var scope: Scope var scope: Scope
let body = p(n, c, scope, normal) 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: if localId != 0 and n.sym.magic == mNone:
s.add '_' s.add '_'
s.addInt localId 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): elif n.kind == nkSym and (renderIds in g.flags or sfGenSym in n.sym.flags or n.sym.kind == skTemp):
s.add '_' s.add '_'
s.addInt n.sym.id s.addInt n.sym.id

View file

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

View file

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