Skip to content

Commit 60f6979

Browse files
committed
NCGenerics: loosen builtin requirements
A number of builtins that do not actually copy their argument(s) were requiring Copyable anyway. rdar://123253877
1 parent d6f9401 commit 60f6979

File tree

2 files changed

+56
-13
lines changed

2 files changed

+56
-13
lines changed

lib/AST/Builtins.cpp

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -884,23 +884,23 @@ static ValueDecl *getTakeOperation(ASTContext &ctx, Identifier id) {
884884

885885
static ValueDecl *getStoreOperation(ASTContext &ctx, Identifier id) {
886886
return getBuiltinFunction(ctx, id, _thin,
887-
_generics(_unrestricted, _conformsToDefaults(0)),
887+
_generics(_unrestricted),
888888
_parameters(_owned(_typeparam(0)),
889889
_rawPointer),
890890
_void);
891891
}
892892

893893
static ValueDecl *getDestroyOperation(ASTContext &ctx, Identifier id) {
894894
return getBuiltinFunction(ctx, id, _thin,
895-
_generics(_unrestricted, _conformsToDefaults(0)),
895+
_generics(_unrestricted),
896896
_parameters(_metatype(_typeparam(0)),
897897
_rawPointer),
898898
_void);
899899
}
900900

901901
static ValueDecl *getDestroyArrayOperation(ASTContext &ctx, Identifier id) {
902902
return getBuiltinFunction(ctx, id, _thin,
903-
_generics(_unrestricted, _conformsToDefaults(0)),
903+
_generics(_unrestricted),
904904
_parameters(_metatype(_typeparam(0)),
905905
_rawPointer,
906906
_word),
@@ -920,9 +920,20 @@ static ValueDecl *getAssumeAlignment(ASTContext &ctx, Identifier id) {
920920
_rawPointer);
921921
}
922922

923+
static ValueDecl *getCopyArrayOperation(ASTContext &ctx, Identifier id) {
924+
return getBuiltinFunction(ctx, id, _thin,
925+
_generics(_unrestricted,
926+
_conformsTo(_typeparam(0), _copyable)),
927+
_parameters(_metatype(_typeparam(0)),
928+
_rawPointer,
929+
_rawPointer,
930+
_word),
931+
_void);
932+
}
933+
923934
static ValueDecl *getTransferArrayOperation(ASTContext &ctx, Identifier id) {
924935
return getBuiltinFunction(ctx, id, _thin,
925-
_generics(_unrestricted, _conformsToDefaults(0)),
936+
_generics(_unrestricted),
926937
_parameters(_metatype(_typeparam(0)),
927938
_rawPointer,
928939
_rawPointer,
@@ -985,9 +996,7 @@ static ValueDecl *getAllocWithTailElemsOperation(ASTContext &Context,
985996
static ValueDecl *getProjectTailElemsOperation(ASTContext &ctx,
986997
Identifier id) {
987998
return getBuiltinFunction(ctx, id, _thin,
988-
_generics(_unrestricted, _unrestricted,
989-
_conformsToDefaults(0),
990-
_conformsToDefaults(1)),
999+
_generics(_unrestricted, _unrestricted),
9911000
_parameters(_typeparam(0),
9921001
_metatype(_typeparam(1))),
9931002
_rawPointer);
@@ -1007,9 +1016,7 @@ static ValueDecl *getGepOperation(ASTContext &ctx, Identifier id,
10071016
static ValueDecl *getGetTailAddrOperation(ASTContext &ctx, Identifier id,
10081017
Type argType) {
10091018
return getBuiltinFunction(ctx, id, _thin,
1010-
_generics(_unrestricted, _unrestricted,
1011-
_conformsToDefaults(0),
1012-
_conformsToDefaults(1)),
1019+
_generics(_unrestricted, _unrestricted),
10131020
_parameters(_rawPointer,
10141021
argType,
10151022
_metatype(_typeparam(0)),
@@ -2785,12 +2792,15 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
27852792
return getDestroyArrayOperation(Context, Id);
27862793

27872794
case BuiltinValueKind::CopyArray:
2788-
case BuiltinValueKind::TakeArrayNoAlias:
2789-
case BuiltinValueKind::TakeArrayFrontToBack:
2790-
case BuiltinValueKind::TakeArrayBackToFront:
27912795
case BuiltinValueKind::AssignCopyArrayNoAlias:
27922796
case BuiltinValueKind::AssignCopyArrayFrontToBack:
27932797
case BuiltinValueKind::AssignCopyArrayBackToFront:
2798+
if (!Types.empty()) return nullptr;
2799+
return getCopyArrayOperation(Context, Id);
2800+
2801+
case BuiltinValueKind::TakeArrayNoAlias:
2802+
case BuiltinValueKind::TakeArrayFrontToBack:
2803+
case BuiltinValueKind::TakeArrayBackToFront:
27942804
case BuiltinValueKind::AssignTakeArray:
27952805
if (!Types.empty()) return nullptr;
27962806
return getTransferArrayOperation(Context, Id);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %target-swift-frontend-typecheck -verify %s -DILLEGAL \
2+
// RUN: -enable-experimental-feature NoncopyableGenerics \
3+
// RUN: -enable-builtin-module \
4+
// RUN: -verify-additional-prefix illegal-
5+
6+
// RUN: %target-swift-frontend -emit-sil -sil-verify-all -verify %s \
7+
// RUN: -enable-experimental-feature NoncopyableGenerics \
8+
// RUN: -enable-builtin-module
9+
10+
import Builtin
11+
12+
struct NC: ~Copyable {}
13+
14+
func checkPointerBuiltins(_ ptr: Builtin.RawPointer, _ value: consuming NC) {
15+
Builtin.initialize(value, ptr)
16+
#if ILLEGAL
17+
Builtin.copy(value) // expected-illegal-error {{noncopyable type 'NC' cannot be substituted for copyable generic parameter 'T' in 'copy'}}
18+
#endif
19+
}
20+
21+
func checkArrayBuiltins(_ dest: Builtin.RawPointer, src: Builtin.RawPointer, count: Builtin.Word) {
22+
Builtin.takeArrayFrontToBack(NC.self, dest, src, count)
23+
Builtin.takeArrayBackToFront(NC.self, dest, src, count)
24+
Builtin.assignTakeArray(NC.self, dest, src, count)
25+
Builtin.destroyArray(NC.self, dest, count)
26+
27+
#if ILLEGAL
28+
Builtin.copyArray(NC.self, dest, src, count) // expected-illegal-error {{noncopyable type 'NC' cannot be substituted for copyable generic parameter 'T' in 'copyArray'}}
29+
Builtin.assignCopyArrayNoAlias(NC.self, dest, src, count) // expected-illegal-error {{noncopyable type 'NC' cannot be substituted for copyable generic parameter 'T' in 'assignCopyArrayNoAlias'}}
30+
Builtin.assignCopyArrayFrontToBack(NC.self, dest, src, count) // expected-illegal-error {{noncopyable type 'NC' cannot be substituted for copyable generic parameter 'T' in 'assignCopyArrayFrontToBack'}}
31+
Builtin.assignCopyArrayBackToFront(NC.self, dest, src, count) // expected-illegal-error {{noncopyable type 'NC' cannot be substituted for copyable generic parameter 'T' in 'assignCopyArrayBackToFront'}}
32+
#endif
33+
}

0 commit comments

Comments
 (0)