Skip to content

Commit a7d37a9

Browse files
committed
[ownership] When we flag an over consume, improve error msg by dumping consuming user list.
Specifically, there are a few places in the ownership data flow where before this patch we just dumped the violating user and the block where the overconsume occurred. Since we only dumped the block rather than consuming user list, it could require a little bit of time/energy to identify why the block was considered to already have a consume in it. So at least by dumping the consuming user list, the compiler writer has more information to reason about this.
1 parent 551862c commit a7d37a9

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

lib/SIL/LinearLifetimeChecker.cpp

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ struct State {
6363
/// put in missing destroys.
6464
SmallVectorImpl<SILBasicBlock *> *leakingBlocks;
6565

66+
/// The list of passed in consuming uses.
67+
ArrayRef<BranchPropagatedUser> consumingUses;
68+
69+
/// The list of passed in non consuming uses.
70+
ArrayRef<BranchPropagatedUser> nonConsumingUses;
71+
6672
/// The set of blocks with consuming uses.
6773
SmallPtrSet<SILBasicBlock *, 8> blocksWithConsumingUses;
6874

@@ -80,16 +86,22 @@ struct State {
8086

8187
State(SILValue value, SmallPtrSetImpl<SILBasicBlock *> &visitedBlocks,
8288
ErrorBehaviorKind errorBehavior,
83-
SmallVectorImpl<SILBasicBlock *> *leakingBlocks)
89+
SmallVectorImpl<SILBasicBlock *> *leakingBlocks,
90+
ArrayRef<BranchPropagatedUser> consumingUses,
91+
ArrayRef<BranchPropagatedUser> nonConsumingUses)
8492
: value(value), beginBlock(value->getParentBlock()), error(errorBehavior),
85-
visitedBlocks(visitedBlocks), leakingBlocks(leakingBlocks) {}
93+
visitedBlocks(visitedBlocks), leakingBlocks(leakingBlocks),
94+
consumingUses(consumingUses), nonConsumingUses(nonConsumingUses) {}
8695

8796
State(SILBasicBlock *beginBlock,
8897
SmallPtrSetImpl<SILBasicBlock *> &visitedBlocks,
8998
ErrorBehaviorKind errorBehavior,
90-
SmallVectorImpl<SILBasicBlock *> *leakingBlocks)
99+
SmallVectorImpl<SILBasicBlock *> *leakingBlocks,
100+
ArrayRef<BranchPropagatedUser> consumingUses,
101+
ArrayRef<BranchPropagatedUser> nonConsumingUses)
91102
: value(), beginBlock(beginBlock), error(errorBehavior),
92-
visitedBlocks(visitedBlocks), leakingBlocks(leakingBlocks) {}
103+
visitedBlocks(visitedBlocks), leakingBlocks(leakingBlocks),
104+
consumingUses(consumingUses), nonConsumingUses(nonConsumingUses) {}
93105

94106
void initializeAllNonConsumingUses(
95107
ArrayRef<BranchPropagatedUser> nonConsumingUsers);
@@ -124,6 +136,22 @@ struct State {
124136
/// for validity. If this is a linear typed value, return true. Return false
125137
/// otherwise.
126138
void checkDataflowEndState(DeadEndBlocks &deBlocks);
139+
140+
void dumpConsumingUsers() const {
141+
llvm::errs() << "Consuming Users:\n";
142+
for (auto user : consumingUses) {
143+
llvm::errs() << *user.getInst();
144+
}
145+
llvm::errs() << "\n";
146+
}
147+
148+
void dumpNonConsumingUsers() const {
149+
llvm::errs() << "Non Consuming Users:\n";
150+
for (auto user : nonConsumingUses) {
151+
llvm::errs() << *user.getInst();
152+
}
153+
llvm::errs() << "\n";
154+
}
127155
};
128156

129157
} // end anonymous namespace
@@ -224,7 +252,8 @@ void State::initializeConsumingUse(BranchPropagatedUser consumingUser,
224252
llvm::errs() << "Value: N/A\n";
225253
}
226254
llvm::errs() << "User: " << *consumingUser << "Block: bb"
227-
<< userBlock->getDebugID() << "\n\n";
255+
<< userBlock->getDebugID() << "\n";
256+
dumpConsumingUsers();
228257
});
229258
}
230259

@@ -327,7 +356,8 @@ void State::checkPredsForDoubleConsume(BranchPropagatedUser consumingUser,
327356
}
328357

329358
llvm::errs() << "User: " << *consumingUser << "Block: bb"
330-
<< userBlock->getDebugID() << "\n\n";
359+
<< userBlock->getDebugID() << "\n";
360+
dumpConsumingUsers();
331361
});
332362
}
333363

@@ -356,7 +386,8 @@ void State::checkPredsForDoubleConsume(SILBasicBlock *userBlock) {
356386
llvm::errs() << "N/A. \n";
357387
}
358388

359-
llvm::errs() << "Block: bb" << userBlock->getDebugID() << "\n\n";
389+
llvm::errs() << "Block: bb" << userBlock->getDebugID() << "\n";
390+
dumpConsumingUsers();
360391
});
361392
}
362393

@@ -514,7 +545,8 @@ LinearLifetimeError LinearLifetimeChecker::checkValue(
514545
SmallVectorImpl<SILBasicBlock *> *leakingBlocks) {
515546
assert(!consumingUses.empty() && "Must have at least one consuming user?!");
516547

517-
State state(value, visitedBlocks, errorBehavior, leakingBlocks);
548+
State state(value, visitedBlocks, errorBehavior, leakingBlocks, consumingUses,
549+
nonConsumingUses);
518550

519551
// First add our non-consuming uses and their blocks to the
520552
// blocksWithNonConsumingUses map. While we do this, if we have multiple uses

0 commit comments

Comments
 (0)