Skip to content

Commit 78aee95

Browse files
committed
[SILVerifier] InitAccessors: Adjust verifier to map init accessor ref into context before checking initialValue
1 parent 73765c8 commit 78aee95

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2733,17 +2733,28 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
27332733
require(AI->getModule().getStage() == SILStage::Raw,
27342734
"assign_or_init can only exist in raw SIL");
27352735

2736-
// The init and set functions have the same type: (Src type) -> Void
2737-
27382736
SILValue initFn = AI->getInitializer();
2737+
SILValue setterFn = AI->getSetter();
2738+
27392739
CanSILFunctionType initTy = initFn->getType().castTo<SILFunctionType>();
2740-
SILFunctionConventions initConv(initTy, AI->getModule());
2741-
require(initConv.getNumIndirectSILResults() ==
2742-
AI->getInitializedProperties().size(),
2743-
"init function has invalid number of indirect results");
2744-
checkAssigOrInitInstAccessorArgs(Src->getType(), initConv);
2740+
// Check init - it's an unapplied reference that takes property addresses
2741+
// and `initialValue`.
2742+
{
2743+
// We need to map un-applied function reference into context before
2744+
// check `initialValue` argument.
2745+
auto subs = cast<PartialApplyInst>(setterFn)->getSubstitutionMap();
2746+
initTy = initTy->substGenericArgs(F.getModule(), subs,
2747+
F.getTypeExpansionContext());
27452748

2746-
SILValue setterFn = AI->getSetter();
2749+
SILFunctionConventions initConv(initTy, AI->getModule());
2750+
require(initConv.getNumIndirectSILResults() ==
2751+
AI->getInitializedProperties().size(),
2752+
"init function has invalid number of indirect results");
2753+
checkAssigOrInitInstAccessorArgs(Src->getType(), initConv);
2754+
}
2755+
2756+
// Check setter - it's a partially applied reference which takes
2757+
// `initialValue`.
27472758
CanSILFunctionType setterTy = setterFn->getType().castTo<SILFunctionType>();
27482759
SILFunctionConventions setterConv(setterTy, AI->getModule());
27492760
require(setterConv.getNumIndirectSILResults() == 0,

0 commit comments

Comments
 (0)