Skip to content

Commit 1edbbce

Browse files
authored
Merge pull request #70425 from kavon/escapable-builtins
2 parents dda7e96 + 0c5748f commit 1edbbce

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed

lib/AST/Module.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,13 +1828,20 @@ static ProtocolConformanceRef getBuiltinMetaTypeTypeConformance(
18281828
/// appropriate.
18291829
static ProtocolConformanceRef getBuiltinBuiltinTypeConformance(
18301830
Type type, const BuiltinType *builtinType, ProtocolDecl *protocol) {
1831-
// All builtin are Sendable and Copyable
1832-
if (protocol->isSpecificProtocol(KnownProtocolKind::Sendable) ||
1833-
protocol->isSpecificProtocol(KnownProtocolKind::Copyable)) {
1834-
ASTContext &ctx = protocol->getASTContext();
1835-
return ProtocolConformanceRef(
1836-
ctx.getBuiltinConformance(type, protocol,
1831+
// All builtin are Sendable, Copyable, and Escapable
1832+
if (auto kp = protocol->getKnownProtocolKind()) {
1833+
switch (*kp) {
1834+
case KnownProtocolKind::Sendable:
1835+
case KnownProtocolKind::Copyable:
1836+
case KnownProtocolKind::Escapable: {
1837+
ASTContext &ctx = protocol->getASTContext();
1838+
return ProtocolConformanceRef(
1839+
ctx.getBuiltinConformance(type, protocol,
18371840
BuiltinConformanceKind::Synthesized));
1841+
}
1842+
default:
1843+
break;
1844+
}
18381845
}
18391846

18401847
return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);

lib/AST/Requirement.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,11 @@ void InverseRequirement::expandDefaults(
301301
for (auto gp : gps) {
302302
auto protos = InverseRequirement::expandDefault(gp);
303303
for (auto ip : protos) {
304-
auto protoTy =
305-
ctx.getProtocol(getKnownProtocolKind(ip))->getDeclaredInterfaceType();
304+
auto proto = ctx.getProtocol(getKnownProtocolKind(ip));
305+
if (!proto)
306+
llvm_unreachable("failed to load Copyable/Escapable/etc from stdlib!");
307+
308+
auto protoTy = proto->getDeclaredInterfaceType();
306309
result.push_back({{RequirementKind::Conformance, gp, protoTy},
307310
SourceLoc(),
308311
/*inferred=*/true,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %target-typecheck-verify-swift -parse-stdlib -module-name Swift -enable-experimental-feature BuiltinModule -enable-experimental-feature NoncopyableGenerics -enable-experimental-feature NonEscapableTypes
2+
3+
// REQUIRES: asserts
4+
5+
/// This test specifically covers constructs that are only valid in the stdlib.
6+
7+
import Builtin
8+
9+
@_marker public protocol Copyable: ~Escapable {}
10+
@_marker public protocol Escapable: ~Copyable {}
11+
12+
struct NC: ~Copyable {}
13+
14+
@frozen public struct UnsafePointer<T: ~Copyable>: Copyable {
15+
var value: Builtin.RawPointer
16+
}
17+
18+
@frozen
19+
public enum Optional<T: ~Copyable> {
20+
case some(T)
21+
case none
22+
}
23+
24+
public func wrapping<T: ~Copyable>(_ t: consuming T) -> T? {
25+
return .some(t)
26+
}
27+
28+
// No ownership required.
29+
func checkCopyability(_ t: UnsafePointer<NC>) {}

0 commit comments

Comments
 (0)