import_ref.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 `ImportIRInst` with
  21. // a `None` ir_id for an entity that was not imported.
  22. auto GetCanonicalImportIRInst(Context& context, SemIR::InstId inst_id)
  23. -> SemIR::ImportIRInst;
  24. // Verifies a new instruction is the same as a previous instruction.
  25. // prev_import_ir_inst should come from GetCanonicalImportIRInst.
  26. auto VerifySameCanonicalImportIRInst(Context& context, SemIR::InstId prev_id,
  27. SemIR::ImportIRInst prev_import_ir_inst,
  28. SemIR::ImportIRId new_ir_id,
  29. const SemIR::File* new_import_ir,
  30. SemIR::InstId new_inst_id) -> void;
  31. // If the passed in instruction ID is an ImportRefUnloaded, turns it into an
  32. // ImportRefLoaded for use.
  33. auto LoadImportRef(Context& context, SemIR::InstId inst_id) -> void;
  34. // Load all impls declared in the api file corresponding to this impl file.
  35. auto ImportImplsFromApiFile(Context& context) -> void;
  36. // Load a specific impl declared in an imported IR.
  37. auto ImportImpl(Context& context, SemIR::ImportIRId import_ir_id,
  38. SemIR::ImplId impl_id) -> void;
  39. } // namespace Carbon::Check
  40. #endif // CARBON_TOOLCHAIN_CHECK_IMPORT_REF_H_