diff options
author | Clyybber <darkmine956@gmail.com> | 2020-07-17 10:56:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-17 10:56:17 +0200 |
commit | 1355b461aa70cd1e17b2f07085aa6c97cb54283f (patch) | |
tree | 493f236f32668e5379a1c6dfa61a846ffbaa90d2 | |
parent | 9fb7467fda597957634b17782745a7f25d83296f (diff) | |
download | Nim-1355b461aa70cd1e17b2f07085aa6c97cb54283f.tar.gz |
Show that a variable is cursor in --expandArc (#15002)
-rw-r--r-- | compiler/cursor_inference.nim | 9 | ||||
-rw-r--r-- | compiler/injectdestructors.nim | 11 | ||||
-rw-r--r-- | compiler/renderer.nim | 2 | ||||
-rw-r--r-- | tests/arc/topt_cursor.nim | 6 | ||||
-rw-r--r-- | tests/arc/topt_refcursors.nim | 18 |
5 files changed, 23 insertions, 23 deletions
diff --git a/compiler/cursor_inference.nim b/compiler/cursor_inference.nim index 224131270..94b06ac79 100644 --- a/compiler/cursor_inference.nim +++ b/compiler/cursor_inference.nim @@ -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 diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim index 556d098f4..99eefca57 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/injectdestructors.nim @@ -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) diff --git a/compiler/renderer.nim b/compiler/renderer.nim index 3cd532e15..f600d58bf 100644 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -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 diff --git a/tests/arc/topt_cursor.nim b/tests/arc/topt_cursor.nim index 6b923cf76..63f261877 100644 --- a/tests/arc/topt_cursor.nim +++ b/tests/arc/topt_cursor.nim @@ -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) diff --git a/tests/arc/topt_refcursors.nim b/tests/arc/topt_refcursors.nim index 7316e2beb..c8759f121 100644 --- a/tests/arc/topt_refcursors.nim +++ b/tests/arc/topt_refcursors.nim @@ -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 ------------------------''' """ |