jyn514 / saltwater

A C compiler written in Rust, with a focus on good error messages.
BSD 3-Clause "New" or "Revised" License
294 stars 27 forks source link

Add preconditions and postconditions #417

Open jyn514 opened 4 years ago

jyn514 commented 4 years ago

https://docs.rs/contracts/0.4.0/contracts/

jyn514 commented 4 years ago

To avoid compiling this for end users, a friend suggested using a feature which is enabled by default only in dev mode:

[profile.dev]
features = ["contracts", "color-backtrace"]
karroffel commented 4 years ago

Just mentioning that contracts by default will always run, but you can use the override_debug feature to make them debug only. In that case no further profile configuration should be needed, at least for the contracts crate.

jyn514 commented 4 years ago

Just mentioning that contracts by default will always run, but you can use the override_debug feature to make them debug only. In that case no further profile configuration should be needed, at least for the contracts crate.

This will not run the contracts, but it will still compile the contracts crate.

karroffel commented 4 years ago

But compiling the attributes without the contracts crate will fail, unless I misunderstand how you intend to use the crate :upside_down_face:

jyn514 commented 4 years ago

Something like this:

#[cfg_attr(feature = "contracts", post(old(self.lval) || old(self) == ret))]
fn rval(self) -> Expr {
    unimplemented!();
}

That does seem super verbose though ...