mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Support BitAnd operator between facet types (#5022)
Doing so results in TODOs in the resulting semir, since we don't handle combining the facet types together properly or doing lookup into them. There's a test added demonstrating this, which will be made to work in followups. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
co-authored by
Jon Ross-Perkins
parent
92e635c2f0
commit
129cf35d78
@@ -109,6 +109,22 @@ struct AnyFloat {
|
||||
}
|
||||
};
|
||||
|
||||
// Constraint that requires the type to be the type type.
|
||||
using Type = BuiltinType<TypeType::SingletonInstId>;
|
||||
|
||||
// Constraint that requires the type to be a type value, whose type is type
|
||||
// type. Also accepts symbolic constant value types.
|
||||
struct AnyType {
|
||||
static auto Check(const File& sem_ir, ValidateState& state, TypeId type_id)
|
||||
-> bool {
|
||||
if (BuiltinType<TypeType::SingletonInstId>::Check(sem_ir, state, type_id)) {
|
||||
return true;
|
||||
}
|
||||
return sem_ir.types().GetAsInst(type_id).type_id() ==
|
||||
TypeType::SingletonTypeId;
|
||||
}
|
||||
};
|
||||
|
||||
// Checks that the specified type matches the given type constraint.
|
||||
template <typename TypeConstraint>
|
||||
auto Check(const File& sem_ir, ValidateState& state, TypeId type_id) -> bool {
|
||||
@@ -130,9 +146,6 @@ auto Check(const File& sem_ir, ValidateState& state, TypeId type_id) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Constraint that requires the type to be the type type.
|
||||
using Type = BuiltinType<TypeType::SingletonInstId>;
|
||||
|
||||
} // namespace
|
||||
|
||||
// Validates that this builtin has a signature matching the specified signature.
|
||||
@@ -394,6 +407,10 @@ constexpr BuiltinInfo BoolEq = {"bool.eq",
|
||||
constexpr BuiltinInfo BoolNeq = {"bool.neq",
|
||||
ValidateSignature<auto(Bool, Bool)->Bool>};
|
||||
|
||||
// "type.and": facet type combination.
|
||||
constexpr BuiltinInfo TypeAnd = {
|
||||
"type.and", ValidateSignature<auto(AnyType, AnyType)->AnyType>};
|
||||
|
||||
} // namespace BuiltinFunctionInfo
|
||||
|
||||
CARBON_DEFINE_ENUM_CLASS_NAMES(BuiltinFunctionKind) = {
|
||||
@@ -495,6 +512,9 @@ auto BuiltinFunctionKind::IsCompTimeOnly(const File& sem_ir,
|
||||
// literal types. See AnyIntLiteralTypes comment for explanation.
|
||||
return AnyIntLiteralTypes(sem_ir, arg_ids, return_type_id);
|
||||
|
||||
case TypeAnd:
|
||||
return true;
|
||||
|
||||
default:
|
||||
// TODO: Should the sized MakeType functions be compile-time only? We
|
||||
// can't produce diagnostics for bad sizes at runtime.
|
||||
|
||||
Reference in New Issue
Block a user