Skip to content

Commit 03f4e40

Browse files
committed
[Async CC] Move self after formal arguments.
Partial applies of methods supply only self. When applies of the resulting thick function are performed, that self was one of the arguments is not known. As a result, self must appear after the fields that might be supplied at the apply site, which is to say all the arguments.
1 parent 63b5ba4 commit 03f4e40

File tree

2 files changed

+39
-34
lines changed

2 files changed

+39
-34
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -143,29 +143,6 @@ AsyncContextLayout irgen::getAsyncContextLayout(
143143
if (hasLocalContextParameter) {
144144
parameters = parameters.drop_back();
145145
}
146-
Optional<AsyncContextLayout::ArgumentInfo> localContextInfo = llvm::None;
147-
if (hasLocalContext) {
148-
if (hasLocalContextParameter) {
149-
SILType ty =
150-
IGF.IGM.silConv.getSILType(localContextParameter, substitutedType,
151-
IGF.IGM.getMaximalTypeExpansionContext());
152-
auto argumentLoweringType =
153-
getArgumentLoweringType(ty.getASTType(), localContextParameter,
154-
/*isNoEscape*/ true);
155-
156-
auto &ti = IGF.getTypeInfoForLowered(argumentLoweringType);
157-
valTypes.push_back(ty);
158-
typeInfos.push_back(&ti);
159-
localContextInfo = {ty, localContextParameter.getConvention()};
160-
} else {
161-
// TODO: DETERMINE: Is there a field in this case to match the sync ABI?
162-
auto &ti = IGF.IGM.getNativeObjectTypeInfo();
163-
SILType ty = SILType::getNativeObjectType(IGF.IGM.Context);
164-
valTypes.push_back(ty);
165-
typeInfos.push_back(&ti);
166-
localContextInfo = {ty, substitutedType->getCalleeConvention()};
167-
}
168-
}
169146

170147
// ArgTypes formalArguments...;
171148
for (auto parameter : parameters) {
@@ -192,6 +169,31 @@ AsyncContextLayout irgen::getAsyncContextLayout(
192169
typeInfos.push_back(&bindingsTI);
193170
}
194171

172+
Optional<AsyncContextLayout::ArgumentInfo> localContextInfo = llvm::None;
173+
if (hasLocalContext) {
174+
if (hasLocalContextParameter) {
175+
SILType ty =
176+
IGF.IGM.silConv.getSILType(localContextParameter, substitutedType,
177+
IGF.IGM.getMaximalTypeExpansionContext());
178+
auto argumentLoweringType =
179+
getArgumentLoweringType(ty.getASTType(), localContextParameter,
180+
/*isNoEscape*/ true);
181+
182+
auto &ti = IGF.getTypeInfoForLowered(argumentLoweringType);
183+
valTypes.push_back(ty);
184+
typeInfos.push_back(&ti);
185+
localContextInfo = {ty, localContextParameter.getConvention()};
186+
} else {
187+
// TODO: DETERMINE: Is there a field in this case to match the sync ABI?
188+
auto &ti = IGF.IGM.getNativeObjectTypeInfo();
189+
SILType ty = SILType::getNativeObjectType(IGF.IGM.Context);
190+
valTypes.push_back(ty);
191+
typeInfos.push_back(&ti);
192+
localContextInfo = {ty, substitutedType->getCalleeConvention()};
193+
}
194+
}
195+
196+
195197
Optional<AsyncContextLayout::TrailingWitnessInfo> trailingWitnessInfo;
196198
if (originalType->getRepresentation() ==
197199
SILFunctionTypeRepresentation::WitnessMethod) {

lib/IRGen/GenCall.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ namespace irgen {
8383
// };
8484
// ResultTypes directResults...;
8585
// };
86+
// ArgTypes formalArguments...;
87+
// SelfType self?;
8688
// };
8789
struct AsyncContextLayout : StructLayout {
8890
struct ArgumentInfo {
@@ -124,14 +126,7 @@ namespace irgen {
124126
unsigned getIndexAfterDirectReturns() {
125127
return getFirstDirectReturnIndex() + getDirectReturnCount();
126128
}
127-
unsigned getLocalContextIndex() {
128-
assert(hasLocalContext());
129-
return getIndexAfterDirectReturns();
130-
}
131-
unsigned getIndexAfterLocalContext() {
132-
return getIndexAfterDirectReturns() + (hasLocalContext() ? 1 : 0);
133-
}
134-
unsigned getFirstArgumentIndex() { return getIndexAfterLocalContext(); }
129+
unsigned getFirstArgumentIndex() { return getIndexAfterDirectReturns(); }
135130
unsigned getIndexAfterArguments() {
136131
return getFirstArgumentIndex() + getArgumentCount();
137132
}
@@ -142,16 +137,24 @@ namespace irgen {
142137
unsigned getIndexAfterBindings() {
143138
return getIndexAfterArguments() + (hasBindings() ? 1 : 0);
144139
}
140+
unsigned getLocalContextIndex() {
141+
assert(hasLocalContext());
142+
return getIndexAfterBindings();
143+
}
144+
unsigned getIndexAfterLocalContext() {
145+
return getIndexAfterBindings() +
146+
(hasLocalContext() ? 1 : 0);
147+
}
145148
unsigned getSelfMetadataIndex() {
146149
assert(hasTrailingWitnesses());
147-
return getIndexAfterBindings();
150+
return getIndexAfterLocalContext();
148151
}
149152
unsigned getSelfWitnessTableIndex() {
150153
assert(hasTrailingWitnesses());
151-
return getIndexAfterBindings() + 1;
154+
return getIndexAfterLocalContext() + 1;
152155
}
153156
unsigned getIndexAfterTrailingWitnesses() {
154-
return getIndexAfterBindings() + (hasTrailingWitnesses() ? 2 : 0);
157+
return getIndexAfterLocalContext() + (hasTrailingWitnesses() ? 2 : 0);
155158
}
156159

157160
public:

0 commit comments

Comments
 (0)