Skip to content

Commit 464d7ec

Browse files
committed
[ast] Add a @moveOnly type attribute only available at the SIL level.
It currently is just removed when we type check types, so it doesn't do anything. Eventually this is going to be the way at the SIL level one can convert an AST type into its move only equivalent.
1 parent 47efc38 commit 464d7ec

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

include/swift/AST/Attr.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ TYPE_ATTR(yields)
8585
TYPE_ATTR(yield_once)
8686
TYPE_ATTR(yield_many)
8787
TYPE_ATTR(captures_generics)
88+
// Used at the SIL level to mark a type as moveOnly.
89+
TYPE_ATTR(moveOnly)
8890

8991
// SIL metatype attributes.
9092
TYPE_ATTR(thin)

lib/Sema/TypeCheckType.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2840,6 +2840,12 @@ TypeResolver::resolveAttributedType(TypeAttributes &attrs, TypeRepr *repr,
28402840
attrs.clearAttribute(TAK_box);
28412841
}
28422842

2843+
// In SIL *only*, allow @moveOnly to specify a moveOnly type.
2844+
if ((options & TypeResolutionFlags::SILType) && attrs.has(TAK_moveOnly)) {
2845+
//ty = ty->getCanonicalType()->getMoveOnlyType();
2846+
attrs.clearAttribute(TAK_moveOnly);
2847+
}
2848+
28432849
// In SIL *only*, allow @dynamic_self to specify a dynamic Self type.
28442850
if ((options & TypeResolutionFlags::SILMode) && attrs.has(TAK_dynamic_self)) {
28452851
ty = rebuildWithDynamicSelf(getASTContext(), ty);

test/Sema/moveonly_type_attr.sil

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-sil-opt -verify %s | %FileCheck %s
2+
3+
sil_stage raw
4+
5+
class Klass {}
6+
7+
// Make sure that we just ignore this type attribute.
8+
9+
// CHECK-LABEL: sil [ossa] @foo : $@convention(thin) (@owned @moveOnly Klass) -> () {
10+
// CHECK: bb0(%0 : @owned $@moveOnly Klass):
11+
// CHECK: destroy_value %0 : $@moveOnly Klass
12+
// CHECK: } // end sil function 'foo'
13+
sil [ossa] @foo : $@convention(thin) (@owned @moveOnly Klass) -> () {
14+
bb0(%0 : @owned $@moveOnly Klass):
15+
destroy_value %0 : $@moveOnly Klass
16+
%9999 = tuple()
17+
return %9999 : $()
18+
}

test/Sema/moveonly_type_attr.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-typecheck-verify-swift -parse-stdlib -disable-availability-checking -verify-syntax-tree
2+
3+
import Swift
4+
5+
class Klass {}
6+
7+
// Make sure we ignore this attribute and error in swift mode.
8+
9+
let l: @moveOnly Klass = Klass() // expected-error {{attribute does not apply to type}}

0 commit comments

Comments
 (0)