mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 10:54:49 +01:00
Add support for iN and uN for all suitable N. (#3868)
`i32` is retained as a special case for now, for bootstrapping purposes, and maps to `BuiltinIntType`, which is distinct from `Core.Int(32)`. This will be removed later once we support `Core.BigInt`. For now this provides both the `iN` types and also the builtins to support `Core.Int(N)`. The intent is that we'll change the `iN` support to rewrite to calls here when we do that for the other type literals and type keywords. No conversions between integer types are supported yet, and all literals are of type `i32`, so we can't actually form values of any of these new types. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com> Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
This commit is contained in:
co-authored by
Jon Ross-Perkins
Carbon Infra Bot
parent
895e90e791
commit
bb117aea3a
@@ -64,10 +64,16 @@ struct BuiltinType {
|
||||
using Bool = BuiltinType<InstId::BuiltinBoolType>;
|
||||
|
||||
// Constraint that requires the type to be an integer type.
|
||||
//
|
||||
// TODO: This only matches i32 for now. Support iN for all N, and the
|
||||
// Core.BigInt type we use to implement for integer literals.
|
||||
using AnyInt = BuiltinType<InstId::BuiltinIntType>;
|
||||
struct AnyInt {
|
||||
static auto Check(const File& sem_ir, ValidateState& state, TypeId type_id)
|
||||
-> bool {
|
||||
// TODO: Support Core.BigInt once it exists.
|
||||
if (BuiltinType<InstId::BuiltinIntType>::Check(sem_ir, state, type_id)) {
|
||||
return true;
|
||||
}
|
||||
return sem_ir.types().Is<IntType>(type_id);
|
||||
}
|
||||
};
|
||||
|
||||
// Constraint that requires the type to be the type type.
|
||||
using Type = BuiltinType<InstId::BuiltinTypeType>;
|
||||
@@ -141,9 +147,18 @@ constexpr BuiltinInfo None = {"", nullptr};
|
||||
constexpr BuiltinInfo IntMakeType32 = {"int.make_type_32",
|
||||
ValidateSignature<auto()->Type>};
|
||||
|
||||
// Returns the `iN` type.
|
||||
// TODO: Should we use a more specific type as the type of the bit width?
|
||||
constexpr BuiltinInfo IntMakeTypeSigned = {
|
||||
"int.make_type_signed", ValidateSignature<auto(AnyInt)->Type>};
|
||||
|
||||
// Returns the `uN` type.
|
||||
constexpr BuiltinInfo IntMakeTypeUnsigned = {
|
||||
"int.make_type_unsigned", ValidateSignature<auto(AnyInt)->Type>};
|
||||
|
||||
// Returns float types, such as `f64`. Currently only supports `f64`.
|
||||
constexpr BuiltinInfo FloatMakeType = {"float.make_type",
|
||||
ValidateSignature<auto(IntT)->Type>};
|
||||
ValidateSignature<auto(AnyInt)->Type>};
|
||||
|
||||
// Returns the `bool` type.
|
||||
constexpr BuiltinInfo BoolMakeType = {"bool.make_type",
|
||||
|
||||
Reference in New Issue
Block a user