topt_wasmoved_destroy_pairs.nim 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. discard """
  2. output: ''''''
  3. cmd: '''nim c --gc:arc --expandArc:main --expandArc:tfor --hint:Performance:off $file'''
  4. nimout: '''--expandArc: main
  5. var
  6. a
  7. b
  8. x
  9. x = f()
  10. if cond:
  11. add(a):
  12. let blitTmp = x
  13. blitTmp
  14. else:
  15. add(b):
  16. let blitTmp_1 = x
  17. blitTmp_1
  18. `=destroy`(b)
  19. `=destroy`(a)
  20. -- end of expandArc ------------------------
  21. --expandArc: tfor
  22. var
  23. a
  24. b
  25. x
  26. try:
  27. x = f()
  28. block :tmp:
  29. var i_cursor
  30. var i_1 = 0
  31. block :tmp_1:
  32. while i_1 < 4:
  33. var :tmpD
  34. i_cursor = i_1
  35. if i_cursor == 2:
  36. return
  37. add(a):
  38. wasMoved(:tmpD)
  39. `=copy`(:tmpD, x)
  40. :tmpD
  41. inc i_1, 1
  42. if cond:
  43. add(a):
  44. let blitTmp = x
  45. wasMoved(x)
  46. blitTmp
  47. else:
  48. add(b):
  49. let blitTmp_1 = x
  50. wasMoved(x)
  51. blitTmp_1
  52. finally:
  53. `=destroy`(x)
  54. `=destroy_1`(b)
  55. `=destroy_1`(a)
  56. -- end of expandArc ------------------------'''
  57. """
  58. proc f(): seq[int] =
  59. @[1, 2, 3]
  60. proc main(cond: bool) =
  61. var a, b: seq[seq[int]]
  62. var x = f()
  63. if cond:
  64. a.add x
  65. else:
  66. b.add x
  67. # all paths move 'x' so no wasMoved(x); destroy(x) pair should be left in the
  68. # AST.
  69. main(false)
  70. proc tfor(cond: bool) =
  71. var a, b: seq[seq[int]]
  72. var x = f()
  73. for i in 0 ..< 4:
  74. if i == 2: return
  75. a.add x
  76. if cond:
  77. a.add x
  78. else:
  79. b.add x
  80. tfor(false)