more precise borrow checking of 'result' (#15406)
This commit is contained in:
parent
ce72d7ffc5
commit
e3b5f80a89
2 changed files with 8 additions and 3 deletions
|
|
@ -1248,7 +1248,7 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) =
|
||||||
if not t.hasSideEffect and t.hasDangerousAssign:
|
if not t.hasSideEffect and t.hasDangerousAssign:
|
||||||
t.hasSideEffect = varpartitions.hasSideEffect(partitions, mutationInfo)
|
t.hasSideEffect = varpartitions.hasSideEffect(partitions, mutationInfo)
|
||||||
if views in c.features:
|
if views in c.features:
|
||||||
checkBorrowedLocations(partitions, g.config)
|
checkBorrowedLocations(partitions, body, g.config)
|
||||||
|
|
||||||
if sfThread in s.flags and t.gcUnsafe:
|
if sfThread in s.flags and t.gcUnsafe:
|
||||||
if optThreads in g.config.globalOptions and optThreadAnalysis in g.config.globalOptions:
|
if optThreads in g.config.globalOptions and optThreadAnalysis in g.config.globalOptions:
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,9 @@ proc registerVariable(c: var Partitions; n: PNode) =
|
||||||
connectedVia: unknownLineInfo, flags: {connectsConstParam},
|
connectedVia: unknownLineInfo, flags: {connectsConstParam},
|
||||||
maxMutation: -1, minConnection: high(int),
|
maxMutation: -1, minConnection: high(int),
|
||||||
mutations: @[])
|
mutations: @[])
|
||||||
|
elif n.sym.kind == skResult:
|
||||||
|
c.s.add VarIndex(kind: isEmptyRoot, sym: n.sym,
|
||||||
|
aliveStart: high(int), aliveEnd: c.abstractTime)
|
||||||
else:
|
else:
|
||||||
c.s.add VarIndex(kind: isEmptyRoot, sym: n.sym,
|
c.s.add VarIndex(kind: isEmptyRoot, sym: n.sym,
|
||||||
aliveStart: c.abstractTime, aliveEnd: c.abstractTime)
|
aliveStart: c.abstractTime, aliveEnd: c.abstractTime)
|
||||||
|
|
@ -567,6 +570,8 @@ proc computeLiveRanges(c: var Partitions; n: PNode) =
|
||||||
let id = variableId(c, n.sym)
|
let id = variableId(c, n.sym)
|
||||||
if id >= 0:
|
if id >= 0:
|
||||||
c.s[id].aliveEnd = max(c.s[id].aliveEnd, c.abstractTime)
|
c.s[id].aliveEnd = max(c.s[id].aliveEnd, c.abstractTime)
|
||||||
|
if n.sym.kind == skResult:
|
||||||
|
c.s[id].aliveStart = min(c.s[id].aliveStart, c.abstractTime)
|
||||||
|
|
||||||
of nodesToIgnoreSet:
|
of nodesToIgnoreSet:
|
||||||
dec c.abstractTime
|
dec c.abstractTime
|
||||||
|
|
@ -621,7 +626,7 @@ proc computeGraphPartitions*(s: PSym; n: PNode; cursorInference = false): Partit
|
||||||
traverse(result, n)
|
traverse(result, n)
|
||||||
|
|
||||||
proc dangerousMutation(g: MutationInfo; v: VarIndex): bool =
|
proc dangerousMutation(g: MutationInfo; v: VarIndex): bool =
|
||||||
#echo "range ", v.aliveStart, " .. ", v.aliveEnd
|
#echo "range ", v.aliveStart, " .. ", v.aliveEnd, " ", v.sym
|
||||||
if isMutated in g.flags:
|
if isMutated in g.flags:
|
||||||
for m in g.mutations:
|
for m in g.mutations:
|
||||||
#echo "mutation ", m
|
#echo "mutation ", m
|
||||||
|
|
@ -643,7 +648,7 @@ proc cannotBorrow(config: ConfigRef; s: PSym; g: MutationInfo) =
|
||||||
m.add " is the statement that connected the mutation to the parameter"
|
m.add " is the statement that connected the mutation to the parameter"
|
||||||
localError(config, s.info, m)
|
localError(config, s.info, m)
|
||||||
|
|
||||||
proc checkBorrowedLocations*(par: var Partitions; config: ConfigRef) =
|
proc checkBorrowedLocations*(par: var Partitions; body: PNode; config: ConfigRef) =
|
||||||
for i in 0 ..< par.s.len:
|
for i in 0 ..< par.s.len:
|
||||||
let s = par.s[i].sym
|
let s = par.s[i].sym
|
||||||
if s.kind != skParam and isViewType(s.typ):
|
if s.kind != skParam and isViewType(s.typ):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue