Skip to content

Commit 596961c

Browse files
authored
Merge pull request #29033 from apple/revert-28737-vg-v3-clang-types-in-swiftinterface
Revert "Clang function types v2: Electric Boogaloo (parsing + printing)"
2 parents 2e7e81e + e805fe4 commit 596961c

22 files changed

+22
-276
lines changed

include/swift/AST/ASTPrinter.h

-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define SWIFT_AST_ASTPRINTER_H
1515

1616
#include "swift/Basic/LLVM.h"
17-
#include "swift/Basic/QuotedString.h"
1817
#include "swift/Basic/UUID.h"
1918
#include "swift/AST/Identifier.h"
2019
#include "llvm/ADT/StringRef.h"
@@ -186,8 +185,6 @@ class ASTPrinter {
186185
return *this;
187186
}
188187

189-
ASTPrinter &operator<<(QuotedString s);
190-
191188
ASTPrinter &operator<<(unsigned long long N);
192189
ASTPrinter &operator<<(UUID UU);
193190

include/swift/AST/ClangModuleLoader.h

-11
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class CompilerInstance;
2121
class Preprocessor;
2222
class Sema;
2323
class TargetInfo;
24-
class Type;
2524
} // namespace clang
2625

2726
namespace swift {
@@ -101,16 +100,6 @@ class ClangModuleLoader : public ModuleLoader {
101100
lookupRelatedEntity(StringRef clangName, ClangTypeKind kind,
102101
StringRef relatedEntityKind,
103102
llvm::function_ref<void(TypeDecl *)> receiver) = 0;
104-
105-
/// Try to parse the string as a Clang function type.
106-
///
107-
/// Returns null if there was a parsing failure.
108-
virtual const clang::Type *parseClangFunctionType(StringRef type,
109-
SourceLoc loc) const = 0;
110-
111-
/// Print the Clang type.
112-
virtual void printClangType(const clang::Type *type,
113-
llvm::raw_ostream &os) const = 0;
114103
};
115104

116105
} // namespace swift

include/swift/AST/DiagnosticsSema.def

-7
Original file line numberDiff line numberDiff line change
@@ -3924,13 +3924,6 @@ ERROR(unsupported_convention,none,
39243924
"convention '%0' not supported", (StringRef))
39253925
ERROR(unreferenced_generic_parameter,none,
39263926
"generic parameter '%0' is not used in function signature", (StringRef))
3927-
ERROR(unexpected_ctype_for_non_c_convention,none,
3928-
"convention '%0' does not support the 'cType' argument label, did you "
3929-
"mean @convention(c, cType: \"%1\") or @convention(block, cType: \"%1\") "
3930-
"instead?", (StringRef, StringRef))
3931-
ERROR(unable_to_parse_c_function_type,none,
3932-
"unable to parse '%0'; it should be a C function pointer type or a "
3933-
"block pointer type", (StringRef))
39343927

