Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions lib/SIL/SILFunctionType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,12 @@ static CanSILFunctionType getSILFunctionType(SILModule &M,
// from the function to which the argument is attached.
if (constant && !constant->isDefaultArgGenerator())
if (auto function = constant->getAnyFunctionRef()) {
auto getCanonicalType = [&](Type t) -> CanType {
if (genericSig)
return genericSig->getCanonicalTypeInContext(t, *M.getSwiftModule());
return t->getCanonicalType();
};

auto &Types = M.Types;
auto loweredCaptures = Types.getLoweredLocalCaptures(*function);

Expand All @@ -745,22 +751,21 @@ static CanSILFunctionType getSILFunctionType(SILModule &M,
ParameterConvention convention = ParameterConvention::Direct_Unowned;
auto selfMetatype = MetatypeType::get(
loweredCaptures.getDynamicSelfType()->getSelfType(),
MetatypeRepresentation::Thick)
->getCanonicalType();
SILParameterInfo param(selfMetatype, convention);
MetatypeRepresentation::Thick);
auto canSelfMetatype = getCanonicalType(selfMetatype);
SILParameterInfo param(canSelfMetatype, convention);
inputs.push_back(param);

continue;
}

auto *VD = capture.getDecl();
auto type = VD->getType()->getCanonicalType();

type = ArchetypeBuilder::mapTypeOutOfContext(
function->getAsDeclContext(), type)->getCanonicalType();

auto type = ArchetypeBuilder::mapTypeOutOfContext(
function->getAsDeclContext(), VD->getType());
auto canType = getCanonicalType(type);

auto &loweredTL = Types.getTypeLowering(
AbstractionPattern(genericSig, type), type);
AbstractionPattern(genericSig, canType), canType);
auto loweredTy = loweredTL.getLoweredType();
switch (Types.getDeclCaptureKind(capture)) {
case CaptureKind::None:
Expand Down
18 changes: 18 additions & 0 deletions test/SILGen/generic_closures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,21 @@ func mixed_generic_nongeneric_nesting<T>(t: T) {
// CHECK-LABEL: sil shared @_TFF16generic_closures32mixed_generic_nongeneric_nestingurFT1tx_T_L_5outerurFT_T_ : $@convention(thin) <T> () -> ()
// CHECK-LABEL: sil shared @_TFFF16generic_closures32mixed_generic_nongeneric_nestingurFT1tx_T_L_5outerurFT_T_L_6middleu__rFT1uqd___T_ : $@convention(thin) <T><U> (@in U) -> ()
// CHECK-LABEL: sil shared @_TFFFF16generic_closures32mixed_generic_nongeneric_nestingurFT1tx_T_L_5outerurFT_T_L_6middleu__rFT1uqd___T_L_5inneru__rfT_qd__ : $@convention(thin) <T><U> (@owned @box U) -> @out U

protocol Doge {
associatedtype Nose : NoseProtocol
}

protocol NoseProtocol {
associatedtype Squeegee
}

protocol Doggo {}

struct DogSnacks<A : Doggo> {}

func capture_same_type_representative<Daisy: Doge, Roo: Doggo>(slobber: Roo)
where Roo == Daisy.Nose.Squeegee {
var s = DogSnacks<Daisy.Nose.Squeegee>()
_ = { _ = s }
}