Skip to content

Commit bcbc1da

Browse files
committed
[Typed throws] Properly reabstract closure types with originally-indirect errors
Thank you, John McCall for debugging this with me!
1 parent 07d8871 commit bcbc1da

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,10 +2306,13 @@ static CanSILFunctionType getSILFunctionType(
23062306
auto &errorTLConv = TC.getTypeLowering(origErrorType, errorType,
23072307
TypeExpansionContext::minimal());
23082308

2309+
bool isFormallyIndirectError =
2310+
origErrorType.isTypeParameter() || errorTLConv.isAddressOnly();
2311+
23092312
errorResult = SILResultInfo(errorTLConv.getLoweredType().getASTType(),
2310-
errorTLConv.isAddressOnly()
2311-
? ResultConvention::Indirect
2312-
: ResultConvention::Owned);
2313+
isFormallyIndirectError
2314+
? ResultConvention::Indirect
2315+
: ResultConvention::Owned);
23132316
}
23142317

23152318
// Lower the result type.

test/SILGen/typed_throws_generic.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ extension Collection {
249249
}
250250
}
251251

252-
// CHECK-LABEL: sil private [ossa] @$s20typed_throws_generic9forcedMapySayq_GSayxGr0_lFq_xXEfU_ : $@convention(thin) <T, U> (@in_guaranteed T) -> (@out U, @error Never)
252+
// CHECK-LABEL: sil private [ossa] @$s20typed_throws_generic9forcedMapySayq_GSayxGr0_lFq_xXEfU_ : $@convention(thin) <T, U> (@in_guaranteed T) -> (@out U, @error_indirect Never)
253253
func forcedMap<T, U>(_ source: [T]) -> [U] {
254-
// CHECK: bb0(%0 : $*U, %1 : $*T)
254+
// CHECK: bb0(%0 : $*U, %1 : $*Never, %2 : $*T)
255255
return source.typedMap { $0 as! U }
256256
}

0 commit comments

Comments
 (0)