|
16 | 16 |
|
17 | 17 | #include "swift/AST/Builtins.h"
|
18 | 18 | #include "swift/AST/ASTContext.h"
|
| 19 | +#include "swift/AST/ASTSynthesis.h" |
19 | 20 | #include "swift/AST/FileUnit.h"
|
20 | 21 | #include "swift/AST/Module.h"
|
21 | 22 | #include "swift/AST/ParameterList.h"
|
@@ -180,6 +181,28 @@ getBuiltinFunction(Identifier Id, ArrayRef<Type> argTypes, Type ResType) {
|
180 | 181 | return FD;
|
181 | 182 | }
|
182 | 183 |
|
| 184 | +template <class ExtInfoS, class ParamsS, class ResultS> |
| 185 | +static FuncDecl * |
| 186 | +getBuiltinFunction(ASTContext &ctx, Identifier id, |
| 187 | + const ExtInfoS &extInfoS, const ParamsS ¶msS, |
| 188 | + const ResultS &resultS) { |
| 189 | + ModuleDecl *M = ctx.TheBuiltinModule; |
| 190 | + DeclContext *DC = &M->getMainFile(FileUnitKind::Builtin); |
| 191 | + |
| 192 | + SynthesisContext SC(ctx, DC); |
| 193 | + auto params = synthesizeParameterList(SC, paramsS); |
| 194 | + auto extInfo = synthesizeExtInfo(SC, extInfoS); |
| 195 | + auto resultType = synthesizeType(SC, resultS); |
| 196 | + |
| 197 | + DeclName name(ctx, id, params); |
| 198 | + auto *FD = FuncDecl::createImplicit( |
| 199 | + ctx, StaticSpellingKind::None, name, /*NameLoc=*/SourceLoc(), |
| 200 | + extInfo.isAsync(), extInfo.isThrowing(), |
| 201 | + /*GenericParams=*/nullptr, params, resultType, DC); |
| 202 | + FD->setAccess(AccessLevel::Public); |
| 203 | + return FD; |
| 204 | +} |
| 205 | + |
183 | 206 | namespace {
|
184 | 207 |
|
185 | 208 | enum class BuiltinThrowsKind : uint8_t {
|
@@ -1409,6 +1432,13 @@ static ValueDecl *getCreateAsyncTaskFuture(ASTContext &ctx, Identifier id) {
|
1409 | 1432 | return builder.build(id);
|
1410 | 1433 | }
|
1411 | 1434 |
|
| 1435 | +static ValueDecl *getConvertTaskToJob(ASTContext &ctx, Identifier id) { |
| 1436 | + return getBuiltinFunction(ctx, id, |
| 1437 | + _thin, |
| 1438 | + _parameters(_owned(_nativeObject)), |
| 1439 | + _job); |
| 1440 | +} |
| 1441 | + |
1412 | 1442 | static ValueDecl *getAutoDiffCreateLinearMapContext(ASTContext &ctx,
|
1413 | 1443 | Identifier id) {
|
1414 | 1444 | return getBuiltinFunction(
|
@@ -2589,6 +2619,9 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
|
2589 | 2619 | case BuiltinValueKind::CreateAsyncTaskFuture:
|
2590 | 2620 | return getCreateAsyncTaskFuture(Context, Id);
|
2591 | 2621 |
|
| 2622 | + case BuiltinValueKind::ConvertTaskToJob: |
| 2623 | + return getConvertTaskToJob(Context, Id); |
| 2624 | + |
2592 | 2625 | case BuiltinValueKind::PoundAssert:
|
2593 | 2626 | return getPoundAssert(Context, Id);
|
2594 | 2627 |
|
|
0 commit comments