diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2020-10-01 11:16:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-01 11:16:04 +0200 |
commit | 2b91845f1db165541be5d2ebad7fe1f956e90fb1 (patch) | |
tree | e5443a66c230fc3e1b6002138f464a6eac99680d | |
parent | b703f02ad2a95975513f07d1a48c368b80825ddb (diff) | |
download | Nim-2b91845f1db165541be5d2ebad7fe1f956e90fb1.tar.gz |
refactoring, fixes yet another strictFuncs regression (#15446)
-rw-r--r-- | compiler/sempass2.nim | 5 | ||||
-rw-r--r-- | compiler/varpartitions.nim | 20 | ||||
-rw-r--r-- | tests/effects/tstrict_funcs.nim | 17 |
3 files changed, 34 insertions, 8 deletions
diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index d591da855..cda156224 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -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: diff --git a/compiler/varpartitions.nim b/compiler/varpartitions.nim index 1fb4bd93e..b416aa41d 100644 --- a/compiler/varpartitions.nim +++ b/compiler/varpartitions.nim @@ -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 diff --git a/tests/effects/tstrict_funcs.nim b/tests/effects/tstrict_funcs.nim new file mode 100644 index 000000000..a45e5f759 --- /dev/null +++ b/tests/effects/tstrict_funcs.nim @@ -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]) + |