Skip to content

Commit e89b534

Browse files
authored
Merge pull request #34514 from varungandhi-apple/vg-irgen-remove-old-clangtypeconverter
2 parents 517bcc4 + 0484f3a commit e89b534

File tree

8 files changed

+34
-789
lines changed

8 files changed

+34
-789
lines changed

include/swift/AST/ASTContext.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,14 @@ class ASTContext final {
640640
/// if applicable.
641641
const Decl *getSwiftDeclForExportedClangDecl(const clang::Decl *decl);
642642

643+
/// General conversion method from Swift types -> Clang types.
644+
///
645+
/// HACK: This method is only intended to be called from a specific place in
646+
/// IRGen. For converting function types, strongly prefer using one of the
647+
/// other methods instead, instead of manually iterating over parameters
648+
/// and results.
649+
const clang::Type *getClangTypeForIRGen(Type ty);
650+
643651
/// Determine whether the given Swift type is representable in a
644652
/// given foreign language.
645653
ForeignRepresentationInfo

lib/AST/ASTContext.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "swift/Subsystems.h"
5555
#include "swift/Syntax/References.h"
5656
#include "swift/Syntax/SyntaxArena.h"
57+
#include "clang/AST/Type.h"
5758
#include "llvm/ADT/DenseMap.h"
5859
#include "llvm/ADT/Statistic.h"
5960
#include "llvm/ADT/StringMap.h"
@@ -4589,6 +4590,10 @@ ASTContext::getSwiftDeclForExportedClangDecl(const clang::Decl *decl) {
45894590
return impl.Converter->getSwiftDeclForExportedClangDecl(decl);
45904591
}
45914592

4593+
const clang::Type *
4594+
ASTContext::getClangTypeForIRGen(Type ty) {
4595+
return getClangTypeConverter().convert(ty).getTypePtrOrNull();
4596+
}
45924597

45934598
CanGenericSignature ASTContext::getSingleGenericParameterSignature() const {
45944599
if (auto theSig = getImpl().SingleGenericParameterSignature)

lib/AST/ClangTypeConverter.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
//
1313
// This file implements generation of Clang AST types from Swift AST types for
1414
// types that are representable in Objective-C interfaces.
15-
// Large chunks of the code are lightly modified versions of the code in
16-
// IRGen/GenClangType.cpp (which should eventually go away), so make sure
17-
// to keep the two in sync.
18-
// The three major differences are that, in this file:
15+
//
16+
// The usage of ClangTypeConverter at the AST level means that we may
17+
// encounter ill-formed types and/or sugared types. To avoid crashing and
18+
// keeping sugar as much as possible (in case the generated Clang type needs
19+
// to be surfaced to the user):
20+
//
1921
// 1. We fail gracefully instead of asserting/UB.
2022
// 2. We try to keep clang sugar instead of discarding it.
21-
// 3. We use getAs instead of cast as we handle Swift types with sugar.
2223
//
2324
//===----------------------------------------------------------------------===//
2425

lib/AST/ClangTypeConverter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class ClangTypeConverter :
9494
SmallVectorImpl<clang::TemplateArgument> &templateArgs);
9595

9696
private:
97+
friend ASTContext; // HACK: expose `convert` method to ASTContext
98+
9799
clang::QualType convert(Type type);
98100

99101
clang::QualType convertMemberType(NominalTypeDecl *DC,

0 commit comments

Comments
 (0)