December 13, 2011
On 12/13/2011 11:28 AM, Timon Gehr wrote:
> On 12/13/2011 08:06 PM, Walter Bright wrote:
>> Is this bug and enhancement suggestion on bugzilla?
>
> I think the bug has just been fixed by Kenji Hara:
> https://github.com/D-Programming-Language/dmd/pull/558
>
> I have filed an enhancement:
> http://d.puremagic.com/issues/show_bug.cgi?id=7105

Thank you (and thanks to Kenji, too!)
December 14, 2011
On Tue, 13 Dec 2011 00:57:28 -0500, Jesse Phillips <jessekphillips+d@gmail.com> wrote:

> On Mon, 12 Dec 2011 13:56:43 -0500, Steven Schveighoffer wrote:
>
>> The example we were discussing on the other thread was this:
>>
>> void foo(ref inout(int)* a, inout(int)* b) { a = b;}
>
> Is this just so it is easier to explain inout and won't have to explain
> that const will do the same thing? Or does this actually do something
> using const there doesn't?
>
> void f(ref const(int)* a, const(int)* b) {a = b; }
> void main() {
>    const(int)* a;
>    immutable(int)* b;
>    auto c = (new int[](5)).ptr;
>    f(a, c);
>    f(b, c); //test.d(7): Error: cast(const(int)*)b is not an lvalue
> }

Yes it does:

immutable(int)* d;

foo(b, d); // OK
f(b, d); // error (as you cited above).

-Steve
December 14, 2011
On Tue, 13 Dec 2011 06:07:49 -0500, kenji hara <k.hara.pg@gmail.com> wrote:

> 2011/12/13 Timon Gehr <timon.gehr@gmx.ch>:
>> On 12/13/2011 09:41 AM, kenji hara wrote:
> [snip]
>>>
>>> Against an inout function that does not return inout type:
>>> - the number of inout parameters should be 2 more?
>>
>> If we required that, then IFTI would also have to replace inout with const
>> in case there is only one of them. That potentially introduces
>> counter-intuitive behaviour.
>
> Maybe it is an enhancement filed as 6809.

