mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[AST] Implement printing suppression for ~Sendable
This commit is contained in:
@@ -85,6 +85,7 @@ namespace swift {
|
||||
struct ExternalSourceLocs;
|
||||
class CaptureListExpr;
|
||||
class DeclRefExpr;
|
||||
class InverseTypeRepr;
|
||||
class LiteralExpr;
|
||||
class BraceStmt;
|
||||
class DeclAttributes;
|
||||
@@ -1970,6 +1971,12 @@ public:
|
||||
Type getResolvedType(unsigned i, TypeResolutionStage stage =
|
||||
TypeResolutionStage::Interface) const;
|
||||
|
||||
/// If the given index corresponds to a "suppressed" entry, returns the
|
||||
/// information associated with it, and `std::nullopt` otherwise.
|
||||
std::optional<std::pair<Type, InverseTypeRepr *>> getAsSuppressed(
|
||||
unsigned i,
|
||||
TypeResolutionStage stage = TypeResolutionStage::Interface) const;
|
||||
|
||||
/// Returns the underlying array of inherited type entries.
|
||||
///
|
||||
/// NOTE: The `Type` associated with an entry may not be resolved yet.
|
||||
|
||||
@@ -8223,9 +8223,19 @@ swift::getInheritedForPrinting(
|
||||
}
|
||||
}
|
||||
|
||||
if (options.SuppressConformanceSuppression &&
|
||||
inherited.getEntry(i).isSuppressed()) {
|
||||
continue;
|
||||
if (inherited.getEntry(i).isSuppressed()) {
|
||||
// All `~<<Protocol>>` inheritances are suppressed.
|
||||
if (options.SuppressConformanceSuppression)
|
||||
continue;
|
||||
|
||||
if (options.SuppressTildeSendable) {
|
||||
if (auto type = inherited.getAsSuppressed(i)->first) {
|
||||
auto *sendable =
|
||||
decl->getASTContext().getProtocol(KnownProtocolKind::Sendable);
|
||||
if (sendable && sendable == type->getAnyNominal())
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Results.push_back(inherited.getEntry(i));
|
||||
|
||||
@@ -2034,6 +2034,20 @@ Type InheritedTypes::getResolvedType(unsigned i,
|
||||
.getInheritedTypeOrNull(getASTContext());
|
||||
}
|
||||
|
||||
std::optional<std::pair<Type, InverseTypeRepr *>>
|
||||
InheritedTypes::getAsSuppressed(unsigned i, TypeResolutionStage stage) const {
|
||||
ASTContext &ctx = isa<const ExtensionDecl *>(Decl)
|
||||
? cast<const ExtensionDecl *>(Decl)->getASTContext()
|
||||
: cast<const TypeDecl *>(Decl)->getASTContext();
|
||||
auto result =
|
||||
evaluateOrDefault(ctx.evaluator, InheritedTypeRequest{Decl, i, stage},
|
||||
InheritedTypeResult::forDefault());
|
||||
if (result != InheritedTypeResult::Kind::Suppressed)
|
||||
return std::nullopt;
|
||||
|
||||
return result.getSuppressed();
|
||||
}
|
||||
|
||||
ExtensionDecl::ExtensionDecl(SourceLoc extensionLoc,
|
||||
TypeRepr *extendedType,
|
||||
ArrayRef<InheritedEntry> inherited,
|
||||
|
||||
35
test/ModuleInterface/tilde_sendable.swift
Normal file
35
test/ModuleInterface/tilde_sendable.swift
Normal file
@@ -0,0 +1,35 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -module-name Library -enable-experimental-feature TildeSendable
|
||||
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library
|
||||
// RUN: %FileCheck %s < %t/Library.swiftinterface
|
||||
|
||||
// REQUIRES: swift_feature_TildeSendable
|
||||
|
||||
// CHECK: #if compiler(>=5.3) && $TildeSendable
|
||||
// CHECK: public class A : ~Swift.Sendable {
|
||||
// CHECK: }
|
||||
// CHECK: #else
|
||||
// CHECK: public class A {
|
||||
// CHECK: }
|
||||
// CHECK: #endif
|
||||
public class A: ~Sendable {
|
||||
public init() {}
|
||||
}
|
||||
|
||||
protocol P {
|
||||
}
|
||||
|
||||
// CHECK: #if compiler(>=5.3) && $TildeSendable
|
||||
// CHECK: public struct S : ~Swift.Sendable {
|
||||
// CHECK: public let x: Swift.Int
|
||||
// CHECK: }
|
||||
// CHECK: #else
|
||||
// CHECK: public struct S {
|
||||
// CHECK: public let x: Swift.Int
|
||||
// CHECK: }
|
||||
// CHECK: #endif
|
||||
|
||||
// CHECK-NOT: extension Library.S : Swift.Sendable {}
|
||||
public struct S: P, ~Sendable {
|
||||
public let x: Int
|
||||
}
|
||||
Reference in New Issue
Block a user