Skip to content

Commit dafa9b9

Browse files
committed
[unittests] Remove a use of addTopLevelDecl
Instead, cache the decls as a result of ParseSourceFileRequest.
1 parent 011f4f1 commit dafa9b9

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

unittests/AST/TestContext.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
#include "TestContext.h"
1414
#include "swift/AST/Module.h"
15+
#include "swift/AST/ParseRequests.h"
1516
#include "swift/Strings.h"
1617
#include "swift/Subsystems.h"
1718

1819
using namespace swift;
1920
using namespace swift::unittest;
2021

21-
22-
static void declareOptionalType(ASTContext &ctx, SourceFile *fileForLookups,
22+
static Decl *createOptionalType(ASTContext &ctx, SourceFile *fileForLookups,
2323
Identifier name) {
2424
auto wrapped = new (ctx) GenericTypeParamDecl(fileForLookups,
2525
ctx.getIdentifier("Wrapped"),
@@ -30,7 +30,7 @@ static void declareOptionalType(ASTContext &ctx, SourceFile *fileForLookups,
3030
auto decl = new (ctx) EnumDecl(SourceLoc(), name, SourceLoc(),
3131
/*inherited*/{}, params, fileForLookups);
3232
wrapped->setDeclContext(decl);
33-
fileForLookups->addTopLevelDecl(decl);
33+
return decl;
3434
}
3535

3636
TestContext::TestContext(ShouldDeclareOptionalTypes optionals)
@@ -50,8 +50,13 @@ TestContext::TestContext(ShouldDeclareOptionalTypes optionals)
5050
module->addFile(*FileForLookups);
5151

5252
if (optionals == DeclareOptionalTypes) {
53-
declareOptionalType(Ctx, FileForLookups, Ctx.getIdentifier("Optional"));
54-
declareOptionalType(Ctx, FileForLookups,
55-
Ctx.getIdentifier("ImplicitlyUnwrappedOptional"));
53+
SmallVector<Decl *, 2> optionalTypes;
54+
optionalTypes.push_back(createOptionalType(
55+
Ctx, FileForLookups, Ctx.getIdentifier("Optional")));
56+
optionalTypes.push_back(createOptionalType(
57+
Ctx, FileForLookups, Ctx.getIdentifier("ImplicitlyUnwrappedOptional")));
58+
59+
Ctx.evaluator.cacheOutput(ParseSourceFileRequest{FileForLookups},
60+
Ctx.AllocateCopy(optionalTypes));
5661
}
5762
}

0 commit comments

Comments
 (0)