Skip to content

Commit 7b140f8

Browse files
committed
[SILGen] InitAccessors: AssignOrInit instruction should reference init accessor directly
Previously init accessor has been partially applied just like a setter but that is no loger valid now that it operates on individual field references.
1 parent 6c0e391 commit 7b140f8

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,6 +2722,12 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
27222722
checkAssignByWrapperArgs(Src->getType(), setterConv);
27232723
}
27242724

2725+
void checkAssigOrInitInstAccessorArgs(SILType argTy,
2726+
SILFunctionConventions &conv) {
2727+
unsigned argIdx = conv.getSILArgIndexOfFirstParam();
2728+
checkAssignByWrapperArgsRecursively(argTy, conv, argIdx);
2729+
}
2730+
27252731
void checkAssignOrInitInst(AssignOrInitInst *AI) {
27262732
SILValue Src = AI->getSrc();
27272733
require(AI->getModule().getStage() == SILStage::Raw,
@@ -2732,9 +2738,10 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
27322738
SILValue initFn = AI->getInitializer();
27332739
CanSILFunctionType initTy = initFn->getType().castTo<SILFunctionType>();
27342740
SILFunctionConventions initConv(initTy, AI->getModule());
2735-
require(initConv.getNumIndirectSILResults() == 0,
2736-
"init function has indirect results");
2737-
checkAssignByWrapperArgs(Src->getType(), initConv);
2741+
require(initConv.getNumIndirectSILResults() ==
2742+
AI->getInitializedProperties().size(),
2743+
"init function has invalid number of indirect results");
2744+
checkAssigOrInitInstAccessorArgs(Src->getType(), initConv);
27382745

27392746
SILValue setterFn = AI->getSetter();
27402747
CanSILFunctionType setterTy = setterFn->getType().castTo<SILFunctionType>();

lib/SILGen/SILGenLValue.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,16 +1718,6 @@ namespace {
17181718
auto initConstant = SGF.getAccessorDeclRef(initAccessor);
17191719
SILValue initFRef = SGF.emitGlobalFunctionRef(loc, initConstant);
17201720

1721-
SmallVector<SILValue, 1> capturedArgs;
1722-
SILValue capturedBase = base.getValue();
1723-
capturedArgs.push_back(capturedBase);
1724-
1725-
PartialApplyInst *initPAI =
1726-
SGF.B.createPartialApply(loc, initFRef,
1727-
Substitutions, capturedArgs,
1728-
ParameterConvention::Direct_Guaranteed);
1729-
ManagedValue initFn = SGF.emitManagedRValueWithCleanup(initPAI);
1730-
17311721
// Emit the set accessor function partially applied to the base.
17321722
auto setterFRef = getSetterFRef();
17331723
auto setterTy = getSetterType(setterFRef);
@@ -1736,9 +1726,9 @@ namespace {
17361726

17371727
// Create the assign_or_init with the initializer and setter.
17381728
auto value = emitValue(field, FieldType, setterTy, setterConv);
1739-
SGF.B.createAssignOrInit(
1740-
loc, value.forward(SGF), initFn.getValue(), setterFn.getValue(),
1741-
AssignOrInitInst::Unknown);
1729+
SGF.B.createAssignOrInit(loc, value.forward(SGF), initFRef,
1730+
setterFn.getValue(),
1731+
AssignOrInitInst::Unknown);
17421732
return;
17431733
}
17441734

0 commit comments

Comments
 (0)