import_ref.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_IMPORT_REF_H_
  5. #define CARBON_TOOLCHAIN_CHECK_IMPORT_REF_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/sem_ir/file.h"
  8. #include "toolchain/sem_ir/ids.h"
  9. namespace Carbon::Check {
  10. // Sets the IRs for `ImportIRId::ApiForImpl` from `import_ir`, and
  11. // `ImportIRId::Cpp` from defaults. Should be called before `AddImportIR` in
  12. // order to ensure the correct IDs are assigned.
  13. auto SetSpecialImportIRs(Context& context, SemIR::ImportIR import_ir) -> void;
  14. // Adds an ImportIR, returning the ID. May use an existing ID if already added.
  15. auto AddImportIR(Context& context, SemIR::ImportIR import_ir)
  16. -> SemIR::ImportIRId;
  17. // Adds an import_ref instruction for the specified instruction in the
  18. // specified IR. The import_ref is initially marked as unused.
  19. auto AddImportRef(Context& context, SemIR::ImportIRInst import_ir_inst,
  20. SemIR::EntityNameId entity_name_id) -> SemIR::InstId;
  21. // Returns the canonical IR inst for an entity. Returns an `ImportIRInst` with
  22. // a `None` ir_id for an entity that was not imported. This may add an
  23. // `ImportIR` if it finds an indirectly referenced `File` that hasn't previously
  24. // been found.
  25. auto GetCanonicalImportIRInst(Context& context, SemIR::InstId inst_id)
  26. -> SemIR::ImportIRInst;
  27. // Verifies a new instruction is the same as a previous instruction.
  28. // prev_import_ir_inst should come from GetCanonicalImportIRInst.
  29. auto VerifySameCanonicalImportIRInst(Context& context, SemIR::NameId name_id,
  30. SemIR::InstId prev_id,
  31. SemIR::ImportIRInst prev_import_ir_inst,
  32. SemIR::ImportIRId new_ir_id,
  33. const SemIR::File* new_import_ir,
  34. SemIR::InstId new_inst_id) -> void;
  35. // If the passed in instruction ID is an ImportRefUnloaded, turns it into an
  36. // ImportRefLoaded for use.
  37. auto LoadImportRef(Context& context, SemIR::InstId inst_id) -> void;
  38. // Load all impls declared in the api file corresponding to this impl file.
  39. auto ImportImplsFromApiFile(Context& context) -> void;
  40. // Load an impl that is declared in an imported IR.
  41. auto ImportImpl(Context& context, SemIR::ImportIRId import_ir_id,
  42. SemIR::ImplId impl_id) -> void;
  43. // Load an interface that is declared in an imported IR.
  44. auto ImportInterface(Context& context, SemIR::ImportIRId import_ir_id,
  45. SemIR::InterfaceId interface_id) -> SemIR::InterfaceId;
  46. } // namespace Carbon::Check
  47. #endif // CARBON_TOOLCHAIN_CHECK_IMPORT_REF_H_