Update struct.dd - postblit documentation#2281
Conversation
|
Thanks for your pull request and interest in making D better, @RazvanN7! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
|
@RazvanN7 - need to define what happens when the entire struct is qualified and then defines a postblit with no qualifier/same qualifier/different qualifier. |
wilzbach
left a comment
There was a problem hiding this comment.
Self-containing + no information that will be out of date soon please
spec/struct.dd
Outdated
| $(D this(this) immutable;) or $(D this(this) shared;), then the code | ||
| is ill-formed. Historically, such definitions passed compilation but | ||
| could not be invoked. A deprecation diagnostic is issued by the front-end | ||
| of dmd 2.080 or later, see $(BUGZILLA 18417). Example:) |
There was a problem hiding this comment.
Don't add things that can get outdated into the spec, because they will.
Info this belongs into the changelog entry
spec/struct.dd
Outdated
|
|
||
| $(P If a postblit is qualified with `const` as in $(D this(this) const;), | ||
| the code is ill-formed. A deprecation diagnostic is issued by the | ||
| front-end of dmd 2.080 or later, see $(BUGZILLA 18417). Prior versions |
There was a problem hiding this comment.
Again information that will get outdated, better not add it.
spec/struct.dd
Outdated
| } | ||
| --- | ||
|
|
||
| $(P This allows incorrect code to compile, refer to $(BUGZILLA 18357) for examples.) |
There was a problem hiding this comment.
This doesn't work. The spec should be self-containing as Bugzilla might be offline or it simply might be print as ebook or PDF.
|
Out of interest: does this try to address https://issues.dlang.org/show_bug.cgi?id=14246? |
There's already
Not sure whether we really want to increase our cross-repository even further. |
No, this PR documents solely the postblitting mechanism; it's a work in progress, though. |
andralex
left a comment
There was a problem hiding this comment.
Couple of minor changes requested
| internal postblit functions:) | ||
|
|
||
| $(OL | ||
| $(LI `void __postblit()`. The compiler assigns this name to the explicitly |
There was a problem hiding this comment.
Please specify entire signatures (as I did in the commit I added) and make sure those I added are correct.
| --- | ||
| ) | ||
|
|
||
| $(P Neither of the above postblits is defined for structs that don't |
There was a problem hiding this comment.
Should specify somewhere (perhaps here) what happens if someone does NOT define this(this) but DOES define the special functions. Is the compiler going to insert the calls? (Hopefully not!)
spec/struct.dd
Outdated
| --- | ||
| ) | ||
|
|
||
| $(P Postblits are not overloadable. If two or more postblits are defined, |
There was a problem hiding this comment.
Better (missed this): "Postblits cannot be overloaded." The word "overloadable" is a bit awkward.
|
|
||
| $(OL | ||
| $(LI `const`. When a postblit is qualified with `const` as in | ||
| $(D this(this) const;) or $(D const this(this);) then the postblit |
There was a problem hiding this comment.
I removed the "is ill-formed" part here because the code is accepted. Please don't forget - we're documenting behavior here, not what should happen. If we deprecate this with the next version, then yes please do mention it's ill-formed but no diagnostic is issues by front-end versions prior to 2.xxx.
There was a problem hiding this comment.
We will deprecate this with the next version, but @wilzbach argued that information that gets outdated should not be in the spec. I thought that saying it's ill-formed but not mentioning the deprecation is the best compromise since you can actually call the function but it's not doing what it is supposed to.
There was a problem hiding this comment.
It's helpful to give that information so people who see invalid code getting compiled don't get confused.
| $(OL | ||
| $(LI `const`. When a postblit is qualified with `const` as in | ||
| $(D this(this) const;) or $(D const this(this);) then the postblit | ||
| is succesfully called on mutable (unqualified), `const`, |
There was a problem hiding this comment.
I removed the backquotes around mutable because mutable is not a keyword.
| $(LI `immutable`. When a postblit is qualified with `immutable` | ||
| as in $(D this(this) immutable) or $(D immutable this(this)) | ||
| the code is ill-formed. The `immutable` postblit passes the | ||
| compilation phase but cannot be invoked. Example:) |
There was a problem hiding this comment.
Version when this will be diagnosed? I think we can leave this text as is and add a mention once we merge the appropriate PR.
|
Sorry for being late to the party, but should the behavior for an array of structs be defined too? In any case, the behavior for now is: foreach (ref e; cast(S*)this.v.ptr)[0 .. n])
e.__xpostblit(); |
No description provided.