mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-17 06:08:11 +00:00
Move SubobjectDestroy and SelfDestruct out of interface Destroy (#7942)
Determining that a type has trivial destruction requires checking whether all of its subobjects have trivial destruction and whether its type has a custom witness for `Destroy.Op`. This isn't possible when `Destroy` is the custodian for `Destroy.Op` and `SubobjectDestroy.Op`, so we need to make `SubobjectDestroy` its own interface. `Destroy.SelfDestruct` becomes a standalone function because it depends on `SubobjectDestroy` and `Destroy` being implemented, and is also responsible for generating any custom witnesses for both interfaces. Making `SelfDestruct` an interface was experimented with, but this required a blanket impl that caused issues for facet types. `Destroy` depends on `SubobjectDestroy` to be implemented. We'd ideally use `require impls SubobjectDestroy`, but it isn't complete yet, and it also causes problems when `Destroy` is implemented inside the class definition. We work around this by temporarily renaming the `Destroy` interface to `DestroyImpl`, and introducing a constraint called `Destroy` so that user code doesn't need to write `Core.SubobjectDestroy & Core.Destroy`.
This commit is contained in:
1 parent
57bf903ef1
commit
05a7ecbd34
357 files changed
+41452
-59092
No files matched your search
@@ -17,6 +17,7 @@
|
||||
#include "toolchain/check/custom_witness.h"
|
||||
#include "toolchain/check/function.h"
|
||||
#include "toolchain/check/inst.h"
|
||||
#include "toolchain/check/interface.h"
|
||||
#include "toolchain/check/literal.h"
|
||||
#include "toolchain/check/name_lookup.h"
|
||||
#include "toolchain/check/pattern.h"
|
||||
@@ -39,7 +40,7 @@ static auto GetClangOperatorKind(Context& context, SemIR::LocId loc_id,
|
||||
-> std::optional<clang::OverloadedOperatorKind> {
|
||||
switch (interface_name) {
|
||||
// Unary operators.
|
||||
case CoreIdentifier::Destroy:
|
||||
case CoreIdentifier::DestroyImpl:
|
||||
case CoreIdentifier::SubobjectDestroy:
|
||||
case CoreIdentifier::SelfDestruct:
|
||||
case CoreIdentifier::As:
|
||||
@@ -581,31 +582,6 @@ static auto GetBuiltinOperatorInfo(clang::OverloadedOperatorKind kind)
|
||||
return OpTable[kind];
|
||||
}
|
||||
|
||||
static auto GetCoreInterfaceId(Context& context, SemIR::LocId loc_id,
|
||||
CoreIdentifier interface_name)
|
||||
-> SemIR::InterfaceId {
|
||||
auto inst_id = LookupNameInCore(context, loc_id, interface_name);
|
||||
|
||||
// Non-generic interfaces.
|
||||
if (auto facet_type = context.insts().TryGetAs<SemIR::FacetType>(inst_id)) {
|
||||
const auto& declared =
|
||||
context.declared_facet_types().Get(facet_type->declared_facet_type_id);
|
||||
auto single = declared.TryAsSingleExtend();
|
||||
CARBON_KIND_SWITCH(*single) {
|
||||
case CARBON_KIND(SemIR::SpecificInterface si): {
|
||||
return si.interface_id;
|
||||
}
|
||||
case CARBON_KIND(SemIR::SpecificNamedConstraint _): {
|
||||
CARBON_FATAL("Operators in named constraints are not yet needed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto type_id = context.insts().Get(inst_id).type_id();
|
||||
auto generic = context.types().GetAs<SemIR::GenericInterfaceType>(type_id);
|
||||
return generic.interface_id;
|
||||
}
|
||||
|
||||
// Builds a Carbon builtin function declaration corresponding to an overload
|
||||
// candidate that selected a C++ builtin operator. Returns None if no
|
||||
// corresponding builtin function could or should be built.
|
||||
|
||||
Reference in new issue
Block a user