Skip to content

[cxx-interop][nfc] Add a ClangImporter request zone. #39435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/swift/Basic/Statistics.def
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ FRONTEND_STATISTIC(Sema, NumUnloadedLazyIterableDeclContexts)
#include "swift/AST/TypeCheckerTypeIDZone.def"
#include "swift/Sema/IDETypeCheckingRequestIDZone.def"
#include "swift/IDE/IDERequestIDZone.def"
#include "swift/ClangImporter/ClangImporterTypeIDZone.def"
#undef SWIFT_REQUEST

#define SWIFT_REQUEST(ZONE, NAME, Sig, Caching, LocOptions) FRONTEND_STATISTIC(SILGen, NAME)
Expand Down
74 changes: 38 additions & 36 deletions include/swift/Basic/TypeIDZones.def
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
//===--- TypeIDZones.def - List of TypeID Zones -----------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This definition file describes the zones for TypeID.
//
//===----------------------------------------------------------------------===//

SWIFT_TYPEID_ZONE(C, 0)
SWIFT_TYPEID_ZONE(AST, 1)

SWIFT_TYPEID_ZONE(Parse, 8)
SWIFT_TYPEID_ZONE(NameLookup, 9)

SWIFT_TYPEID_ZONE(TypeChecker, 10)
SWIFT_TYPEID_ZONE(AccessControl, 11)
SWIFT_TYPEID_ZONE(SILGen, 12)
SWIFT_TYPEID_ZONE(SILOptimizer, 13)
SWIFT_TYPEID_ZONE(TBDGen, 14)

SWIFT_TYPEID_ZONE(IRGen, 20)

SWIFT_TYPEID_ZONE(IDETypeChecking, 97)

SWIFT_TYPEID_ZONE(IDETypes, 136)
SWIFT_TYPEID_ZONE(IDE, 137)

// N.B. This is not a formal zone and exists solely to support the unit tests.
SWIFT_TYPEID_ZONE(ArithmeticEvaluator, 255)
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This definition file describes the zones for TypeID.
//
//===----------------------------------------------------------------------===//

SWIFT_TYPEID_ZONE(C, 0)
SWIFT_TYPEID_ZONE(AST, 1)

SWIFT_TYPEID_ZONE(Parse, 8)
SWIFT_TYPEID_ZONE(NameLookup, 9)

SWIFT_TYPEID_ZONE(TypeChecker, 10)
SWIFT_TYPEID_ZONE(AccessControl, 11)
SWIFT_TYPEID_ZONE(SILGen, 12)
SWIFT_TYPEID_ZONE(SILOptimizer, 13)
SWIFT_TYPEID_ZONE(TBDGen, 14)

SWIFT_TYPEID_ZONE(IRGen, 20)

SWIFT_TYPEID_ZONE(IDETypeChecking, 97)

SWIFT_TYPEID_ZONE(IDETypes, 136)
SWIFT_TYPEID_ZONE(IDE, 137)

SWIFT_TYPEID_ZONE(ClangImporter, 139)

// N.B. This is not a formal zone and exists solely to support the unit tests.
SWIFT_TYPEID_ZONE(ArithmeticEvaluator, 255)
48 changes: 48 additions & 0 deletions include/swift/ClangImporter/ClangImporterRequests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//===--- ClangImporterRequests.h - Clang Importer Requests ------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines clang-importer requests.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_CLANG_IMPORTER_REQUESTS_H
#define SWIFT_CLANG_IMPORTER_REQUESTS_H

#include "swift/AST/SimpleRequest.h"
#include "swift/AST/ASTTypeIDs.h"
#include "swift/AST/EvaluatorDependencies.h"

namespace swift {

#define SWIFT_TYPEID_ZONE ClangImporter
#define SWIFT_TYPEID_HEADER "swift/ClangImporter/ClangImporterTypeIDZone.def"
#include "swift/Basic/DefineTypeIDZone.h"
#undef SWIFT_TYPEID_ZONE
#undef SWIFT_TYPEID_HEADER

// Set up reporting of evaluated requests.
template<typename Request>
void reportEvaluatedRequest(UnifiedStatsReporter &stats,
const Request &request);

#define SWIFT_REQUEST(Zone, RequestType, Sig, Caching, LocOptions) \
template <> \
inline void reportEvaluatedRequest(UnifiedStatsReporter &stats, \
const RequestType &request) { \
++stats.getFrontendCounters().RequestType; \
}
#include "swift/ClangImporter/ClangImporterTypeIDZone.def"
#undef SWIFT_REQUEST

} // end namespace swift

#endif // SWIFT_CLANG_IMPORTER_REQUESTS_H

17 changes: 17 additions & 0 deletions include/swift/ClangImporter/ClangImporterTypeIDZone.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===--- ClangImporterTypeIDZone.def ----------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This definition file describes the types in the clang importer
// TypeID zone, for use with the TypeID template.
//
//===----------------------------------------------------------------------===//

