Skip to content

[NFC] Construct AsyncContextLayout from module. #34585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 38 additions & 38 deletions lib/IRGen/GenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ static Size getCoroutineContextSize(IRGenModule &IGM,
llvm_unreachable("bad kind");
}

AsyncContextLayout irgen::getAsyncContextLayout(IRGenFunction &IGF,
AsyncContextLayout irgen::getAsyncContextLayout(IRGenModule &IGM,
SILFunction *function) {
SubstitutionMap forwardingSubstitutionMap =
function->getForwardingSubstitutionMap();
CanSILFunctionType originalType = function->getLoweredFunctionType();
CanSILFunctionType substitutedType = originalType->substGenericArgs(
IGF.IGM.getSILModule(), forwardingSubstitutionMap,
IGF.IGM.getMaximalTypeExpansionContext());
auto layout = getAsyncContextLayout(IGF, originalType, substitutedType,
IGM.getSILModule(), forwardingSubstitutionMap,
IGM.getMaximalTypeExpansionContext());
auto layout = getAsyncContextLayout(IGM, originalType, substitutedType,
forwardingSubstitutionMap);
return layout;
}

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

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

auto addTaskContinuationFunction = [&]() {
auto ty = SILType();
auto &ti = IGF.IGM.getTaskContinuationFunctionPtrTypeInfo();
auto &ti = IGM.getTaskContinuationFunctionPtrTypeInfo();
valTypes.push_back(ty);
typeInfos.push_back(&ti);
};
auto addExecutor = [&]() {
auto ty = SILType();
auto &ti = IGF.IGM.getSwiftExecutorPtrTypeInfo();
auto &ti = IGM.getSwiftExecutorPtrTypeInfo();
valTypes.push_back(ty);
typeInfos.push_back(&ti);
};

// AsyncContext * __ptrauth_swift_async_context_parent Parent;
{
auto ty = SILType();
auto &ti = IGF.IGM.getSwiftContextPtrTypeInfo();
auto &ti = IGM.getSwiftContextPtrTypeInfo();
valTypes.push_back(ty);
typeInfos.push_back(&ti);
}
Expand All @@ -136,9 +136,9 @@ AsyncContextLayout irgen::getAsyncContextLayout(
// AsyncContextFlags Flags;
{
auto ty = SILType::getPrimitiveObjectType(
BuiltinIntegerType::get(32, IGF.IGM.IRGen.SIL.getASTContext())
BuiltinIntegerType::get(32, IGM.IRGen.SIL.getASTContext())
->getCanonicalType());
const auto &ti = IGF.IGM.getTypeInfo(ty);
const auto &ti = IGM.getTypeInfo(ty);
valTypes.push_back(ty);
typeInfos.push_back(&ti);
}
Expand All @@ -149,19 +149,19 @@ AsyncContextLayout irgen::getAsyncContextLayout(
}

// SwiftError *errorResult;
auto errorCanType = IGF.IGM.Context.getExceptionType();
auto errorCanType = IGM.Context.getExceptionType();
auto errorType = SILType::getPrimitiveObjectType(errorCanType);
auto &errorTypeInfo = IGF.getTypeInfoForLowered(errorCanType);
auto &errorTypeInfo = IGM.getTypeInfoForLowered(errorCanType);
typeInfos.push_back(&errorTypeInfo);
valTypes.push_back(errorType);

// IndirectResultTypes *indirectResults...;
auto indirectResults = fnConv.getIndirectSILResults();
for (auto indirectResult : indirectResults) {
auto ty = fnConv.getSILType(indirectResult,
IGF.IGM.getMaximalTypeExpansionContext());
IGM.getMaximalTypeExpansionContext());
auto retLoweringTy = CanInOutType::get(ty.getASTType());
auto &ti = IGF.getTypeInfoForLowered(retLoweringTy);
auto &ti = IGM.getTypeInfoForLowered(retLoweringTy);
valTypes.push_back(ty);
typeInfos.push_back(&ti);
indirectReturnInfos.push_back(indirectResult);
Expand All @@ -178,8 +178,8 @@ AsyncContextLayout irgen::getAsyncContextLayout(
// YieldTypes yieldValues...
for (auto yield : fnConv.getYields()) {
auto ty =
fnConv.getSILType(yield, IGF.IGM.getMaximalTypeExpansionContext());
auto &ti = IGF.getTypeInfoForLowered(ty.getASTType());
fnConv.getSILType(yield, IGM.getMaximalTypeExpansionContext());
auto &ti = IGM.getTypeInfoForLowered(ty.getASTType());
valTypes.push_back(ty);
typeInfos.push_back(&ti);
yieldInfos.push_back(yield);
Expand All @@ -188,8 +188,8 @@ AsyncContextLayout irgen::getAsyncContextLayout(
// ResultTypes directResults...;
for (auto result : fnConv.getDirectSILResults()) {
auto ty =
fnConv.getSILType(result, IGF.IGM.getMaximalTypeExpansionContext());
auto &ti = IGF.getTypeInfoForLowered(ty.getASTType());
fnConv.getSILType(result, IGM.getMaximalTypeExpansionContext());
auto &ti = IGM.getTypeInfoForLowered(ty.getASTType());
valTypes.push_back(ty);
typeInfos.push_back(&ti);
directReturnInfos.push_back(result);
Expand All @@ -208,25 +208,25 @@ AsyncContextLayout irgen::getAsyncContextLayout(

// ArgTypes formalArguments...;
for (auto parameter : parameters) {
SILType ty = IGF.IGM.silConv.getSILType(
parameter, substitutedType, IGF.IGM.getMaximalTypeExpansionContext());
SILType ty = IGM.silConv.getSILType(
parameter, substitutedType, IGM.getMaximalTypeExpansionContext());

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

auto &ti = IGF.getTypeInfoForLowered(argumentLoweringType);
auto &ti = IGM.getTypeInfoForLowered(argumentLoweringType);

valTypes.push_back(ty);
typeInfos.push_back(&ti);
paramInfos.push_back({ty, parameter.getConvention()});
}
auto bindings = NecessaryBindings::forAsyncFunctionInvocation(
IGF.IGM, originalType, substitutionMap);
IGM, originalType, substitutionMap);
if (!bindings.empty()) {
auto bindingsSize = bindings.getBufferSize(IGF.IGM);
auto &bindingsTI = IGF.IGM.getOpaqueStorageTypeInfo(
bindingsSize, IGF.IGM.getPointerAlignment());
auto bindingsSize = bindings.getBufferSize(IGM);
auto &bindingsTI = IGM.getOpaqueStorageTypeInfo(
bindingsSize, IGM.getPointerAlignment());
valTypes.push_back(SILType());
typeInfos.push_back(&bindingsTI);
}
Expand All @@ -235,20 +235,20 @@ AsyncContextLayout irgen::getAsyncContextLayout(
if (hasLocalContext) {
if (hasLocalContextParameter) {
SILType ty =
IGF.IGM.silConv.getSILType(localContextParameter, substitutedType,
IGF.IGM.getMaximalTypeExpansionContext());
IGM.silConv.getSILType(localContextParameter, substitutedType,
IGM.getMaximalTypeExpansionContext());
auto argumentLoweringType =
getArgumentLoweringType(ty.getASTType(), localContextParameter,
/*isNoEscape*/ true);

auto &ti = IGF.getTypeInfoForLowered(argumentLoweringType);
auto &ti = IGM.getTypeInfoForLowered(argumentLoweringType);
valTypes.push_back(ty);
typeInfos.push_back(&ti);
localContextInfo = {ty, localContextParameter.getConvention()};
} else {
// TODO: DETERMINE: Is there a field in this case to match the sync ABI?
auto &ti = IGF.IGM.getNativeObjectTypeInfo();
SILType ty = SILType::getNativeObjectType(IGF.IGM.Context);
auto &ti = IGM.getNativeObjectTypeInfo();
SILType ty = SILType::getNativeObjectType(IGM.Context);
valTypes.push_back(ty);
typeInfos.push_back(&ti);
localContextInfo = {ty, substitutedType->getCalleeConvention()};
Expand All @@ -259,27 +259,27 @@ AsyncContextLayout irgen::getAsyncContextLayout(
Optional<AsyncContextLayout::TrailingWitnessInfo> trailingWitnessInfo;
if (originalType->getRepresentation() ==
SILFunctionTypeRepresentation::WitnessMethod) {
assert(getTrailingWitnessSignatureLength(IGF.IGM, originalType) == 2);
assert(getTrailingWitnessSignatureLength(IGM, originalType) == 2);

// First, the Self metadata.
{
auto ty = SILType();
auto &ti = IGF.IGM.getTypeMetadataPtrTypeInfo();
auto &ti = IGM.getTypeMetadataPtrTypeInfo();
valTypes.push_back(ty);
typeInfos.push_back(&ti);
}
// Then, the Self witness table.
{
auto ty = SILType();
auto &ti = IGF.IGM.getWitnessTablePtrTypeInfo();
auto &ti = IGM.getWitnessTablePtrTypeInfo();
valTypes.push_back(ty);
typeInfos.push_back(&ti);
}
trailingWitnessInfo = AsyncContextLayout::TrailingWitnessInfo();
}

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

AsyncContextLayout::AsyncContextLayout(
IRGenModule &IGM, LayoutStrategy strategy, ArrayRef<SILType> fieldTypes,
ArrayRef<const TypeInfo *> fieldTypeInfos, IRGenFunction &IGF,
ArrayRef<const TypeInfo *> fieldTypeInfos,
CanSILFunctionType originalType, CanSILFunctionType substitutedType,
SubstitutionMap substitutionMap, NecessaryBindings &&bindings,
Optional<TrailingWitnessInfo> trailingWitnessInfo, SILType errorType,
Expand All @@ -299,7 +299,7 @@ AsyncContextLayout::AsyncContextLayout(
Optional<AsyncContextLayout::ArgumentInfo> localContextInfo)
: StructLayout(IGM, /*decl=*/nullptr, LayoutKind::NonHeapObject, strategy,
fieldTypeInfos, /*typeToFill*/ nullptr),
IGF(IGF), originalType(originalType), substitutedType(substitutedType),
IGM(IGM), originalType(originalType), substitutedType(substitutedType),
substitutionMap(substitutionMap), errorType(errorType),
canHaveValidError(canHaveValidError), isCoroutine(isCoroutine),
yieldInfos(yieldInfos.begin(), yieldInfos.end()),
Expand Down Expand Up @@ -2171,7 +2171,7 @@ class AsyncCallEmission final : public CallEmission {
AsyncContextLayout getAsyncContextLayout() {
if (!asyncContextLayout) {
asyncContextLayout.emplace(::getAsyncContextLayout(
IGF, getCallee().getOrigFunctionType(),
IGF.IGM, getCallee().getOrigFunctionType(),
getCallee().getSubstFunctionType(), getCallee().getSubstitutions()));
}
return *asyncContextLayout;
Expand Down
20 changes: 10 additions & 10 deletions lib/IRGen/GenCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace irgen {
ResumeParentExecutor = 1,
Error = 1,
};
IRGenFunction &IGF;
IRGenModule &IGM;
CanSILFunctionType originalType;
CanSILFunctionType substitutedType;
SubstitutionMap substitutionMap;
Expand Down Expand Up @@ -254,9 +254,9 @@ namespace irgen {
// indexing of the function parameters, *not* the indexing of
// AsyncContextLayout.
SILType getParameterType(unsigned index) {
SILFunctionConventions origConv(substitutedType, IGF.getSILModule());
SILFunctionConventions origConv(substitutedType, IGM.getSILModule());
return origConv.getSILArgumentType(
index, IGF.IGM.getMaximalTypeExpansionContext());
index, IGM.getMaximalTypeExpansionContext());
}
unsigned getArgumentCount() { return argumentInfos.size(); }
bool hasTrailingWitnesses() { return (bool)trailingWitnessInfo; }
Expand All @@ -283,7 +283,7 @@ namespace irgen {

AsyncContextLayout(
IRGenModule &IGM, LayoutStrategy strategy, ArrayRef<SILType> fieldTypes,
ArrayRef<const TypeInfo *> fieldTypeInfos, IRGenFunction &IGF,
ArrayRef<const TypeInfo *> fieldTypeInfos,
CanSILFunctionType originalType, CanSILFunctionType substitutedType,
SubstitutionMap substitutionMap, NecessaryBindings &&bindings,
Optional<TrailingWitnessInfo> trailingWitnessInfo, SILType errorType,
Expand All @@ -294,18 +294,18 @@ namespace irgen {
Optional<ArgumentInfo> localContextInfo);
};

llvm::Value *getDynamicAsyncContextSize(IRGenFunction &IGF,
AsyncContextLayout layout,
CanSILFunctionType functionType,
llvm::Value *thickContext);
AsyncContextLayout getAsyncContextLayout(IRGenFunction &IGF,
AsyncContextLayout getAsyncContextLayout(IRGenModule &IGM,
SILFunction *function);

AsyncContextLayout getAsyncContextLayout(IRGenFunction &IGF,
AsyncContextLayout getAsyncContextLayout(IRGenModule &IGM,
CanSILFunctionType originalType,
CanSILFunctionType substitutedType,
SubstitutionMap substitutionMap);

llvm::Value *getDynamicAsyncContextSize(IRGenFunction &IGF,
AsyncContextLayout layout,
CanSILFunctionType functionType,
llvm::Value *thickContext);
llvm::CallingConv::ID expandCallingConv(IRGenModule &IGM,
SILFunctionTypeRepresentation convention);

Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ class AsyncPartialApplicationForwarderEmission
: PartialApplicationForwarderEmission(
IGM, subIGF, fwd, staticFnPtr, calleeHasContext, origSig, origType,
substType, outType, subs, layout, conventions),
layout(getAsyncContextLayout(subIGF, origType, substType, subs)),
layout(getAsyncContextLayout(subIGF.IGM, origType, substType, subs)),
currentArgumentIndex(outType->getNumParameters()) {
task = origParams.claimNext();
executor = origParams.claimNext();
Expand Down
4 changes: 2 additions & 2 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ class IRGenSILFunction :
} // end anonymous namespace

static AsyncContextLayout getAsyncContextLayout(IRGenSILFunction &IGF) {
return getAsyncContextLayout(IGF, IGF.CurSILFn);
return getAsyncContextLayout(IGF.IGM, IGF.CurSILFn);
}

namespace {
Expand Down Expand Up @@ -3064,7 +3064,7 @@ void IRGenSILFunction::visitPartialApplyInst(swift::PartialApplyInst *i) {
i->getSubstCalleeType());
llvm::Value *innerContext = std::get<1>(result);
auto layout =
getAsyncContextLayout(*this, i->getOrigCalleeType(),
getAsyncContextLayout(IGM, i->getOrigCalleeType(),
i->getSubstCalleeType(), i->getSubstitutionMap());
auto size = getDynamicAsyncContextSize(
*this, layout, i->getOrigCalleeType(), innerContext);
Expand Down