Skip to content

Commit

Permalink
switch cps phases to use explicit calls instead of pragmas
Browse files Browse the repository at this point in the history
nim-lang/Nim#18349 shows that pragmas
calls are unreliable and bugs might make it way through a phase,
which makes it hard for us to debug
  • Loading branch information
alaviss authored and disruptek committed Jun 27, 2021
1 parent 57569b3 commit c0f61f8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cps/transform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1026,9 +1026,12 @@ proc cpsTransformProc(T: NimNode, n: NimNode): NimNode =
n.body.add newCpsPending()

# run other stages
n.addPragma(bindSym"cpsFloater")
n.addPragma(bindSym"cpsResolver", env.identity)
n.addPragma(bindSym"cpsManageException")
{.warning: "compiler bug workaround, see: https://github.com/nim-lang/Nim/issues/18349".}
let processMainContinuation =
newCall(bindSym"cpsFloater"):
newCall(bindSym"cpsResolver", env.identity):
newCall(bindSym"cpsManageException"):
n

# storing the source environment on helpers
for p in [whelp, booty]:
Expand All @@ -1041,7 +1044,7 @@ proc cpsTransformProc(T: NimNode, n: NimNode): NimNode =
env = env.storeType(force = off)

# generated proc bodies, remaining proc, whelp, bootstrap
result = newStmtList(types, n, dots, whelp, booty)
result = newStmtList(types, processMainContinuation, dots, whelp, booty)
result = workaroundRewrites result

macro cpsTransform*(T, n: typed): untyped =
Expand Down

0 comments on commit c0f61f8

Please sign in to comment.