Skip to content

Commit 08e0988

Browse files
committed
Comment mayWriteToMemory.
It's important that fundamental APIs don't lie to their users. Make it clear that this API always returns true for deinitialization, even if we could for example analyze the destructor and determine that there aren't any actual writes!
1 parent 399d1c9 commit 08e0988

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,8 @@ class SILInstruction
620620
/// that are not visible by merely examining their uses.
621621
bool mayHaveSideEffects() const;
622622

623-
/// Returns true if the instruction may write to memory.
623+
/// Returns true if the instruction may write to memory, deinitialize memory,
624+
/// or have other unknown side effects.
624625
bool mayWriteToMemory() const {
625626
MemoryBehavior B = getMemoryBehavior();
626627
return B == MemoryBehavior::MayWrite ||
@@ -636,7 +637,8 @@ class SILInstruction
636637
B == MemoryBehavior::MayHaveSideEffects;
637638
}
638639

639-
/// Returns true if the instruction may read from or write to memory.
640+
/// Returns true if the instruction may read from memory, write to memory,
641+
/// deinitialize memory, or have other unknown side effects.
640642
bool mayReadOrWriteMemory() const {
641643
return getMemoryBehavior() != MemoryBehavior::None;
642644
}

include/swift/SILOptimizer/Analysis/AliasAnalysis.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,17 @@ class AliasAnalysis : public SILAnalysis {
224224
B == MemoryBehavior::MayHaveSideEffects;
225225
}
226226

227-
/// Returns true if \p Inst may write to memory in a manner that
228-
/// affects V.
227+
/// Returns true if \p Inst may write to memory, deinitialize memory, or have
228+
/// other side effects that may affect V.
229229
bool mayWriteToMemory(SILInstruction *Inst, SILValue V) {
230230
auto B = computeMemoryBehavior(Inst, V);
231231
return B == MemoryBehavior::MayWrite ||
232232
B == MemoryBehavior::MayReadWrite ||
233233
B == MemoryBehavior::MayHaveSideEffects;
234234
}
235235

236-
/// Returns true if \p Inst may read or write to memory in a manner that
237-
/// affects V.
236+
/// Returns true if \p Inst may read to memory, write to memory, deinitialize
237+
/// memory, or have other side effects that may affect V.
238238
bool mayReadOrWriteMemory(SILInstruction *Inst, SILValue V) {
239239
auto B = computeMemoryBehavior(Inst, V);
240240
return MemoryBehavior::None != B;

0 commit comments

Comments
 (0)