type.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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, SemIRLoc loc, SemIR::IntType result)
  12. -> bool;
  13. // Enforces that the bit width is 64 for a float.
  14. auto ValidateFloatBitWidth(Context& context, SemIRLoc loc,
  15. SemIR::InstId inst_id) -> bool;
  16. // Enforces that a float type has a valid bit width.
  17. auto ValidateFloatType(Context& context, SemIRLoc loc, SemIR::FloatType result)
  18. -> 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::TypeId interface_type_id)
  26. -> SemIR::TypeId;
  27. // Gets a singleton type. The returned type will be complete. Requires that
  28. // `singleton_id` is already validated to be a singleton.
  29. auto GetSingletonType(Context& context, SemIR::InstId singleton_id)
  30. -> SemIR::TypeId;
  31. // Gets a class type.
  32. auto GetClassType(Context& context, SemIR::ClassId class_id,
  33. SemIR::SpecificId specific_id) -> SemIR::TypeId;
  34. // Gets a function type. The returned type will be complete.
  35. auto GetFunctionType(Context& context, SemIR::FunctionId fn_id,
  36. SemIR::SpecificId specific_id) -> SemIR::TypeId;
  37. // Gets the type of an associated function with the `Self` parameter bound to
  38. // a particular value. The returned type will be complete.
  39. auto GetFunctionTypeWithSelfType(Context& context,
  40. SemIR::InstId interface_function_type_id,
  41. SemIR::InstId self_id) -> SemIR::TypeId;
  42. // Gets a generic class type, which is the type of a name of a generic class,
  43. // such as the type of `Vector` given `class Vector(T:! type)`. The returned
  44. // type will be complete.
  45. auto GetGenericClassType(Context& context, SemIR::ClassId class_id,
  46. SemIR::SpecificId enclosing_specific_id)
  47. -> SemIR::TypeId;
  48. // Gets a generic interface type, which is the type of a name of a generic
  49. // interface, such as the type of `AddWith` given
  50. // `interface AddWith(T:! type)`. The returned type will be complete.
  51. auto GetGenericInterfaceType(Context& context, SemIR::InterfaceId interface_id,
  52. SemIR::SpecificId enclosing_specific_id)
  53. -> SemIR::TypeId;
  54. // Gets the facet type corresponding to a particular interface.
  55. auto GetInterfaceType(Context& context, SemIR::InterfaceId interface_id,
  56. SemIR::SpecificId specific_id) -> SemIR::TypeId;
  57. // Returns a pointer type whose pointee type is `pointee_type_id`.
  58. auto GetPointerType(Context& context, SemIR::TypeId pointee_type_id)
  59. -> SemIR::TypeId;
  60. // Returns a struct type with the given fields.
  61. auto GetStructType(Context& context, SemIR::StructTypeFieldsId fields_id)
  62. -> SemIR::TypeId;
  63. // Returns a tuple type with the given element types.
  64. auto GetTupleType(Context& context, llvm::ArrayRef<SemIR::TypeId> type_ids)
  65. -> SemIR::TypeId;
  66. // Returns an unbound element type.
  67. auto GetUnboundElementType(Context& context, SemIR::TypeId class_type_id,
  68. SemIR::TypeId element_type_id) -> SemIR::TypeId;
  69. } // namespace Carbon::Check
  70. #endif // CARBON_TOOLCHAIN_CHECK_TYPE_H_