Skip to content

Commit f5f3ccb

Browse files
authored
Merge pull request swiftlang#28885 from gottesmm/pr-68358de07d2e4962213824f9724b80a6175141ae
2 parents 10936f6 + 980b1f0 commit f5f3ccb

File tree

3 files changed

+36
-25
lines changed

3 files changed

+36
-25
lines changed

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ class ElementUseCollector {
558558

559559
// If this is a delegating initializer, collect uses specially.
560560
if (IsSelfOfNonDelegatingInitializer &&
561-
TheMemory.getType()->getClassOrBoundGenericClass() != nullptr) {
561+
TheMemory.getASTType()->getClassOrBoundGenericClass() != nullptr) {
562562
assert(!TheMemory.isDerivedClassSelfOnly() &&
563563
"Should have been handled outside of here");
564564
// If this is a class pointer, we need to look through ref_element_addrs.
@@ -1125,14 +1125,14 @@ void ElementUseCollector::collectUses(SILValue Pointer, unsigned BaseEltNo) {
11251125
/// constructor. The memory object has class type.
11261126
void ElementUseCollector::collectClassSelfUses() {
11271127
assert(IsSelfOfNonDelegatingInitializer &&
1128-
TheMemory.getType()->getClassOrBoundGenericClass() != nullptr);
1128+
TheMemory.getASTType()->getClassOrBoundGenericClass() != nullptr);
11291129

11301130
// For efficiency of lookup below, compute a mapping of the local ivars in the
11311131
// class to their element number.
11321132
llvm::SmallDenseMap<VarDecl *, unsigned> EltNumbering;
11331133

11341134
{
1135-
SILType T = TheMemory.MemorySILType;
1135+
SILType T = TheMemory.getType();
11361136
auto *NTD = T.getNominalOrBoundGenericNominal();
11371137
unsigned NumElements = 0;
11381138
for (auto *VD : NTD->getStoredProperties()) {
@@ -1149,7 +1149,7 @@ void ElementUseCollector::collectClassSelfUses() {
11491149
// MUI use-def chain directly to find our uses.
11501150
auto *MemoryInst = TheMemory.MemoryInst;
11511151
if (MemoryInst->getKind() == MarkUninitializedInst::RootSelf) {
1152-
collectClassSelfUses(MemoryInst, TheMemory.MemorySILType, EltNumbering);
1152+
collectClassSelfUses(MemoryInst, TheMemory.getType(), EltNumbering);
11531153
return;
11541154
}
11551155

@@ -1217,7 +1217,7 @@ void ElementUseCollector::collectClassSelfUses() {
12171217
// Loads of the box produce self, so collect uses from them.
12181218
if (isa<LoadInst>(User) || isa<LoadBorrowInst>(User)) {
12191219
auto load = cast<SingleValueInstruction>(User);
1220-
collectClassSelfUses(load, TheMemory.MemorySILType, EltNumbering);
1220+
collectClassSelfUses(load, TheMemory.getType(), EltNumbering);
12211221
continue;
12221222
}
12231223

@@ -1857,7 +1857,7 @@ static bool shouldPerformClassInitSelf(const DIMemoryObjectInfo &MemoryInfo) {
18571857
return true;
18581858

18591859
return MemoryInfo.isNonDelegatingInit() &&
1860-
MemoryInfo.getType()->getClassOrBoundGenericClass() != nullptr &&
1860+
MemoryInfo.getASTType()->getClassOrBoundGenericClass() != nullptr &&
18611861
MemoryInfo.isDerivedClassSelfOnly();
18621862
}
18631863

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.h

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@ class DIMemoryObjectInfo {
5656
/// The uninitialized memory that we are analyzing.
5757
MarkUninitializedInst *MemoryInst;
5858

59+
private:
5960
/// This is the base type of the memory allocation.
6061
SILType MemorySILType;
6162

63+
public:
6264
/// This is the count of elements being analyzed. For memory objects that are
6365
/// tuples, this is the flattened element count. For 'self' members in init
64-
/// methods, this is the local field count (+1 for derive classes).
66+
/// methods, this is the local field count (+1 for super/self classes were
67+
/// initialized).
6568
unsigned NumElements;
6669

70+
private:
6771
/// True if the memory object being analyzed represents a 'let', which is
6872
/// initialize-only (reassignments are not allowed).
6973
bool IsLet = false;
@@ -81,23 +85,31 @@ class DIMemoryObjectInfo {
8185
/// Return the first instruction of the function containing the memory object.
8286
SILInstruction *getFunctionEntryPoint() const;
8387

84-
CanType getType() const { return MemorySILType.getASTType(); }
88+
CanType getASTType() const { return MemorySILType.getASTType(); }
89+
SILType getType() const { return MemorySILType; }
90+
91+
/// Returns true if this memory object is of trivial type.
92+
bool hasTrivialType() const { return MemorySILType.isTrivial(getFunction()); }
93+
94+
/// Returns true if NumElements has a dummy value in it to force a struct to
95+
/// be non-empty.
96+
bool hasDummyElement() const { return HasDummyElement; }
8597

8698
SingleValueInstruction *getAddress() const { return MemoryInst; }
8799

88-
/// getNumMemoryElements - Return the number of elements, without the extra
89-
/// "super.init" tracker in initializers of derived classes.
100+
/// Return the number of elements, without the extra "super.init" tracker in
101+
/// initializers of derived classes.
90102
unsigned getNumMemoryElements() const {
91103
return NumElements - (unsigned)isDerivedClassSelf();
92104
}
93105

94-
/// isAnyInitSelf - Return true if this is 'self' in any kind of initializer.
106+
/// Return true if this is 'self' in any kind of initializer.
95107
bool isAnyInitSelf() const { return !MemoryInst->isVar(); }
96108

97109
/// True if the memory object is the 'self' argument of a struct initializer.
98110
bool isStructInitSelf() const {
99111
if (MemoryInst->isRootSelf() || MemoryInst->isCrossModuleRootSelf()) {
100-
if (auto decl = getType()->getAnyNominal()) {
112+
if (auto decl = getASTType()->getAnyNominal()) {
101113
if (isa<StructDecl>(decl)) {
102114
return true;
103115
}
@@ -123,7 +135,7 @@ class DIMemoryObjectInfo {
123135
return false;
124136

125137
if (!MemoryInst->isVar()) {
126-
if (auto decl = getType()->getAnyNominal()) {
138+
if (auto decl = getASTType()->getAnyNominal()) {
127139
if (isa<ClassDecl>(decl)) {
128140
return true;
129141
}
@@ -176,14 +188,14 @@ class DIMemoryObjectInfo {
176188
return false;
177189
}
178190

179-
/// emitElementAddress - Given an element number (in the flattened sense)
180-
/// return a pointer to a leaf element of the specified number.
191+
/// Given an element number (in the flattened sense) return a pointer to a
192+
/// leaf element of the specified number.
181193
SILValue
182194
emitElementAddress(unsigned TupleEltNo, SILLocation Loc, SILBuilder &B,
183195
llvm::SmallVectorImpl<std::pair<SILValue, SILValue>>
184196
&EndBorrowList) const;
185197

186-
/// getElementType - Return the swift type of the specified element.
198+
/// Return the swift type of the specified element.
187199
SILType getElementType(unsigned EltNo) const;
188200

189201
/// Push the symbolic path name to the specified element number onto the

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -792,11 +792,11 @@ void LifetimeChecker::doIt() {
792792
// memory object will destruct the memory. If the memory (or some element
793793
// thereof) is not initialized on some path, the bad things happen. Process
794794
// releases to adjust for this.
795-
if (!TheMemory.MemorySILType.isTrivial(F)) {
795+
if (!TheMemory.hasTrivialType()) {
796796
for (unsigned i = 0, e = Destroys.size(); i != e; ++i)
797797
processNonTrivialRelease(i);
798798
}
799-
799+
800800
// If the memory object had any non-trivial stores that are init or assign
801801
// based on the control flow path reaching them, then insert dynamic control
802802
// logic and CFG diamonds to handle this.
@@ -1020,7 +1020,7 @@ void LifetimeChecker::handleStoreUse(unsigned UseID) {
10201020
if (auto *ctor = fnLoc.getAsASTNode<ConstructorDecl>())
10211021
selfTy = ctor->getImplicitSelfDecl()->getType();
10221022
else
1023-
selfTy = TheMemory.getType();
1023+
selfTy = TheMemory.getASTType();
10241024

10251025
StructDecl *theStruct = selfTy->getStructOrBoundGenericStruct();
10261026
assert(theStruct);
@@ -1284,7 +1284,7 @@ void LifetimeChecker::handleEscapeUse(const DIMemoryUse &Use) {
12841284
diagnose(Module, Inst->getLoc(), diag::self_before_selfinit_value_type);
12851285
if (!HasSuggestedNoArgSelfInit && FullyUninitialized) {
12861286
auto *maybeStruct =
1287-
TheMemory.getType().getStructOrBoundGenericStruct();
1287+
TheMemory.getASTType().getStructOrBoundGenericStruct();
12881288
maybeSuggestNoArgSelfInit(Module, Inst->getLoc(), maybeStruct);
12891289
HasSuggestedNoArgSelfInit = true;
12901290
}
@@ -1618,9 +1618,8 @@ bool LifetimeChecker::diagnoseReturnWithoutInitializingStoredProperties(
16181618
if (!shouldEmitError(Inst))
16191619
return true;
16201620

1621-
if (TheMemory.isCrossModuleStructInitSelf() &&
1622-
TheMemory.HasDummyElement) {
1623-
Type selfTy = TheMemory.getType();
1621+
if (TheMemory.isCrossModuleStructInitSelf() && TheMemory.hasDummyElement()) {
1622+
Type selfTy = TheMemory.getASTType();
16241623
const StructDecl *theStruct = selfTy->getStructOrBoundGenericStruct();
16251624
assert(theStruct);
16261625

@@ -1813,7 +1812,7 @@ void LifetimeChecker::handleSelfInitUse(unsigned UseID) {
18131812

18141813
assert(TheMemory.isAnyInitSelf());
18151814
assert(!TheMemory.isClassInitSelf() || TheMemory.isNonRootClassSelf());
1816-
assert(TheMemory.getType()->hasReferenceSemantics());
1815+
assert(TheMemory.getASTType()->hasReferenceSemantics());
18171816

18181817
// Determine the liveness states of the memory object, including the
18191818
// self/super.init state.
@@ -1981,7 +1980,7 @@ void LifetimeChecker::processUninitializedRelease(SILInstruction *Release,
19811980
if (Pointer->getType().isAddress())
19821981
Pointer = B.createLoad(Loc, Pointer, LoadOwnershipQualifier::Take);
19831982

1984-
auto MetatypeTy = CanMetatypeType::get(TheMemory.MemorySILType.getASTType(),
1983+
auto MetatypeTy = CanMetatypeType::get(TheMemory.getASTType(),
19851984
MetatypeRepresentation::Thick);
19861985
auto SILMetatypeTy = SILType::getPrimitiveObjectType(MetatypeTy);
19871986
SILValue Metatype;

0 commit comments

Comments
 (0)