Skip to content

Commit 18aa710

Browse files
committed
Eliminate some pointless uses of the doomed DeclContext::getSelfTypeInContext()
1 parent 6fffae7 commit 18aa710

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,13 +1331,7 @@ void TypeChecker::completePropertyBehaviorParameter(VarDecl *VD,
13311331
// Borrow the parameters from the requirement declaration.
13321332
SmallVector<ParameterList *, 2> ParamLists;
13331333
if (DC->isTypeContext()) {
1334-
auto self = new (Context) ParamDecl(/*let*/ true, SourceLoc(), SourceLoc(),
1335-
Identifier(), SourceLoc(),
1336-
Context.Id_self,
1337-
DC->getSelfTypeInContext(), DC);
1338-
self->setInterfaceType(DC->getSelfInterfaceType());
1339-
self->setImplicit();
1340-
1334+
auto self = ParamDecl::createSelf(SourceLoc(), DC);
13411335
ParamLists.push_back(ParameterList::create(Context, SourceLoc(),
13421336
self, SourceLoc()));
13431337
ParamLists.back()->get(0)->setImplicit();

lib/Sema/TypeCheckDecl.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4616,14 +4616,18 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
46164616
if (!selfNominal) return;
46174617

46184618
// Check the parameters for a reference to 'Self'.
4619+
auto genericEnv = FD->getGenericEnvironment();
46194620
bool isProtocol = isa<ProtocolDecl>(selfNominal);
46204621
for (auto param : *FD->getParameterList(1)) {
46214622
auto paramType = param->getType();
46224623
if (!paramType) break;
46234624

46244625
// Look through 'inout'.
46254626
paramType = paramType->getInOutObjectType();
4626-
4627+
if (genericEnv) {
4628+
paramType = genericEnv->mapTypeOutOfContext(FD->getModuleContext(),
4629+
paramType);
4630+
}
46274631
// Look through a metatype reference, if there is one.
46284632
if (auto metatypeType = paramType->getAs<AnyMetatypeType>())
46294633
paramType = metatypeType->getInstanceType();
@@ -4636,11 +4640,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
46364640
if (auto genericParam = paramType->getAs<GenericTypeParamType>())
46374641
if (genericParam->isEqual(DC->getSelfInterfaceType()))
46384642
return;
4639-
4640-
// ... or the 'Self' archetype?
4641-
if (auto archetype = paramType->getAs<ArchetypeType>())
4642-
if (archetype->isEqual(DC->getSelfTypeInContext()))
4643-
return;
46444643
}
46454644
}
46464645

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2392,7 +2392,7 @@ static void diagnoseNoWitness(ValueDecl *Requirement, Type RequirementType,
23922392
Options.AccessibilityFilter = Accessibility::Private;
23932393
Options.PrintAccessibility = false;
23942394
Options.FunctionBody = [](const ValueDecl *VD) { return "<#code#>"; };
2395-
Options.setBaseType(Adopter->getSelfTypeInContext());
2395+
Options.setBaseType(Conformance->getType());
23962396
Options.CurrentModule = Adopter->getParentModule();
23972397
if (!Adopter->isExtensionContext()) {
23982398
// Create a variable declaration instead of a computed property in

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ resolveTopLevelIdentTypeComponent(TypeChecker &TC, DeclContext *DC,
942942
// while the 'Self' type is more than just a reference to a TypeDecl.
943943

944944
return DynamicSelfType::get(
945-
func->getDeclContext()->getSelfTypeInContext(),
945+
func->computeSelfType()->getRValueInstanceType(),
946946
TC.Context);
947947
}
948948

0 commit comments

Comments
 (0)