Define Destroy for class types#7362
Conversation
4f44217 to
57319f3
Compare
Destroy for trivial and partial typesDestroy for class types
f03c93c to
819a4fd
Compare
| Types that do not implement `Destructor` have _isolated trivial destruction_. A | ||
| type comprised of subobjects that all have isolated trivial destruction has | ||
| _trivial destruction_. See [`TrivialDestroy` interface] below. |
There was a problem hiding this comment.
I feel like the pair of terms here are a bit hard for me to read clearly. Mostly, I'm worried that a modifying word like "isolated" doesn't leave it clear that subobject destructors may not be trivial...
What do folks think about instead using two distinct terms here, "trivial" and something else for what here is "isolated trivial destruction"? My best initial idea is "simple destruction"?
There was a problem hiding this comment.
"Simple destruction" is decent, but I think the best solution would be to describe trivial destruction in an entirely different way. This paragraph has been one of the hardest to write, because of its recursive nature.
Types that do not implement
Destructorhave trivial destruction if, and only if, none of their subobjects implementDestructor.
That's the best I can come up with. Alternatively:
Types that do not implement
Destructorhave trivial destruction if, and only if, all of their subobjects have trivial destruction. Types that implementDestructordo not have trivial destruction.
Thoughts on these alternative phrasings?
There was a problem hiding this comment.
A type has trivial destruction if, and only if, neither it, nor any of its subobjects, implement
Destructor.
A type has trivial destruction if, and only if, it does not implement
Destructorand none of its subobjects implementDestructor.
I think I like this last one the best.
| #### Empty `Destructor.Op()` should be an error | ||
|
|
||
| An empty `Destructor.Op()` definition should be an error. We should allow users | ||
| to "reserve" non-trivial destruction by providing a spelling that communicates | ||
| "no behaviour is intentional" using a clearer syntax. |
There was a problem hiding this comment.
It's not clear why we need to do this given that we later make constraining on Destructor an error -- even without impl-ing it, the ability to impl it is still "reserved".
Is there another reason for this?
There was a problem hiding this comment.
I think this syntax implying that C1 has non-trivial destruction subtle, and that having something a bit more explicit would be helpful.
class C1 {
impl as Destructor {
fn Op(self) {}
}
}The best we can do without this would be
class C1 {
impl as Destructor {
fn Op(self) {
// C1 has non-trivial destruction, but this destructor
// is intentionally empty.
}
}
}| clarifies that trivial destruction is a property that code can query. The | ||
| Leads confirmed this is the case. | ||
|
|
||
| ## Proposal |
There was a problem hiding this comment.
I think you need to explain a bit more here in order to bridge from #1154 and the current design's for destruction and your update here. Either here, or in an update to the design docs. For example -- how do these terms map to the very different terms currently in the design? What updates would happen to the design to integrate and connect it with these interfaces? How does it interact with the current design's destroy function?
There was a problem hiding this comment.
Would it be better to describe these in the proposal, or in the design doc?
|
|
||
| ```carbon | ||
| interface Destroy { | ||
| private fn Op(ref self); |
There was a problem hiding this comment.
A bit surprising that this is private -- can it not be called?
Should it be unsafe instead?
|
|
||
| ```carbon | ||
| interface DynamicDestroy { | ||
| private fn Op(ref self); |
There was a problem hiding this comment.
This in particular seems a bit odd to be private.
There was a problem hiding this comment.
Replaced with final. Same for TrivialDestroy.
|
|
||
| This is a successor to [P001154 Destructors](/proposals/p001154-destructors.md). | ||
| Several alternatives that were explored in P001154 are proposed in this | ||
| document. |
There was a problem hiding this comment.
I think there are a lot of design decisions here that we should probably have alternatives?
The proposal doc is a bit messy right now, but this is a good save point for `values.md`.
|
I've pushed my most recent changes. Feel free to review values.md, but the proposal doc is not in a reviewable state yet. |
Define the core interfaces
Destructor,Destroy,TrivialDestroy, andDynamicDestroy. Describe how destroy works for class types.