Skip to content

Commit 66586a6

Browse files
committed
Revert "Merge pull request swiftlang#76129 from aschwaighofer/irgen_typed_throws_irgenthunk"
This reverts commit dd0de58, reversing changes made to 74b3221.
1 parent 55252e5 commit 66586a6

File tree

5 files changed

+46
-84
lines changed

5 files changed

+46
-84
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6507,46 +6507,3 @@ llvm::FunctionType *FunctionPointer::getFunctionType() const {
65076507

65086508
return Sig.getType();
65096509
}
6510-
6511-
void irgen::buildDirectError(IRGenFunction &IGF,
6512-
const CombinedResultAndErrorType &combined,
6513-
const NativeConventionSchema &errorSchema,
6514-
SILType silErrorTy, Explosion &errorResult,
6515-
bool forAsync, Explosion &out) {
6516-
if (combined.combinedTy->isVoidTy()) {
6517-
return;
6518-
}
6519-
6520-
llvm::Value *expandedResult = llvm::UndefValue::get(combined.combinedTy);
6521-
auto *structTy = dyn_cast<llvm::StructType>(combined.combinedTy);
6522-
6523-
if (!errorSchema.getExpandedType(IGF.IGM)->isVoidTy()) {
6524-
auto nativeError =
6525-
errorSchema.mapIntoNative(IGF.IGM, IGF, errorResult, silErrorTy, false);
6526-
6527-
if (structTy) {
6528-
for (unsigned i : combined.errorValueMapping) {
6529-
llvm::Value *elt = nativeError.claimNext();
6530-
auto *nativeTy = structTy->getElementType(i);
6531-
elt = convertForDirectError(IGF, elt, nativeTy,
6532-
/*forExtraction*/ false);
6533-
expandedResult = IGF.Builder.CreateInsertValue(expandedResult, elt, i);
6534-
}
6535-
if (forAsync) {
6536-
IGF.emitAllExtractValues(expandedResult, structTy, out);
6537-
} else {
6538-
out = expandedResult;
6539-
}
6540-
} else if (!errorSchema.getExpandedType(IGF.IGM)->isVoidTy()) {
6541-
out = convertForDirectError(IGF, nativeError.claimNext(),
6542-
combined.combinedTy,
6543-
/*forExtraction*/ false);
6544-
}
6545-
} else {
6546-
if (forAsync && structTy) {
6547-
IGF.emitAllExtractValues(expandedResult, structTy, out);
6548-
} else {
6549-
out = expandedResult;
6550-
}
6551-
}
6552-
}

lib/IRGen/GenCall.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,6 @@ namespace irgen {
278278
llvm::Value *convertForDirectError(IRGenFunction &IGF, llvm::Value *value,
279279
llvm::Type *toTy, bool forExtraction);
280280

281-
void buildDirectError(IRGenFunction &IGF,
282-
const CombinedResultAndErrorType &combined,
283-
const NativeConventionSchema &errorSchema,
284-
SILType silErrorTy, Explosion &errorResult,
285-
bool forAsync, Explosion &out);
286281
} // end namespace irgen
287282
} // end namespace swift
288283

