Skip to content

More Sema cleanup #12893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,12 @@ class alignas(1 << DeclAlignInBits) Decl {

/// Whether there is are lazily-loaded conformances for this nominal type.
unsigned HasLazyConformances : 1;

/// Whether we have already validated all members of the type that
/// affect layout.
unsigned HasValidatedLayout : 1;
};
enum { NumNominalTypeDeclBits = NumGenericTypeDeclBits + 3 };
enum { NumNominalTypeDeclBits = NumGenericTypeDeclBits + 4 };
static_assert(NumNominalTypeDeclBits <= 32, "fits in an unsigned");

class ProtocolDeclBitfields {
Expand Down Expand Up @@ -2817,6 +2821,7 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
NominalTypeDeclBits.AddedImplicitInitializers = false;
ExtensionGeneration = 0;
NominalTypeDeclBits.HasLazyConformances = false;
NominalTypeDeclBits.HasValidatedLayout = false;
}

friend class ProtocolType;
Expand Down Expand Up @@ -2859,11 +2864,23 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
return NominalTypeDeclBits.AddedImplicitInitializers;
}

/// Note that we have attempted to
/// Note that we have attempted to add implicit initializers.
void setAddedImplicitInitializers() {
NominalTypeDeclBits.AddedImplicitInitializers = true;
}


/// Determine whether we have already validated any members
/// which affect layout.
bool hasValidatedLayout() const {
return NominalTypeDeclBits.HasValidatedLayout;
}

/// Note that we have attempted to validate any members
/// which affect layout.
void setHasValidatedLayout() {
NominalTypeDeclBits.HasValidatedLayout = true;
}

/// Compute the type of this nominal type.
void computeType();

Expand Down
15 changes: 5 additions & 10 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7891,7 +7891,11 @@ static bool shouldValidateMemberDuringFinalization(NominalTypeDecl *nominal,
}

void TypeChecker::requestClassLayout(ClassDecl *classDecl) {
// FIXME: Check a flag in the class...
if (classDecl->hasValidatedLayout())
return;

classDecl->setHasValidatedLayout();

if (isa<SourceFile>(classDecl->getModuleScopeContext()))
DeclsToFinalize.insert(classDecl);
}
Expand Down Expand Up @@ -8157,15 +8161,6 @@ checkExtensionGenericParams(TypeChecker &tc, ExtensionDecl *ext, Type type,
return { env, extContextType };
}

// FIXME: In TypeChecker.cpp; only needed because LLDB creates
// extensions of typealiases to unbound generic types, which is
// ill-formed but convenient.
namespace swift {
GenericParamList *cloneGenericParams(ASTContext &ctx,
DeclContext *dc,
GenericParamList *fromParams);
} // namespace swift

void TypeChecker::validateExtension(ExtensionDecl *ext) {
// If we're currently validating, or have already validated this extension,
// there's nothing more to do now.
Expand Down
14 changes: 3 additions & 11 deletions lib/Sema/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,11 @@ Type TypeChecker::lookupBoolType(const DeclContext *dc) {
return *boolType;
}

namespace swift {

/// Clone the given generic parameters in the given list. We don't need any
/// of the requirements, because they will be inferred.
GenericParamList *cloneGenericParams(ASTContext &ctx,
DeclContext *dc,
GenericParamList *fromParams) {
static GenericParamList *cloneGenericParams(ASTContext &ctx,
DeclContext *dc,
GenericParamList *fromParams) {
// Clone generic parameters.
SmallVector<GenericTypeParamDecl *, 2> toGenericParams;
for (auto fromGP : *fromParams) {
Expand All @@ -292,12 +290,6 @@ GenericParamList *cloneGenericParams(ASTContext &ctx,

return toParams;
}
} // namespace swift

// FIXME: total hack
GenericParamList *createProtocolGenericParams(ASTContext &ctx,
ProtocolDecl *proto,
DeclContext *dc);

static void bindExtensionDecl(ExtensionDecl *ED, TypeChecker &TC) {
if (ED->getExtendedType())
Expand Down
6 changes: 0 additions & 6 deletions lib/Sema/TypeChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -741,12 +741,6 @@ class TypeChecker final : public LazyResolver {
/// will need to compute captures for.
std::vector<AnyFunctionRef> ClosuresWithUncomputedCaptures;

/// Describes an attempt to capture a local function.
struct LocalFunctionCapture {
FuncDecl *LocalFunction;
SourceLoc CaptureLoc;
};

/// Local functions that have been captured before their definitions.
///
/// We need this to guard against functions that would transitively capture
Expand Down