[gambit-list] Code elimination in (not safe) context

Marc Feeley feeley at iro.umontreal.ca
Wed Nov 27 09:41:58 EST 2019


I was going to suggest using the cond-expand approach.

Also, it might be interesting for the compiler to make the current declarations testable as cond-expand features.  Giving something like:

  (cond-expand ((declare (not safe))
                …)
               ((declare (debug))
                …)
               ((declare (optimize-dead-definitions))
                …)
               (else
                …))

The implementation of this is complicated by the fact that the interpreter and compiler don’t manage declarations the same way.

Marc



> On Nov 27, 2019, at 9:10 AM, Dimitris Vyzovitis <vyzo at hackzen.org> wrote:
> 
> 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 at 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





More information about the Gambit-list mailing list