mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 08:44:41 +01:00
Add functions for instantiating builtin types through lookup. (#3857)
Note, my instinct is that `Float(dyn_size)` should be invalid. However, I think the constant evaluation doesn't result in the call being evaluated in eval.cpp when the size is non-constant. I think I could get an error for symbolic phase calls, but that seems a little less interesting already. Long-term maybe we want a way to mark functions as _must_ be evaluated during constant phase? Also, I think there may be a bug with literal value parse node locations, I should be able to point at the position of `arg_ids[0]` but it's missing a line number so I point at `loc` instead.
This commit is contained in:
@@ -68,6 +68,10 @@ using Bool = BuiltinType<InstId::BuiltinBoolType>;
|
||||
// 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>;
|
||||
|
||||
// Constraint that requires the type to be the type type.
|
||||
using Type = BuiltinType<InstId::BuiltinTypeType>;
|
||||
|
||||
} // namespace
|
||||
|
||||
// Validates that this builtin has a signature matching the specified signature.
|
||||
@@ -132,6 +136,19 @@ using IntU = TypeParam<1, AnyInt>;
|
||||
// Not a builtin function.
|
||||
constexpr BuiltinInfo None = {"", nullptr};
|
||||
|
||||
// Returns the `i32` type. Doesn't take a bit size because we need an integer
|
||||
// type as a basis for that.
|
||||
constexpr BuiltinInfo IntMakeType32 = {"int.make_type_32",
|
||||
ValidateSignature<auto()->Type>};
|
||||
|
||||
// Returns float types, such as `f64`. Currently only supports `f64`.
|
||||
constexpr BuiltinInfo FloatMakeType = {"float.make_type",
|
||||
ValidateSignature<auto(IntT)->Type>};
|
||||
|
||||
// Returns the `bool` type.
|
||||
constexpr BuiltinInfo BoolMakeType = {"bool.make_type",
|
||||
ValidateSignature<auto()->Type>};
|
||||
|
||||
// "int.negate": integer negation.
|
||||
constexpr BuiltinInfo IntNegate = {"int.negate",
|
||||
ValidateSignature<auto(IntT)->IntT>};
|
||||
|
||||
Reference in New Issue
Block a user