Skip to content

Commit 45cadc2

Browse files
committed
SIL: Fix type lowering for generic local functions with captures
We want the generic signature to appear on the outermost function, after the captures, otherwise we run into trouble because we have a generic function type in value position, which is not allowed. Brings us a step closer to allowing local generic functions to capture values, but NFC for now.
1 parent 112511c commit 45cadc2

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

lib/SIL/TypeLowering.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,33 +1773,41 @@ TypeConverter::getFunctionInterfaceTypeWithCaptures(CanAnyFunctionType funcType,
17731773
CanGenericSignature genericSig = getEffectiveGenericSignature(theClosure,
17741774
captureInfo);
17751775

1776+
auto innerExtInfo = AnyFunctionType::ExtInfo(FunctionType::Representation::Thin,
1777+
funcType->isNoReturn(),
1778+
funcType->throws());
1779+
17761780
// If we don't have any local captures (including function captures),
17771781
// there's no context to apply.
17781782
if (!theClosure.getCaptureInfo().hasLocalCaptures()) {
17791783
if (!genericSig)
1780-
return adjustFunctionType(funcType,
1781-
FunctionType::Representation::Thin);
1784+
return CanFunctionType::get(funcType.getInput(),
1785+
funcType.getResult(),
1786+
innerExtInfo);
17821787

1783-
auto extInfo = AnyFunctionType::ExtInfo(FunctionType::Representation::Thin,
1784-
funcType->isNoReturn(),
1785-
funcType->throws());
1786-
17871788
return CanGenericFunctionType::get(genericSig,
17881789
funcType.getInput(),
17891790
funcType.getResult(),
1790-
extInfo);
1791+
innerExtInfo);
17911792
}
17921793

1794+
// Strip the generic signature off the inner type; we will add it to the
1795+
// outer type with captures.
1796+
funcType = CanFunctionType::get(funcType.getInput(),
1797+
funcType.getResult(),
1798+
innerExtInfo);
1799+
17931800
// Add an extra empty tuple level to represent the captures. We'll append the
17941801
// lowered capture types here.
17951802
auto extInfo = AnyFunctionType::ExtInfo(FunctionType::Representation::Thin,
17961803
/*noreturn*/ false,
1797-
funcType->throws());
1804+
/*throws*/ false);
17981805

1799-
if (genericSig)
1806+
if (genericSig) {
18001807
return CanGenericFunctionType::get(genericSig,
18011808
Context.TheEmptyTupleType, funcType,
18021809
extInfo);
1810+
}
18031811

18041812
return CanFunctionType::get(Context.TheEmptyTupleType, funcType, extInfo);
18051813
}

0 commit comments

Comments
 (0)