Reduce dumped context on parse verify errors. (#2725)

I'm suspicious this is responsible for some OOMs in fuzzing... Specifically, it dumps a really big parse tree, then the auto fuzzing system OOMs trying to cache the entire output in memory.
This commit is contained in:
Jon Ross-Perkins
2023-03-30 14:58:14 -07:00
committed by GitHub
parent 706e611b6d
commit 1f741c292f
2 changed files with 9 additions and 5 deletions
+8 -4
View File
@@ -25,8 +25,12 @@ auto ParseTree::Parse(TokenizedBuffer& tokens, DiagnosticConsumer& consumer,
// Delegate to the parser.
auto tree = Parser::Parse(tokens, emitter, vlog_stream);
auto verify_error = tree.Verify();
CARBON_CHECK(!verify_error) << tree << *verify_error;
if (auto verify = tree.Verify(); !verify.ok()) {
if (vlog_stream) {
tree.Print(*vlog_stream);
}
CARBON_FATAL() << "Invalid tree returned by Parse(): " << verify.error();
}
return tree;
}
@@ -188,7 +192,7 @@ auto ParseTree::Print(llvm::raw_ostream& output, bool preorder) const -> void {
output << "]\n";
}
auto ParseTree::Verify() const -> std::optional<Error> {
auto ParseTree::Verify() const -> ErrorOr<Success> {
llvm::SmallVector<ParseTree::Node> nodes;
// Traverse the tree in postorder.
for (Node n : postorder()) {
@@ -259,7 +263,7 @@ auto ParseTree::Verify() const -> std::optional<Error> {
"TokenizedBuffer has {1} tokens.",
node_impls_.size(), tokens_->size()));
}
return std::nullopt;
return Success();
}
auto ParseTree::PostorderIterator::Print(llvm::raw_ostream& output) const
+1 -1
View File
@@ -146,7 +146,7 @@ class ParseTree {
// This is primarily intended to be used as a
// debugging aid. This routine doesn't directly CHECK so that it can be used
// within a debugger.
[[nodiscard]] auto Verify() const -> std::optional<Error>;
[[nodiscard]] auto Verify() const -> ErrorOr<Success>;
private:
friend class Parser;