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
84 lines
4.0 KiB
C++
84 lines
4.0 KiB
C++
// 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
|
|
|
|
#ifndef CARBON_TOOLCHAIN_CHECK_CUSTOM_WITNESS_H_
|
|
#define CARBON_TOOLCHAIN_CHECK_CUSTOM_WITNESS_H_
|
|
|
|
#include "toolchain/check/context.h"
|
|
#include "toolchain/sem_ir/builtin_function_kind.h"
|
|
#include "toolchain/sem_ir/ids.h"
|
|
|
|
namespace Carbon::Check {
|
|
|
|
// Builds a witness that the given type implements the given interface,
|
|
// populating it with the specified set of values. Returns a corresponding
|
|
// lookup result. Produces a diagnostic and returns `None` if the specified
|
|
// values aren't suitable for the interface.
|
|
auto BuildCustomWitness(Context& context, SemIR::LocId loc_id,
|
|
SemIR::ConstantId query_self_const_id,
|
|
SemIR::SpecificInterface query_specific_interface,
|
|
llvm::ArrayRef<SemIR::InstId> values) -> SemIR::InstId;
|
|
|
|
// Builds a witness that the given type is copyable via a primitive copy.
|
|
auto BuildPrimitiveCopyWitness(
|
|
Context& context, SemIR::LocId loc_id,
|
|
SemIR::ConstantId query_self_const_id,
|
|
SemIR::SpecificInterface query_specific_interface) -> SemIR::InstId;
|
|
|
|
// Returns a manufactured operator function.
|
|
// `param_types` contains the parameter types. The first element of
|
|
// `param_types` is treated as the `self` type, and any subsequent elements
|
|
// are treated as the types of the remaining explicit parameters.
|
|
// The `interface_id` is the interface containing the `op_name` function, which
|
|
// should be an interface in Core.
|
|
auto MakeBuiltinOperatorFunction(Context& context, SemIR::LocId loc_id,
|
|
llvm::ArrayRef<SemIR::TypeId> param_types,
|
|
SemIR::TypeId return_type_id,
|
|
CoreIdentifier op_name,
|
|
SemIR::BuiltinFunctionKind builtin_kind,
|
|
SemIR::InterfaceId interface_id)
|
|
-> SemIR::InstId;
|
|
|
|
// Builds a witness that the given type is trivially destroyable.
|
|
auto BuildTrivialDestroyWitness(
|
|
Context& context, SemIR::LocId loc_id,
|
|
SemIR::ConstantId query_self_const_id,
|
|
SemIR::SpecificInterface query_specific_interface) -> SemIR::InstId;
|
|
|
|
// Given an interface, returns the corresponding enum if it's covered by
|
|
// `CoreInterface`, or `Unknown` if it's some other interface.
|
|
auto GetCoreInterface(Context& context, SemIR::InterfaceId interface_id)
|
|
-> SemIR::CoreInterface;
|
|
|
|
// Maps a `CoreInterface` to its `CoreIdentifier` equivalent.
|
|
auto AsCoreIdentifier(SemIR::CoreInterface core_interface) -> CoreIdentifier;
|
|
|
|
// Returns a witness for a `CoreInterface` `CustomWitness`. A return value of
|
|
// `None` indicates a non-final witness should be produced, while `std::nullopt`
|
|
// indicates the query is final and no witness can be produced.
|
|
//
|
|
// If `build_witness` is false, this function always returns `None` as the
|
|
// witness, whether it would be final or not. It is used to indicate the
|
|
// presence of such a witness without adding instructions for it.
|
|
auto LookupCustomWitness(Context& context, SemIR::LocId loc_id,
|
|
SemIR::CoreInterface core_interface,
|
|
SemIR::ConstantId query_self_const_id,
|
|
SemIR::SpecificInterface query_specific_interface,
|
|
bool build_witness) -> std::optional<SemIR::InstId>;
|
|
|
|
// Builds a witness for the `Destroy` interface.
|
|
//
|
|
// `op_id` refers to the synthesised `Destroy.Op` and is generated differently
|
|
// based on whether the specific is a Carbon type or a C++ type.
|
|
auto BuildDestroyWitness(Context& context, SemIR::LocId loc_id,
|
|
SemIR::TypeId self_type_id,
|
|
SemIR::ConstantId query_self_const_id,
|
|
SemIR::SpecificInterface query_specific_interface,
|
|
SemIR::InstId subobject_destroy_fn_id)
|
|
-> SemIR::InstId;
|
|
|
|
} // namespace Carbon::Check
|
|
|
|
#endif // CARBON_TOOLCHAIN_CHECK_CUSTOM_WITNESS_H_
|