Test trace output of Tree::VerifyExtractAs, fix found bugs (#3545)

Tests previously uncovered code. Fix uncovered problems:
* formatting of trace output
* package & import directives need to be classified as declarations
* the problem that meant the previous problem wasn't caught by existing
tests (since `Tree::Verify` didn't check that top-level declarations
match `AnyDeclId`, as required by `Tree::ExtractFile()`).
This commit is contained in:
josh11b
2023-12-28 00:27:53 +00:00
committed by GitHub
parent 29104e212a
commit 73cf277bdf
4 changed files with 169 additions and 14 deletions
+10 -2
View File
@@ -248,8 +248,8 @@ auto Tree::Verify() const -> ErrorOr<Success> {
}
// Should extract successfully if node not marked as having an error.
// Without this code, a 10 mloc test case of lex & parse takes
// 4.129 s ± 0.041 s. With this additional verification, it takes
// 5.768 s ± 0.036 s.
// 4.129 s ± 0.041 s. With this additional verification, it takes
// 5.768 s ± 0.036 s.
if (!n_impl.has_error && !TestExtract(this, n, n_impl.kind, nullptr)) {
ErrorBuilder trace;
trace << llvm::formatv(
@@ -311,6 +311,14 @@ auto Tree::Verify() const -> ErrorOr<Success> {
prev_index = n.index;
}
// Validate the roots, ensures Tree::ExtractFile() doesn't CHECK-fail.
if (!TryExtractNodeFromChildren<File>(roots(), nullptr)) {
ErrorBuilder trace;
trace << "Roots of tree couldn't be extracted as a `File`. Trace:\n";
TryExtractNodeFromChildren<File>(roots(), &trace);
return trace;
}
if (!has_errors_ && static_cast<int32_t>(node_impls_.size()) !=
tokens_->expected_parse_tree_size()) {
return Error(