From 772b7ffe8c1aa9b92adf3a410077822989785634 Mon Sep 17 00:00:00 2001 From: zerbina <100542850+zerbina@users.noreply.github.com> Date: Sat, 9 Nov 2024 18:47:27 +0000 Subject: [PATCH] tests: update the `--expandArc` tests --- tests/arc/topt_cursor.nim | 59 +++++++++----- tests/arc/topt_no_cursor.nim | 95 ++++++++++++---------- tests/arc/topt_no_loop_cursor.nim | 16 ++-- tests/arc/topt_refcursors.nim | 16 ++-- tests/arc/topt_wasmoved_destroy_pairs.nim | 51 ++++++------ tests/lang_objects/destructor/tv2_cast.nim | 32 ++++---- 6 files changed, 149 insertions(+), 120 deletions(-) diff --git a/tests/arc/topt_cursor.nim b/tests/arc/topt_cursor.nim index 40026762cfa..a1bdd26dca9 100644 --- a/tests/arc/topt_cursor.nim +++ b/tests/arc/topt_cursor.nim @@ -15,11 +15,12 @@ scope: L1: def_cursor _3: (string, int) = x def _4: string = $(arg _3) -> [Resume] - echo(arg type(array[0..0, string]), arg _4) -> [L2, Resume] - goto [L2, L3] + echo(arg type(array[0..0, string]), arg _4) -> [L2] + =destroy(name _4) + goto [L3] finally (L2): =destroy(name _4) - continue {L3} + continue [Resume] L3: -- end of expandArc ------------------------ --expandArc: sio @@ -29,34 +30,52 @@ scope: def_cursor filename: string = "debug.txt" def_cursor _3: string = filename def f: File = open(arg _3, arg fmRead, arg 8000) -> [Resume] + def _4: uint32 scope: def res: string = newStringOfCap(arg 80) scope: while true: scope: - def_cursor _6: File = f - def :tmp: bool = readLine(arg _6, name res) -> [L1, L2, Resume] + def_cursor _7: File = f + def :tmp: bool = readLine(arg _7, name res) -> [L1] scope: - def_cursor _7: bool = :tmp - def _8: bool = not(arg _7) - if _8: + def_cursor _8: bool = :tmp + def _9: bool = not(arg _8) + if _9: scope: - goto [L4] + goto [L3] scope: def_cursor x: string = res - def_cursor _10: string = x - echo(arg type(array[0..0, string]), arg _10) -> [L1, L2, Resume] - L4: - goto [L1, L2, L5] + def_cursor _11: string = x + echo(arg type(array[0..0, string]), arg _11) -> [L1] + L3: + =destroy(name res) + _4 = 0'u32 + goto [L4] finally (L1): =destroy(name res) - continue {L2} - finally (L2): - scope: - def_cursor _11: File = f - close(arg _11) -> [Leave(L2), Resume] - continue {L5} - L5: + continue [L5] + except (L5): + _4 := 1'u32 + L4: + scope: + def_cursor _12: File = f + close(arg _12) -> [L6] + goto [L7] + finally (L6): + def _13: bool = eqI(arg _4, arg 1'u32) + if _13: + nimAbortException(arg true) + continue [Resume] + L7: + case _4 + of 0'u32: goto L9 + of 1'u32: goto L10 + L9: + goto [L11] + L10: + raise -> [Resume] + L11: -- end of expandArc ------------------------''' """ diff --git a/tests/arc/topt_no_cursor.nim b/tests/arc/topt_no_cursor.nim index 53496c6d0b2..aa90e81fc6b 100644 --- a/tests/arc/topt_no_cursor.nim +++ b/tests/arc/topt_no_cursor.nim @@ -13,7 +13,7 @@ doing shady stuff... nimout: '''--expandArc: newTarget scope: - def splat: tuple[dir: string, name: string, ext: string] = splitFile(arg path) -> [L0, Resume] + def splat: tuple[dir: string, name: string, ext: string] = splitFile(arg path) -> [L0] bind_mut _7: string = splat.0 def _3: string = move _7 wasMoved(name _7) @@ -28,7 +28,7 @@ scope: =destroy(name splat) goto [L1] finally (L0): - continue {} + continue [Resume] L1: -- end of expandArc ------------------------ --expandArc: delete @@ -79,15 +79,17 @@ scope: =copy(name _5, arg it.1) def a: (seq[int], seq[int]) = (consume _4, consume _5) def_cursor _6: (seq[int], seq[int]) = a - def _7: string = $(arg _6) -> [L0, Resume] - echo(arg type(array[0..0, string]), arg _7) -> [L1, L0, Resume] - goto [L1, L0, L2] + def _7: string = $(arg _6) -> [L0] + echo(arg type(array[0..0, string]), arg _7) -> [L1] + =destroy(name _7) + =destroy(name a) + goto [L2] finally (L1): =destroy(name _7) - continue {L0} + continue [L0] finally (L0): =destroy(name a) - continue {L2} + continue [Resume] L2: -- end of expandArc ------------------------ --expandArc: extractConfig @@ -114,7 +116,7 @@ scope: def_cursor _11: int = i def line: lent string = borrow a[_11] def_cursor _13: string = line[] - def splitted: seq[string] = split(arg _13, arg " ", arg -1) -> [L3, Resume] + def splitted: seq[string] = split(arg _13, arg " ", arg -1) -> [L3] scope: def_cursor _14: string = splitted[0] def _15: bool = eqStr(arg _14, arg "opt") @@ -123,27 +125,29 @@ scope: def_cursor _18: string = splitted[1] =copy(name lan_ip, arg _18) def_cursor _16: string = lan_ip - echo(arg type(array[0..0, string]), arg _16) -> [L4, L3, Resume] + echo(arg type(array[0..0, string]), arg _16) -> [L4] def_cursor _17: string = splitted[1] - echo(arg type(array[0..0, string]), arg _17) -> [L4, L3, Resume] - goto [L4, L6] + echo(arg type(array[0..0, string]), arg _17) -> [L4] + =destroy(name splitted) + goto [L6] finally (L4): =destroy(name splitted) - continue {L3, L6} + continue [L3] L6: - i = addI(arg i, arg 1) -> [L3, Resume] + i = addI(arg i, arg 1) -> [L3] L2: - goto [L3, L7] + =destroy(name lan_ip) + goto [L7] finally (L3): =destroy(name lan_ip) - continue {L7} + continue [Resume] L7: --expandArc: mergeShadowScope scope: def shadowScope: Scope =copy(name shadowScope, arg c[].currentScope) - rawCloseScope(arg c) -> [L0, Resume] + rawCloseScope(arg c) -> [L0] scope: def_cursor _4: Scope = shadowScope def_cursor a: seq[Symbol] = _4[].symbols @@ -166,17 +170,18 @@ scope: def sym: lent Symbol = borrow a[_13] def _14: Symbol =copy(name _14, arg sym[]) - addInterfaceDecl(arg c, consume _14) -> [L4, L0, Resume] - goto [L4, L5] + addInterfaceDecl(arg c, consume _14) -> [L4] + goto [L5] finally (L4): - continue {L0, L5} + continue [L0] L5: - i = addI(arg i, arg 1) -> [L0, Resume] + i = addI(arg i, arg 1) -> [L0] L3: - goto [L0, L6] + =destroy(name shadowScope) + goto [L6] finally (L0): =destroy(name shadowScope) - continue {L6} + continue [Resume] L6: -- end of expandArc ------------------------ --expandArc: treturn @@ -190,25 +195,25 @@ scope: if _4: scope: result := move x - wasMoved(name x) - goto [L1, L2] + goto [L1] def_cursor _5: sink string = x def _6: int = lengthStr(arg _5) - def _7: string = $(arg _6) -> [L1, L3, Resume] - echo(arg type(array[0..0, string]), arg _7) -> [L4, L1, L3, Resume] - goto [L4, L1, L5] - finally (L4): + def _7: string = $(arg _6) -> [L2] + echo(arg type(array[0..0, string]), arg _7) -> [L3] + =destroy(name _7) + =destroy(name x) + goto [L4] + finally (L3): =destroy(name _7) - continue {L1} - finally (L1): + continue [L2] + finally (L2): =destroy(name x) - continue {L2, L3, L5} - L5: -goto [L2] -finally (L3): - =destroy(name result) - continue {} -L2: + continue [L5] + L4: +goto [L1] +finally (L5): + continue [Resume] +L1: -- end of expandArc ------------------------ --expandArc: check @@ -231,38 +236,38 @@ scope: def _9: string = parentDir(arg _8) -> [Resume] def _10: string =copy(name _10, arg this[].value) - def _11: tuple[head: string, tail: string] = splitPath(consume _10) -> [L2, Resume] + def _11: tuple[head: string, tail: string] = splitPath(consume _10) -> [L2] bind_mut _19: string = _11.1 def _12: string = move _19 wasMoved(name _19) _4 := (consume _9, consume _12) - wasMoved(name _9) =destroy(name _11) - goto [L2, L3] + goto [L3] finally (L2): =destroy(name _9) - continue {L3} + continue [Resume] L3: L1: def par: tuple[dir: string, front: string] = move _4 scope: def_cursor _13: string = par.0 - def _14: bool = dirExists(arg _13) -> [L4, Resume] + def _14: bool = dirExists(arg _13) -> [L4] if _14: scope: def_cursor _15: string = par.0 def_cursor _16: string = par.1 - def _17: seq[string] = getSubDirs(arg _15, arg _16) -> [L4, Resume] + def _17: seq[string] = getSubDirs(arg _15, arg _16) -> [L4] =sink(name this[].matchDirs, arg _17) goto [L6] scope: def _18: seq[string] = @[] =sink(name this[].matchDirs, arg _18) L6: - goto [L4, L7] + =destroy(name par) + goto [L7] finally (L4): =destroy(name par) - continue {L7} + continue [Resume] L7: -- end of expandArc ------------------------''' diff --git a/tests/arc/topt_no_loop_cursor.nim b/tests/arc/topt_no_loop_cursor.nim index 8f5de25f8ea..dc27f376264 100644 --- a/tests/arc/topt_no_loop_cursor.nim +++ b/tests/arc/topt_no_loop_cursor.nim @@ -19,18 +19,20 @@ scope: goto [L2] def y: Object = () def_cursor _5: Object = x - use(arg _5) -> [L3, L4, Resume] + use(arg _5) -> [L3] x = sink y - goto [L3, L5] + destroy y + goto [L4] finally (L3): destroy y - continue {L4, L5} - L5: + continue [L5] + L4: L2: - goto [L4, L6] - finally (L4): + destroy x + goto [L6] + finally (L5): destroy x - continue {L6} + continue [Resume] L6: -- end diff --git a/tests/arc/topt_refcursors.nim b/tests/arc/topt_refcursors.nim index 7db1110c098..35f305b2900 100644 --- a/tests/arc/topt_refcursors.nim +++ b/tests/arc/topt_refcursors.nim @@ -42,19 +42,19 @@ scope: =copy(name ri, arg _18[].ri) def_cursor _19: Node = jt def_cursor _20: string = _19[].s - echo(arg type(array[0..0, string]), arg _20) -> [L6, L7, Resume] + echo(arg type(array[0..0, string]), arg _20) -> [L6] =sink(name jt, arg ri) - wasMoved(name ri) - goto [L6, L8] + goto [L7] finally (L6): =destroy(name ri) - continue {L7, L8} - L8: + continue [L8] + L7: L5: - goto [L7, L9] - finally (L7): + =destroy(name jt) + goto [L9] + finally (L8): =destroy(name jt) - continue {L9} + continue [Resume] L9: -- end of expandArc ------------------------''' diff --git a/tests/arc/topt_wasmoved_destroy_pairs.nim b/tests/arc/topt_wasmoved_destroy_pairs.nim index 4475c61e52f..a1778fdb5b1 100644 --- a/tests/arc/topt_wasmoved_destroy_pairs.nim +++ b/tests/arc/topt_wasmoved_destroy_pairs.nim @@ -6,7 +6,7 @@ discard """ scope: def a: seq[seq[int]] def b: seq[seq[int]] - def x: seq[int] = f() -> [L0, Resume] + def x: seq[int] = f() -> [L0] scope: if cond: scope: @@ -16,11 +16,12 @@ scope: scope: def _6: seq[int] = move x add(name b, consume _6) - goto [L0, L3] + L2: + =destroy(name b) + =destroy(name a) + goto [L3] finally (L0): - =destroy(name b) - =destroy(name a) - continue {L3} + continue [Resume] L3: -- end of expandArc ------------------------ --expandArc: tfor @@ -28,7 +29,7 @@ scope: scope: def a: seq[seq[int]] def b: seq[seq[int]] - def x: seq[int] = f() -> [L0, Resume] + def x: seq[int] = f() -> [L0] scope: def a: int = 0 def b: int = 4 @@ -50,34 +51,35 @@ scope: def _13: bool = eqI(arg i, arg 2) if _13: scope: - goto [L5, L0, L6] + =destroy(name x) + =destroy(name a) + goto [L5] def _14: seq[int] =copy(name _14, arg x) add(name a, consume _14) - i = addI(arg i, arg 1) -> [L5, L0, Resume] + i = addI(arg i, arg 1) -> [L6] L3: scope: if cond: scope: def _15: seq[int] = move x - wasMoved(name x) add(name a, consume _15) goto [L8] scope: def _16: seq[int] = move x - wasMoved(name x) add(name b, consume _16) L8: - goto [L5, L0, L9] - finally (L5): + =destroy(name b) + =destroy(name a) + goto [L9] + finally (L6): =destroy(name x) - continue {L0} + continue [L0] finally (L0): - =destroy(name b) =destroy(name a) - continue {L6, L9} + continue [Resume] L9: -L6: +L5: -- end of expandArc ------------------------ --expandArc: texit scope: @@ -86,7 +88,8 @@ scope: scope: if cond: scope: - goto [L1, L2] + =destroy(name x) + goto [L1] def _4: string = boolToStr(arg cond) str := move _4 scope: @@ -94,15 +97,11 @@ scope: if _5: scope: result := move str - wasMoved(name str) - goto [L1, L2] - goto [L1, L4] - finally (L1): - =destroy(name x) - =destroy(name str) - continue {L2, L4} - L4: -L2: + =destroy(name x) + goto [L1] + =destroy(name x) + =destroy(name str) +L1: -- end of expandArc ------------------------''' """ diff --git a/tests/lang_objects/destructor/tv2_cast.nim b/tests/lang_objects/destructor/tv2_cast.nim index 65e884caa7b..fe9c69b3861 100644 --- a/tests/lang_objects/destructor/tv2_cast.nim +++ b/tests/lang_objects/destructor/tv2_cast.nim @@ -9,16 +9,17 @@ scope: def _2: string = newString(arg 100) def_cursor _3: seq[byte] = cast _2 def _4: openArray[byte] = toOpenArray _3 - def _5: seq[byte] = encode(arg _4) -> [L0, Resume] + def _5: seq[byte] = encode(arg _4) -> [L0] def_cursor _6: string = cast _5 def data: string =copy(name data, arg _6) =destroy(name data) =destroy(name _5) - goto [L0, L1] + =destroy(name _2) + goto [L1] finally (L0): =destroy(name _2) - continue {L1} + continue [Resume] L1: -- end of expandArc ------------------------ --expandArc: main1 @@ -26,51 +27,54 @@ scope: def s: string = newString(arg 100) def_cursor _3: string = s def _4: int = lengthStr(arg _3) - def _5: int = subI(arg _4, arg 1) -> [L0, Resume] - chckBounds(arg s, arg 0, arg _5) -> [L0, Resume] + def _5: int = subI(arg _4, arg 1) -> [L0] + chckBounds(arg s, arg 0, arg _5) -> [L0] def _6: openArray[byte] = toOpenArray s, 0, _5 - def _7: seq[byte] = encode(arg _6) -> [L0, Resume] + def _7: seq[byte] = encode(arg _6) -> [L0] def_cursor _8: string = cast _7 def data: string =copy(name data, arg _8) =destroy(name data) =destroy(name _7) - goto [L0, L1] + =destroy(name s) + goto [L1] finally (L0): =destroy(name s) - continue {L1} + continue [Resume] L1: -- end of expandArc ------------------------ --expandArc: main2 scope: def s: seq[byte] = newSeq(arg 100) -> [Resume] def _3: openArray[byte] = toOpenArray s - def _4: seq[byte] = encode(arg _3) -> [L0, Resume] + def _4: seq[byte] = encode(arg _3) -> [L0] def_cursor _5: string = cast _4 def data: string =copy(name data, arg _5) =destroy(name data) =destroy(name _4) - goto [L0, L1] + =destroy(name s) + goto [L1] finally (L0): =destroy(name s) - continue {L1} + continue [Resume] L1: -- end of expandArc ------------------------ --expandArc: main3 scope: def _2: seq[byte] = newSeq(arg 100) -> [Resume] def _3: openArray[byte] = toOpenArray _2 - def _4: seq[byte] = encode(arg _3) -> [L0, Resume] + def _4: seq[byte] = encode(arg _3) -> [L0] def_cursor _5: string = cast _4 def data: string =copy(name data, arg _5) =destroy(name data) =destroy(name _4) - goto [L0, L1] + =destroy(name _2) + goto [L1] finally (L0): =destroy(name _2) - continue {L1} + continue [Resume] L1: -- end of expandArc ------------------------''' """