Skip to content

Commit d432286

Browse files
committed
Re-apply "Sema: Targeted fix for LLDB REPL issue"
Now with a change to the AST printer to never print @_fixed_layout. Once some more groundwork is in place, we will be able to only print this attribute when its needed, but this is good enough for now.
1 parent 3d2056d commit d432286

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

include/swift/AST/PrintOptions.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ struct PrintOptions {
123123
bool PrintUserInaccessibleAttrs = true;
124124

125125
/// List of attribute kinds that should not be printed.
126-
std::vector<DeclAttrKind> ExcludeAttrList = { DAK_Transparent, DAK_Effects };
126+
std::vector<DeclAttrKind> ExcludeAttrList =
127+
{ DAK_Transparent, DAK_Effects, DAK_FixedLayout };
127128

128129
/// List of attribute kinds that should be printed exclusively.
129130
/// Empty means allow all.
@@ -287,6 +288,7 @@ struct PrintOptions {
287288
static PrintOptions printEverything() {
288289
PrintOptions result = printVerbose();
289290
result.ExcludeAttrList.clear();
291+
result.ExcludeAttrList.push_back(DAK_FixedLayout);
290292
result.PrintStorageRepresentationAttrs = true;
291293
result.AbstractAccessors = false;
292294
result.PrintAccessibility = true;

lib/AST/Decl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,6 +1857,10 @@ bool NominalTypeDecl::hasFixedLayout() const {
18571857
return true;
18581858
}
18591859

1860+
// Objective-C enums always have a fixed layout.
1861+
if (isa<EnumDecl>(this) && isObjC())
1862+
return true;
1863+
18601864
// Otherwise, access via indirect "resilient" interfaces.
18611865
return false;
18621866
}

lib/Sema/TypeCheckDecl.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6957,18 +6957,17 @@ static void validateFixedLayoutAttribute(TypeChecker &TC,
69576957
NominalTypeDecl *D) {
69586958
DeclAttributes &Attrs = D->getAttrs();
69596959

6960-
if (Attrs.hasAttribute<FixedLayoutAttr>())
6960+
// FIXME: Add a per-module serialized HasFixedLayout flag, instead of
6961+
// giving every decl this attribute.
6962+
6963+
if (Attrs.hasAttribute<FixedLayoutAttr>() ||
6964+
TC.Context.LangOpts.EnableResilience)
69616965
return;
69626966

69636967
// Since -enable-resilience should not change how we call into
69646968
// existing compiled modules, make all value types @_fixed_layout
69656969
// when the frontend is not run with the -enable-resilience flag.
6966-
if (!TC.Context.LangOpts.EnableResilience &&
6967-
D->getFormalAccess() == Accessibility::Public)
6968-
Attrs.add(new (TC.Context) FixedLayoutAttr(/*IsImplicit*/ true));
6969-
// @objc enums are always @_fixed_layout.
6970-
else if (isa<EnumDecl>(D) && D->isObjC())
6971-
Attrs.add(new (TC.Context) FixedLayoutAttr(/*IsImplicit*/ true));
6970+
Attrs.add(new (TC.Context) FixedLayoutAttr(/*IsImplicit*/ true));
69726971
}
69736972

69746973
static void validateAttributes(TypeChecker &TC, Decl *D) {

0 commit comments

Comments
 (0)