Thread overview
[Issue 8931] array/slice assignment causes destruction + postblit instead of opAssign
Jul 20, 2015
Jonathan M Davis
Jul 24, 2015
Jonathan M Davis
July 20, 2015
https://issues.dlang.org/show_bug.cgi?id=8931

Jonathan M Davis <issues.dlang@jmdavisProg.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |issues.dlang@jmdavisProg.co
                   |                            |m

--- Comment #5 from Jonathan M Davis <issues.dlang@jmdavisProg.com> ---
(In reply to monarchdodra from comment #4)
> I did some extra thinking about this, and this might be invalid. While one might "expect" opAssign to be called, doing this would mean it is impossible to have a strong exception safe behavior should one of the assignements fails.

IIRC, isn't opAssign actually supposed to assign to a copy and then have the result blitted into the variable that you're actually assigning to in order to make it exception safe like you're concerned about? The extension of that would be to do opAssign into a copy of the static array, and then blit it into the original afterwards. I'm not sure how desirable that is, but it would be an extension of what happens with opAssign in general (assuming that I'm remembering that right).

--
July 24, 2015
https://issues.dlang.org/show_bug.cgi?id=8931

--- Comment #6 from monarchdodra@gmail.com ---
(In reply to Jonathan M Davis from comment #5)
> (In reply to monarchdodra from comment #4)
> > I did some extra thinking about this, and this might be invalid. While one might "expect" opAssign to be called, doing this would mean it is impossible to have a strong exception safe behavior should one of the assignements fails.
> 
> IIRC, isn't opAssign actually supposed to assign to a copy and then have the result blitted into the variable that you're actually assigning to in order to make it exception safe like you're concerned about? The extension of that would be to do opAssign into a copy of the static array, and then blit it into the original afterwards. I'm not sure how desirable that is, but it would be an extension of what happens with opAssign in general (assuming that I'm remembering that right).

Well (IIRC), not exactly. The *default* implementation of opAssign, provided you implemented "this(this)" works that way, yes. However, once you *do* define opAssign, the all bets are off. The compiler calls your opAssign, and you have to make your own guarantees.

That said, back to my original comment, the current implementation postblits the elements 1 at a time anyways, so the exception safety is just as bad as assigning the elements 1 at a tie.

--
July 24, 2015
https://issues.dlang.org/show_bug.cgi?id=8931

--- Comment #7 from Jonathan M Davis <issues.dlang@jmdavisProg.com> ---
(In reply to monarchdodra from comment #6)
> (In reply to Jonathan M Davis from comment #5)
> > IIRC, isn't opAssign actually supposed to assign to a copy and then have the result blitted into the variable that you're actually assigning to in order to make it exception safe like you're concerned about? The extension of that would be to do opAssign into a copy of the static array, and then blit it into the original afterwards. I'm not sure how desirable that is, but it would be an extension of what happens with opAssign in general (assuming that I'm remembering that right).
> 
> Well (IIRC), not exactly. The *default* implementation of opAssign, provided you implemented "this(this)" works that way, yes. However, once you *do* define opAssign, the all bets are off. The compiler calls your opAssign, and you have to make your own guarantees.

Hmmm. Well, I don't know how to test that to figure out what's going on, given that bitblitting is involved and thus you have no functions to add code to print out or whatnot. I guess that the only way to figure out what's happening for sure would be to read the assembly, and I'm not very good at that.

> That said, back to my original comment, the current implementation postblits the elements 1 at a time anyways, so the exception safety is just as bad as assigning the elements 1 at a tie.

Which is why I was suggesting that one solution might be to do it all into another static array first and then blit that over after it succeeds. I'm not sure that that's a _good_ solution, since it requires blitting everything over, but it would at least theoretically give you the exception safety.

Either way, it seems rather odd to be using postblits instead of opAssign when doing assignment, even if it's in a static array.

--
December 13
https://issues.dlang.org/show_bug.cgi?id=8931

--- Comment #8 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17561

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--