Skip to content

Commit 97202fa

Browse files
committed
[Async CC] Put direct returns after indirect returns.
For callers who do not know the actual type of the called function, e.g. when the called function is the result of a partial apply, the offset to the direct returns would otherwise not be known.
1 parent 6fce6d9 commit 97202fa

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ AsyncContextLayout irgen::getAsyncContextLayout(
121121
indirectReturnInfos.push_back(indirectResult);
122122
}
123123

124+
// ResultTypes directResults...;
125+
auto directResults = fnConv.getDirectSILResults();
126+
for (auto result : directResults) {
127+
auto ty =
128+
fnConv.getSILType(result, IGF.IGM.getMaximalTypeExpansionContext());
129+
auto &ti = IGF.getTypeInfoForLowered(ty.getASTType());
130+
valTypes.push_back(ty);
131+
typeInfos.push_back(&ti);
132+
directReturnInfos.push_back(result);
133+
}
134+
124135
// SelfType self?;
125136
bool hasLocalContextParameter = hasSelfContextParameter(substitutedType);
126137
bool canHaveValidError = substitutedType->hasErrorResult();
@@ -203,17 +214,6 @@ AsyncContextLayout irgen::getAsyncContextLayout(
203214
trailingWitnessInfo = AsyncContextLayout::TrailingWitnessInfo();
204215
}
205216

206-
// ResultTypes directResults...;
207-
auto directResults = fnConv.getDirectSILResults();
208-
for (auto result : directResults) {
209-
auto ty =
210-
fnConv.getSILType(result, IGF.IGM.getMaximalTypeExpansionContext());
211-
auto &ti = IGF.getTypeInfoForLowered(ty.getASTType());
212-
valTypes.push_back(ty);
213-
typeInfos.push_back(&ti);
214-
directReturnInfos.push_back(result);
215-
}
216-
217217
return AsyncContextLayout(
218218
IGF.IGM, LayoutStrategy::Optimal, valTypes, typeInfos, IGF, originalType,
219219
substitutedType, substitutionMap, std::move(bindings),

lib/IRGen/GenCall.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,21 @@ namespace irgen {
115115
unsigned getFirstIndirectReturnIndex() {
116116
return getErrorIndex() + getErrorCount();
117117
}
118+
unsigned getIndexAfterIndirectReturns() {
119+
return getFirstIndirectReturnIndex() + getIndirectReturnCount();
120+
}
121+
unsigned getFirstDirectReturnIndex() {
122+
return getIndexAfterIndirectReturns();
123+
}
124+
unsigned getIndexAfterDirectReturns() {
125+
return getFirstDirectReturnIndex() + getDirectReturnCount();
126+
}
118127
unsigned getLocalContextIndex() {
119128
assert(hasLocalContext());
120-
return getFirstIndirectReturnIndex() + getIndirectReturnCount();
129+
return getIndexAfterDirectReturns();
121130
}
122131
unsigned getIndexAfterLocalContext() {
123-
return getFirstIndirectReturnIndex() + getIndirectReturnCount() +
124-
(hasLocalContext() ? 1 : 0);
132+
return getIndexAfterDirectReturns() + (hasLocalContext() ? 1 : 0);
125133
}
126134
unsigned getBindingsIndex() {
127135
assert(hasBindings());
@@ -145,9 +153,6 @@ namespace irgen {
145153
unsigned getIndexAfterTrailingWitnesses() {
146154
return getIndexAfterArguments() + (hasTrailingWitnesses() ? 2 : 0);
147155
}
148-
unsigned getFirstDirectReturnIndex() {
149-
return getIndexAfterTrailingWitnesses();
150-
}
151156

152157
public:
153158
bool canHaveError() { return canHaveValidError; }

0 commit comments

Comments
 (0)