Skip to content

Commit a9aee1b

Browse files
committed
[Async CC] Put bindings after formal arguments.
Bindings will always be supplied by the first partial apply, so they will only be added to the async context when its full layout is known. If they are earlier in the layout, subsequent partial applies will put their arguments into the wrong position because they will not be privy to the space requirements of the bindings.
1 parent 97202fa commit a9aee1b

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,6 @@ AsyncContextLayout irgen::getAsyncContextLayout(
168168
}
169169

170170
// ArgTypes formalArguments...;
171-
auto bindings = NecessaryBindings::forAsyncFunctionInvocation(
172-
IGF.IGM, originalType, substitutionMap);
173-
if (!bindings.empty()) {
174-
auto bindingsSize = bindings.getBufferSize(IGF.IGM);
175-
auto &bindingsTI = IGF.IGM.getOpaqueStorageTypeInfo(
176-
bindingsSize, IGF.IGM.getPointerAlignment());
177-
valTypes.push_back(SILType());
178-
typeInfos.push_back(&bindingsTI);
179-
}
180171
for (auto parameter : parameters) {
181172
SILType ty = IGF.IGM.silConv.getSILType(
182173
parameter, substitutedType, IGF.IGM.getMaximalTypeExpansionContext());
@@ -191,6 +182,15 @@ AsyncContextLayout irgen::getAsyncContextLayout(
191182
typeInfos.push_back(&ti);
192183
paramInfos.push_back({ty, parameter.getConvention()});
193184
}
185+
auto bindings = NecessaryBindings::forAsyncFunctionInvocation(
186+
IGF.IGM, originalType, substitutionMap);
187+
if (!bindings.empty()) {
188+
auto bindingsSize = bindings.getBufferSize(IGF.IGM);
189+
auto &bindingsTI = IGF.IGM.getOpaqueStorageTypeInfo(
190+
bindingsSize, IGF.IGM.getPointerAlignment());
191+
valTypes.push_back(SILType());
192+
typeInfos.push_back(&bindingsTI);
193+
}
194194

195195
Optional<AsyncContextLayout::TrailingWitnessInfo> trailingWitnessInfo;
196196
if (originalType->getRepresentation() ==

lib/IRGen/GenCall.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,27 +131,27 @@ namespace irgen {
131131
unsigned getIndexAfterLocalContext() {
132132
return getIndexAfterDirectReturns() + (hasLocalContext() ? 1 : 0);
133133
}
134+
unsigned getFirstArgumentIndex() { return getIndexAfterLocalContext(); }
135+
unsigned getIndexAfterArguments() {
136+
return getFirstArgumentIndex() + getArgumentCount();
137+
}
134138
unsigned getBindingsIndex() {
135139
assert(hasBindings());
136-
return getIndexAfterLocalContext();
140+
return getIndexAfterArguments();
137141
}
138142
unsigned getIndexAfterBindings() {
139-
return getIndexAfterLocalContext() + (hasBindings() ? 1 : 0);
140-
}
141-
unsigned getFirstArgumentIndex() { return getIndexAfterBindings(); }
142-
unsigned getIndexAfterArguments() {
143-
return getFirstArgumentIndex() + getArgumentCount();
143+
return getIndexAfterArguments() + (hasBindings() ? 1 : 0);
144144
}
145145
unsigned getSelfMetadataIndex() {
146146
assert(hasTrailingWitnesses());
147-
return getIndexAfterArguments();
147+
return getIndexAfterBindings();
148148
}
149149
unsigned getSelfWitnessTableIndex() {
150150
assert(hasTrailingWitnesses());
151-
return getIndexAfterArguments() + 1;
151+
return getIndexAfterBindings() + 1;
152152
}
153153
unsigned getIndexAfterTrailingWitnesses() {
154-
return getIndexAfterArguments() + (hasTrailingWitnesses() ? 2 : 0);
154+
return getIndexAfterBindings() + (hasTrailingWitnesses() ? 2 : 0);
155155
}
156156

157157
public:

0 commit comments

Comments
 (0)