import_ref.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 IR for ImportIRId::ApiForImpl. Should be called before AddImportIR
  11. // in order to ensure the correct ID is assigned.
  12. auto SetApiImportIR(Context& context, SemIR::ImportIR import_ir) -> void;
  13. // Adds an ImportIR, returning the ID. May use an existing ID if already added.
  14. auto AddImportIR(Context& context, SemIR::ImportIR import_ir)
  15. -> SemIR::ImportIRId;
  16. // Adds an import_ref instruction for the specified instruction in the
  17. // specified IR. The import_ref is initially marked as unused.
  18. auto AddImportRef(Context& context, SemIR::ImportIRInst import_ir_inst,
  19. SemIR::EntityNameId entity_name_id) -> SemIR::InstId;
  20. // Returns the canonical IR inst for an entity. Returns an invalid ir_id for the
  21. // current IR.
  22. auto GetCanonicalImportIRInst(Context& context, const SemIR::File* cursor_ir,
  23. SemIR::InstId cursor_inst_id)
  24. -> SemIR::ImportIRInst;
  25. // Verifies a new instruction is the same as a previous instruction.
  26. // prev_import_ir_inst should come from GetCanonicalImportIRInst.
  27. auto VerifySameCanonicalImportIRInst(Context& context, SemIR::InstId prev_id,
  28. SemIR::ImportIRInst prev_import_ir_inst,
  29. SemIR::ImportIRId new_ir_id,
  30. const SemIR::File* new_import_ir,
  31. SemIR::InstId new_inst_id) -> void;
  32. // If the passed in instruction ID is an ImportRefUnloaded, turns it into an
  33. // ImportRefLoaded for use.
  34. auto LoadImportRef(Context& context, SemIR::InstId inst_id) -> void;
  35. // Load all impls declared in the api file corresponding to this impl file.
  36. auto ImportImplsFromApiFile(Context& context) -> void;
  37. // Load a specific impl declared in an imported IR.
  38. auto ImportImpl(Context& context, SemIR::ImportIRId import_ir_id,
  39. SemIR::ImplId impl_id) -> void;
  40. } // namespace Carbon::Check
  41. #endif // CARBON_TOOLCHAIN_CHECK_IMPORT_REF_H_