Skip to content

Commit 7408ac3

Browse files
authored
Merge pull request #8405 from slavapestov/gardening-from-sil-serialization-inlineable-work
Gardening from SIL serialization inlineable work
2 parents 1f26028 + 53759f7 commit 7408ac3

File tree

13 files changed

+42
-62
lines changed

13 files changed

+42
-62
lines changed

lib/AST/Decl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3790,8 +3790,7 @@ bool AbstractStorageDecl::requiresForeignGetterAndSetter() const {
37903790
return true;
37913791
// Otherwise, we only dispatch by @objc if the declaration is dynamic or
37923792
// NSManaged.
3793-
return getAttrs().hasAttribute<DynamicAttr>() ||
3794-
getAttrs().hasAttribute<NSManagedAttr>();
3793+
return isDynamic() || getAttrs().hasAttribute<NSManagedAttr>();
37953794
}
37963795

37973796

lib/SIL/SILDeclRef.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ swift::getMethodDispatch(AbstractFunctionDecl *method) {
5454
if (fd->isAccessor() && fd->getAccessorStorageDecl()->hasClangNode())
5555
return MethodDispatch::Class;
5656
}
57-
if (method->getAttrs().hasAttribute<DynamicAttr>())
57+
if (method->isDynamic())
5858
return MethodDispatch::Class;
5959
}
6060

@@ -96,20 +96,20 @@ bool swift::requiresForeignEntryPoint(ValueDecl *vd) {
9696
if (fd->isGetterOrSetter())
9797
return requiresForeignEntryPoint(fd->getAccessorStorageDecl());
9898

99-
return fd->getAttrs().hasAttribute<DynamicAttr>();
99+
return fd->isDynamic();
100100
}
101101

102102
if (auto *cd = dyn_cast<ConstructorDecl>(vd)) {
103103
if (cd->hasClangNode())
104104
return true;
105105

106-
return cd->getAttrs().hasAttribute<DynamicAttr>();
106+
return cd->isDynamic();
107107
}
108108

109109
if (auto *asd = dyn_cast<AbstractStorageDecl>(vd))
110110
return asd->requiresForeignGetterAndSetter();
111111

112-
return vd->getAttrs().hasAttribute<DynamicAttr>();
112+
return vd->isDynamic();
113113
}
114114

115115
/// TODO: We should consult the cached LoweredLocalCaptures the SIL

lib/SILGen/SILGenFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ SILGenFunction::emitSiblingMethodRef(SILLocation loc,
136136
// If the method is dynamic, access it through runtime-hookable virtual
137137
// dispatch (viz. objc_msgSend for now).
138138
if (methodConstant.hasDecl()
139-
&& methodConstant.getDecl()->getAttrs().hasAttribute<DynamicAttr>())
139+
&& methodConstant.getDecl()->isDynamic())
140140
methodValue = emitDynamicMethodRef(loc, methodConstant,
141141
SGM.Types.getConstantInfo(methodConstant));
142142
else

