From b87ef6553201c73e24b1b53641cc18abe17d6e9b Mon Sep 17 00:00:00 2001 From: Mathias Stearn Date: Fri, 8 Dec 2017 19:55:04 -0500 Subject: [PATCH 1/2] Use addCallback rather than callback= in asyncfutures.all() (#6850) * Use addCallback rather than callback= in asyncfutures.all() Addresses part of #6849 * Stop using do notation for #6849 * Update example style --- lib/pure/asyncdispatch.nim | 5 +++-- lib/pure/asyncfutures.nim | 4 ++-- tests/async/tasyncall.nim | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim index 4c96aa6148..a71d30ab9f 100644 --- a/lib/pure/asyncdispatch.nim +++ b/lib/pure/asyncdispatch.nim @@ -59,9 +59,10 @@ export asyncfutures, asyncstreams ## ## .. code-block::nim ## var future = socket.recv(100) -## future.callback = +## future.addCallback( ## proc () = ## echo(future.read) +## ) ## ## All asynchronous functions returning a ``Future`` will not block. They ## will not however return immediately. An asynchronous function will have @@ -1611,4 +1612,4 @@ proc waitFor*[T](fut: Future[T]): T = fut.read -{.deprecated: [setEvent: trigger].} \ No newline at end of file +{.deprecated: [setEvent: trigger].} diff --git a/lib/pure/asyncfutures.nim b/lib/pure/asyncfutures.nim index bebd196114..4bd3227a11 100644 --- a/lib/pure/asyncfutures.nim +++ b/lib/pure/asyncfutures.nim @@ -333,7 +333,7 @@ proc all*[T](futs: varargs[Future[T]]): auto = let totalFutures = len(futs) for fut in futs: - fut.callback = proc(f: Future[T]) = + fut.addCallback proc (f: Future[T]) = inc(completedFutures) if not retFuture.finished: if f.failed: @@ -355,7 +355,7 @@ proc all*[T](futs: varargs[Future[T]]): auto = for i, fut in futs: proc setCallback(i: int) = - fut.callback = proc(f: Future[T]) = + fut.addCallback proc (f: Future[T]) = inc(completedFutures) if not retFuture.finished: if f.failed: diff --git a/tests/async/tasyncall.nim b/tests/async/tasyncall.nim index a3926eabdd..775dd0c6f0 100644 --- a/tests/async/tasyncall.nim +++ b/tests/async/tasyncall.nim @@ -40,6 +40,16 @@ proc testVarargs(x, y, z: int): seq[int] = result = waitFor all(a, b, c) +proc testWithDupes() = + var + tasks = newSeq[Future[void]](taskCount) + fut = futureWithoutValue() + + for i in 0.. Date: Sat, 9 Dec 2017 06:07:37 -0600 Subject: [PATCH 2/2] modify getTypeImpl to reduce result to final implementation (#6891) * added test case for getTypeImpl * modify getTypeImpl to reduce result to final implementation --- compiler/vmdeps.nim | 6 +++--- tests/macros/tgettypeinst.nim | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/compiler/vmdeps.nim b/compiler/vmdeps.nim index 44550a3895..fb277272b1 100644 --- a/compiler/vmdeps.nim +++ b/compiler/vmdeps.nim @@ -84,10 +84,10 @@ proc mapTypeToAstX(t: PType; info: TLineInfo; if inst: if t.sym != nil: # if this node has a symbol - if allowRecursion: # getTypeImpl behavior: turn off recursion - allowRecursion = false - else: # getTypeInst behavior: return symbol + if not allowRecursion: # getTypeInst behavior: return symbol return atomicType(t.sym) + #else: # getTypeImpl behavior: turn off recursion + # allowRecursion = false case t.kind of tyNone: result = atomicType("none", mNone) diff --git a/tests/macros/tgettypeinst.nim b/tests/macros/tgettypeinst.nim index ea98721c48..2f1abe193c 100644 --- a/tests/macros/tgettypeinst.nim +++ b/tests/macros/tgettypeinst.nim @@ -113,8 +113,12 @@ type Generic[T] = seq[int] Concrete = Generic[int] + Generic2[T1, T2] = seq[T1] + Concrete2 = Generic2[int, float] + Alias1 = float Alias2 = Concrete + Alias3 = Concrete2 Vec[N: static[int],T] = object arr: array[N,T] @@ -154,15 +158,21 @@ test(Tree): left: ref Tree right: ref Tree test(Concrete): - type _ = Generic[int] + type _ = seq[int] test(Generic[int]): type _ = seq[int] test(Generic[float]): type _ = seq[int] +test(Concrete2): + type _ = seq[int] +test(Generic2[int,float]): + type _ = seq[int] test(Alias1): type _ = float test(Alias2): - type _ = Generic[int] + type _ = seq[int] +test(Alias3): + type _ = seq[int] test(Vec[4,float32]): type _ = object arr: array[0..3,float32]