Skip to content

[DebugInfo] Don't record that the standard library imports itself #17226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,17 +1111,25 @@ void IRGenerator::emitGlobalTopLevel(bool emitForParallelEmission) {

void IRGenModule::finishEmitAfterTopLevel() {
// Emit the implicit import of the swift standard library.
// FIXME: We'd get the exact set of implicit imports if we went through the
// SourceFile's getImportedModules instead, but then we'd lose location info
// for the explicit imports.
if (DebugInfo) {
std::pair<swift::Identifier, swift::SourceLoc> AccessPath[] = {
{ Context.StdlibModuleName, swift::SourceLoc() }
};
if (ModuleDecl *TheStdlib = Context.getStdlibModule()) {
if (TheStdlib != getSwiftModule()) {
std::pair<swift::Identifier, swift::SourceLoc> AccessPath[] = {
{ Context.StdlibModuleName, swift::SourceLoc() }
};

auto Imp = ImportDecl::create(Context,
getSwiftModule(),
SourceLoc(),
ImportKind::Module, SourceLoc(),
AccessPath);
DebugInfo->emitImport(Imp);
auto Imp = ImportDecl::create(Context,
getSwiftModule(),
SourceLoc(),
ImportKind::Module, SourceLoc(),
AccessPath);
Imp->setModule(TheStdlib);
DebugInfo->emitImport(Imp);
}
}
}
}

Expand Down
11 changes: 2 additions & 9 deletions lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1696,15 +1696,8 @@ void IRGenDebugInfoImpl::emitImport(ImportDecl *D) {
if (Opts.DebugInfoKind <= IRGenDebugInfoKind::LineTables)
return;

swift::ModuleDecl *M = IGM.Context.getModule(D->getModulePath());
if (!M &&
D->getModulePath()[0].first == IGM.Context.TheBuiltinModule->getName())
M = IGM.Context.TheBuiltinModule;
if (!M) {
assert(M && "Could not find module for import decl.");
return;
}
ModuleDecl::ImportedModule Imported = {D->getModulePath(), M};
assert(D->getModule() && "compiler-synthesized ImportDecl is incomplete");
ModuleDecl::ImportedModule Imported = {D->getModulePath(), D->getModule()};
auto DIMod = getOrCreateModule(Imported);
auto L = getDebugLoc(*this, D);
auto *File = getOrCreateFile(L.Filename);
Expand Down
26 changes: 26 additions & 0 deletions test/DebugInfo/ImportsStdlib.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// RUN: %empty-directory(%t)

// RUN: %target-swift-frontend -emit-ir -parse-stdlib -module-name NotTheStdlib %s -I %t -g -o - > %t.ll
// RUN: %FileCheck %s < %t.ll
// RUN: %FileCheck -check-prefix=NEGATIVE %s < %t.ll

// RUN: %target-swift-frontend -c -parse-stdlib -module-name NotTheStdlib %s -I %t -g -o %t.o
// RUN: %llvm-dwarfdump -a %t.o > %t.dump
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking the IR would have been sufficient — we already check that a DIImportedEntity(DIModule) gets lowered correctly elsewhere, but this is fine, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. I copied from the other test and just updated everything.

// RUN: %FileCheck -check-prefix=DWARF %s < %t.dump
// RUN: %FileCheck -check-prefix=NEGATIVE-DWARF %s < %t.dump

// CHECK-DAG: ![[MODULE:[0-9]+]] = !DIModule({{.*}}, name: "NotTheStdlib", includePath: "{{.*}}test{{.*}}DebugInfo{{.*}}"
// CHECK-DAG: !DIImportedEntity(tag: DW_TAG_imported_module, scope: ![[THISFILE:[0-9]+]], entity: ![[MODULE]]
// CHECK-DAG: ![[THISFILE]] = !DIFile(filename: "ImportsStdlib.swift", directory: "{{.*}}test/DebugInfo")

// NEGATIVE-NOT: !DIFile(filename: "Swift.swiftmodule"
// NEGATIVE-NOT: !DIModule({{.*}}, name: "Swift"

// DWARF: .debug_info
// DWARF: DW_TAG_module
// DWARF: DW_AT_name ("NotTheStdlib")
// DWARF: DW_AT_LLVM_include_path

// DWARF: file_names{{.*}} ImportsStdlib.swift

// NEGATIVE-DWARF-NOT: DW_AT_name ("Swift")