Skip to content

Commit 8f63e6c

Browse files
authored
Merge pull request #12893 from slavapestov/more-sema-cleanup
More Sema cleanup
2 parents 3cfab2f + 66211a8 commit 8f63e6c

File tree

4 files changed

+28
-30
lines changed

4 files changed

+28
-30
lines changed

include/swift/AST/Decl.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,12 @@ class alignas(1 << DeclAlignInBits) Decl {
458458

459459
/// Whether there is are lazily-loaded conformances for this nominal type.
460460
unsigned HasLazyConformances : 1;
461+
462+
/// Whether we have already validated all members of the type that
463+
/// affect layout.
464+
unsigned HasValidatedLayout : 1;
461465
};
462-
enum { NumNominalTypeDeclBits = NumGenericTypeDeclBits + 3 };
466+
enum { NumNominalTypeDeclBits = NumGenericTypeDeclBits + 4 };
463467
static_assert(NumNominalTypeDeclBits <= 32, "fits in an unsigned");
464468

465469
class ProtocolDeclBitfields {
@@ -2817,6 +2821,7 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
28172821
NominalTypeDeclBits.AddedImplicitInitializers = false;
28182822
ExtensionGeneration = 0;
28192823
NominalTypeDeclBits.HasLazyConformances = false;
2824+
NominalTypeDeclBits.HasValidatedLayout = false;
28202825
}
28212826

28222827
friend class ProtocolType;
@@ -2859,11 +2864,23 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
28592864
return NominalTypeDeclBits.AddedImplicitInitializers;
28602865
}
28612866

2862-
/// Note that we have attempted to
2867+
/// Note that we have attempted to add implicit initializers.
28632868
void setAddedImplicitInitializers() {
28642869
NominalTypeDeclBits.AddedImplicitInitializers = true;
28652870
}
2866-
2871+
2872+
/// Determine whether we have already validated any members
2873+
/// which affect layout.
2874+
bool hasValidatedLayout() const {
2875+
return NominalTypeDeclBits.HasValidatedLayout;
2876+
}
2877+
2878+
/// Note that we have attempted to validate any members
2879+
/// which affect layout.
2880+
void setHasValidatedLayout() {
2881+
NominalTypeDeclBits.HasValidatedLayout = true;
2882+
}
2883+
28672884
/// Compute the type of this nominal type.
28682885
void computeType();
28692886

lib/Sema/TypeCheckDecl.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7891,7 +7891,11 @@ static bool shouldValidateMemberDuringFinalization(NominalTypeDecl *nominal,
78917891
}
78927892

78937893
void TypeChecker::requestClassLayout(ClassDecl *classDecl) {
7894-
// FIXME: Check a flag in the class...
7894+
if (classDecl->hasValidatedLayout())
7895+
return;
7896+
7897+
classDecl->setHasValidatedLayout();
7898+
78957899
if (isa<SourceFile>(classDecl->getModuleScopeContext()))
78967900
DeclsToFinalize.insert(classDecl);
78977901
}
@@ -8157,15 +8161,6 @@ checkExtensionGenericParams(TypeChecker &tc, ExtensionDecl *ext, Type type,
81578161
return { env, extContextType };
81588162
}
81598163

8160-
// FIXME: In TypeChecker.cpp; only needed because LLDB creates
8161-
// extensions of typealiases to unbound generic types, which is
8162-
// ill-formed but convenient.
8163-
namespace swift {
8164-
GenericParamList *cloneGenericParams(ASTContext &ctx,
8165-
DeclContext *dc,
8166-
GenericParamList *fromParams);
8167-
} // namespace swift
8168-
81698164
void TypeChecker::validateExtension(ExtensionDecl *ext) {
81708165
// If we're currently validating, or have already validated this extension,
81718166
// there's nothing more to do now.

lib/Sema/TypeChecker.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,11 @@ Type TypeChecker::lookupBoolType(const DeclContext *dc) {
261261
return *boolType;
262262
}
263263

264-
namespace swift {
265-
266264
/// Clone the given generic parameters in the given list. We don't need any
267265
/// of the requirements, because they will be inferred.
268-
GenericParamList *cloneGenericParams(ASTContext &ctx,
269-
DeclContext *dc,
270-
GenericParamList *fromParams) {
266+
static GenericParamList *cloneGenericParams(ASTContext &ctx,
267+
DeclContext *dc,
268+
GenericParamList *fromParams) {
271269
// Clone generic parameters.
272270
SmallVector<GenericTypeParamDecl *, 2> toGenericParams;
273271
for (auto fromGP : *fromParams) {
@@ -292,12 +290,6 @@ GenericParamList *cloneGenericParams(ASTContext &ctx,
292290

293291
return toParams;
294292
}
295-
} // namespace swift
296-
297-
// FIXME: total hack
298-
GenericParamList *createProtocolGenericParams(ASTContext &ctx,
299-
ProtocolDecl *proto,
300-
DeclContext *dc);
301293

302294
static void bindExtensionDecl(ExtensionDecl *ED, TypeChecker &TC) {
303295
if (ED->getExtendedType())

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -741,12 +741,6 @@ class TypeChecker final : public LazyResolver {
741741
/// will need to compute captures for.
742742
std::vector<AnyFunctionRef> ClosuresWithUncomputedCaptures;
743743

744-
/// Describes an attempt to capture a local function.
745-
struct LocalFunctionCapture {
746-
FuncDecl *LocalFunction;
747-
SourceLoc CaptureLoc;
748-
};
749-
750744
/// Local functions that have been captured before their definitions.
751745
///
752746
/// We need this to guard against functions that would transitively capture

0 commit comments

Comments
 (0)