A Nimble module when you need a parachute !
This is a simple Nimble module that uses that uses tag tracking to track usage of addr
, cast
, unsafeAddr
.
It also defines unsafe
template that simple {.push: tags[Unsafe].}
to the scope.
Parachute defines castTag
, addrTag
and unsafeAddrTag
, that simply calls the system
version while adding tags: [Unsafe]
.
Once the tags is present, it is trivial to allow/forbid tags at compile time. Read Nim's manual for more detailed information.
To avoid having to change too much your code, there is a small macro openParachute()
which declare addr
and unsafeAddr
as templates.
Since addr
cannot be overloaded, it will have to be excluded from system
.
In short, if you want to use the tagged version of addr
and unsafeAddr
do the following in your file :
import system except addr
import parachute
openParachute
This way of doing things avoid exporting addr``and ``unsafeAddr
identifier that would potentially collide.
Since cast
is a keyword of the language, it cannot be replaced or used as an identifier.
This means that for use the tagged version of cast you have to explicitly call castTag
.
But since cast
is most often called in conjonction with addr
or unsafeAddr
, it should be too impactful.
The documentation is accessible here .
Look into the tests/
folder for more elaborate examples.
What really would improve this concept would be:
- Being able to remove a tag. This would make wrapping unsafe code a breeze !
- Being able to "forbid" a tag without filtering every offet effects. Something like
{.tags: [not Unsafe].}
to explicitly forbid a tags without failing to compile on others.