I think if we loosen the restriction of inout so that it can be only one one parameter, then it becomes simply a new type of immutable.  This makes moot that enhancement request I filed.  I think you have suggested similar things in the past and I argued against it (I'm sorry for changing my mind!)

The idea that inout simply resolves to something, and then the call falls under normal rules is really attractive.

I even thought of another idea: If inout is solely on return value, then there is no way to resolve what inout should be matched to.  But what if it simply becomes polyconst (can bind to any flavor of const)?  Because there are no inout parameters, and global inout variables are illegal, it can be deduced that the value must be unique.

I had previously suggested that only having inout on the return type should be illegal, so this would supersede that.

>>> - at least one parameter should have 'out' or 'ref' storage class as a
>>> *return parameter*?
>>
>> Not necessarily.
>>
>>> But I'm not sure these restrictions are necessarily required.
>>
>> I think we should indeed drop the restrictions, because they complicate the
>> language for little gain.
>
> Indeed.

I agree with Timon here.

-Steve
December 27, 2011
On 12.12.2011 19:56, Steven Schveighoffer wrote:
> Currently, the rules of inout say you cannot put inout on a parameter
> without putting it on the return type as well. This makes sense, it
> gives the compiler one place to worry about whether implicit casting
> rules will properly work.
>
> But Timon Gehr brought up in another thread (started by Merdhad) that we
> can separate the resolution of inout from the applicability of the
> parameters. Essentially, calling an inout function goes through two phases:
>
> 1. determine what inout resolves to
> 2. try and call the function.
>
> inout rules don't have to change regarding resolving inout's actual
> value. In other words, if all inout places are matched as int,
> immutable, or inout, then inout resolves to that value. Otherwise inout
> resolves to const.
> If this ends up being viable, this is actually easier to explain than
> the current rules for inout. We just have to make sure the rules are
> sound before doing something like this.

Looks as though 'inout' is about to become a misnomer...


December 27, 2011
On Tuesday, 27 December 2011 at 08:30:53 UTC, Don wrote:
> Looks as though 'inout' is about to become a misnomer...

Not the first to be so, so no problem.
December 27, 2011
The patch https://github.com/D-Programming-Language/dmd/pull/558 implements the two phases of inout resolution.

Until merging of it, I'll not post a patch to relax inout rule.

Kenji Hara

2011/12/13 Steven Schveighoffer <schveiguy@yahoo.com>:
> Currently, the rules of inout say you cannot put inout on a parameter without putting it on the return type as well.  This makes sense, it gives the compiler one place to worry about whether implicit casting rules will properly work.
>
> But Timon Gehr brought up in another thread (started by Merdhad) that we can separate the resolution of inout from the applicability of the parameters.  Essentially, calling an inout function goes through two phases:
>
> 1. determine what inout resolves to
> 2. try and call the function.
>
> inout rules don't have to change regarding resolving inout's actual value.  In other words, if all inout places are matched as int, immutable, or inout, then inout resolves to that value.  Otherwise inout resolves to const.
>
> But what's different is (at least in my mind) the function call might not necessarily succeed even when the resolution is completed.
>
> Take for example:
>
> inout(int)* foo(inout(int)** a, inout(int)* b);
>
> Now, if we call foo like this:
>
> int a;
> int b;
> int* pa = &a;
>
> foo(&pa, &b);
>
> This means foo is called with (int **, int *).  This means inout resolves to
> mutable (no qualifier).  *NOW* we try calling foo as if it were written:
>
> int *foo(int **a, int *b)
>
> And it can be done.  Not only that, but there is nothing bad that could be happening in foo that should be disallowed by the compiler.
>
> Now let's see what happens were we *could* do something bad:
>
> immutable(int) c;
> auto pc = &c;
>
> foo(&pc, &b);
>
> Now, foo is being called with (immutable(int)**, int *).  Inout resolves to
> const (due to the mix of mutable and immutable).  *NOW* we try calling foo
> as if it were written:
>
> const(int)* foo(const(int)** a, const(int)* b);
>
> And it *FAILS*.  This is because you cannot implicitly convert
> immutable(int)** to const(int)** (well, at least it *shouldn't* compile, I'm
> not sure if it does currently).
>
> What this does is allow more possibilities for inout than we currently do.  Because inout is not now tied to returning something, we can create functions that have inout parameters but no inout return value.
>
> The example we were discussing on the other thread was this:
>
> void foo(ref inout(int)* a, inout(int)* b) { a = b;}
>
> This would compile as long as you call with const(int)* as the first
> parameter, or if both parameters matched in constancy (i.e. both were
> immutable, both were mutable, or both were inout).
>
> This gives us more cases where you don't have to repeat functions for the sake of handling different types of constancy, particularly when we have mutable references 2 levels deep.  I can't see anything technically wrong with this, can anyone else?
>
> The one thing that I think still should be required is if you have inout on the return value, there *must* be an inout on a parameter.  Otherwise, the compiler has no idea what it should be (since we don't overload on return type in D).
>
> If this ends up being viable, this is actually easier to explain than the current rules for inout.  We just have to make sure the rules are sound before doing something like this.
>
> -Steve
January 19, 2012
2011/12/13 Steven Schveighoffer <schveiguy@yahoo.com>:
> immutable(int) c;
> auto pc = &c;
>
> foo(&pc, &b);
>
> Now, foo is being called with (immutable(int)**, int *).  Inout resolves to
> const (due to the mix of mutable and immutable).  *NOW* we try calling foo
> as if it were written:
>
> const(int)* foo(const(int)** a, const(int)* b);
>
> And it *FAILS*.  This is because you cannot implicitly convert
> immutable(int)** to const(int)** (well, at least it *shouldn't* compile, I'm
> not sure if it does currently).

Today, with git head, this code might be rejected correctly. So relaxing inout rule is more reasonable now.

Kenji Hara
1 2
Next ›   Last »