www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - template constraint diagnostics

reply "Trass3r" <un known.com> writes:
http://youtu.be/qwXq5MqY2ZA?t=33m57s

I wish we had diagnostics like that in D.
Oct 15 2014
next sibling parent reply "Atila Neves" <atila.neves gmail.com> writes:
Same here. I've been thinking of a DIP for a while, just haven't 
had time to put it together.

Atila

On Wednesday, 15 October 2014 at 17:29:35 UTC, Trass3r wrote:
 http://youtu.be/qwXq5MqY2ZA?t=33m57s

 I wish we had diagnostics like that in D.
Oct 16 2014
parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 10/16/14 4:21 AM, Atila Neves wrote:
 Same here. I've been thinking of a DIP for a while, just haven't had
 time to put it together.

 Atila

 On Wednesday, 15 October 2014 at 17:29:35 UTC, Trass3r wrote:
 http://youtu.be/qwXq5MqY2ZA?t=33m57s

 I wish we had diagnostics like that in D.
It would be nice. I don't think it would be too difficult. You are analyzing an expression that evaluates to false, and it wouldn't take much to dig down to find out which subexpressions cause the false to occur. -Steve
Oct 16 2014
parent reply "Trass3r" <un known.com> writes:
 I don't think it would be too difficult. You are analyzing an 
 expression that evaluates to false, and it wouldn't take much 
 to dig down to find out which subexpressions cause the false to 
 occur.
I think it's not that straightforward in dmd as it simply delegates the constraint to the interpreter and uses the resulting bool.
Oct 16 2014
parent reply ketmar via Digitalmars-d <digitalmars-d puremagic.com> writes:
On Thu, 16 Oct 2014 21:12:16 +0000
Trass3r via Digitalmars-d <digitalmars-d puremagic.com> wrote:

 I think it's not that straightforward in dmd as it simply=20
 delegates the constraint to the interpreter and uses the=20
 resulting bool.
as there is no parallel execution, evaluator can store results in expression objects. and then simple visitor can do what it wants with this results.
Oct 16 2014
parent reply Marco Leise <Marco.Leise gmx.de> writes:
Am Fri, 17 Oct 2014 00:18:08 +0300
schrieb ketmar via Digitalmars-d <digitalmars-d puremagic.com>:

 On Thu, 16 Oct 2014 21:12:16 +0000
 Trass3r via Digitalmars-d <digitalmars-d puremagic.com> wrote:
=20
 I think it's not that straightforward in dmd as it simply=20
 delegates the constraint to the interpreter and uses the=20
 resulting bool.
as there is no parallel execution, evaluator can store results in expression objects. and then simple visitor can do what it wants with this results.
ketmar gtfo ... oh wait, that's a great idea actually! --=20 Marco
Oct 16 2014
parent reply ketmar via Digitalmars-d <digitalmars-d puremagic.com> writes:
On Fri, 17 Oct 2014 08:00:03 +0200
Marco Leise via Digitalmars-d <digitalmars-d puremagic.com> wrote:

 ketmar gtfo ... oh wait, that's a great idea actually!
;-)
Oct 17 2014
parent "market" <dont spam.me> writes:
On Friday, 17 October 2014 at 13:22:26 UTC, ketmar via
Digitalmars-d wrote:
 On Fri, 17 Oct 2014 08:00:03 +0200
 Marco Leise via Digitalmars-d <digitalmars-d puremagic.com> 
 wrote:

 ketmar gtfo ... oh wait, that's a great idea actually!
;-)
it is! ketmar ctfb
Oct 17 2014
prev sibling parent reply Shammah Chancellor <email domain.com> writes:
On 2014-10-15 17:29:33 +0000, Trass3r said:

 http://youtu.be/qwXq5MqY2ZA?t=33m57s
 
 I wish we had diagnostics like that in D.
I have answered your call: https://github.com/D-Programming-Language/phobos/pull/2627 Please comment. -S.
Oct 18 2014
parent reply Shammah Chancellor <email domain.com> writes:
On 2014-10-18 21:52:30 +0000, Shammah Chancellor said:

 On 2014-10-15 17:29:33 +0000, Trass3r said:
 
 http://youtu.be/qwXq5MqY2ZA?t=33m57s
 
 I wish we had diagnostics like that in D.
I have answered your call: https://github.com/D-Programming-Language/phobos/pull/2627 Please comment. -S.
I don't know if anyone looked at this yet, but I've updated it quite a bit since the original post. Please take a look again and comment. It also generates some useful DDoc now. Docs: bool isConcept(T, C, bool diagnostics = false, string errorPrefix = "")(); Returns true if T supports the concept C. Note, templated member functions are not supported currently. Concepts should be defined as in the following example: ---- class CInputRange(E) : Concept { abstract void popFront(); property abstract E front(); bool empty; //Optional Axioms function. This will be checked if it compiles, and that it returns true if it does. static bool Axioms(T)() { return true; } } class CInfinite() : Concept { static bool Axioms(T)() { enum empty = T.empty; return !empty; } } class CInfiniteInputRange(E) : CInputRange!E { mixin CInfinite; } --- template conceptDiagnostic(R, string F, int L, C...) Prints error messages for why template instantiation failed. Examples: --- bool DoStuff(R)(R infRange) if ( isConcept!(R, CInfiniteInputRange!string)) { return true; } bool DoStuff(R)(R infRange) if ( isConcept!(R, COutputRange!string)) { return true; } //Example of using conceptDiagnostic bool DoStuff(R, string F = __FILE__, size_t L = __LINE__ )(R infRange) { mixin conceptDiagnostic!(R, F, L, COutputRange!string, CInfiniteInputRange!string); return false; } --- class Concept; Base class for Concepts. All Concepts should derive from this, or another concept.
Oct 18 2014
parent "Vlad Levenfeld" <vlevenfeld gmail.com> writes:
I have something like this for mixin interfaces that require that 
the host struct support certain semantics. There's a Traits 
struct (concept-ish) that takes a set of strings for trait 
identifiers and their definitions (which is some code that 
compiles if and only if the trait is satisfied).

The Traits struct has a member mixin template, "require", which 
can be used by the interface that instantiated the Traits. When 
one of the mixed-in requirements is failed, the compiler 
generates an error message like this:

source/evx/meta/traits/generator.d-mixin-49(50): Error: static 
assert  "MyStruct must support {size_t x = buffer.length;} to 
enable TransferOps."

Not as nice as a compiler-aided concept solution but I have been 
pretty happy with it so far. It doesn't take me long to forget 
what some interface requirements are, and this way the compiler 
can explicitly guide me.
Oct 18 2014