Skip to content

Commit 67158d9

Browse files
authored
Merge pull request swiftlang#73904 from tshortli/nonescapable-in-swiftinterface-6.0
[6.0] Sema: Relax feature check for non-escapable types in swiftinterfaces
2 parents 43cebb8 + e458cf9 commit 67158d9

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4406,7 +4406,7 @@ class ConstraintSystem {
44064406
/// \param UseDC The context of the access. Some variables have different
44074407
/// types depending on where they are used.
44084408
///
4409-
/// \param memberLocator The locator anchored at this value reference, when
4409+
/// \param locator The locator anchored at this value reference, when
44104410
/// it is a member reference.
44114411
///
44124412
/// \param wantInterfaceType Whether we want the interface type, if available.
@@ -4424,7 +4424,7 @@ class ConstraintSystem {
44244424
/// \param UseDC The context of the access. Some variables have different
44254425
/// types depending on where they are used.
44264426
///
4427-
/// \param memberLocator The locator anchored at this value reference, when
4427+
/// \param locator The locator anchored at this value reference, when
44284428
/// it is a member reference.
44294429
///
44304430
/// \param wantInterfaceType Whether we want the interface type, if available.

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)