Skip to content

Commit 1076617

Browse files
authored
---
yaml --- r: 570809 b: refs/heads/main c: 34353b8 h: refs/heads/main i: 570807: 67caf65
1 parent b998b21 commit 1076617

23 files changed

+274
-392
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2015,4 +2015,4 @@ refs/tags/swift-5.3-DEVELOPMENT-SNAPSHOT-2020-09-06-a: 539017b61d4fd33e72f269983
20152015
refs/tags/swift-5.3-DEVELOPMENT-SNAPSHOT-2020-09-07-a: 30277ea9d7139d33bf3a0b476c9f05f7140a17f0
20162016
refs/tags/swift-5.3-DEVELOPMENT-SNAPSHOT-2020-09-09-a: e1eb555e1b2365ec8b0252d9d7edec351f40f9ca
20172017
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2020-09-11-a: 48ed530cc4805b5f29fc519ec25ed290e058e674
2018-
refs/heads/main: 2bbebcb18022362192780157917eb16e3c9b8239
2018+
refs/heads/main: 34353b8a40809a6b279b3fd5eab94874aa53b55f

trunk/docs/SIL.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,7 @@ alloc_stack
19611961
```````````
19621962
::
19631963

1964-
sil-instruction ::= 'alloc_stack' sil-type (',' debug-var-attr)*
1964+
sil-instruction ::= 'alloc_stack' '[dynamic_lifetime]'? sil-type (',' debug-var-attr)*
19651965

19661966
%1 = alloc_stack $T
19671967
// %1 has type $*T
@@ -1980,6 +1980,10 @@ predecessors, the stack height and order of allocations must be consistent
19801980
coming from all predecessor blocks. ``alloc_stack`` allocations must be
19811981
deallocated in last-in, first-out stack order.
19821982

1983+
The ``dynamic_lifetime`` attribute specifies that the initialization and
1984+
destruction of the stored value cannot be verified at compile time.
1985+
This is the case, e.g. for conditionally initialized objects.
1986+
19831987
The memory is not retainable. To allocate a retainable box for a value
19841988
type, use ``alloc_box``.
19851989

trunk/include/swift/SIL/ApplySite.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ class ApplySite {
134134
/// Return the callee operand as a value.
135135
SILValue getCallee() const { return getCalleeOperand()->get(); }
136136

137+
/// Return the callee operand.
138+
Operand *getCalleeOperand() { FOREACH_IMPL_RETURN(getCalleeOperand()); }
139+
137140
/// Return the callee operand.
138141
const Operand *getCalleeOperand() const {
139142
FOREACH_IMPL_RETURN(getCalleeOperand());

trunk/include/swift/SIL/BasicBlockUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ class DeadEndBlocks {
7171
DeadEndBlocks(const SILFunction *F) : F(F) {}
7272

7373
/// Returns true if \p BB is a dead-end block.
74-
bool isDeadEnd(SILBasicBlock *BB) {
74+
bool isDeadEnd(const SILBasicBlock *block) {
7575
if (!isComputed) {
7676
// Lazily compute the dataflow.
7777
compute();
7878
isComputed = true;
7979
}
80-
return ReachableBlocks.count(BB) == 0;
80+
return ReachableBlocks.count(block) == 0;
8181
}
8282
};
8383

trunk/include/swift/SIL/BranchPropagatedUser.h

Lines changed: 0 additions & 158 deletions
This file was deleted.

trunk/include/swift/SIL/LinearLifetimeChecker.h

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include "swift/Basic/Debug.h"
1717
#include "swift/Basic/LLVM.h"
18-
#include "swift/SIL/BranchPropagatedUser.h"
1918
#include "swift/SIL/SILArgument.h"
2019
#include "swift/SIL/SILInstruction.h"
2120
#include "swift/SIL/SILValue.h"
@@ -29,7 +28,6 @@ class SILInstruction;
2928
class SILModule;
3029
class SILValue;
3130
class DeadEndBlocks;
32-
class BranchPropagatedUser;
3331

3432
namespace ownership {
3533

@@ -167,30 +165,21 @@ class LinearLifetimeChecker {
167165
/// \p leakingBlocks If non-null a list of blocks where the value was detected
168166
/// to leak. Can be used to insert missing destroys.
169167
LinearLifetimeError
170-
checkValue(SILValue value, ArrayRef<BranchPropagatedUser> consumingUses,
171-
ArrayRef<BranchPropagatedUser> nonConsumingUses,
168+
checkValue(SILValue value, ArrayRef<Operand *> consumingUses,
169+
ArrayRef<Operand *> nonConsumingUses,
172170
ownership::ErrorBehaviorKind errorBehavior,
173171
SmallVectorImpl<SILBasicBlock *> *leakingBlocks = nullptr);
174172

175173
/// Returns true that \p value forms a linear lifetime with consuming uses \p
176174
/// consumingUses, non consuming uses \p nonConsumingUses. Returns false
177175
/// otherwise.
178-
bool validateLifetime(SILValue value,
179-
ArrayRef<BranchPropagatedUser> consumingUses,
180-
ArrayRef<BranchPropagatedUser> nonConsumingUses) {
176+
bool validateLifetime(SILValue value, ArrayRef<Operand *> consumingUses,
177+
ArrayRef<Operand *> nonConsumingUses) {
181178
return !checkValue(value, consumingUses, nonConsumingUses,
182179
ownership::ErrorBehaviorKind::ReturnFalse,
183180
nullptr /*leakingBlocks*/)
184181
.getFoundError();
185182
}
186-
187-
bool validateLifetime(SILValue value,
188-
ArrayRef<SILInstruction *> consumingUses,
189-
ArrayRef<SILInstruction *> nonConsumingUses) {
190-
return validateLifetime(
191-
value, BranchPropagatedUser::convertFromInstArray(consumingUses),
192-
BranchPropagatedUser::convertFromInstArray(nonConsumingUses));
193-
}
194183
};
195184

196185
} // namespace swift

trunk/include/swift/SIL/MemAccessUtils.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ namespace swift {
5353
/// (pointer-to-address is not stripped).
5454
SILValue stripAccessMarkers(SILValue v);
5555

56+
/// Return a non-null address-type SingleValueInstruction if \p v is the result
57+
/// of an address projection that may be inside of a formal access, such as
58+
/// (begin_borrow, struct_element_addr, tuple_element_addr).
59+
///
60+
/// The resulting projection must have an address-type operand at index zero
61+
/// representing the projected address.
62+
SingleValueInstruction *isAccessProjection(SILValue v);
63+
5664
/// Attempt to return the address corresponding to a variable's formal access
5765
/// by stripping indexing and address projections.
5866
///
@@ -540,7 +548,7 @@ bool memInstMustInitialize(Operand *memOper);
540548
/// alloc_stack. If the alloc_stack is destroyed in pieces, we do not guarantee
541549
/// that the list of destroying users is a minimal jointly post-dominating set.
542550
bool isSingleInitAllocStack(AllocStackInst *asi,
543-
SmallVectorImpl<SILInstruction *> &destroyingUsers);
551+
SmallVectorImpl<Operand *> &destroyingUses);
544552

545553
/// Return true if the given address producer may be the source of a formal
546554
/// access (a read or write of a potentially aliased, user visible variable).

trunk/include/swift/SIL/OwnershipUtils.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,16 +319,15 @@ struct BorrowScopeIntroducingValue {
319319

320320
bool isLocalScope() const { return kind.isLocalScope(); }
321321

322-
/// Returns true if the passed in set of instructions is completely within the
323-
/// lifetime of this borrow introducer.
322+
/// Returns true if the passed in set of uses is completely within
323+
/// the lifetime of this borrow introducer.
324324
///
325325
/// NOTE: Scratch space is used internally to this method to store the end
326326
/// borrow scopes if needed.
327-
bool
328-
areInstructionsWithinScope(ArrayRef<SILInstruction *> instructions,
329-
SmallVectorImpl<SILInstruction *> &scratchSpace,
330-
SmallPtrSetImpl<SILBasicBlock *> &visitedBlocks,
331-
DeadEndBlocks &deadEndBlocks) const;
327+
bool areUsesWithinScope(ArrayRef<Operand *> instructions,
328+
SmallVectorImpl<Operand *> &scratchSpace,
329+
SmallPtrSetImpl<SILBasicBlock *> &visitedBlocks,
330+
DeadEndBlocks &deadEndBlocks) const;
332331

333332
/// Given a local borrow scope introducer, visit all non-forwarding consuming
334333
/// users. This means that this looks through guaranteed block arguments.

trunk/include/swift/SIL/SILBuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ class SILBuilder {
728728
}
729729

730730
BeginBorrowInst *createBeginBorrow(SILLocation Loc, SILValue LV) {
731+
assert(!LV->getType().isAddress());
731732
return insert(new (getModule())
732733
BeginBorrowInst(getSILDebugLocation(Loc), LV));
733734
}

trunk/include/swift/SIL/SILInstruction.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,18 @@ class AllocStackInst final
14441444
}
14451445
}
14461446

1447+
/// Set to true that this alloc_stack contains a value whose lifetime can not
1448+
/// be ascertained from uses.
1449+
///
1450+
/// As an example if an alloc_stack is known to be only conditionally
1451+
/// initialized.
14471452
void setDynamicLifetime() { dynamicLifetime = true; }
1453+
1454+
/// Returns true if the alloc_stack's initialization can not be ascertained
1455+
/// from uses directly (so should be treated conservatively).
1456+
///
1457+
/// An example of an alloc_stack with dynamic lifetime is an alloc_stack that
1458+
/// is conditionally initialized.
14481459
bool hasDynamicLifetime() const { return dynamicLifetime; }
14491460

14501461
/// Return the debug variable information attached to this instruction.
@@ -1875,6 +1886,7 @@ class ApplyInstBase<Impl, Base, false> : public Base {
18751886
/// The operand number of the first argument.
18761887
static unsigned getArgumentOperandNumber() { return NumStaticOperands; }
18771888

1889+
Operand *getCalleeOperand() { return &getAllOperands()[Callee]; }
18781890
const Operand *getCalleeOperand() const { return &getAllOperands()[Callee]; }
18791891
SILValue getCallee() const { return getCalleeOperand()->get(); }
18801892

trunk/include/swift/SIL/SILValue.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,9 @@ class Operand {
669669
return constraint == UseLifetimeConstraint::MustBeInvalidated;
670670
}
671671

672+
SILBasicBlock *getParentBlock() const;
673+
SILFunction *getParentFunction() const;
674+
672675
private:
673676
void removeFromCurrent() {
674677
if (!Back) return;

trunk/lib/AST/ASTDumper.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3204,8 +3204,11 @@ static void dumpSubstitutionMapRec(
32043204
out << "substitution ";
32053205
genericParams[i]->print(out);
32063206
out << " -> ";
3207-
if (replacementTypes[i])
3208-
replacementTypes[i]->print(out);
3207+
if (replacementTypes[i]) {
3208+
PrintOptions opts;
3209+
opts.PrintForSIL = true;
3210+
replacementTypes[i]->print(out, opts);
3211+
}
32093212
else
32103213
out << "<<unresolved concrete type>>";
32113214
printParen(')');

0 commit comments

Comments
 (0)