From 2b91845f1db165541be5d2ebad7fe1f956e90fb1 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 1 Oct 2020 11:16:04 +0200 Subject: [PATCH] refactoring, fixes yet another strictFuncs regression (#15446) --- compiler/sempass2.nim | 5 ++++- compiler/varpartitions.nim | 20 +++++++++++++------- tests/effects/tstrict_funcs.nim | 17 +++++++++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 tests/effects/tstrict_funcs.nim diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index d591da8550..cda156224a 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 1fb4bd93ed..b416aa41d7 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..