Skip to content

Commit a5268f8

Browse files
authored
Merge pull request #15189 from huonw/one-unnamed-owned-argument
[AST] ParenType needs enough bits to store ValueOwnership::Owned.
2 parents 96b695b + e7002b6 commit a5268f8

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

include/swift/AST/Types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class alignas(1 << TypeAlignInBits) TypeBase {
290290
HasCachedType : 1
291291
);
292292

293-
enum { NumFlagBits = 5 };
293+
enum { NumFlagBits = 8 };
294294
SWIFT_INLINE_BITFIELD(ParenType, SugarType, NumFlagBits,
295295
/// Whether there is an original type.
296296
Flags : NumFlagBits

test/Constraints/closures.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,22 @@ _ = f0(X2(), {$0.g()})
3535

3636
func inoutToSharedConversions() {
3737
func fooOW<T, U>(_ f : (__owned T) -> U) {}
38-
fooOW({ (x : Int) in return Int(5) }) // '__owned'-to-'__owned' allowed
38+
fooOW({ (x : Int) in return Int(5) }) // defaut-to-'__owned' allowed
39+
fooOW({ (x : __owned Int) in return Int(5) }) // '__owned'-to-'__owned' allowed
3940
fooOW({ (x : __shared Int) in return Int(5) }) // '__shared'-to-'__owned' allowed
40-
fooOW({ (x : inout Int) in return Int(5) }) // expected-error {{cannot convert value of type '(inout Int) -> Int' to expected argument type '(_) -> _'}}
41+
fooOW({ (x : inout Int) in return Int(5) }) // expected-error {{cannot convert value of type '(inout Int) -> Int' to expected argument type '(__owned _) -> _'}}
4142

4243
func fooIO<T, U>(_ f : (inout T) -> U) {}
4344
fooIO({ (x : inout Int) in return Int(5) }) // 'inout'-to-'inout' allowed
44-
fooIO({ (x : __shared Int) in return Int(5) }) // expected-error {{cannot convert value of type '(__shared Int) -> Int' to expected argument type '(inout _) -> _'}}
4545
fooIO({ (x : Int) in return Int(5) }) // expected-error {{cannot convert value of type '(inout Int) -> Int' to expected argument type '(inout _) -> _'}}
46+
fooIO({ (x : __shared Int) in return Int(5) }) // expected-error {{cannot convert value of type '(__shared Int) -> Int' to expected argument type '(inout _) -> _'}}
47+
fooIO({ (x : __owned Int) in return Int(5) }) // expected-error {{cannot convert value of type '(__owned Int) -> Int' to expected argument type '(inout _) -> _'}}
4648

4749
func fooSH<T, U>(_ f : (__shared T) -> U) {}
4850
fooSH({ (x : __shared Int) in return Int(5) }) // '__shared'-to-'__shared' allowed
51+
fooSH({ (x : __owned Int) in return Int(5) }) // '__owned'-to-'__shared' allowed
4952
fooSH({ (x : inout Int) in return Int(5) }) // expected-error {{cannot convert value of type '(inout Int) -> Int' to expected argument type '(__shared _) -> _'}}
50-
fooSH({ (x : Int) in return Int(5) }) // '__owned'-to-'__shared' allowed
53+
fooSH({ (x : Int) in return Int(5) }) // default-to-'__shared' allowed
5154
}
5255

5356
// Autoclosure

test/Runtime/demangleToMetadata.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ DemangleToMetadataTests.test("function types") {
6868

6969
// Ownership parameters.
7070
expectEqual(type(of: f1_shared), _typeByMangledName("yyyXlhc")!)
71-
expectEqual(type(of: f1_owned), _typeByMangledName("yyyXlc")!)
71+
expectEqual(type(of: f1_owned), _typeByMangledName("yyyXlnc")!)
7272

7373
// Mix-and-match.
7474
expectEqual(type(of: f2_variadic_inout), _typeByMangledName("yyytd_ytztc")!)

test/SILGen/owned.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ struct Foo {
2222
let r = ref
2323
}
2424
}
25+
26+
// rdar://problem/38390524
27+
// CHECK-LABEL: sil hidden @$S5owned19oneUnnamedArgument1yyAA14ValueAggregateVnF : $@convention(thin) (@owned ValueAggregate) -> () {
28+
func oneUnnamedArgument1(_: __owned ValueAggregate) {}
29+
// CHECK-LABEL: sil hidden @$S5owned19oneUnnamedArgument2yyAA12RefAggregateCnF : $@convention(thin) (@owned RefAggregate) -> () {
30+
func oneUnnamedArgument2(_: __owned RefAggregate) {}

0 commit comments

Comments
 (0)