Skip to content

Sema: Remove unnecessary circularity breaks #27379

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
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
1 change: 1 addition & 0 deletions include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,7 @@ class UnderlyingTypeRequest :
bool isCached() const { return true; }
Optional<Type> getCachedResult() const;
void cacheResult(Type value) const;
void diagnoseCycle(DiagnosticEngine &diags) const;
};

class OperatorPrecedenceGroupRequest
Expand Down
2 changes: 0 additions & 2 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3407,8 +3407,6 @@ ProtocolType::ProtocolType(ProtocolDecl *TheDecl, Type Parent,
: NominalType(TypeKind::Protocol, &Ctx, TheDecl, Parent, properties) { }

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

Expand Down
4 changes: 0 additions & 4 deletions lib/AST/Builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ getBuiltinFunction(Identifier Id, ArrayRef<Type> argTypes, Type ResType,
ParamDecl(ParamDecl::Specifier::Default, SourceLoc(), SourceLoc(),
Identifier(), SourceLoc(), Identifier(), DC);
PD->setInterfaceType(argType);
PD->setValidationToChecked();
PD->setImplicit();
params.push_back(PD);
}
Expand All @@ -179,7 +178,6 @@ getBuiltinFunction(Identifier Id, ArrayRef<Type> argTypes, Type ResType,
paramList,
TypeLoc::withoutLoc(ResType), DC);
FD->computeType(Info);
FD->setValidationToChecked();
FD->setImplicit();
FD->setAccess(AccessLevel::Public);
return FD;
Expand Down Expand Up @@ -209,7 +207,6 @@ getBuiltinGenericFunction(Identifier Id,
Identifier(), SourceLoc(),
Identifier(), DC);
PD->setInterfaceType(paramIfaceType);
PD->setValidationToChecked();
PD->setImplicit();
params.push_back(PD);
}
Expand All @@ -228,7 +225,6 @@ getBuiltinGenericFunction(Identifier Id,

func->setGenericSignature(Sig);
func->computeType();
func->setValidationToChecked();
func->setImplicit();
func->setAccess(AccessLevel::Public);

Expand Down
4 changes: 0 additions & 4 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,6 @@ ParamDecl *PatternBindingInitializer::getImplicitSelfDecl() {
C.Id_self, this);
SelfParam->setImplicit();
SelfParam->setInterfaceType(DC->getSelfInterfaceType());
SelfParam->setValidationToChecked();
}
}

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

DD->setImplicit();
DD->setValidationToChecked();

// Synthesize an empty body for the destructor as needed.
DD->setBodySynthesizer(synthesizeEmptyFunctionBody);
Expand Down Expand Up @@ -6664,8 +6662,6 @@ void AbstractFunctionDecl::computeSelfDeclType() {
? ParamDecl::Specifier::InOut
: ParamDecl::Specifier::Default;
selfDecl->setSpecifier(specifier);

selfDecl->setValidationToChecked();
}

void AbstractFunctionDecl::setParameters(ParameterList *BodyParams) {
Expand Down
4 changes: 0 additions & 4 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ void BuiltinUnit::LookupCache::lookupValue(
const_cast<BuiltinUnit*>(&M));
TAD->setUnderlyingType(Ty);
TAD->setAccess(AccessLevel::Public);
TAD->setValidationToChecked();
TAD->computeType();
Entry = TAD;
}
Expand Down Expand Up @@ -399,9 +398,6 @@ ModuleDecl::ModuleDecl(Identifier name, ASTContext &ctx)
setImplicit();
setInterfaceType(ModuleType::get(this));

// validateDecl() should return immediately given a ModuleDecl.
setValidationToChecked();

setAccess(AccessLevel::Public);
}

Expand Down
8 changes: 8 additions & 0 deletions lib/AST/TypeCheckRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "swift/AST/ASTContext.h"
#include "swift/AST/Decl.h"
#include "swift/AST/DiagnosticsCommon.h"
#include "swift/AST/DiagnosticsSema.h"
#include "swift/AST/Module.h"
#include "swift/AST/NameLookup.h"
#include "swift/AST/PropertyWrappers.h"
Expand Down Expand Up @@ -855,6 +856,13 @@ void UnderlyingTypeRequest::cacheResult(Type value) const {
typeAlias->UnderlyingTy.setType(value);
}

void UnderlyingTypeRequest::diagnoseCycle(DiagnosticEngine &diags) const {
auto aliasDecl = std::get<0>(getStorage());
diags.diagnose(aliasDecl, diag::recursive_decl_reference,
aliasDecl->getDescriptiveKind(),
aliasDecl->getName());
}

