Skip to content

Commit 5d9202c

Browse files
committed
consider parameter sources for partial_apply with non fixed layout only
1 parent 0b6fd1f commit 5d9202c

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

lib/IRGen/GenFunc.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,9 +1309,21 @@ Optional<StackAddress> irgen::emitFunctionPartialApplication(
13091309
SmallVector<SILType, 4> argValTypes;
13101310
SmallVector<ParameterConvention, 4> argConventions;
13111311

1312+
bool considerParameterSources = true;
1313+
for (auto param : params) {
1314+
SILType argType = IGF.IGM.silConv.getSILType(param, origType);
1315+
auto argLoweringTy = getArgumentLoweringType(argType.getASTType(), param);
1316+
auto &ti = IGF.getTypeInfoForLowered(argLoweringTy);
1317+
1318+
if (!isa<FixedTypeInfo>(ti)) {
1319+
considerParameterSources = false;
1320+
break;
1321+
}
1322+
}
1323+
13121324
// Reserve space for polymorphic bindings.
13131325
auto bindings =
1314-
NecessaryBindings::forPartialApplyForwarder(IGF.IGM, origType, subs);
1326+
NecessaryBindings::forPartialApplyForwarder(IGF.IGM, origType, subs, considerParameterSources);
13151327

13161328
if (!bindings.empty()) {
13171329
hasSingleSwiftRefcountedContext = No;

lib/IRGen/GenProto.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class PolymorphicConvention {
100100

101101
FulfillmentMap Fulfillments;
102102

103-
bool ForPartialApplyForwarder;
103+
bool ConsiderParameterSources;
104104

105105
GenericSignature::ConformsToArray getConformsTo(Type t) {
106106
return Generics->getConformsTo(t);
@@ -113,7 +113,7 @@ class PolymorphicConvention {
113113
}
114114

115115
public:
116-
PolymorphicConvention(IRGenModule &IGM, CanSILFunctionType fnType, bool forPartialApplyForwarder);
116+
PolymorphicConvention(IRGenModule &IGM, CanSILFunctionType fnType, bool considerParameterSources);
117117

118118
ArrayRef<MetadataSource> getSources() const { return Sources; }
119119

@@ -181,9 +181,9 @@ class PolymorphicConvention {
181181

182182
PolymorphicConvention::PolymorphicConvention(IRGenModule &IGM,
183183
CanSILFunctionType fnType,
184-
bool forPartialApplyForwarder = false)
184+
bool considerParameterSources = true)
185185
: IGM(IGM), M(*IGM.getSwiftModule()), FnType(fnType),
186-
ForPartialApplyForwarder(forPartialApplyForwarder) {
186+
ConsiderParameterSources(considerParameterSources) {
187187
initGenerics();
188188

189189
auto rep = fnType->getRepresentation();
@@ -221,10 +221,12 @@ PolymorphicConvention::PolymorphicConvention(IRGenModule &IGM,
221221
considerParameter(params[selfIndex], selfIndex, true);
222222
}
223223

224-
// Now consider the rest of the parameters.
225-
for (auto index : indices(params)) {
226-
if (index != selfIndex)
227-
considerParameter(params[index], index, false);
224+
if (ConsiderParameterSources) {
225+
// Now consider the rest of the parameters.
226+
for (auto index : indices(params)) {
227+
if (index != selfIndex)
228+
considerParameter(params[index], index, false);
229+
}
228230
}
229231
}
230232
}
@@ -388,10 +390,10 @@ void PolymorphicConvention::considerParameter(SILParameterInfo param,
388390
case ParameterConvention::Direct_Owned:
389391
case ParameterConvention::Direct_Unowned:
390392
case ParameterConvention::Direct_Guaranteed:
391-
// Don't consider ClassPointer source for partial_apply forwader.
393+
// Don't consider ClassPointer source and Metadata source for partial_apply forwader with non fixed layout.
392394
// If not, we may end up with missing TypeMetadata for a type dependent generic parameter
393395
// while generating code for destructor of HeapLayout.
394-
if (ForPartialApplyForwarder) return;
396+
if (!ConsiderParameterSources) return;
395397
// Classes are sources of metadata.
396398
if (type->getClassOrBoundGenericClass()) {
397399
considerNewTypeSource(MetadataSource::Kind::ClassPointer,
@@ -2991,14 +2993,16 @@ NecessaryBindings::forFunctionInvocations(IRGenModule &IGM,
29912993
NecessaryBindings
29922994
NecessaryBindings::forPartialApplyForwarder(IRGenModule &IGM,
29932995
CanSILFunctionType origType,
2994-
SubstitutionMap subs) {
2996+
SubstitutionMap subs,
2997+
bool considerParameterSources) {
29952998
return computeBindings(IGM, origType, subs,
2996-
true /*forPartialApplyForwarder*/);
2999+
true /*forPartialApplyForwarder*/,
3000+
considerParameterSources);
29973001
}
29983002

29993003
NecessaryBindings NecessaryBindings::computeBindings(
30003004
IRGenModule &IGM, CanSILFunctionType origType, SubstitutionMap subs,
3001-
bool forPartialApplyForwarder) {
3005+
bool forPartialApplyForwarder, bool considerParameterSources) {
30023006

30033007
NecessaryBindings bindings;
30043008
bindings.forPartialApply = forPartialApplyForwarder;
@@ -3008,7 +3012,7 @@ NecessaryBindings NecessaryBindings::computeBindings(
30083012
return bindings;
30093013

30103014
// Figure out what we're actually required to pass:
3011-
PolymorphicConvention convention(IGM, origType, forPartialApplyForwarder);
3015+
PolymorphicConvention convention(IGM, origType, considerParameterSources);
30123016

30133017
// - unfulfilled requirements
30143018
convention.enumerateUnfulfilledRequirements(

lib/IRGen/NecessaryBindings.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class NecessaryBindings {
5959
SubstitutionMap subs);
6060
static NecessaryBindings forPartialApplyForwarder(IRGenModule &IGM,
6161
CanSILFunctionType origType,
62-
SubstitutionMap subs);
62+
SubstitutionMap subs,
63+
bool considerParameterSources = true);
6364

6465
/// Add whatever information is necessary to reconstruct type metadata
6566
/// for the given type.
@@ -98,7 +99,8 @@ class NecessaryBindings {
9899
static NecessaryBindings computeBindings(IRGenModule &IGM,
99100
CanSILFunctionType origType,
100101
SubstitutionMap subs,
101-
bool forPartialApplyForwarder);
102+
bool forPartialApplyForwarder,
103+
bool considerParameterSources = true);
102104
};
103105

104106
} // end namespace irgen

0 commit comments

Comments
 (0)