Skip to content

Commit cf2e90b

Browse files
authored
Merge pull request #42238 from slavapestov/endifextension
Fix bogus ASTPrinter output with synthesized extension for conformance to protocol with primary associated types
2 parents fa74025 + 3a1cf82 commit cf2e90b

File tree

5 files changed

+32
-21
lines changed

5 files changed

+32
-21
lines changed

include/swift/AST/ASTPrinter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ StringRef getAccessorKindString(AccessorKind value);
389389
/// for the compiler features that it uses. Note that printBody
390390
/// may be called multiple times if the declaration uses suppressible
391391
/// features.
392-
bool printWithCompatibilityFeatureChecks(ASTPrinter &printer,
392+
void printWithCompatibilityFeatureChecks(ASTPrinter &printer,
393393
PrintOptions &options,
394394
Decl *decl,
395395
llvm::function_ref<void()> printBody);

include/swift/Basic/Features.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ LANGUAGE_FEATURE(BuiltinStackAlloc, 0, "Builtin.stackAlloc", true)
7474
SUPPRESSIBLE_LANGUAGE_FEATURE(SpecializeAttributeWithAvailability, 0, "@_specialize attribute with availability", true)
7575
LANGUAGE_FEATURE(BuiltinAssumeAlignment, 0, "Builtin.assumeAlignment", true)
7676
SUPPRESSIBLE_LANGUAGE_FEATURE(UnsafeInheritExecutor, 0, "@_unsafeInheritExecutor", true)
77-
SUPPRESSIBLE_LANGUAGE_FEATURE(PrimaryAssociatedTypes, 0, "Primary associated types", true)
77+
SUPPRESSIBLE_LANGUAGE_FEATURE(PrimaryAssociatedTypes, 346, "Primary associated types", true)
7878
SUPPRESSIBLE_LANGUAGE_FEATURE(UnavailableFromAsync, 0, "@_unavailableFromAsync", true)
7979
SUPPRESSIBLE_LANGUAGE_FEATURE(NoAsyncAvailability, 340, "@available(*, noasync)", true)
8080

lib/AST/ASTPrinter.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,12 +2588,12 @@ void PrintAST::printSynthesizedExtensionImpl(Type ExtendedType,
25882588
// protocol Foo {}
25892589
// extension Foo where <requirments from ExtDecl> { ... }
25902590
// struct Bar {}
2591-
// extension Bar: Foo where <requirments from TransformContext> { ... }
2591+
// extension Bar: Foo where <requirements from TransformContext> { ... }
25922592
//
25932593
// should produce a synthesized extension of Bar with both sets of
2594-
// requirments:
2594+
// requirements:
25952595
//
2596-
// extension Bar where <requirments from ExtDecl+TransformContext { ... }
2596+
// extension Bar where <requirements from ExtDecl+TransformContext> { ... }
25972597
//
25982598
if (!printCombinedRequirementsIfNeeded())
25992599
printDeclGenericRequirements(ExtDecl);
@@ -3208,21 +3208,21 @@ static void printWithSuppressibleFeatureChecks(ASTPrinter &printer,
32083208
/// #endif
32093209
/// #endif
32103210
/// ```
3211-
bool swift::printWithCompatibilityFeatureChecks(ASTPrinter &printer,
3211+
void swift::printWithCompatibilityFeatureChecks(ASTPrinter &printer,
32123212
PrintOptions &options,
32133213
Decl *decl,
32143214
llvm::function_ref<void()> printBody) {
32153215
// A single accessor does not get a feature check,
32163216
// it should go around the whole decl.
32173217
if (isa<AccessorDecl>(decl)) {
32183218
printBody();
3219-
return false;
3219+
return;
32203220
}
32213221

32223222
FeatureSet features = getUniqueFeaturesUsed(decl);
32233223
if (features.empty()) {
32243224
printBody();
3225-
return false;
3225+
return;
32263226
}
32273227

32283228
// Enter a `#if` for the required features, if any.
@@ -3252,8 +3252,6 @@ bool swift::printWithCompatibilityFeatureChecks(ASTPrinter &printer,
32523252
printer.printNewline();
32533253
printer << "#endif";
32543254
}
3255-
3256-
return true;
32573255
}
32583256

32593257
void PrintAST::visitExtensionDecl(ExtensionDecl *decl) {

lib/Frontend/ModuleInterfaceSupport.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -650,17 +650,8 @@ class InheritedProtocolCollector {
650650
printer << " {}";
651651
};
652652

653-
bool printedNewline = false;
654-
if (printOptions.PrintCompatibilityFeatureChecks) {
655-
printedNewline =
656-
printWithCompatibilityFeatureChecks(printer, curPrintOptions,
657-
proto, printBody);
658-
} else {
659-
printBody();
660-
printedNewline = false;
661-
}
662-
if (!printedNewline)
663-
printer << "\n";
653+
printBody();
654+
printer << "\n";
664655
}
665656
}
666657

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -typecheck -module-name ParameterizedProtocols -emit-module-interface-path %t/ParameterizedProtocols.swiftinterface %s
3+
// RUN: %FileCheck %s < %t/ParameterizedProtocols.swiftinterface
4+
5+
public struct S1 : P1 {
6+
public typealias T = Int
7+
}
8+
9+
public struct S2 : Q1 {}
10+
11+
protocol P1 : P2 {}
12+
13+
public protocol P2<T> {
14+
associatedtype T
15+
}
16+
17+
protocol Q1 : Q2 {}
18+
19+
public protocol Q2 {}
20+
21+
// CHECK: extension ParameterizedProtocols.S1 : ParameterizedProtocols.P2 {}
22+
// CHECK-NEXT: extension ParameterizedProtocols.S2 : ParameterizedProtocols.Q2 {}

0 commit comments

Comments
 (0)