-
-
Notifications
You must be signed in to change notification settings - Fork 379
spec: class: add __ctor, __dtor and __xdtor aliases #3125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Thanks for your pull request, @ljmf00! 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. |
Should we also refer to this on |
spec/class.dd
Outdated
@@ -371,6 +371,9 @@ $(GNAME Constructor): | |||
} | |||
------ | |||
|
|||
$(P The compiler may generate a $(D __ctor) alias that matches with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if the right wording is may
, should
or omit it. Should we enforce this to be implemented? I think so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the compiler required to generate these aliases to comply to the spec? Or are they just an optional thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the compiler required to generate these aliases to comply to the spec? Or are they just an optional thing?
Technically yes, since e.g. __ctor
is mentioned in several specification examples but this can be considered an implementation detail. You, as a user, probably don't require this, unless doing e.g. custom class allocators, custom traits or other advanced code. This is mostly used internally by the D runtime hooks and standard library traits, although I think it is useful to make it not implementation-defined to ease the user for the reasons I stated above.
@@ -729,6 +732,11 @@ $(GNAME Destructor): | |||
by the gc. | |||
) | |||
|
|||
$(P The compiler may generate $(D __dtor) and $(D __xdtor) alias that | |||
matches the class destructor definition and inclusive destructors, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the term "inclusive destructor" defined elsewhere in the spec? If not I think it should have a definition somewhere.
I note that __xpostblit()
's description in the struct page of the spec mentions the creation of aliases.
void __xpostblit(). The field and aggregated postblits, although generated for a struct, are not actual struct members. In order to be able to call them, the compiler internally creates an alias, called __xpostblit which is a member of the struct and which points to the generated postblit that is the most inclusive.
However, I note that this wording seems to be descriptive rather than prescriptive, which isn't ideal for the language specification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the inclusive destructor
concept to the glossary. Please review it.
About the __xpostblit()
, I think it is a bit out of scope of this PR, although I can write a separate one fixing that wording.
There's no linked bugzilla issue, so what's the idea behind this PR? It's already specified that identifiers starting with a double underscore are reserved. |
Yes, but this has a special purpose, and as I said above, it is noted in some specification examples such as traits and structs. We should also follow the same struct section, which specifies the behaviour of |
Signed-off-by: Luís Ferreira <[email protected]>
@@ -371,6 +371,9 @@ $(GNAME Constructor): | |||
} | |||
------ | |||
|
|||
$(P The compiler generate a $(D __ctor) alias that matches with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$(P The compiler generate a $(D __ctor) alias that matches with | |
$(P The compiler generates a $(D __ctor) alias that matches with |
@@ -371,6 +371,9 @@ $(GNAME Constructor): | |||
} | |||
------ | |||
|
|||
$(P The compiler generate a $(D __ctor) alias that matches with | |||
constructors definitions.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constructors definitions.) | |
constructor definitions.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand what you mean by this sentence. Could you please elaborate?
@ljmf00 can you please rebase your PR? |
Yes, I'll add to my TODO list. |
@@ -258,6 +258,11 @@ void test() | |||
syntax) refers to the ability to call a function as if it were a method of | |||
its first argument. For example `funct(arg)` may be written as | |||
`arg.funct()`.) | |||
|
|||
$(DT $(LNAME2 inclusive_destructor, inclusive-destructor, Inclusive |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$(DT $(LNAME2 inclusive_destructor, inclusive-destructor, Inclusive | |
$(DT $(LNAME2 inclusive-destructor, Inclusive |
$(DT $(LNAME2 inclusive_destructor, inclusive-destructor, Inclusive | ||
Destructor)) | ||
$(DD An inclusive destructor is a destructor that includes destruction | ||
of the object itself and its fields, if reaching its lifetime.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of the object itself and its fields, if reaching its lifetime.) | |
of the object itself and its fields.) |
Destructors can be called early (for example, by destroy
), and this definition applies regardless of when it is called.
ping @ljmf00 |
Signed-off-by: Luís Ferreira [email protected]