Just a follow up:
It is possible to do it with a cond-expand, as the gerbil compiler can detect when it is compiling with (not safe). The contract check in the generated code would be at the function entry point and look like: (cond-expand (gerbil-runtime-checks ...) ;; do checks and raise exception if the contract is violated (else))
When the compiler detects that it is in a safe context (absence of a local or prelude (not safe) declaration), then it can emit a (define-cond-expand-feature|gerbil-runtime-checks|) for gsc, and compile in the contract checks.
This is a reasonably good solution, so there is no pressing need to add a construct to gambit that conditionally compiles based on declarations.
-- vyzo
On Tue, Nov 26, 2019 at 8:39 PM Dimitris Vyzovitis vyzo@hackzen.org wrote:
Is there a mechanism by which we can declare code to be eliminated when compiling with (declare (not safe))? I haven't been able to find anything, and it would be very nice to have something like (when-declare (safe) stuff ...), which would be eliminated in unsafe compilation. The context is that I want to add a contract system to Gerbil, but I don't want the runtime checks to persist when compiling with (not safe).
-- vyzo