Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions lib/SILGen/SILGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,14 @@ RValue RValueEmitter::visitTupleShuffleExpr(TupleShuffleExpr *E,
// If we're emitting into an initialization, we can try shuffling the
// elements of the initialization.
if (Initialization *I = C.getEmitInto()) {
if (I->canSplitIntoTupleElements()) {
// In Swift 3 mode, we might be stripping off labels from a
// one-element tuple; the destination type is a ParenType in
// that case.
//
// FIXME: Remove this eventually.
if (I->canSplitIntoTupleElements() &&
!(isa<ParenType>(E->getType().getPointer()) &&
SGF.getASTContext().isSwiftVersion3())) {
emitTupleShuffleExprInto(*this, E, I);
return RValue();
}
Expand All @@ -1943,10 +1950,13 @@ RValue RValueEmitter::visitTupleShuffleExpr(TupleShuffleExpr *E,
// Prepare a new tuple to hold the shuffled result.
RValue result(E->getType()->getCanonicalType());

// In Swift 3 mode, we might have to shuffle off labels.
// In Swift 3 mode, we might be stripping off labels from a
// one-element tuple; the destination type is a ParenType in
// that case.
//
// FIXME: Remove this eventually.
if (isa<ParenType>(E->getType().getPointer())) {
if (isa<ParenType>(E->getType().getPointer()) &&
SGF.getASTContext().isSwiftVersion3()) {
assert(E->getElementMapping().size() == 1);
auto shuffleIndex = E->getElementMapping()[0];
assert(shuffleIndex != TupleShuffleExpr::DefaultInitialize &&
Expand Down
7 changes: 7 additions & 0 deletions test/Compatibility/tuple_arguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,10 @@ do {
// with single 'Any' parameter
func takesAny(_: Any) {}

enum HasAnyCase {
case any(_: Any)
}

do {
let fn: (Any) -> () = { _ in }

Expand All @@ -1282,4 +1286,7 @@ do {

takesAny(123)
takesAny(data: 123)

_ = HasAnyCase.any(123)
_ = HasAnyCase.any(data: 123)
}
7 changes: 7 additions & 0 deletions test/Constraints/tuple_arguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,10 @@ do {
// with single 'Any' parameter
func takesAny(_: Any) {}

enum HasAnyCase {
case any(_: Any)
}

do {
let fn: (Any) -> () = { _ in }

Expand All @@ -1267,4 +1271,7 @@ do {

takesAny(123)
takesAny(data: 123) // expected-error {{extraneous argument label 'data:' in call}}

_ = HasAnyCase.any(123)
_ = HasAnyCase.any(data: 123) // expected-error {{extraneous argument label 'data:' in call}}
}
11 changes: 11 additions & 0 deletions test/SILGen/argument_shuffle_swift3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

func fn(_: Any) {}

enum HasAnyCase {
case any(_: Any)
}

// CHECK-LABEL: sil hidden @_TF23argument_shuffle_swift31gFT1xP__T_ : $@convention(thin) (@in Any) -> () {
func g(x: Any) {
// CHECK: [[FN:%.*]] = function_ref @_TF23argument_shuffle_swift32fnFP_T_ : $@convention(thin) (@in Any) -> ()
Expand All @@ -10,5 +14,12 @@ func g(x: Any) {
// CHECK: [[FN:%.*]] = function_ref @_TF23argument_shuffle_swift32fnFP_T_ : $@convention(thin) (@in Any) -> ()
// CHECK: apply [[FN:%.*]]({{.*}}) : $@convention(thin) (@in Any) -> ()
fn(data: x)

// CHECK: inject_enum_addr {{.*}} : $*HasAnyCase, #HasAnyCase.any!enumelt.1
_ = HasAnyCase.any(123)

// CHECK: inject_enum_addr {{.*}} : $*HasAnyCase, #HasAnyCase.any!enumelt.1
_ = HasAnyCase.any(data: 123)

// CHECK: return
}