DIP 1016--ref T accepts r-values--Community Review Round 1

Manu turkeyman at gmail.com
Sun Jul 22 08:53:53 UTC 2018


On Sun, 22 Jul 2018 at 01:00, Johannes Loher via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On Saturday, 21 July 2018 at 08:59:39 UTC, Manu wrote:
> > 4. A struct-type getter that returns by-val exhibits this
> > gotcha in a
> > variety of ways; you 'get' the member (a by-val copy), then
> > mutate a
> > member in any way, (ie, call a method), and you've accidentally
> > modified the copy, not the source value! (`ref` is not the bug)
> >   - note, in all other constructions of this same 'bug',
> > existing
> > language semantics find it acceptable to silently accept the
> > accidental mutation of an expiring rvalue. Nobody is losing
> > sleep at
> > night.
>
> This argument kind of convinced me. I also just realized, there
> is another such situation which is very similar to functions
> taking ref parameters, where references to rvalues are actually
> allowed: foreach loops. The following code is actually valid,
> which kind of surprised me:
>
> foreach(ref e; iota(0, 10))
> {
>      e += 1;
> }
>
> So DIP 1016 actually seems to make the language more consistent
> in that regard.

Hooray! Perhaps my cause is not so hopeless after all these years :)

Yes, there are countless possible constructions of this 'issue'.
Here's my personal favourite:
  T().mutate();

;)

It's not 'ref's job to address this issue.

> I also carefully reread the DIP and found some minor issues:
>
> - "It has been noted that is it possible to perceive the current
> usage of":
> it should be "[...] it is [...]

There's a PR that nobody has merged that fixes some bugs.

> - Somebody already mentioned this, but this sections sounds
> confusing, please find a better wording: "An example may be some
> meta that reflects or receives a function by alias." Also you
> seem to be using "meta" as a noun many times. I'm not totally
> sure, but I don't think it actually is a noun and for the least,
> It is very uncommon as a noun which makes understanding the
> corresponding sections much harder. For example I don't
> understand what is actually meant by "brittle meta" in a later
> section.

I use the term 'meta' (as in meta-programming) to refer to
compile-time constructions.
I don't tend to say "a template", because many problematic
constructions are compositions, and then consider mixin; not
'template's.
I feel like 'meta' is the simplest accepted term for "compile time
machinery". I'm happy to change my language if it's so confusing. What
should I write?


More information about the Digitalmars-d mailing list