Skip to content

Clarification on generating contracts in release mode. #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
thindil opened this issue Jul 31, 2022 · 3 comments
Open

Clarification on generating contracts in release mode. #18

thindil opened this issue Jul 31, 2022 · 3 comments

Comments

@thindil
Copy link
Contributor

thindil commented Jul 31, 2022

Documentation says that NimContracts doesn't generate any code for runtime when build with release mode. But the code says something different. 😄 The contracts are not generated only when assertions are disabled during compilation. They are enabled by default for -d:release mode, at least for Nim 1.6.6. Thus, my question is, who is right? The documentation or the code? 😉

Personally, I would prefer to go in the documentation way, enable generation of contracts only when a code is compiled in debug mode. If this version preferred, I can create PR with proper changes, it should be a small patch.

@Udiknedormin
Copy link
Owner

Udiknedormin commented Sep 26, 2022

It may be that Nim's default behavior changed since back when this library was written, as it was before 1.0. You're correct to assume the intention is still to not generate any runtime checks for -d:release.

Thank you for your offer of help too, it is very welcome.

@Udiknedormin
Copy link
Owner

I also found the part of Nim docs about that:

From Nim 0.20:

The compiler may not generate any code at all for assert if it is advised to do so through the -d:release or --assertions:off command line switches.

Same for 1.0.0, 1.2.0 and 1.4.0 --- the change has only been introduced in Nim 1.6.0:

No code will be generated for assert when passing -d:danger (implied by --assertions:off). See command line switches.

That being said, I looked through the NimContracts documentation and I haven't found any explicit mention of -d:release flag. There are two fragments that may suggest it, although implicitly:

From ghost:

As both ghost code and contracts are assertion-lived, release code will be equivalent to:

Which, indeed, uses the term "release code", but it is described which flag to use right above (which still holds true):

Marks ghost code, only used for tests and static analysis.
It can be turned on or off by assertions compiler flag.

However, from the FAQ:

Contra: Use when defined(release): or when defined(contracts):
Contracts: True.

Because the default Nim behavior changed, I'd rather change it back and update the docs of ghost, rather than changing the default behavior of the -d:release mode for Nim version >= 1.6.0.

Udiknedormin added a commit that referenced this issue Sep 26, 2022
…_release

no checks for release mode; even for Nim 1.6.0 (Issue #18)
@thindil
Copy link
Contributor Author

thindil commented Sep 26, 2022

Ah, thank you very much, for the clarification and your work. I agree with the solution. I think, the issue can be closed.

Have a nice time. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants