Skip to content

Commit 00599ee

Browse files
committed
Check for completeness of the SwiftOnoneSupport library
When compiling SwiftOnoneSupport, issue errors for missing functions which are expected in the module. This ensures ABI compatibility. rdar://problem/48924409
1 parent a8a18c0 commit 00599ee

File tree

8 files changed

+41
-1
lines changed

8 files changed

+41
-1
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,13 @@ ERROR(circular_transparent,none,
251251
"inlining 'transparent' functions forms circular loop", ())
252252
NOTE(note_while_inlining,none,
253253
"while inlining here", ())
254+
255+
// Pre-specializations
254256
ERROR(cannot_prespecialize,none,
255257
"Cannot pre-specialize %0", (StringRef))
258+
ERROR(missing_prespecialization,none,
259+
"Pre-specialized function %0 missing in SwiftOnoneSupport module",
260+
(StringRef))
256261

257262
// Arithmetic diagnostics.
258263
ERROR(integer_conversion_overflow,none,

include/swift/Frontend/FrontendOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ class FrontendOptions {
158158
/// module appears to not be a public module.
159159
Optional<bool> SerializeOptionsForDebugging;
160160

161+
/// When true, check if all required SwiftOnoneSupport symbols are present in
162+
/// the module.
163+
bool CheckOnoneSupportCompleteness = false;
164+
161165
/// If set, inserts instrumentation useful for testing the debugger.
162166
bool DebuggerTestingTransform = false;
163167

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,9 @@ def import_module : Separate<["-"], "import-module">,
416416
def print_stats : Flag<["-"], "print-stats">,
417417
HelpText<"Print various statistics">;
418418

419+
def check_onone_completeness : Flag<["-"], "check-onone-completeness">,
420+
HelpText<"Print errors if the compile OnoneSupport module is missing symbols">;
421+
419422
def debugger_testing_transform : Flag<["-"], "debugger-testing-transform">,
420423
HelpText<"Instrument the code with calls to an intrinsic that record the expected values of "
421424
"local variables so they can be compared against the results from the debugger.">;

include/swift/SILOptimizer/Utils/Generics.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ class GenericFuncSpecializer {
319319
/// prespecialization for -Onone support.
320320
bool isKnownPrespecialization(StringRef SpecName);
321321

322+
/// Checks if all OnoneSupport pre-specializations are included in the module
323+
/// as public functions.
324+
///
325+
/// Issues errors for all missing functions.
326+
void checkCompletenessOfPrespecializations(SILModule &M);
327+
322328
/// Create a new apply based on an old one, but with a different
323329
/// function being applied.
324330
ApplySite replaceWithSpecializedFunction(ApplySite AI, SILFunction *NewF,

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ bool ArgsToFrontendOptionsConverter::convert(
9696
setUnsignedIntegerArgument(OPT_switch_checking_invocation_threshold_EQ, 10,
9797
Opts.SwitchCheckingInvocationThreshold);
9898

99+
Opts.CheckOnoneSupportCompleteness = Args.hasArg(OPT_check_onone_completeness);
100+
99101
Opts.DebuggerTestingTransform = Args.hasArg(OPT_debugger_testing_transform);
100102

101103
computePlaygroundOptions();

lib/Frontend/Frontend.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "swift/Parse/Lexer.h"
3030
#include "swift/SIL/SILModule.h"
3131
#include "swift/SILOptimizer/PassManager/Passes.h"
32+
#include "swift/SILOptimizer/Utils/Generics.h"
3233
#include "swift/Serialization/SerializationOptions.h"
3334
#include "swift/Serialization/SerializedModuleLoader.h"
3435
#include "swift/Strings.h"
@@ -1110,6 +1111,11 @@ static void performSILOptimizations(CompilerInvocation &Invocation,
11101111
} else {
11111112
runSILOptimizationPasses(*SM);
11121113
}
1114+
if (Invocation.getFrontendOptions().CheckOnoneSupportCompleteness &&
1115+
// TODO: handle non-ObjC based stdlib builds, e.g. on linux.
1116+
Invocation.getLangOptions().EnableObjCInterop) {
1117+
checkCompletenessOfPrespecializations(*SM);
1118+
}
11131119
}
11141120

11151121
static void countStatsPostSILOpt(UnifiedStatsReporter &Stats,

lib/SILOptimizer/Utils/Generics.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,6 +2590,20 @@ bool swift::isKnownPrespecialization(StringRef SpecName) {
25902590
return PrespecSet.count(SpecName) != 0;
25912591
}
25922592

2593+
void swift::checkCompletenessOfPrespecializations(SILModule &M) {
2594+
const char **Pos = &PrespecSymbols[0];
2595+
while (const char *Sym = *Pos++) {
2596+
StringRef FunctionName(Sym);
2597+
SILFunction *F = M.lookUpFunction(FunctionName);
2598+
if (!F || F->getLinkage() != SILLinkage::Public) {
2599+
M.getASTContext().Diags.diagnose(SourceLoc(),
2600+
diag::missing_prespecialization,
2601+
FunctionName);
2602+
}
2603+
}
2604+
2605+
}
2606+
25932607
/// Try to look up an existing specialization in the specialization cache.
25942608
/// If it is found, it tries to link this specialization.
25952609
///

stdlib/public/SwiftOnoneSupport/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ add_swift_target_library(swiftSwiftOnoneSupport ${SWIFT_STDLIB_LIBRARY_BUILD_TYP
66
# _explicitly_ special-cased to result in extra symbols generated by the
77
# optimizer, meaning TBDGen can't (and shouldn't: it has to run
88
# 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}"
9+
SWIFT_COMPILE_FLAGS "-parse-stdlib" "-Xllvm" "-sil-inline-generics=false" "-Xfrontend" "-validate-tbd-against-ir=none" "-Xfrontend" "-check-onone-completeness" "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
1010
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
1111
INSTALL_IN_COMPONENT stdlib)
1212
if(WINDOWS IN_LIST SWIFT_SDKS)

0 commit comments

Comments
 (0)