Skip to content

Commit db157c9

Browse files
committed
Strengthen verification of the operand of hop_to_executor and extract_executor.
1 parent 718390a commit db157c9

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,24 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
10691069
what + " must be Optional<Builtin.Executor>");
10701070
}
10711071

1072+
/// Require the operand to be an object of some type that conforms to
1073+
/// Actor or DistributedActor.
1074+
void requireAnyActorType(SILValue value, bool allowOptional,
1075+
bool allowExecutor, const Twine &what) {
1076+
auto type = value->getType();
1077+
require(type.isObject(), what + " must be an object type");
1078+
1079+
auto actorType = type.getASTType();
1080+
if (allowOptional) {
1081+
if (auto objectType = actorType.getOptionalObjectType())
1082+
actorType = objectType;
1083+
}
1084+
if (allowExecutor && isa<BuiltinExecutorType>(actorType))
1085+
return;
1086+
require(actorType->isAnyActorType(),
1087+
what + " must be some kind of actor type");
1088+
}
1089+
10721090
/// Assert that two types are equal.
10731091
void requireSameType(Type type1, Type type2, const Twine &complaint) {
10741092
_require(type1->isEqual(type2), complaint,
@@ -5806,10 +5824,21 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
58065824
if (HI->getModule().getStage() == SILStage::Lowered) {
58075825
requireOptionalExecutorType(executor,
58085826
"hop_to_executor operand in lowered SIL");
5827+
} else {
5828+
requireAnyActorType(executor,
5829+
/*allow optional*/ true,
5830+
/*allow executor*/ true,
5831+
"hop_to_executor operand");
58095832
}
58105833
}
58115834

58125835
void checkExtractExecutorInst(ExtractExecutorInst *EEI) {
5836+
requireObjectType(BuiltinExecutorType, EEI,
5837+
"extract_executor result");
5838+
requireAnyActorType(EEI->getExpectedExecutor(),
5839+
/*allow optional*/ false,
5840+
/*allow executor*/ false,
5841+
"extract_executor operand");
58135842
if (EEI->getModule().getStage() == SILStage::Lowered) {
58145843
require(false,
58155844
"extract_executor instruction should have been lowered away");

lib/SILOptimizer/Mandatory/LowerHopToActor.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,19 @@ static bool isOptionalBuiltinExecutor(SILType type) {
112112
void LowerHopToActor::recordDominatingInstFor(SILInstruction *inst) {
113113
SILValue actor;
114114
if (auto *hop = dyn_cast<HopToExecutorInst>(inst)) {
115+
// hop_to_executor can take optional and non-optional Builtin.Executor
116+
// values directly. If we see Optional<Builtin.Executor>, there's
117+
// nothing to do.
115118
actor = hop->getTargetExecutor();
116-
// If hop_to_executor was emitted with an optional executor operand,
117-
// there's nothing to derive.
118-
if (isOptionalBuiltinExecutor(actor->getType())) {
119+
if (isOptionalBuiltinExecutor(actor->getType()))
119120
return;
120-
}
121121
} else if (auto *extract = dyn_cast<ExtractExecutorInst>(inst)) {
122+
// extract_executor can only take non-optional actor values.
122123
actor = extract->getExpectedExecutor();
123124
} else {
124125
return;
125126
}
126127

127-
if (isOptionalBuiltinExecutor(actor->getType()))
128-
return;
129-
130128
auto *dominatingInst = ExecutorDerivationForActor.lookup(actor);
131129
if (dominatingInst) {
132130
DominatingActorHops.insert(dominatingInst, inst);

test/SILOptimizer/consume_operator_kills_addresses_dbginfo.sil

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ public protocol P {
1919
sil @forceSplit : $@convention(thin) @async () -> ()
2020
sil @genericUse : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
2121

22-
enum Optional<T> {
23-
case some(T)
24-
case none
25-
}
26-
2722
///////////
2823
// Tests //
2924
///////////

0 commit comments

Comments
 (0)