@@ -132,28 +132,31 @@ StringRef swift::getBuiltinBaseName(ASTContext &C, StringRef Name,
132
132
133
133
// / Build a builtin function declaration.
134
134
static FuncDecl *
135
- getBuiltinFunction (Identifier Id,
136
- ArrayRef<TupleTypeElt> ArgTypes,
137
- Type ResType,
135
+ getBuiltinFunction (Identifier Id, ArrayRef<Type> argTypes, Type ResType,
138
136
FunctionType::ExtInfo Info = FunctionType::ExtInfo()) {
139
137
auto &Context = ResType->getASTContext ();
140
- Type ArgType = TupleType::get (ArgTypes, Context);
138
+
139
+ SmallVector<TupleTypeElt, 4 > tupleElts;
140
+ for (Type argType : argTypes)
141
+ tupleElts.push_back (argType);
142
+
143
+ Type ArgType = TupleType::get (tupleElts, Context);
141
144
Type FnType;
142
145
FnType = FunctionType::get (ArgType, ResType, Info);
143
146
144
147
Module *M = Context.TheBuiltinModule ;
145
148
DeclContext *DC = &M->getMainFile (FileUnitKind::Builtin);
146
149
147
150
SmallVector<TuplePatternElt, 4 > ParamPatternElts;
148
- for (auto &ArgTupleElt : ArgTypes ) {
151
+ for (Type argType : argTypes ) {
149
152
auto PD = new (Context) ParamDecl (/* IsLet*/ true , SourceLoc (),
150
153
Identifier (), SourceLoc (),
151
- Identifier (), ArgTupleElt. getType () ,
154
+ Identifier (), argType ,
152
155
DC);
153
156
PD->setImplicit ();
154
157
Pattern *Pat = new (Context) NamedPattern (PD, /* implicit=*/ true );
155
- Pat = new (Context) TypedPattern (Pat,
156
- TypeLoc::withoutLoc (ArgTupleElt. getType ()), /* implicit=*/ true );
158
+ Pat = new (Context) TypedPattern (Pat, TypeLoc::withoutLoc (argType),
159
+ /* implicit=*/ true );
157
160
PD->setParamParentPattern (Pat);
158
161
159
162
ParamPatternElts.push_back (TuplePatternElt (Pat));
@@ -254,41 +257,37 @@ static ValueDecl *getGepOperation(Identifier Id, Type ArgType) {
254
257
auto &Context = ArgType->getASTContext ();
255
258
256
259
// This is always "(i8*, IntTy) -> i8*"
257
- TupleTypeElt ArgElts[] = { Context.TheRawPointerType , ArgType };
260
+ Type ArgElts[] = { Context.TheRawPointerType , ArgType };
258
261
Type ResultTy = Context.TheRawPointerType ;
259
262
return getBuiltinFunction (Id, ArgElts, ResultTy);
260
263
}
261
264
262
265
// / Build a binary operation declaration.
263
266
static ValueDecl *getBinaryOperation (Identifier Id, Type ArgType) {
264
- TupleTypeElt ArgElts[] = { ArgType, ArgType };
265
- Type ResultTy = ArgType;
266
- return getBuiltinFunction (Id, ArgElts, ResultTy);
267
+ return getBuiltinFunction (Id, { ArgType, ArgType }, ArgType);
267
268
}
268
269
269
270
// / Build a declaration for a binary operation with overflow.
270
271
static ValueDecl *getBinaryOperationWithOverflow (Identifier Id,
271
272
Type ArgType) {
272
273
auto &Context = ArgType->getASTContext ();
273
274
Type ShouldCheckForOverflowTy = BuiltinIntegerType::get (1 , Context);
274
- TupleTypeElt ArgElts[] = { ArgType, ArgType, ShouldCheckForOverflowTy };
275
+ Type ArgElts[] = { ArgType, ArgType, ShouldCheckForOverflowTy };
275
276
Type OverflowBitTy = BuiltinIntegerType::get (1 , Context);
276
277
TupleTypeElt ResultElts[] = { ArgType, OverflowBitTy };
277
278
Type ResultTy = TupleType::get (ResultElts, Context);
278
279
return getBuiltinFunction (Id, ArgElts, ResultTy);
279
280
}
280
281
281
282
static ValueDecl *getUnaryOperation (Identifier Id, Type ArgType) {
282
- TupleTypeElt ArgElts[] = { ArgType };
283
- Type ResultTy = ArgType;
284
- return getBuiltinFunction (Id, ArgElts, ResultTy);
283
+ return getBuiltinFunction (Id, { ArgType }, ArgType);
285
284
}
286
285
287
286
// / Build a binary predicate declaration.
288
287
static ValueDecl *getBinaryPredicate (Identifier Id, Type ArgType) {
289
288
auto &Context = ArgType->getASTContext ();
290
289
291
- TupleTypeElt ArgElts[] = { ArgType, ArgType };
290
+ Type ArgElts[] = { ArgType, ArgType };
292
291
Type ResultTy = BuiltinIntegerType::get (1 , Context);
293
292
if (auto VecTy = ArgType->getAs <BuiltinVectorType>()) {
294
293
ResultTy = BuiltinVectorType::get (Context, ResultTy,
@@ -425,8 +424,7 @@ static ValueDecl *getCastOperation(ASTContext &Context, Identifier Id,
425
424
return nullptr ;
426
425
}
427
426
428
- TupleTypeElt ArgElts[] = { Input };
429
- return getBuiltinFunction (Id, ArgElts, Output);
427
+ return getBuiltinFunction (Id, { Input }, Output);
430
428
}
431
429
432
430
static const char * const GenericParamNames[] = {
@@ -692,14 +690,13 @@ static ValueDecl *getIsOptionalOperation(ASTContext &Context, Identifier Id) {
692
690
693
691
static ValueDecl *getAllocOperation (ASTContext &Context, Identifier Id) {
694
692
Type PtrSizeTy = BuiltinIntegerType::getWordType (Context);
695
- TupleTypeElt ArgElts[] = { PtrSizeTy, PtrSizeTy };
696
693
Type ResultTy = Context.TheRawPointerType ;
697
- return getBuiltinFunction (Id, ArgElts , ResultTy);
694
+ return getBuiltinFunction (Id, { PtrSizeTy, PtrSizeTy } , ResultTy);
698
695
}
699
696
700
697
static ValueDecl *getDeallocOperation (ASTContext &Context, Identifier Id) {
701
698
auto PtrSizeTy = BuiltinIntegerType::getWordType (Context);
702
- TupleTypeElt ArgElts[] = { Context.TheRawPointerType , PtrSizeTy, PtrSizeTy };
699
+ Type ArgElts[] = { Context.TheRawPointerType , PtrSizeTy, PtrSizeTy };
703
700
Type ResultTy = TupleType::getEmpty (Context);
704
701
return getBuiltinFunction (Id, ArgElts, ResultTy);
705
702
}
@@ -722,32 +719,26 @@ static ValueDecl *getUnexpectedErrorOperation(ASTContext &Context,
722
719
723
720
static ValueDecl *getCmpXChgOperation (ASTContext &Context, Identifier Id,
724
721
Type T) {
725
- TupleTypeElt ArgElts[] = { Context.TheRawPointerType , T, T };
722
+ Type ArgElts[] = { Context.TheRawPointerType , T, T };
726
723
Type BoolTy = BuiltinIntegerType::get (1 , Context);
727
- TupleTypeElt ResultElts[] = { T, BoolTy };
728
- Type ResultTy = TupleType::get (ResultElts, Context);
724
+ Type ResultTy = TupleType::get ({ T, BoolTy }, Context);
729
725
return getBuiltinFunction (Id, ArgElts, ResultTy);
730
726
}
731
727
732
728
static ValueDecl *getAtomicRMWOperation (ASTContext &Context, Identifier Id,
733
729
Type T) {
734
- TupleTypeElt ArgElts[] = { Context.TheRawPointerType , T };
735
- Type ResultTy = T;
736
- return getBuiltinFunction (Id, ArgElts, ResultTy);
730
+ return getBuiltinFunction (Id, { Context.TheRawPointerType , T }, T);
737
731
}
738
732
739
733
static ValueDecl *getAtomicLoadOperation (ASTContext &Context, Identifier Id,
740
734
Type T) {
741
- TupleTypeElt ArgElts[] = { Context.TheRawPointerType };
742
- Type ResultTy = T;
743
- return getBuiltinFunction (Id, ArgElts, ResultTy);
735
+ return getBuiltinFunction (Id, { Type (Context.TheRawPointerType ) }, T);
744
736
}
745
737
746
738
static ValueDecl *getAtomicStoreOperation (ASTContext &Context, Identifier Id,
747
739
Type T) {
748
- TupleTypeElt ArgElts[] = { Context.TheRawPointerType , T };
749
- Type ResultTy = Context.TheEmptyTupleType ;
750
- return getBuiltinFunction (Id, ArgElts, ResultTy);
740
+ return getBuiltinFunction (Id, { Context.TheRawPointerType , T },
741
+ Context.TheEmptyTupleType );
751
742
}
752
743
753
744
static ValueDecl *getNativeObjectCast (ASTContext &Context, Identifier Id,
@@ -790,8 +781,6 @@ static ValueDecl *getCastFromBridgeObjectOperation(ASTContext &C,
790
781
Identifier Id,
791
782
BuiltinValueKind BV) {
792
783
Type BridgeTy = C.TheBridgeObjectType ;
793
- TupleTypeElt ArgElts[] = { BridgeTy };
794
-
795
784
switch (BV) {
796
785
case BuiltinValueKind::CastReferenceFromBridgeObject: {
797
786
GenericSignatureBuilder builder (C);
@@ -802,7 +791,7 @@ static ValueDecl *getCastFromBridgeObjectOperation(ASTContext &C,
802
791
803
792
case BuiltinValueKind::CastBitPatternFromBridgeObject: {
804
793
Type WordTy = BuiltinIntegerType::get (BuiltinIntegerWidth::pointer (), C);
805
- return getBuiltinFunction (Id, ArgElts , WordTy);
794
+ return getBuiltinFunction (Id, { BridgeTy } , WordTy);
806
795
}
807
796
808
797
default :
@@ -868,16 +857,13 @@ static ValueDecl *getCondFailOperation(ASTContext &C, Identifier Id) {
868
857
// Int1 -> ()
869
858
auto CondTy = BuiltinIntegerType::get (1 , C);
870
859
auto VoidTy = TupleType::getEmpty (C);
871
- TupleTypeElt CondElt (CondTy);
872
- return getBuiltinFunction (Id, CondElt, VoidTy);
860
+ return getBuiltinFunction (Id, {CondTy}, VoidTy);
873
861
}
874
862
875
863
static ValueDecl *getAssertConfOperation (ASTContext &C, Identifier Id) {
876
864
// () -> Int32
877
865
auto Int32Ty = BuiltinIntegerType::get (32 , C);
878
- auto VoidTy = TupleType::getEmpty (C);
879
- TupleTypeElt EmptyElt (VoidTy);
880
- return getBuiltinFunction (Id, EmptyElt, Int32Ty);
866
+ return getBuiltinFunction (Id, {}, Int32Ty);
881
867
}
882
868
883
869
static ValueDecl *getFixLifetimeOperation (ASTContext &C, Identifier Id) {
@@ -899,9 +885,8 @@ static ValueDecl *getExtractElementOperation(ASTContext &Context, Identifier Id,
899
885
if (!IndexTy || !IndexTy->isFixedWidth () || IndexTy->getFixedWidth () != 32 )
900
886
return nullptr ;
901
887
902
- TupleTypeElt ArgElts[] = { VecTy, IndexTy };
903
888
Type ResultTy = VecTy->getElementType ();
904
- return getBuiltinFunction (Id, ArgElts , ResultTy);
889
+ return getBuiltinFunction (Id, { VecTy, IndexTy } , ResultTy);
905
890
}
906
891
907
892
static ValueDecl *getInsertElementOperation (ASTContext &Context, Identifier Id,
@@ -920,16 +905,15 @@ static ValueDecl *getInsertElementOperation(ASTContext &Context, Identifier Id,
920
905
if (!IndexTy || !IndexTy->isFixedWidth () || IndexTy->getFixedWidth () != 32 )
921
906
return nullptr ;
922
907
923
- TupleTypeElt ArgElts[] = { VecTy, ElementTy, IndexTy };
924
- Type ResultTy = VecTy;
925
- return getBuiltinFunction (Id, ArgElts, ResultTy);
908
+ Type ArgElts[] = { VecTy, ElementTy, IndexTy };
909
+ return getBuiltinFunction (Id, ArgElts, VecTy);
926
910
}
927
911
928
912
static ValueDecl *getStaticReportOperation (ASTContext &Context, Identifier Id) {
929
913
auto BoolTy = BuiltinIntegerType::get (1 , Context);
930
914
auto MessageTy = Context.TheRawPointerType ;
931
915
932
- TupleTypeElt ArgElts[] = { BoolTy, BoolTy, MessageTy };
916
+ Type ArgElts[] = { BoolTy, BoolTy, MessageTy };
933
917
Type ResultTy = TupleType::getEmpty (Context);
934
918
935
919
return getBuiltinFunction (Id, ArgElts, ResultTy);
@@ -946,12 +930,10 @@ static ValueDecl *getCheckedTruncOperation(ASTContext &Context,
946
930
if (InTy->getLeastWidth () < OutTy->getGreatestWidth ())
947
931
return nullptr ;
948
932
949
- TupleTypeElt ArgElts[] = { InTy };
950
933
Type OverflowBitTy = BuiltinIntegerType::get (1 , Context);
951
934
TupleTypeElt ResultElts[] = { OutTy, OverflowBitTy };
952
935
Type ResultTy = TupleType::get (ResultElts, Context);
953
-
954
- return getBuiltinFunction (Id, ArgElts, ResultTy);
936
+ return getBuiltinFunction (Id, { InTy }, ResultTy);
955
937
}
956
938
957
939
static ValueDecl *getCheckedConversionOperation (ASTContext &Context,
@@ -961,12 +943,10 @@ static ValueDecl *getCheckedConversionOperation(ASTContext &Context,
961
943
if (!BuiltinTy)
962
944
return nullptr ;
963
945
964
- TupleTypeElt ArgElts[] = { BuiltinTy };
965
946
Type SignErrorBitTy = BuiltinIntegerType::get (1 , Context);
966
947
TupleTypeElt ResultElts[] = { BuiltinTy, SignErrorBitTy };
967
948
Type ResultTy = TupleType::get (ResultElts, Context);
968
-
969
- return getBuiltinFunction (Id, ArgElts, ResultTy);
949
+ return getBuiltinFunction (Id, { BuiltinTy }, ResultTy);
970
950
}
971
951
972
952
static ValueDecl *getIntToFPWithOverflowOperation (ASTContext &Context,
@@ -977,10 +957,7 @@ static ValueDecl *getIntToFPWithOverflowOperation(ASTContext &Context,
977
957
if (!InTy || !OutTy)
978
958
return nullptr ;
979
959
980
- TupleTypeElt ArgElts[] = { InTy };
981
- Type ResultTy = OutTy;
982
-
983
- return getBuiltinFunction (Id, ArgElts, ResultTy);
960
+ return getBuiltinFunction (Id, { InTy }, OutTy);
984
961
}
985
962
986
963
static ValueDecl *getUnreachableOperation (ASTContext &Context,
@@ -1001,11 +978,7 @@ static ValueDecl *getOnceOperation(ASTContext &Context,
1001
978
/* noreturn*/ false , /* throws*/ false );
1002
979
1003
980
auto BlockTy = FunctionType::get (VoidTy, VoidTy, Thin);
1004
-
1005
- TupleTypeElt InFields[] = {HandleTy, BlockTy};
1006
- auto OutTy = VoidTy;
1007
-
1008
- return getBuiltinFunction (Id, InFields, OutTy);
981
+ return getBuiltinFunction (Id, {HandleTy, BlockTy}, VoidTy);
1009
982
}
1010
983
1011
984
static ValueDecl *getTryPinOperation (ASTContext &ctx, Identifier name) {
@@ -1232,7 +1205,7 @@ static Type DecodeIntrinsicType(ArrayRef<llvm::Intrinsic::IITDescriptor> &Table,
1232
1205
static bool
1233
1206
getSwiftFunctionTypeForIntrinsic (unsigned iid, ArrayRef<Type> TypeArgs,
1234
1207
ASTContext &Context,
1235
- SmallVectorImpl<TupleTypeElt > &ArgElts,
1208
+ SmallVectorImpl<Type > &ArgElts,
1236
1209
Type &ResultTy, FunctionType::ExtInfo &Info) {
1237
1210
llvm::Intrinsic::ID ID = (llvm::Intrinsic::ID)iid;
1238
1211
@@ -1327,7 +1300,7 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
1327
1300
// If this is the name of an LLVM intrinsic, cons up a swift function with a
1328
1301
// type that matches the IR types.
1329
1302
if (unsigned ID = getLLVMIntrinsicID (OperationName, !Types.empty ())) {
1330
- SmallVector<TupleTypeElt , 8 > ArgElts;
1303
+ SmallVector<Type , 8 > ArgElts;
1331
1304
Type ResultTy;
1332
1305
FunctionType::ExtInfo Info;
1333
1306
if (getSwiftFunctionTypeForIntrinsic (ID, Types, Context, ArgElts, ResultTy,
0 commit comments