@@ -218,6 +218,9 @@ struct ASTContext::Implementation {
218
218
// / The declaration of Swift.Optional<T>.None.
219
219
EnumElementDecl *OptionalNoneDecl = nullptr ;
220
220
221
+ // / The declaration of Swift.Void.
222
+ TypeAliasDecl *VoidDecl = nullptr ;
223
+
221
224
// / The declaration of Swift.UnsafeMutableRawPointer.memory.
222
225
VarDecl *UnsafeMutableRawPointerMemoryDecl = nullptr ;
223
226
@@ -712,7 +715,8 @@ FuncDecl *ASTContext::getPlusFunctionOnRangeReplaceableCollection() const {
712
715
continue ;
713
716
for (auto Req: FD->getGenericRequirements ()) {
714
717
if (Req.getKind () == RequirementKind::Conformance &&
715
- Req.getProtocolDecl () == getRangeReplaceableCollectionDecl ()) {
718
+ Req.getProtocolDecl () ==
719
+ getProtocol (KnownProtocolKind::RangeReplaceableCollection)) {
716
720
getImpl ().PlusFunctionOnRangeReplaceableCollection = FD;
717
721
}
718
722
}
@@ -733,17 +737,13 @@ FuncDecl *ASTContext::getPlusFunctionOnString() const {
733
737
if (!FD->getOperatorDecl ())
734
738
continue ;
735
739
auto ResultType = FD->getResultInterfaceType ();
736
- if (ResultType->getNominalOrBoundGenericNominal () != getStringDecl ())
740
+ if (! ResultType->isString ())
737
741
continue ;
738
742
auto ParamList = FD->getParameters ();
739
743
if (ParamList->size () != 2 )
740
744
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 ()) {
747
747
getImpl ().PlusFunctionOnString = FD;
748
748
break ;
749
749
}
@@ -803,22 +803,28 @@ FuncDecl *ASTContext::getAsyncSequenceMakeAsyncIterator() const {
803
803
}
804
804
805
805
#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; \
818
817
} \
819
818
} \
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
+ }
822
828
#include " swift/AST/KnownStdlibTypes.def"
823
829
824
830
CanType ASTContext::getExceptionType () const {
@@ -846,6 +852,30 @@ EnumElementDecl *ASTContext::getOptionalNoneDecl() const {
846
852
return getImpl ().OptionalNoneDecl ;
847
853
}
848
854
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
+
849
879
static VarDecl *getPointeeProperty (VarDecl *&cache,
850
880
NominalTypeDecl *(ASTContext::*getNominal)() const ,
851
881
const ASTContext &ctx) {
@@ -911,13 +941,6 @@ CanType ASTContext::getAnyObjectType() const {
911
941
return getImpl ().AnyObjectType ;
912
942
}
913
943
914
- CanType ASTContext::getNeverType () const {
915
- auto neverDecl = getNeverDecl ();
916
- if (!neverDecl)
917
- return CanType ();
918
- return neverDecl->getDeclaredInterfaceType ()->getCanonicalType ();
919
- }
920
-
921
944
#define KNOWN_SDK_TYPE_DECL (MODULE, NAME, DECLTYPE, GENERIC_ARGS ) \
922
945
DECLTYPE *ASTContext::get##NAME##Decl() const { \
923
946
if (!getImpl ().NAME ##Decl) { \
@@ -1159,19 +1182,18 @@ FuncDecl *getBinaryComparisonOperatorIntDecl(const ASTContext &C, StringRef op,
1159
1182
if (!C.getIntDecl () || !C.getBoolDecl ())
1160
1183
return nullptr ;
1161
1184
1162
- auto intType = C.getIntDecl ()->getDeclaredInterfaceType ();
1163
1185
auto isIntParam = [&](AnyFunctionType::Param param) {
1164
1186
return (!param.isVariadic () && !param.isInOut () &&
1165
- param.getPlainType ()->isEqual (intType ));
1187
+ param.getPlainType ()->isInt ( ));
1166
1188
};
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) {
1170
1192
// Check for the signature: (Int, Int) -> Bool
1171
1193
if (type->getParams ().size () != 2 ) return false ;
1172
1194
if (!isIntParam (type->getParams ()[0 ]) ||
1173
1195
!isIntParam (type->getParams ()[1 ])) return false ;
1174
- return type->getResult ()->isEqual (boolType );
1196
+ return type->getResult ()->isBool ( );
1175
1197
});
1176
1198
cached = decl;
1177
1199
return decl;
@@ -1226,11 +1248,8 @@ FuncDecl *ASTContext::getArrayAppendElementDecl() const {
1226
1248
return nullptr ;
1227
1249
1228
1250
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 ())
1234
1253
return nullptr ;
1235
1254
1236
1255
auto ParamList = FnDecl->getParameters ();
@@ -1273,11 +1292,8 @@ FuncDecl *ASTContext::getArrayReserveCapacityDecl() const {
1273
1292
return nullptr ;
1274
1293
1275
1294
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 ())
1281
1297
return nullptr ;
1282
1298
1283
1299
auto ParamList = FnDecl->getParameters ();
@@ -4631,7 +4647,7 @@ Type ASTContext::getBridgedToObjC(const DeclContext *dc, Type type,
4631
4647
[&](KnownProtocolKind known) -> ProtocolConformanceRef {
4632
4648
// Don't ascribe any behavior to Optional other than what we explicitly
4633
4649
// give it. We don't want things like AnyObject?? to work.
4634
- if (type->getAnyNominal () == getOptionalDecl ())
4650
+ if (type->isOptional ())
4635
4651
return ProtocolConformanceRef::forInvalid ();
4636
4652
4637
4653
// Find the protocol.
0 commit comments