From 8e7829ff8266859f313b3dd7e192dcd1560b8d5f Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sat, 23 Dec 2017 19:50:15 +0100 Subject: [PATCH] DFA attempt to capture the essence of linear types --- compiler/dfa.nim | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/compiler/dfa.nim b/compiler/dfa.nim index 6bb7a03a9e..2e80a1b263 100644 --- a/compiler/dfa.nim +++ b/compiler/dfa.nim @@ -337,10 +337,12 @@ proc gen(c: var Con; n: PNode) = proc dfa(code: seq[Instr]) = var u = newSeq[IntSet](code.len) # usages var d = newSeq[IntSet](code.len) # defs + var c = newSeq[IntSet](code.len) # consumed var backrefs = initTable[int, int]() for i in 0.. 0 and maxIters > 0: # and someChange: dec maxIters var pc = w.pop() # w[^1] @@ -389,6 +392,10 @@ proc dfa(code: seq[Instr]) = when defined(debugDfa): echo "Excluding ", pc, " prev ", prevPc assign d[pc], intersect + if consuming >= 0: + if not c[pc].containsOrIncl(consuming): + someChange = true + consuming = -1 # our interpretation ![I!]: prevPc = pc @@ -406,12 +413,21 @@ proc dfa(code: seq[Instr]) = #if someChange: w.add pc + code[pc].dest inc pc - of use, useWithinCall, def: + of use, useWithinCall: + #if not d[prevPc].missingOrExcl(): + # someChange = true + consuming = code[pc].sym.id + when defined(debugDfa): + echo "consumed: ", consuming + inc pc + of def: + if not d[pc].containsOrIncl(code[pc].sym.id): + someChange = true inc pc when defined(useDfa) and defined(debugDfa): for i in 0..