mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user