Skip to content

Commit 116a453

Browse files
authored
Merge pull request #82177 from eeckstein/fix-lha
LowerHopToActor: insert a borrow scope for an `Optional<Actor>.none` value
2 parents 16a6536 + 5489627 commit 116a453

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/SILOptimizer/Mandatory/LowerHopToActor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ SILValue LowerHopToActor::emitGetExecutor(SILBuilderWithScope &B,
273273
if (auto wrappedActor = actorType->getOptionalObjectType()) {
274274
assert(makeOptional);
275275

276-
if (B.hasOwnership() && actor->getOwnershipKind() == OwnershipKind::Owned) {
276+
if (B.hasOwnership() && actor->getOwnershipKind() != OwnershipKind::Guaranteed) {
277277
actor = B.createBeginBorrow(loc, actor);
278278
needEndBorrow = true;
279279
}

test/SILOptimizer/lower_hop_to_actor.sil

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,17 @@ bb0(%0 : @guaranteed $Optional<any Actor>):
307307
return %r
308308
}
309309

310+
// CHECK-LABEL: sil [ossa] @optional_none :
311+
// CHECK: %0 = enum
312+
// CHECK-NEXT: %1 = begin_borrow %0
313+
// CHECK-NEXT: switch_enum %1
314+
// CHECK: mark_dependence
315+
// CHECK-NEXT: end_borrow %1
316+
// CHECKL: } // end sil function '@optional_none'
317+
sil [ossa] @optional_none : $@convention(thin) @async () -> () {
318+
bb0:
319+
%0 = enum $Optional<any Actor>, #Optional.none!enumelt
320+
hop_to_executor %0
321+
%r = tuple ()
322+
return %r
323+
}

0 commit comments

Comments
 (0)