Skip to content

Commit 496d29c

Browse files
committed
AST: Remove FragileFunctionKind.allowUsableFromInline.
It was effectively always true after allowing default argument expressions to reference `@usableFromInline` decls.
1 parent b9262e5 commit 496d29c

File tree

5 files changed

+32
-56
lines changed

5 files changed

+32
-56
lines changed

include/swift/AST/DeclContext.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,9 @@ struct FragileFunctionKind {
217217
};
218218

219219
Kind kind = None;
220-
bool allowUsableFromInline = false;
221220

222221
friend bool operator==(FragileFunctionKind lhs, FragileFunctionKind rhs) {
223-
return (lhs.kind == rhs.kind &&
224-
lhs.allowUsableFromInline == rhs.allowUsableFromInline);
222+
return lhs.kind == rhs.kind;
225223
}
226224

227225
/// Casts to `unsigned` for diagnostic %selects.

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6539,10 +6539,6 @@ ERROR(availability_macro_in_inlinable, none,
65396539

65406540
#undef FRAGILE_FUNC_KIND
65416541

6542-
NOTE(resilience_decl_declared_here_public,
6543-
none, DECL_OR_ACCESSOR "2 %1 is not public",
6544-
(DescriptiveDeclKind, DeclName, bool))
6545-
65466542
NOTE(resilience_decl_declared_here,
65476543
none, DECL_OR_ACCESSOR "2 %1 is not '@usableFromInline' or public",
65486544
(DescriptiveDeclKind, DeclName, bool))

lib/AST/DeclContext.cpp

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,10 @@ ResilienceExpansion DeclContext::getResilienceExpansion() const {
445445

446446
FragileFunctionKind DeclContext::getFragileFunctionKind() const {
447447
auto &context = getASTContext();
448-
return evaluateOrDefault(context.evaluator,
449-
FragileFunctionKindRequest { const_cast<DeclContext *>(this) },
450-
{FragileFunctionKind::None, false});
448+
return evaluateOrDefault(
449+
context.evaluator,
450+
FragileFunctionKindRequest{const_cast<DeclContext *>(this)},
451+
{FragileFunctionKind::None});
451452
}
452453

453454
FragileFunctionKind
@@ -466,20 +467,17 @@ swift::FragileFunctionKindRequest::evaluate(Evaluator &evaluator,
466467
if (VD->getDeclContext()->isLocalContext()) {
467468
auto kind = VD->getDeclContext()->getFragileFunctionKind();
468469
if (kind.kind != FragileFunctionKind::None)
469-
return {FragileFunctionKind::DefaultArgument,
470-
kind.allowUsableFromInline};
470+
return {FragileFunctionKind::DefaultArgument};
471471
}
472472

473473
auto effectiveAccess =
474474
VD->getFormalAccessScope(/*useDC=*/nullptr,
475475
/*treatUsableFromInlineAsPublic=*/true);
476476
if (effectiveAccess.isPublic()) {
477-
return {FragileFunctionKind::DefaultArgument,
478-
/*allowUsableFromInline=*/true};
477+
return {FragileFunctionKind::DefaultArgument};
479478
}
480479

481-
return {FragileFunctionKind::None,
482-
/*allowUsableFromInline=*/false};
480+
return {FragileFunctionKind::None};
483481
}
484482

485483
// Stored property initializer contexts use minimal resilience expansion
@@ -488,13 +486,11 @@ swift::FragileFunctionKindRequest::evaluate(Evaluator &evaluator,
488486
auto bindingIndex = init->getBindingIndex();
489487
if (auto *varDecl = init->getBinding()->getAnchoringVarDecl(bindingIndex)) {
490488
if (varDecl->isInitExposedToClients()) {
491-
return {FragileFunctionKind::PropertyInitializer,
492-
/*allowUsableFromInline=*/true};
489+
return {FragileFunctionKind::PropertyInitializer};
493490
}
494491
}
495492

496-
return {FragileFunctionKind::None,
497-
/*allowUsableFromInline=*/false};
493+
return {FragileFunctionKind::None};
498494
}
499495

500496
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(dc)) {
@@ -510,53 +506,44 @@ swift::FragileFunctionKindRequest::evaluate(Evaluator &evaluator,
510506
// If the function is not externally visible, we will not be serializing
511507
// its body.
512508
if (!funcAccess.isPublic()) {
513-
return {FragileFunctionKind::None,
514-
/*allowUsableFromInline=*/false};
509+
return {FragileFunctionKind::None};
515510
}
516511

517512
// If the function is public, @_transparent implies @inlinable.
518513
if (AFD->isTransparent()) {
519-
return {FragileFunctionKind::Transparent,
520-
/*allowUsableFromInline=*/true};
514+
return {FragileFunctionKind::Transparent};
521515
}
522516

523517
if (AFD->getAttrs().hasAttribute<InlinableAttr>()) {
524-
return {FragileFunctionKind::Inlinable,
525-
/*allowUsableFromInline=*/true};
518+
return {FragileFunctionKind::Inlinable};
526519
}
527520

528521
if (AFD->getAttrs().hasAttribute<AlwaysEmitIntoClientAttr>()) {
529-
return {FragileFunctionKind::AlwaysEmitIntoClient,
530-
/*allowUsableFromInline=*/true};
522+
return {FragileFunctionKind::AlwaysEmitIntoClient};
531523
}
532524

533525
if (AFD->isBackDeployed(context->getASTContext())) {
534-
return {FragileFunctionKind::BackDeploy,
535-
/*allowUsableFromInline=*/true};
526+
return {FragileFunctionKind::BackDeploy};
536527
}
537528

538529
// Property and subscript accessors inherit @_alwaysEmitIntoClient,
539530
// @backDeployed, and @inlinable from their storage declarations.
540531
if (auto accessor = dyn_cast<AccessorDecl>(AFD)) {
541532
auto *storage = accessor->getStorage();
542533
if (storage->getAttrs().getAttribute<InlinableAttr>()) {
543-
return {FragileFunctionKind::Inlinable,
544-
/*allowUsableFromInline=*/true};
534+
return {FragileFunctionKind::Inlinable};
545535
}
546536
if (storage->getAttrs().hasAttribute<AlwaysEmitIntoClientAttr>()) {
547-
return {FragileFunctionKind::AlwaysEmitIntoClient,
548-
/*allowUsableFromInline=*/true};
537+
return {FragileFunctionKind::AlwaysEmitIntoClient};
549538
}
550539
if (storage->isBackDeployed(context->getASTContext())) {
551-
return {FragileFunctionKind::BackDeploy,
552-
/*allowUsableFromInline=*/true};
540+
return {FragileFunctionKind::BackDeploy};
553541
}
554542
}
555543
}
556544
}
557545

558-
return {FragileFunctionKind::None,
559-
/*allowUsableFromInline=*/false};
546+
return {FragileFunctionKind::None};
560547
}
561548

