Skip to content

Commit 02683f8

Browse files
Merge pull request #26717 from aschwaighofer/fix_specialization_of_thin_to_thick
SpecializeOpaqueArchetypes: Fix specialization of thin_to_thick_function
2 parents 98a54a1 + 058c43e commit 02683f8

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/SILOptimizer/Transforms/SpecializeOpaqueArchetypes.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,21 @@ class OpaqueSpecializerCloner
256256
Inst->isInitializationOfDest()));
257257
}
258258

259+
SILValue remapResultType(SILLocation loc, SILValue val) {
260+
auto specializedTy = remapType(val->getType());
261+
if (val->getType() == specializedTy)
262+
return val;
263+
return createCast(loc, val, specializedTy);
264+
}
265+
266+
void visitThinToThickFunctionInst(ThinToThickFunctionInst *Inst) {
267+
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
268+
auto loc = getOpLocation(Inst->getLoc());
269+
auto opd = remapResultType(loc, getOpValue(Inst->getOperand()));
270+
recordClonedInstruction(Inst, getBuilder().createThinToThickFunction(
271+
loc, opd, getOpType(Inst->getType())));
272+
}
273+
259274
void visitStoreInst(StoreInst *Inst) {
260275
auto src = getOpValue(Inst->getSrc());
261276
auto dst = getOpValue(Inst->getDest());

test/SILOptimizer/specialize_opaque_type_archetypes.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,3 +539,10 @@ struct Test : RandomAccessCollection {
539539
return foos[i.offset].p
540540
}
541541
}
542+
543+
@inline(never)
544+
func useAbstractFunction<T: P>(_ fn: (Int64) -> T) {}
545+
546+
public func testThinToThick() {
547+
useAbstractFunction(bar)
548+
}

0 commit comments

Comments
 (0)