Skip to content

[frontend] Fix TBD validation almost always done for modules #40414

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
Dec 17, 2021
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
6 changes: 5 additions & 1 deletion lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1390,10 +1390,14 @@ static bool validateTBDIfNeeded(const CompilerInvocation &Invocation,
// may have serialized hand-crafted SIL definitions that are invisible to
// TBDGen as it is an AST-only traversal.
if (auto *mod = MSF.dyn_cast<ModuleDecl *>()) {
return llvm::none_of(mod->getFiles(), [](const FileUnit *File) -> bool {
bool hasSIB = llvm::any_of(mod->getFiles(), [](const FileUnit *File) -> bool {
auto SASTF = dyn_cast<SerializedASTFile>(File);
return SASTF && SASTF->isSIB();
});

if (hasSIB) {
return false;
}
}

// "Default" mode's behavior varies if using a debug compiler.
Expand Down
25 changes: 25 additions & 0 deletions test/TBD/sib-module.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %empty-directory(%t)

// RUN: %target-swiftc_driver -emit-sib -module-name mysibmodule %s -o - | %target-swiftc_driver -emit-module -module-name mysibmodule -o %t/mysibmodule.swiftmodule -

/// Since -validate-tbd-against-ir=default, TBD validation is not done since the module has a SIB file
// RUN: %target-swift-frontend -emit-sil %t/mysibmodule.swiftmodule | %FileCheck %s

// RUN: %target-swiftc_driver -emit-module -module-name mynonsibmodule -o %t/mynonsibmodule.swiftmodule %s

/// Since -validate-tbd-against-ir=default, TBD validation is done or not depending on the build configuration
// RUN: %target-swift-frontend -emit-sil %t/mynonsibmodule.swiftmodule | %FileCheck %s

public class MyClass {
var x : Int

public init(input : Int) {
x = 2 * input
}

public func do_something(input : Int) -> Int {
return x * input
}
}

// CHECK: class MyClass