Start checking for a few possible resource exhaustion scenarios for explorer (#2793)

I couldn't figure out a way to actually hit a reasonable out-of-memory case once I add the maximum interpreter step count. However, the step count limit seems more important.

I've moved the todo stack limit out of function calls because there are plenty of ways to build up the todo stack without any function calls.

Fixes #2791
This commit is contained in:
Jon Ross-Perkins
2023-04-21 15:14:14 -07:00
committed by GitHub
parent f310316ef4
commit b828093c87
10 changed files with 104 additions and 19 deletions
+3 -3
View File
@@ -21,7 +21,7 @@ void ActionStack::Print(llvm::raw_ostream& out) const {
void ActionStack::Start(std::unique_ptr<Action> action) {
result_ = std::nullopt;
CARBON_CHECK(todo_.IsEmpty());
CARBON_CHECK(todo_.empty());
todo_.Push(std::move(action));
}
@@ -253,7 +253,7 @@ auto ActionStack::UnwindPast(Nonnull<const Statement*> ast_node,
void ActionStack::PopScopes(
std::stack<std::unique_ptr<Action>>& cleanup_stack) {
while (!todo_.IsEmpty() && llvm::isa<ScopeAction>(*todo_.Top())) {
while (!todo_.empty() && llvm::isa<ScopeAction>(*todo_.Top())) {
auto act = todo_.Pop();
if (act->scope()) {
cleanup_stack.push(std::move(act));
@@ -262,7 +262,7 @@ void ActionStack::PopScopes(
}
void ActionStack::SetResult(Nonnull<const Value*> result) {
if (todo_.IsEmpty()) {
if (todo_.empty()) {
result_ = result;
} else {
todo_.Top()->AddResult(result);