Skip to content

Commit 2840478

Browse files
committed
When preparing necessary bindings, we sometimes decide to capture
bound generic type metadata rather than its individual components. Don't crash when actually restoring that metadata. Fixes SR-901.
1 parent 479d792 commit 2840478

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

lib/IRGen/GenProto.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,19 +2612,19 @@ void irgen::bindGenericRequirement(IRGenFunction &IGF,
26122612
GenericRequirement requirement,
26132613
llvm::Value *value,
26142614
GetTypeParameterInContextFn getInContext) {
2615-
// Get the corresponding context archetype.
2616-
auto archetype = cast<ArchetypeType>(getInContext(requirement.TypeParameter));
2615+
// Get the corresponding context type.
2616+
auto type = getInContext(requirement.TypeParameter);
26172617

26182618
if (auto proto = requirement.Protocol) {
2619+
assert(isa<ArchetypeType>(type));
26192620
assert(value->getType() == IGF.IGM.WitnessTablePtrTy);
2620-
setProtocolWitnessTableName(IGF.IGM, value, archetype, proto);
2621+
setProtocolWitnessTableName(IGF.IGM, value, type, proto);
26212622
auto kind = LocalTypeDataKind::forAbstractProtocolWitnessTable(proto);
2622-
IGF.setUnscopedLocalTypeData(archetype, kind, value);
2623+
IGF.setUnscopedLocalTypeData(type, kind, value);
26232624
} else {
26242625
assert(value->getType() == IGF.IGM.TypeMetadataPtrTy);
2625-
setTypeMetadataName(IGF.IGM, value, archetype);
2626-
auto kind = LocalTypeDataKind::forTypeMetadata();
2627-
IGF.setUnscopedLocalTypeData(archetype, kind, value);
2626+
setTypeMetadataName(IGF.IGM, value, type);
2627+
IGF.bindLocalTypeDataFromTypeMetadata(type, IsExact, value);
26282628
}
26292629
}
26302630

test/IRGen/partial_apply.sil

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,3 +573,17 @@ bb0(%0 : $Int):
573573
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds %swift.type*, %swift.type** [[BUFFER]], i32 2
574574
// CHECK-NEXT: [[T1:%.*]] = bitcast %swift.type** [[T0]] to i8***
575575
// CHECK-NEXT: %T.Y.P2 = load i8**, i8*** [[T1]], align 8
576+
577+
struct ComplexBoundedType<T: P2> {}
578+
579+
// SR-901: Ensure that a partial_apply which captures bound generic type
580+
// metadata doesn't crash when restoring the generic context.
581+
582+
sil hidden_external @generic_function : $@convention(thin) <T> () -> ()
583+
sil @partial_apply_with_generic_type : $@convention(thin) <U: P2> () -> () {
584+
bb0:
585+
%fn = function_ref @generic_function : $@convention(thin) <T> () -> ()
586+
%pa = partial_apply %fn <ComplexBoundedType<U>>() : $@convention(thin) <T> () -> ()
587+
%result = tuple ()
588+
return %result : $()
589+
}

0 commit comments

Comments
 (0)