refactoring, fixes yet another strictFuncs regression (#15446)
This commit is contained in:
parent
b703f02ad2
commit
2b91845f1d
3 changed files with 34 additions and 8 deletions
|
|
@ -1244,7 +1244,10 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) =
|
||||||
|
|
||||||
var mutationInfo = MutationInfo()
|
var mutationInfo = MutationInfo()
|
||||||
if {strictFuncs, views} * c.features != {}:
|
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:
|
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:
|
||||||
|
|
|
||||||
|
|
@ -84,11 +84,17 @@ type
|
||||||
maxMutation, minConnection: AbstractTime
|
maxMutation, minConnection: AbstractTime
|
||||||
mutations: seq[AbstractTime]
|
mutations: seq[AbstractTime]
|
||||||
|
|
||||||
|
Goal* = enum
|
||||||
|
constParameters,
|
||||||
|
borrowChecking,
|
||||||
|
cursorInference
|
||||||
|
|
||||||
Partitions* = object
|
Partitions* = object
|
||||||
abstractTime: AbstractTime
|
abstractTime: AbstractTime
|
||||||
s: seq[VarIndex]
|
s: seq[VarIndex]
|
||||||
graphs: seq[MutationInfo]
|
graphs: seq[MutationInfo]
|
||||||
unanalysableMutation, performCursorInference: bool
|
goals: set[Goal]
|
||||||
|
unanalysableMutation: bool
|
||||||
inAsgnSource, inConstructor, inNoSideEffectSection: int
|
inAsgnSource, inConstructor, inNoSideEffectSection: int
|
||||||
owner: PSym
|
owner: PSym
|
||||||
config: ConfigRef
|
config: ConfigRef
|
||||||
|
|
@ -546,7 +552,7 @@ proc borrowingAsgn(c: var Partitions; dest, src: PNode) =
|
||||||
of noView: discard "nothing to do"
|
of noView: discard "nothing to do"
|
||||||
|
|
||||||
proc deps(c: var Partitions; dest, src: PNode) =
|
proc deps(c: var Partitions; dest, src: PNode) =
|
||||||
if not c.performCursorInference:
|
if borrowChecking in c.goals:
|
||||||
borrowingAsgn(c, dest, src)
|
borrowingAsgn(c, dest, src)
|
||||||
|
|
||||||
var targets, sources: seq[PSym]
|
var targets, sources: seq[PSym]
|
||||||
|
|
@ -565,7 +571,7 @@ proc deps(c: var Partitions; dest, src: PNode) =
|
||||||
for s in sources:
|
for s in sources:
|
||||||
connect(c, t, s, dest.info)
|
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:
|
if dest.kind == nkSym:
|
||||||
let vid = variableId(c, dest.sym)
|
let vid = variableId(c, dest.sym)
|
||||||
if vid >= 0:
|
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: potentialMutation(c, r, it.info)
|
||||||
for r in roots: noCursor(c, r)
|
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
|
# a call like 'result.add toOpenArray()' can also be a borrow
|
||||||
# operation. We know 'paramType' is a tyVar and we really care if
|
# operation. We know 'paramType' is a tyVar and we really care if
|
||||||
# 'paramType[0]' is still a view type, this is not a typo!
|
# 'paramType[0]' is still a view type, this is not a typo!
|
||||||
|
|
@ -785,8 +791,8 @@ proc computeLiveRanges(c: var Partitions; n: PNode) =
|
||||||
else:
|
else:
|
||||||
for child in n: computeLiveRanges(c, child)
|
for child in n: computeLiveRanges(c, child)
|
||||||
|
|
||||||
proc computeGraphPartitions*(s: PSym; n: PNode; config: ConfigRef; cursorInference = false): Partitions =
|
proc computeGraphPartitions*(s: PSym; n: PNode; config: ConfigRef; goals: set[Goal]): Partitions =
|
||||||
result = Partitions(performCursorInference: cursorInference, owner: s, config: config)
|
result = Partitions(owner: s, config: config, goals: goals)
|
||||||
if s.kind notin {skModule, skMacro}:
|
if s.kind notin {skModule, skMacro}:
|
||||||
let params = s.typ.n
|
let params = s.typ.n
|
||||||
for i in 1..<params.len:
|
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])
|
# cannotBorrow(config, s, par.graphs[par.s[rid].con.graphIndex])
|
||||||
|
|
||||||
proc computeCursors*(s: PSym; n: PNode; config: ConfigRef) =
|
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:
|
for i in 0 ..< par.s.len:
|
||||||
let v = addr(par.s[i])
|
let v = addr(par.s[i])
|
||||||
if v.flags * {ownsData, preventCursor} == {} and v.sym.kind notin {skParam, skResult} and
|
if v.flags * {ownsData, preventCursor} == {} and v.sym.kind notin {skParam, skResult} and
|
||||||
|
|
|
||||||
17
tests/effects/tstrict_funcs.nim
Normal file
17
tests/effects/tstrict_funcs.nim
Normal 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])
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue