Skip to content

Commit 31aa280

Browse files
authored
Merge pull request #15408 from slavapestov/decl-checker-cleanup
Declaration checker cleanups
2 parents c38d3df + a6ff282 commit 31aa280

17 files changed

+2735
-2750
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,6 @@ enum class AssociatedValueCheck {
180180
HasAssociatedValues,
181181
};
182182

183-
/// Describes if an enum element constructor directly or indirectly references
184-
/// its enclosing type.
185-
enum class ElementRecursiveness {
186-
/// The element does not reference its enclosing type.
187-
NotRecursive,
188-
/// The element is currently being validated, and may references its enclosing
189-
/// type.
190-
PotentiallyRecursive,
191-
/// The element does not reference its enclosing type.
192-
Recursive
193-
};
194-
195183
/// Diagnostic printing of \c StaticSpellingKind.
196184
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, StaticSpellingKind SSK);
197185

@@ -339,13 +327,9 @@ class alignas(1 << DeclAlignInBits) Decl {
339327
defaultArgumentKind : NumDefaultArgumentKindBits
340328
);
341329

342-
SWIFT_INLINE_BITFIELD(EnumElementDecl, ValueDecl, 3,
330+
SWIFT_INLINE_BITFIELD(EnumElementDecl, ValueDecl, 1,
343331
/// \brief Whether or not this element has an associated value.
344-
HasArgumentType : 1,
345-
346-
/// \brief Whether or not this element directly or indirectly references
347-
/// the enum type.
348-
Recursiveness : 2
332+
HasArgumentType : 1
349333
);
350334

351335
SWIFT_INLINE_BITFIELD(AbstractFunctionDecl, ValueDecl, 3+8+5+1+1+1+1+1,
@@ -5769,8 +5753,6 @@ class EnumElementDecl : public ValueDecl {
57695753
EqualsLoc(EqualsLoc),
57705754
RawValueExpr(RawValueExpr)
57715755
{
5772-
Bits.EnumElementDecl.Recursiveness =
5773-
static_cast<unsigned>(ElementRecursiveness::NotRecursive);
57745756
Bits.EnumElementDecl.HasArgumentType = HasArgumentType;
57755757
}
57765758

@@ -5815,15 +5797,6 @@ class EnumElementDecl : public ValueDecl {
58155797
}
58165798
SourceRange getSourceRange() const;
58175799

5818-
ElementRecursiveness getRecursiveness() const {
5819-
return
5820-
static_cast<ElementRecursiveness>(Bits.EnumElementDecl.Recursiveness);
5821-
}
5822-
5823-
void setRecursiveness(ElementRecursiveness recursiveness) {
5824-
Bits.EnumElementDecl.Recursiveness = static_cast<unsigned>(recursiveness);
5825-
}
5826-
58275800
bool hasAssociatedValues() const {
58285801
return Bits.EnumElementDecl.HasArgumentType;
58295802
}

lib/ClangImporter/ImportDecl.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3250,23 +3250,24 @@ namespace {
32503250
if (hasZeroInitializableStorage) {
32513251
// Add constructors for the struct.
32523252
ctors.push_back(createDefaultConstructor(Impl, result));
3253-
if (hasReferenceableFields && hasMemberwiseInitializer) {
3254-
// The default zero initializer suppresses the implicit value
3255-
// constructor that would normally be formed, so we have to add that
3256-
// explicitly as well.
3257-
//
3258-
// If we can completely represent the struct in SIL, leave the body
3259-
// implicit, otherwise synthesize one to call property setters.
3260-
bool wantBody = (hasUnreferenceableStorage &&
3261-
!Impl.hasFinishedTypeChecking());
3262-
auto valueCtor = createValueConstructor(Impl, result, members,
3263-
/*want param names*/true,
3264-
/*want body*/wantBody);
3265-
if (!hasUnreferenceableStorage)
3266-
valueCtor->setIsMemberwiseInitializer();
3253+
}
32673254

3268-
ctors.push_back(valueCtor);
3269-
}
3255+
if (hasReferenceableFields && hasMemberwiseInitializer) {
3256+
// The default zero initializer suppresses the implicit value
3257+
// constructor that would normally be formed, so we have to add that
3258+
// explicitly as well.
3259+
//
3260+
// If we can completely represent the struct in SIL, leave the body
3261+
// implicit, otherwise synthesize one to call property setters.
3262+
bool wantBody = (hasUnreferenceableStorage &&
3263+
!Impl.hasFinishedTypeChecking());
3264+
auto valueCtor = createValueConstructor(Impl, result, members,
3265+
/*want param names*/true,
3266+
/*want body*/wantBody);
3267+
if (!hasUnreferenceableStorage)
3268+
valueCtor->setIsMemberwiseInitializer();
3269+
3270+
ctors.push_back(valueCtor);
32703271
}
32713272

32723273
for (auto member : members) {

lib/Sema/CodeSynthesis.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,7 @@ void TypeChecker::completePropertyBehaviorParameter(VarDecl *VD,
13971397

13981398
Parameter->setInterfaceType(SubstInterfaceTy);
13991399
Parameter->setGenericEnvironment(genericEnv);
1400+
Parameter->setValidationStarted();
14001401

14011402
// Mark the method to be final, implicit, and private. In a class, this
14021403
// prevents it from being dynamically dispatched.
@@ -1895,11 +1896,11 @@ void swift::maybeAddAccessorsToVariable(VarDecl *var, TypeChecker &TC) {
18951896
ConstructorDecl *swift::createImplicitConstructor(TypeChecker &tc,
18961897
NominalTypeDecl *decl,
18971898
ImplicitConstructorKind ICK) {
1899+
assert(!decl->hasClangNode());
1900+
18981901
ASTContext &context = tc.Context;
18991902
SourceLoc Loc = decl->getLoc();
19001903
auto accessLevel = AccessLevel::Internal;
1901-
if (decl->hasClangNode())
1902-
accessLevel = std::max(accessLevel, decl->getFormalAccess());
19031904

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

19771978
// Type-check the constructor declaration.
1978-
tc.typeCheckDecl(ctor, /*isFirstPass=*/true);
1979-
1980-
// If the struct in which this constructor is being added was imported,
1981-
// add it as an external definition.
1982-
if (decl->hasClangNode()) {
1983-
tc.Context.addExternalDecl(ctor);
1984-
}
1979+
tc.validateDecl(ctor);
19851980

19861981
return ctor;
19871982
}
@@ -2152,6 +2147,7 @@ swift::createDesignatedInitOverride(TypeChecker &tc,
21522147
// Wire up the overrides.
21532148
ctor->getAttrs().add(new (tc.Context) OverrideAttr(/*IsImplicit=*/true));
21542149
ctor->setOverriddenDecl(superclassCtor);
2150+
ctor->setValidationStarted();
21552151

21562152
if (kind == DesignatedInitKind::Stub) {
21572153
// Make this a stub implementation.

lib/Sema/DerivedConformanceCodable.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ static FuncDecl *deriveEncodable_encode(TypeChecker &tc, Decl *parentDecl,
768768
}
769769

770770
encodeDecl->setInterfaceType(interfaceType);
771+
encodeDecl->setValidationStarted();
771772
encodeDecl->setAccess(target->getFormalAccess());
772773

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

11111112
initDecl->setInterfaceType(interfaceType);
1113+
initDecl->setValidationStarted();
11121114
initDecl->setInitializerInterfaceType(initializerType);
11131115
initDecl->setAccess(target->getFormalAccess());
11141116

lib/Sema/DerivedConformanceCodingKey.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ static ValueDecl *deriveInitDecl(TypeChecker &tc, Decl *parentDecl,
181181
initDecl->setInterfaceType(allocIfaceType);
182182
initDecl->setInitializerInterfaceType(initIfaceType);
183183
initDecl->setAccess(enumDecl->getFormalAccess());
184+
initDecl->setValidationStarted();
184185

185186
// If the enum was not imported, the derived conformance is either from the
186187
// enum itself or an extension, in which case we will emit the declaration

lib/Sema/DerivedConformanceEquatableHashable.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ deriveEquatable_eq(TypeChecker &tc, Decl *parentDecl, NominalTypeDecl *typeDecl,
671671
}
672672
eqDecl->setInterfaceType(interfaceTy);
673673
eqDecl->copyFormalAccessAndVersionedAttrFrom(typeDecl);
674+
eqDecl->setValidationStarted();
674675

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

10641065
getterDecl->setInterfaceType(interfaceType);
1066+
getterDecl->setValidationStarted();
10651067
getterDecl->copyFormalAccessAndVersionedAttrFrom(typeDecl);
10661068

10671069
// If the enum was not imported, the derived conformance is either from the
@@ -1073,6 +1075,7 @@ deriveHashable_hashValue(TypeChecker &tc, Decl *parentDecl,
10731075
// Finish creating the property.
10741076
hashValueDecl->setImplicit();
10751077
hashValueDecl->setInterfaceType(intType);
1078+
hashValueDecl->setValidationStarted();
10761079
hashValueDecl->makeComputed(SourceLoc(), getterDecl,
10771080
nullptr, nullptr, SourceLoc());
10781081
hashValueDecl->copyFormalAccessAndVersionedAttrFrom(typeDecl);

lib/Sema/DerivedConformanceRawRepresentable.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ static ConstructorDecl *deriveRawRepresentable_init(TypeChecker &tc,
344344
initDecl->setInterfaceType(allocIfaceType);
345345
initDecl->setInitializerInterfaceType(initIfaceType);
346346
initDecl->copyFormalAccessAndVersionedAttrFrom(enumDecl);
347+
initDecl->setValidationStarted();
347348

348349
// If the enum was not imported, the derived conformance is either from the
349350
// enum itself or an extension, in which case we will emit the declaration

lib/Sema/DerivedConformances.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ DerivedConformance::declareDerivedPropertyGetter(TypeChecker &tc,
281281
FunctionType::ExtInfo());
282282
getterDecl->setInterfaceType(interfaceType);
283283
getterDecl->copyFormalAccessAndVersionedAttrFrom(property);
284+
getterDecl->setValidationStarted();
284285

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

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

0 commit comments

Comments
 (0)