Question about publishing a useful function I have written

Cecil Ward cecil at cecilward.com
Tue Jul 14 21:58:49 UTC 2020


I have written something which may or may not be novel and I’m 
wondering about how to distribute it to as many users as 
possible, hoping others will find it useful. What’s the best way 
to publish a D routine ?

It is called
     void assume( bool condition ) nothrow nogc safe

for example:
     assume( x < 100 );
or
     assume( y != 0 );

It generates no code at all, but t does tell the gdc compiler 
that the given condition is true and so later code generation may 
assume that truth in all code generation. So for example, given 
the assumes above,
     if ( x==200)
is false and no code is generated for the if-true basic block.

It might look a bit like assert but it isn’t the same thing. I 
think assert is disabled in full release build and is only there 
in debug mode, is that correct? Also assert generates code in 
that it calls panic or hits a ud2 or whatever, whereas assume is 
also zero code.

Does anyone know if this has already been published by someone 
else?

Unfortunately at the moment it only works with gdc as it relies 
on functions that are gdc-specific for its implementation. 
However I could use conditional compilation to simply set up a 
null implementation for other compilers.

I’d like to get it implemented with ldc if I can.


If anyone would like to give assume a try with gdc, then shout 
and I’ll try and find some way of getting it to you easily.


More information about the Digitalmars-d-learn mailing list