Skip to content

Commit 7bdd72a

Browse files
[AST] Add printing for Clang function types in SIL.
1 parent 8d6781a commit 7bdd72a

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

include/swift/AST/Types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3900,6 +3900,11 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
39003900

39013901
bool empty() const { return !ClangFunctionType; }
39023902
Uncommon(const clang::FunctionType *type) : ClangFunctionType(type) {}
3903+
3904+
public:
3905+
/// Analog of AnyFunctionType::ExtInfo::Uncommon::printClangFunctionType.
3906+
void printClangFunctionType(ClangModuleLoader *cml,
3907+
llvm::raw_ostream &os) const;
39033908
};
39043909

39053910
Uncommon Other;

lib/AST/ASTContext.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3156,6 +3156,11 @@ ArrayRef<Requirement> GenericFunctionType::getRequirements() const {
31563156
return Signature->getRequirements();
31573157
}
31583158

3159+
void SILFunctionType::ExtInfo::Uncommon::printClangFunctionType(
3160+
ClangModuleLoader *cml, llvm::raw_ostream &os) const {
3161+
cml->printClangType(ClangFunctionType, os);
3162+
}
3163+
31593164
void SILFunctionType::Profile(
31603165
llvm::FoldingSetNodeID &id,
31613166
GenericSignature genericParams,

lib/AST/ASTPrinter.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3911,7 +3911,8 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
39113911
}
39123912
}
39133913

3914-
void printFunctionExtInfo(SILFunctionType::ExtInfo info,
3914+
void printFunctionExtInfo(ASTContext &Ctx,
3915+
SILFunctionType::ExtInfo info,
39153916
ProtocolConformanceRef witnessMethodConformance) {
39163917
if (Options.SkipAttributes)
39173918
return;
@@ -3925,10 +3926,19 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
39253926
}
39263927
}
39273928

3928-
if ((Options.PrintFunctionRepresentationAttrs !=
3929-
PrintOptions::FunctionRepresentationMode::None) &&
3930-
!Options.excludeAttrKind(TAK_convention) &&
3931-
info.getRepresentation() != SILFunctionType::Representation::Thick) {
3929+
3930+
SmallString<64> buf;
3931+
switch (Options.PrintFunctionRepresentationAttrs) {
3932+
case PrintOptions::FunctionRepresentationMode::None:
3933+
break;
3934+
case PrintOptions::FunctionRepresentationMode::NameOnly:
3935+
case PrintOptions::FunctionRepresentationMode::Full:
3936+
if (Options.excludeAttrKind(TAK_convention) ||
3937+
info.getRepresentation() == SILFunctionType::Representation::Thick)
3938+
break;
3939+
3940+
bool printNameOnly = Options.PrintFunctionRepresentationAttrs ==
3941+
PrintOptions::FunctionRepresentationMode::NameOnly;
39323942
Printer.callPrintStructurePre(PrintStructureKind::BuiltinAttribute);
39333943
Printer.printAttrName("@convention");
39343944
Printer << "(";
@@ -3943,6 +3953,11 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
39433953
break;
39443954
case SILFunctionType::Representation::CFunctionPointer:
39453955
Printer << "c";
3956+
// FIXME: [clang-function-type-serialization] Once we start serializing
3957+
// Clang function types, we should be able to remove the second check.
3958+
if (printNameOnly || !info.getUncommonInfo().hasValue())
3959+
break;
3960+
printCType(Ctx, Printer, info);
39463961
break;
39473962
case SILFunctionType::Representation::Method:
39483963
Printer << "method";
@@ -4102,7 +4117,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
41024117

41034118
void visitSILFunctionType(SILFunctionType *T) {
41044119
printSILCoroutineKind(T->getCoroutineKind());
4105-
printFunctionExtInfo(T->getExtInfo(),
4120+
printFunctionExtInfo(T->getASTContext(), T->getExtInfo(),
41064121
T->getWitnessMethodConformanceOrInvalid());
41074122
printCalleeConvention(T->getCalleeConvention());
41084123

0 commit comments

Comments
 (0)