Bug 7105 – relax inout rules

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-12-13T11:28:00Z
Last change time
2013-01-02T01:42:24Z
Keywords
pull
Assigned to
nobody
Creator
timon.gehr
Blocks
7542, 7543

Comments

Comment #0 by timon.gehr — 2011-12-13T11:28:26Z
Currently, DMD requires that the return type of a function that has inout-qualified parameters is itself qualified with inout. Removing this restriction would make the type system more expressive. For example, the following function still requires code duplication to work for multiple differently qualified parameters: void copy(int** tgt, int* src){ *tgt = src; } void copy(immutable(int)** tgt, immutable(int)* src){ *tgt = src; } void copy(const(int)** tgt, const(int)* src){ *tgt = src; } With the lifted restriction, these three overloads can be merged: void copy(inout(int)** tgt, inout(int)* src){ *tgt = src; } Also see the newsgroup discussion on the topic: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=151839
Comment #1 by smjg — 2012-02-14T11:25:40Z
Another use case is to support foreach on a container of arbitrary constancy, by using int opApply(int delegate(ref inout(T)) dg) inout;
Comment #2 by timon.gehr — 2012-02-14T11:44:47Z
That is an enhancement of what is suggested here. It is not very clear that inout should behave like that inside delegate/function pointer parameters. Maybe it is best if you open another enhancement request that discusses your design and its use cases in detail. For example, what would be the meaning of the following declarations? inout(int)[] delegate(inout(int)[] dg; inout(int)[] foo(inout(int)[]delegate(inout(int)[] dg, inout(int)[] x){ ... }
Comment #3 by smjg — 2012-02-14T13:05:25Z
(In reply to comment #2) > For example, what would be the meaning of the following declarations? > > inout(int)[] delegate(inout(int)[] dg; > inout(int)[] foo(inout(int)[]delegate(inout(int)[] dg, inout(int)[] x){ ... } Both of these would be syntax errors, because the brackets aren't matched. But I see the ambiguity now. Does the inout status belong to the delegate itself or to the function of which it is a parameter? If the signature of dg is invalid because it doesn't pass the inout status through, then in principle it could be taken to belong to the outer function. Which would be passing the inout status through to the delegate rather than as a return. I'll think about it and continue the discussion on the newsgroup. Stewart.
Comment #4 by k.hara.pg — 2012-02-18T23:48:12Z
Comment #5 by k.hara.pg — 2012-02-19T03:37:40Z
(In reply to comment #1) > Another use case is to support foreach on a container of arbitrary constancy, > by using > > int opApply(int delegate(ref inout(T)) dg) inout; I think that the inout parameter contravariant (I've filed as issue 7542) is necessary due to enable such signatures.
Comment #6 by k.hara.pg — 2012-02-19T03:55:08Z
(In reply to comment #5) > (In reply to comment #1) > > Another use case is to support foreach on a container of arbitrary constancy, > > by using > > > > int opApply(int delegate(ref inout(T)) dg) inout; > > I think that the inout parameter contravariant (I've filed as issue 7542) is > necessary due to enable such signatures. And I've posted issue 7543.
Comment #7 by smjg — 2012-02-19T06:37:31Z
(In reply to comment #3) > (In reply to comment #2) > > For example, what would be the meaning of the following declarations? > > > > inout(int)[] delegate(inout(int)[] dg; > > inout(int)[] foo(inout(int)[]delegate(inout(int)[] dg, inout(int)[] x){ ... } > > Both of these would be syntax errors, because the brackets aren't matched. > > But I see the ambiguity now. Does the inout status belong to the delegate > itself or to the function of which it is a parameter? > > If the signature of dg is invalid because it doesn't pass the inout status > through, then in principle it could be taken to belong to the outer function. > Which would be passing the inout status through to the delegate rather than as > a return. > > I'll think about it and continue the discussion on the newsgroup. digitalmars.D "inout and function/delegate parameters" On web interface: http://forum.dlang.org/thread/[email protected]
Comment #8 by github-bugzilla — 2012-02-19T11:01:35Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/98988d685d8fb16ebe05430c1dd8db5f799f1fe8 Merge pull request #735 from 9rnsr/fix7105 Issue 7105 - relax inout rules
Comment #9 by github-bugzilla — 2012-12-29T01:42:43Z
Commit pushed to master at https://github.com/D-Programming-Language/d-programming-language.org https://github.com/D-Programming-Language/d-programming-language.org/commit/ec215c4def669d8e5765328ee16e54eb876c66c3 Relax inout rule It has been introduced by issue 7105 from 2.059. In current, an inout is not necessary to appear in the return type.
Comment #10 by github-bugzilla — 2013-01-02T01:42:24Z