Skip to content

Commit a511622

Browse files
authored
Merge pull request #27379 from slavapestov/circular-validation-cleanups-2
Sema: Remove unnecessary circularity breaks
2 parents 951c626 + 6702d38 commit a511622

35 files changed

+149
-238
lines changed

include/swift/AST/TypeCheckRequests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,7 @@ class UnderlyingTypeRequest :
12091209
bool isCached() const { return true; }
12101210
Optional<Type> getCachedResult() const;
12111211
void cacheResult(Type value) const;
1212+
void diagnoseCycle(DiagnosticEngine &diags) const;
12121213
};
12131214

12141215
class OperatorPrecedenceGroupRequest

lib/AST/ASTContext.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3407,8 +3407,6 @@ ProtocolType::ProtocolType(ProtocolDecl *TheDecl, Type Parent,
34073407
: NominalType(TypeKind::Protocol, &Ctx, TheDecl, Parent, properties) { }
34083408

34093409
LValueType *LValueType::get(Type objectTy) {
3410-
assert(!objectTy->hasError() &&
3411-
"cannot have ErrorType wrapped inside LValueType");
34123410
assert(!objectTy->is<LValueType>() && !objectTy->is<InOutType>() &&
34133411
"cannot have 'inout' or @lvalue wrapped inside an @lvalue");
34143412

lib/AST/Builtins.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ getBuiltinFunction(Identifier Id, ArrayRef<Type> argTypes, Type ResType,
162162
ParamDecl(ParamDecl::Specifier::Default, SourceLoc(), SourceLoc(),
163163
Identifier(), SourceLoc(), Identifier(), DC);
164164
PD->setInterfaceType(argType);
165-
PD->setValidationToChecked();
166165
PD->setImplicit();
167166
params.push_back(PD);
168167
}
@@ -179,7 +178,6 @@ getBuiltinFunction(Identifier Id, ArrayRef<Type> argTypes, Type ResType,
179178
paramList,
180179
TypeLoc::withoutLoc(ResType), DC);
181180
FD->computeType(Info);
182-
FD->setValidationToChecked();
183181
FD->setImplicit();
184182
FD->setAccess(AccessLevel::Public);
185183
return FD;
@@ -209,7 +207,6 @@ getBuiltinGenericFunction(Identifier Id,
209207
Identifier(), SourceLoc(),
210208
Identifier(), DC);
211209
PD->setInterfaceType(paramIfaceType);
212-
PD->setValidationToChecked();
213210
PD->setImplicit();
214211
params.push_back(PD);
215212
}
@@ -228,7 +225,6 @@ getBuiltinGenericFunction(Identifier Id,
228225

229226
func->setGenericSignature(Sig);
230227
func->computeType();
231-
func->setValidationToChecked();
232228
func->setImplicit();
233229
func->setAccess(AccessLevel::Public);
234230

lib/AST/Decl.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,6 @@ ParamDecl *PatternBindingInitializer::getImplicitSelfDecl() {
13611361
C.Id_self, this);
13621362
SelfParam->setImplicit();
13631363
SelfParam->setInterfaceType(DC->getSelfInterfaceType());
1364-
SelfParam->setValidationToChecked();
13651364
}
13661365
}
13671366

@@ -3864,7 +3863,6 @@ GetDestructorRequest::evaluate(Evaluator &evaluator, ClassDecl *CD) const {
38643863
auto *DD = new (ctx) DestructorDecl(CD->getLoc(), CD);
38653864

38663865
DD->setImplicit();
3867-
DD->setValidationToChecked();
38683866

38693867
// Synthesize an empty body for the destructor as needed.
38703868
DD->setBodySynthesizer(synthesizeEmptyFunctionBody);
@@ -6664,8 +6662,6 @@ void AbstractFunctionDecl::computeSelfDeclType() {
66646662
? ParamDecl::Specifier::InOut
66656663
: ParamDecl::Specifier::Default;
66666664
selfDecl->setSpecifier(specifier);
6667-
6668-
selfDecl->setValidationToChecked();
66696665
}
66706666

66716667
void AbstractFunctionDecl::setParameters(ParameterList *BodyParams) {

lib/AST/Module.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ void BuiltinUnit::LookupCache::lookupValue(
103103
const_cast<BuiltinUnit*>(&M));
104104
TAD->setUnderlyingType(Ty);
105105
TAD->setAccess(AccessLevel::Public);
106-
TAD->setValidationToChecked();
107106
TAD->computeType();
108107
Entry = TAD;
109108
}
@@ -399,9 +398,6 @@ ModuleDecl::ModuleDecl(Identifier name, ASTContext &ctx)
399398
setImplicit();
400399
setInterfaceType(ModuleType::get(this));
401400

402-
// validateDecl() should return immediately given a ModuleDecl.
403-
setValidationToChecked();
404-
405401
setAccess(AccessLevel::Public);
406402
}
407403

