Skip to content

Commit d3762f9

Browse files
authored
Remove unused ImportCppId and list of Cpp imports in File (#6290)
See discussion: https://discord.com/channels/655572317891461132/655578254970716160/1432518191350808659 Part of #5245.
1 parent 9b95944 commit d3762f9

File tree

9 files changed

+15
-30
lines changed

9 files changed

+15
-30
lines changed

toolchain/base/value_ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct PackageNameId : public IdBase<PackageNameId> {
8383
static constexpr llvm::StringLiteral Label = "package";
8484
static const PackageNameId None;
8585
static const PackageNameId Core;
86+
static constexpr llvm::StringLiteral CppName = "Cpp";
8687

8788
// Returns the PackageNameId corresponding to a particular IdentifierId.
8889
static auto ForIdentifier(IdentifierId id) -> PackageNameId {

toolchain/check/check.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ static auto GetImportKey(UnitAndImports& unit_info,
5252
return {package_name, library_name};
5353
}
5454

55-
static constexpr llvm::StringLiteral CppPackageName = "Cpp";
5655
static constexpr llvm::StringLiteral MainPackageName = "Main";
5756

5857
static auto RenderImportKey(ImportKey import_key) -> std::string {
@@ -81,7 +80,7 @@ static auto TrackImport(Map<ImportKey, UnitAndImports*>& api_map,
8180
const auto import_key = GetImportKey(unit_info, file_package_id, import);
8281
const auto& [import_package_name, import_library_name] = import_key;
8382

84-
if (import_package_name == CppPackageName) {
83+
if (import_package_name == PackageNameId::CppName) {
8584
if (!explicit_import_map) {
8685
// Don't diagnose the implicit import in `impl package Cpp`, because we'll
8786
// have diagnosed the use of `Cpp` in the declaration.
@@ -265,7 +264,8 @@ static auto BuildApiMapAndDiagnosePackaging(
265264
import_key.second.empty() ? ExplicitMainPackage
266265
: ExplicitMainLibrary);
267266
continue;
268-
} else if (import_key.first == CppPackageName) {
267+
}
268+
if (import_key.first == PackageNameId::CppName) {
269269
CARBON_DIAGNOSTIC(CppPackageDeclaration, Error,
270270
"`Cpp` cannot be used by a `package` declaration");
271271
unit_info.emitter.Emit(packaging->names.node_id, CppPackageDeclaration);

toolchain/check/cpp/import.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,14 +440,6 @@ static auto GenerateAst(
440440
static auto AddNamespace(Context& context, PackageNameId cpp_package_id,
441441
llvm::ArrayRef<Parse::Tree::PackagingNames> imports)
442442
-> SemIR::NameScopeId {
443-
auto& import_cpps = context.sem_ir().import_cpps();
444-
import_cpps.Reserve(imports.size());
445-
for (const Parse::Tree::PackagingNames& import : imports) {
446-
import_cpps.Add({.node_id = context.parse_tree().As<Parse::ImportDeclId>(
447-
import.node_id),
448-
.library_id = import.library_id});
449-
}
450-
451443
return AddImportNamespaceToScope(
452444
context,
453445
GetSingletonType(context, SemIR::NamespaceType::TypeInstId),

toolchain/sem_ir/absolute_node_id.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ static auto FollowImportRef(
1616
ImportIRInstId import_ir_inst_id) -> bool {
1717
auto import_ir_inst = cursor_ir->import_ir_insts().Get(import_ir_inst_id);
1818
if (import_ir_inst.ir_id() == ImportIRId::Cpp) {
19-
CARBON_CHECK(cursor_ir->import_cpps().size() > 0);
2019
absolute_node_ids.push_back(
2120
AbsoluteNodeId(import_ir_inst.clang_source_loc_id()));
2221
return true;

toolchain/sem_ir/file.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ File::File(const Parse::Tree* parse_tree, CheckIRId check_ir_id,
5151
// The `2` prevents adding a tag for the global ids
5252
// `ImportIRId::{ApiForImpl,Cpp}`.
5353
import_irs_(IdTag(check_ir_id.index, 2)),
54-
import_cpps_(check_ir_id),
5554
clang_decls_(check_ir_id),
5655
// The `+1` prevents adding a tag to the global `NameSpace::PackageInstId`
5756
// instruction. It's not a "singleton" instruction, but it's a unique

toolchain/sem_ir/file.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ class File : public Printable<File> {
211211
auto import_ir_insts() const -> const ImportIRInstStore& {
212212
return import_ir_insts_;
213213
}
214-
auto import_cpps() -> ImportCppStore& { return import_cpps_; }
215-
auto import_cpps() const -> const ImportCppStore& { return import_cpps_; }
216214
auto clang_ast_unit() -> clang::ASTUnit* { return clang_ast_unit_; }
217215
auto clang_ast_unit() const -> const clang::ASTUnit* {
218216
return clang_ast_unit_;
@@ -360,9 +358,6 @@ class File : public Printable<File> {
360358
// that are import-related.
361359
ImportIRInstStore import_ir_insts_;
362360

363-
// List of Cpp imports.
364-
ImportCppStore import_cpps_;
365-
366361
// The Clang AST to use when looking up `Cpp` names. Null if there are no
367362
// `Cpp` imports.
368363
clang::ASTUnit* clang_ast_unit_ = nullptr;

toolchain/sem_ir/formatter.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,13 +1253,21 @@ auto Formatter::FormatCallRhs(Call inst) -> void {
12531253
auto Formatter::FormatImportCppDeclRhs() -> void {
12541254
out_ << " ";
12551255
OpenBrace();
1256-
for (ImportCpp import_cpp : sem_ir_->import_cpps().values()) {
1256+
for (const Parse::Tree::PackagingNames& import :
1257+
sem_ir_->parse_tree().imports()) {
1258+
if (auto package_ident_id = import.package_id.AsIdentifierId();
1259+
!package_ident_id.has_value() ||
1260+
sem_ir_->identifiers().Get(package_ident_id) !=
1261+
PackageNameId::CppName) {
1262+
continue;
1263+
}
1264+
12571265
Indent();
12581266
out_ << "import Cpp ";
1259-
if (import_cpp.library_id.has_value()) {
1267+
if (import.library_id.has_value()) {
12601268
out_ << "\""
12611269
<< FormatEscaped(
1262-
sem_ir_->string_literal_values().Get(import_cpp.library_id))
1270+
sem_ir_->string_literal_values().Get(import.library_id))
12631271
<< "\"";
12641272
} else {
12651273
out_ << "inline";

toolchain/sem_ir/ids.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,6 @@ struct GenericInstIndex : public IndexBase<GenericInstIndex> {
447447
constexpr GenericInstIndex GenericInstIndex::None =
448448
GenericInstIndex::MakeNone();
449449

450-
// The ID of an `ImportCpp`.
451-
struct ImportCppId : public IdBase<ImportCppId> {
452-
static constexpr llvm::StringLiteral Label = "import_cpp";
453-
454-
using IdBase::IdBase;
455-
};
456-
457450
// The ID of an `ImportIR` within the set of imported IRs, both direct and
458451
// indirect.
459452
struct ImportIRId : public IdBase<ImportIRId> {

toolchain/sem_ir/import_cpp.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ struct ImportCpp : Printable<ImportCpp> {
2020
StringLiteralValueId library_id;
2121
};
2222

23-
using ImportCppStore = ValueStore<ImportCppId, ImportCpp>;
24-
2523
} // namespace Carbon::SemIR
2624

2725
#endif // CARBON_TOOLCHAIN_SEM_IR_IMPORT_CPP_H_

0 commit comments

Comments
 (0)