Skip to content

Commit 4317bbd

Browse files
authored
Merge pull request #39435 from zoecarver/lazy-pt7-clang-importer-zone
[cxx-interop][nfc] Add a ClangImporter request zone.
2 parents 295394a + d52973f commit 4317bbd

File tree

13 files changed

+155
-36
lines changed

13 files changed

+155
-36
lines changed

include/swift/Basic/Statistics.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ FRONTEND_STATISTIC(Sema, NumUnloadedLazyIterableDeclContexts)
268268
#include "swift/AST/TypeCheckerTypeIDZone.def"
269269
#include "swift/Sema/IDETypeCheckingRequestIDZone.def"
270270
#include "swift/IDE/IDERequestIDZone.def"
271+
#include "swift/ClangImporter/ClangImporterTypeIDZone.def"
271272
#undef SWIFT_REQUEST
272273

273274
#define SWIFT_REQUEST(ZONE, NAME, Sig, Caching, LocOptions) FRONTEND_STATISTIC(SILGen, NAME)

include/swift/Basic/TypeIDZones.def

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
//===--- TypeIDZones.def - List of TypeID Zones -----------------*- C++ -*-===//
2-
//
3-
// This source file is part of the Swift.org open source project
4-
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6-
// Licensed under Apache License v2.0 with Runtime Library Exception
7-
//
8-
// See https://swift.org/LICENSE.txt for license information
9-
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10-
//
11-
//===----------------------------------------------------------------------===//
12-
//
13-
// This definition file describes the zones for TypeID.
14-
//
15-
//===----------------------------------------------------------------------===//
16-
17-
SWIFT_TYPEID_ZONE(C, 0)
18-
SWIFT_TYPEID_ZONE(AST, 1)
19-
20-
SWIFT_TYPEID_ZONE(Parse, 8)
21-
SWIFT_TYPEID_ZONE(NameLookup, 9)
22-
23-
SWIFT_TYPEID_ZONE(TypeChecker, 10)
24-
SWIFT_TYPEID_ZONE(AccessControl, 11)
25-
SWIFT_TYPEID_ZONE(SILGen, 12)
26-
SWIFT_TYPEID_ZONE(SILOptimizer, 13)
27-
SWIFT_TYPEID_ZONE(TBDGen, 14)
28-
29-
SWIFT_TYPEID_ZONE(IRGen, 20)
30-
31-
SWIFT_TYPEID_ZONE(IDETypeChecking, 97)
32-
33-
SWIFT_TYPEID_ZONE(IDETypes, 136)
34-
SWIFT_TYPEID_ZONE(IDE, 137)
35-
36-
// N.B. This is not a formal zone and exists solely to support the unit tests.
37-
SWIFT_TYPEID_ZONE(ArithmeticEvaluator, 255)
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This definition file describes the zones for TypeID.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
SWIFT_TYPEID_ZONE(C, 0)
18+
SWIFT_TYPEID_ZONE(AST, 1)
19+
20+
SWIFT_TYPEID_ZONE(Parse, 8)
21+
SWIFT_TYPEID_ZONE(NameLookup, 9)
22+
23+
SWIFT_TYPEID_ZONE(TypeChecker, 10)
24+
SWIFT_TYPEID_ZONE(AccessControl, 11)
25+
SWIFT_TYPEID_ZONE(SILGen, 12)
26+
SWIFT_TYPEID_ZONE(SILOptimizer, 13)
27+
SWIFT_TYPEID_ZONE(TBDGen, 14)
28+
29+
SWIFT_TYPEID_ZONE(IRGen, 20)
30+
31+
SWIFT_TYPEID_ZONE(IDETypeChecking, 97)
32+
33+
SWIFT_TYPEID_ZONE(IDETypes, 136)
34+
SWIFT_TYPEID_ZONE(IDE, 137)
35+
36+
SWIFT_TYPEID_ZONE(ClangImporter, 139)
37+
38+
// N.B. This is not a formal zone and exists solely to support the unit tests.
39+
SWIFT_TYPEID_ZONE(ArithmeticEvaluator, 255)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//===--- ClangImporterRequests.h - Clang Importer Requests ------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines clang-importer requests.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
#ifndef SWIFT_CLANG_IMPORTER_REQUESTS_H
17+
#define SWIFT_CLANG_IMPORTER_REQUESTS_H
18+
19+
#include "swift/AST/SimpleRequest.h"
20+
#include "swift/AST/ASTTypeIDs.h"
21+
#include "swift/AST/EvaluatorDependencies.h"
22+
23+
namespace swift {
24+
25+
#define SWIFT_TYPEID_ZONE ClangImporter
26+
#define SWIFT_TYPEID_HEADER "swift/ClangImporter/ClangImporterTypeIDZone.def"
27+
#include "swift/Basic/DefineTypeIDZone.h"
28+
#undef SWIFT_TYPEID_ZONE
29+
#undef SWIFT_TYPEID_HEADER
30+
31+
// Set up reporting of evaluated requests.
32+
template<typename Request>
33+
void reportEvaluatedRequest(UnifiedStatsReporter &stats,
34+
const Request &request);
35+
36+
#define SWIFT_REQUEST(Zone, RequestType, Sig, Caching, LocOptions) \
37+
template <> \
38+
inline void reportEvaluatedRequest(UnifiedStatsReporter &stats, \
39+
const RequestType &request) { \
40+
++stats.getFrontendCounters().RequestType; \
41+
}
42+
#include "swift/ClangImporter/ClangImporterTypeIDZone.def"
43+
#undef SWIFT_REQUEST
44+
45+
} // end namespace swift
46+
47+
#endif // SWIFT_CLANG_IMPORTER_REQUESTS_H
48+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===--- ClangImporterTypeIDZone.def ----------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This definition file describes the types in the clang importer
14+
// TypeID zone, for use with the TypeID template.
15+
//
16+
//===----------------------------------------------------------------------===//
17+

