Skip to content

Commit cd2eb61

Browse files
authored
Merge pull request #17312 from slavapestov/inlinable-warning-tweak
Only warn about @inlinable implying @usableFromInline in -swift-version 4.2
2 parents c2b9ffc + cfdcbc7 commit cd2eb61

File tree

5 files changed

+29
-23
lines changed

5 files changed

+29
-23
lines changed

lib/Sema/DerivedConformanceRawRepresentable.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,22 @@ static void deriveBodyRawRepresentable_raw(AbstractFunctionDecl *toRawDecl) {
121121
toRawDecl->setBody(body);
122122
}
123123

124+
static void maybeMarkAsInlinable(DerivedConformance &derived,
125+
AbstractFunctionDecl *afd) {
126+
ASTContext &C = derived.TC.Context;
127+
auto parentDC = derived.getConformanceContext();
128+
if (parentDC->getParentModule()->getResilienceStrategy() !=
129+
ResilienceStrategy::Resilient) {
130+
AccessScope access =
131+
afd->getFormalAccessScope(nullptr,
132+
/*treatUsableFromInlineAsPublic*/true);
133+
if (auto *attr = afd->getAttrs().getAttribute<UsableFromInlineAttr>())
134+
attr->setInvalid();
135+
if (access.isPublic())
136+
afd->getAttrs().add(new (C) InlinableAttr(/*implicit*/false));
137+
}
138+
}
139+
124140
static VarDecl *deriveRawRepresentable_raw(DerivedConformance &derived) {
125141
ASTContext &C = derived.TC.Context;
126142

@@ -143,14 +159,7 @@ static VarDecl *deriveRawRepresentable_raw(DerivedConformance &derived) {
143159

144160
// If the containing module is not resilient, make sure clients can get at
145161
// the raw value without function call overhead.
146-
if (parentDC->getParentModule()->getResilienceStrategy() !=
147-
ResilienceStrategy::Resilient) {
148-
AccessScope access =
149-
enumDecl->getFormalAccessScope(nullptr,
150-
/*treatUsableFromInlineAsPublic*/true);
151-
if (access.isPublic())
152-
getterDecl->getAttrs().add(new (C) InlinableAttr(/*implicit*/false));
153-
}
162+
maybeMarkAsInlinable(derived, getterDecl);
154163

155164
derived.addMembersToConformanceContext({getterDecl, propDecl, pbDecl});
156165

@@ -350,14 +359,7 @@ deriveRawRepresentable_init(DerivedConformance &derived) {
350359

351360
// If the containing module is not resilient, make sure clients can construct
352361
// an instance without function call overhead.
353-
if (parentDC->getParentModule()->getResilienceStrategy() !=
354-
ResilienceStrategy::Resilient) {
355-
AccessScope access =
356-
enumDecl->getFormalAccessScope(nullptr,
357-
/*treatUsableFromInlineAsPublic*/true);
358-
if (access.isPublic())
359-
initDecl->getAttrs().add(new (C) InlinableAttr(/*implicit*/false));
360-
}
362+
maybeMarkAsInlinable(derived, initDecl);
361363

362364
C.addSynthesizedDecl(initDecl);
363365

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,9 +1982,7 @@ void AttributeChecker::visitUsableFromInlineAttr(UsableFromInlineAttr *attr) {
19821982

19831983
// On internal declarations, @inlinable implies @usableFromInline.
19841984
if (VD->getAttrs().hasAttribute<InlinableAttr>()) {
1985-
if (attr->isImplicit())
1986-
attr->setInvalid();
1987-
else
1985+
if (TC.Context.isSwiftVersionAtLeast(4,2))
19881986
diagnoseAndRemoveAttr(attr, diag::inlinable_implies_usable_from_inline);
19891987
return;
19901988
}

test/Compatibility/attr_inlinable_old_spelling_4.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55

66
@_inlineable public func oldInlinableFunction() {}
77
@_versioned func oldVersionedFunction() {}
8+
9+
// No warning here
10+
@_inlineable @_versioned func redundantAttribute() {}

test/Compatibility/attr_inlinable_old_spelling_42.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77

88
@_versioned func oldVersionedFunction() {}
99
// expected-warning@-1 {{'@_versioned' has been renamed to '@usableFromInline'}}{{2-12=usableFromInline}}
10+
11+
@inlinable @usableFromInline func redundantAttribute() {}
12+
// expected-warning@-1 {{'@inlinable' declaration is already '@usableFromInline'}}

test/attr/attr_inlinable.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// RUN: %target-typecheck-verify-swift -swift-version 4
2-
// RUN: %target-typecheck-verify-swift -swift-version 4 -enable-testing
3-
// RUN: %target-typecheck-verify-swift -swift-version 4 -enable-resilience
4-
// RUN: %target-typecheck-verify-swift -swift-version 4 -enable-resilience -enable-testing
1+
// RUN: %target-typecheck-verify-swift -swift-version 4.2
2+
// RUN: %target-typecheck-verify-swift -swift-version 4.2 -enable-testing
3+
// RUN: %target-typecheck-verify-swift -swift-version 4.2 -enable-resilience
4+
// RUN: %target-typecheck-verify-swift -swift-version 4.2 -enable-resilience -enable-testing
55
@inlinable struct TestInlinableStruct {}
66
// expected-error@-1 {{'@inlinable' attribute cannot be applied to this declaration}}
77

0 commit comments

Comments
 (0)