Skip to content

Only warn about @inlinable implying @usableFromInline in -swift-version 4.2 #17312

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
merged 2 commits into from
Jun 19, 2018
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
34 changes: 18 additions & 16 deletions lib/Sema/DerivedConformanceRawRepresentable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ static void deriveBodyRawRepresentable_raw(AbstractFunctionDecl *toRawDecl) {
toRawDecl->setBody(body);
}

static void maybeMarkAsInlinable(DerivedConformance &derived,
AbstractFunctionDecl *afd) {
ASTContext &C = derived.TC.Context;
auto parentDC = derived.getConformanceContext();
if (parentDC->getParentModule()->getResilienceStrategy() !=
ResilienceStrategy::Resilient) {
AccessScope access =
afd->getFormalAccessScope(nullptr,
/*treatUsableFromInlineAsPublic*/true);
if (auto *attr = afd->getAttrs().getAttribute<UsableFromInlineAttr>())
attr->setInvalid();
if (access.isPublic())
afd->getAttrs().add(new (C) InlinableAttr(/*implicit*/false));
}
}

static VarDecl *deriveRawRepresentable_raw(DerivedConformance &derived) {
ASTContext &C = derived.TC.Context;

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

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

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

Expand Down Expand Up @@ -350,14 +359,7 @@ deriveRawRepresentable_init(DerivedConformance &derived) {

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

C.addSynthesizedDecl(initDecl);

Expand Down
4 changes: 1 addition & 3 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1982,9 +1982,7 @@ void AttributeChecker::visitUsableFromInlineAttr(UsableFromInlineAttr *attr) {

// On internal declarations, @inlinable implies @usableFromInline.
if (VD->getAttrs().hasAttribute<InlinableAttr>()) {
if (attr->isImplicit())
attr->setInvalid();
else
if (TC.Context.isSwiftVersionAtLeast(4,2))
diagnoseAndRemoveAttr(attr, diag::inlinable_implies_usable_from_inline);
return;
}
Expand Down
3 changes: 3 additions & 0 deletions test/Compatibility/attr_inlinable_old_spelling_4.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@

@_inlineable public func oldInlinableFunction() {}
@_versioned func oldVersionedFunction() {}

// No warning here
@_inlineable @_versioned func redundantAttribute() {}
3 changes: 3 additions & 0 deletions test/Compatibility/attr_inlinable_old_spelling_42.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@

@_versioned func oldVersionedFunction() {}
// expected-warning@-1 {{'@_versioned' has been renamed to '@usableFromInline'}}{{2-12=usableFromInline}}

@inlinable @usableFromInline func redundantAttribute() {}
// expected-warning@-1 {{'@inlinable' declaration is already '@usableFromInline'}}
8 changes: 4 additions & 4 deletions test/attr/attr_inlinable.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: %target-typecheck-verify-swift -swift-version 4
// RUN: %target-typecheck-verify-swift -swift-version 4 -enable-testing
// RUN: %target-typecheck-verify-swift -swift-version 4 -enable-resilience
// RUN: %target-typecheck-verify-swift -swift-version 4 -enable-resilience -enable-testing
// RUN: %target-typecheck-verify-swift -swift-version 4.2
// RUN: %target-typecheck-verify-swift -swift-version 4.2 -enable-testing
// RUN: %target-typecheck-verify-swift -swift-version 4.2 -enable-resilience
// RUN: %target-typecheck-verify-swift -swift-version 4.2 -enable-resilience -enable-testing
@inlinable struct TestInlinableStruct {}
// expected-error@-1 {{'@inlinable' attribute cannot be applied to this declaration}}

Expand Down