Skip to content

Commit

Permalink
describe {.used.} tradeoffs
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck committed Jul 3, 2023
1 parent 806891a commit e023e37
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion chronos/asyncmacro2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,19 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
nnkElseExpr.newTree(
newStmtList(
quote do: {.push warning[resultshadowed]: off.},
# var result: `baseType`
# var result {.used.}: `baseType`
# In the proc body, result may or may not end up being used
# depending on how the body is written - with implicit returns /
# expressions in particular, it is likely but not guaranteed that
# it is not used. Ideally, we would avoid emitting it in this
# case to avoid the default initializaiton. {.used.} typically
# works better than {.push.} which has a tendency to leak out of
# scope.
# TODO figure out if there's a way to detect `result` usage in
# the proc body _after_ template exapnsion, and therefore
# avoid creating this variable - one option is to create an
# addtional when branch witha fake `result` and check
# `compiles(procBody)` - this is not without cost though
nnkVarSection.newTree(nnkIdentDefs.newTree(
nnkPragmaExpr.newTree(
ident "result",
Expand Down

0 comments on commit e023e37

Please sign in to comment.