Skip to content

Declaration checker cleanups #15408

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 12 commits into from
Mar 22, 2018
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
31 changes: 2 additions & 29 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,6 @@ enum class AssociatedValueCheck {
HasAssociatedValues,
};

/// Describes if an enum element constructor directly or indirectly references
/// its enclosing type.
enum class ElementRecursiveness {
/// The element does not reference its enclosing type.
NotRecursive,
/// The element is currently being validated, and may references its enclosing
/// type.
PotentiallyRecursive,
/// The element does not reference its enclosing type.
Recursive
};

/// Diagnostic printing of \c StaticSpellingKind.
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, StaticSpellingKind SSK);

Expand Down Expand Up @@ -339,13 +327,9 @@ class alignas(1 << DeclAlignInBits) Decl {
defaultArgumentKind : NumDefaultArgumentKindBits
);

SWIFT_INLINE_BITFIELD(EnumElementDecl, ValueDecl, 3,
SWIFT_INLINE_BITFIELD(EnumElementDecl, ValueDecl, 1,
/// \brief Whether or not this element has an associated value.
HasArgumentType : 1,

/// \brief Whether or not this element directly or indirectly references
/// the enum type.
Recursiveness : 2
HasArgumentType : 1
);

SWIFT_INLINE_BITFIELD(AbstractFunctionDecl, ValueDecl, 3+8+5+1+1+1+1+1,
Expand Down Expand Up @@ -5769,8 +5753,6 @@ class EnumElementDecl : public ValueDecl {
EqualsLoc(EqualsLoc),
RawValueExpr(RawValueExpr)
{
Bits.EnumElementDecl.Recursiveness =
static_cast<unsigned>(ElementRecursiveness::NotRecursive);
Bits.EnumElementDecl.HasArgumentType = HasArgumentType;
}

Expand Down Expand Up @@ -5815,15 +5797,6 @@ class EnumElementDecl : public ValueDecl {
}
SourceRange getSourceRange() const;

ElementRecursiveness getRecursiveness() const {
return
static_cast<ElementRecursiveness>(Bits.EnumElementDecl.Recursiveness);
}

void setRecursiveness(ElementRecursiveness recursiveness) {
Bits.EnumElementDecl.Recursiveness = static_cast<unsigned>(recursiveness);
}

bool hasAssociatedValues() const {
return Bits.EnumElementDecl.HasArgumentType;
}
Expand Down
33 changes: 17 additions & 16 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3250,23 +3250,24 @@ namespace {
if (hasZeroInitializableStorage) {
// Add constructors for the struct.
ctors.push_back(createDefaultConstructor(Impl, result));
if (hasReferenceableFields && hasMemberwiseInitializer) {
// The default zero initializer suppresses the implicit value
// constructor that would normally be formed, so we have to add that
// explicitly as well.
//
// If we can completely represent the struct in SIL, leave the body
// implicit, otherwise synthesize one to call property setters.
bool wantBody = (hasUnreferenceableStorage &&
!Impl.hasFinishedTypeChecking());
auto valueCtor = createValueConstructor(Impl, result, members,
/*want param names*/true,
/*want body*/wantBody);
if (!hasUnreferenceableStorage)
valueCtor->setIsMemberwiseInitializer();
}

ctors.push_back(valueCtor);
}
if (hasReferenceableFields && hasMemberwiseInitializer) {
// The default zero initializer suppresses the implicit value
// constructor that would normally be formed, so we have to add that
// explicitly as well.
//
// If we can completely represent the struct in SIL, leave the body
// implicit, otherwise synthesize one to call property setters.
bool wantBody = (hasUnreferenceableStorage &&
!Impl.hasFinishedTypeChecking());
auto valueCtor = createValueConstructor(Impl, result, members,
/*want param names*/true,
/*want body*/wantBody);
if (!hasUnreferenceableStorage)
valueCtor->setIsMemberwiseInitializer();

ctors.push_back(valueCtor);
}

for (auto member : members) {
Expand Down
14 changes: 5 additions & 9 deletions lib/Sema/CodeSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,7 @@ void TypeChecker::completePropertyBehaviorParameter(VarDecl *VD,

Parameter->setInterfaceType(SubstInterfaceTy);
Parameter->setGenericEnvironment(genericEnv);
Parameter->setValidationStarted();

// Mark the method to be final, implicit, and private. In a class, this
// prevents it from being dynamically dispatched.
Expand Down Expand Up @@ -1895,11 +1896,11 @@ void swift::maybeAddAccessorsToVariable(VarDecl *var, TypeChecker &TC) {
ConstructorDecl *swift::createImplicitConstructor(TypeChecker &tc,
NominalTypeDecl *decl,
ImplicitConstructorKind ICK) {
assert(!decl->hasClangNode());

ASTContext &context = tc.Context;
SourceLoc Loc = decl->getLoc();
auto accessLevel = AccessLevel::Internal;
if (decl->hasClangNode())
accessLevel = std::max(accessLevel, decl->getFormalAccess());

// Determine the parameter type of the implicit constructor.
SmallVector<ParamDecl*, 8> params;
Expand Down Expand Up @@ -1975,13 +1976,7 @@ ConstructorDecl *swift::createImplicitConstructor(TypeChecker &tc,
}

// Type-check the constructor declaration.
tc.typeCheckDecl(ctor, /*isFirstPass=*/true);

// If the struct in which this constructor is being added was imported,
// add it as an external definition.
if (decl->hasClangNode()) {
tc.Context.addExternalDecl(ctor);
}
tc.validateDecl(ctor);

return ctor;
}
Expand Down Expand Up @@ -2152,6 +2147,7 @@ swift::createDesignatedInitOverride(TypeChecker &tc,
// Wire up the overrides.
ctor->getAttrs().add(new (tc.Context) OverrideAttr(/*IsImplicit=*/true));
ctor->setOverriddenDecl(superclassCtor);
ctor->setValidationStarted();

if (kind == DesignatedInitKind::Stub) {
// Make this a stub implementation.
Expand Down
2 changes: 2 additions & 0 deletions lib/Sema/DerivedConformanceCodable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ static FuncDecl *deriveEncodable_encode(TypeChecker &tc, Decl *parentDecl,
}

encodeDecl->setInterfaceType(interfaceType);
encodeDecl->setValidationStarted();
encodeDecl->setAccess(target->getFormalAccess());

// If the type was not imported, the derived conformance is either from the
Expand Down Expand Up @@ -1109,6 +1110,7 @@ static ValueDecl *deriveDecodable_init(TypeChecker &tc, Decl *parentDecl,
}

initDecl->setInterfaceType(interfaceType);
initDecl->setValidationStarted();
initDecl->setInitializerInterfaceType(initializerType);
initDecl->setAccess(target->getFormalAccess());

Expand Down
1 change: 1 addition & 0 deletions lib/Sema/DerivedConformanceCodingKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ static ValueDecl *deriveInitDecl(TypeChecker &tc, Decl *parentDecl,
initDecl->setInterfaceType(allocIfaceType);
initDecl->setInitializerInterfaceType(initIfaceType);
initDecl->setAccess(enumDecl->getFormalAccess());
initDecl->setValidationStarted();

// If the enum was not imported, the derived conformance is either from the
// enum itself or an extension, in which case we will emit the declaration
Expand Down
3 changes: 3 additions & 0 deletions lib/Sema/DerivedConformanceEquatableHashable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ deriveEquatable_eq(TypeChecker &tc, Decl *parentDecl, NominalTypeDecl *typeDecl,
}
eqDecl->setInterfaceType(interfaceTy);
eqDecl->copyFormalAccessAndVersionedAttrFrom(typeDecl);
eqDecl->setValidationStarted();

// If the enum was not imported, the derived conformance is either from the
// enum itself or an extension, in which case we will emit the declaration
Expand Down Expand Up @@ -1062,6 +1063,7 @@ deriveHashable_hashValue(TypeChecker &tc, Decl *parentDecl,
AnyFunctionType::ExtInfo());

getterDecl->setInterfaceType(interfaceType);
getterDecl->setValidationStarted();
getterDecl->copyFormalAccessAndVersionedAttrFrom(typeDecl);

// If the enum was not imported, the derived conformance is either from the
Expand All @@ -1073,6 +1075,7 @@ deriveHashable_hashValue(TypeChecker &tc, Decl *parentDecl,
// Finish creating the property.
hashValueDecl->setImplicit();
hashValueDecl->setInterfaceType(intType);
hashValueDecl->setValidationStarted();
hashValueDecl->makeComputed(SourceLoc(), getterDecl,
nullptr, nullptr, SourceLoc());
hashValueDecl->copyFormalAccessAndVersionedAttrFrom(typeDecl);
Expand Down
1 change: 1 addition & 0 deletions lib/Sema/DerivedConformanceRawRepresentable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ static ConstructorDecl *deriveRawRepresentable_init(TypeChecker &tc,
initDecl->setInterfaceType(allocIfaceType);
initDecl->setInitializerInterfaceType(initIfaceType);
initDecl->copyFormalAccessAndVersionedAttrFrom(enumDecl);
initDecl->setValidationStarted();

// If the enum was not imported, the derived conformance is either from the
// enum itself or an extension, in which case we will emit the declaration
Expand Down
2 changes: 2 additions & 0 deletions lib/Sema/DerivedConformances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ DerivedConformance::declareDerivedPropertyGetter(TypeChecker &tc,
FunctionType::ExtInfo());
getterDecl->setInterfaceType(interfaceType);
getterDecl->copyFormalAccessAndVersionedAttrFrom(property);
getterDecl->setValidationStarted();

// If the enum was not imported, the derived conformance is either from the
// enum itself or an extension, in which case we will emit the declaration
Expand Down Expand Up @@ -308,6 +309,7 @@ DerivedConformance::declareDerivedProperty(TypeChecker &tc, Decl *parentDecl,
propDecl->setImplicit();
propDecl->copyFormalAccessAndVersionedAttrFrom(typeDecl);
propDecl->setInterfaceType(propertyInterfaceType);
propDecl->setValidationStarted();

// If this is supposed to be a final property, mark it as such.
assert(isFinal || !parentDC->getAsClassOrClassExtensionContext());
Expand Down
Loading