Skip to content

Commit 0ece008

Browse files
authored
Merge pull request #23109 from davezarzycki/revert_gsb_opt
Revert gsb opt
2 parents f6aaf8a + 236a0dc commit 0ece008

File tree

2 files changed

+15
-49
lines changed

2 files changed

+15
-49
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -935,11 +935,6 @@ class GenericSignatureBuilder::RequirementSource final
935935
AssociatedTypeDecl,
936936
};
937937

938-
/// Cache DependentMemberType results instead of calling
939-
/// DependentMemberType::get(). The much smaller hash table is more
940-
/// processor cache efficient.
941-
mutable llvm::DenseMap<Type, Type> ReplacedSelfCache;
942-
943938
/// The kind of storage we have.
944939
const StorageKind storageKind;
945940

@@ -959,9 +954,8 @@ class GenericSignatureBuilder::RequirementSource final
959954
/// A protocol conformance used to satisfy the requirement.
960955
void *conformance;
961956

962-
/// A precomputed dependent member of an associated type to which a
963-
/// requirement is being applied.
964-
DependentMemberType *dependentMember;
957+
/// An associated type to which a requirement is being applied.
958+
AssociatedTypeDecl *assocType;
965959
} storage;
966960

967961
friend TrailingObjects;
@@ -1099,8 +1093,7 @@ class GenericSignatureBuilder::RequirementSource final
10991093
assert(isAcceptableStorageKind(kind, storageKind) &&
11001094
"RequirementSource kind/storageKind mismatch");
11011095

1102-
auto ty = assocType->getDeclaredInterfaceType();
1103-
storage.dependentMember = cast<DependentMemberType>(ty.getPointer());
1096+
storage.assocType = assocType;
11041097
}
11051098

11061099
RequirementSource(Kind kind, const RequirementSource *parent)
@@ -1322,18 +1315,11 @@ class GenericSignatureBuilder::RequirementSource final
13221315
return ProtocolConformanceRef::getFromOpaqueValue(storage.conformance);
13231316
}
13241317

1325-
/// Retrieve the precomputed dependent member for the associated type
1326-
/// declaration for this requirement, if there is one.
1327-
DependentMemberType *getDependentMember() const {
1328-
if (storageKind != StorageKind::AssociatedTypeDecl) return nullptr;
1329-
return storage.dependentMember;
1330-
}
1331-
13321318
/// Retrieve the associated type declaration for this requirement, if there
13331319
/// is one.
13341320
AssociatedTypeDecl *getAssociatedType() const {
13351321
if (storageKind != StorageKind::AssociatedTypeDecl) return nullptr;
1336-
return storage.dependentMember->getAssocType();
1322+
return storage.assocType;
13371323
}
13381324

