type.h 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef CARBON_TOOLCHAIN_CHECK_TYPE_H_
  5. #define CARBON_TOOLCHAIN_CHECK_TYPE_H_
  6. #include "llvm/ADT/ArrayRef.h"
  7. #include "toolchain/check/context.h"
  8. #include "toolchain/sem_ir/ids.h"
  9. namespace Carbon::Check {
  10. // Enforces that an integer type has a valid bit width.
  11. auto ValidateIntType(Context& context, SemIR::LocId loc_id,
  12. SemIR::IntType result) -> bool;
  13. // Enforces that the bit width is 64 for a float.
  14. auto ValidateFloatBitWidth(Context& context, SemIR::LocId loc_id,
  15. SemIR::InstId inst_id) -> bool;
  16. // Enforces that a float type has a valid bit width.
  17. auto ValidateFloatType(Context& context, SemIR::LocId loc_id,
  18. SemIR::FloatType result) -> bool;
  19. // Gets the type to use for an unbound associated entity declared in this
  20. // interface. For example, this is the type of `I.T` after
  21. // `interface I { let T:! type; }`. The name of the interface is used for
  22. // diagnostics.
  23. // TODO: Should we use a different type for each such entity, or the same type
  24. // for all associated entities?
  25. auto GetAssociatedEntityType(Context& context, SemIR::InterfaceId interface_id,
  26. SemIR::SpecificId interface_specific_id)
  27. -> SemIR::TypeId;
  28. // Gets a singleton type. The returned type will be complete. Requires that
  29. // `singleton_id` is already validated to be a singleton.
  30. auto GetSingletonType(Context& context, SemIR::TypeInstId singleton_id)
  31. -> SemIR::TypeId;
  32. // Gets a class type.
  33. auto GetClassType(Context& context, SemIR::ClassId class_id,
  34. SemIR::SpecificId specific_id) -> SemIR::TypeId;
  35. // Gets a function type. The returned type will be complete.
  36. auto GetFunctionType(Context& context, SemIR::FunctionId fn_id,
  37. SemIR::SpecificId specific_id) -> SemIR::TypeId;
  38. // Gets the type of an associated function with the `Self` parameter bound to
  39. // a particular value. The returned type will be complete.
  40. auto GetFunctionTypeWithSelfType(Context& context,
  41. SemIR::TypeInstId interface_function_type_id,
  42. SemIR::InstId self_id) -> SemIR::TypeId;
  43. // Gets a generic class type, which is the type of a name of a generic class,
  44. // such as the type of `Vector` given `class Vector(T:! type)`. The returned
  45. // type will be complete.
  46. auto GetGenericClassType(Context& context, SemIR::ClassId class_id,
  47. SemIR::SpecificId enclosing_specific_id)
  48. -> SemIR::TypeId;
  49. // Gets a generic interface type, which is the type of a name of a generic
  50. // interface, such as the type of `AddWith` given
  51. // `interface AddWith(T:! type)`. The returned type will be complete.
  52. auto GetGenericInterfaceType(Context& context, SemIR::InterfaceId interface_id,
  53. SemIR::SpecificId enclosing_specific_id)
  54. -> SemIR::TypeId;
  55. // Gets the facet type corresponding to a particular interface.
  56. auto GetInterfaceType(Context& context, SemIR::InterfaceId interface_id,
  57. SemIR::SpecificId specific_id) -> SemIR::TypeId;
  58. // Returns a pointer type whose pointee type is `pointee_type_id`.
  59. auto GetPointerType(Context& context, SemIR::TypeInstId pointee_type_id)
  60. -> SemIR::TypeId;
  61. // Returns a struct type with the given fields.
  62. auto GetStructType(Context& context, SemIR::StructTypeFieldsId fields_id)
  63. -> SemIR::TypeId;
  64. // Returns a tuple type with the given element types.
  65. auto GetTupleType(Context& context, llvm::ArrayRef<SemIR::InstId> type_inst_ids)
  66. -> SemIR::TypeId;
  67. // Returns an unbound element type.
  68. auto GetUnboundElementType(Context& context, SemIR::TypeInstId class_type_id,
  69. SemIR::TypeInstId element_type_id) -> SemIR::TypeId;
  70. } // namespace Carbon::Check
  71. #endif // CARBON_TOOLCHAIN_CHECK_TYPE_H_