Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ljmf00
Copy link
Member

@ljmf00 ljmf00 commented Nov 22, 2021

Signed-off-by: Luís Ferreira [email protected]

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @ljmf00!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

@ljmf00
Copy link
Member Author

ljmf00 commented Nov 22, 2021

Should we also refer to this on structs ?

@ljmf00 ljmf00 changed the title spec: class: add __ctor() and __dtor() aliases spec: class: add __ctor(), __dtor() and __xdtor() aliases Nov 22, 2021
@ljmf00 ljmf00 changed the title spec: class: add __ctor(), __dtor() and __xdtor() aliases spec: class: add __ctor, __dtor and __xdtor aliases Nov 22, 2021
spec/class.dd Outdated
@@ -371,6 +371,9 @@ $(GNAME Constructor):
}
------

$(P The compiler may generate a $(D __ctor) alias that matches with
Copy link
Member Author

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

Copy link

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?

Copy link
Member Author

@ljmf00 ljmf00 Nov 23, 2021

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,
Copy link
Member

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.

Copy link
Member Author

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.

@dkorpel
Copy link
Contributor

dkorpel commented Nov 23, 2021

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.

@ljmf00
Copy link
Member Author

ljmf00 commented Nov 23, 2021

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 __postblit and __xpostblit.

@@ -371,6 +371,9 @@ $(GNAME Constructor):
}
------

$(P The compiler generate a $(D __ctor) alias that matches with
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$(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.)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
constructors definitions.)
constructor definitions.)

Copy link
Contributor

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?

@PetarKirov PetarKirov requested review from RazvanN7 and dkorpel May 22, 2023 14:38
@PetarKirov
Copy link
Member

@ljmf00 can you please rebase your PR?

@ljmf00
Copy link
Member Author

ljmf00 commented May 22, 2023

@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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$(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.)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

@RazvanN7
Copy link
Contributor

RazvanN7 commented Mar 6, 2024

ping @ljmf00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants