June 29, 2017
On Thursday, 29 June 2017 at 01:37:17 UTC, H. S. Teoh wrote:
> On Thu, Jun 29, 2017 at 01:22:31AM +0000, Mark via Digitalmars-d wrote: [...]
>> So basically, I'd like the ability to implement fairly simple contracts (with a similar level of sophistication to the above examples) that the compiler can check for me. I don't know, maybe this is easier to implement using UDAs...
>
> One idea I have is that the compiler could recognize certain straightforward contracts (like int < value) and use VRP (value range propagation) to detect cases where it's clear that the contract would be violated.
>
> However, this can only be done in a very rudimentary fashion, because:
>
> (1) DbC contracts pertain to *runtime* argument values, so while
> checking for simple cases at compile-time is nice, it isn't really in
> the charter of (D's implementation of) DbC.
>
> (2) VRP in the compiler currently only works within a very limited
> scope, IIRC within a single expression. So while it may detect the
> `foo(bar())` case, it probably won't detect the `x=bar(); foo(x);` case.
> Ostensibly the scope of VRP ought to be expanded, however:
>
> (3) In the past Walter has shown some reluctance in adding features that hurt compilation time; if a more sophisticated implementation of VRP is required and it's deemed too expensive in terms of compilation time, Walter may veto it.
>
> (4) Arbitrarily complex boolean conditions are undecidable in general, so unless you have a way to solve the halting problem, a general solution is intractible.  Of course, the kind of conditions you find in contracts generally ought to be nowhere near the halting problem in complexity, but it's not clear how far one can go without running the risk of (3).  My guess is that something based on VRP is the most likely to materialize in the foreseeable future.
>
>
> T

https://github.com/dlang/dmd/pull/3799
June 29, 2017
On Thu, Jun 29, 2017 at 08:22:50AM +0000, via Digitalmars-d wrote:
> On Thursday, 29 June 2017 at 01:37:17 UTC, H. S. Teoh wrote:
[...]
> > One idea I have is that the compiler could recognize certain straightforward contracts (like int < value) and use VRP (value range propagation) to detect cases where it's clear that the contract would be violated.
[...]
> https://github.com/dlang/dmd/pull/3799

Haha, funny, I've seen that PR before but totally forgot about it. Seems to have reached an impasse, unfortunately.  Seems that Walter and other are not perfectly happy with it, and handing contracts off to CTFE raises other issues.


T

-- 
Some days you win; most days you lose.
June 30, 2017
On Thursday, 29 June 2017 at 01:37:17 UTC, H. S. Teoh wrote:
> (1) DbC contracts pertain to *runtime* argument values, so while
> checking for simple cases at compile-time is nice, it isn't really in
> the charter of (D's implementation of) DbC.
>
>
> T

That's a good point.

I guess UDAs combined with static assert is the right way to implement compile-time checkable contracts. This seems to be the approach taken by Andrei in his Big O notation library [1].

Anyway, contracts are still useful for documentation purposes, as was pointed out. Personally I like them because they encourage me to think carefully about the preconditions and postconditions of the functions I write.

[1] http://forum.dlang.org/post/mailman.898.1482091540.9448.digitalmars-d@puremagic.com
July 04, 2017
On Tuesday, 20 June 2017 at 11:57:55 UTC, Mike Parker wrote:
> DIP 1009 is titled "Improve Contract Usability".
>
> https://github.com/dlang/DIPs/blob/master/DIPs/DIP1009.md
>
> All review-related feedback on and discussion of the DIP should occur in this thread. The review period will end at 11:59 PM ET on July 3 (3:59 AM GMT July 4), or when I make a post declaring it complete.
>

So this review period is now closed. Thanks to all who participated.
4 5 6 7 8 9 10 11 12 13 14
Next ›   Last »