Skip to content

Commit da20912

Browse files
committed
[SILGen] Properly substitute contextual archetypes when generating assign_by_wrapper
Fixes SR-11303 / rdar://problem/54311335
1 parent bb70f0e commit da20912

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib/SILGen/SILGenLValue.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,9 @@ namespace {
13821382
VarDecl *field = dyn_cast<VarDecl>(Storage);
13831383
VarDecl *backingVar = field->getPropertyWrapperBackingProperty();
13841384
assert(backingVar);
1385-
CanType ValType = backingVar->getType()->getCanonicalType();
1385+
CanType ValType =
1386+
SGF.F.mapTypeIntoContext(backingVar->getInterfaceType())
1387+
->getCanonicalType();
13861388
SILType varStorageType =
13871389
SGF.SGM.Types.getSubstitutedStorageType(backingVar, ValType);
13881390
auto typeData =
@@ -1405,7 +1407,7 @@ namespace {
14051407
assert(field->getAttachedPropertyWrappers().size() == 1);
14061408
auto wrapperInfo = field->getAttachedPropertyWrapperTypeInfo(0);
14071409
auto ctor = wrapperInfo.wrappedValueInit;
1408-
SubstitutionMap subs = backingVar->getType()->getMemberSubstitutionMap(
1410+
SubstitutionMap subs = ValType->getMemberSubstitutionMap(
14091411
SGF.getModule().getSwiftModule(), ctor);
14101412

14111413
Type ity = ctor->getInterfaceType();
@@ -1416,8 +1418,8 @@ namespace {
14161418
.asForeign(requiresForeignEntryPoint(ctor));
14171419
RValue initFuncRV =
14181420
SGF.emitApplyPropertyWrapperAllocator(loc, subs,initRef,
1419-
backingVar->getType(),
1420-
CanAnyFunctionType(substIty));
1421+
ValType,
1422+
CanAnyFunctionType(substIty));
14211423
ManagedValue initFn = std::move(initFuncRV).getAsSingleValue(SGF, loc);
14221424

14231425
// Create the allocating setter function. It captures the base address.

test/SILGen/property_wrappers.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,20 @@ public class Container {
449449
}
450450
}
451451

452+
// SR-11303 / rdar://problem/54311335 - crash due to wrong archetype used in generated SIL
453+
public protocol TestProtocol {}
454+
public class TestClass<T> {
455+
@WrapperWithInitialValue var value: T
456+
457+
// CHECK-LABEL: sil hidden [ossa] @$s17property_wrappers9TestClassC5value8protocolACyxGx_qd__tcAA0C8ProtocolRd__lufc
458+
// CHECK: metatype $@thin WrapperWithInitialValue<T>.Type
459+
// CHECK: function_ref @$s17property_wrappers23WrapperWithInitialValueV07wrappedF0ACyxGx_tcfCTc
460+
init<U: TestProtocol>(value: T, protocol: U) {
461+
self.value = value
462+
}
463+
}
464+
465+
452466
// CHECK-LABEL: sil_vtable ClassUsingWrapper {
453467
// CHECK: #ClassUsingWrapper.x!getter.1: (ClassUsingWrapper) -> () -> Int : @$s17property_wrappers17ClassUsingWrapperC1xSivg // ClassUsingWrapper.x.getter
454468
// CHECK: #ClassUsingWrapper.x!setter.1: (ClassUsingWrapper) -> (Int) -> () : @$s17property_wrappers17ClassUsingWrapperC1xSivs // ClassUsingWrapper.x.setter

0 commit comments

Comments
 (0)