DIP30, delegates more destruction for your pleasure

deadalnix deadalnix at gmail.com
Thu Mar 14 08:41:13 PDT 2013


On Thursday, 14 March 2013 at 11:42:29 UTC, Timon Gehr wrote:
> On 03/14/2013 04:12 AM, deadalnix wrote:
>> ...
>>>
>>
>> It is a tempting idea, but do not work. Consider :
>>
>> void delegate() immutable a;
>> const void delegate() b = a;
>>
>> This would be forbidden as covariance of function parameters 
>> and
>> transitivity act in opposite directions.
>
> Uh, why?
>
> In my current opinion, it should be as follows:
>
> void main(){
> 	void delegate()inout w;
> 	void delegate()immutable i;
> 	void delegate()const c;
> 	void delegate() m;
> 	void delegate()const inout wc;
> 	
> 	// The following cases should be disallowed:
> 	
> 	i=c; // there may be mutable references to context
> 	c=m; // m may modify context
> 	i=m; // m may modify context
> 	w=i; // cannot use immutable as const or mutable
> 	w=m; // cannot use mutable as immutable
> 	w=c; // cannot use const as immutable
> 	wc=m;// cannot use mutable as immutable
> 	wc=c;// wc will access context as const or immutable
> 	i=w; // inout could mean const or mutable
> 	c=w; // inout could mean mutable
> 	i=wc; // inout const could mean const
>
> 	// These should be allowed:
> 	
> 	c=i; // certainly const if only immutable data accessed
> 	c=wc;// certainly const if only const inout data accessed
> 	m=c; // just loses guarantees to caller
> 	m=i; // ditto
> 	m=w; // ditto
> 	m=wc;// ditto
> 	w=wc;// m=c, c=c and i=i are valid
> 	wc=i;// c=i and i=i are valid
> 	wc=w;// c=m is not valid, but does the same thing as c=c here
> }
>
> If you disagree with one of them, please demonstrate how to 
> break the type system using the conversion, or argue why a 
> conversion would be valid.

DIP updated.

The loss of information in cases like m=i causes problem when the 
copy or the destruction of the context isn't trivial.

Cases like c=m must be enabled as they will happen anyway by 
transitivity (or we must prevent delegate call when the type 
qualifier is changed via transitivity which seem worse to me).

inout const isn't a valid type qualifier so I dropped it.


More information about the Digitalmars-d mailing list