@@ -218,6 +218,9 @@ struct ASTContext::Implementation {
218218 // / The declaration of Swift.Optional<T>.None.
219219 EnumElementDecl *OptionalNoneDecl = nullptr ;
220220
221+ // / The declaration of Swift.Void.
222+ TypeAliasDecl *VoidDecl = nullptr ;
223+
221224 // / The declaration of Swift.UnsafeMutableRawPointer.memory.
222225 VarDecl *UnsafeMutableRawPointerMemoryDecl = nullptr ;
223226
@@ -712,7 +715,8 @@ FuncDecl *ASTContext::getPlusFunctionOnRangeReplaceableCollection() const {
712715 continue ;
713716 for (auto Req: FD->getGenericRequirements ()) {
714717 if (Req.getKind () == RequirementKind::Conformance &&
715- Req.getProtocolDecl () == getRangeReplaceableCollectionDecl ()) {
718+ Req.getProtocolDecl () ==
719+ getProtocol (KnownProtocolKind::RangeReplaceableCollection)) {
716720 getImpl ().PlusFunctionOnRangeReplaceableCollection = FD;
717721 }
718722 }
@@ -733,17 +737,13 @@ FuncDecl *ASTContext::getPlusFunctionOnString() const {
733737 if (!FD->getOperatorDecl ())
734738 continue ;
735739 auto ResultType = FD->getResultInterfaceType ();
736- if (ResultType->getNominalOrBoundGenericNominal () != getStringDecl ())
740+ if (! ResultType->isString ())
737741 continue ;
738742 auto ParamList = FD->getParameters ();
739743 if (ParamList->size () != 2 )
740744 continue ;
741- auto CheckIfStringParam = [this ](ParamDecl* Param) {
742- auto Type = Param->getInterfaceType ()->getNominalOrBoundGenericNominal ();
743- return Type == getStringDecl ();
744- };
745- if (CheckIfStringParam (ParamList->get (0 )) &&
746- CheckIfStringParam (ParamList->get (1 ))) {
745+ if (ParamList->get (0 )->getInterfaceType ()->isString () &&
746+ ParamList->get (1 )->getInterfaceType ()->isString ()) {
747747 getImpl ().PlusFunctionOnString = FD;
748748 break ;
749749 }
@@ -803,22 +803,28 @@ FuncDecl *ASTContext::getAsyncSequenceMakeAsyncIterator() const {
803803}
804804
805805#define KNOWN_STDLIB_TYPE_DECL (NAME, DECL_CLASS, NUM_GENERIC_PARAMS ) \
806- DECL_CLASS *ASTContext::get##NAME##Decl() const { \
807- if (getImpl ().NAME ##Decl) \
808- return getImpl ().NAME ##Decl; \
809- SmallVector<ValueDecl *, 1 > results; \
810- lookupInSwiftModule (#NAME, results); \
811- for (auto result : results) { \
812- if (auto type = dyn_cast<DECL_CLASS>(result)) { \
813- auto params = type->getGenericParams (); \
814- if (NUM_GENERIC_PARAMS == (params == nullptr ? 0 : params->size ())) { \
815- getImpl ().NAME ##Decl = type; \
816- return type; \
817- } \
806+ DECL_CLASS *ASTContext::get##NAME##Decl() const { \
807+ if (getImpl ().NAME ##Decl) \
808+ return getImpl ().NAME ##Decl; \
809+ SmallVector<ValueDecl *, 1 > results; \
810+ lookupInSwiftModule (#NAME, results); \
811+ for (auto result : results) { \
812+ if (auto type = dyn_cast<DECL_CLASS>(result)) { \
813+ auto params = type->getGenericParams (); \
814+ if (NUM_GENERIC_PARAMS == (params == nullptr ? 0 : params->size ())) { \
815+ getImpl ().NAME ##Decl = type; \
816+ return type; \
818817 } \
819818 } \
820- return nullptr ; \
821- }
819+ } \
820+ return nullptr ; \
821+ } \
822+ \
823+ Type ASTContext::get##NAME##Type() const { \
824+ if (!get##NAME##Decl ()) \
825+ return Type (); \
826+ return get##NAME##Decl ()->getDeclaredInterfaceType (); \
827+ }
822828#include " swift/AST/KnownStdlibTypes.def"
823829
824830CanType ASTContext::getExceptionType () const {
@@ -846,6 +852,30 @@ EnumElementDecl *ASTContext::getOptionalNoneDecl() const {
846852 return getImpl ().OptionalNoneDecl ;
847853}
848854
855+ TypeAliasDecl *ASTContext::getVoidDecl () const {
856+ if (getImpl ().VoidDecl ) {
857+ return getImpl ().VoidDecl ;
858+ }
859+
860+ SmallVector<ValueDecl *, 1 > results;
861+ lookupInSwiftModule (" Void" , results);
862+ for (auto result : results) {
863+ if (auto typealias = dyn_cast<TypeAliasDecl>(result)) {
864+ getImpl ().VoidDecl = typealias;
865+ return typealias;
866+ }
867+ }
868+
869+ return nullptr ;
870+ }
871+
872+ Type ASTContext::getVoidType () const {
873+ auto decl = getVoidDecl ();
874+ if (!decl)
875+ return Type ();
876+ return decl->getDeclaredInterfaceType ();
877+ }
878+
849879static VarDecl *getPointeeProperty (VarDecl *&cache,
850880 NominalTypeDecl *(ASTContext::*getNominal)() const ,
851881 const ASTContext &ctx) {
@@ -911,13 +941,6 @@ CanType ASTContext::getAnyObjectType() const {
911941 return getImpl ().AnyObjectType ;
912942}
913943
914- CanType ASTContext::getNeverType () const {
915- auto neverDecl = getNeverDecl ();
916- if (!neverDecl)
917- return CanType ();
918- return neverDecl->getDeclaredInterfaceType ()->getCanonicalType ();
919- }
920-
921944#define KNOWN_SDK_TYPE_DECL (MODULE, NAME, DECLTYPE, GENERIC_ARGS ) \
922945DECLTYPE *ASTContext::get##NAME##Decl() const { \
923946 if (!getImpl ().NAME ##Decl) { \
@@ -1159,19 +1182,18 @@ FuncDecl *getBinaryComparisonOperatorIntDecl(const ASTContext &C, StringRef op,
11591182 if (!C.getIntDecl () || !C.getBoolDecl ())
11601183 return nullptr ;
11611184
1162- auto intType = C.getIntDecl ()->getDeclaredInterfaceType ();
11631185 auto isIntParam = [&](AnyFunctionType::Param param) {
11641186 return (!param.isVariadic () && !param.isInOut () &&
1165- param.getPlainType ()->isEqual (intType ));
1187+ param.getPlainType ()->isInt ( ));
11661188 };
1167- auto boolType = C. getBoolDecl ()-> getDeclaredInterfaceType ();
1168- auto decl = lookupOperatorFunc (C, op, intType,
1169- [=](FunctionType *type) {
1189+
1190+ auto decl = lookupOperatorFunc (C, op, C. getIntType (),
1191+ [=](FunctionType *type) {
11701192 // Check for the signature: (Int, Int) -> Bool
11711193 if (type->getParams ().size () != 2 ) return false ;
11721194 if (!isIntParam (type->getParams ()[0 ]) ||
11731195 !isIntParam (type->getParams ()[1 ])) return false ;
1174- return type->getResult ()->isEqual (boolType );
1196+ return type->getResult ()->isBool ( );
11751197 });
11761198 cached = decl;
11771199 return decl;
@@ -1226,11 +1248,8 @@ FuncDecl *ASTContext::getArrayAppendElementDecl() const {
12261248 return nullptr ;
12271249
12281250 auto SelfInOutTy = SelfDecl->getInterfaceType ();
1229- BoundGenericStructType *SelfGenericStructTy =
1230- SelfInOutTy->getAs <BoundGenericStructType>();
1231- if (!SelfGenericStructTy)
1232- return nullptr ;
1233- if (SelfGenericStructTy->getDecl () != getArrayDecl ())
1251+
1252+ if (!SelfInOutTy->isArray ())
12341253 return nullptr ;
12351254
12361255 auto ParamList = FnDecl->getParameters ();
@@ -1273,11 +1292,8 @@ FuncDecl *ASTContext::getArrayReserveCapacityDecl() const {
12731292 return nullptr ;
12741293
12751294 auto SelfInOutTy = SelfDecl->getInterfaceType ();
1276- BoundGenericStructType *SelfGenericStructTy =
1277- SelfInOutTy->getAs <BoundGenericStructType>();
1278- if (!SelfGenericStructTy)
1279- return nullptr ;
1280- if (SelfGenericStructTy->getDecl () != getArrayDecl ())
1295+
1296+ if (!SelfInOutTy->isArray ())
12811297 return nullptr ;
12821298
12831299 auto ParamList = FnDecl->getParameters ();
@@ -4631,7 +4647,7 @@ Type ASTContext::getBridgedToObjC(const DeclContext *dc, Type type,
46314647 [&](KnownProtocolKind known) -> ProtocolConformanceRef {
46324648 // Don't ascribe any behavior to Optional other than what we explicitly
46334649 // give it. We don't want things like AnyObject?? to work.
4634- if (type->getAnyNominal () == getOptionalDecl ())
4650+ if (type->isOptional ())
46354651 return ProtocolConformanceRef::forInvalid ();
46364652
46374653 // Find the protocol.
0 commit comments