Skip to content

Commit ab2345a

Browse files
committed
FunctionPassContext: support setting arbitrary function type representations when creating specialized functions
1 parent 4920ace commit ab2345a

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ClosureSpecialization.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ private struct SpecializationInfo {
410410
// The specialized function is always a thin function. This is important because we add additional
411411
// parameters after the Self parameter of witness methods. In this case the new function is not a
412412
// method anymore.
413-
makeThin: true, makeBare: true)
413+
withRepresentation: .thin, makeBare: true)
414414

415415
context.buildSpecializedFunction(
416416
specializedFunction: specializedFunction,

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/PackSpecialization.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ private struct PackExplodedFunction {
553553
withParams: newParameters,
554554
withResults: newResults,
555555
// If a method has a dynamic self parameter, it cannot be converted into a thin function (non-method).
556-
makeThin: !original.mayBindDynamicSelf)
556+
withRepresentation: original.mayBindDynamicSelf ? nil : .thin)
557557

558558
self.buildSpecializedFunction(context)
559559
}

SwiftCompilerSources/Sources/Optimizer/PassManager/FunctionPassContext.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,13 @@ struct FunctionPassContext : MutatingContext {
168168
from original: Function, withName specializedFunctionName: String,
169169
withParams specializedParameters: [ParameterInfo],
170170
withResults specializedResults: [ResultInfo]? = nil,
171-
makeThin: Bool = false,
171+
withRepresentation: FunctionTypeRepresentation? = nil,
172172
makeBare: Bool = false,
173173
preserveGenericSignature: Bool = true
174174
) -> Function {
175175
return specializedFunctionName._withBridgedStringRef { nameRef in
176176
let bridgedParamInfos = specializedParameters.map { $0._bridged }
177+
let repr = withRepresentation ?? original.loweredFunctionType.functionTypeRepresentation
177178

178179
return bridgedParamInfos.withUnsafeBufferPointer { paramBuf in
179180

@@ -183,15 +184,15 @@ struct FunctionPassContext : MutatingContext {
183184
return bridgedPassContext.createSpecializedFunctionDeclaration(
184185
nameRef, paramBuf.baseAddress, paramBuf.count,
185186
resultBuf.baseAddress, resultBuf.count,
186-
original.bridged, makeThin, makeBare,
187+
original.bridged, repr.bridged, makeBare,
187188
preserveGenericSignature
188189
).function
189190
}
190191
} else {
191192
return bridgedPassContext.createSpecializedFunctionDeclaration(
192193
nameRef, paramBuf.baseAddress, paramBuf.count,
193194
nil, 0,
194-
original.bridged, makeThin, makeBare,
195+
original.bridged, repr.bridged, makeBare,
195196
preserveGenericSignature
196197
).function
197198
}

include/swift/SILOptimizer/OptimizerBridging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ struct BridgedPassContext {
274274
const BridgedResultInfo *_Nullable specializedBridgedResults,
275275
SwiftInt resultCount,
276276
BridgedFunction bridgedOriginal,
277-
bool makeThin,
277+
BridgedASTType::FunctionTypeRepresentation representation,
278278
bool makeBare,
279279
bool preserveGenericSignature) const;
280280

lib/SILOptimizer/Utils/OptimizerBridging.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ createSpecializedFunctionDeclaration(BridgedStringRef specializedName,
393393
const BridgedResultInfo * _Nullable specializedBridgedResults,
394394
SwiftInt resultCount,
395395
BridgedFunction bridgedOriginal,
396-
bool makeThin,
396+
BridgedASTType::FunctionTypeRepresentation representation,
397397
bool makeBare,
398398
bool preserveGenericSignature) const {
399399
auto *original = bridgedOriginal.getFunction();
@@ -415,9 +415,7 @@ createSpecializedFunctionDeclaration(BridgedStringRef specializedName,
415415
// The specialized function is always a thin function. This is important
416416
// because we may add additional parameters after the Self parameter of
417417
// witness methods. In this case the new function is not a method anymore.
418-
auto extInfo = originalType->getExtInfo();
419-
if (makeThin)
420-
extInfo = extInfo.withRepresentation(SILFunctionTypeRepresentation::Thin);
418+
auto extInfo = originalType->getExtInfo().withRepresentation((SILFunctionTypeRepresentation)representation);
421419

422420
auto ClonedTy = SILFunctionType::get(
423421
preserveGenericSignature ? originalType->getInvocationGenericSignature() : GenericSignature(),

0 commit comments

Comments
 (0)