NimContracts icon indicating copy to clipboard operation
NimContracts copied to clipboard

Potential for static verification?

Open hcphoenix opened this issue 6 years ago • 2 comments

I'm getting from the readme and skimming the source that all contracts are evaluated at runtime, right?

I'm very interested in the possibility of static verification--see the .NET Code Contracts library for one example of this. I ask because if this isn't currently suppported then it's something I'm interested in working on, and I suspect that Nim's AST manipulation features are robust enough to allow it.

hcphoenix avatar Apr 29 '18 03:04 hcphoenix

Sorry to answer after such a long time.

Yes, I know about static verification tools for .NET, JVM and many others, but it's not currently supported by NimContracts. Nim's AST can, of course, give you much information about the code itself, but in itself, it doesn't have much static analysis power (even though compiler does has some). One of the problems is that Nim's macros are written for simplicity rather than providing the user with absolutely every bit of information available, so pretty much the whole engine would need to be written separately or as a serious plug-in to the compiler. In fact, it seems to me it should be an external program to be run on the code rather than just the compiler running checks before compiling... unless you write that program in Nim and provide a macro to run it during compilation.

As for now, I don't really have time to work on a Nim static analysis tool but feel free to use NimContracts for that if you see it fit. I hope to try my best on that one day too.

Anyway: thank you for asking. :) Good to see that there are people actually interested in that topic.

Udiknedormin avatar Aug 07 '18 21:08 Udiknedormin

Update: I can see Nim version 1.2 added built-in support for pragmas with almost the same names as the ones used by NimContracts. I think it might be a good point to consider using those, as any external tools can be expected to operate on them.

Udiknedormin avatar May 05 '20 15:05 Udiknedormin