diff --git a/include/swift/AST/KnownIdentifiers.def b/include/swift/AST/KnownIdentifiers.def index 5624a18d20f10..7d49cf21d0ace 100644 --- a/include/swift/AST/KnownIdentifiers.def +++ b/include/swift/AST/KnownIdentifiers.def @@ -59,6 +59,7 @@ IDENTIFIER(error) IDENTIFIER(errorDomain) IDENTIFIER(forKeyedSubscript) IDENTIFIER(Foundation) +IDENTIFIER(FoundationBase) IDENTIFIER(for) IDENTIFIER(forKey) IDENTIFIER(from) diff --git a/include/swift/SIL/BridgedTypes.def b/include/swift/SIL/BridgedTypes.def index 138b67f0673d6..496bb3132c9e3 100644 --- a/include/swift/SIL/BridgedTypes.def +++ b/include/swift/SIL/BridgedTypes.def @@ -34,15 +34,19 @@ #define BRIDGING_KNOWN_TYPE(module, type) #endif +#ifndef BRIDGING_KNOWN_TYPE_WITH_MODULES_2 +#define BRIDGING_KNOWN_TYPE_WITH_MODULES_2(module1, module2, type) +#endif + #ifndef BRIDGE_TYPE #define BRIDGE_TYPE(bmodule, btype, nmodule, ntype, opt) #endif -BRIDGING_KNOWN_TYPE(Foundation, NSString) -BRIDGING_KNOWN_TYPE(Foundation, NSArray) -BRIDGING_KNOWN_TYPE(Foundation, NSDictionary) -BRIDGING_KNOWN_TYPE(Foundation, NSSet) -BRIDGING_KNOWN_TYPE(Foundation, NSError) +BRIDGING_KNOWN_TYPE_WITH_MODULES_2(FoundationBase, Foundation, NSString) +BRIDGING_KNOWN_TYPE_WITH_MODULES_2(FoundationBase, Foundation, NSArray) +BRIDGING_KNOWN_TYPE_WITH_MODULES_2(FoundationBase, Foundation, NSDictionary) +BRIDGING_KNOWN_TYPE_WITH_MODULES_2(FoundationBase, Foundation, NSSet) +BRIDGING_KNOWN_TYPE_WITH_MODULES_2(FoundationBase, Foundation, NSError) BRIDGING_KNOWN_TYPE(Swift, String) BRIDGING_KNOWN_TYPE(ObjectiveC, ObjCBool) BRIDGING_KNOWN_TYPE(ObjectiveC, Selector) @@ -55,4 +59,4 @@ BRIDGE_TYPE(Darwin, DarwinBoolean, Swift, Bool, false) #undef BRIDGING_KNOWN_TYPE #undef BRIDGE_TYPE - +#undef BRIDGING_KNOWN_TYPE_WITH_MODULES_2 diff --git a/include/swift/SIL/TypeLowering.h b/include/swift/SIL/TypeLowering.h index 295ec0b6e57f7..fdbe51324a56f 100644 --- a/include/swift/SIL/TypeLowering.h +++ b/include/swift/SIL/TypeLowering.h @@ -697,6 +697,8 @@ class TypeConverter { // Types converted during foreign bridging. #define BRIDGING_KNOWN_TYPE(BridgedModule,BridgedType) \ Optional BridgedType##Ty; +#define BRIDGING_KNOWN_TYPE_WITH_MODULES_2(_1, _2, BridgedType) \ + Optional BridgedType##Ty; #include "swift/SIL/BridgedTypes.def" const TypeLowering & @@ -950,6 +952,8 @@ class TypeConverter { /// Known types for bridging. #define BRIDGING_KNOWN_TYPE(BridgedModule,BridgedType) \ CanType get##BridgedType##Type(); +#define BRIDGING_KNOWN_TYPE_WITH_MODULES_2(_1, _2, BridgedType) \ + CanType get##BridgedType##Type(); #include "swift/SIL/BridgedTypes.def" /// Get the capture list from a closure, with transitive function captures diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 9dfddd55825e3..2918ed067c043 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -848,7 +848,11 @@ StructDecl *ASTContext::getObjCBoolDecl() const { #define GET_FOUNDATION_DECL(NAME) \ ClassDecl *ASTContext::get##NAME##Decl() const { \ if (!getImpl().NAME##Decl) { \ - if (ModuleDecl *M = getLoadedModule(Id_Foundation)) { \ + ModuleDecl *M = getLoadedModule(Id_FoundationBase); \ + if (!M) { \ + M = getLoadedModule(Id_Foundation); \ + } \ + if (M) { \ /* Note: use unqualified lookup so we find NSError regardless of */ \ /* whether it's defined in the Foundation module or the Clang */ \ /* Foundation module it imports. */ \ diff --git a/lib/SIL/SILFunctionType.cpp b/lib/SIL/SILFunctionType.cpp index 60c41bf05f347..4d3840f9e36e9 100644 --- a/lib/SIL/SILFunctionType.cpp +++ b/lib/SIL/SILFunctionType.cpp @@ -173,11 +173,33 @@ static CanType getKnownType(Optional &cacheSlot, ASTContext &C, return t; } +static CanType getKnownTypeFromModules2(Optional &cacheSlot, ASTContext &C, + StringRef moduleName1, StringRef moduleName2, + StringRef typeName) { + + auto temporaryCacheSlot = Optional(); + auto T = getKnownType(temporaryCacheSlot, C, moduleName1, typeName); + + if (!T) { + temporaryCacheSlot = Optional(); + T = getKnownType(temporaryCacheSlot, C, moduleName2, typeName); + } + + cacheSlot = temporaryCacheSlot; + return T; +} + #define BRIDGING_KNOWN_TYPE(BridgedModule,BridgedType) \ CanType TypeConverter::get##BridgedType##Type() { \ return getKnownType(BridgedType##Ty, M.getASTContext(), \ #BridgedModule, #BridgedType); \ } +#define BRIDGING_KNOWN_TYPE_WITH_MODULES_2(BridgedModule1,BridgedModule2,BridgedType) \ + CanType TypeConverter::get##BridgedType##Type() { \ + return getKnownTypeFromModules2(BridgedType##Ty, M.getASTContext(), \ + #BridgedModule1, #BridgedModule2, \ + #BridgedType); \ + } #include "swift/SIL/BridgedTypes.def" /// Adjust a function type to have a slightly different type. diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index 984cd195ddc5c..bb5d5653b85fa 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -3539,7 +3539,12 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName, // a lookup into that Objective-C type. if (bridgedType) { LookupResult &bridgedLookup = lookupMember(bridgedType, memberName); + ModuleDecl *foundationModule = nullptr; + ModuleDecl *FoundationBaseModule = nullptr; + ModuleDecl *swiftFoundationModule = nullptr; + ModuleDecl *swiftFoundationBaseModule = nullptr; + for (auto result : bridgedLookup) { // Ignore results from the Objective-C "Foundation" // module. Those core APIs are explicitly provided by the @@ -3556,6 +3561,39 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName, continue; } + if (FoundationBaseModule) { + if (module == FoundationBaseModule) + continue; + } else if (ClangModuleUnit::hasClangModule(module) && + module->getName().str() == "FoundationBase") { + // Cache the foundation module name so we don't need to look + // for it again. + FoundationBaseModule = module; + continue; + } + + if (swiftFoundationModule) { + if (module == swiftFoundationModule) + continue; + } else if (ClangModuleUnit::hasClangModule(module) && + module->getName().str() == "SwiftFoundation") { + // Cache the foundation module name so we don't need to look + // for it again. + swiftFoundationModule = module; + continue; + } + + if (swiftFoundationBaseModule) { + if (module == swiftFoundationBaseModule) + continue; + } else if (ClangModuleUnit::hasClangModule(module) && + module->getName().str() == "SwiftFoundationBase") { + // Cache the foundation module name so we don't need to look + // for it again. + swiftFoundationBaseModule = module; + continue; + } + addChoice(getOverloadChoice(result.getValueDecl(), /*isBridged=*/true, /*isUnwrappedOptional=*/false)); diff --git a/stdlib/public/core/BridgeObjectiveC.swift b/stdlib/public/core/BridgeObjectiveC.swift index 7dc8996fbe1b4..42de6b52c395e 100644 --- a/stdlib/public/core/BridgeObjectiveC.swift +++ b/stdlib/public/core/BridgeObjectiveC.swift @@ -658,7 +658,7 @@ extension Optional: _Unwrappable { } } -private let _foundationSwiftValueType = _typeByName("Foundation.__SwiftValue") as? _NSSwiftValue.Type +private let _foundationSwiftValueType = (_typeByName("FoundationBase.__SwiftValue") as? _NSSwiftValue.Type) ?? (_typeByName("Foundation.__SwiftValue") as? _NSSwiftValue.Type) @usableFromInline internal var _nullPlaceholder: AnyObject { diff --git a/utils/update_checkout/update_checkout/update_checkout.py b/utils/update_checkout/update_checkout/update_checkout.py index a2159bdf7602e..dea0840a910bb 100755 --- a/utils/update_checkout/update_checkout/update_checkout.py +++ b/utils/update_checkout/update_checkout/update_checkout.py @@ -386,11 +386,11 @@ def full_target_name(repository, target): raise RuntimeError('Cannot determine if %s is a branch or a tag' % target) -def skip_list_for_platform(config): +def skip_list_for_platform(config, treat_like_platform=None): # If there is a platforms key only include the repo if the # plaform is in the list skip_list = [] - platform_name = platform.system() + platform_name = treat_like_platform or platform.system() for repo_name, repo_info in config['repos'].items(): if 'platforms' in repo_info: @@ -479,6 +479,10 @@ def main(): help="Number of threads to run at once", default=0, dest="n_processes") + parser.add_argument( + '--platform', + help='Clone as if the platform was the one specified, useful for e.g. Docker use.', + dest="platform") args = parser.parse_args() if not args.scheme: @@ -526,7 +530,7 @@ def main(): if scheme is None: scheme = config['default-branch-scheme'] - skip_repo_list = skip_list_for_platform(config) + skip_repo_list = skip_list_for_platform(config, args.platform) skip_repo_list.extend(args.skip_repository_list) clone_results = obtain_all_additional_swift_sources(args, config, clone_with_ssh,