//----------------------------------------------------------------------------//
// EnumRawValuesRequest computation.
//----------------------------------------------------------------------------//
Expand Down
34 changes: 0 additions & 34 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ createVarWithPattern(ASTContext &ctx, DeclContext *dc, Identifier name, Type ty,
if (isImplicit)
var->setImplicit();
var->setInterfaceType(ty);
var->setValidationToChecked();
var->setAccess(access);
var->setSetterAccess(setterAccess);

Expand Down Expand Up @@ -528,7 +527,6 @@ makeEnumRawValueConstructor(ClangImporter::Implementation &Impl,
SourceLoc(), C.Id_rawValue,
enumDecl);
param->setInterfaceType(rawTy);
param->setValidationToChecked();

auto paramPL = ParameterList::createWithoutLoc(param);

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

ctorDecl->computeType();
ctorDecl->setValidationToChecked();
ctorDecl->setBodySynthesizer(synthesizeEnumRawValueConstructorBody, enumDecl);
return ctorDecl;
}
Expand Down Expand Up @@ -620,7 +617,6 @@ static void makeEnumRawValueGetter(ClangImporter::Implementation &Impl,
getterDecl->setIsTransparent(false);

getterDecl->computeType();
getterDecl->setValidationToChecked();

getterDecl->setAccess(AccessLevel::Public);
getterDecl->setBodySynthesizer(synthesizeEnumRawValueGetterBody, enumDecl);
Expand Down Expand Up @@ -702,7 +698,6 @@ static AccessorDecl *makeStructRawValueGetter(
getterDecl->setIsTransparent(false);

getterDecl->computeType();
getterDecl->setValidationToChecked();

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

getterDecl->computeType();
getterDecl->setValidationToChecked();

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

setterDecl->computeType();
setterDecl->setValidationToChecked();

return setterDecl;
}
Expand Down Expand Up @@ -1316,7 +1309,6 @@ createDefaultConstructor(ClangImporter::Implementation &Impl,

// Set the constructor's type.
constructor->computeType();
constructor->setValidationToChecked();

constructor->setAccess(AccessLevel::Public);

Expand Down Expand Up @@ -1429,7 +1421,6 @@ createValueConstructor(ClangImporter::Implementation &Impl,
ParamDecl(ParamDecl::Specifier::Default, SourceLoc(), SourceLoc(), argName,
SourceLoc(), var->getName(), structDecl);
param->setInterfaceType(var->getInterfaceType());
param->setValidationToChecked();
Impl.recordImplicitUnwrapForDecl(param, var->isImplicitlyUnwrappedOptional());
valueParameters.push_back(param);
}
Expand All @@ -1446,7 +1437,6 @@ createValueConstructor(ClangImporter::Implementation &Impl,

// Set the constructor's type.
constructor->computeType();
constructor->setValidationToChecked();

constructor->setAccess(AccessLevel::Public);

Expand Down Expand Up @@ -1488,7 +1478,6 @@ static void addSynthesizedTypealias(NominalTypeDecl *nominal, Identifier name,
nullptr, nominal);
typealias->setUnderlyingType(underlyingType);
typealias->setAccess(AccessLevel::Public);
typealias->setValidationToChecked();
typealias->setImplicit();
typealias->computeType();

Expand Down Expand Up @@ -1664,7 +1653,6 @@ static void makeStructRawValuedWithBridge(
computedVar->setImplicit();
computedVar->setAccess(AccessLevel::Public);
computedVar->setSetterAccess(AccessLevel::Private);
computedVar->setValidationToChecked();

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

thunk->setGenericSignature(dc->getGenericSignatureOfContext());
thunk->computeType();
thunk->setValidationToChecked();

thunk->setAccess(getOverridableAccessLevel(dc));

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

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

Expand All @@ -1782,7 +1768,6 @@ buildSubscriptSetterDecl(ClangImporter::Implementation &Impl,
setter->getClangNode());
thunk->setGenericSignature(dc->getGenericSignatureOfContext());
thunk->computeType();
thunk->setValidationToChecked();

thunk->setAccess(getOverridableAccessLevel(dc));

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

auto *params = ParameterList::createEmpty(C);
Expand All @@ -1970,7 +1954,6 @@ static bool addErrorDomain(NominalTypeDecl *swiftDecl,
TypeLoc::withoutLoc(stringTy), swiftDecl);
getterDecl->setStatic(isStatic);
getterDecl->computeType();
getterDecl->setValidationToChecked();
getterDecl->setIsObjC(false);
getterDecl->setIsDynamic(false);
getterDecl->setIsTransparent(false);
Expand Down Expand Up @@ -2561,7 +2544,6 @@ namespace {
/*genericparams*/nullptr, DC);
typealias->setUnderlyingType(
underlying->getDeclaredInterfaceType());
typealias->setValidationToChecked();
typealias->computeType();

Impl.SpecialTypedefNames[Decl->getCanonicalDecl()] =
Expand All @@ -2582,7 +2564,6 @@ namespace {
/*genericparams*/nullptr, DC);
typealias->setUnderlyingType(
Impl.SwiftContext.getAnyObjectType());
typealias->setValidationToChecked();
typealias->computeType();

Impl.SpecialTypedefNames[Decl->getCanonicalDecl()] =
Expand Down Expand Up @@ -2651,7 +2632,6 @@ namespace {
Loc,
/*genericparams*/nullptr, DC);
Result->setUnderlyingType(SwiftType);
Result->setValidationToChecked();
Result->computeType();

// Make Objective-C's 'id' unavailable.
Expand Down Expand Up @@ -2805,7 +2785,6 @@ namespace {
// Create the wrapper struct.
errorWrapper = new (C) StructDecl(loc, name, loc, None, nullptr, dc);
errorWrapper->computeType();
errorWrapper->setValidationToChecked();
errorWrapper->setAddedImplicitInitializers();
errorWrapper->setAccess(AccessLevel::Public);
errorWrapper->getAttrs().add(
Expand Down Expand Up @@ -2840,7 +2819,6 @@ namespace {
nsErrorProp->setImplicit();
nsErrorProp->setAccess(AccessLevel::Public);
nsErrorProp->setInterfaceType(nsErrorType);
nsErrorProp->setValidationToChecked();

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

// Create a pattern binding to describe the variable.
Pattern *varPattern = createTypedNamedPattern(rawValue);
Expand Down Expand Up @@ -2947,7 +2924,6 @@ namespace {
C.Id_ErrorType, loc,
/*genericparams=*/nullptr, enumDecl);
alias->setUnderlyingType(errorWrapper->getDeclaredInterfaceType());
alias->setValidationToChecked();
alias->computeType();
enumDecl->addMember(alias);

Expand Down Expand Up @@ -3775,7 +3751,6 @@ namespace {
result->setIsObjC(false);
result->setIsDynamic(false);
result->computeType();
result->setValidationToChecked();

Impl.recordImplicitUnwrapForDecl(result,
importedType.isImplicitlyUnwrapped());
Expand Down Expand Up @@ -4033,7 +4008,6 @@ namespace {
Loc,
/*genericparams*/nullptr, DC);
Result->setUnderlyingType(SwiftTypeDecl->getDeclaredInterfaceType());
Result->setValidationToChecked();
Result->computeType();

return Result;
Expand Down Expand Up @@ -4364,7 +4338,6 @@ namespace {

// Compute the interface type.
result->computeType();
result->setValidationToChecked();

Impl.recordImplicitUnwrapForDecl(result, isIUO);

Expand Down Expand Up @@ -4572,7 +4545,6 @@ namespace {
SmallVector<TypeLoc, 4> inheritedTypes;
importObjCProtocols(result, decl->getReferencedProtocols(),
inheritedTypes);
result->setValidationToChecked();
result->setInherited(Impl.SwiftContext.AllocateCopy(inheritedTypes));
result->setMemberLoader(&Impl, 0);

Expand Down Expand Up @@ -5169,7 +5141,6 @@ namespace {
}

typealias->setUnderlyingType(typeDecl->getDeclaredInterfaceType());
typealias->setValidationToChecked();
typealias->computeType();
return typealias;
}
Expand Down Expand Up @@ -5406,7 +5377,6 @@ Decl *SwiftDeclConverter::importCompatibilityTypeAlias(
}

alias->setUnderlyingType(typeDecl->getDeclaredInterfaceType());
alias->setValidationToChecked();
alias->computeType();

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

parameterList = ParameterList::createWithoutLoc(paramDecl);
} else {
Expand Down Expand Up @@ -8138,7 +8107,6 @@ ClangImporter::Implementation::importDeclContextOf(
nominal->getDeclaredType());
SwiftContext.evaluator.cacheOutput(ExtendedNominalRequest{ext},
std::move(nominal));
ext->setValidationToChecked();
ext->setMemberLoader(this, reinterpret_cast<uintptr_t>(declSubmodule));

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

var->setInterfaceType(type);
Expand All @@ -8409,7 +8376,6 @@ ClangImporter::Implementation::createConstant(Identifier name, DeclContext *dc,
func->setStatic(isStatic);
func->computeType();
func->setAccess(getOverridableAccessLevel(dc));
func->setValidationToChecked();
func->setIsObjC(false);
func->setIsDynamic(false);

Expand Down
2 changes: 0 additions & 2 deletions lib/ClangImporter/ImporterImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1234,8 +1234,6 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
D->setAccess(access);
if (auto ASD = dyn_cast<AbstractStorageDecl>(D))
ASD->setSetterAccess(access);
// All imported decls are constructed fully validated.
D->setValidationToChecked();
if (auto AFD = dyn_cast<AbstractFunctionDecl>(static_cast<Decl *>(D)))
AFD->setNeedsNewVTableEntry(false);
return D;
Expand Down
Loading