Skip to content

Commit 95e7fcd

Browse files
committed
Update a bunch of tests and respect PrintSpaceBeforeInheritance in more places
1 parent 9f7c72c commit 95e7fcd

File tree

142 files changed

+818
-803
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+818
-803
lines changed

include/swift/AST/ASTPrinter.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,14 @@ class ASTPrinter {
311311
PendingNewlines++;
312312
}
313313

314+
void printColonForType(const PrintOptions &options)
315+
{
316+
if (options.PrintSpaceBeforeInheritance) {
317+
*this << ' ';
318+
}
319+
*this << ": ";
320+
}
321+
314322
void forceNewlines() {
315323
if (PendingNewlines > 0) {
316324
llvm::SmallString<16> Str;

include/swift/AST/GenericParamList.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ class RequirementRepr {
215215
}
216216

217217
SWIFT_DEBUG_DUMP;
218-
void print(raw_ostream &OS) const;
219-
void print(ASTPrinter &Printer) const;
218+
void print(raw_ostream &OS, const PrintOptions &Options = PrintOptions()) const;
219+
void print(ASTPrinter &Printer, const PrintOptions &Options = PrintOptions()) const;
220220
};
221221

222222
/// GenericParamList - A list of generic parameters that is part of a generic
@@ -400,7 +400,7 @@ class alignas(RequirementRepr) TrailingWhereClause final :
400400
return SourceRange(WhereLoc, EndLoc);
401401
}
402402

403-
void print(llvm::raw_ostream &OS, bool printWhereKeyword) const;
403+
void print(llvm::raw_ostream &OS, const PrintOptions &PO, bool printWhereKeyword) const;
404404

405405
};
406406

include/swift/AST/PrintOptions.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ struct PrintOptions {
585585

586586
/// Whether to print a space before the `:` of an inheritance list in a type
587587
/// decl.
588-
bool PrintSpaceBeforeInheritance = true;
588+
bool PrintSpaceBeforeInheritance = false;
589589

590590
/// Whether to print feature checks for compatibility with older Swift
591591
/// compilers that might parse the result.
@@ -653,15 +653,13 @@ struct PrintOptions {
653653
result.PrintDocumentationComments = true;
654654
result.PrintLongAttrsOnSeparateLines = true;
655655
result.AlwaysTryPrintParameterLabels = true;
656-
result.PrintSpaceBeforeInheritance = false;
657656
return result;
658657
}
659658

660659
/// The print options used for formatting diagnostic arguments.
661660
static PrintOptions forDiagnosticArguments() {
662661
PrintOptions result;
663662
result.PrintExplicitPackTypes = false;
664-
result.PrintSpaceBeforeInheritance = false;
665663
return result;
666664
}
667665

@@ -688,7 +686,6 @@ struct PrintOptions {
688686
if (printFullConvention)
689687
result.PrintFunctionRepresentationAttrs =
690688
PrintOptions::FunctionRepresentationMode::Full;
691-
result.PrintSpaceBeforeInheritance = false;
692689
return result;
693690
}
694691

@@ -714,7 +711,6 @@ struct PrintOptions {
714711
result.MapCrossImportOverlaysToDeclaringModule = true;
715712
result.PrintCurrentMembersOnly = false;
716713
result.SuppressExpandedMacros = true;
717-
result.PrintSpaceBeforeInheritance = false;
718714
return result;
719715
}
720716

@@ -775,6 +771,7 @@ struct PrintOptions {
775771
static PrintOptions printQualifiedSILType() {
776772
PrintOptions result = PrintOptions::printSIL();
777773
result.FullyQualifiedTypesIfAmbiguous = true;
774+
result.PrintSpaceBeforeInheritance = true;
778775
return result;
779776
}
780777

lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ namespace {
14711471
}, label);
14721472
} else {
14731473
printFieldQuotedRaw([&](raw_ostream &OS) {
1474-
Where->print(OS, /*printWhereKeyword*/ false);
1474+
Where->print(OS, PrintOptions(), /*printWhereKeyword*/ false);
14751475
}, label);
14761476
}
14771477
};

