Asking for code review - contract programming

max haughton maxhaton at gmail.com
Mon Jan 24 12:46:59 UTC 2022


On Monday, 24 January 2022 at 12:41:40 UTC, Mark wrote:
> On Tuesday, 11 January 2022 at 17:40:48 UTC, Ali Cehreli wrote:
>> The following invariant check might be a 'static assert':
>>
>>   
>> https://github.com/Fr3nchK1ss/SnakeD/blob/master/source/ground.d#L26
>>
>> (invariant has runtime cost.)
>>
>> Ali
>
> Does the compiler not rewrite `assert`s into `static assert`s 
> if there is no dependence on runtime values? Maybe this is a 
> worthwhile optimization to implement.

https://d.godbolt.org/z/46q6osKjK The assertions must still 
happen at runtime, however if the compiler can prove (as it does 
with *any* function) that it cannot be called then it will elide 
the assert.


More information about the Digitalmars-d mailing list