12
12
13
13
#include " TestContext.h"
14
14
#include " swift/AST/Module.h"
15
+ #include " swift/AST/ParseRequests.h"
15
16
#include " swift/Strings.h"
16
17
#include " swift/Subsystems.h"
17
18
18
19
using namespace swift ;
19
20
using namespace swift ::unittest;
20
21
21
-
22
- static void declareOptionalType (ASTContext &ctx, SourceFile *fileForLookups,
22
+ static Decl *createOptionalType (ASTContext &ctx, SourceFile *fileForLookups,
23
23
Identifier name) {
24
24
auto wrapped = new (ctx) GenericTypeParamDecl (fileForLookups,
25
25
ctx.getIdentifier (" Wrapped" ),
@@ -30,7 +30,7 @@ static void declareOptionalType(ASTContext &ctx, SourceFile *fileForLookups,
30
30
auto decl = new (ctx) EnumDecl (SourceLoc (), name, SourceLoc (),
31
31
/* inherited*/ {}, params, fileForLookups);
32
32
wrapped->setDeclContext (decl);
33
- fileForLookups-> addTopLevelDecl ( decl) ;
33
+ return decl;
34
34
}
35
35
36
36
TestContext::TestContext (ShouldDeclareOptionalTypes optionals)
@@ -50,8 +50,13 @@ TestContext::TestContext(ShouldDeclareOptionalTypes optionals)
50
50
module ->addFile (*FileForLookups);
51
51
52
52
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));
56
61
}
57
62
}
0 commit comments