ORC: cursor inference bugfix (#17973)

* fixed a .cursor inference bug

* added a test case
This commit is contained in:
Andreas Rumpf
2021-05-08 16:47:06 +02:00
committed by GitHub
parent 38b41f893a
commit c14427dbf3
3 changed files with 50 additions and 5 deletions

View File

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

View File

@@ -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)

View File

@@ -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())))