39353928
// Opaque types
39363929
ERROR(unsupported_opaque_type,none,

include/swift/AST/PrintOptions.h

+3-18
Original file line numberDiff line numberDiff line change
@@ -306,21 +306,8 @@ struct PrintOptions {
306306
/// List of decls that should be printed even if they are implicit and \c SkipImplicit is set to true.
307307
std::vector<const Decl*> TreatAsExplicitDeclList;
308308

309-
enum class FunctionRepresentationMode : uint8_t {
310-
/// Print the entire convention, including an arguments.
311-
/// For example, this will print a cType argument label if applicable.
312-
Full,
313-
/// Print only the name of the convention, skipping extra argument labels.
314-
NameOnly,
315-
/// Skip printing the @convention(..) altogether.
316-
None
317-
};
318-
319309
/// Whether to print function @convention attribute on function types.
320-
// FIXME: [clang-function-type-serialization] Once we start serializing Clang
321-
// types, we should also start printing the full type in the swiftinterface.
322-
FunctionRepresentationMode PrintFunctionRepresentationAttrs =
323-
FunctionRepresentationMode::NameOnly;
310+
bool PrintFunctionRepresentationAttrs = true;
324311

325312
/// Whether to print storage representation attributes on types, e.g.
326313
/// '@sil_weak', '@sil_unmanaged'.
@@ -515,8 +502,7 @@ struct PrintOptions {
515502
/// consistent and well-formed.
516503
///
517504
/// \see swift::emitSwiftInterface
518-
static PrintOptions printSwiftInterfaceFile(bool preferTypeRepr,
519-
bool printFullConvention);
505+
static PrintOptions printSwiftInterfaceFile(bool preferTypeRepr);
520506

521507
/// Retrieve the set of options suitable for "Generated Interfaces", which
522508
/// are a prettified representation of the public API of a module, to be
@@ -599,8 +585,7 @@ struct PrintOptions {
599585
PO.SkipUnderscoredKeywords = true;
600586
PO.EnumRawValues = EnumRawValueMode::Print;
601587
PO.PrintImplicitAttrs = false;
602-
PO.PrintFunctionRepresentationAttrs =
603-
PrintOptions::FunctionRepresentationMode::None;
588+
PO.PrintFunctionRepresentationAttrs = false;
604589
PO.PrintDocumentationComments = false;
605590
PO.ExcludeAttrList.push_back(DAK_Available);
606591
PO.SkipPrivateStdlibDecls = true;

include/swift/AST/Types.h

-16
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class AssociatedTypeDecl;
5959
class ASTContext;
6060
enum BufferPointerTypeKind : unsigned;
6161
class ClassDecl;
62-
class ClangModuleLoader;
6362
class DependentMemberType;
6463
class GenericTypeParamDecl;
6564
class GenericTypeParamType;
@@ -2951,11 +2950,6 @@ class AnyFunctionType : public TypeBase {
29512950

29522951
bool empty() const { return !ClangFunctionType; }
29532952
Uncommon(const clang::Type *type) : ClangFunctionType(type) {}
2954-
2955-
public:
2956-
/// Use the ClangModuleLoader to print the Clang type as a string.
2957-
void printClangFunctionType(ClangModuleLoader *cml,
2958-
llvm::raw_ostream &os);
29592953
};
29602954

29612955
private:
@@ -3900,11 +3894,6 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
39003894

39013895
bool empty() const { return !ClangFunctionType; }
39023896
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;
39083897
};
39093898

39103899
Uncommon Other;
@@ -3958,11 +3947,6 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
39583947
return getSILFunctionLanguage(getRepresentation());
39593948
}
39603949

3961-
/// Return the underlying Uncommon value if it is not the default value.
3962-
Optional<Uncommon> getUncommonInfo() const {
3963-
return Other.empty() ? Optional<Uncommon>() : Other;
3964-
}
3965-
39663950
bool hasSelfParam() const {
39673951
switch (getRepresentation()) {
39683952
case Representation::Thick:

include/swift/ClangImporter/ClangImporter.h

-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ namespace clang {
4040
class NamedDecl;
4141
class Sema;
4242
class TargetInfo;
43-
class Type;
4443
class VisibleDeclConsumer;
4544
class DeclarationName;
4645
}
@@ -417,11 +416,6 @@ class ClangImporter final : public ClangModuleLoader {
417416
/// with -import-objc-header option.
418417
getPCHFilename(const ClangImporterOptions &ImporterOptions,
419418
StringRef SwiftPCHHash, bool &isExplicit);
420-
421-
const clang::Type *parseClangFunctionType(StringRef type,
422-
SourceLoc loc) const override;
423-
void printClangType(const clang::Type *type,
424-
llvm::raw_ostream &os) const override;
425419
};
426420

427421
ImportDecl *createImportDecl(ASTContext &Ctx, DeclContext *DC, ClangNode ClangN,

include/swift/Frontend/ModuleInterfaceSupport.h

-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ struct ModuleInterfaceOptions {
3131
/// interface, or should we fully-qualify them?
3232
bool PreserveTypesAsWritten = false;
3333

34-
/// Should we emit the cType when printing @convention(c) or no?
35-
/// FIXME: [clang-function-type-serialization] This check should go away.
36-
bool PrintFullConvention = false;
37-
3834
/// Copy of all the command-line flags passed at .swiftinterface
3935
/// generation time, re-applied to CompilerInvocation when reading
4036
/// back .swiftinterface and reconstructing .swiftmodule.

include/swift/Option/FrontendOptions.td

-5
Original file line numberDiff line numberDiff line change
@@ -602,11 +602,6 @@ def module_interface_preserve_types_as_written :
602602
HelpText<"When emitting a module interface, preserve types as they were "
603603
"written in the source">;
604604

605-
def experimental_print_full_convention :
606-
Flag<["-"], "experimental-print-full-convention">,
607-
HelpText<"When emitting a module interface, emit additional @convention "
608-
"arguments, regardless of whether they were written in the source">;
609-
610605
def prebuilt_module_cache_path :
611606
Separate<["-"], "prebuilt-module-cache-path">,
612607
HelpText<"Directory of prebuilt modules for loading module interfaces">;

lib/AST/ASTContext.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -3156,11 +3156,6 @@ 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-
31643159
void SILFunctionType::Profile(
31653160
llvm::FoldingSetNodeID &id,
31663161
GenericSignature genericParams,

lib/AST/ASTPrinter.cpp

+12-64
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "swift/AST/ASTMangler.h"
2020
#include "swift/AST/ASTVisitor.h"
2121
#include "swift/AST/Attr.h"
22-
#include "swift/AST/ClangModuleLoader.h"
2322
#include "swift/AST/Comment.h"
2423
#include "swift/AST/Decl.h"
2524
#include "swift/AST/Expr.h"
@@ -99,8 +98,7 @@ static bool contributesToParentTypeStorage(const AbstractStorageDecl *ASD) {
9998
return !ND->isResilient() && ASD->hasStorage() && !ASD->isStatic();
10099
}
101100

102-
PrintOptions PrintOptions::printSwiftInterfaceFile(bool preferTypeRepr,
103-
bool printFullConvention) {
101+
PrintOptions PrintOptions::printSwiftInterfaceFile(bool preferTypeRepr) {
104102
PrintOptions result;
105103
result.PrintLongAttrsOnSeparateLines = true;
106104
result.TypeDefinitions = true;
@@ -117,9 +115,6 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(bool preferTypeRepr,
117115
result.OpaqueReturnTypePrinting =
118116
OpaqueReturnTypePrintingMode::StableReference;
119117
result.PreferTypeRepr = preferTypeRepr;
120-
if (printFullConvention)
121-
result.PrintFunctionRepresentationAttrs =
122-
PrintOptions::FunctionRepresentationMode::Full;
123118

124119
// We should print __consuming, __owned, etc for the module interface file.
125120
result.SkipUnderscoredKeywords = false;
@@ -326,14 +321,6 @@ void ASTPrinter::callPrintDeclPre(const Decl *D,
326321
printDeclPre(D, Bracket);
327322
}
328323

329-
ASTPrinter &ASTPrinter::operator<<(QuotedString s) {
330-
llvm::SmallString<32> Str;
331-
llvm::raw_svector_ostream OS(Str);
332-
OS << s;
333-
printTextImpl(OS.str());
334-
return *this;
335-
}
336-
337324
ASTPrinter &ASTPrinter::operator<<(unsigned long long N) {
338325
llvm::SmallString<32> Str;
339326
llvm::raw_svector_ostream OS(Str);
@@ -3491,15 +3478,6 @@ void Pattern::print(llvm::raw_ostream &OS, const PrintOptions &Options) const {
34913478
// Type Printing
34923479
//===----------------------------------------------------------------------===//
34933480

3494-
template <typename ExtInfo>
3495-
void printCType(ASTContext &Ctx, ASTPrinter &Printer, ExtInfo &info) {
3496-
auto *cml = Ctx.getClangModuleLoader();
3497-
SmallString<64> buf;
3498-
llvm::raw_svector_ostream os(buf);
3499-
info.getUncommonInfo().getValue().printClangFunctionType(cml, os);
3500-
Printer << ", cType: " << QuotedString(os.str());
3501-
}
3502-
35033481
namespace {
35043482
class TypePrinter : public TypeVisitor<TypePrinter> {
35053483
using super = TypeVisitor;
@@ -3862,7 +3840,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
38623840
visit(staticSelfT);
38633841
}
38643842

3865-
void printFunctionExtInfo(ASTContext &Ctx, AnyFunctionType::ExtInfo info) {
3843+
void printFunctionExtInfo(AnyFunctionType::ExtInfo info) {
38663844
if (Options.SkipAttributes)
38673845
return;
38683846

@@ -3875,18 +3853,9 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
38753853
}
38763854
}
38773855

3878-
SmallString<64> buf;
3879-
switch (Options.PrintFunctionRepresentationAttrs) {
3880-
case PrintOptions::FunctionRepresentationMode::None:
3881-
return;
3882-
case PrintOptions::FunctionRepresentationMode::Full:
3883-
case PrintOptions::FunctionRepresentationMode::NameOnly:
3884-
if (Options.excludeAttrKind(TAK_convention) ||
3885-
info.getSILRepresentation() == SILFunctionType::Representation::Thick)
3886-
return;
3887-
3888-
bool printNameOnly = Options.PrintFunctionRepresentationAttrs ==
3889-
PrintOptions::FunctionRepresentationMode::NameOnly;
3856+
if (Options.PrintFunctionRepresentationAttrs &&
3857+
!Options.excludeAttrKind(TAK_convention) &&
3858+
info.getSILRepresentation() != SILFunctionType::Representation::Thick) {
38903859
Printer.callPrintStructurePre(PrintStructureKind::BuiltinAttribute);
38913860
Printer.printAttrName("@convention");
38923861
Printer << "(";
@@ -3902,11 +3871,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
39023871
break;
39033872
case SILFunctionType::Representation::CFunctionPointer:
39043873
Printer << "c";
3905-
// FIXME: [clang-function-type-serialization] Once we start serializing
3906-
// Clang function types, we should be able to remove the second check.
3907-
if (printNameOnly || !info.getUncommonInfo().hasValue())
3908-
break;
3909-
printCType(Ctx, Printer, info);
39103874
break;
39113875
case SILFunctionType::Representation::Method:
39123876
Printer << "method";
@@ -3927,8 +3891,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
39273891
}
39283892
}
39293893

3930-
void printFunctionExtInfo(ASTContext &Ctx,
3931-
SILFunctionType::ExtInfo info,
3894+
void printFunctionExtInfo(SILFunctionType::ExtInfo info,
39323895
ProtocolConformanceRef witnessMethodConformance) {
39333896
if (Options.SkipAttributes)
39343897
return;
@@ -3942,19 +3905,9 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
39423905
}
39433906
}
39443907

3945-
3946-
SmallString<64> buf;
3947-
switch (Options.PrintFunctionRepresentationAttrs) {
3948-
case PrintOptions::FunctionRepresentationMode::None:
3949-
break;
3950-
case PrintOptions::FunctionRepresentationMode::NameOnly:
3951-
case PrintOptions::FunctionRepresentationMode::Full:
3952-
if (Options.excludeAttrKind(TAK_convention) ||
3953-
info.getRepresentation() == SILFunctionType::Representation::Thick)
3954-
break;
3955-
3956-
bool printNameOnly = Options.PrintFunctionRepresentationAttrs ==
3957-
PrintOptions::FunctionRepresentationMode::NameOnly;
3908+
if (Options.PrintFunctionRepresentationAttrs &&
3909+
!Options.excludeAttrKind(TAK_convention) &&
3910+
info.getRepresentation() != SILFunctionType::Representation::Thick) {
39583911
Printer.callPrintStructurePre(PrintStructureKind::BuiltinAttribute);
39593912
Printer.printAttrName("@convention");
39603913
Printer << "(";
@@ -3969,11 +3922,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
39693922
break;
39703923
case SILFunctionType::Representation::CFunctionPointer:
39713924
Printer << "c";
3972-
// FIXME: [clang-function-type-serialization] Once we start serializing
3973-
// Clang function types, we should be able to remove the second check.
3974-
if (printNameOnly || !info.getUncommonInfo().hasValue())
3975-
break;
3976-
printCType(Ctx, Printer, info);
39773925
break;
39783926
case SILFunctionType::Representation::Method:
39793927
Printer << "method";
@@ -4043,7 +3991,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
40433991
Printer.printStructurePost(PrintStructureKind::FunctionType);
40443992
};
40453993

4046-
printFunctionExtInfo(T->getASTContext(), T->getExtInfo());
3994+
printFunctionExtInfo(T->getExtInfo());
40473995

40483996
// If we're stripping argument labels from types, do it when printing.
40493997
visitAnyFunctionTypeParams(T->getParams(), /*printLabels*/false);
@@ -4080,7 +4028,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
40804028
Printer.printStructurePost(PrintStructureKind::FunctionType);
40814029
};
40824030

4083-
printFunctionExtInfo(T->getASTContext(), T->getExtInfo());
4031+
printFunctionExtInfo(T->getExtInfo());
40844032
printGenericSignature(T->getGenericSignature(),
40854033
PrintAST::PrintParams |
40864034
PrintAST::PrintRequirements);
@@ -4133,7 +4081,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
41334081

41344082
void visitSILFunctionType(SILFunctionType *T) {
41354083
printSILCoroutineKind(T->getCoroutineKind());
4136-
printFunctionExtInfo(T->getASTContext(), T->getExtInfo(),
4084+
printFunctionExtInfo(T->getExtInfo(),
41374085
T->getWitnessMethodConformanceOrInvalid());
41384086
printCalleeConvention(T->getCalleeConvention());
41394087

lib/AST/Type.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "swift/AST/Types.h"
1818
#include "ForeignRepresentationInfo.h"
1919
#include "swift/AST/ASTContext.h"
20-
#include "swift/AST/ClangModuleLoader.h"
2120
#include "swift/AST/ExistentialLayout.h"
2221
#include "swift/AST/ReferenceCounting.h"
2322
#include "swift/AST/TypeCheckRequests.h"
@@ -3240,11 +3239,6 @@ Type ProtocolCompositionType::get(const ASTContext &C,
32403239
return build(C, CanTypes, HasExplicitAnyObject);
32413240
}
32423241

3243-
void AnyFunctionType::ExtInfo::Uncommon::printClangFunctionType(
3244-
ClangModuleLoader *cml, llvm::raw_ostream &os) {
3245-
cml->printClangType(ClangFunctionType, os);
3246-
}
3247-
32483242
void
32493243
AnyFunctionType::ExtInfo::assertIsFunctionType(const clang::Type *type) {
32503244
#ifndef NDEBUG

0 commit comments

Comments
 (0)