mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Expand use of CheckIRId stores (#5820)
This is trying to make it clearer when vectors are being indexed with `CheckIRId`. The only one that I still kind of want to change is the `SmallVector<std::unique_ptr<CompilationUnit>>`, but because it's a `unique_ptr` that's a little more complex. I may not bother. Note, some of the changes around nuanced `SmallVector` interactions were based on trying to copy the way `SmallVector` itself takes arguments, like with range passing.
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include "llvm/ADT/IntrusiveRefCntPtr.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/VirtualFileSystem.h"
|
||||
#include "toolchain/base/fixed_size_value_store.h"
|
||||
#include "toolchain/base/kind_switch.h"
|
||||
#include "toolchain/check/diagnostic_helpers.h"
|
||||
#include "toolchain/check/generic.h"
|
||||
@@ -55,15 +56,14 @@ static auto GetImportedIRCount(UnitAndImports* unit_and_imports) -> int {
|
||||
|
||||
CheckUnit::CheckUnit(
|
||||
UnitAndImports* unit_and_imports,
|
||||
llvm::ArrayRef<Parse::GetTreeAndSubtreesFn> tree_and_subtrees_getters,
|
||||
const Parse::GetTreeAndSubtreesStore* tree_and_subtrees_getters,
|
||||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
|
||||
std::shared_ptr<clang::CompilerInvocation> clang_invocation,
|
||||
llvm::raw_ostream* vlog_stream)
|
||||
: unit_and_imports_(unit_and_imports),
|
||||
tree_and_subtrees_getter_(
|
||||
tree_and_subtrees_getters
|
||||
[unit_and_imports->unit->sem_ir->check_ir_id().index]),
|
||||
total_ir_count_(tree_and_subtrees_getters.size()),
|
||||
tree_and_subtrees_getter_(tree_and_subtrees_getters->Get(
|
||||
unit_and_imports->unit->sem_ir->check_ir_id())),
|
||||
total_ir_count_(tree_and_subtrees_getters->size()),
|
||||
fs_(std::move(fs)),
|
||||
clang_invocation_(std::move(clang_invocation)),
|
||||
emitter_(&unit_and_imports_->err_tracker, tree_and_subtrees_getters,
|
||||
@@ -163,11 +163,12 @@ auto CheckUnit::InitPackageScopeAndImports() -> void {
|
||||
|
||||
auto CheckUnit::CollectDirectImports(
|
||||
llvm::SmallVector<SemIR::ImportIR>& results,
|
||||
llvm::MutableArrayRef<int> ir_to_result_index, SemIR::InstId import_decl_id,
|
||||
const PackageImports& imports, bool is_local) -> void {
|
||||
FixedSizeValueStore<SemIR::CheckIRId, int>& ir_to_result_index,
|
||||
SemIR::InstId import_decl_id, const PackageImports& imports, bool is_local)
|
||||
-> void {
|
||||
for (const auto& import : imports.imports) {
|
||||
const auto& direct_ir = *import.unit_info->unit->sem_ir;
|
||||
auto& index = ir_to_result_index[direct_ir.check_ir_id().index];
|
||||
auto& index = ir_to_result_index.Get(direct_ir.check_ir_id());
|
||||
if (index != -1) {
|
||||
// This should only happen when doing API imports for an implementation
|
||||
// file. Don't change the entry; is_export doesn't matter.
|
||||
@@ -191,7 +192,9 @@ auto CheckUnit::CollectTransitiveImports(SemIR::InstId import_decl_id,
|
||||
// Track whether an IR was imported in full, including `export import`. This
|
||||
// distinguishes from IRs that are indirectly added without all names being
|
||||
// exported to this IR.
|
||||
llvm::SmallVector<int> ir_to_result_index(total_ir_count_, -1);
|
||||
auto ir_to_result_index =
|
||||
FixedSizeValueStore<SemIR::CheckIRId, int>::MakeWithExplicitSize(
|
||||
total_ir_count_, -1);
|
||||
|
||||
// First add direct imports. This means that if an entity is imported both
|
||||
// directly and indirectly, the import path will reflect the direct import.
|
||||
@@ -219,7 +222,7 @@ auto CheckUnit::CollectTransitiveImports(SemIR::InstId import_decl_id,
|
||||
}
|
||||
|
||||
auto& indirect_index =
|
||||
ir_to_result_index[indirect_ir.sem_ir->check_ir_id().index];
|
||||
ir_to_result_index.Get(indirect_ir.sem_ir->check_ir_id());
|
||||
if (indirect_index == -1) {
|
||||
indirect_index = results.size();
|
||||
// TODO: In the case of a recursive `export import`, this only points at
|
||||
|
||||
Reference in New Issue
Block a user