Skip to content

[SIL] Don't print duplicated import decls #17084

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
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
9 changes: 9 additions & 0 deletions lib/SIL/SILPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2712,6 +2712,15 @@ void SILModule::print(SILPrintContext &PrintCtx, ModuleDecl *M,
!D->isImplicit()) {
if (isa<AccessorDecl>(D))
continue;

// skip to visit ASTPrinter to avoid sil-opt prints duplicated import declarations
if (auto importDecl = dyn_cast<ImportDecl>(D)) {
StringRef importName = importDecl->getModule()->getName().str();
if (importName == BUILTIN_NAME ||
importName == STDLIB_NAME ||
importName == SWIFT_SHIMS_NAME)
continue;
}
D->print(OS, Options);
OS << "\n\n";
}
Expand Down
19 changes: 19 additions & 0 deletions test/SIL/import-decls.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: %empty-directory(%t)
// RUN: touch %t/empty.swift
// RUN: %target-swift-frontend -emit-module -module-name TestModule %t/empty.swift -o %t
// RUN: %target-sil-opt %s -I=%t | %FileCheck %s

sil_stage raw

import Builtin
import Swift

import TestModule

func foo() {}

// CHECK: import Builtin
// CHECK: import Swift
// CHECK-NOT: import Builtin
// CHECK-NOT: import Swift{{$}}
// CHECK: import TestModule