@@ -134,7 +134,7 @@ struct ASTContext::Implementation {
134
134
// / The AnyObject type.
135
135
CanType AnyObjectType;
136
136
137
- #define KNOWN_STDLIB_TYPE_DECL (NAME, DECL_CLASS, NUM_GENERIC_PARAMS ) \
137
+ #define KNOWN_STDLIB_TYPE_DECL_WITH_NAME (NAME, IDSTR , DECL_CLASS, NUM_GENERIC_PARAMS ) \
138
138
/* * The declaration of Swift.NAME. */ \
139
139
DECL_CLASS *NAME##Decl = nullptr ;
140
140
#include " swift/AST/KnownStdlibTypes.def"
@@ -188,12 +188,9 @@ FOR_KNOWN_FOUNDATION_TYPES(CACHE_FOUNDATION_DECL)
188
188
// / func ==(Int, Int) -> Bool
189
189
FuncDecl *EqualIntDecl = nullptr ;
190
190
191
- // / func _combineHashValues(Int, Int ) -> Int
192
- FuncDecl *CombineHashValuesDecl = nullptr ;
191
+ // / func _hashValue<H: Hashable>(for: H ) -> Int
192
+ FuncDecl *HashValueForDecl = nullptr ;
193
193
194
- // / func _mixInt(Int) -> Int
195
- FuncDecl *MixIntDecl = nullptr ;
196
-
197
194
// / func append(Element) -> void
198
195
FuncDecl *ArrayAppendElementDecl = nullptr ;
199
196
@@ -616,11 +613,11 @@ FuncDecl *ASTContext::getPlusFunctionOnString() const {
616
613
return Impl.PlusFunctionOnString ;
617
614
}
618
615
619
- #define KNOWN_STDLIB_TYPE_DECL (NAME, DECL_CLASS, NUM_GENERIC_PARAMS ) \
616
+ #define KNOWN_STDLIB_TYPE_DECL_WITH_NAME (NAME, IDSTR , DECL_CLASS, NUM_GENERIC_PARAMS ) \
620
617
DECL_CLASS *ASTContext::get##NAME##Decl() const { \
621
618
if (!Impl.NAME ##Decl) \
622
619
Impl.NAME ##Decl = dyn_cast_or_null<DECL_CLASS>( \
623
- findStdlibType (*this , #NAME , NUM_GENERIC_PARAMS)); \
620
+ findStdlibType (*this , IDSTR , NUM_GENERIC_PARAMS)); \
624
621
return Impl.NAME ##Decl; \
625
622
}
626
623
#include " swift/AST/KnownStdlibTypes.def"
@@ -989,44 +986,29 @@ FuncDecl *ASTContext::getGetBoolDecl(LazyResolver *resolver) const {
989
986
return decl;
990
987
}
991
988
992
- FuncDecl *ASTContext::getCombineHashValuesDecl () const {
993
- if (Impl.CombineHashValuesDecl )
994
- return Impl.CombineHashValuesDecl ;
995
-
996
- auto resolver = getLazyResolver ();
997
- auto intType = getIntDecl ()->getDeclaredType ();
998
-
999
- auto callback = [&](Type inputType, Type resultType) {
1000
- // Look for the signature (Int, Int) -> Int
1001
- auto tupleType = dyn_cast<TupleType>(inputType.getPointer ());
1002
- assert (tupleType);
1003
- return tupleType->getNumElements () == 2 &&
1004
- tupleType->getElementType (0 )->isEqual (intType) &&
1005
- tupleType->getElementType (1 )->isEqual (intType) &&
1006
- resultType->isEqual (intType);
1007
- };
1008
-
1009
- auto decl = lookupLibraryIntrinsicFunc (
1010
- *this , " _combineHashValues" , resolver, callback);
1011
- Impl.CombineHashValuesDecl = decl;
1012
- return decl;
1013
- }
1014
-
1015
- FuncDecl *ASTContext::getMixIntDecl () const {
1016
- if (Impl.MixIntDecl )
1017
- return Impl.MixIntDecl ;
989
+ FuncDecl *ASTContext::getHashValueForDecl () const {
990
+ if (Impl.HashValueForDecl )
991
+ return Impl.HashValueForDecl ;
1018
992
1019
- auto resolver = getLazyResolver ();
1020
- auto intType = getIntDecl ()->getDeclaredType ();
1021
-
1022
- auto callback = [&](Type inputType, Type resultType) {
1023
- // Look for the signature (Int) -> Int
1024
- return inputType->isEqual (intType) && resultType->isEqual (intType);
1025
- };
1026
-
1027
- auto decl = lookupLibraryIntrinsicFunc (*this , " _mixInt" , resolver, callback);
1028
- Impl.MixIntDecl = decl;
1029
- return decl;
993
+ SmallVector<ValueDecl *, 1 > results;
994
+ lookupInSwiftModule (" _hashValue" , results);
995
+ for (auto result : results) {
996
+ auto *fd = dyn_cast<FuncDecl>(result);
997
+ if (!fd)
998
+ continue ;
999
+ auto paramLists = fd->getParameterLists ();
1000
+ if (paramLists.size () != 1 || paramLists[0 ]->size () != 1 )
1001
+ continue ;
1002
+ auto paramDecl = paramLists[0 ]->get (0 );
1003
+ if (paramDecl->getArgumentName () != Id_for)
1004
+ continue ;
1005
+ auto genericParams = fd->getGenericParams ();
1006
+ if (!genericParams || genericParams->size () != 1 )
1007
+ continue ;
1008
+ Impl.HashValueForDecl = fd;
1009
+ return fd;
1010
+ }
1011
+ return nullptr ;
1030
1012
}
1031
1013
1032
1014
FuncDecl *ASTContext::getArrayAppendElementDecl () const {
0 commit comments