Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
October 16, 2016 Advanced const propagation for structs | ||||
---|---|---|---|---|
| ||||
Hi, Extern precompiled Mir GLAS requires additional API changes. Reduced example: ```d struct S(T) { size_t len; T ptr; } auto foo(S!(const(double)*) sl) { } S!(double*) a; const S!(double*) b; foo(a); // fails foo(b); // fails ``` https://issues.dlang.org/show_bug.cgi?id=16616 |
October 16, 2016 Re: Advanced const propagation for structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Yaroshenko Attachments:
| On 10/16/2016 11:36 AM, Ilya Yaroshenko wrote:
> Hi,
>
> Extern precompiled Mir GLAS requires additional API changes. Reduced example:
>
> ```d
> struct S(T)
> {
> size_t len;
> T ptr;
> }
>
> auto foo(S!(const(double)*) sl)
> {
> }
>
> S!(double*) a;
> const S!(double*) b;
>
> foo(a); // fails
> foo(b); // fails
>
> ```
>
> https://issues.dlang.org/show_bug.cgi?id=16616
This issue has been discussed before in context of custom containers and AFAIK so far no one was able to come up with even theoretical concept of how it can be possibly addressed. The issue is crazy complicated because of how D templates work:
struct S (T)
{
static if (is(typeof(T) == const))
int a;
else
string a;
}
const S!(int) one;
S!(const int) two;
pragma(msg, typeof(one.a)); // string
pragma(msg, typeof(two.a)); // int
|
October 16, 2016 Re: Advanced const propagation for structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Yaroshenko | On Sunday, 16 October 2016 at 08:36:17 UTC, Ilya Yaroshenko wrote:
> Hi,
>
> Extern precompiled Mir GLAS requires additional API changes.
> Reduced example:
>
> ```d
> struct S(T)
> {
> size_t len;
> T ptr;
> }
>
> auto foo(S!(const(double)*) sl)
> {
> }
>
> S!(double*) a;
> const S!(double*) b;
>
> foo(a); // fails
> foo(b); // fails
>
> ```
>
> https://issues.dlang.org/show_bug.cgi?id=16616
Is there a way to say "the constness (and/or immutability) of this type is dependent on the type of a template parameter". i.e. signal that const A!B is interchangeable with A!(const B) and const A!(const B)?
If not does it make sense to add this?
|
October 16, 2016 Re: Advanced const propagation for structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicholas Wilson | On Sunday, 16 October 2016 at 13:17:09 UTC, Nicholas Wilson wrote: > On Sunday, 16 October 2016 at 08:36:17 UTC, Ilya Yaroshenko wrote: >> Hi, >> >> Extern precompiled Mir GLAS requires additional API changes. >> Reduced example: >> >> ```d >> struct S(T) >> { >> size_t len; >> T ptr; >> } >> >> auto foo(S!(const(double)*) sl) >> { >> } >> >> S!(double*) a; >> const S!(double*) b; >> >> foo(a); // fails >> foo(b); // fails >> >> ``` >> >> https://issues.dlang.org/show_bug.cgi?id=16616 > > Is there a way to say "the constness (and/or immutability) of this type is dependent on the type of a template parameter". i.e. signal that const A!B is interchangeable with A!(const B) and const A!(const B)? > > If not does it make sense to add this? A workaround was found https://github.com/dlang/phobos/pull/4869 |
October 16, 2016 Re: Advanced const propagation for structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot | On 16.10.2016 14:18, Dicebot wrote:
> This issue has been discussed before in context of custom containers and
> AFAIK so far no one was able to come up with even theoretical concept of
> how it can be possibly addressed.
Actually, I did propose a solution before. Just allow annotations on template type parameters (to enable the new implicit upcasts) and check for binary compatibility of the respective template instances during implicit conversion.
|
October 17, 2016 Re: Advanced const propagation for structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr Attachments:
| On 10/17/2016 12:57 AM, Timon Gehr wrote:
> On 16.10.2016 14:18, Dicebot wrote:
>> This issue has been discussed before in context of custom containers and AFAIK so far no one was able to come up with even theoretical concept of how it can be possibly addressed.
>
> Actually, I did propose a solution before. Just allow annotations on template type parameters (to enable the new implicit upcasts) and check for binary compatibility of the respective template instances during implicit conversion.
Can you find a link to that post? I don't remember anything like that.
|
October 17, 2016 Re: Advanced const propagation for structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot | On 17.10.2016 05:29, Dicebot wrote: > On 10/17/2016 12:57 AM, Timon Gehr wrote: >> On 16.10.2016 14:18, Dicebot wrote: >>> This issue has been discussed before in context of custom containers and >>> AFAIK so far no one was able to come up with even theoretical concept of >>> how it can be possibly addressed. >> >> Actually, I did propose a solution before. Just allow annotations on >> template type parameters (to enable the new implicit upcasts) and check >> for binary compatibility of the respective template instances during >> implicit conversion. > > Can you find a link to that post? I don't remember anything like that. > forum.dlang.org/post/lkfkel$2avp$1@digitalmars.com forum.dlang.org/post/ljrt6t$2fpc$1@digitalmars.com forum.dlang.org/post/ljt0mc$cto$1@digitalmars.com |
Copyright © 1999-2021 by the D Language Foundation