mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 13:50:10 +01:00
This change partially implements [PR #7362], which revises how objects are destroyed. It is a partial implementation for two reasons: 1. This change moves `Destroy.Op`'s current behaviour into `Destroy.SubobjectDestroy`, but it doesn't add support for objects with non-trivial destruction. 2. `Destroy.SubobjectDestroy` is a workaround for `require impls SubobjectDestroy`. We aren't able to use the latter until the dependents add their requirements' implementations to their own witness tables. [PR #7362]: https://github.com/carbon-language/carbon-lang/pulls/7362
36 lines
1.1 KiB
Plaintext
36 lines
1.1 KiB
Plaintext
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
package Core library "prelude/destroy";
|
|
|
|
// TODO: uncomment when `require impls` adds a witness table entry.
|
|
// interface SubobjectDestroy {
|
|
// final fn Op(ref self) = "subobject.destroy";
|
|
// }
|
|
|
|
interface Destroy {
|
|
// TODO: uncomment when `require impls` adds a witness table entry.
|
|
// require impls SubobjectDestroy;
|
|
|
|
// TODO: change `Self` to `partial Self`.
|
|
fn Op(ref self);
|
|
|
|
// TODO: remove when `require impls` adds a witness table entry.
|
|
final fn SubobjectDestroy(unused ref self) {
|
|
// This function body is ignored by the toolchain. We can't use
|
|
// a built-in because the compiler treats it as an error. We
|
|
// should address this at some point, but it's not a high
|
|
// priority right now.
|
|
}
|
|
|
|
final fn SelfDestruct(ref self) {
|
|
self.Op();
|
|
self.SubobjectDestroy();
|
|
}
|
|
}
|
|
|
|
// TODO: uncomment when `require impls` adds a witness table entry.
|
|
// impl forall [T: SubobjectDestroy] partial T as Destroy {
|
|
// alias Op = T.Op;
|
|
// }
|