Skip to content

Commit

Permalink
[ASTPrinter] Put desugaring constraints for existential types behind a
Browse files Browse the repository at this point in the history
PrintOptions flag that is only enabled for interface printing.
  • Loading branch information
hborla committed May 24, 2022
1 parent e9c14cd commit 38dfb99
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/swift/AST/PrintOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ struct PrintOptions {
/// types.
bool PrintExplicitAny = false;

/// Whether to desugar the constraint for an existential type.
bool DesugarExistentialConstraint = false;

/// Whether to skip keywords with a prefix of underscore such as __consuming.
bool SkipUnderscoredKeywords = false;

Expand Down
7 changes: 6 additions & 1 deletion lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(ModuleDecl *ModuleToPrint,
result.AlwaysTryPrintParameterLabels = true;
result.PrintSPIs = printSPIs;
result.PrintExplicitAny = true;
result.DesugarExistentialConstraint = true;

// We should print __consuming, __owned, etc for the module interface file.
result.SkipUnderscoredKeywords = false;
Expand Down Expand Up @@ -6216,7 +6217,11 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
// interfaces. Verifying that the underlying type of a
// protocol typealias is a constriant type is fundamentally
// circular, so the desugared type should be written in source.
visit(T->getConstraintType()->getDesugaredType());
if (Options.DesugarExistentialConstraint) {
visit(T->getConstraintType()->getDesugaredType());
} else {
visit(T->getConstraintType());
}
}

void visitLValueType(LValueType *T) {
Expand Down

0 comments on commit 38dfb99

Please sign in to comment.