562549
/// Determine whether the innermost context is generic.

lib/AST/TypeCheckRequests.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -588,29 +588,28 @@ void swift::simple_display(llvm::raw_ostream &out,
588588
switch (value.kind) {
589589
case FragileFunctionKind::Transparent:
590590
out << "transparent";
591-
break;
591+
return;
592592
case FragileFunctionKind::Inlinable:
593593
out << "inlinable";
594-
break;
594+
return;
595595
case FragileFunctionKind::AlwaysEmitIntoClient:
596596
out << "alwaysEmitIntoClient";
597-
break;
597+
return;
598598
case FragileFunctionKind::DefaultArgument:
599599
out << "defaultArgument";
600-
break;
600+
return;
601601
case FragileFunctionKind::PropertyInitializer:
602602
out << "propertyInitializer";
603-
break;
603+
return;
604604
case FragileFunctionKind::BackDeploy:
605605
out << "backDeploy";
606-
break;
606+
return;
607607
case FragileFunctionKind::None:
608608
out << "none";
609-
break;
609+
return;
610610
}
611611

612-
out << ", allowUsableFromInline: "
613-
<< (value.allowUsableFromInline ? "true" : "false");
612+
llvm_unreachable("Bad FragileFunctionKind");
614613
}
615614

616615
//----------------------------------------------------------------------------//

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
6161
return false;
6262

6363
// General check on access-level of the decl.
64-
auto declAccessScope = D->getFormalAccessScope(/*useDC=*/nullptr,
65-
fragileKind.allowUsableFromInline);
64+
auto declAccessScope =
65+
D->getFormalAccessScope(/*useDC=*/nullptr,
66+
/*allowUsableFromInline=*/true);
6667

6768
// If the decl is imported, check if the import lowers it's access level.
6869
auto importAccessLevel = AccessLevel::Public;
@@ -134,13 +135,8 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
134135
diagAccessLevel,
135136
fragileKind.getSelector(), isAccessor);
136137

137-
if (fragileKind.allowUsableFromInline) {
138-
Context.Diags.diagnose(D, diag::resilience_decl_declared_here,
139-
D->getDescriptiveKind(), diagName, isAccessor);
140-
} else {
141-
Context.Diags.diagnose(D, diag::resilience_decl_declared_here_public,
142-
D->getDescriptiveKind(), diagName, isAccessor);
143-
}
138+
Context.Diags.diagnose(D, diag::resilience_decl_declared_here,
139+
D->getDescriptiveKind(), diagName, isAccessor);
144140

145141
if (problematicImport.has_value() &&
146142
diagAccessLevel == importAccessLevel) {

0 commit comments

Comments
 (0)