lib/AST/TypeCheckRequests.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "swift/AST/ASTContext.h"
1313
#include "swift/AST/Decl.h"
1414
#include "swift/AST/DiagnosticsCommon.h"
15+
#include "swift/AST/DiagnosticsSema.h"
1516
#include "swift/AST/Module.h"
1617
#include "swift/AST/NameLookup.h"
1718
#include "swift/AST/PropertyWrappers.h"
@@ -855,6 +856,13 @@ void UnderlyingTypeRequest::cacheResult(Type value) const {
855856
typeAlias->UnderlyingTy.setType(value);
856857
}
857858

859+
void UnderlyingTypeRequest::diagnoseCycle(DiagnosticEngine &diags) const {
860+
auto aliasDecl = std::get<0>(getStorage());
861+
diags.diagnose(aliasDecl, diag::recursive_decl_reference,
862+
aliasDecl->getDescriptiveKind(),
863+
aliasDecl->getName());
864+
}
865+
858866
//----------------------------------------------------------------------------//
859867
// EnumRawValuesRequest computation.
860868
//----------------------------------------------------------------------------//

lib/ClangImporter/ImportDecl.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ createVarWithPattern(ASTContext &ctx, DeclContext *dc, Identifier name, Type ty,
137137
if (isImplicit)
138138
var->setImplicit();
139139
var->setInterfaceType(ty);
140-
var->setValidationToChecked();
141140
var->setAccess(access);
142141
var->setSetterAccess(setterAccess);
143142

@@ -528,7 +527,6 @@ makeEnumRawValueConstructor(ClangImporter::Implementation &Impl,
528527
SourceLoc(), C.Id_rawValue,
529528
enumDecl);
530529
param->setInterfaceType(rawTy);
531-
param->setValidationToChecked();
532530

533531
auto paramPL = ParameterList::createWithoutLoc(param);
534532

@@ -543,7 +541,6 @@ makeEnumRawValueConstructor(ClangImporter::Implementation &Impl,
543541
ctorDecl->setAccess(AccessLevel::Public);
544542

545543
ctorDecl->computeType();
546-
ctorDecl->setValidationToChecked();
547544
ctorDecl->setBodySynthesizer(synthesizeEnumRawValueConstructorBody, enumDecl);
548545
return ctorDecl;
549546
}
@@ -620,7 +617,6 @@ static void makeEnumRawValueGetter(ClangImporter::Implementation &Impl,
620617
getterDecl->setIsTransparent(false);
621618

622619
getterDecl->computeType();
623-
getterDecl->setValidationToChecked();
624620

625621
getterDecl->setAccess(AccessLevel::Public);
626622
getterDecl->setBodySynthesizer(synthesizeEnumRawValueGetterBody, enumDecl);
@@ -702,7 +698,6 @@ static AccessorDecl *makeStructRawValueGetter(
702698
getterDecl->setIsTransparent(false);
703699

704700
getterDecl->computeType();
705-
getterDecl->setValidationToChecked();
706701

707702
getterDecl->setAccess(AccessLevel::Public);
708703
getterDecl->setBodySynthesizer(synthesizeStructRawValueGetterBody, storedVar);
@@ -734,7 +729,6 @@ static AccessorDecl *makeFieldGetterDecl(ClangImporter::Implementation &Impl,
734729
getterDecl->setIsDynamic(false);
735730

736731
getterDecl->computeType();
737-
getterDecl->setValidationToChecked();
738732

739733
return getterDecl;
740734
}
@@ -771,7 +765,6 @@ static AccessorDecl *makeFieldSetterDecl(ClangImporter::Implementation &Impl,
771765
setterDecl->setAccess(AccessLevel::Public);
772766

773767
setterDecl->computeType();
774-
setterDecl->setValidationToChecked();
775768

776769
return setterDecl;
777770
}
@@ -1316,7 +1309,6 @@ createDefaultConstructor(ClangImporter::Implementation &Impl,
13161309

13171310
// Set the constructor's type.
13181311
constructor->computeType();
1319-
constructor->setValidationToChecked();
13201312

13211313
constructor->setAccess(AccessLevel::Public);
13221314

@@ -1429,7 +1421,6 @@ createValueConstructor(ClangImporter::Implementation &Impl,
14291421
ParamDecl(ParamDecl::Specifier::Default, SourceLoc(), SourceLoc(), argName,
14301422
SourceLoc(), var->getName(), structDecl);
14311423
param->setInterfaceType(var->getInterfaceType());
1432-
param->setValidationToChecked();
14331424
Impl.recordImplicitUnwrapForDecl(param, var->isImplicitlyUnwrappedOptional());
14341425
valueParameters.push_back(param);
14351426
}
@@ -1446,7 +1437,6 @@ createValueConstructor(ClangImporter::Implementation &Impl,
14461437

14471438
// Set the constructor's type.
14481439
constructor->computeType();
1449-
constructor->setValidationToChecked();
14501440

14511441
constructor->setAccess(AccessLevel::Public);
14521442

@@ -1488,7 +1478,6 @@ static void addSynthesizedTypealias(NominalTypeDecl *nominal, Identifier name,
14881478
nullptr, nominal);
14891479
typealias->setUnderlyingType(underlyingType);
14901480
typealias->setAccess(AccessLevel::Public);
1491-
typealias->setValidationToChecked();
14921481
typealias->setImplicit();
14931482
typealias->computeType();
14941483

@@ -1664,7 +1653,6 @@ static void makeStructRawValuedWithBridge(
16641653
computedVar->setImplicit();
16651654
computedVar->setAccess(AccessLevel::Public);
16661655
computedVar->setSetterAccess(AccessLevel::Private);
1667-
computedVar->setValidationToChecked();
16681656

16691657
// Create the getter for the computed value variable.
16701658
auto computedVarGetter = makeStructRawValueGetter(
@@ -1727,7 +1715,6 @@ buildSubscriptGetterDecl(ClangImporter::Implementation &Impl,
17271715

17281716
thunk->setGenericSignature(dc->getGenericSignatureOfContext());
17291717
thunk->computeType();
1730-
thunk->setValidationToChecked();
17311718

17321719
thunk->setAccess(getOverridableAccessLevel(dc));
17331720

@@ -1762,7 +1749,6 @@ buildSubscriptSetterDecl(ClangImporter::Implementation &Impl,
17621749
new (C) ParamDecl(ParamDecl::Specifier::Default, SourceLoc(), SourceLoc(),
17631750
Identifier(), loc, valueIndex->get(0)->getName(), dc);
17641751
paramVarDecl->setInterfaceType(elementInterfaceTy);
1765-
paramVarDecl->setValidationToChecked();
17661752

17671753
auto valueIndicesPL = ParameterList::create(C, {paramVarDecl, index});
17681754

@@ -1782,7 +1768,6 @@ buildSubscriptSetterDecl(ClangImporter::Implementation &Impl,
17821768
setter->getClangNode());
17831769
thunk->setGenericSignature(dc->getGenericSignatureOfContext());
17841770
thunk->computeType();
1785-
thunk->setValidationToChecked();
17861771

17871772
thunk->setAccess(getOverridableAccessLevel(dc));
17881773

@@ -1951,7 +1936,6 @@ static bool addErrorDomain(NominalTypeDecl *swiftDecl,
19511936
/*IsStatic*/isStatic, VarDecl::Introducer::Var, /*IsCaptureList*/false,
19521937
SourceLoc(), C.Id_errorDomain, swiftDecl);
19531938
errorDomainPropertyDecl->setInterfaceType(stringTy);
1954-
errorDomainPropertyDecl->setValidationToChecked();
19551939
errorDomainPropertyDecl->setAccess(AccessLevel::Public);
19561940

19571941
auto *params = ParameterList::createEmpty(C);
@@ -1970,7 +1954,6 @@ static bool addErrorDomain(NominalTypeDecl *swiftDecl,
19701954
TypeLoc::withoutLoc(stringTy), swiftDecl);
19711955
getterDecl->setStatic(isStatic);
19721956
getterDecl->computeType();
1973-
getterDecl->setValidationToChecked();
19741957
getterDecl->setIsObjC(false);
19751958
getterDecl->setIsDynamic(false);
19761959
getterDecl->setIsTransparent(false);
@@ -2561,7 +2544,6 @@ namespace {
25612544
/*genericparams*/nullptr, DC);
25622545
typealias->setUnderlyingType(
25632546
underlying->getDeclaredInterfaceType());
2564-
typealias->setValidationToChecked();
25652547
typealias->computeType();
25662548

25672549
Impl.SpecialTypedefNames[Decl->getCanonicalDecl()] =
@@ -2582,7 +2564,6 @@ namespace {
25822564
/*genericparams*/nullptr, DC);
25832565
typealias->setUnderlyingType(
25842566
Impl.SwiftContext.getAnyObjectType());
2585-
typealias->setValidationToChecked();
25862567
typealias->computeType();
25872568

25882569
Impl.SpecialTypedefNames[Decl->getCanonicalDecl()] =
@@ -2651,7 +2632,6 @@ namespace {
26512632
Loc,
26522633
/*genericparams*/nullptr, DC);
26532634
Result->setUnderlyingType(SwiftType);
2654-
Result->setValidationToChecked();
26552635
Result->computeType();
26562636

26572637
// Make Objective-C's 'id' unavailable.
@@ -2805,7 +2785,6 @@ namespace {
28052785
// Create the wrapper struct.
28062786
errorWrapper = new (C) StructDecl(loc, name, loc, None, nullptr, dc);
28072787
errorWrapper->computeType();
2808-
errorWrapper->setValidationToChecked();
28092788
errorWrapper->setAddedImplicitInitializers();
28102789
errorWrapper->setAccess(AccessLevel::Public);
28112790
errorWrapper->getAttrs().add(
@@ -2840,7 +2819,6 @@ namespace {
28402819
nsErrorProp->setImplicit();
28412820
nsErrorProp->setAccess(AccessLevel::Public);
28422821
nsErrorProp->setInterfaceType(nsErrorType);
2843-
nsErrorProp->setValidationToChecked();
28442822

28452823
// Create a pattern binding to describe the variable.
28462824
Pattern *nsErrorPattern = createTypedNamedPattern(nsErrorProp);
@@ -2918,7 +2896,6 @@ namespace {
29182896
rawValue->setAccess(AccessLevel::Public);
29192897
rawValue->setSetterAccess(AccessLevel::Private);
29202898
rawValue->setInterfaceType(underlyingType);
2921-
rawValue->setValidationToChecked();
29222899

29232900
// Create a pattern binding to describe the variable.
29242901
Pattern *varPattern = createTypedNamedPattern(rawValue);
@@ -2947,7 +2924,6 @@ namespace {
29472924
C.Id_ErrorType, loc,
29482925
/*genericparams=*/nullptr, enumDecl);
29492926
alias->setUnderlyingType(errorWrapper->getDeclaredInterfaceType());
2950-
alias->setValidationToChecked();
29512927
alias->computeType();
29522928
enumDecl->addMember(alias);
29532929

@@ -3775,7 +3751,6 @@ namespace {
37753751
result->setIsObjC(false);
37763752
result->setIsDynamic(false);
37773753
result->computeType();
3778-
result->setValidationToChecked();
37793754

37803755
Impl.recordImplicitUnwrapForDecl(result,
37813756
importedType.isImplicitlyUnwrapped());
@@ -4033,7 +4008,6 @@ namespace {
40334008
Loc,
40344009
/*genericparams*/nullptr, DC);
40354010
Result->setUnderlyingType(SwiftTypeDecl->getDeclaredInterfaceType());
4036-
Result->setValidationToChecked();
40374011
Result->computeType();
40384012

40394013
return Result;
@@ -4364,7 +4338,6 @@ namespace {
43644338

43654339
// Compute the interface type.
43664340
result->computeType();
4367-
result->setValidationToChecked();
43684341

43694342
Impl.recordImplicitUnwrapForDecl(result, isIUO);
43704343

@@ -4572,7 +4545,6 @@ namespace {
45724545
SmallVector<TypeLoc, 4> inheritedTypes;
45734546
importObjCProtocols(result, decl->getReferencedProtocols(),
45744547
inheritedTypes);
4575-
result->setValidationToChecked();
45764548
result->setInherited(Impl.SwiftContext.AllocateCopy(inheritedTypes));
45774549
result->setMemberLoader(&Impl, 0);
45784550

@@ -5169,7 +5141,6 @@ namespace {
51695141
}
51705142

51715143
typealias->setUnderlyingType(typeDecl->getDeclaredInterfaceType());
5172-
typealias->setValidationToChecked();
51735144
typealias->computeType();
51745145
return typealias;
51755146
}
@@ -5406,7 +5377,6 @@ Decl *SwiftDeclConverter::importCompatibilityTypeAlias(
54065377
}
54075378

54085379
alias->setUnderlyingType(typeDecl->getDeclaredInterfaceType());
5409-
alias->setValidationToChecked();
54105380
alias->computeType();
54115381

54125382
// Record that this is the official version of this declaration.
@@ -5816,7 +5786,6 @@ Decl *SwiftDeclConverter::importGlobalAsInitializer(
58165786
ParamDecl::Specifier::Default, SourceLoc(), SourceLoc(), argNames.front(),
58175787
SourceLoc(), argNames.front(), dc);
58185788
paramDecl->setInterfaceType(Impl.SwiftContext.TheEmptyTupleType);
5819-
paramDecl->setValidationToChecked();
58205789

58215790
parameterList = ParameterList::createWithoutLoc(paramDecl);
58225791
} else {
@@ -8138,7 +8107,6 @@ ClangImporter::Implementation::importDeclContextOf(
81388107
nominal->getDeclaredType());
81398108
SwiftContext.evaluator.cacheOutput(ExtendedNominalRequest{ext},
81408109
std::move(nominal));
8141-
ext->setValidationToChecked();
81428110
ext->setMemberLoader(this, reinterpret_cast<uintptr_t>(declSubmodule));
81438111

81448112
if (auto protoDecl = ext->getExtendedProtocolDecl()) {
@@ -8384,7 +8352,6 @@ ClangImporter::Implementation::createConstant(Identifier name, DeclContext *dc,
83848352
var = new (SwiftContext)
83858353
VarDecl(/*IsStatic*/isStatic, VarDecl::Introducer::Var,
83868354
/*IsCaptureList*/false, SourceLoc(), name, dc);
8387-
var->setValidationToChecked();
83888355
}
83898356

83908357
var->setInterfaceType(type);
@@ -8409,7 +8376,6 @@ ClangImporter::Implementation::createConstant(Identifier name, DeclContext *dc,
84098376
func->setStatic(isStatic);
84108377
func->computeType();
84118378
func->setAccess(getOverridableAccessLevel(dc));
8412-
func->setValidationToChecked();
84138379
func->setIsObjC(false);
84148380
func->setIsDynamic(false);
84158381

lib/ClangImporter/ImporterImpl.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,8 +1234,6 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
12341234
D->setAccess(access);
12351235
if (auto ASD = dyn_cast<AbstractStorageDecl>(D))
12361236
ASD->setSetterAccess(access);
1237-
// All imported decls are constructed fully validated.
1238-
D->setValidationToChecked();
12391237
if (auto AFD = dyn_cast<AbstractFunctionDecl>(static_cast<Decl *>(D)))
12401238
AFD->setNeedsNewVTableEntry(false);
12411239
return D;

0 commit comments

Comments
 (0)