6 changes: 6 additions & 0 deletions include/swift/Subsystems.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,12 @@ namespace swift {
/// Calling registerIDERequestFunctions will invoke this function as well.
void registerIDETypeCheckRequestFunctions(Evaluator &evaluator);

/// Register clang importer request functions with the evaluator.
///
/// Clients that form an ASTContext and import any Clang APIs should call this function
/// after forming the ASTContext.
void registerClangImporterRequestFunctions(Evaluator &evaluator);

/// Register SILOptimizer passes necessary for IRGen.
void registerIRGenSILTransforms(ASTContext &ctx);

Expand Down
1 change: 1 addition & 0 deletions lib/AST/NameLookupRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "swift/AST/Evaluator.h"
#include "swift/AST/Module.h"
#include "swift/AST/SourceFile.h"
#include "swift/ClangImporter/ClangImporterRequests.h"
#include "swift/Subsystems.h"

using namespace swift;
Expand Down
1 change: 1 addition & 0 deletions lib/ClangImporter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_swift_host_library(swiftClangImporter STATIC
ClangAdapter.cpp
ClangDiagnosticConsumer.cpp
ClangImporter.cpp
ClangImporterRequests.cpp
ClangModuleDependencyScanner.cpp
ClangSourceBufferImporter.cpp
DWARFImporter.cpp
Expand Down
37 changes: 37 additions & 0 deletions lib/ClangImporter/ClangImporterRequests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//===--- ClangImporterRequests.cpp - Clang Importer Requests --------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#include "swift/AST/NameLookupRequests.h"
#include "swift/AST/ASTContext.h"
#include "swift/AST/Decl.h"
#include "swift/AST/Evaluator.h"
#include "swift/AST/Module.h"
#include "swift/AST/SourceFile.h"
#include "swift/ClangImporter/ClangImporterRequests.h"
#include "swift/Subsystems.h"

using namespace swift;

// Define request evaluation functions for each of the name lookup requests.
static AbstractRequestFunction *clangImporterRequestFunctions[] = {
nullptr // TODO: remove this whenever a request is actually added.
#define SWIFT_REQUEST(Zone, Name, Sig, Caching, LocOptions) \
reinterpret_cast<AbstractRequestFunction *>(&Name::evaluateRequest),
#include "swift/ClangImporter/ClangImporterTypeIDZone.def"
#undef SWIFT_REQUEST
};

void swift::registerClangImporterRequestFunctions(Evaluator &evaluator) {
evaluator.registerRequestFunctions(Zone::ClangImporter,
clangImporterRequestFunctions);
}

1 change: 1 addition & 0 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ bool CompilerInstance::setUpASTContextIfNeeded() {
SourceMgr, Diagnostics));
registerParseRequestFunctions(Context->evaluator);
registerTypeCheckerRequestFunctions(Context->evaluator);
registerClangImporterRequestFunctions(Context->evaluator);
registerSILGenRequestFunctions(Context->evaluator);
registerSILOptimizerRequestFunctions(Context->evaluator);
registerTBDGenRequestFunctions(Context->evaluator);
Expand Down
1 change: 1 addition & 0 deletions lib/IDE/CompletionInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ bool CompletionInstance::performCachedOperationIfPossible(
registerParseRequestFunctions(tmpCtx->evaluator);
registerIDERequestFunctions(tmpCtx->evaluator);
registerTypeCheckerRequestFunctions(tmpCtx->evaluator);
registerClangImporterRequestFunctions(tmpCtx->evaluator);
registerSILGenRequestFunctions(tmpCtx->evaluator);
ModuleDecl *tmpM = ModuleDecl::create(Identifier(), *tmpCtx);
SourceFile *tmpSF = new (*tmpCtx)
Expand Down
2 changes: 2 additions & 0 deletions tools/swift-ide-test/swift-ide-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,7 @@ static int doSyntaxColoring(const CompilerInvocation &InitInvok,

registerParseRequestFunctions(Parser.getParser().Context.evaluator);
registerTypeCheckerRequestFunctions(Parser.getParser().Context.evaluator);
registerClangImporterRequestFunctions(Parser.getParser().Context.evaluator);

Parser.getDiagnosticEngine().addConsumer(PrintDiags);

Expand Down Expand Up @@ -1887,6 +1888,7 @@ static int doStructureAnnotation(const CompilerInvocation &InitInvok,
registerParseRequestFunctions(Parser.getParser().Context.evaluator);
registerTypeCheckerRequestFunctions(
Parser.getParser().Context.evaluator);
registerClangImporterRequestFunctions(Parser.getParser().Context.evaluator);

// Display diagnostics to stderr.
PrintingDiagnosticConsumer PrintDiags;
Expand Down
1 change: 1 addition & 0 deletions unittests/AST/TestContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ TestContext::TestContext(ShouldDeclareOptionalTypes optionals)
SourceMgr, Diags)) {
registerParseRequestFunctions(Ctx.evaluator);
registerTypeCheckerRequestFunctions(Ctx.evaluator);
registerClangImporterRequestFunctions(Ctx.evaluator);
auto stdlibID = Ctx.getIdentifier(STDLIB_NAME);
auto *module = ModuleDecl::create(stdlibID, Ctx);
Ctx.addLoadedModule(module);
Expand Down
1 change: 1 addition & 0 deletions unittests/Sema/SemaFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ SemaTest::SemaTest()

registerParseRequestFunctions(Context.evaluator);
registerTypeCheckerRequestFunctions(Context.evaluator);
registerClangImporterRequestFunctions(Context.evaluator);

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