Skip to content

Commit cf73ead

Browse files
authored
Merge pull request #12112 from jckarter/dynamic-self-synthetic-capture-4.0
[4.0] SIL: Substitute DynamicSelfType out of context when synthesizing a capture parameter for it.
2 parents 8de71ad + 0773224 commit cf73ead

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/SIL/SILFunctionType.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,9 +765,14 @@ static CanSILFunctionType getSILFunctionType(SILModule &M,
765765
for (auto capture : loweredCaptures.getCaptures()) {
766766
if (capture.isDynamicSelfMetadata()) {
767767
ParameterConvention convention = ParameterConvention::Direct_Unowned;
768+
auto dynamicSelfInterfaceType = GenericEnvironment::mapTypeOutOfContext(
769+
function->getGenericEnvironment(),
770+
loweredCaptures.getDynamicSelfType());
771+
768772
auto selfMetatype = MetatypeType::get(
769-
loweredCaptures.getDynamicSelfType(),
773+
dynamicSelfInterfaceType,
770774
MetatypeRepresentation::Thick);
775+
771776
auto canSelfMetatype = getCanonicalType(selfMetatype);
772777
SILParameterInfo param(canSelfMetatype, convention);
773778
inputs.push_back(param);

test/SILGen/dynamic_self.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,28 @@ class Derived : Base {
363363
}
364364
}
365365

366+
class Generic<T> {
367+
// Examples where we have to add a special argument to capture Self's metadata
368+
func t1() -> Self {
369+
// CHECK-LABEL: sil private @_T012dynamic_self7GenericC2t1ACyxGXDyFAEXDSgycfU_ : $@convention(thin) <T> (@owned <τ_0_0> { var @sil_weak Optional<Generic<τ_0_0>> } <T>, @thick @dynamic_self Generic<T>.Type) -> @owned Optional<Generic<T>>
370+
_ = {[weak self] in self }
371+
return self
372+
}
373+
374+
func t2() -> Self {
375+
// CHECK-LABEL: sil private @_T012dynamic_self7GenericC2t2ACyxGXDyFAEXD_AEXDtycfU_ : $@convention(thin) <T> (@owned (Generic<T>, Generic<T>), @thick @dynamic_self Generic<T>.Type) -> (@owned Generic<T>, @owned Generic<T>)
376+
let selves = (self, self)
377+
_ = { selves }
378+
return self
379+
}
380+
381+
func t3() -> Self {
382+
// CHECK-LABEL: sil private @_T012dynamic_self7GenericC2t3ACyxGXDyFAEXDycfU_ : $@convention(thin) <T> (@owned @sil_unowned Generic<T>, @thick @dynamic_self Generic<T>.Type) -> @owned Generic<T>
383+
_ = {[unowned self] in self }
384+
return self
385+
}
386+
}
387+
366388
// CHECK-LABEL: sil_witness_table hidden X: P module dynamic_self {
367389
// CHECK: method #P.f!1: {{.*}} : @_T012dynamic_self1XCAA1PA2aDP1f{{[_0-9a-zA-Z]*}}FTW
368390

0 commit comments

Comments
 (0)