www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Advanced const propagation for structs

reply Ilya Yaroshenko <ilyayaroshenko gmail.com> writes:
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
Oct 16 2016
next sibling parent reply Dicebot <public dicebot.lv> writes:
 protected-headers="v1"
From: Dicebot <public dicebot.lv>
Newsgroups: d,i,g,i,t,a,l,m,a,r,s,.,D
Subject: Re: Advanced const propagation for structs
References: <tdsvyuhuamgfibbdszev forum.dlang.org>
In-Reply-To: <tdsvyuhuamgfibbdszev forum.dlang.org>

--MvFDN3d2B4TOF1p20oWssvIM6KtBXMW9o
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

On 10/16/2016 11:36 AM, Ilya Yaroshenko wrote:
 Hi,
=20
 Extern precompiled Mir GLAS requires additional API changes.
 Reduced example:
=20
 ```d
 struct S(T)
 {
   size_t len;
   T ptr;
 }
=20
 auto foo(S!(const(double)*) sl)
 {
 }
=20
 S!(double*) a;
 const S!(double*) b;
=20
 foo(a); // fails
 foo(b); // fails
=20
 ```
=20
 https://issues.dlang.org/show_bug.cgi?id=3D16616
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) =3D=3D 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 --MvFDN3d2B4TOF1p20oWssvIM6KtBXMW9o--
Oct 16 2016
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
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.
Oct 16 2016
parent reply Dicebot <public dicebot.lv> writes:
 protected-headers="v1"
From: Dicebot <public dicebot.lv>
Newsgroups: d,i,g,i,t,a,l,m,a,r,s,.,D
Subject: Re: Advanced const propagation for structs
References: <tdsvyuhuamgfibbdszev forum.dlang.org>
 <ntvr78$lqv$1 digitalmars.com> <nu0t4o$29gm$1 digitalmars.com>
In-Reply-To: <nu0t4o$29gm$1 digitalmars.com>

--kpG8st2RHWWcsg4MqkVrURmdHgwm5DotQ
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

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 a=
nd
 AFAIK so far no one was able to come up with even theoretical concept =
of
 how it can be possibly addressed.
=20 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. --kpG8st2RHWWcsg4MqkVrURmdHgwm5DotQ--
Oct 16 2016
parent Timon Gehr <timon.gehr gmx.ch> writes:
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
Oct 17 2016
prev sibling parent reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
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?
Oct 16 2016
parent Ilya Yaroshenko <ilyayaroshenko gmail.com> writes:
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
Oct 16 2016