digitalmars.D - template constraint diagnostics
- Trass3r (2/2) Oct 15 2014 http://youtu.be/qwXq5MqY2ZA?t=33m57s
- Atila Neves (4/6) Oct 16 2014 Same here. I've been thinking of a DIP for a while, just haven't
- Steven Schveighoffer (6/13) Oct 16 2014 It would be nice.
- Trass3r (3/7) Oct 16 2014 I think it's not that straightforward in dmd as it simply
- ketmar via Digitalmars-d (5/8) Oct 16 2014 as there is no parallel execution, evaluator can store results in
- Marco Leise (5/14) Oct 16 2014 ketmar gtfo ... oh wait, that's a great idea actually!
- ketmar via Digitalmars-d (3/4) Oct 17 2014 ;-)
- market (3/8) Oct 17 2014 it is! ketmar ctfb
- Shammah Chancellor (5/8) Oct 18 2014 I have answered your call:
- Shammah Chancellor (57/70) Oct 18 2014 I don't know if anyone looked at this yet, but I've updated it quite a
- Vlad Levenfeld (16/16) Oct 18 2014 I have something like this for mixin interfaces that require that
http://youtu.be/qwXq5MqY2ZA?t=33m57s I wish we had diagnostics like that in D.
Oct 15 2014
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
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: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. -Stevehttp://youtu.be/qwXq5MqY2ZA?t=33m57s I wish we had diagnostics like that in D.
Oct 16 2014
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
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
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: =20ketmar gtfo ... oh wait, that's a great idea actually! --=20 MarcoI 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
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
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:it is! ketmar ctfbketmar gtfo ... oh wait, that's a great idea actually!;-)
Oct 17 2014
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
On 2014-10-18 21:52:30 +0000, Shammah Chancellor said:On 2014-10-15 17:29:33 +0000, Trass3r said: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.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
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