Skip to content
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

Adopt a search path for bridgeable types in component modules (no longer just in Foundation) #21234

Closed
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
1 change: 1 addition & 0 deletions include/swift/AST/KnownIdentifiers.def
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ IDENTIFIER(error)
IDENTIFIER(errorDomain)
IDENTIFIER(forKeyedSubscript)
IDENTIFIER(Foundation)
IDENTIFIER(FoundationBase)
IDENTIFIER(for)
IDENTIFIER(forKey)
IDENTIFIER(from)
Expand Down
16 changes: 10 additions & 6 deletions include/swift/SIL/BridgedTypes.def
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
4 changes: 4 additions & 0 deletions include/swift/SIL/TypeLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,8 @@ class TypeConverter {
// Types converted during foreign bridging.
#define BRIDGING_KNOWN_TYPE(BridgedModule,BridgedType) \
Optional<CanType> BridgedType##Ty;
#define BRIDGING_KNOWN_TYPE_WITH_MODULES_2(_1, _2, BridgedType) \
Optional<CanType> BridgedType##Ty;
#include "swift/SIL/BridgedTypes.def"

const TypeLowering &
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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. */ \
Expand Down
22 changes: 22 additions & 0 deletions lib/SIL/SILFunctionType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,33 @@ static CanType getKnownType(Optional<CanType> &cacheSlot, ASTContext &C,
return t;
}

static CanType getKnownTypeFromModules2(Optional<CanType> &cacheSlot, ASTContext &C,
StringRef moduleName1, StringRef moduleName2,
StringRef typeName) {

auto temporaryCacheSlot = Optional<CanType>();
auto T = getKnownType(temporaryCacheSlot, C, moduleName1, typeName);

if (!T) {
temporaryCacheSlot = Optional<CanType>();
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.
Expand Down
38 changes: 38 additions & 0 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/BridgeObjectiveC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 7 additions & 3 deletions utils/update_checkout/update_checkout/update_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down