lib/AST/ASTPrinter.cpp

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,6 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(ModuleDecl *ModuleToPrint,
254254

255255
// We should provide backward-compatible Swift interfaces when we can.
256256
result.PrintCompatibilityFeatureChecks = true;
257-
258-
// Don't print a space before ':' in inheritance clauses.
259-
result.PrintSpaceBeforeInheritance = false;
260257

261258
result.FunctionBody = [](const ValueDecl *decl, ASTPrinter &printer) {
262259
auto AFD = dyn_cast<AbstractFunctionDecl>(decl);
@@ -901,6 +898,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
901898
FreshOptions.TransformContext = options.TransformContext;
902899
FreshOptions.CurrentModule = options.CurrentModule;
903900
FreshOptions.FullyQualifiedTypesIfAmbiguous = options.FullyQualifiedTypesIfAmbiguous;
901+
FreshOptions.PrintSpaceBeforeInheritance = options.PrintSpaceBeforeInheritance;
904902
T.print(Printer, FreshOptions);
905903
return;
906904
}
@@ -1982,7 +1980,7 @@ void PrintAST::printSingleDepthOfGenericSignature(
19821980
PrintNameContext::GenericParameter);
19831981

19841982
if (param->isValue()) {
1985-
Printer << " : ";
1983+
Printer.printColonForType(Options);
19861984
printType(param->getValueType());
19871985
}
19881986

@@ -1995,7 +1993,7 @@ void PrintAST::printSingleDepthOfGenericSignature(
19951993
printType(param);
19961994

19971995
if (param->isValue()) {
1998-
Printer << " : ";
1996+
Printer.printColonForType(Options);
19991997
printType(param->getValueType());
20001998
}
20011999
}
@@ -2039,7 +2037,7 @@ void PrintAST::printSingleDepthOfGenericSignature(
20392037
if (printRequirements)
20402038
Printer << " " << tok::kw_where << " ";
20412039
else
2042-
Printer << " : ";
2040+
Printer.printColonForType(Options);
20432041

20442042
isFirstReq = false;
20452043
} else {
@@ -2088,7 +2086,8 @@ void PrintAST::printSingleDepthOfGenericSignature(
20882086
if (printRequirements)
20892087
Printer << " " << tok::kw_where << " ";
20902088
else
2091-
Printer << " : ";
2089+
2090+
Printer.printColonForType(Options);
20922091

20932092
isFirstReq = false;
20942093
} else {
@@ -2174,21 +2173,23 @@ void PrintAST::printRequirement(const Requirement &req) {
21742173
printTransformedType(req.getFirstType());
21752174
Printer << ", ";
21762175
printTransformedType(req.getSecondType());
2177-
Printer << ")) : Any";
2176+
Printer << "))";
2177+
Printer.printColonForType(Options);
2178+
Printer << "Any";
21782179
return;
21792180
case RequirementKind::Layout:
21802181
if (isPackRequirement)
21812182
Printer << "repeat ";
21822183
printTransformedType(req.getFirstType());
2183-
Printer << " : ";
2184+
Printer.printColonForType(Options);
21842185
req.getLayoutConstraint()->print(Printer, Options);
21852186
return;
21862187
case RequirementKind::Conformance:
21872188
case RequirementKind::Superclass:
21882189
if (isPackRequirement)
21892190
Printer << "repeat ";
21902191
printTransformedType(req.getFirstType());
2191-
Printer << " : ";
2192+
Printer.printColonForType(Options);
21922193
break;
21932194
case RequirementKind::SameType:
21942195
if (isPackRequirement)
@@ -2205,7 +2206,7 @@ void PrintAST::printRequirement(const InverseRequirement &inverse,
22052206
if (!forInherited) {
22062207
Printer.callPrintStructurePre(PrintStructureKind::GenericRequirement);
22072208
printTransformedType(inverse.subject);
2208-
Printer << " : ";
2209+
Printer.printColonForType(Options);
22092210
Printer.printStructurePost(PrintStructureKind::GenericRequirement);
22102211
}
22112212

@@ -2933,10 +2934,7 @@ void PrintAST::printInherited(const Decl *decl) {
29332934
if (TypesToPrint.empty())
29342935
return;
29352936

2936-
if (Options.PrintSpaceBeforeInheritance) {
2937-
Printer << " ";
2938-
}
2939-
Printer << ": ";
2937+
Printer.printColonForType(Options);
29402938

29412939
interleave(TypesToPrint, [&](InheritedEntry inherited) {
29422940
printTypeLoc(inherited, [&] {
@@ -4630,8 +4628,10 @@ void PrintAST::visitInfixOperatorDecl(InfixOperatorDecl *decl) {
46304628
[&]{
46314629
Printer.printName(decl->getName());
46324630
});
4633-
if (auto *group = decl->getPrecedenceGroup())
4634-
Printer << " : " << group->getName();
4631+
if (auto *group = decl->getPrecedenceGroup()) {
4632+
Printer.printColonForType(Options);
4633+
Printer << group->getName();
4634+
}
46354635
}
46364636

46374637
void PrintAST::visitPrecedenceGroupDecl(PrecedenceGroupDecl *decl) {
@@ -6339,7 +6339,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
63396339
if (T->isDictionary()) {
63406340
Printer << "[";
63416341
visit(T->getGenericArgs()[0]);
6342-
Printer << " : ";
6342+
Printer.printColonForType(Options);
63436343
visit(T->getGenericArgs()[1]);
63446344
Printer << "]";
63456345
return;
@@ -7126,7 +7126,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
71267126
} else {
71277127
Printer << "[";
71287128
visit(T->getKeyType());
7129-
Printer << " : ";
7129+
Printer << ": ";
71307130
visit(T->getValueType());
71317131
Printer << "]";
71327132
}
@@ -8163,43 +8163,43 @@ swift::getInheritedForPrinting(
81638163
// Generic param list printing.
81648164
//===----------------------------------------------------------------------===//
81658165

8166-
void RequirementRepr::print(raw_ostream &out) const {
8166+
void RequirementRepr::print(raw_ostream &out, const PrintOptions &options) const {
81678167
StreamPrinter printer(out);
8168-
print(printer);
8168+
print(printer, options);
81698169
}
81708170

8171-
void RequirementRepr::print(ASTPrinter &out) const {
8171+
void RequirementRepr::print(ASTPrinter &out, const PrintOptions &options) const {
81728172
auto printLayoutConstraint =
81738173
[&](const LayoutConstraintLoc &LayoutConstraintLoc) {
8174-
LayoutConstraintLoc.getLayoutConstraint()->print(out, PrintOptions());
8174+
LayoutConstraintLoc.getLayoutConstraint()->print(out, options);
81758175
};
81768176

81778177
switch (getKind()) {
81788178
case RequirementReprKind::LayoutConstraint:
81798179
if (auto *repr = getSubjectRepr()) {
8180-
repr->print(out, PrintOptions());
8180+
repr->print(out, options);
81818181
}
8182-
out << " : ";
8182+
out.printColonForType(options);
81838183
printLayoutConstraint(getLayoutConstraintLoc());
81848184
break;
81858185

81868186
case RequirementReprKind::TypeConstraint:
81878187
if (auto *repr = getSubjectRepr()) {
8188-
repr->print(out, PrintOptions());
8188+
repr->print(out, options);
81898189
}
8190-
out << " : ";
8190+
out.printColonForType(options);
81918191
if (auto *repr = getConstraintRepr()) {
8192-
repr->print(out, PrintOptions());
8192+
repr->print(out, options);
81938193
}
81948194
break;
81958195

81968196
case RequirementReprKind::SameType:
81978197
if (auto *repr = getFirstTypeRepr()) {
8198-
repr->print(out, PrintOptions());
8198+
repr->print(out, options);
81998199
}
82008200
out << " == ";
82018201
if (auto *repr = getSecondTypeRepr()) {
8202-
repr->print(out, PrintOptions());
8202+
repr->print(out, options);
82038203
}
82048204
break;
82058205
}
@@ -8212,6 +8212,7 @@ void GenericParamList::print(raw_ostream &out, const PrintOptions &PO) const {
82128212

82138213
static void printTrailingRequirements(ASTPrinter &Printer,
82148214
ArrayRef<RequirementRepr> Reqs,
8215+
const PrintOptions &Options,
82158216
bool printWhereKeyword) {
82168217
if (Reqs.empty())
82178218
return;
@@ -8222,7 +8223,7 @@ static void printTrailingRequirements(ASTPrinter &Printer,
82228223
Reqs,
82238224
[&](const RequirementRepr &req) {
82248225
Printer.callPrintStructurePre(PrintStructureKind::GenericRequirement);
8225-
req.print(Printer);
8226+
req.print(Printer, Options);
82268227
Printer.printStructurePost(PrintStructureKind::GenericRequirement);
82278228
},
82288229
[&] { Printer << ", "; });
@@ -8236,7 +8237,7 @@ void GenericParamList::print(ASTPrinter &Printer,
82368237
[&](const GenericTypeParamDecl *P) {
82378238
Printer << P->getName();
82388239
if (!P->getInherited().empty()) {
8239-
Printer << " : ";
8240+
Printer.printColonForType(PO);
82408241

82418242
auto loc = P->getInherited().getEntry(0);
82428243
if (willUseTypeReprPrinting(loc, nullptr, PO)) {
@@ -8248,13 +8249,15 @@ void GenericParamList::print(ASTPrinter &Printer,
82488249
},
82498250
[&] { Printer << ", "; });
82508251

8251-
printTrailingRequirements(Printer, getRequirements(),
8252+
printTrailingRequirements(Printer, getRequirements(), PO,
82528253
/*printWhereKeyword*/ true);
82538254
Printer << '>';
82548255
}
82558256

82568257
void TrailingWhereClause::print(llvm::raw_ostream &OS,
8258+
const PrintOptions &PO,
82578259
bool printWhereKeyword) const {
82588260
StreamPrinter Printer(OS);
8259-
printTrailingRequirements(Printer, getRequirements(), printWhereKeyword);
8261+
printTrailingRequirements(Printer, getRequirements(), PO,
8262+
printWhereKeyword);
82608263
}

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ TypeAliasRequirementsRequest::evaluate(Evaluator &evaluator,
11951195
if (!assocType->getInherited().empty())
11961196
out << ", ";
11971197

1198-
whereClause->print(out, /*printWhereKeyword*/false);
1198+
whereClause->print(out, PrintOptions(), /*printWhereKeyword*/false);
11991199
}
12001200
}
12011201
return result;

lib/AST/TypeRepr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ void DictionaryTypeRepr::printImpl(ASTPrinter &Printer,
500500
const PrintOptions &Opts) const {
501501
Printer << "[";
502502
printTypeRepr(Key, Printer, Opts);
503-
Printer << " : ";
503+
Printer.printColonForType(Opts);
504504
printTypeRepr(Value, Printer, Opts);
505505
Printer << "]";
506506
}

lib/Frontend/ModuleInterfaceSupport.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,16 +822,22 @@ class InheritedProtocolCollector {
822822
out << "@_spi(" << DummyProtocolName << ")\n";
823823
out << "@available(*, unavailable)\nextension ";
824824
nominal->getDeclaredType().print(out, printOptions);
825-
out << " : ";
825+
if (printOptions.PrintSpaceBeforeInheritance) {
826+
out << ' ';
827+
}
828+
out << ": ";
826829
llvm::interleave(
827830
conformanceProtos,
828831
[&out, &printOptions](const ProtocolType *protoTy) {
829832
protoTy->print(out, printOptions);
830833
},
831834
[&out] { out << ", "; });
832835
out << " where "
833-
<< nominal->getGenericSignature().getGenericParams()[0]->getName()
834-
<< " : " << DummyProtocolName << " {}\n";
836+
<< nominal->getGenericSignature().getGenericParams()[0]->getName();
837+
if (printOptions.PrintSpaceBeforeInheritance) {
838+
out << ' ';
839+
}
840+
out << ": " << DummyProtocolName << " {}\n";
835841
};
836842

837843
// We have to print conformances for invertible protocols in separate

lib/SIL/IR/SILPrinter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4844,6 +4844,7 @@ PrintOptions PrintOptions::printSIL(const SILPrintContext *ctx) {
48444844
result.AbstractAccessors = false;
48454845
result.PrintForSIL = true;
48464846
result.PrintInSILBody = true;
4847+
result.PrintSpaceBeforeInheritance = true;
48474848
result.PreferTypeRepr = false;
48484849
result.OpaqueReturnTypePrinting =
48494850
OpaqueReturnTypePrintingMode::StableReference;

test/APINotes/properties.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// REQUIRES: objc_interop
88

99

10-
// CHECK-BOTH-LABEL: class TestProperties : Base {
10+
// CHECK-BOTH-LABEL: class TestProperties: Base {
1111

1212
// CHECK-BOTH-DAG: func accessorsOnly() -> Any
1313
// CHECK-BOTH-DAG: func setAccessorsOnly(_ accessorsOnly: Any)
@@ -34,7 +34,7 @@
3434

3535
// CHECK-BOTH: {{^}$}}
3636

37-
// CHECK-BOTH-LABEL: class TestPropertiesSub : TestProperties {
37+
// CHECK-BOTH-LABEL: class TestPropertiesSub: TestProperties {
3838
// CHECK-BOTH-DAG: func accessorsOnly() -> Any
3939
// CHECK-BOTH-DAG: func setAccessorsOnly(_ accessorsOnly: Any)
4040
// CHECK-BOTH-DAG: class func accessorsOnlyForClass() -> Any

0 commit comments

Comments
 (0)