Skip to content

Commit cfa968a

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 0871a9d commit cfa968a

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
@@ -2759,15 +2759,26 @@ bool VarDecl::isLayoutExposedToClients() const {
27592759
if (!parent) return false;
27602760
if (isStatic()) return false;
27612761

2762-
2762+
auto M = getDeclContext()->getParentModule();
27632763
auto nominalAccess =
27642764
parent->getFormalAccessScope(/*useDC=*/nullptr,
27652765
/*treatUsableFromInlineAsPublic=*/true);
2766-
if (!nominalAccess.isPublic()) return false;
27672766

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

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

0 commit comments

Comments
 (0)