mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 20:20:10 +01:00
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:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user