Skip to content

Commit 3114ed1

Browse files
committed
Allow '@usableFromInline' on 'dynamic' decls
It actually /does/ make sense to enforce the usable-from-inline rules on dynamic declarations, but that would break source compatibility at this point. Just allow '@usableFromInline' to be written on 'dynamic' declarations, so that it'll be compatible with Swift 5.
1 parent ab980ff commit 3114ed1

File tree

6 files changed

+25
-23
lines changed

6 files changed

+25
-23
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4031,9 +4031,6 @@ WARNING(inlinable_implies_usable_from_inline,none,
40314031
ERROR(usable_from_inline_attr_in_protocol,none,
40324032
"'@usableFromInline' attribute cannot be used in protocols", ())
40334033

4034-
ERROR(usable_from_inline_dynamic_not_supported,none,
4035-
"'@usableFromInline' attribute cannot be applied to 'dynamic' declarations", ())
4036-
40374034
#define FRAGILE_FUNC_KIND \
40384035
"%select{a '@_transparent' function|" \
40394036
"an '@inline(__always)' function|" \

lib/Sema/TypeCheckAttr.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,16 +1844,6 @@ void AttributeChecker::visitUsableFromInlineAttr(UsableFromInlineAttr *attr) {
18441844
return;
18451845
}
18461846

1847-
// Symbols of dynamically-dispatched declarations are never referenced
1848-
// directly, so marking them as @usableFromInline does not make sense.
1849-
if (VD->isDynamic()) {
1850-
if (attr->isImplicit())
1851-
attr->setInvalid();
1852-
else
1853-
diagnoseAndRemoveAttr(attr, diag::usable_from_inline_dynamic_not_supported);
1854-
return;
1855-
}
1856-
18571847
// On internal declarations, @inlinable implies @usableFromInline.
18581848
if (VD->getAttrs().hasAttribute<InlinableAttr>()) {
18591849
if (TC.Context.isSwiftVersionAtLeast(4,2))

test/Compatibility/attr_usableFromInline_swift4.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-typecheck-verify-swift -swift-version 4
2-
// RUN: %target-typecheck-verify-swift -enable-testing -swift-version 4
1+
// RUN: %target-typecheck-verify-swift -swift-version 4 -disable-objc-attr-requires-foundation-module -enable-objc-interop
2+
// RUN: %target-typecheck-verify-swift -enable-testing -swift-version 4 -disable-objc-attr-requires-foundation-module -enable-objc-interop
33

44
@usableFromInline private func privateVersioned() {}
55
// expected-error@-1 {{'@usableFromInline' attribute can only be applied to internal declarations, but 'privateVersioned()' is private}}
@@ -121,3 +121,9 @@ enum BadEnum {
121121

122122
@usableFromInline
123123
class BadClass : InternalClass {}
124+
125+
public class DynamicMembers {
126+
@usableFromInline @objc dynamic init() {}
127+
@usableFromInline @objc dynamic func foo() {}
128+
@usableFromInline @objc dynamic var bar: Int = 0
129+
}

test/Compatibility/attr_usableFromInline_swift42.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-typecheck-verify-swift -swift-version 4.2
2-
// RUN: %target-typecheck-verify-swift -enable-testing -swift-version 4.2
1+
// RUN: %target-typecheck-verify-swift -swift-version 4.2 -disable-objc-attr-requires-foundation-module -enable-objc-interop
2+
// RUN: %target-typecheck-verify-swift -enable-testing -swift-version 4.2 -disable-objc-attr-requires-foundation-module -enable-objc-interop
33

44
@usableFromInline private func privateVersioned() {}
55
// expected-error@-1 {{'@usableFromInline' attribute can only be applied to internal declarations, but 'privateVersioned()' is private}}
@@ -141,3 +141,9 @@ enum BadEnum {
141141
@usableFromInline
142142
class BadClass : InternalClass {}
143143
// expected-warning@-1 {{type referenced from the superclass of a '@usableFromInline' class should be '@usableFromInline' or public}}
144+
145+
public class DynamicMembers {
146+
@usableFromInline @objc dynamic init() {}
147+
@usableFromInline @objc dynamic func foo() {}
148+
@usableFromInline @objc dynamic var bar: Int = 0
149+
}

test/attr/attr_objc.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,13 +2291,10 @@ class User: NSObject {
22912291
}
22922292
}
22932293

2294-
// 'dynamic' methods cannot be @inlinable or @usableFromInline
2294+
// 'dynamic' methods cannot be @inlinable.
22952295
class BadClass {
22962296
@inlinable @objc dynamic func badMethod1() {}
22972297
// expected-error@-1 {{'@inlinable' attribute cannot be applied to 'dynamic' declarations}}
2298-
2299-
@usableFromInline @objc dynamic func badMethod2() {}
2300-
// expected-error@-1 {{'@usableFromInline' attribute cannot be applied to 'dynamic' declarations}}
23012298
}
23022299

23032300
@objc

test/attr/attr_usableFromInline.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-typecheck-verify-swift -swift-version 5
2-
// RUN: %target-typecheck-verify-swift -enable-testing -swift-version 5
1+
// RUN: %target-typecheck-verify-swift -swift-version 5 -disable-objc-attr-requires-foundation-module -enable-objc-interop
2+
// RUN: %target-typecheck-verify-swift -swift-version 5 -disable-objc-attr-requires-foundation-module -enable-objc-interop -enable-testing
33

44
@usableFromInline private func privateVersioned() {}
55
// expected-error@-1 {{'@usableFromInline' attribute can only be applied to internal declarations, but 'privateVersioned()' is private}}
@@ -68,6 +68,12 @@ public func usesEqEnum() -> Bool {
6868
_ = RawEnum(rawValue: 0)
6969
}
7070

71+
public class DynamicMembers {
72+
@usableFromInline @objc dynamic init() {}
73+
@usableFromInline @objc dynamic func foo() {}
74+
@usableFromInline @objc dynamic var bar: Int = 0
75+
}
76+
7177
internal struct InternalStruct {}
7278
// expected-note@-1 9{{type declared here}}
7379

0 commit comments

Comments
 (0)