Skip to content

Commit c882c50

Browse files
committed
---
yaml --- r: 348150 b: refs/heads/master c: c42b732 h: refs/heads/master
1 parent f9411ca commit c882c50

File tree

31 files changed

+290
-81
lines changed

31 files changed

+290
-81
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 23da09fc1bb10e9599defa20a5b60389c286a946
2+
refs/heads/master: c42b732e26f43e205f8d6ee824eeb86790635fcd
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/cmake/modules/SwiftSource.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ function(_compile_swift_files
269269
# into the new runtime.
270270
if (SWIFTFILE_IS_STDLIB OR SWIFTFILE_IS_SDK_OVERLAY)
271271
list(APPEND swift_flags "-runtime-compatibility-version" "none")
272+
list(APPEND swift_flags "-disable-autolinking-runtime-compatibility-dynamic-replacements")
272273
endif()
273274

274275
if (SWIFTFILE_IS_STDLIB_CORE OR SWIFTFILE_IS_SDK_OVERLAY)

trunk/include/swift/AST/ASTContext.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,10 @@ class ASTContext final {
590590
/// Get the runtime availability of the opaque types language feature for the target platform.
591591
AvailabilityContext getOpaqueTypeAvailability();
592592

593+
/// Get the runtime availability of features introduced in the Swift 5.1
594+
/// compiler for the target platform.
595+
AvailabilityContext getSwift51Availability();
596+
593597
//===--------------------------------------------------------------------===//
594598
// Diagnostics Helper functions
595599
//===--------------------------------------------------------------------===//

trunk/include/swift/AST/Decl.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ class alignas(1 << DeclAlignInBits) Decl {
605605
HasAnyUnavailableValues : 1
606606
);
607607

608-
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1+1+1,
608+
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1+1+1+1,
609609
/// If the module was or is being compiled with `-enable-testing`.
610610
TestingEnabled : 1,
611611

@@ -620,14 +620,18 @@ class alignas(1 << DeclAlignInBits) Decl {
620620
/// Whether all imports have been resolved. Used to detect circular imports.
621621
HasResolvedImports : 1,
622622

623-
// If the module was or is being compiled with `-enable-private-imports`.
623+
/// If the module was or is being compiled with `-enable-private-imports`.
624624
PrivateImportsEnabled : 1,
625625

626-
// If the module is compiled with `-enable-implicit-dynamic`.
626+
/// If the module is compiled with `-enable-implicit-dynamic`.
627627
ImplicitDynamicEnabled : 1,
628628

629-
// Whether the module is a system module.
630-
IsSystemModule : 1
629+
/// Whether the module is a system module.
630+
IsSystemModule : 1,
631+
632+
/// Whether the module was imported from Clang (or, someday, maybe another
633+
/// language).
634+
IsNonSwiftModule : 1
631635
);
632636

633637
SWIFT_INLINE_BITFIELD(PrecedenceGroupDecl, Decl, 1+2,

trunk/include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,11 @@ ERROR(module_not_compiled_for_private_import,none,
792792
ERROR(import_implementation_cannot_be_exported,none,
793793
"module %0 cannot be both exported and implementation-only", (Identifier))
794794

795+
WARNING(module_not_compiled_with_library_evolution,none,
796+
"module %0 was not compiled with library evolution support; "
797+
"using it means binary compatibility for %1 can't be guaranteed",
798+
(Identifier, Identifier))
799+
795800

796801
// Operator decls
797802
ERROR(ambiguous_operator_decls,none,

trunk/include/swift/AST/IRGenOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ class IRGenOptions {
228228

229229
/// Pull in runtime compatibility shim libraries by autolinking.
230230
Optional<llvm::VersionTuple> AutolinkRuntimeCompatibilityLibraryVersion;
231+
Optional<llvm::VersionTuple> AutolinkRuntimeCompatibilityDynamicReplacementLibraryVersion;
231232

232233
IRGenOptions()
233234
: DWARFVersion(2), OutputKind(IRGenOutputKind::LLVMAssembly),

trunk/include/swift/AST/Module.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,18 @@ class ModuleDecl : public DeclContext, public TypeDecl {
337337
Bits.ModuleDecl.IsSystemModule = flag;
338338
}
339339

340+
/// Returns true if this module is a non-Swift module that was imported into
341+
/// Swift.
342+
///
343+
/// Right now that's just Clang modules.
344+
bool isNonSwiftModule() const {
345+
return Bits.ModuleDecl.IsNonSwiftModule;
346+
}
347+
/// \see #isNonSwiftModule
348+
void setIsNonSwiftModule(bool flag = true) {
349+
Bits.ModuleDecl.IsNonSwiftModule = flag;
350+
}
351+
340352
bool isResilient() const {
341353
return getResilienceStrategy() != ResilienceStrategy::Default;
342354
}

trunk/include/swift/Option/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,4 +912,10 @@ def disable_autolinking_runtime_compatibility : Flag<["-"], "disable-autolinking
912912
Flags<[FrontendOption]>,
913913
HelpText<"Do not use autolinking for runtime compatibility libraries">;
914914

915+
def disable_autolinking_runtime_compatibility_dynamic_replacements
916+
: Flag<[ "-" ], "disable-autolinking-runtime-compatibility-dynamic-replacements">,
917+
Flags<[ FrontendOption ]>,
918+
HelpText<"Do not use autolinking for the dynamic replacement runtime "
919+
"compatibility library">;
920+
915921
include "FrontendOptions.td"

trunk/include/swift/Runtime/Exclusivity.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,19 @@ void swift_beginAccess(void *pointer, ValueBuffer *buffer,
4444
/// replacement function if it should be called.
4545
/// Returns null if the original function (which is passed in \p CurrFn) should
4646
/// be called.
47+
#ifdef __APPLE__
48+
__attribute__((weak_import))
49+
#endif
4750
SWIFT_RUNTIME_EXPORT
4851
char *swift_getFunctionReplacement(char **ReplFnPtr, char *CurrFn);
4952

5053
/// Returns the original function of a replaced function, which is loaded from
5154
/// \p OrigFnPtr.
5255
/// This function is called from a replacement function to call the original
5356
/// function.
57+
#ifdef __APPLE__
58+
__attribute__((weak_import))
59+
#endif
5460
SWIFT_RUNTIME_EXPORT
5561
char *swift_getOrigOfReplaceable(char **OrigFnPtr);
5662

trunk/include/swift/Runtime/RuntimeFnWrappersGen.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
namespace swift {
2323

2424
class AvailabilityContext;
25+
class ASTContext;
26+
27+
enum class RuntimeAvailability {
28+
AlwaysAvailable,
29+
AvailableByCompatibilityLibrary,
30+
ConditionallyAvailable
31+
};
2532

2633
/// Generate an llvm declaration for a runtime entry with a
2734
/// given name, return types, argument types, attributes and
@@ -30,7 +37,8 @@ llvm::Constant *getRuntimeFn(llvm::Module &Module,
3037
llvm::Constant *&cache,
3138
char const *name,
3239
llvm::CallingConv::ID cc,
33-
bool isWeakLinked,
40+
RuntimeAvailability availability,
41+
ASTContext *context,
3442
llvm::ArrayRef<llvm::Type*> retTypes,
3543
llvm::ArrayRef<llvm::Type*> argTypes,
3644
llvm::ArrayRef<llvm::Attribute::AttrKind> attrs);

trunk/include/swift/Runtime/RuntimeFunctions.def

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ FUNCTION(GetGenericMetadata, swift_getGenericMetadata,
638638
// const OpaqueTypeDescriptor *descriptor,
639639
// uintptr_t index);
640640
FUNCTION(GetOpaqueTypeMetadata, swift_getOpaqueTypeMetadata,
641-
SwiftCC, OpaqueTypeAvailability,
641+
SwiftCC, ConditionallyAvailable,
642642
RETURNS(TypeMetadataResponseTy),
643643
ARGS(SizeTy, Int8PtrTy, OpaqueTypeDescriptorPtrTy, SizeTy),
644644
ATTRS(NoUnwind, ReadOnly))
@@ -647,7 +647,7 @@ FUNCTION(GetOpaqueTypeMetadata, swift_getOpaqueTypeMetadata,
647647
// const OpaqueTypeDescriptor *descriptor,
648648
// uintptr_t index);
649649
FUNCTION(GetOpaqueTypeConformance, swift_getOpaqueTypeConformance,
650-
SwiftCC, OpaqueTypeAvailability,
650+
SwiftCC, ConditionallyAvailable,
651651
RETURNS(WitnessTablePtrTy),
652652
ARGS(Int8PtrTy, OpaqueTypeDescriptorPtrTy, SizeTy),
653653
ATTRS(NoUnwind, ReadOnly))
@@ -1225,12 +1225,14 @@ FUNCTION(EndAccess, swift_endAccess, C_CC, AlwaysAvailable,
12251225
ARGS(getFixedBufferTy()->getPointerTo()),
12261226
ATTRS(NoUnwind))
12271227

1228-
FUNCTION(GetOrigOfReplaceable, swift_getOrigOfReplaceable, C_CC, AlwaysAvailable,
1228+
FUNCTION(GetOrigOfReplaceable, swift_getOrigOfReplaceable, C_CC,
1229+
AvailableByCompatibilityLibrary,
12291230
RETURNS(FunctionPtrTy),
12301231
ARGS(FunctionPtrTy->getPointerTo()),
12311232
ATTRS(NoUnwind))
12321233

1233-
FUNCTION(GetReplacement, swift_getFunctionReplacement, C_CC, AlwaysAvailable,
1234+
FUNCTION(GetReplacement, swift_getFunctionReplacement, C_CC,
1235+
AvailableByCompatibilityLibrary,
12341236
RETURNS(FunctionPtrTy),
12351237
ARGS(FunctionPtrTy->getPointerTo(), FunctionPtrTy),
12361238
ATTRS(NoUnwind))

trunk/lib/AST/Availability.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ AvailabilityContext AvailabilityInference::inferForType(Type t) {
218218
}
219219

220220
AvailabilityContext ASTContext::getOpaqueTypeAvailability() {
221+
return getSwift51Availability();
222+
}
223+
224+
AvailabilityContext ASTContext::getSwift51Availability() {
221225
auto target = LangOpts.Target;
222226

223227
if (target.isMacOSX()) {

trunk/lib/ClangImporter/ClangImporter.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,8 +1672,7 @@ ModuleDecl *ClangImporter::Implementation::finishLoadingClangModule(
16721672
Identifier name = SwiftContext.getIdentifier((*clangModule).Name);
16731673
result = ModuleDecl::create(name, SwiftContext);
16741674
result->setIsSystemModule(clangModule->IsSystem);
1675-
// Silence error messages about testably importing a Clang module.
1676-
result->setTestingEnabled();
1675+
result->setIsNonSwiftModule();
16771676
result->setHasResolvedImports();
16781677

16791678
wrapperUnit =
@@ -1842,8 +1841,7 @@ ClangModuleUnit *ClangImporter::Implementation::getWrapperForModule(
18421841
Identifier name = SwiftContext.getIdentifier(underlying->Name);
18431842
auto wrapper = ModuleDecl::create(name, SwiftContext);
18441843
wrapper->setIsSystemModule(underlying->IsSystem);
1845-
// Silence error messages about testably importing a Clang module.
1846-
wrapper->setTestingEnabled();
1844+
wrapper->setIsNonSwiftModule();
18471845
wrapper->setHasResolvedImports();
18481846

18491847
auto file = new (SwiftContext) ClangModuleUnit(*wrapper, *this,

trunk/lib/DWARFImporter/DWARFImporter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ class DWARFImporter::Implementation {
120120
return it->second->getParentModule();
121121

122122
auto *decl = ModuleDecl::create(name, SwiftContext);
123-
// Silence error messages about testably importing a Clang module.
124-
decl->setTestingEnabled();
123+
decl->setIsNonSwiftModule();
125124
decl->setHasResolvedImports();
126125
auto wrapperUnit = new (SwiftContext) DWARFModuleUnit(*decl);
127126
ModuleWrappers.insert({name, wrapperUnit});

trunk/lib/Driver/DarwinToolChains.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,22 @@ toolchains::Darwin::constructInvocation(const LinkJobAction &job,
427427
}
428428
}
429429

430+
if (job.getKind() == LinkKind::Executable) {
431+
if (runtimeCompatibilityVersion)
432+
if (*runtimeCompatibilityVersion <= llvm::VersionTuple(5, 0)) {
433+
// Swift 5.0 dynamic replacement compatibility library.
434+
SmallString<128> BackDeployLib;
435+
BackDeployLib.append(RuntimeLibPath);
436+
llvm::sys::path::append(BackDeployLib,
437+
"libswiftCompatibilityDynamicReplacements.a");
438+
439+
if (llvm::sys::fs::exists(BackDeployLib)) {
440+
Arguments.push_back("-force_load");
441+
Arguments.push_back(context.Args.MakeArgString(BackDeployLib));
442+
}
443+
}
444+
}
445+
430446
// Link the standard library.
431447
Arguments.push_back("-L");
432448
if (context.Args.hasFlag(options::OPT_static_stdlib,

trunk/lib/Driver/ToolChains.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ static void addRuntimeLibraryFlags(const OutputInfo &OI,
275275

276276
Arguments.push_back("-autolink-library");
277277
switch (RT) {
278-
default: llvm_unreachable("invalid MSVC runtime library");
279278
case OutputInfo::MSVCRuntime::MultiThreaded:
280279
Arguments.push_back("libcmt");
281280
break;
@@ -445,7 +444,12 @@ ToolChain::constructInvocation(const CompileJobAction &job,
445444
Arguments.push_back("-runtime-compatibility-version");
446445
Arguments.push_back(arg->getValue());
447446
}
448-
447+
448+
context.Args.AddLastArg(
449+
Arguments,
450+
options::
451+
OPT_disable_autolinking_runtime_compatibility_dynamic_replacements);
452+
449453
return II;
450454
}
451455

trunk/lib/Frontend/CompilerInvocation.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,11 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
11931193
runtimeCompatibilityVersion;
11941194
}
11951195

1196+
if (!Args.hasArg(options::
1197+
OPT_disable_autolinking_runtime_compatibility_dynamic_replacements)) {
1198+
Opts.AutolinkRuntimeCompatibilityDynamicReplacementLibraryVersion =
1199+
getSwiftRuntimeCompatibilityVersionForTarget(Triple);
1200+
}
11961201
return false;
11971202
}
11981203

trunk/lib/IRGen/GenDecl.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,15 @@ void IRGenModule::emitSourceFile(SourceFile &SF) {
467467
/*forceLoad*/ true));
468468
}
469469
}
470+
471+
if (auto compatibilityVersion =
472+
IRGen.Opts.AutolinkRuntimeCompatibilityDynamicReplacementLibraryVersion) {
473+
if (*compatibilityVersion <= llvm::VersionTuple(5, 0)) {
474+
this->addLinkLibrary(LinkLibrary("swiftCompatibilityDynamicReplacements",
475+
LibraryKind::Library,
476+
/*forceLoad*/ true));
477+
}
478+
}
470479
}
471480
}
472481

@@ -2242,8 +2251,8 @@ void IRGenModule::createReplaceableProlog(IRGenFunction &IGF, SILFunction *f) {
22422251
rhs = FnAddr;
22432252
} else {
22442253
// Call swift_getFunctionReplacement to check which function to call.
2245-
auto *callRTFunc = IGF.Builder.CreateCall(getGetReplacementFn(),
2246-
{ ReplAddr, FnAddr });
2254+
auto *callRTFunc =
2255+
IGF.Builder.CreateCall(getGetReplacementFn(), {ReplAddr, FnAddr});
22472256
callRTFunc->setDoesNotThrow();
22482257
ReplFn = callRTFunc;
22492258
rhs = llvm::ConstantExpr::getNullValue(ReplFn->getType());
@@ -2411,8 +2420,9 @@ void IRGenModule::emitDynamicReplacementOriginalFunctionThunk(SILFunction *f) {
24112420
llvm::ConstantExpr::getInBoundsGetElementPtr(nullptr, linkEntry, indices),
24122421
FunctionPtrTy->getPointerTo());
24132422

2414-
auto *OrigFn = IGF.Builder.CreateCall(getGetOrigOfReplaceableFn(),
2415-
{ fnPtrAddr });
2423+
auto *OrigFn =
2424+
IGF.Builder.CreateCall(getGetOrigOfReplaceableFn(), {fnPtrAddr});
2425+
24162426
OrigFn->setDoesNotThrow();
24172427

24182428
auto *typeFnPtr =

0 commit comments

Comments
 (0)