lib/IRGen/GenThunk.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ void IRGenThunk::prepareArguments() {
153153
auto &resultSchema = resultTI.nativeReturnValueSchema(IGF.IGM);
154154

155155
if (resultSchema.requiresIndirect() ||
156-
errorSchema.shouldReturnTypedErrorIndirectly() ||
157-
conv.hasIndirectSILResults()) {
156+
errorSchema.shouldReturnTypedErrorIndirectly()) {
158157
auto directTypedErrorAddr = original.takeLast();
159158
IGF.setCalleeTypedErrorResultSlot(Address(directTypedErrorAddr,
160159
errorTI.getStorageType(),
@@ -406,21 +405,7 @@ void IRGenThunk::emit() {
406405
errorArgValues.add(errorValue);
407406
emitAsyncReturn(IGF, *asyncLayout, origTy, errorArgValues.claimAll());
408407
} else {
409-
if (!error->empty()) {
410-
// Map the direct error explosion from the call back to the native
411-
// explosion for the return.
412-
SILType silErrorTy = conv.getSILErrorType(expansionContext);
413-
auto &errorTI = IGF.IGM.getTypeInfo(silErrorTy);
414-
auto &errorSchema = errorTI.nativeReturnValueSchema(IGF.IGM);
415-
auto combined =
416-
combineResultAndTypedErrorType(IGF.IGM, schema, errorSchema);
417-
Explosion nativeAgg;
418-
buildDirectError(IGF, combined, errorSchema, silErrorTy, *error,
419-
/*forAsync*/ false, nativeAgg);
420-
IGF.emitScalarReturn(IGF.CurFn->getReturnType(), nativeAgg);
421-
} else {
422-
IGF.emitScalarReturn(IGF.CurFn->getReturnType(), *error);
423-
}
408+
IGF.emitScalarReturn(IGF.CurFn->getReturnType(), *error);
424409
}
425410
IGF.Builder.emitBlock(successBB);
426411
} else {

lib/IRGen/IRGenSIL.cpp

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4426,6 +4426,48 @@ void IRGenSILFunction::visitThrowInst(swift::ThrowInst *i) {
44264426
getSILModule());
44274427
assert(!conv.hasIndirectSILErrorResults());
44284428

4429+
auto buildDirectError = [=](const CombinedResultAndErrorType &combined,
4430+
const NativeConventionSchema &errorSchema,
4431+
SILType silErrorTy, Explosion &errorResult,
4432+
bool forAsync, Explosion &out) {
4433+
if (combined.combinedTy->isVoidTy()) {
4434+
return;
4435+
}
4436+
4437+
llvm::Value *expandedResult = llvm::UndefValue::get(combined.combinedTy);
4438+
auto *structTy = dyn_cast<llvm::StructType>(combined.combinedTy);
4439+
4440+
if (!errorSchema.getExpandedType(IGM)->isVoidTy()) {
4441+
auto nativeError =
4442+
errorSchema.mapIntoNative(IGM, *this, errorResult, silErrorTy, false);
4443+
4444+
if (structTy) {
4445+
for (unsigned i : combined.errorValueMapping) {
4446+
llvm::Value *elt = nativeError.claimNext();
4447+
auto *nativeTy = structTy->getElementType(i);
4448+
elt = convertForDirectError(*this, elt, nativeTy,
4449+
/*forExtraction*/ false);
4450+
expandedResult = Builder.CreateInsertValue(expandedResult, elt, i);
4451+
}
4452+
if (forAsync) {
4453+
emitAllExtractValues(expandedResult, structTy, out);
4454+
} else {
4455+
out = expandedResult;
4456+
}
4457+
} else if (!errorSchema.getExpandedType(IGM)->isVoidTy()) {
4458+
out =
4459+
convertForDirectError(*this, nativeError.claimNext(),
4460+
combined.combinedTy, /*forExtraction*/ false);
4461+
}
4462+
} else {
4463+
if (forAsync && structTy) {
4464+
emitAllExtractValues(expandedResult, structTy, out);
4465+
} else {
4466+
out = expandedResult;
4467+
}
4468+
}
4469+
};
4470+
44294471
if (!isAsync()) {
44304472
auto fnTy = CurFn->getFunctionType();
44314473
auto retTy = fnTy->getReturnType();
@@ -4458,8 +4500,7 @@ void IRGenSILFunction::visitThrowInst(swift::ThrowInst *i) {
44584500
auto combined =
44594501
combineResultAndTypedErrorType(IGM, resultSchema, errorSchema);
44604502
Explosion nativeAgg;
4461-
buildDirectError(*this, combined, errorSchema, silErrorTy,
4462-
errorResult,
4503+
buildDirectError(combined, errorSchema, silErrorTy, errorResult,
44634504
/*forAsync*/ false, nativeAgg);
44644505

44654506
emitScalarReturn(combined.combinedTy, nativeAgg);
@@ -4509,7 +4550,7 @@ void IRGenSILFunction::visitThrowInst(swift::ThrowInst *i) {
45094550
Explosion nativeAgg;
45104551
auto combined =
45114552
combineResultAndTypedErrorType(IGM, resultSchema, errorSchema);
4512-
buildDirectError(*this, combined, errorSchema, silErrorTy, exn,
4553+
buildDirectError(combined, errorSchema, silErrorTy, exn,
45134554
/*forAsync*/ true, nativeAgg);
45144555
assert(exn.empty() && "Unclaimed typed error results");
45154556

test/IRGen/typed_throws.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s --check-prefix=CHECK
66

7-
// RUN: %target-swift-frontend -primary-file %s -emit-ir -enable-library-evolution
8-
97
// XFAIL: CPU=arm64e
108
// REQUIRES: PTRSIZE=64
119

@@ -218,17 +216,3 @@ func mayThrowEmptyErrorAsync(x: Bool) async throws(EmptyError) -> String? {
218216

219217
return ""
220218
}
221-
222-
223-
enum SP: Error {
224-
case a
225-
case b(Int32)
226-
}
227-
228-
protocol Proto {
229-
// This used to crash.
230-
static func f() throws(SP) -> Self
231-
232-
// This used to crash.
233-
static func f2() throws(SP) -> Int64
234-
}

0 commit comments

Comments
 (0)