Skip to content

Commit caa3dd4

Browse files
committed
[Frontend] Turn symbols-missing-from-TBD validation on by default in debug builds on Apple platforms.
TBD validation is effectively an expensive assertion, and is currently only tuned for Apple platforms. However, we don't want it to regress more, and it would be nice to start getting validation from people using master snapshots. Together, this means that turning it on by default for the cases mentioned above is an appropriate course of action. At the very least, this has the benefit of running validation across the stdlib, the overlays and the whole testsuite on each build, so people making changes to the compiler that change symbols are hopefully alerted. One limitation here is that this is only validating that the TBD is a superset of the true set of symbols: it could include spurious symbols that aren't actually in the binary. This case is less problematic for Swift than symbols missing from the TBD file, and so we've focused energy on this. Once we've fixed the extra-symbols problems and are confident in it, this validation can be upgraded to validate that too. Half of rdar://problem/40431434.
1 parent 4c2f529 commit caa3dd4

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

include/swift/Frontend/FrontendOptions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,14 @@ class FrontendOptions {
240240

241241
/// The different modes for validating TBD against the LLVM IR.
242242
enum class TBDValidationMode {
243+
Default, ///< Do the default validation for the current platform.
243244
None, ///< Do no validation.
244245
MissingFromTBD, ///< Only check for symbols that are in IR but not TBD.
245246
All, ///< Check for symbols that are in IR but not TBD and TBD but not IR.
246247
};
247248

248249
/// Compare the symbols in the IR against the TBD file we would generate.
249-
TBDValidationMode ValidateTBDAgainstIR = TBDValidationMode::None;
250+
TBDValidationMode ValidateTBDAgainstIR = TBDValidationMode::Default;
250251

251252
/// The install_name to use in the TBD file.
252253
std::string TBDInstallName;

lib/FrontendTool/FrontendTool.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,9 +1144,20 @@ static bool validateTBDIfNeeded(CompilerInvocation &Invocation,
11441144
return false;
11451145

11461146
const auto &frontendOpts = Invocation.getFrontendOptions();
1147-
const auto mode = frontendOpts.ValidateTBDAgainstIR;
1147+
auto mode = frontendOpts.ValidateTBDAgainstIR;
11481148
// Ensure all cases are covered by using a switch here.
11491149
switch (mode) {
1150+
case FrontendOptions::TBDValidationMode::Default:
1151+
#ifndef NDEBUG
1152+
// When a debug compiler is targeting an apple platform, we do some
1153+
// validation by default.
1154+
if (Invocation.getLangOptions().Target.getVendor() == llvm::Triple::Apple) {
1155+
mode = FrontendOptions::TBDValidationMode::MissingFromTBD;
1156+
break;
1157+
}
1158+
#endif
1159+
// Otherwise, the default is to do nothing.
1160+
LLVM_FALLTHROUGH;
11501161
case FrontendOptions::TBDValidationMode::None:
11511162
return false;
11521163
case FrontendOptions::TBDValidationMode::All:

stdlib/public/SwiftOnoneSupport/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ add_swift_library(swiftSwiftOnoneSupport ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_
22
# This file should be listed the first. Module name is inferred from the
33
# filename.
44
SwiftOnoneSupport.swift
5-
SWIFT_COMPILE_FLAGS "-parse-stdlib" "-Xllvm" "-sil-inline-generics=false" "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
5+
# We have to disable validation of TBD files, because this module is
6+
# _explicitly_ special-cased to result in extra symbols generated by the
7+
# optimizer, meaning TBDGen can't (and shouldn't: it has to run
8+
# pre-optimization for performance) list them.
9+
SWIFT_COMPILE_FLAGS "-parse-stdlib" "-Xllvm" "-sil-inline-generics=false" "-Xfrontend" "-validate-tbd-against-ir=none" "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
610
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
711
INSTALL_IN_COMPONENT stdlib)

0 commit comments

Comments
 (0)