Skip to content

Commit ec1326f

Browse files
authored
Merge pull request #10503 from atrick/fix
2 parents d31ffc7 + 9a11f99 commit ec1326f

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

lib/SILOptimizer/Analysis/AccessSummaryAnalysis.cpp

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -131,46 +131,45 @@ void AccessSummaryAnalysis::processArgument(FunctionInfo *info,
131131
/// only ultimately used by an apply, a try_apply or as an argument (but not
132132
/// the called function) in a partial_apply.
133133
/// TODO: This really should be checked in the SILVerifier.
134-
static bool hasExpectedUsesOfNoEscapePartialApply(SILInstruction *closure) {
135-
for (Operand *use : closure->getUses()) {
136-
SILInstruction *user = use->getUser();
134+
static bool hasExpectedUsesOfNoEscapePartialApply(Operand *partialApplyUse) {
135+
SILInstruction *user = partialApplyUse->getUser();
137136

138-
// It is fine to call the partial apply
139-
switch (user->getKind()) {
140-
case ValueKind::ApplyInst:
141-
case ValueKind::TryApplyInst:
142-
return true;
143-
144-
case ValueKind::ConvertFunctionInst:
145-
return hasExpectedUsesOfNoEscapePartialApply(user);
137+
// It is fine to call the partial apply
138+
switch (user->getKind()) {
139+
case ValueKind::ApplyInst:
140+
case ValueKind::TryApplyInst:
141+
return true;
146142

147-
case ValueKind::PartialApplyInst:
148-
return closure != cast<PartialApplyInst>(user)->getCallee();
149-
150-
case ValueKind::StoreInst:
151-
case ValueKind::DestroyValueInst:
152-
// @block_storage is passed by storing it to the stack. We know this is
153-
// still nonescaping simply because our original argument convention is
154-
// @inout_aliasable. In this SIL, both store and destroy_value are users
155-
// of %closure:
156-
//
157-
// %closure = partial_apply %f1(%arg)
158-
// : $@convention(thin) (@inout_aliasable T) -> ()
159-
// %storage = alloc_stack $@block_storage @callee_owned () -> ()
160-
// %block_addr = project_block_storage %storage
161-
// : $*@block_storage @callee_owned () -> ()
162-
// store %closure to [init] %block_addr : $*@callee_owned () -> ()
163-
// %block = init_block_storage_header %storage
164-
// : $*@block_storage @callee_owned () -> (),
165-
// invoke %f2 : $@convention(c)
166-
// (@inout_aliasable @block_storage @callee_owned () -> ()) -> (),
167-
// type $@convention(block) () -> ()
168-
// %copy = copy_block %block : $@convention(block) () -> ()
169-
// destroy_value %storage : $@callee_owned () -> ()
170-
return true;
171-
default:
172-
return false;
173-
}
143+
case ValueKind::ConvertFunctionInst:
144+
return llvm::all_of(user->getUses(),
145+
hasExpectedUsesOfNoEscapePartialApply);
146+
147+
case ValueKind::PartialApplyInst:
148+
return partialApplyUse->get() != cast<PartialApplyInst>(user)->getCallee();
149+
150+
case ValueKind::StoreInst:
151+
case ValueKind::DestroyValueInst:
152+
// @block_storage is passed by storing it to the stack. We know this is
153+
// still nonescaping simply because our original argument convention is
154+
// @inout_aliasable. In this SIL, both store and destroy_value are users
155+
// of %closure:
156+
//
157+
// %closure = partial_apply %f1(%arg)
158+
// : $@convention(thin) (@inout_aliasable T) -> ()
159+
// %storage = alloc_stack $@block_storage @callee_owned () -> ()
160+
// %block_addr = project_block_storage %storage
161+
// : $*@block_storage @callee_owned () -> ()
162+
// store %closure to [init] %block_addr : $*@callee_owned () -> ()
163+
// %block = init_block_storage_header %storage
164+
// : $*@block_storage @callee_owned () -> (),
165+
// invoke %f2 : $@convention(c)
166+
// (@inout_aliasable @block_storage @callee_owned () -> ()) -> (),
167+
// type $@convention(block) () -> ()
168+
// %copy = copy_block %block : $@convention(block) () -> ()
169+
// destroy_value %storage : $@callee_owned () -> ()
170+
return true;
171+
default:
172+
return false;
174173
}
175174
}
176175
#endif
@@ -189,8 +188,9 @@ void AccessSummaryAnalysis::processPartialApply(FunctionInfo *callerInfo,
189188
assert(isa<FunctionRefInst>(apply->getCallee()) &&
190189
"Noescape partial apply of non-functionref?");
191190

192-
assert(hasExpectedUsesOfNoEscapePartialApply(apply)
193-
&& "noescape partial_apply has unexpected use!");
191+
assert(llvm::all_of(apply->getUses(),
192+
hasExpectedUsesOfNoEscapePartialApply) &&
193+
"noescape partial_apply has unexpected use!");
194194

195195
// The argument index in the called function.
196196
ApplySite site(apply);

0 commit comments

Comments
 (0)