Skip to content

Commit 8e9dec2

Browse files
committed
[NFC] Construct AsyncContextLayout from module.
Previously, an IRGenFunction was being passed to the functions that construct an AsyncContextLayout. That was not actually necessary and prevented construction of the layout in contexts where no IRGenFunction was present. Here that requirement is eased to requiring an IRGenModule which is indeed required to construct an AsyncContextLayout.
1 parent de1c787 commit 8e9dec2

File tree

4 files changed

+51
-51
lines changed

4 files changed

+51
-51
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,21 @@ static Size getCoroutineContextSize(IRGenModule &IGM,
7878
llvm_unreachable("bad kind");
7979
}
8080

81-
AsyncContextLayout irgen::getAsyncContextLayout(IRGenFunction &IGF,
81+
AsyncContextLayout irgen::getAsyncContextLayout(IRGenModule &IGM,
8282
SILFunction *function) {
8383
SubstitutionMap forwardingSubstitutionMap =
8484
function->getForwardingSubstitutionMap();
8585
CanSILFunctionType originalType = function->getLoweredFunctionType();
8686
CanSILFunctionType substitutedType = originalType->substGenericArgs(
87-
IGF.IGM.getSILModule(), forwardingSubstitutionMap,
88-
IGF.IGM.getMaximalTypeExpansionContext());
89-
auto layout = getAsyncContextLayout(IGF, originalType, substitutedType,
87+
IGM.getSILModule(), forwardingSubstitutionMap,
88+
IGM.getMaximalTypeExpansionContext());
89+
auto layout = getAsyncContextLayout(IGM, originalType, substitutedType,
9090
forwardingSubstitutionMap);
9191
return layout;
9292
}
9393

9494
AsyncContextLayout irgen::getAsyncContextLayout(
95-
IRGenFunction &IGF, CanSILFunctionType originalType,
95+
IRGenModule &IGM, CanSILFunctionType originalType,
9696
CanSILFunctionType substitutedType, SubstitutionMap substitutionMap) {
9797
SmallVector<const TypeInfo *, 4> typeInfos;
9898
SmallVector<SILType, 4> valTypes;
@@ -103,25 +103,25 @@ AsyncContextLayout irgen::getAsyncContextLayout(
103103
SmallVector<SILResultInfo, 4> directReturnInfos;
104104

105105
auto parameters = substitutedType->getParameters();
106-
SILFunctionConventions fnConv(substitutedType, IGF.getSILModule());
106+
SILFunctionConventions fnConv(substitutedType, IGM.getSILModule());
107107

108108
auto addTaskContinuationFunction = [&]() {
109109
auto ty = SILType();
110-
auto &ti = IGF.IGM.getTaskContinuationFunctionPtrTypeInfo();
110+
auto &ti = IGM.getTaskContinuationFunctionPtrTypeInfo();
111111
valTypes.push_back(ty);
112112
typeInfos.push_back(&ti);
113113
};
114114
auto addExecutor = [&]() {
115115
auto ty = SILType();
116-
auto &ti = IGF.IGM.getSwiftExecutorPtrTypeInfo();
116+
auto &ti = IGM.getSwiftExecutorPtrTypeInfo();
117117
valTypes.push_back(ty);
118118
typeInfos.push_back(&ti);
119119
};
120120

121121
// AsyncContext * __ptrauth_swift_async_context_parent Parent;
122122
{
123123
auto ty = SILType();
124-
auto &ti = IGF.IGM.getSwiftContextPtrTypeInfo();
124+
auto &ti = IGM.getSwiftContextPtrTypeInfo();
125125
valTypes.push_back(ty);
126126
typeInfos.push_back(&ti);
127127
}
@@ -136,9 +136,9 @@ AsyncContextLayout irgen::getAsyncContextLayout(
136136
// AsyncContextFlags Flags;
137137
{
138138
auto ty = SILType::getPrimitiveObjectType(
139-
BuiltinIntegerType::get(32, IGF.IGM.IRGen.SIL.getASTContext())
139+
BuiltinIntegerType::get(32, IGM.IRGen.SIL.getASTContext())
140140
->getCanonicalType());
141-
const auto &ti = IGF.IGM.getTypeInfo(ty);
141+
const auto &ti = IGM.getTypeInfo(ty);
142142
valTypes.push_back(ty);
143143
typeInfos.push_back(&ti);
144144
}
@@ -149,19 +149,19 @@ AsyncContextLayout irgen::getAsyncContextLayout(
149149
}
150150

151151
// SwiftError *errorResult;
152-
auto errorCanType = IGF.IGM.Context.getExceptionType();
152+
auto errorCanType = IGM.Context.getExceptionType();
153153
auto errorType = SILType::getPrimitiveObjectType(errorCanType);
154-
auto &errorTypeInfo = IGF.getTypeInfoForLowered(errorCanType);
154+
auto &errorTypeInfo = IGM.getTypeInfoForLowered(errorCanType);
155155
typeInfos.push_back(&errorTypeInfo);
156156
valTypes.push_back(errorType);
157157

158158
// IndirectResultTypes *indirectResults...;
159159
auto indirectResults = fnConv.getIndirectSILResults();
160160
for (auto indirectResult : indirectResults) {
161161
auto ty = fnConv.getSILType(indirectResult,
162-
IGF.IGM.getMaximalTypeExpansionContext());
162+
IGM.getMaximalTypeExpansionContext());
163163
auto retLoweringTy = CanInOutType::get(ty.getASTType());
164-
auto &ti = IGF.getTypeInfoForLowered(retLoweringTy);
164+
auto &ti = IGM.getTypeInfoForLowered(retLoweringTy);
165165
valTypes.push_back(ty);
166166
typeInfos.push_back(&ti);
167167
indirectReturnInfos.push_back(indirectResult);
@@ -178,8 +178,8 @@ AsyncContextLayout irgen::getAsyncContextLayout(
178178
// YieldTypes yieldValues...
179179
for (auto yield : fnConv.getYields()) {
180180
auto ty =
181-
fnConv.getSILType(yield, IGF.IGM.getMaximalTypeExpansionContext());
182-
auto &ti = IGF.getTypeInfoForLowered(ty.getASTType());
181+
fnConv.getSILType(yield, IGM.getMaximalTypeExpansionContext());
182+
auto &ti = IGM.getTypeInfoForLowered(ty.getASTType());
183183
valTypes.push_back(ty);
184184
typeInfos.push_back(&ti);
185185
yieldInfos.push_back(yield);
@@ -188,8 +188,8 @@ AsyncContextLayout irgen::getAsyncContextLayout(
188188
// ResultTypes directResults...;
189189
for (auto result : fnConv.getDirectSILResults()) {
190190
auto ty =
191-
fnConv.getSILType(result, IGF.IGM.getMaximalTypeExpansionContext());
192-
auto &ti = IGF.getTypeInfoForLowered(ty.getASTType());
191+
fnConv.getSILType(result, IGM.getMaximalTypeExpansionContext());
192+
auto &ti = IGM.getTypeInfoForLowered(ty.getASTType());
193193
valTypes.push_back(ty);
194194
typeInfos.push_back(&ti);
195195
directReturnInfos.push_back(result);
@@ -208,25 +208,25 @@ AsyncContextLayout irgen::getAsyncContextLayout(
208208

209209
// ArgTypes formalArguments...;
210210
for (auto parameter : parameters) {
211-
SILType ty = IGF.IGM.silConv.getSILType(
212-
parameter, substitutedType, IGF.IGM.getMaximalTypeExpansionContext());
211+
SILType ty = IGM.silConv.getSILType(
212+
parameter, substitutedType, IGM.getMaximalTypeExpansionContext());
213213

214214
auto argumentLoweringType =
215215
getArgumentLoweringType(ty.getASTType(), parameter,
216216
/*isNoEscape*/ true);
217217

218-
auto &ti = IGF.getTypeInfoForLowered(argumentLoweringType);
218+
auto &ti = IGM.getTypeInfoForLowered(argumentLoweringType);
219219

220220
valTypes.push_back(ty);
221221
typeInfos.push_back(&ti);
222222
paramInfos.push_back({ty, parameter.getConvention()});
223223
}
224224
auto bindings = NecessaryBindings::forAsyncFunctionInvocation(
225-
IGF.IGM, originalType, substitutionMap);
225+
IGM, originalType, substitutionMap);
226226
if (!bindings.empty()) {
227-
auto bindingsSize = bindings.getBufferSize(IGF.IGM);
228-
auto &bindingsTI = IGF.IGM.getOpaqueStorageTypeInfo(
229-
bindingsSize, IGF.IGM.getPointerAlignment());
227+
auto bindingsSize = bindings.getBufferSize(IGM);
228+
auto &bindingsTI = IGM.getOpaqueStorageTypeInfo(
229+
bindingsSize, IGM.getPointerAlignment());
230230
valTypes.push_back(SILType());
231231
typeInfos.push_back(&bindingsTI);
232232
}
@@ -235,20 +235,20 @@ AsyncContextLayout irgen::getAsyncContextLayout(
235235
if (hasLocalContext) {
236236
if (hasLocalContextParameter) {
237237
SILType ty =
238-
IGF.IGM.silConv.getSILType(localContextParameter, substitutedType,
239-
IGF.IGM.getMaximalTypeExpansionContext());
238+
IGM.silConv.getSILType(localContextParameter, substitutedType,
239+
IGM.getMaximalTypeExpansionContext());
240240
auto argumentLoweringType =
241241
getArgumentLoweringType(ty.getASTType(), localContextParameter,
242242
/*isNoEscape*/ true);
243243

244-
auto &ti = IGF.getTypeInfoForLowered(argumentLoweringType);
244+
auto &ti = IGM.getTypeInfoForLowered(argumentLoweringType);
245245
valTypes.push_back(ty);
246246
typeInfos.push_back(&ti);
247247
localContextInfo = {ty, localContextParameter.getConvention()};
248248
} else {
249249
// TODO: DETERMINE: Is there a field in this case to match the sync ABI?
250-
auto &ti = IGF.IGM.getNativeObjectTypeInfo();
251-
SILType ty = SILType::getNativeObjectType(IGF.IGM.Context);
250+
auto &ti = IGM.getNativeObjectTypeInfo();
251+
SILType ty = SILType::getNativeObjectType(IGM.Context);
252252
valTypes.push_back(ty);
253253
typeInfos.push_back(&ti);
254254
localContextInfo = {ty, substitutedType->getCalleeConvention()};
@@ -259,27 +259,27 @@ AsyncContextLayout irgen::getAsyncContextLayout(
259259
Optional<AsyncContextLayout::TrailingWitnessInfo> trailingWitnessInfo;
260260
if (originalType->getRepresentation() ==
261261
SILFunctionTypeRepresentation::WitnessMethod) {
262-
assert(getTrailingWitnessSignatureLength(IGF.IGM, originalType) == 2);
262+
assert(getTrailingWitnessSignatureLength(IGM, originalType) == 2);
263263

264264
// First, the Self metadata.
265265
{
266266
auto ty = SILType();
267-
auto &ti = IGF.IGM.getTypeMetadataPtrTypeInfo();
267+
auto &ti = IGM.getTypeMetadataPtrTypeInfo();
268268
valTypes.push_back(ty);
269269
typeInfos.push_back(&ti);
270270
}
271271
// Then, the Self witness table.
272272
{
273273
auto ty = SILType();
274-
auto &ti = IGF.IGM.getWitnessTablePtrTypeInfo();
274+
auto &ti = IGM.getWitnessTablePtrTypeInfo();
275275
valTypes.push_back(ty);
276276
typeInfos.push_back(&ti);
277277
}
278278
trailingWitnessInfo = AsyncContextLayout::TrailingWitnessInfo();
279279
}
280280

281281
return AsyncContextLayout(
282-
IGF.IGM, LayoutStrategy::Optimal, valTypes, typeInfos, IGF, originalType,
282+
IGM, LayoutStrategy::Optimal, valTypes, typeInfos, originalType,
283283
substitutedType, substitutionMap, std::move(bindings),
284284
trailingWitnessInfo, errorType, canHaveValidError, paramInfos,
285285
isCoroutine, yieldInfos, indirectReturnInfos, directReturnInfos,
@@ -288,7 +288,7 @@ AsyncContextLayout irgen::getAsyncContextLayout(
288288

289289
AsyncContextLayout::AsyncContextLayout(
290290
IRGenModule &IGM, LayoutStrategy strategy, ArrayRef<SILType> fieldTypes,
291-
ArrayRef<const TypeInfo *> fieldTypeInfos, IRGenFunction &IGF,
291+
ArrayRef<const TypeInfo *> fieldTypeInfos,
292292
CanSILFunctionType originalType, CanSILFunctionType substitutedType,
293293
SubstitutionMap substitutionMap, NecessaryBindings &&bindings,
294294
Optional<TrailingWitnessInfo> trailingWitnessInfo, SILType errorType,
@@ -299,7 +299,7 @@ AsyncContextLayout::AsyncContextLayout(
299299
Optional<AsyncContextLayout::ArgumentInfo> localContextInfo)
300300
: StructLayout(IGM, /*decl=*/nullptr, LayoutKind::NonHeapObject, strategy,
301301
fieldTypeInfos, /*typeToFill*/ nullptr),
302-
IGF(IGF), originalType(originalType), substitutedType(substitutedType),
302+
IGM(IGM), originalType(originalType), substitutedType(substitutedType),
303303
substitutionMap(substitutionMap), errorType(errorType),
304304
canHaveValidError(canHaveValidError), isCoroutine(isCoroutine),
305305
yieldInfos(yieldInfos.begin(), yieldInfos.end()),
@@ -2171,7 +2171,7 @@ class AsyncCallEmission final : public CallEmission {
21712171
AsyncContextLayout getAsyncContextLayout() {
21722172
if (!asyncContextLayout) {
21732173
asyncContextLayout.emplace(::getAsyncContextLayout(
2174-
IGF, getCallee().getOrigFunctionType(),
2174+
IGF.IGM, getCallee().getOrigFunctionType(),
21752175
getCallee().getSubstFunctionType(), getCallee().getSubstitutions()));
21762176
}
21772177
return *asyncContextLayout;

lib/IRGen/GenCall.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ namespace irgen {
105105
ResumeParentExecutor = 1,
106106
Error = 1,
107107
};
108-
IRGenFunction &IGF;
108+
IRGenModule &IGM;
109109
CanSILFunctionType originalType;
110110
CanSILFunctionType substitutedType;
111111
SubstitutionMap substitutionMap;
@@ -254,9 +254,9 @@ namespace irgen {
254254
// indexing of the function parameters, *not* the indexing of
255255
// AsyncContextLayout.
256256
SILType getParameterType(unsigned index) {
257-
SILFunctionConventions origConv(substitutedType, IGF.getSILModule());
257+
SILFunctionConventions origConv(substitutedType, IGM.getSILModule());
258258
return origConv.getSILArgumentType(
259-
index, IGF.IGM.getMaximalTypeExpansionContext());
259+
index, IGM.getMaximalTypeExpansionContext());
260260
}
261261
unsigned getArgumentCount() { return argumentInfos.size(); }
262262
bool hasTrailingWitnesses() { return (bool)trailingWitnessInfo; }
@@ -283,7 +283,7 @@ namespace irgen {
283283

284284
AsyncContextLayout(
285285
IRGenModule &IGM, LayoutStrategy strategy, ArrayRef<SILType> fieldTypes,
286-
ArrayRef<const TypeInfo *> fieldTypeInfos, IRGenFunction &IGF,
286+
ArrayRef<const TypeInfo *> fieldTypeInfos,
287287
CanSILFunctionType originalType, CanSILFunctionType substitutedType,
288288
SubstitutionMap substitutionMap, NecessaryBindings &&bindings,
289289
Optional<TrailingWitnessInfo> trailingWitnessInfo, SILType errorType,
@@ -294,18 +294,18 @@ namespace irgen {
294294
Optional<ArgumentInfo> localContextInfo);
295295
};
296296

297-
llvm::Value *getDynamicAsyncContextSize(IRGenFunction &IGF,
298-
AsyncContextLayout layout,
299-
CanSILFunctionType functionType,
300-
llvm::Value *thickContext);
301-
AsyncContextLayout getAsyncContextLayout(IRGenFunction &IGF,
297+
AsyncContextLayout getAsyncContextLayout(IRGenModule &IGM,
302298
SILFunction *function);
303299

304-
AsyncContextLayout getAsyncContextLayout(IRGenFunction &IGF,
300+
AsyncContextLayout getAsyncContextLayout(IRGenModule &IGM,
305301
CanSILFunctionType originalType,
306302
CanSILFunctionType substitutedType,
307303
SubstitutionMap substitutionMap);
308304

305+
llvm::Value *getDynamicAsyncContextSize(IRGenFunction &IGF,
306+
AsyncContextLayout layout,
307+
CanSILFunctionType functionType,
308+
llvm::Value *thickContext);
309309
llvm::CallingConv::ID expandCallingConv(IRGenModule &IGM,
310310
SILFunctionTypeRepresentation convention);
311311

lib/IRGen/GenFunc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ class AsyncPartialApplicationForwarderEmission
10671067
: PartialApplicationForwarderEmission(
10681068
IGM, subIGF, fwd, staticFnPtr, calleeHasContext, origSig, origType,
10691069
substType, outType, subs, layout, conventions),
1070-
layout(getAsyncContextLayout(subIGF, origType, substType, subs)),
1070+
layout(getAsyncContextLayout(subIGF.IGM, origType, substType, subs)),
10711071
currentArgumentIndex(outType->getNumParameters()) {
10721072
task = origParams.claimNext();
10731073
executor = origParams.claimNext();

lib/IRGen/IRGenSIL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ class IRGenSILFunction :
11751175
} // end anonymous namespace
11761176

11771177
static AsyncContextLayout getAsyncContextLayout(IRGenSILFunction &IGF) {
1178-
return getAsyncContextLayout(IGF, IGF.CurSILFn);
1178+
return getAsyncContextLayout(IGF.IGM, IGF.CurSILFn);
11791179
}
11801180

11811181
namespace {
@@ -3064,7 +3064,7 @@ void IRGenSILFunction::visitPartialApplyInst(swift::PartialApplyInst *i) {
30643064
i->getSubstCalleeType());
30653065
llvm::Value *innerContext = std::get<1>(result);
30663066
auto layout =
3067-
getAsyncContextLayout(*this, i->getOrigCalleeType(),
3067+
getAsyncContextLayout(IGM, i->getOrigCalleeType(),
30683068
i->getSubstCalleeType(), i->getSubstitutionMap());
30693069
auto size = getDynamicAsyncContextSize(
30703070
*this, layout, i->getOrigCalleeType(), innerContext);

0 commit comments

Comments
 (0)