Skip to content

Commit f6ec0f0

Browse files
authored
Merge pull request swiftlang#15118 from gottesmm/pr-cbca07b2b7cf24f1f8cef16851d14a5f2e1e676b
SILGen: Fix up ownership of key path entry points for +0.
2 parents 6e58020 + ad79b5c commit f6ec0f0

File tree

2 files changed

+46
-16
lines changed

2 files changed

+46
-16
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3849,7 +3849,13 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
38493849
case KeyPathPatternComponent::Kind::SettableProperty: {
38503850
bool hasIndices = !component.getSubscriptIndices().empty();
38513851

3852-
// Getter should be <Sig...> @convention(thin) (@in Base) -> @out Result
3852+
ParameterConvention normalArgConvention;
3853+
if (F.getModule().getOptions().EnableGuaranteedNormalArguments)
3854+
normalArgConvention = ParameterConvention::Indirect_In_Guaranteed;
3855+
else
3856+
normalArgConvention = ParameterConvention::Indirect_In;
3857+
3858+
// Getter should be <Sig...> @convention(thin) (@in_guaranteed Base) -> @out Result
38533859
{
38543860
auto getter = component.getComputedPropertyGetter();
38553861
auto substGetterType = getter->getLoweredFunctionType()
@@ -3861,9 +3867,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
38613867
require(substGetterType->getNumParameters() == 1 + hasIndices,
38623868
"getter should have one parameter");
38633869
auto baseParam = substGetterType->getParameters()[0];
3864-
require(baseParam.getConvention() ==
3865-
ParameterConvention::Indirect_In,
3866-
"getter base parameter should be @in");
3870+
require(baseParam.getConvention() == normalArgConvention,
3871+
"getter base parameter should have normal arg convention");
38673872
require(baseParam.getType() == loweredBaseTy.getSwiftRValueType(),
38683873
"getter base parameter should match base of component");
38693874

@@ -3889,7 +3894,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
38893894

38903895
if (kind == KeyPathPatternComponent::Kind::SettableProperty) {
38913896
// Setter should be
3892-
// <Sig...> @convention(thin) (@in Result, @in Base) -> ()
3897+
// <Sig...> @convention(thin) (@in_guaranteed Result, @in Base) -> ()
38933898

38943899
auto setter = component.getComputedPropertySetter();
38953900
auto substSetterType = setter->getLoweredFunctionType()
@@ -3903,16 +3908,17 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
39033908
"setter should have two parameters");
39043909

39053910
auto newValueParam = substSetterType->getParameters()[0];
3906-
require(newValueParam.getConvention() ==
3907-
ParameterConvention::Indirect_In,
3908-
"setter value parameter should be @in");
3911+
// TODO: This should probably be unconditionally +1 when we
3912+
// can represent that.
3913+
require(newValueParam.getConvention() == normalArgConvention,
3914+
"setter value parameter should havee normal arg convention");
39093915

39103916
auto baseParam = substSetterType->getParameters()[1];
3911-
require(baseParam.getConvention() ==
3912-
ParameterConvention::Indirect_In
3917+
require(baseParam.getConvention() == normalArgConvention
39133918
|| baseParam.getConvention() ==
39143919
ParameterConvention::Indirect_Inout,
3915-
"setter base parameter should be @in or @inout");
3920+
"setter base parameter should be normal arg convention "
3921+
"or @inout");
39163922

39173923
if (hasIndices) {
39183924
auto indicesParam = substSetterType->getParameters()[2];

lib/SILGen/SILGenExpr.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3008,7 +3008,14 @@ emitKeyPathRValueBase(SILGenFunction &subSGF,
30083008
if (!storage->getDeclContext()->isTypeContext())
30093009
return ManagedValue();
30103010

3011-
auto paramOrigValue = subSGF.emitManagedRValueWithCleanup(paramArg);
3011+
ManagedValue paramOrigValue;
3012+
3013+
if (subSGF.SGM.M.getOptions().EnableGuaranteedNormalArguments) {
3014+
paramOrigValue =
3015+
ManagedValue::forBorrowedRValue(paramArg).copy(subSGF, loc);
3016+
} else {
3017+
paramOrigValue = subSGF.emitManagedRValueWithCleanup(paramArg);
3018+
}
30123019
auto paramSubstValue = subSGF.emitOrigToSubstValue(loc, paramOrigValue,
30133020
AbstractionPattern::getOpaque(),
30143021
baseType);
@@ -3107,9 +3114,15 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
31073114
propertyType);
31083115
}
31093116

3117+
ParameterConvention paramConvention;
3118+
if (SGM.M.getOptions().EnableGuaranteedNormalArguments)
3119+
paramConvention = ParameterConvention::Indirect_In_Guaranteed;
3120+
else
3121+
paramConvention = ParameterConvention::Indirect_In;
3122+
31103123
SmallVector<SILParameterInfo, 2> params;
31113124
params.push_back({loweredBaseTy.getSwiftRValueType(),
3112-
ParameterConvention::Indirect_In});
3125+
paramConvention});
31133126
auto &C = SGM.getASTContext();
31143127
if (!indexes.empty())
31153128
params.push_back({C.getUnsafeRawPointerDecl()->getDeclaredType()
@@ -3224,15 +3237,21 @@ SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
32243237

32253238
auto &C = SGM.getASTContext();
32263239

3240+
ParameterConvention paramConvention;
3241+
if (SGM.M.getOptions().EnableGuaranteedNormalArguments)
3242+
paramConvention = ParameterConvention::Indirect_In_Guaranteed;
3243+
else
3244+
paramConvention = ParameterConvention::Indirect_In;
3245+
32273246
SmallVector<SILParameterInfo, 3> params;
32283247
// property value
32293248
params.push_back({loweredPropTy.getSwiftRValueType(),
3230-
ParameterConvention::Indirect_In});
3249+
paramConvention});
32313250
// base
32323251
params.push_back({loweredBaseTy.getSwiftRValueType(),
32333252
property->isSetterMutating()
32343253
? ParameterConvention::Indirect_Inout
3235-
: ParameterConvention::Indirect_In});
3254+
: paramConvention});
32363255
// indexes
32373256
if (!indexes.empty())
32383257
params.push_back({C.getUnsafeRawPointerDecl()->getDeclaredType()
@@ -3298,7 +3317,12 @@ SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
32983317
indexes,
32993318
indexPtrArg);
33003319

3301-
auto valueOrig = subSGF.emitManagedRValueWithCleanup(valueArg);
3320+
ManagedValue valueOrig;
3321+
if (SGM.M.getOptions().EnableGuaranteedNormalArguments)
3322+
valueOrig = ManagedValue::forBorrowedRValue(valueArg)
3323+
.copy(subSGF, loc);
3324+
else
3325+
valueOrig = subSGF.emitManagedRValueWithCleanup(valueArg);
33023326
auto valueSubst = subSGF.emitOrigToSubstValue(loc, valueOrig,
33033327
AbstractionPattern::getOpaque(),
33043328
propertyType);

0 commit comments

Comments
 (0)