Skip to content

Outliner: Can't handle generic ObjC classes #13859

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

Merged
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
11 changes: 7 additions & 4 deletions lib/SILOptimizer/Transforms/Outliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ bool BridgedProperty::matchMethodCall(SILBasicBlock::iterator It) {
FirstInst != ObjCMethod ? FirstInst : ObjCMethod->getOperand();
if (!ObjCMethod || !ObjCMethod->hasOneUse() ||
ObjCMethod->getOperand() != Instance ||
ObjCMethod->getFunction()->getLoweredFunctionType()->isPolymorphic())
ObjCMethod->getFunction()->getLoweredFunctionType()->isPolymorphic() ||
ObjCMethod->getType().castTo<SILFunctionType>()->isPolymorphic())
return false;

// Don't outline in the outlined function.
Expand Down Expand Up @@ -569,7 +570,8 @@ bool BridgedProperty::matchInstSequence(SILBasicBlock::iterator It) {
if (!Load) {
// Try to match without the load/strong_retain prefix.
auto *CMI = dyn_cast<ObjCMethodInst>(It);
if (!CMI || CMI->getFunction()->getLoweredFunctionType()->isPolymorphic())
if (!CMI || CMI->getFunction()->getLoweredFunctionType()->isPolymorphic() ||
CMI->getType().castTo<SILFunctionType>()->isPolymorphic())
return false;
FirstInst = CMI;
} else
Expand Down Expand Up @@ -608,7 +610,6 @@ bool BridgedProperty::matchInstSequence(SILBasicBlock::iterator It) {
if (!Release || NumUses != 4)
return false;
}

return true;
}

Expand Down Expand Up @@ -1106,8 +1107,10 @@ bool ObjCMethodCall::matchInstSequence(SILBasicBlock::iterator I) {

ObjCMethod = dyn_cast<ObjCMethodInst>(I);
if (!ObjCMethod ||
ObjCMethod->getFunction()->getLoweredFunctionType()->isPolymorphic())
ObjCMethod->getFunction()->getLoweredFunctionType()->isPolymorphic() ||
ObjCMethod->getType().castTo<SILFunctionType>()->isPolymorphic())
return false;

auto *Use = ObjCMethod->getSingleUse();
if (!Use)
return false;
Expand Down
7 changes: 7 additions & 0 deletions test/SILOptimizer/Inputs/Outliner.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@
- (NSString*) doSomething;
@end

@protocol FooProto <NSObject>
@end

@protocol SomeGenericClass <FooProto>
@property (nonatomic, nullable, readonly, strong) NSString *version;
- (NSString*) doSomething;
- (id) doSomething2 : (NSArray<NSString*>*) arr;
@end
14 changes: 14 additions & 0 deletions test/SILOptimizer/outliner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,17 @@ public func dontCrash<T: Proto>(x : Gizmo2<T>) {
print(s)

}

public func dontCrash2(_ c: SomeGenericClass) -> Bool {
guard let str = c.version else {
return false
}
guard let str2 = c.doSomething() else {
return false
}

let arr = [ "foo", "bar"]
c.doSomething2(arr)

return true
}