Skip to content

Commit d706863

Browse files
committed
[cxx-interop][nfc] Add a ClangImporter request zone.
This is just the boilerplate for adding a request zone. I haven't actually added any requrests in this commit.
1 parent b1236e9 commit d706863

File tree

13 files changed

+119
-0
lines changed

13 files changed

+119
-0
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@
3333
SWIFT_TYPEID_ZONE(IDETypes, 136)
3434
SWIFT_TYPEID_ZONE(IDE, 137)
3535

36+
SWIFT_TYPEID_ZONE(ClangImporter, 139)
37+
3638
// N.B. This is not a formal zone and exists solely to support the unit tests.
3739
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)

0 commit comments

Comments
 (0)