From 9953e0bbca92d81e41a5ca39981b02596027f236 Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 31 May 2014 01:16:16 +0200 Subject: [PATCH] tdisjoint_slice2 works --- compiler/ccgcalls.nim | 2 +- compiler/guards.nim | 8 ++++++++ compiler/lowerings.nim | 2 +- compiler/semparallel.nim | 2 +- tests/parallel/tdisjoint_slice2.nim | 20 ++++++++++++++++---- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/compiler/ccgcalls.nim b/compiler/ccgcalls.nim index a7840305d..71e23aa1d 100644 --- a/compiler/ccgcalls.nim +++ b/compiler/ccgcalls.nim @@ -86,7 +86,7 @@ proc openArrayLoc(p: BProc, n: PNode): PRope = initLocExpr(p, q[2], b) initLocExpr(p, q[3], c) let fmt = - case skipTypes(a.t, abstractVar).kind + case skipTypes(a.t, abstractVar+{tyPtr}).kind of tyOpenArray, tyVarargs, tyArray, tyArrayConstr: "($1)+($2), ($3)-($2)+1" of tyString, tySequence: diff --git a/compiler/guards.nim b/compiler/guards.nim index ec5adb4da..813a30014 100644 --- a/compiler/guards.nim +++ b/compiler/guards.nim @@ -752,6 +752,14 @@ proc pleViaModelRec(m: var TModel; a, b: PNode): TImplication = if ple(m, a, x) == impYes: if ple(m, y, b) == impYes: return impYes #if pleViaModelRec(m, y, b): return impYes + # fact: 16 <= i + # x y + # question: i <= 15? no! + result = impliesLe(fact, a, b) + if result != impUnknown: return result + if sameTree(y, a): + result = ple(m, x, b) + if result != impUnknown: return result proc pleViaModel(model: TModel; aa, bb: PNode): TImplication = # compute replacements: diff --git a/compiler/lowerings.nim b/compiler/lowerings.nim index 5636d423f..b159502dc 100644 --- a/compiler/lowerings.nim +++ b/compiler/lowerings.nim @@ -338,7 +338,7 @@ proc setupArgsForParallelism(n: PNode; objType: PType; scratchObj: PSym; objType.addField(fieldB) if getMagic(n) == mSlice: - let a = genAddrOf(n[0]) + let a = genAddrOf(n[1]) field.typ = a.typ objType.addField(field) result.add newFastAsgnStmt(newDotExpr(scratchObj, field), a) diff --git a/compiler/semparallel.nim b/compiler/semparallel.nim index 678ffd2fb..72def1137 100644 --- a/compiler/semparallel.nim +++ b/compiler/semparallel.nim @@ -166,7 +166,7 @@ proc overlap(m: TModel; x,y,c,d: PNode) = of impUnknown: localError(x.info, "cannot prove: $# > $#; required for ($#)..($#) disjoint from ($#)..($#)" % - [?y, ?d, ?x, ?y, ?c, ?d]) + [?c, ?y, ?x, ?y, ?c, ?d]) of impYes: localError(x.info, "($#)..($#) not disjoint from ($#)..($#)" % [?x, ?y, ?c, ?d]) of impNo: discard diff --git a/tests/parallel/tdisjoint_slice2.nim b/tests/parallel/tdisjoint_slice2.nim index b26559fc2..1e86ea644 100644 --- a/tests/parallel/tdisjoint_slice2.nim +++ b/tests/parallel/tdisjoint_slice2.nim @@ -1,3 +1,15 @@ +discard """ + output: '''0 +1 +2 +3 +4 +5 +6 +7 +8''' + sortoutput: true +""" import threadpool @@ -7,12 +19,12 @@ proc f(a: openArray[int]) = proc f(a: int) = echo a proc main() = - var a: array[0..30, int] + var a: array[0..9, int] = [0,1,2,3,4,5,6,7,8,9] parallel: - spawn f(a[0..15]) + spawn f(a[0..2]) #spawn f(a[16..30]) - var i = 16 - while i <= 29: + var i = 3 + while i <= 8: spawn f(a[i]) spawn f(a[i+1]) inc i, 2