tasyncleak2.nim 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. discard """
  2. output: "success"
  3. cmd: "nim c --gc:orc $file"
  4. """
  5. # issue #15076
  6. import deques, strutils, asyncdispatch
  7. proc doNothing(): Future[void] =
  8. #[
  9. var
  10. :env
  11. :env_1
  12. try:
  13. `=destroy`(:env)
  14. internalNew(:env)
  15. `=sink`(:env.retFuture1, newFuture("doNothing"))
  16. `=destroy_1`(:env_1)
  17. internalNew(:env_1)
  18. `=`(:env_1.:up, :env)
  19. `=sink_1`(:env.nameIterVar2, (doNothingIter, :env_1))
  20. (doNothingNimAsyncContinue, :env)()
  21. return `=_1`(result, :env.retFuture1)
  22. finally:
  23. `=destroy`(:env)
  24. ]#
  25. var retFuture = newFuture[void]("doNothing")
  26. iterator doNothingIter(): FutureBase {.closure.} =
  27. # inspected ARC code: looks correct!
  28. block:
  29. var qqq = initDeque[string]()
  30. for i in 0 .. 1000:
  31. qqq.addLast($i)
  32. complete(retFuture) # env.up.retFuture1
  33. var nameIterVar = doNothingIter # iter_Env -> retFuture ->
  34. proc doNothingNimAsyncContinue() {.closure.} =
  35. # inspected ARC code: looks correct
  36. if not nameIterVar.finished:
  37. var next_gensym0 = nameIterVar()
  38. while (not next_gensym0.isNil) and next_gensym0.finished:
  39. next_gensym0 = nameIterVar()
  40. if nameIterVar.finished:
  41. break
  42. if next_gensym0 != nil:
  43. {.gcsafe.}:
  44. next_gensym0.addCallback cast[proc () {.closure, gcsafe.}](doNothingNimAsyncContinue)
  45. doNothingNimAsyncContinue()
  46. return retFuture
  47. proc main(): Future[void] =
  48. template await[T](f_gensym12: Future[T]): auto {.used.} =
  49. var internalTmpFuture_gensym12: FutureBase = f_gensym12
  50. yield internalTmpFuture_gensym12
  51. (cast[typeof(f_gensym12)](internalTmpFuture_gensym12)).read()
  52. var retFuture = newFuture[void]("main")
  53. iterator mainIter(): FutureBase {.closure.} =
  54. block:
  55. for x in 0 .. 1000:
  56. await doNothing()
  57. complete(retFuture)
  58. var nameIterVar_gensym11 = mainIter
  59. proc mainNimAsyncContinue() {.closure.} =
  60. if not nameIterVar_gensym11.finished:
  61. var next_gensym11 = unown nameIterVar_gensym11()
  62. while (not next_gensym11.isNil) and next_gensym11.finished:
  63. next_gensym11 = unown nameIterVar_gensym11()
  64. if nameIterVar_gensym11.finished:
  65. break
  66. if next_gensym11 != nil:
  67. {.gcsafe.}:
  68. next_gensym11.addCallback cast[proc () {.closure, gcsafe.}](mainNimAsyncContinue)
  69. mainNimAsyncContinue()
  70. return retFuture
  71. for i in 0..9:
  72. waitFor main()
  73. GC_fullCollect()
  74. doAssert getOccupiedMem() < 1024
  75. echo "success"