refactoring, fixes yet another strictFuncs regression (#15446)

This commit is contained in:
Andreas Rumpf
2020-10-01 11:16:04 +02:00
committed by GitHub
parent b703f02ad2
commit 2b91845f1d
3 changed files with 34 additions and 8 deletions

View File

@@ -1244,7 +1244,10 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) =
var mutationInfo = MutationInfo()
if {strictFuncs, views} * c.features != {}:
var partitions = computeGraphPartitions(s, body, g.config)
var goals: set[Goal] = {}
if strictFuncs in c.features: goals.incl constParameters
if views in c.features: goals.incl borrowChecking
var partitions = computeGraphPartitions(s, body, g.config, goals)
if not t.hasSideEffect and t.hasDangerousAssign:
t.hasSideEffect = varpartitions.hasSideEffect(partitions, mutationInfo)
if views in c.features:

View File

@@ -84,11 +84,17 @@ type
maxMutation, minConnection: AbstractTime
mutations: seq[AbstractTime]
Goal* = enum
constParameters,
borrowChecking,
cursorInference
Partitions* = object
abstractTime: AbstractTime
s: seq[VarIndex]
graphs: seq[MutationInfo]
unanalysableMutation, performCursorInference: bool
goals: set[Goal]
unanalysableMutation: bool
inAsgnSource, inConstructor, inNoSideEffectSection: int
owner: PSym
config: ConfigRef
@@ -546,7 +552,7 @@ proc borrowingAsgn(c: var Partitions; dest, src: PNode) =
of noView: discard "nothing to do"
proc deps(c: var Partitions; dest, src: PNode) =
if not c.performCursorInference:
if borrowChecking in c.goals:
borrowingAsgn(c, dest, src)
var targets, sources: seq[PSym]
@@ -565,7 +571,7 @@ proc deps(c: var Partitions; dest, src: PNode) =
for s in sources:
connect(c, t, s, dest.info)
if c.performCursorInference and src.kind != nkEmpty:
if cursorInference in c.goals and src.kind != nkEmpty:
if dest.kind == nkSym:
let vid = variableId(c, dest.sym)
if vid >= 0:
@@ -647,7 +653,7 @@ proc traverse(c: var Partitions; n: PNode) =
for r in roots: potentialMutation(c, r, it.info)
for r in roots: noCursor(c, r)
if not c.performCursorInference:
if borrowChecking in c.goals:
# a call like 'result.add toOpenArray()' can also be a borrow
# operation. We know 'paramType' is a tyVar and we really care if
# 'paramType[0]' is still a view type, this is not a typo!
@@ -785,8 +791,8 @@ proc computeLiveRanges(c: var Partitions; n: PNode) =
else:
for child in n: computeLiveRanges(c, child)
proc computeGraphPartitions*(s: PSym; n: PNode; config: ConfigRef; cursorInference = false): Partitions =
result = Partitions(performCursorInference: cursorInference, owner: s, config: config)
proc computeGraphPartitions*(s: PSym; n: PNode; config: ConfigRef; goals: set[Goal]): Partitions =
result = Partitions(owner: s, config: config, goals: goals)
if s.kind notin {skModule, skMacro}:
let params = s.typ.n
for i in 1..<params.len:
@@ -852,7 +858,7 @@ proc checkBorrowedLocations*(par: var Partitions; body: PNode; config: ConfigRef
# cannotBorrow(config, s, par.graphs[par.s[rid].con.graphIndex])
proc computeCursors*(s: PSym; n: PNode; config: ConfigRef) =
var par = computeGraphPartitions(s, n, config, true)
var par = computeGraphPartitions(s, n, config, {cursorInference})
for i in 0 ..< par.s.len:
let v = addr(par.s[i])
if v.flags * {ownsData, preventCursor} == {} and v.sym.kind notin {skParam, skResult} and

View File

@@ -0,0 +1,17 @@
discard """
cmd: "nim c --experimental:strictFuncs $file"
"""
import tables, streams, nre, parsecsv
type
Contig2Reads = TableRef[string, seq[string]]
proc get_Contig2Reads(sin: Stream, fn: string, contig2len: TableRef[string, int]): Contig2Reads =
result = newTable[string, seq[string]]()
var parser: CsvParser
open(parser, sin, filename = fn, separator = ' ', skipInitialSpace = true)
while readRow(parser, 2):
if contig2len.haskey(parser.row[1]):
mgetOrPut(result, parser.row[1], @[]).add(parser.row[0])