Skip to content

Commit ae60159

Browse files
committed
[ModulePrint] Add the initial implementation for printing synthesized extensions.
For a concrete type, members from its conforming protocols' extensions can be hard to manually surface. In this commit, when printing Swift modules, we start to replicate these extensions and synthesize them as if they are the concrete type's native extensions. Credit to Doug for suggesting this practice.
1 parent 35bce55 commit ae60159

File tree

9 files changed

+352
-65
lines changed

9 files changed

+352
-65
lines changed

include/swift/AST/PrintOptions.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace swift {
2020
class GenericParamList;
2121
class CanType;
2222
class ExtensionDecl;
23+
class NominalTypeDecl;
2324
class TypeBase;
2425
class DeclContext;
2526
class Type;
@@ -205,6 +206,8 @@ struct PrintOptions {
205206

206207
std::shared_ptr<PrinterArchetypeTransformer> pTransformer;
207208

209+
NominalTypeDecl *SynthesizedTarget = nullptr;
210+
208211
/// Retrieve the set of options for verbose printing to users.
209212
static PrintOptions printVerbose() {
210213
PrintOptions result;
@@ -247,8 +250,13 @@ struct PrintOptions {
247250
}
248251

249252
static PrintOptions printTypeInterface(Type T, const DeclContext *DC);
253+
250254
void setArchetypeTransform(Type T, const DeclContext *DC);
251255

256+
void initArchetypeTransformerForSynthesizedExtensions(NominalTypeDecl *D);
257+
258+
void clearArchetypeTransformerForSynthesizedExtensions();
259+
252260
/// Retrieve the print options that are suitable to print the testable interface.
253261
static PrintOptions printTestableInterface() {
254262
PrintOptions result = printInterface();

include/swift/IDE/ModuleInterfacePrinting.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ typedef OptionSet<ModuleTraversal> ModuleTraversalOptions;
4040

4141
void printModuleInterface(ModuleDecl *M,
4242
ModuleTraversalOptions TraversalOptions,
43-
ASTPrinter &Printer, const PrintOptions &Options);
43+
ASTPrinter &Printer, const PrintOptions &Options,
44+
const bool PrintSynthesizedExtensions);
4445

4546
// FIXME: this API should go away when Swift can represent Clang submodules as
4647
// 'swift::Module *' objects.
4748
void printSubmoduleInterface(ModuleDecl *M, ArrayRef<StringRef> FullModuleName,
4849
ModuleTraversalOptions TraversalOptions,
49-
ASTPrinter &Printer, const PrintOptions &Options);
50+
ASTPrinter &Printer, const PrintOptions &Options,
51+
const bool PrintSynthesizedExtensions);
5052

5153
/// Print the interface for a header that has been imported via the implicit
5254
/// objc header importing feature.

0 commit comments

Comments
 (0)