13391325
/// Profiling support for \c FoldingSet.
@@ -1572,11 +1558,6 @@ class GenericSignatureBuilder::PotentialArchetype {
15721558
/// that share a name.
15731559
llvm::MapVector<Identifier, StoredNestedType> NestedTypes;
15741560

1575-
/// Cache DependentMemberType results instead of calling
1576-
/// DependentMemberType::get(). The much smaller hash table is more
1577-
/// processor cache efficient.
1578-
mutable llvm::DenseMap<Type, DependentMemberType*> CachedDMTs;
1579-
15801561
/// Construct a new potential archetype for a concrete declaration.
15811562
PotentialArchetype(PotentialArchetype *parent, AssociatedTypeDecl *assocType)
15821563
: parentOrContext(parent), identifier(assocType) {
@@ -1616,14 +1597,6 @@ class GenericSignatureBuilder::PotentialArchetype {
16161597
return identifier.assocType;
16171598
}
16181599

1619-
/// Retrieve the type declaration to which this nested type was resolved.
1620-
DependentMemberType *getResolvedDependentMemberType(Type Parent) const {
1621-
auto *&known = CachedDMTs[Parent];
1622-
if (!known)
1623-
known = DependentMemberType::get(Parent, getResolvedType());
1624-
return known;
1625-
}
1626-
16271600
/// Determine whether this is a generic parameter.
16281601
bool isGenericParam() const {
16291602
return parentOrContext.is<ASTContext *>();

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ const void *RequirementSource::getOpaqueStorage1() const {
818818
return storage.type;
819819

820820
case StorageKind::AssociatedTypeDecl:
821-
return storage.dependentMember;
821+
return storage.assocType;
822822
}
823823

824824
llvm_unreachable("Unhandled StorageKind in switch.");
@@ -918,16 +918,11 @@ bool RequirementSource::isSelfDerivedSource(GenericSignatureBuilder &builder,
918918
/// the nested type. This limited operation makes sure that it does not
919919
/// create any new potential archetypes along the way, so it should only be
920920
/// used in cases where we're reconstructing something that we know exists.
921-
static Type replaceSelfWithType(llvm::DenseMap<Type, Type> &cache,
922-
Type selfType, Type depTy) {
921+
static Type replaceSelfWithType(Type selfType, Type depTy) {
923922
if (auto depMemTy = depTy->getAs<DependentMemberType>()) {
924-
Type baseType = replaceSelfWithType(cache, selfType, depMemTy->getBase());
923+
Type baseType = replaceSelfWithType(selfType, depMemTy->getBase());
925924
assert(depMemTy->getAssocType() && "Missing associated type");
926-
auto &known = cache[baseType];
927-
if (!known) {
928-
known = DependentMemberType::get(baseType, depMemTy->getAssocType());
929-
}
930-
return known;
925+
return DependentMemberType::get(baseType, depMemTy->getAssocType());
931926
}
932927

933928
assert(depTy->is<GenericTypeParamType>() && "missing Self?");
@@ -1371,8 +1366,8 @@ RequirementSource::visitPotentialArchetypesAlongPath(
13711366

13721367
if (visitor(parentType, this)) return nullptr;
13731368

1374-
return replaceSelfWithType(ReplacedSelfCache,
1375-
parentType, getDependentMember());
1369+
return replaceSelfWithType(parentType,
1370+
getAssociatedType()->getDeclaredInterfaceType());
13761371
}
13771372

13781373
case RequirementSource::NestedTypeNameMatch:
@@ -1407,8 +1402,7 @@ RequirementSource::visitPotentialArchetypesAlongPath(
14071402

14081403
if (visitor(parentType, this)) return nullptr;
14091404

1410-
return replaceSelfWithType(ReplacedSelfCache,
1411-
parentType, getStoredType());
1405+
return replaceSelfWithType(parentType, getStoredType());
14121406
}
14131407
}
14141408
llvm_unreachable("unhandled kind");
@@ -1442,7 +1436,7 @@ ProtocolDecl *RequirementSource::getProtocolDecl() const {
14421436
return getProtocolConformance().getRequirement();
14431437

14441438
case StorageKind::AssociatedTypeDecl:
1445-
return storage.dependentMember->getAssocType()->getProtocol();
1439+
return storage.assocType->getProtocol();
14461440
}
14471441

14481442
llvm_unreachable("Unhandled StorageKind in switch.");
@@ -1613,9 +1607,8 @@ void RequirementSource::print(llvm::raw_ostream &out,
16131607
}
16141608

16151609
case StorageKind::AssociatedTypeDecl:
1616-
auto assocType = storage.dependentMember->getAssocType();
1617-
out << " (" << assocType->getProtocol()->getName()
1618-
<< "::" << assocType->getName() << ")";
1610+
out << " (" << storage.assocType->getProtocol()->getName()
1611+
<< "::" << storage.assocType->getName() << ")";
16191612
break;
16201613
}
16211614

@@ -2940,7 +2933,7 @@ Type GenericSignatureBuilder::PotentialArchetype::getDependentType(
29402933
if (parentType->hasError())
29412934
return parentType;
29422935

2943-
return getResolvedDependentMemberType(parentType);
2936+
return DependentMemberType::get(parentType, getResolvedType());
29442937
}
29452938

29462939
assert(isGenericParam() && "Not a generic parameter?");

0 commit comments

Comments
 (0)