Skip to content

Commit 8d61176

Browse files
authored
Merge pull request #7018 from slavapestov/tuple-to-optional-function-conversion
SILGen: Relax assertion in tuple-to-optional function result conversion
2 parents ad36dc4 + 8ad5504 commit 8d61176

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

lib/SILGen/SILGenPoly.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,6 @@ ResultPlanner::planTupleIntoDirectResult(AbstractionPattern innerOrigType,
19181918
PlanData &planData,
19191919
SILResultInfo outerResult) {
19201920
assert(innerOrigType.isTuple());
1921-
assert(!outerOrigType.isTuple());
19221921

19231922
CanTupleType outerSubstTupleType = dyn_cast<TupleType>(outerSubstType);
19241923

test/SILGen/function_conversion.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,48 @@ func convTupleScalarOpaque<T>(_ f: @escaping (T...) -> ()) -> ((_ args: T...) ->
424424
return f
425425
}
426426

427+
// CHECK-LABEL: sil hidden @_TF19function_conversion25convTupleToOptionalDirectFFSiTSiSi_FSiGSqTSiSi__ : $@convention(thin) (@owned @callee_owned (Int) -> (Int, Int)) -> @owned @callee_owned (Int) -> Optional<(Int, Int)>
428+
// CHECK: bb0(%0 : $@callee_owned (Int) -> (Int, Int)):
429+
// CHECK: [[FN:%.*]] = copy_value %0
430+
// CHECK: [[THUNK_FN:%.*]] = function_ref @_TTRXFo_dSi_dSidSi_XFo_dSi_dGSqTSiSi___
431+
// CHECK-NEXT: [[THUNK:%.*]] = partial_apply [[THUNK_FN]]([[FN]])
432+
// CHECK-NEXT: destroy_value %0
433+
// CHECK-NEXT: return [[THUNK]]
434+
435+
// CHECK-LABEL: sil shared [transparent] [reabstraction_thunk] @_TTRXFo_dSi_dSidSi_XFo_dSi_dGSqTSiSi___ : $@convention(thin) (Int, @owned @callee_owned (Int) -> (Int, Int)) -> Optional<(Int, Int)>
436+
// CHECK: bb0(%0 : $Int, %1 : $@callee_owned (Int) -> (Int, Int)):
437+
// CHECK: [[RESULT:%.*]] = apply %1(%0)
438+
// CHECK-NEXT: [[LEFT:%.*]] = tuple_extract [[RESULT]]
439+
// CHECK-NEXT: [[RIGHT:%.*]] = tuple_extract [[RESULT]]
440+
// CHECK-NEXT: [[RESULT:%.*]] = tuple ([[LEFT]] : $Int, [[RIGHT]] : $Int)
441+
// CHECK-NEXT: [[OPTIONAL:%.*]] = enum $Optional<(Int, Int)>, #Optional.some!enumelt.1, [[RESULT]]
442+
// CHECK-NEXT: return [[OPTIONAL]]
443+
444+
func convTupleToOptionalDirect(_ f: @escaping (Int) -> (Int, Int)) -> (Int) -> (Int, Int)? {
445+
return f
446+
}
447+
448+
// CHECK-LABEL: sil hidden @_TF19function_conversion27convTupleToOptionalIndirecturFFxTxx_FxGSqTxx__ : $@convention(thin) <T> (@owned @callee_owned (@in T) -> (@out T, @out T)) -> @owned @callee_owned (@in T) -> @out Optional<(T, T)>
449+
// CHECK: bb0(%0 : $@callee_owned (@in T) -> (@out T, @out T)):
450+
// CHECK: [[FN:%.*]] = copy_value %0
451+
// CHECK: [[THUNK_FN:%.*]] = function_ref @_TTRGrXFo_ix_ixix_XFo_ix_iGSqTxx___
452+
// CHECK-NEXT: [[THUNK:%.*]] = partial_apply [[THUNK_FN]]<T>([[FN]])
453+
// CHECK-NEXT: destroy_value %0
454+
// CHECK-NEXT: return [[THUNK]]
455+
456+
// CHECK: sil shared [transparent] [reabstraction_thunk] @_TTRGrXFo_ix_ixix_XFo_ix_iGSqTxx___ : $@convention(thin) <T> (@in T, @owned @callee_owned (@in T) -> (@out T, @out T)) -> @out Optional<(T, T)>
457+
// CHECK: bb0(%0 : $*Optional<(T, T)>, %1 : $*T, %2 : $@callee_owned (@in T) -> (@out T, @out T)):
458+
// CHECK: [[OPTIONAL:%.*]] = init_enum_data_addr %0 : $*Optional<(T, T)>, #Optional.some!enumelt.1
459+
// CHECK-NEXT: [[LEFT:%.*]] = tuple_element_addr %3 : $*(T, T), 0
460+
// CHECK-NEXT: [[RIGHT:%.*]] = tuple_element_addr %3 : $*(T, T), 1
461+
// CHECK-NEXT: apply %2([[LEFT]], [[RIGHT]], %1)
462+
// CHECK-NEXT: inject_enum_addr %0 : $*Optional<(T, T)>, #Optional.some!enumelt.1
463+
// CHECK: return
464+
465+
func convTupleToOptionalIndirect<T>(_ f: @escaping (T) -> (T, T)) -> (T) -> (T, T)? {
466+
return f
467+
}
468+
427469
// ==== Make sure we support AnyHashable erasure
428470

429471
// CHECK-LABEL: sil hidden @_TF19function_conversion15convAnyHashableuRxs8HashablerFT1tx_T_
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %target-swift-frontend %s -emit-ir
2+
3+
let occurrences: [String] = []
4+
let results: [(String, Int)] = occurrences.flatMap({ (match: String) -> (String, Int) in
5+
return ("", 0)
6+
})

0 commit comments

Comments
 (0)