topt_wasmoved_destroy_pairs.nim 1.3 KB

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