Skip to content

Commit 07db1f0

Browse files
committed
Sema: Clean up @usableFromInline validation slightly
1 parent d910e5a commit 07db1f0

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,10 +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
1988-
diagnoseAndRemoveAttr(attr, diag::inlinable_implies_usable_from_inline);
1985+
diagnoseAndRemoveAttr(attr, diag::inlinable_implies_usable_from_inline);
19891986
return;
19901987
}
19911988
}

0 commit comments

Comments
 (0)