include/swift/Subsystems.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,12 @@ namespace swift {
363363
/// Calling registerIDERequestFunctions will invoke this function as well.
364364
void registerIDETypeCheckRequestFunctions(Evaluator &evaluator);
365365

366+
/// Register clang importer request functions with the evaluator.
367+
///
368+
/// Clients that form an ASTContext and import any Clang APIs should call this function
369+
/// after forming the ASTContext.
370+
void registerClangImporterRequestFunctions(Evaluator &evaluator);
371+
366372
/// Register SILOptimizer passes necessary for IRGen.
367373
void registerIRGenSILTransforms(ASTContext &ctx);
368374

lib/AST/NameLookupRequests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "swift/AST/Evaluator.h"
2020
#include "swift/AST/Module.h"
2121
#include "swift/AST/SourceFile.h"
22+
#include "swift/ClangImporter/ClangImporterRequests.h"
2223
#include "swift/Subsystems.h"
2324

2425
using namespace swift;

lib/ClangImporter/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_swift_host_library(swiftClangImporter STATIC
1010
ClangAdapter.cpp
1111
ClangDiagnosticConsumer.cpp
1212
ClangImporter.cpp
13+
ClangImporterRequests.cpp
1314
ClangModuleDependencyScanner.cpp
1415
ClangSourceBufferImporter.cpp
1516
DWARFImporter.cpp
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===--- ClangImporterRequests.cpp - Clang Importer Requests --------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "swift/AST/NameLookupRequests.h"
14+
#include "swift/AST/ASTContext.h"
15+
#include "swift/AST/Decl.h"
16+
#include "swift/AST/Evaluator.h"
17+
#include "swift/AST/Module.h"
18+
#include "swift/AST/SourceFile.h"
19+
#include "swift/ClangImporter/ClangImporterRequests.h"
20+
#include "swift/Subsystems.h"
21+
22+
using namespace swift;
23+
24+
// Define request evaluation functions for each of the name lookup requests.
25+
static AbstractRequestFunction *clangImporterRequestFunctions[] = {
26+
nullptr // TODO: remove this whenever a request is actually added.
27+
#define SWIFT_REQUEST(Zone, Name, Sig, Caching, LocOptions) \
28+
reinterpret_cast<AbstractRequestFunction *>(&Name::evaluateRequest),
29+
#include "swift/ClangImporter/ClangImporterTypeIDZone.def"
30+
#undef SWIFT_REQUEST
31+
};
32+
33+
void swift::registerClangImporterRequestFunctions(Evaluator &evaluator) {
34+
evaluator.registerRequestFunctions(Zone::ClangImporter,
35+
clangImporterRequestFunctions);
36+
}
37+

lib/Frontend/Frontend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ bool CompilerInstance::setUpASTContextIfNeeded() {
221221
SourceMgr, Diagnostics));
222222
registerParseRequestFunctions(Context->evaluator);
223223
registerTypeCheckerRequestFunctions(Context->evaluator);
224+
registerClangImporterRequestFunctions(Context->evaluator);
224225
registerSILGenRequestFunctions(Context->evaluator);
225226
registerSILOptimizerRequestFunctions(Context->evaluator);
226227
registerTBDGenRequestFunctions(Context->evaluator);

lib/IDE/CompletionInstance.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ bool CompletionInstance::performCachedOperationIfPossible(
338338
registerParseRequestFunctions(tmpCtx->evaluator);
339339
registerIDERequestFunctions(tmpCtx->evaluator);
340340
registerTypeCheckerRequestFunctions(tmpCtx->evaluator);
341+
registerClangImporterRequestFunctions(tmpCtx->evaluator);
341342
registerSILGenRequestFunctions(tmpCtx->evaluator);
342343
ModuleDecl *tmpM = ModuleDecl::create(Identifier(), *tmpCtx);
343344
SourceFile *tmpSF = new (*tmpCtx)

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,7 @@ static int doSyntaxColoring(const CompilerInvocation &InitInvok,
16601660

16611661
registerParseRequestFunctions(Parser.getParser().Context.evaluator);
16621662
registerTypeCheckerRequestFunctions(Parser.getParser().Context.evaluator);
1663+
registerClangImporterRequestFunctions(Parser.getParser().Context.evaluator);
16631664

16641665
Parser.getDiagnosticEngine().addConsumer(PrintDiags);
16651666

@@ -1895,6 +1896,7 @@ static int doStructureAnnotation(const CompilerInvocation &InitInvok,
18951896
registerParseRequestFunctions(Parser.getParser().Context.evaluator);
18961897
registerTypeCheckerRequestFunctions(
18971898
Parser.getParser().Context.evaluator);
1899+
registerClangImporterRequestFunctions(Parser.getParser().Context.evaluator);
18981900

18991901
// Display diagnostics to stderr.
19001902
PrintingDiagnosticConsumer PrintDiags;

unittests/AST/TestContext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ TestContext::TestContext(ShouldDeclareOptionalTypes optionals)
4040
SourceMgr, Diags)) {
4141
registerParseRequestFunctions(Ctx.evaluator);
4242
registerTypeCheckerRequestFunctions(Ctx.evaluator);
43+
registerClangImporterRequestFunctions(Ctx.evaluator);
4344
auto stdlibID = Ctx.getIdentifier(STDLIB_NAME);
4445
auto *module = ModuleDecl::create(stdlibID, Ctx);
4546
Ctx.addLoadedModule(module);

unittests/Sema/SemaFixture.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ SemaTest::SemaTest()
3636

3737
registerParseRequestFunctions(Context.evaluator);
3838
registerTypeCheckerRequestFunctions(Context.evaluator);
39+
registerClangImporterRequestFunctions(Context.evaluator);
3940

4041
Context.addModuleLoader(ImplicitSerializedModuleLoader::create(Context));
4142
Context.addModuleLoader(ClangImporter::create(Context), /*isClang=*/true);

0 commit comments

Comments
 (0)