Skip to content

Commit 4bc1abb

Browse files
committed
Sema: Relax feature check for non-escapable types in swiftinterfaces.
Checking for the presence of a feature flag in order to allow syntax tends to result in condfails when applied to `.swiftinterfaces`, since older compilers that have this restriction may be used to compile newer interfaces where the restriction has been lifted. Remove this restriction for non-escapable types when typechecking an interface. Resolves rdar://128577611
1 parent 7e6862b commit 4bc1abb

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,6 +2071,11 @@ namespace {
20712071
return (SF && SF->Kind == SourceFileKind::SIL);
20722072
}
20732073

2074+
bool isInterfaceFile() const {
2075+
auto SF = getDeclContext()->getParentSourceFile();
2076+
return (SF && SF->Kind == SourceFileKind::Interface);
2077+
}
2078+
20742079
/// Short-hand to query the current stage of type resolution.
20752080
bool inStage(TypeResolutionStage stage) const {
20762081
return resolution.getStage() == stage;
@@ -4782,6 +4787,7 @@ TypeResolver::resolveDeclRefTypeRepr(DeclRefTypeRepr *repr,
47824787
if (auto known = proto->getKnownProtocol()) {
47834788
if (*known == KnownProtocolKind::Escapable
47844789
&& !isSILSourceFile()
4790+
&& !isInterfaceFile()
47854791
&& !ctx.LangOpts.hasFeature(Feature::NonescapableTypes)) {
47864792
diagnoseInvalid(repr, repr->getLoc(),
47874793
diag::escapable_requires_feature_flag);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-compiler-version: Swift version 6.0
3+
// swift-module-flags: -swift-version 5 -enable-library-evolution -module-name Library
4+
5+
// RUN: %target-swift-typecheck-module-from-interface(%s) -module-name Library
6+
7+
import Swift
8+
import _Concurrency
9+
import _StringProcessing
10+
import _SwiftConcurrencyShims
11+
12+
// Allow Escapable to appear without -enable-experimental-feature NonescapableTypes
13+
public struct S : Swift.Escapable {
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -module-name Library
3+
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library
4+
// RUN: %FileCheck %s < %t/Library.swiftinterface
5+
6+
struct InternalStruct {}
7+
extension [Int: InternalStruct]: Sendable {}
8+
9+
// CHECK: @available(*, unavailable)
10+
// CHECK: extension Swift.Dictionary : Swift.Copyable, Swift.Escapable, Swift.Sendable where Key : _ConstraintThatIsNotPartOfTheAPIOfThisLibrary {}

0 commit comments

Comments
 (0)