type.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. // Gets the type to use for an unbound associated entity declared in this
  11. // interface. For example, this is the type of `I.T` after
  12. // `interface I { let T:! type; }`. The name of the interface is used for
  13. // diagnostics.
  14. // TODO: Should we use a different type for each such entity, or the same type
  15. // for all associated entities?
  16. auto GetAssociatedEntityType(Context& context, SemIR::TypeId interface_type_id)
  17. -> SemIR::TypeId;
  18. // Gets a singleton type. The returned type will be complete. Requires that
  19. // `singleton_id` is already validated to be a singleton.
  20. auto GetSingletonType(Context& context, SemIR::InstId singleton_id)
  21. -> SemIR::TypeId;
  22. // Gets a class type.
  23. auto GetClassType(Context& context, SemIR::ClassId class_id,
  24. SemIR::SpecificId specific_id) -> SemIR::TypeId;
  25. // Gets a function type. The returned type will be complete.
  26. auto GetFunctionType(Context& context, SemIR::FunctionId fn_id,
  27. SemIR::SpecificId specific_id) -> SemIR::TypeId;
  28. // Gets the type of an associated function with the `Self` parameter bound to
  29. // a particular value. The returned type will be complete.
  30. auto GetFunctionTypeWithSelfType(Context& context,
  31. SemIR::InstId interface_function_type_id,
  32. SemIR::InstId self_id) -> SemIR::TypeId;
  33. // Gets a generic class type, which is the type of a name of a generic class,
  34. // such as the type of `Vector` given `class Vector(T:! type)`. The returned
  35. // type will be complete.
  36. auto GetGenericClassType(Context& context, SemIR::ClassId class_id,
  37. SemIR::SpecificId enclosing_specific_id)
  38. -> SemIR::TypeId;
  39. // Gets a generic interface type, which is the type of a name of a generic
  40. // interface, such as the type of `AddWith` given
  41. // `interface AddWith(T:! type)`. The returned type will be complete.
  42. auto GetGenericInterfaceType(Context& context, SemIR::InterfaceId interface_id,
  43. SemIR::SpecificId enclosing_specific_id)
  44. -> SemIR::TypeId;
  45. // Gets the facet type corresponding to a particular interface.
  46. auto GetInterfaceType(Context& context, SemIR::InterfaceId interface_id,
  47. SemIR::SpecificId specific_id) -> SemIR::TypeId;
  48. // Returns a pointer type whose pointee type is `pointee_type_id`.
  49. auto GetPointerType(Context& context, SemIR::TypeId pointee_type_id)
  50. -> SemIR::TypeId;
  51. // Returns a struct type with the given fields.
  52. auto GetStructType(Context& context, SemIR::StructTypeFieldsId fields_id)
  53. -> SemIR::TypeId;
  54. // Returns a tuple type with the given element types.
  55. auto GetTupleType(Context& context, llvm::ArrayRef<SemIR::TypeId> type_ids)
  56. -> SemIR::TypeId;
  57. // Returns an unbound element type.
  58. auto GetUnboundElementType(Context& context, SemIR::TypeId class_type_id,
  59. SemIR::TypeId element_type_id) -> SemIR::TypeId;
  60. } // namespace Carbon::Check
  61. #endif // CARBON_TOOLCHAIN_CHECK_TYPE_H_