I know I can use -d:danger to deactivate runtime checks for the whole program, but let's assume I usually want the checks, but only deactivate them for a certain section of my code.
The manual describes pragmas to do this, so I can write
proc f() =
{.push checks: off.}
...
{.pop.}
Now, does the pragma only affect the code that is visible between the push and pop pragmas? In other words, in
proc g() =
...
proc f() =
{.push checks: off.}
...
g()
...
{.pop.}
are the runtime checks also deactivated for g? Is there are difference if g is a template or macro?
If the pragmas affect also called code, this would mean that
proc g() =
...
proc f1() =
{.push checks: off.}
...
g()
...
{.pop.}
proc f2() =
...
g()
...
generates two versions of g, one without runtime checks (called from f1) and one with runtime checks (called from f2). Correct?
If the compiler can indeed generate different versions of a proc depending on pragmas, does this also extend to code in other modules (for example, if I call code in algorithms that actually does most of the work in my proc)?
One extra question, not directly related to the one above: Is there a difference in the generated code for
# Pragmas inside the proc
proc f() =
{.push checks: off.}
...
{.pop.}
vs.
# Pragmas outside the proc
{.push checks: off.}
proc f() =
...
{.pop.}
are the runtime checks also deactivated for g? Is there a difference if g is a template or macro?
No, yes. Templates/macros "insert" the code into the proc so it is affected by the checks, whereas proc calls merely call already generated code elsewhere, in this case g was not instantiated with checks: off so it will have checks on inside it. Nim cannot track these pragma changes and generate a new proc every time.
One extra question, not directly related to the one above: Is there a difference in the generated code for
I see no reason for there to be a difference