diff --git a/lib/pure/asyncfutures.nim b/lib/pure/asyncfutures.nim index a122e0c41..5675f5399 100644 --- a/lib/pure/asyncfutures.nim +++ b/lib/pure/asyncfutures.nim @@ -1,4 +1,4 @@ -import os, tables, strutils, times, heapqueue, options, deques +import os, tables, strutils, times, heapqueue, options, deques, cstrutils # TODO: This shouldn't need to be included, but should ideally be exported. type @@ -217,19 +217,15 @@ proc `callback=`*[T](future: Future[T], ## If future has already completed then ``cb`` will be called immediately. future.callback = proc () = cb(future) -proc diff[T](a, b: seq[T]): (int, seq[T]) = +proc diff[T](a, b: seq[T]; firstB, lastB: int): int = ## Iterates through both sequences until the items do not match, - ## returns the remainder of `b` after the last item that does not match + ## returns the remainder of `b[firstB..lastB]` after the last item that does not match ## together with the index of the last match. - ## - ## .. code-block::nim - ## doAssert(diff(@[1,2,42,123], @[1,2,123,678,21]) == (1, @[123,678,21])) - var lastIndex = 0 - for i in 0.. longestLeft: longestLeft = left.len - const indent = 2 + const indent = spaces(2) # Format the entries. for entry in entries: - let indentStr = spaces(indent) - let left = "$#($#)" % [$entry.filename, $entry.line] - result.add("$#$#$# $#\n" % [ - indentStr, + result.add((indent & "$#$# $#\n") % [ left, spaces(longestLeft - left.len + 2), $entry.procName ]) let hint = getHint(entry) if hint.len > 0: - result.add(indentStr & "└─" & hint & "\n") + result.add(indent & "└─" & hint & "\n") proc injectStacktrace[T](future: Future[T]) = when not defined(release): diff --git a/lib/pure/asyncmacro.nim b/lib/pure/asyncmacro.nim index 85d44b9f4..8c679929d 100644 --- a/lib/pure/asyncmacro.nim +++ b/lib/pure/asyncmacro.nim @@ -389,6 +389,8 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} = outerProcBody.add(closureIterator) # -> createCb(retFuture) + # NOTE: The "_continue" suffix is checked for in asyncfutures.nim to produce + # friendlier stack traces: var cbName = genSym(nskProc, prcName & "_continue") var procCb = getAst createCb(retFutureSym, iteratorNameSym, newStrLitNode(prcName),