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:
Jon Ross-Perkins
2024-04-04 23:47:06 +00:00
committed by GitHub
parent f44643f080
commit 6889aff49a
9 changed files with 360 additions and 0 deletions
@@ -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>};