lib/SILGen/SILGenLValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ namespace {
720720
return false;
721721

722722
// If the declaration is dynamic, there's no materializeForSet.
723-
if (decl->getAttrs().hasAttribute<DynamicAttr>())
723+
if (decl->isDynamic())
724724
return false;
725725

726726
// If the declaration was imported from C, we won't gain anything

lib/SILGen/SILGenPoly.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3164,7 +3164,7 @@ getWitnessDispatchKind(Type selfType, SILDeclRef witness, bool isFree) {
31643164
auto *decl = witness.getDecl();
31653165

31663166
// If the witness is dynamic, go through dynamic dispatch.
3167-
if (decl->getAttrs().hasAttribute<DynamicAttr>())
3167+
if (decl->isDynamic())
31683168
return WitnessDispatchKind::Dynamic;
31693169

31703170
bool isFinal = (decl->isFinal() || C->isFinal());

lib/SILGen/SILGenProfiling.cpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ struct MapRegionCounters : public ASTWalker {
123123
CounterMap[WS->getBody()] = NextCounter++;
124124
} else if (auto *RWS = dyn_cast<RepeatWhileStmt>(S)) {
125125
CounterMap[RWS->getBody()] = NextCounter++;
126-
} else if (auto *FS = dyn_cast<ForStmt>(S)) {
127-
CounterMap[FS->getBody()] = NextCounter++;
128126
} else if (auto *FES = dyn_cast<ForEachStmt>(S)) {
129127
CounterMap[FES->getBody()] = NextCounter++;
130128
walkPatternForProfiling(FES->getIterator(), *this);
@@ -536,14 +534,6 @@ struct CoverageMapping : public ASTWalker {
536534
assignCounter(RWS->getCond(), CounterExpr::Ref(BodyCounter));
537535
RepeatWhileStack.push_back(RWS);
538536

539-
} else if (auto *FS = dyn_cast<ForStmt>(S)) {
540-
assignCounter(FS, CounterExpr::Zero());
541-
if (Expr *E = FS->getCond().getPtrOrNull())
542-
assignCounter(E, CounterExpr::Ref(getCurrentCounter()));
543-
if (Expr *E = FS->getIncrement().getPtrOrNull())
544-
assignCounter(E, CounterExpr::Zero());
545-
assignCounter(FS->getBody());
546-
547537
} else if (auto *FES = dyn_cast<ForEachStmt>(S)) {
548538
assignCounter(FES, CounterExpr::Zero());
549539
assignCounter(FES->getBody());
@@ -593,23 +583,14 @@ struct CoverageMapping : public ASTWalker {
593583
(void) RWS;
594584
RepeatWhileStack.pop_back();
595585

596-
} else if (auto *FS = dyn_cast<ForStmt>(S)) {
597-
// Both the condition and the increment are reached through the backedge.
598-
if (Expr *E = FS->getCond().getPtrOrNull())
599-
addToCounter(E, getExitCounter());
600-
if (Expr *E = FS->getIncrement().getPtrOrNull())
601-
addToCounter(E, getExitCounter());
602-
603586
} else if (auto *CS = dyn_cast<ContinueStmt>(S)) {
604587
// Continues create extra backedges, add them to the appropriate counters.
605588
if (!isa<RepeatWhileStmt>(CS->getTarget()))
606589
addToCounter(CS->getTarget(), getCurrentCounter());
607590
if (auto *WS = dyn_cast<WhileStmt>(CS->getTarget())) {
608591
if (auto *E = getConditionNode(WS->getCond()))
609592
addToCounter(E, getCurrentCounter());
610-
} else if (auto *FS = dyn_cast<ForStmt>(CS->getTarget()))
611-
if (Expr *E = FS->getCond().getPtrOrNull())
612-
addToCounter(E, getCurrentCounter());
593+
}
613594
terminateRegion(S);
614595

615596
} else if (auto *BS = dyn_cast<BreakStmt>(S)) {

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6016,7 +6016,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
60166016
}
60176017

60186018
void visitDynamicAttr(DynamicAttr *attr) {
6019-
if (!Override->getAttrs().hasAttribute<DynamicAttr>())
6019+
if (!Override->isDynamic())
60206020
// Dynamic is inherited.
60216021
Override->getAttrs().add(
60226022
new (TC.Context) DynamicAttr(/*implicit*/true));

test/Inputs/clang-importer-sdk/swift-modules-without-ns/Foundation.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
@_exported import CoreGraphics
33
@_exported import Foundation
44

5-
@_silgen_name("swift_StringToNSString") internal
6-
func _convertStringToNSString(_ string: String) -> NSString
5+
@_silgen_name("swift_StringToNSString")
6+
public func _convertStringToNSString(_ string: String) -> NSString
77

8-
@_silgen_name("swift_NSStringToString") internal
9-
func _convertNSStringToString(_ nsstring: NSString?) -> String
8+
@_silgen_name("swift_NSStringToString")
9+
public func _convertNSStringToString(_ nsstring: NSString?) -> String
1010

1111
public func == (lhs: NSObject, rhs: NSObject) -> Bool {
1212
return lhs.isEqual(rhs)
@@ -15,33 +15,33 @@ public func == (lhs: NSObject, rhs: NSObject) -> Bool {
1515
public let NSUTF8StringEncoding: UInt = 8
1616

1717
// NSArray bridging entry points
18-
func _convertNSArrayToArray<T>(_ nsarr: NSArray?) -> [T] {
18+
public func _convertNSArrayToArray<T>(_ nsarr: NSArray?) -> [T] {
1919
return [T]()
2020
}
2121

22-
func _convertArrayToNSArray<T>(_ arr: [T]) -> NSArray {
22+
public func _convertArrayToNSArray<T>(_ arr: [T]) -> NSArray {
2323
return NSArray()
2424
}
2525

2626
// NSDictionary bridging entry points
27-
internal func _convertDictionaryToNSDictionary<Key, Value>(
27+
public func _convertDictionaryToNSDictionary<Key, Value>(
2828
_ d: Dictionary<Key, Value>
2929
) -> NSDictionary {
3030
return NSDictionary()
3131
}
3232

33-
internal func _convertNSDictionaryToDictionary<K: NSObject, V: AnyObject>(
33+
public func _convertNSDictionaryToDictionary<K: NSObject, V: AnyObject>(
3434
_ d: NSDictionary?
3535
) -> Dictionary<K, V> {
3636
return Dictionary<K, V>()
3737
}
3838

3939
// NSSet bridging entry points
40-
internal func _convertSetToNSSet<T : Hashable>(_ s: Set<T>) -> NSSet {
40+
public func _convertSetToNSSet<T>(_ s: Set<T>) -> NSSet {
4141
return NSSet()
4242
}
4343

44-
internal func _convertNSSetToSet<T : Hashable>(_ s: NSSet?) -> Set<T> {
44+
public func _convertNSSetToSet<T>(_ s: NSSet?) -> Set<T> {
4545
return Set<T>()
4646
}
4747

@@ -207,7 +207,7 @@ extension NSError : Error {
207207
}
208208

209209
@_silgen_name("swift_convertNSErrorToError")
210-
func _convertNSErrorToError(_ string: NSError?) -> Error
210+
public func _convertNSErrorToError(_ string: NSError?) -> Error
211211

212212
@_silgen_name("swift_convertErrorToNSError")
213-
func _convertErrorToNSError(_ string: Error) -> NSError
213+
public func _convertErrorToNSError(_ string: Error) -> NSError

test/Inputs/clang-importer-sdk/swift-modules-without-ns/ObjectiveC.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ public struct NSZone {
6161
public var pointer : OpaquePointer
6262
}
6363

64-
internal func _convertBoolToObjCBool(_ x: Bool) -> ObjCBool {
64+
public func _convertBoolToObjCBool(_ x: Bool) -> ObjCBool {
6565
return ObjCBool(x)
6666
}
6767

68-
internal func _convertObjCBoolToBool(_ x: ObjCBool) -> Bool {
68+
public func _convertObjCBoolToBool(_ x: ObjCBool) -> Bool {
6969
return x.boolValue
7070
}
7171

test/Inputs/clang-importer-sdk/swift-modules/Foundation.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
@_exported import CoreGraphics
33
@_exported import Foundation
44

5-
@_silgen_name("swift_StringToNSString") internal
6-
func _convertStringToNSString(_ string: String) -> NSString
5+
@_silgen_name("swift_StringToNSString")
6+
public func _convertStringToNSString(_ string: String) -> NSString
77

8-
@_silgen_name("swift_NSStringToString") internal
9-
func _convertNSStringToString(_ nsstring: NSString?) -> String
8+
@_silgen_name("swift_NSStringToString")
9+
public func _convertNSStringToString(_ nsstring: NSString?) -> String
1010

1111
public func == (lhs: NSObject, rhs: NSObject) -> Bool {
1212
return lhs.isEqual(rhs)
@@ -15,33 +15,33 @@ public func == (lhs: NSObject, rhs: NSObject) -> Bool {
1515
public let NSUTF8StringEncoding: UInt = 8
1616

1717
// NSArray bridging entry points
18-
func _convertNSArrayToArray<T>(_ nsarr: NSArray?) -> [T] {
18+
public func _convertNSArrayToArray<T>(_ nsarr: NSArray?) -> [T] {
1919
return [T]()
2020
}
2121

22-
func _convertArrayToNSArray<T>(_ arr: [T]) -> NSArray {
22+
public func _convertArrayToNSArray<T>(_ arr: [T]) -> NSArray {
2323
return NSArray()
2424
}
2525

2626
// NSDictionary bridging entry points
27-
internal func _convertDictionaryToNSDictionary<Key, Value>(
27+
public func _convertDictionaryToNSDictionary<Key, Value>(
2828
_ d: Dictionary<Key, Value>
2929
) -> NSDictionary {
3030
return NSDictionary()
3131
}
3232

33-
internal func _convertNSDictionaryToDictionary<K: NSObject, V: AnyObject>(
33+
public func _convertNSDictionaryToDictionary<K: NSObject, V: AnyObject>(
3434
_ d: NSDictionary?
3535
) -> Dictionary<K, V> {
3636
return Dictionary<K, V>()
3737
}
3838

3939
// NSSet bridging entry points
40-
internal func _convertSetToNSSet<T>(_ s: Set<T>) -> NSSet {
40+
public func _convertSetToNSSet<T>(_ s: Set<T>) -> NSSet {
4141
return NSSet()
4242
}
4343

44-
internal func _convertNSSetToSet<T>(_ s: NSSet?) -> Set<T> {
44+
public func _convertNSSetToSet<T>(_ s: NSSet?) -> Set<T> {
4545
return Set<T>()
4646
}
4747

@@ -272,10 +272,10 @@ extension NSArray {
272272
}
273273

274274
@_silgen_name("swift_convertNSErrorToError")
275-
func _convertNSErrorToError(_ string: NSError?) -> Error
275+
public func _convertNSErrorToError(_ string: NSError?) -> Error
276276

277277
@_silgen_name("swift_convertErrorToNSError")
278-
func _convertErrorToNSError(_ string: Error) -> NSError
278+
public func _convertErrorToNSError(_ string: Error) -> NSError
279279

280280
/// An internal protocol to represent Swift error enums that map to standard
281281
/// Cocoa NSError domains.

test/Inputs/clang-importer-sdk/swift-modules/ObjectiveC.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ public struct NSZone {
7575
public var pointer : OpaquePointer
7676
}
7777

78-
internal func _convertBoolToObjCBool(_ x: Bool) -> ObjCBool {
78+
public func _convertBoolToObjCBool(_ x: Bool) -> ObjCBool {
7979
return ObjCBool(x)
8080
}
8181

82-
internal func _convertObjCBoolToBool(_ x: ObjCBool) -> Bool {
82+
public func _convertObjCBoolToBool(_ x: ObjCBool) -> Bool {
8383
return x.boolValue
8484
}
8585

test/SILGen/Inputs/Foundation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ func _convertNSDictionaryToDictionary<K: NSObject, V: AnyObject>(
3232
}
3333

3434
// NSSet bridging entry points
35-
func _convertSetToNSSet<T: Hashable>(s: Set<T>) -> NSSet {
35+
func _convertSetToNSSet<T>(s: Set<T>) -> NSSet {
3636
return NSSet()
3737
}
3838

39-
func _convertNSSetToSet<T: NSObject>(s: NSSet?) -> Set<T> {
39+
func _convertNSSetToSet<T>(s: NSSet?) -> Set<T> {
4040
return Set<T>()
4141
}
4242

test/SILGen/Inputs/ObjectiveC.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ public struct ObjCBool {
1212
}
1313

1414
@_silgen_name("swift_BoolToObjCBool")
15-
func _convertBoolToObjCBool(_ x: Bool) -> ObjCBool
15+
public func _convertBoolToObjCBool(_ x: Bool) -> ObjCBool
1616

1717
@_silgen_name("swift_ObjCBoolToBool")
18-
func _convertObjCBoolToBool(_ x: ObjCBool) -> Bool
18+
public func _convertObjCBoolToBool(_ x: ObjCBool) -> Bool
1919

2020

2121
public struct Selector : ExpressibleByStringLiteral {

0 commit comments

Comments
 (0)