mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
FunctionPassContext: support setting arbitrary function type representations when creating specialized functions
This commit is contained in:
@@ -410,7 +410,7 @@ private struct SpecializationInfo {
|
||||
// The specialized function is always a thin function. This is important because we add additional
|
||||
// parameters after the Self parameter of witness methods. In this case the new function is not a
|
||||
// method anymore.
|
||||
makeThin: true, makeBare: true)
|
||||
withRepresentation: .thin, makeBare: true)
|
||||
|
||||
context.buildSpecializedFunction(
|
||||
specializedFunction: specializedFunction,
|
||||
|
||||
@@ -553,7 +553,7 @@ private struct PackExplodedFunction {
|
||||
withParams: newParameters,
|
||||
withResults: newResults,
|
||||
// If a method has a dynamic self parameter, it cannot be converted into a thin function (non-method).
|
||||
makeThin: !original.mayBindDynamicSelf)
|
||||
withRepresentation: original.mayBindDynamicSelf ? nil : .thin)
|
||||
|
||||
self.buildSpecializedFunction(context)
|
||||
}
|
||||
|
||||
@@ -168,12 +168,13 @@ struct FunctionPassContext : MutatingContext {
|
||||
from original: Function, withName specializedFunctionName: String,
|
||||
withParams specializedParameters: [ParameterInfo],
|
||||
withResults specializedResults: [ResultInfo]? = nil,
|
||||
makeThin: Bool = false,
|
||||
withRepresentation: FunctionTypeRepresentation? = nil,
|
||||
makeBare: Bool = false,
|
||||
preserveGenericSignature: Bool = true
|
||||
) -> Function {
|
||||
return specializedFunctionName._withBridgedStringRef { nameRef in
|
||||
let bridgedParamInfos = specializedParameters.map { $0._bridged }
|
||||
let repr = withRepresentation ?? original.loweredFunctionType.functionTypeRepresentation
|
||||
|
||||
return bridgedParamInfos.withUnsafeBufferPointer { paramBuf in
|
||||
|
||||
@@ -183,7 +184,7 @@ struct FunctionPassContext : MutatingContext {
|
||||
return bridgedPassContext.createSpecializedFunctionDeclaration(
|
||||
nameRef, paramBuf.baseAddress, paramBuf.count,
|
||||
resultBuf.baseAddress, resultBuf.count,
|
||||
original.bridged, makeThin, makeBare,
|
||||
original.bridged, repr.bridged, makeBare,
|
||||
preserveGenericSignature
|
||||
).function
|
||||
}
|
||||
@@ -191,7 +192,7 @@ struct FunctionPassContext : MutatingContext {
|
||||
return bridgedPassContext.createSpecializedFunctionDeclaration(
|
||||
nameRef, paramBuf.baseAddress, paramBuf.count,
|
||||
nil, 0,
|
||||
original.bridged, makeThin, makeBare,
|
||||
original.bridged, repr.bridged, makeBare,
|
||||
preserveGenericSignature
|
||||
).function
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ struct BridgedPassContext {
|
||||
const BridgedResultInfo *_Nullable specializedBridgedResults,
|
||||
SwiftInt resultCount,
|
||||
BridgedFunction bridgedOriginal,
|
||||
bool makeThin,
|
||||
BridgedASTType::FunctionTypeRepresentation representation,
|
||||
bool makeBare,
|
||||
bool preserveGenericSignature) const;
|
||||
|
||||
|
||||
@@ -393,7 +393,7 @@ createSpecializedFunctionDeclaration(BridgedStringRef specializedName,
|
||||
const BridgedResultInfo * _Nullable specializedBridgedResults,
|
||||
SwiftInt resultCount,
|
||||
BridgedFunction bridgedOriginal,
|
||||
bool makeThin,
|
||||
BridgedASTType::FunctionTypeRepresentation representation,
|
||||
bool makeBare,
|
||||
bool preserveGenericSignature) const {
|
||||
auto *original = bridgedOriginal.getFunction();
|
||||
@@ -415,9 +415,7 @@ createSpecializedFunctionDeclaration(BridgedStringRef specializedName,
|
||||
// The specialized function is always a thin function. This is important
|
||||
// because we may add additional parameters after the Self parameter of
|
||||
// witness methods. In this case the new function is not a method anymore.
|
||||
auto extInfo = originalType->getExtInfo();
|
||||
if (makeThin)
|
||||
extInfo = extInfo.withRepresentation(SILFunctionTypeRepresentation::Thin);
|
||||
auto extInfo = originalType->getExtInfo().withRepresentation((SILFunctionTypeRepresentation)representation);
|
||||
|
||||
auto ClonedTy = SILFunctionType::get(
|
||||
preserveGenericSignature ? originalType->getInvocationGenericSignature() : GenericSignature(),
|
||||
|
||||
Reference in New Issue
Block a user