From c14427dbf38ffe573c838a452b9187c44d063145 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sat, 8 May 2021 16:47:06 +0200 Subject: [PATCH] ORC: cursor inference bugfix (#17973) * fixed a .cursor inference bug * added a test case --- compiler/varpartitions.nim | 4 +-- lib/pure/asyncfutures.nim | 4 +-- tests/arc/topt_no_cursor.nim | 47 +++++++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/compiler/varpartitions.nim b/compiler/varpartitions.nim index 7bb626c0a..810ce8586 100644 --- a/compiler/varpartitions.nim +++ b/compiler/varpartitions.nim @@ -695,7 +695,7 @@ proc traverse(c: var Partitions; n: PNode) = # 'paramType[0]' is still a view type, this is not a typo! if directViewType(paramType[0]) == noView and classifyViewType(paramType[0]) != noView: borrowingCall(c, paramType[0], n, i) - elif borrowChecking in c.goals and m == mNone: + elif m == mNone: potentialMutationViaArg(c, n[i], parameters) of nkAddr, nkHiddenAddr: @@ -921,4 +921,4 @@ proc computeCursors*(s: PSym; n: PNode; g: ModuleGraph) = discard "cannot cursor into a graph that is mutated" else: v.sym.flags.incl sfCursor - #echo "this is now a cursor ", v.sym, " ", par.s[rid].flags, " ", config $ v.sym.info + #echo "this is now a cursor ", v.sym, " ", par.s[rid].flags, " ", g.config $ v.sym.info diff --git a/lib/pure/asyncfutures.nim b/lib/pure/asyncfutures.nim index fd62b2703..0178ee4d6 100644 --- a/lib/pure/asyncfutures.nim +++ b/lib/pure/asyncfutures.nim @@ -362,9 +362,9 @@ proc read*[T](future: Future[T] | FutureVar[T]): T = ## ## If the result of the future is an error then that error will be raised. when future is Future[T]: - let fut = future + let fut {.cursor.} = future else: - let fut = Future[T](future) + let fut {.cursor.} = Future[T](future) if fut.finished: if fut.error != nil: injectStacktrace(fut) diff --git a/tests/arc/topt_no_cursor.nim b/tests/arc/topt_no_cursor.nim index f1eb8575a..06cc4eda8 100644 --- a/tests/arc/topt_no_cursor.nim +++ b/tests/arc/topt_no_cursor.nim @@ -8,7 +8,7 @@ doing shady stuff... 192.168.0.1 192.168.0.1 192.168.0.1''' - cmd: '''nim c --gc:arc --expandArc:newTarget --expandArc:delete --expandArc:p1 --expandArc:tt --hint:Performance:off --assertions:off --expandArc:extractConfig $file''' + cmd: '''nim c --gc:arc --expandArc:newTarget --expandArc:delete --expandArc:p1 --expandArc:tt --hint:Performance:off --assertions:off --expandArc:extractConfig --expandArc:mergeShadowScope $file''' nimout: '''--expandArc: newTarget var @@ -108,6 +108,25 @@ try: `=destroy`(splitted) finally: `=destroy_1`(lan_ip) +--expandArc: mergeShadowScope + +var shadowScope +`=copy`(shadowScope, c.currentScope) +rawCloseScope(c) +block :tmp: + var sym + var i = 0 + let L = len(shadowScope.symbols) + block :tmp_1: + while i < L: + var :tmpD + sym = shadowScope.symbols[i] + addInterfaceDecl(c): + wasMoved(:tmpD) + `=copy_1`(:tmpD, sym) + :tmpD + inc(i, 1) +`=destroy`(shadowScope) -- end of expandArc ------------------------''' """ @@ -277,3 +296,29 @@ proc extractConfig() = echo splitted[1] # Without this line everything works extractConfig() + + +type + Symbol = ref object + name: string + + Scope = ref object + parent: Scope + symbols: seq[Symbol] + + PContext = ref object + currentScope: Scope + +proc rawCloseScope(c: PContext) = + c.currentScope = c.currentScope.parent + +proc addInterfaceDecl(c: PContext; s: Symbol) = + c.currentScope.symbols.add s + +proc mergeShadowScope*(c: PContext) = + let shadowScope = c.currentScope + c.rawCloseScope + for sym in shadowScope.symbols: + c.addInterfaceDecl(sym) + +mergeShadowScope(PContext(currentScope: Scope(parent: Scope())))