Skip to content

Commit aaf457e

Browse files
committed
SILGen: Pick UIApplicationMain by looking directly in the Clang module.
This saves us from having to do overload resolution on the overlay module, which fails if an overlay declaration exactly matches the imported signature of the original ObjC declaration. Fixes rdar://problem/42352695 harder.
1 parent 18650bc commit aaf457e

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

lib/SILGen/SILGenFunction.cpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -438,30 +438,25 @@ void SILGenFunction::emitArtificialTopLevel(ClassDecl *mainClass) {
438438
// we're getting away with it because the types are guaranteed to already
439439
// be imported.
440440
ASTContext &ctx = getASTContext();
441-
ModuleDecl *UIKit = ctx.getLoadedModule(ctx.getIdentifier("UIKit"));
441+
442+
std::pair<Identifier, SourceLoc> UIKitName =
443+
{ctx.getIdentifier("UIKit"), SourceLoc()};
444+
445+
ModuleDecl *UIKit = ctx
446+
.getClangModuleLoader()
447+
->loadModule(SourceLoc(), UIKitName);
448+
assert(UIKit && "couldn't find UIKit objc module?!");
442449
SmallVector<ValueDecl *, 1> results;
443450
UIKit->lookupQualified(UIKit->getInterfaceType(),
444451
ctx.getIdentifier("UIApplicationMain"),
445452
NL_QualifiedDefault,
446453
/*resolver*/nullptr,
447454
results);
448-
assert(!results.empty() && "couldn't find UIApplicationMain in UIKit");
449-
450-
// We want the original UIApplicationMain() declaration from Objective-C,
451-
// not any overlay overloads.
452-
ValueDecl *UIApplicationMainDecl = nullptr;
453-
for (auto *result : results) {
454-
if (result->hasClangNode()) {
455-
assert(!UIApplicationMainDecl
456-
&& "more than one UIApplicationMain defined in ObjC?!");
457-
UIApplicationMainDecl = result;
458-
#ifndef NDEBUG
459-
break;
460-
#endif
461-
}
462-
}
463-
464-
assert(UIApplicationMainDecl && "no UIApplicationMain defined in ObjC?!");
455+
assert(results.size() == 1
456+
&& "couldn't find a unique UIApplicationMain in the UIKit ObjC "
457+
"module?!");
458+
459+
ValueDecl *UIApplicationMainDecl = results.front();
465460

466461
auto mainRef = SILDeclRef(UIApplicationMainDecl).asForeign();
467462
auto UIApplicationMainFn = SGM.M.getOrCreateFunction(mainClass, mainRef,

test/SILGen/Inputs/UIKit.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@ import Foundation
22
@_exported import UIKit
33

44
public func UIApplicationMain() {}
5+
public func UIApplicationMain(_ argc: Int32,
6+
_ argv: UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>!,
7+
_ principalClassName: String?,
8+
_ delegateClassName: String?) -> Int32 {
9+
return 0
10+
}

0 commit comments

Comments
 (0)