Possible change to array runtime?

sclytrack sclytrack at fake.com
Mon Mar 17 09:24:47 PDT 2014


On Thursday, 13 March 2014 at 22:21:56 UTC, sclytrack wrote:

>
> 	Delayed D Language			D Normal
>
> 	immutable int * a;			int * a;
> 	immutable qual(int) * a;		immutable(int) * a;
> 	immutable int qual(*) a;		immutable int * a;
>
> 	-------------
>
> 	struct A
> 	{
> 		int a;
> 		qual(int) b;
> 	}
> 			
>
> 	A vari;
> 	const A cvari;
> 	vari.a = 1;
> 	cvari = vari;
> 	cvari.a = 2;
> 	cvari.b = 3;	//error
>
> 	-------------
>
> 	qual
> 	class Test
> 	{
> 	}
>
>
> 	Delayed D				D struct language
>
> 	immutable Test t;			immutable(Test) * t;
> 	immutable qual(Test) t; 		immutable Test * t;
>
> 	-------------
>
>
> 	struct Array(T)
> 	{
> 		qual(T) * data;
> 		size_t length;
> 	}
>
>
> 	Array!(int) a;	
> 	const Array!(int) b;
>
> 	void routine(const Array!(int) b)
> 	{
>
> 	}
>
> 	b = a;
> 	routine(a);

I'm not sure how to understand your change proposal, you should
explicit it more. But it seems that you get what the problem is
(or at least, you are poking the right language constructs in
your proposal).


qual would be the entry point of the qualifier so

immutable int * * * * qual(*) * * * data;

So everything to the left would be immutable and
everything to the right would be mutable.

	struct A
  	{
  		char [] a;
  		qual(char) [] b;
  	}

When defining const A data; Again the const
is delayed until the entry qual(int). So ...

A data;

	struct A
	{
		char [] a;
		char [] b;
	}

const A cdata;

	struct A
	{
		char [] a;
		const(char) [] b;
	}

immutable A idata;

	struct A
	{
		char [] a;
		immutable(char) [] b;
	}

All this A has a single memory layout and
a single qualifier that modifies them.

cdata = data;
cdata = idata;

---

	struct B
	{
		A data;
		qual(A) qdata;
	}

B bdata;

	struct B
	{
		A data;
		A qdata;
	}


const B cbdata;

	struct B
	{
		A data;
		const(A) qdata;     //struct A { char [] a; const(char) [] b; 
}		
	}

immutable B ibdata;

	struct B
	{
		A data;
		immutable(A) qdata;	//struct A { char [] a; immutable(char) [] 
b; }
	}


cbdata = bdata
cbdata = ibdata

For functions it the qualifier would also be delayed which
means having the word const in front of it doesn't necessarily
mean it is const.

void routine(const A * data)
{
	data.a = "modifiable";
}

If we are forcing a delayed qualifier on A we are forcing
the same one as the one on the pointer.

const A qual(*) data;

It is the same const applied to the pointer and the
struct A.

---

Okay now to more conventional D.

These two are more or less the same type.

Container!(PayloadType)
Container!(PayloadType, const)

The following two are different types.

Container!(PayloadType)
Container!(const(PayloadType))

---

Container!(PayloadType, const)

The qualifier can be applied to your payload
field and even none-payload fields.

The thing is only PayLoadType is part of the
type definition and the qualifier at the
end is not.

The qualifier at the end
must not participate in the type definition
in any way. Not in static if and so forth.
By some magic needs to be prevented.

Having to deal with a single qualifier
is much easier than having to deal with
the qualifier of every payload.



Again a bit of qual code.

struct Container!(PayloadType)
{
	qual(char) [] a;
	PayloadType payload;
}

PayloadType participates in the type and
sets the memory layout of the type.

Here the qualifier isn't even on the payload.

---

Container!(const(int), int, char [], const)

The first 3 define the type.

	(const(int), int, char [])

The last bit. The qualifier (const) of the
container does not participate
in the definition of the type.

---
For overloading there are too many options.

void routine( immutable Container!(int, const) data);		//a
void routine( immutable Container!(int, immutable) data);	//b

Here the first one (a) is not needed. In delayed qualifier D
this would be.

void routine(imutable qual(Container!(int)) data)		//b

Setting the qual in right in front of the container means that
immutable applies to all the fields of the Container!(int) and
not only those marked with qual.

---

In Normal D style

Existing style. Already possible.

void routine( Container!(int,  ) data);				//a
void routine( const Container!(int, const) data);		//b
void routine( immutable Container!(int, immutable) data);	//c

The new ones.

void routine( Container!(int, const ) data);	
void routine( Container!(int, immutable) data);

The nonsense ones.

void routine( const Container!(int, ) data);		
void routine( immutable Container!(int, const) data);

---


Anyways. Thank you for your time reading this mess.
	


More information about the Digitalmars-d mailing list