Skip to content

[di] Hide some internal state and give some methods better names given current usage. #28885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ class ElementUseCollector {

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

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

{
SILType T = TheMemory.MemorySILType;
SILType T = TheMemory.getType();
auto *NTD = T.getNominalOrBoundGenericNominal();
unsigned NumElements = 0;
for (auto *VD : NTD->getStoredProperties()) {
Expand All @@ -1149,7 +1149,7 @@ void ElementUseCollector::collectClassSelfUses() {
// MUI use-def chain directly to find our uses.
auto *MemoryInst = TheMemory.MemoryInst;
if (MemoryInst->getKind() == MarkUninitializedInst::RootSelf) {
collectClassSelfUses(MemoryInst, TheMemory.MemorySILType, EltNumbering);
collectClassSelfUses(MemoryInst, TheMemory.getType(), EltNumbering);
return;
}

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

Expand Down Expand Up @@ -1857,7 +1857,7 @@ static bool shouldPerformClassInitSelf(const DIMemoryObjectInfo &MemoryInfo) {
return true;

return MemoryInfo.isNonDelegatingInit() &&
MemoryInfo.getType()->getClassOrBoundGenericClass() != nullptr &&
MemoryInfo.getASTType()->getClassOrBoundGenericClass() != nullptr &&
MemoryInfo.isDerivedClassSelfOnly();
}

Expand Down
32 changes: 22 additions & 10 deletions lib/SILOptimizer/Mandatory/DIMemoryUseCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,18 @@ class DIMemoryObjectInfo {
/// The uninitialized memory that we are analyzing.
MarkUninitializedInst *MemoryInst;

private:
/// This is the base type of the memory allocation.
SILType MemorySILType;

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

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

CanType getType() const { return MemorySILType.getASTType(); }
CanType getASTType() const { return MemorySILType.getASTType(); }
SILType getType() const { return MemorySILType; }

/// Returns true if this memory object is of trivial type.
bool hasTrivialType() const { return MemorySILType.isTrivial(getFunction()); }

/// Returns true if NumElements has a dummy value in it to force a struct to
/// be non-empty.
bool hasDummyElement() const { return HasDummyElement; }

SingleValueInstruction *getAddress() const { return MemoryInst; }

/// getNumMemoryElements - Return the number of elements, without the extra
/// "super.init" tracker in initializers of derived classes.
/// Return the number of elements, without the extra "super.init" tracker in
/// initializers of derived classes.
unsigned getNumMemoryElements() const {
return NumElements - (unsigned)isDerivedClassSelf();
}

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

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

if (!MemoryInst->isVar()) {
if (auto decl = getType()->getAnyNominal()) {
if (auto decl = getASTType()->getAnyNominal()) {
if (isa<ClassDecl>(decl)) {
return true;
}
Expand Down Expand Up @@ -176,14 +188,14 @@ class DIMemoryObjectInfo {
return false;
}

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

/// getElementType - Return the swift type of the specified element.
/// Return the swift type of the specified element.
SILType getElementType(unsigned EltNo) const;

/// Push the symbolic path name to the specified element number onto the
Expand Down
17 changes: 8 additions & 9 deletions lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,11 +792,11 @@ void LifetimeChecker::doIt() {
// memory object will destruct the memory. If the memory (or some element
// thereof) is not initialized on some path, the bad things happen. Process
// releases to adjust for this.
if (!TheMemory.MemorySILType.isTrivial(F)) {
if (!TheMemory.hasTrivialType()) {
for (unsigned i = 0, e = Destroys.size(); i != e; ++i)
processNonTrivialRelease(i);
}

// If the memory object had any non-trivial stores that are init or assign
// based on the control flow path reaching them, then insert dynamic control
// logic and CFG diamonds to handle this.
Expand Down Expand Up @@ -1020,7 +1020,7 @@ void LifetimeChecker::handleStoreUse(unsigned UseID) {
if (auto *ctor = fnLoc.getAsASTNode<ConstructorDecl>())
selfTy = ctor->getImplicitSelfDecl()->getType();
else
selfTy = TheMemory.getType();
selfTy = TheMemory.getASTType();

StructDecl *theStruct = selfTy->getStructOrBoundGenericStruct();
assert(theStruct);
Expand Down Expand Up @@ -1284,7 +1284,7 @@ void LifetimeChecker::handleEscapeUse(const DIMemoryUse &Use) {
diagnose(Module, Inst->getLoc(), diag::self_before_selfinit_value_type);
if (!HasSuggestedNoArgSelfInit && FullyUninitialized) {
auto *maybeStruct =
TheMemory.getType().getStructOrBoundGenericStruct();
TheMemory.getASTType().getStructOrBoundGenericStruct();
maybeSuggestNoArgSelfInit(Module, Inst->getLoc(), maybeStruct);
HasSuggestedNoArgSelfInit = true;
}
Expand Down Expand Up @@ -1618,9 +1618,8 @@ bool LifetimeChecker::diagnoseReturnWithoutInitializingStoredProperties(
if (!shouldEmitError(Inst))
return true;

if (TheMemory.isCrossModuleStructInitSelf() &&
TheMemory.HasDummyElement) {
Type selfTy = TheMemory.getType();
if (TheMemory.isCrossModuleStructInitSelf() && TheMemory.hasDummyElement()) {
Type selfTy = TheMemory.getASTType();
const StructDecl *theStruct = selfTy->getStructOrBoundGenericStruct();
assert(theStruct);

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

assert(TheMemory.isAnyInitSelf());
assert(!TheMemory.isClassInitSelf() || TheMemory.isNonRootClassSelf());
assert(TheMemory.getType()->hasReferenceSemantics());
assert(TheMemory.getASTType()->hasReferenceSemantics());

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

auto MetatypeTy = CanMetatypeType::get(TheMemory.MemorySILType.getASTType(),
auto MetatypeTy = CanMetatypeType::get(TheMemory.getASTType(),
MetatypeRepresentation::Thick);
auto SILMetatypeTy = SILType::getPrimitiveObjectType(MetatypeTy);
SILValue Metatype;
Expand Down