Skip to content

Commit f69efcd

Browse files
authored
Merge pull request #6927 from slavapestov/fix-another-crappy-any-thing
SILGen: Fix yet another 'argument labels ignored if parameter type is Any' thing
2 parents a92b6f1 + 140acd6 commit f69efcd

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,14 @@ RValue RValueEmitter::visitTupleShuffleExpr(TupleShuffleExpr *E,
19261926
// If we're emitting into an initialization, we can try shuffling the
19271927
// elements of the initialization.
19281928
if (Initialization *I = C.getEmitInto()) {
1929-
if (I->canSplitIntoTupleElements()) {
1929+
// In Swift 3 mode, we might be stripping off labels from a
1930+
// one-element tuple; the destination type is a ParenType in
1931+
// that case.
1932+
//
1933+
// FIXME: Remove this eventually.
1934+
if (I->canSplitIntoTupleElements() &&
1935+
!(isa<ParenType>(E->getType().getPointer()) &&
1936+
SGF.getASTContext().isSwiftVersion3())) {
19301937
emitTupleShuffleExprInto(*this, E, I);
19311938
return RValue();
19321939
}
@@ -1943,10 +1950,13 @@ RValue RValueEmitter::visitTupleShuffleExpr(TupleShuffleExpr *E,
19431950
// Prepare a new tuple to hold the shuffled result.
19441951
RValue result(E->getType()->getCanonicalType());
19451952

1946-
// In Swift 3 mode, we might have to shuffle off labels.
1953+
// In Swift 3 mode, we might be stripping off labels from a
1954+
// one-element tuple; the destination type is a ParenType in
1955+
// that case.
19471956
//
19481957
// FIXME: Remove this eventually.
1949-
if (isa<ParenType>(E->getType().getPointer())) {
1958+
if (isa<ParenType>(E->getType().getPointer()) &&
1959+
SGF.getASTContext().isSwiftVersion3()) {
19501960
assert(E->getElementMapping().size() == 1);
19511961
auto shuffleIndex = E->getElementMapping()[0];
19521962
assert(shuffleIndex != TupleShuffleExpr::DefaultInitialize &&

test/Compatibility/tuple_arguments.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,10 @@ do {
12741274
// with single 'Any' parameter
12751275
func takesAny(_: Any) {}
12761276

1277+
enum HasAnyCase {
1278+
case any(_: Any)
1279+
}
1280+
12771281
do {
12781282
let fn: (Any) -> () = { _ in }
12791283

@@ -1282,4 +1286,7 @@ do {
12821286

12831287
takesAny(123)
12841288
takesAny(data: 123)
1289+
1290+
_ = HasAnyCase.any(123)
1291+
_ = HasAnyCase.any(data: 123)
12851292
}

test/Constraints/tuple_arguments.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,10 @@ do {
12591259
// with single 'Any' parameter
12601260
func takesAny(_: Any) {}
12611261

1262+
enum HasAnyCase {
1263+
case any(_: Any)
1264+
}
1265+
12621266
do {
12631267
let fn: (Any) -> () = { _ in }
12641268

@@ -1267,4 +1271,7 @@ do {
12671271

12681272
takesAny(123)
12691273
takesAny(data: 123) // expected-error {{extraneous argument label 'data:' in call}}
1274+
1275+
_ = HasAnyCase.any(123)
1276+
_ = HasAnyCase.any(data: 123) // expected-error {{extraneous argument label 'data:' in call}}
12701277
}

test/SILGen/argument_shuffle_swift3.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
func fn(_: Any) {}
44

5+
enum HasAnyCase {
6+
case any(_: Any)
7+
}
8+
59
// CHECK-LABEL: sil hidden @_TF23argument_shuffle_swift31gFT1xP__T_ : $@convention(thin) (@in Any) -> () {
610
func g(x: Any) {
711
// CHECK: [[FN:%.*]] = function_ref @_TF23argument_shuffle_swift32fnFP_T_ : $@convention(thin) (@in Any) -> ()
@@ -10,5 +14,12 @@ func g(x: Any) {
1014
// CHECK: [[FN:%.*]] = function_ref @_TF23argument_shuffle_swift32fnFP_T_ : $@convention(thin) (@in Any) -> ()
1115
// CHECK: apply [[FN:%.*]]({{.*}}) : $@convention(thin) (@in Any) -> ()
1216
fn(data: x)
17+
18+
// CHECK: inject_enum_addr {{.*}} : $*HasAnyCase, #HasAnyCase.any!enumelt.1
19+
_ = HasAnyCase.any(123)
20+
21+
// CHECK: inject_enum_addr {{.*}} : $*HasAnyCase, #HasAnyCase.any!enumelt.1
22+
_ = HasAnyCase.any(data: 123)
23+
1324
// CHECK: return
1425
}

0 commit comments

Comments
 (0)