Skip to content

Commit f48dd8d

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

File tree

136 files changed

+785
-776
lines changed

Some content is hidden

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

136 files changed

+785
-776
lines changed

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/ASTPrinter.cpp

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
901901
FreshOptions.TransformContext = options.TransformContext;
902902
FreshOptions.CurrentModule = options.CurrentModule;
903903
FreshOptions.FullyQualifiedTypesIfAmbiguous = options.FullyQualifiedTypesIfAmbiguous;
904+
FreshOptions.PrintSpaceBeforeInheritance = options.PrintSpaceBeforeInheritance;
904905
T.print(Printer, FreshOptions);
905906
return;
906907
}
@@ -1768,6 +1769,14 @@ static unsigned getDepthOfRequirement(const Requirement &req) {
17681769
llvm_unreachable("bad RequirementKind");
17691770
}
17701771

1772+
static void printColonForInheritance(ASTPrinter &printer, const PrintOptions &options)
1773+
{
1774+
if (options.PrintSpaceBeforeInheritance) {
1775+
printer << ' ';
1776+
}
1777+
printer << ": ";
1778+
}
1779+
17711780
void PrintAST::printGenericSignature(GenericSignature genericSig,
17721781
unsigned flags) {
17731782
ASSERT(!((flags & InnermostOnly) && (flags & PrintInverseRequirements))
@@ -1982,7 +1991,7 @@ void PrintAST::printSingleDepthOfGenericSignature(
19821991
PrintNameContext::GenericParameter);
19831992

19841993
if (param->isValue()) {
1985-
Printer << " : ";
1994+
printColonForInheritance(Printer, Options);
19861995
printType(param->getValueType());
19871996
}
19881997

@@ -1995,7 +2004,7 @@ void PrintAST::printSingleDepthOfGenericSignature(
19952004
printType(param);
19962005

19972006
if (param->isValue()) {
1998-
Printer << " : ";
2007+
printColonForInheritance(Printer, Options);
19992008
printType(param->getValueType());
20002009
}
20012010
}
@@ -2039,7 +2048,7 @@ void PrintAST::printSingleDepthOfGenericSignature(
20392048
if (printRequirements)
20402049
Printer << " " << tok::kw_where << " ";
20412050
else
2042-
Printer << " : ";
2051+
printColonForInheritance(Printer, Options);
20432052

20442053
isFirstReq = false;
20452054
} else {
@@ -2088,7 +2097,8 @@ void PrintAST::printSingleDepthOfGenericSignature(
20882097
if (printRequirements)
20892098
Printer << " " << tok::kw_where << " ";
20902099
else
2091-
Printer << " : ";
2100+
2101+
printColonForInheritance(Printer, Options);
20922102

20932103
isFirstReq = false;
20942104
} else {
@@ -2174,21 +2184,23 @@ void PrintAST::printRequirement(const Requirement &req) {
21742184
printTransformedType(req.getFirstType());
21752185
Printer << ", ";
21762186
printTransformedType(req.getSecondType());
2177-
Printer << ")) : Any";
2187+
Printer << "))";
2188+
printColonForInheritance(Printer, Options);
2189+
Printer << "Any";
21782190
return;
21792191
case RequirementKind::Layout:
21802192
if (isPackRequirement)
21812193
Printer << "repeat ";
21822194
printTransformedType(req.getFirstType());
2183-
Printer << " : ";
2195+
printColonForInheritance(Printer, Options);
21842196
req.getLayoutConstraint()->print(Printer, Options);
21852197
return;
21862198
case RequirementKind::Conformance:
21872199
case RequirementKind::Superclass:
21882200
if (isPackRequirement)
21892201
Printer << "repeat ";
21902202
printTransformedType(req.getFirstType());
2191-
Printer << " : ";
2203+
printColonForInheritance(Printer, Options);
21922204
break;
21932205
case RequirementKind::SameType:
21942206
if (isPackRequirement)
@@ -2205,7 +2217,7 @@ void PrintAST::printRequirement(const InverseRequirement &inverse,
22052217
if (!forInherited) {
22062218
Printer.callPrintStructurePre(PrintStructureKind::GenericRequirement);
22072219
printTransformedType(inverse.subject);
2208-
Printer << " : ";
2220+
printColonForInheritance(Printer, Options);
22092221
Printer.printStructurePost(PrintStructureKind::GenericRequirement);
22102222
}
22112223

@@ -2933,10 +2945,7 @@ void PrintAST::printInherited(const Decl *decl) {
29332945
if (TypesToPrint.empty())
29342946
return;
29352947

2936-
if (Options.PrintSpaceBeforeInheritance) {
2937-
Printer << " ";
2938-
}
2939-
Printer << ": ";
2948+
printColonForInheritance(Printer, Options);
29402949

29412950
interleave(TypesToPrint, [&](InheritedEntry inherited) {
29422951
printTypeLoc(inherited, [&] {
@@ -4630,8 +4639,10 @@ void PrintAST::visitInfixOperatorDecl(InfixOperatorDecl *decl) {
46304639
[&]{
46314640
Printer.printName(decl->getName());
46324641
});
4633-
if (auto *group = decl->getPrecedenceGroup())
4634-
Printer << " : " << group->getName();
4642+
if (auto *group = decl->getPrecedenceGroup()) {
4643+
printColonForInheritance(Printer, Options);
4644+
Printer << group->getName();
4645+
}
46354646
}
46364647

46374648
void PrintAST::visitPrecedenceGroupDecl(PrecedenceGroupDecl *decl) {
@@ -6339,7 +6350,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
63396350
if (T->isDictionary()) {
63406351
Printer << "[";
63416352
visit(T->getGenericArgs()[0]);
6342-
Printer << " : ";
6353+
printColonForInheritance(Printer, Options);
63436354
visit(T->getGenericArgs()[1]);
63446355
Printer << "]";
63456356
return;
@@ -7126,7 +7137,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
71267137
} else {
71277138
Printer << "[";
71287139
visit(T->getKeyType());
7129-
Printer << " : ";
7140+
Printer << ": ";
71307141
visit(T->getValueType());
71317142
Printer << "]";
71327143
}

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

test/AutoDiff/Sema/DerivedConformances/derived_differentiable.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct GenericTangentVectorMember<T: Differentiable>: Differentiable,
99
var x: T.TangentVector
1010
}
1111

12-
// CHECK-AST-LABEL: internal struct GenericTangentVectorMember<T> : {{(Differentiable, AdditiveArithmetic)|(AdditiveArithmetic, Differentiable)}} where T : Differentiable
12+
// CHECK-AST-LABEL: internal struct GenericTangentVectorMember<T> : {{(Differentiable, AdditiveArithmetic)|(AdditiveArithmetic, Differentiable)}} where T: Differentiable
1313
// CHECK-AST: internal var x: T.TangentVector
1414
// CHECK-AST: internal static func + (lhs: GenericTangentVectorMember<T>, rhs: GenericTangentVectorMember<T>) -> GenericTangentVectorMember<T>
1515
// CHECK-AST: internal static func - (lhs: GenericTangentVectorMember<T>, rhs: GenericTangentVectorMember<T>) -> GenericTangentVectorMember<T>
@@ -24,7 +24,7 @@ public struct ConditionallyDifferentiable<T> {
2424
extension ConditionallyDifferentiable: Differentiable where T: Differentiable {}
2525

2626
// CHECK-AST-LABEL: public struct ConditionallyDifferentiable<T> {
27-
// CHECK-AST: @differentiable(reverse, wrt: self where T : Differentiable)
27+
// CHECK-AST: @differentiable(reverse, wrt: self where T: Differentiable)
2828
// CHECK-AST: public var x: T
2929
// CHECK-AST: internal init(x: T)
3030
// CHECK-AST: }
@@ -61,25 +61,25 @@ final class AdditiveArithmeticClass<T: AdditiveArithmetic & Differentiable>: Add
6161
}
6262
}
6363

64-
// CHECK-AST-LABEL: final internal class AdditiveArithmeticClass<T> : AdditiveArithmetic, Differentiable where T : AdditiveArithmetic, T : Differentiable {
64+
// CHECK-AST-LABEL: final internal class AdditiveArithmeticClass<T> : AdditiveArithmetic, Differentiable where T : AdditiveArithmetic, T: Differentiable {
6565
// CHECK-AST: final internal var x: T, y: T
66-
// CHECK-AST: internal struct TangentVector : {{(Differentiable, AdditiveArithmetic)|(AdditiveArithmetic, Differentiable)}}
66+
// CHECK-AST: internal struct TangentVector: {{(Differentiable, AdditiveArithmetic)|(AdditiveArithmetic, Differentiable)}}
6767
// CHECK-AST: }
6868

6969
@frozen
7070
public struct FrozenStruct: Differentiable {}
7171

72-
// CHECK-AST-LABEL: @frozen public struct FrozenStruct : Differentiable {
73-
// CHECK-AST: @frozen public struct TangentVector : {{(Differentiable, AdditiveArithmetic)|(AdditiveArithmetic, Differentiable)}} {
72+
// CHECK-AST-LABEL: @frozen public struct FrozenStruct: Differentiable {
73+
// CHECK-AST: @frozen public struct TangentVector: {{(Differentiable, AdditiveArithmetic)|(AdditiveArithmetic, Differentiable)}} {
7474
// CHECK-AST: internal init()
7575

7676
@usableFromInline
7777
struct UsableFromInlineStruct: Differentiable {}
7878

7979
// CHECK-AST-LABEL: @usableFromInline
80-
// CHECK-AST: struct UsableFromInlineStruct : Differentiable {
80+
// CHECK-AST: struct UsableFromInlineStruct: Differentiable {
8181
// CHECK-AST: @usableFromInline
82-
// CHECK-AST: struct TangentVector : {{(Differentiable, AdditiveArithmetic)|(AdditiveArithmetic, Differentiable)}} {
82+
// CHECK-AST: struct TangentVector: {{(Differentiable, AdditiveArithmetic)|(AdditiveArithmetic, Differentiable)}} {
8383
// CHECK-AST: internal init()
8484

8585
// Test property wrappers.
@@ -96,8 +96,8 @@ struct WrappedPropertiesStruct: Differentiable {
9696
@noDerivative @Wrapper var nondiff: Float
9797
}
9898

99-
// CHECK-AST-LABEL: internal struct WrappedPropertiesStruct : Differentiable {
100-
// CHECK-AST: internal struct TangentVector : {{(Differentiable, AdditiveArithmetic)|(AdditiveArithmetic, Differentiable)}} {
99+
// CHECK-AST-LABEL: internal struct WrappedPropertiesStruct: Differentiable {
100+
// CHECK-AST: internal struct TangentVector: {{(Differentiable, AdditiveArithmetic)|(AdditiveArithmetic, Differentiable)}} {
101101
// CHECK-AST: internal var x: Float.TangentVector
102102
// CHECK-AST: internal var y: Float.TangentVector
103103
// CHECK-AST: internal var z: Float.TangentVector
@@ -111,8 +111,8 @@ class WrappedPropertiesClass: Differentiable {
111111
@noDerivative @Wrapper var noDeriv: Float = 4
112112
}
113113

114-
// CHECK-AST-LABEL: internal class WrappedPropertiesClass : Differentiable {
115-
// CHECK-AST: internal struct TangentVector : {{(Differentiable, AdditiveArithmetic)|(AdditiveArithmetic, Differentiable)}} {
114+
// CHECK-AST-LABEL: internal class WrappedPropertiesClass: Differentiable {
115+
// CHECK-AST: internal struct TangentVector: {{(Differentiable, AdditiveArithmetic)|(AdditiveArithmetic, Differentiable)}} {
116116
// CHECK-AST: internal var x: Float.TangentVector
117117
// CHECK-AST: internal var y: Float.TangentVector
118118
// CHECK-AST: internal var z: Float.TangentVector
@@ -125,17 +125,17 @@ struct AutoDeriveEncodableTV1: TangentVectorMustBeEncodable {
125125
var x: Float
126126
}
127127

128-
// CHECK-AST-LABEL: internal struct AutoDeriveEncodableTV1 : TangentVectorMustBeEncodable {
129-
// CHECK-AST: internal struct TangentVector : {{(Encodable, Differentiable, AdditiveArithmetic)|(Encodable, AdditiveArithmetic, Differentiable)|(Differentiable, Encodable, AdditiveArithmetic)|(AdditiveArithmetic, Encodable, Differentiable)|(Differentiable, AdditiveArithmetic, Encodable)|(AdditiveArithmetic, Differentiable, Encodable)}} {
128+
// CHECK-AST-LABEL: internal struct AutoDeriveEncodableTV1: TangentVectorMustBeEncodable {
129+
// CHECK-AST: internal struct TangentVector: {{(Encodable, Differentiable, AdditiveArithmetic)|(Encodable, AdditiveArithmetic, Differentiable)|(Differentiable, Encodable, AdditiveArithmetic)|(AdditiveArithmetic, Encodable, Differentiable)|(Differentiable, AdditiveArithmetic, Encodable)|(AdditiveArithmetic, Differentiable, Encodable)}} {
130130

131131
struct AutoDeriveEncodableTV2 {
132132
var x: Float
133133
}
134134

135135
extension AutoDeriveEncodableTV2: TangentVectorMustBeEncodable {}
136136

137-
// CHECK-AST-LABEL: extension AutoDeriveEncodableTV2 : TangentVectorMustBeEncodable {
138-
// CHECK-AST: internal struct TangentVector : {{(Encodable, Differentiable, AdditiveArithmetic)|(Encodable, AdditiveArithmetic, Differentiable)|(Differentiable, Encodable, AdditiveArithmetic)|(AdditiveArithmetic, Encodable, Differentiable)|(Differentiable, AdditiveArithmetic, Encodable)|(AdditiveArithmetic, Differentiable, Encodable)}} {
137+
// CHECK-AST-LABEL: extension AutoDeriveEncodableTV2: TangentVectorMustBeEncodable {
138+
// CHECK-AST: internal struct TangentVector: {{(Encodable, Differentiable, AdditiveArithmetic)|(Encodable, AdditiveArithmetic, Differentiable)|(Differentiable, Encodable, AdditiveArithmetic)|(AdditiveArithmetic, Encodable, Differentiable)|(Differentiable, AdditiveArithmetic, Encodable)|(AdditiveArithmetic, Differentiable, Encodable)}} {
139139

140140
protocol TangentVectorP: Differentiable {
141141
var requirement: Int { get }
@@ -155,8 +155,8 @@ extension TangentVectorP where Self == StructWithTangentVectorConstrained.Tangen
155155
var requirement: Int { 42 }
156156
}
157157

158-
// CHECK-AST-LABEL: internal struct StructWithTangentVectorConstrained : TangentVectorConstrained {
159-
// CHECK-AST: internal struct TangentVector : {{(TangentVectorP, Differentiable, AdditiveArithmetic)|(TangentVectorP, AdditiveArithmetic, Differentiable)|(Differentiable, TangentVectorP, AdditiveArithmetic)|(AdditiveArithmetic, TangentVectorP, Differentiable)|(Differentiable, AdditiveArithmetic, TangentVectorP)|(AdditiveArithmetic, Differentiable, TangentVectorP)}} {
158+
// CHECK-AST-LABEL: internal struct StructWithTangentVectorConstrained: TangentVectorConstrained {
159+
// CHECK-AST: internal struct TangentVector: {{(TangentVectorP, Differentiable, AdditiveArithmetic)|(TangentVectorP, AdditiveArithmetic, Differentiable)|(Differentiable, TangentVectorP, AdditiveArithmetic)|(AdditiveArithmetic, TangentVectorP, Differentiable)|(Differentiable, AdditiveArithmetic, TangentVectorP)|(AdditiveArithmetic, Differentiable, TangentVectorP)}} {
160160

161161
// https://github.com/apple/swift/issues/56601
162162

@@ -165,18 +165,18 @@ public struct S1: Differentiable {
165165
public var scalar: Float
166166
}
167167

168-
// CHECK-AST-LABEL: public struct S1 : Differentiable {
168+
// CHECK-AST-LABEL: public struct S1: Differentiable {
169169
// CHECK-AST: public var simd: [Float]
170170
// CHECK-AST: public var scalar: Float
171-
// CHECK-AST: struct TangentVector : AdditiveArithmetic, Differentiable {
171+
// CHECK-AST: struct TangentVector: AdditiveArithmetic, Differentiable {
172172
// CHECK-AST: var simd: Array<Float>.TangentVector
173173
// CHECK-AST: var scalar: Float
174174

175-
// CHECK-SIL-LABEL: public struct S1 : Differentiable {
175+
// CHECK-SIL-LABEL: public struct S1: Differentiable {
176176
// CHECK-SIL: @differentiable(reverse, wrt: self)
177177
// CHECK-SIL: @_hasStorage public var simd: [Float] { get set }
178178
// CHECK-SIL: @differentiable(reverse, wrt: self)
179179
// CHECK-SIL: @_hasStorage public var scalar: Float { get set }
180-
// CHECK-SIL: struct TangentVector : AdditiveArithmetic, Differentiable {
180+
// CHECK-SIL: struct TangentVector: AdditiveArithmetic, Differentiable {
181181
// CHECK-SIL: @_hasStorage var simd: Array<Float>.DifferentiableView { get set }
182182
// CHECK-SIL: @_hasStorage var scalar: Float { get set }

0 commit comments

Comments
 (0)