Skip to content

Commit 140a5b0

Browse files
committed
Sema: Build fully type-checked AST for stub initializers
1 parent b26ba2d commit 140a5b0

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,26 +2338,64 @@ static void synthesizeStubBody(AbstractFunctionDecl *fn, void *) {
23382338
return;
23392339
}
23402340

2341+
auto *staticStringDecl = ctx.getStaticStringDecl();
2342+
auto staticStringType = staticStringDecl->getDeclaredType();
2343+
auto staticStringInit = ctx.getStringBuiltinInitDecl(staticStringDecl);
2344+
2345+
auto *uintDecl = ctx.getUIntDecl();
2346+
auto uintType = uintDecl->getDeclaredType();
2347+
auto uintInit = ctx.getIntBuiltinInitDecl(uintDecl);
2348+
23412349
// Create a call to Swift._unimplementedInitializer
23422350
auto loc = classDecl->getLoc();
23432351
Expr *ref = new (ctx) DeclRefExpr(unimplementedInitDecl,
23442352
DeclNameLoc(loc),
23452353
/*Implicit=*/true);
2354+
ref->setType(unimplementedInitDecl->getInterfaceType()
2355+
->removeArgumentLabels(1));
23462356

23472357
llvm::SmallString<64> buffer;
23482358
StringRef fullClassName = ctx.AllocateCopy(
23492359
(classDecl->getModuleContext()->getName().str() +
23502360
"." +
23512361
classDecl->getName().str()).toStringRef(buffer));
23522362

2353-
Expr *className = new (ctx) StringLiteralExpr(fullClassName, loc,
2363+
auto *className = new (ctx) StringLiteralExpr(fullClassName, loc,
23542364
/*Implicit=*/true);
2355-
Expr *call = CallExpr::createImplicit(ctx, ref, { className },
2356-
{ ctx.Id_className });
2357-
ctor->setBody(BraceStmt::create(ctx, SourceLoc(),
2358-
ASTNode(call),
2359-
SourceLoc(),
2365+
className->setBuiltinInitializer(staticStringInit);
2366+
assert(isa<ConstructorDecl>(className->getBuiltinInitializer().getDecl()));
2367+
className->setType(staticStringType);
2368+
2369+
auto *initName = new (ctx) MagicIdentifierLiteralExpr(
2370+
MagicIdentifierLiteralExpr::Function, loc, /*Implicit=*/true);
2371+
initName->setType(staticStringType);
2372+
initName->setBuiltinInitializer(staticStringInit);
2373+
2374+
auto *file = new (ctx) MagicIdentifierLiteralExpr(
2375+
MagicIdentifierLiteralExpr::File, loc, /*Implicit=*/true);
2376+
file->setType(staticStringType);
2377+
file->setBuiltinInitializer(staticStringInit);
2378+
2379+
auto *line = new (ctx) MagicIdentifierLiteralExpr(
2380+
MagicIdentifierLiteralExpr::Line, loc, /*Implicit=*/true);
2381+
line->setType(uintType);
2382+
line->setBuiltinInitializer(uintInit);
2383+
2384+
auto *column = new (ctx) MagicIdentifierLiteralExpr(
2385+
MagicIdentifierLiteralExpr::Column, loc, /*Implicit=*/true);
2386+
column->setType(uintType);
2387+
column->setBuiltinInitializer(uintInit);
2388+
2389+
Expr *call = CallExpr::createImplicit(
2390+
ctx, ref, { className, initName, file, line, column }, {});
2391+
call->setType(ctx.getNeverType());
2392+
2393+
SmallVector<ASTNode, 2> stmts;
2394+
stmts.push_back(call);
2395+
stmts.push_back(new (ctx) ReturnStmt(SourceLoc(), /*Result=*/nullptr));
2396+
ctor->setBody(BraceStmt::create(ctx, SourceLoc(), stmts, SourceLoc(),
23602397
/*implicit=*/true));
2398+
ctor->setBodyTypeCheckedIfPresent();
23612399
}
23622400

23632401
static std::tuple<GenericEnvironment *, GenericParamList *, SubstitutionMap>

0 commit comments

Comments
 (0)