Skip to content

Commit 1383fcd

Browse files
committed
Sema: Report non-LE structs as fragile use sites in CheckImplementationOnly
In non-library-evolution mode, gated behind the CheckImplementationOnly feature flag, consider structs to be a fragile use site by default, unless marked `@_implementationOnly`. This prevents them to refer to restricted imports like implementation-only.
1 parent 71035a5 commit 1383fcd

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lib/AST/Decl.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,15 +2758,26 @@ bool VarDecl::isLayoutExposedToClients() const {
27582758
if (!parent) return false;
27592759
if (isStatic()) return false;
27602760

2761-
2761+
auto M = getDeclContext()->getParentModule();
27622762
auto nominalAccess =
27632763
parent->getFormalAccessScope(/*useDC=*/nullptr,
27642764
/*treatUsableFromInlineAsPublic=*/true);
2765-
if (!nominalAccess.isPublic()) return false;
27662765

2767-
if (!parent->getAttrs().hasAttribute<FrozenAttr>() &&
2768-
!parent->getAttrs().hasAttribute<FixedLayoutAttr>())
2766+
// Resilient modules hide layouts by default.
2767+
if (!getASTContext().LangOpts.hasFeature(Feature::CheckImplementationOnly) ||
2768+
M->getResilienceStrategy() == ResilienceStrategy::Resilient) {
2769+
if (!nominalAccess.isPublic())
2770+
return false;
2771+
2772+
if (!parent->getAttrs().hasAttribute<FrozenAttr>() &&
2773+
!parent->getAttrs().hasAttribute<FixedLayoutAttr>())
27692774
return false;
2775+
} else {
2776+
// Non-resilient module: layouts are exposed by default unless marked
2777+
// otherwise.
2778+
if (parent->getAttrs().hasAttribute<ImplementationOnlyAttr>())
2779+
return false;
2780+
}
27702781

27712782
if (!hasStorage() &&
27722783
!getAttrs().hasAttribute<LazyAttr>() &&

0 commit comments

Comments
 (0)