mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
In explorer, we already support parsing a string_view, so use that. In toolchain, we need to build support, probably using vfs, so that's a todo. bazel test //explorer:file_test --runs_per_test=5 - branch: Stats over 250 runs: max = 18.3s, min = 5.2s, avg = 11.2s, dev = 2.9s - trunk: Stats over 250 runs: max = 22.3s, min = 5.9s, avg = 12.1s, dev = 2.8s Not a dramatic improvement, but maybe more effective long-term, and this'd been requested on #2876
46 lines
1.2 KiB
C++
46 lines
1.2 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#include "explorer/parse_and_execute/parse_and_execute.h"
|
|
|
|
#include <gmock/gmock.h>
|
|
#include <gtest/gtest.h>
|
|
|
|
namespace Carbon::Testing {
|
|
namespace {
|
|
|
|
using ::testing::Eq;
|
|
|
|
TEST(ParseAndExecuteTest, Recursion) {
|
|
std::string source = R"(
|
|
package Test api;
|
|
fn Main() -> i32 {
|
|
return
|
|
)";
|
|
// A high depth that's expected to complete in a few seconds.
|
|
static constexpr int Depth = 50000;
|
|
for (int i = 0; i < Depth; ++i) {
|
|
source += "if true then\n";
|
|
}
|
|
source += "1\n";
|
|
for (int i = 0; i < Depth; ++i) {
|
|
source += "else 0\n";
|
|
}
|
|
source += R"(
|
|
;
|
|
}
|
|
)";
|
|
TraceStream trace_stream;
|
|
auto err =
|
|
ParseAndExecute("explorer/data/prelude.carbon", "test.carbon", source,
|
|
/*parser_debug=*/false, &trace_stream, &llvm::nulls());
|
|
ASSERT_FALSE(err.ok());
|
|
EXPECT_THAT(err.error().message(),
|
|
Eq("RUNTIME ERROR: overflow:1: stack overflow: too many "
|
|
"interpreter actions on stack"));
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace Carbon::Testing
|