Skip to content

Commit 19ab4cc

Browse files
committed
Update SILGen for borrow accessors under library evolution
Under library evolution, loadable self arguments are passed as @in_guaranteed. SILGen generates load_borrow for such self arguments proactively. load_borrow creates an artifical scope and returning values produced within this scope will be illegal without resorting to unsafe operations today. This change avoids creating a load_borrow proactively for borrow accessors.
1 parent b6c8f89 commit 19ab4cc

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7306,12 +7306,16 @@ bool AccessorBaseArgPreparer::shouldLoadBaseAddress() const {
73067306
return base.isLValue() || base.isPlusZeroRValueOrTrivial()
73077307
|| !SGF.silConv.useLoweredAddresses();
73087308

7309-
case ParameterConvention::Indirect_In_Guaranteed:
7309+
case ParameterConvention::Indirect_In_Guaranteed: {
7310+
if (accessor.isBorrowAccessor()) {
7311+
return false;
7312+
}
73107313
// We can pass the memory we already have at +0. The memory referred to
73117314
// by the base should be already immutable unless it was lowered as an
73127315
// lvalue.
73137316
return base.isLValue()
73147317
|| !SGF.silConv.useLoweredAddresses();
7318+
}
73157319

73167320
// If the accessor wants the value directly, we definitely have to
73177321
// load.

lib/SILGen/SILGenProlog.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -728,13 +728,15 @@ class ArgumentInitHelper {
728728
: AbstractionPattern(substType));
729729

730730
// A parameter can be directly marked as addressable, or its
731-
// addressability can be implied by a scoped dependency.
732-
bool isAddressable = false;
733-
734-
isAddressable = pd->isAddressable()
735-
|| (ScopedDependencies.contains(pd)
736-
&& SGF.getTypeProperties(origType, substType)
737-
.isAddressableForDependencies());
731+
// addressability can be implied by a scoped dependency or a borrow
732+
// dependency.
733+
bool isAddressable =
734+
pd->isAddressable() ||
735+
(ScopedDependencies.contains(pd) &&
736+
SGF.getTypeProperties(origType, substType)
737+
.isAddressableForDependencies()) ||
738+
SGF.getFunction().getConventions().hasGuaranteedAddressResult() ||
739+
SGF.getFunction().getConventions().hasGuaranteedResult();
738740
paramValue = argEmitter.handleParam(origType, substType, pd,
739741
isAddressable);
740742
}

0 commit comments

Comments
 (0)