Commit 2e3862d7 authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

Reland "[torque] Introduce force_assert_statements compiler option"

This is a reland of 2d45ecf0

The reland properly initializes struct fields in unittests. To prevent
this in the future, TorqueCompilerOptions uses brace initialization.

Original change's description:
> [torque] Introduce force_assert_statements compiler option
>
> "assert(...)" statements are usually only visited and generated in
> debug builds. To provide Language Server support for statements inside
> asserts, the force_assert_statements option allows to manually
> override this behavior and visit assert statements in release builds.
>
> R=sigurds@chromium.org
>
> Bug: v8:7793
> Change-Id: I38f48e35f2b0a1a98abb74b7babb1edd2d7dba24
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1599180
> Auto-Submit: Simon Zünd <szuend@chromium.org>
> Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
> Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#61295}

Bug: v8:7793
Change-Id: I96ef863c8c85ae87a00cbe858655d4a2c9368b41
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1599599
Auto-Submit: Simon Zünd <szuend@chromium.org>
Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61315}
parent 0b8d476a
......@@ -20,6 +20,7 @@ class GlobalContext : public ContextualClass<GlobalContext> {
explicit GlobalContext(Ast ast)
: verbose_(false),
collect_language_server_data_(false),
force_assert_statements_(false),
ast_(std::move(ast)) {
CurrentScope::Scope current_scope(nullptr);
CurrentSourcePosition::Scope current_source_position(
......@@ -72,11 +73,18 @@ class GlobalContext : public ContextualClass<GlobalContext> {
static bool collect_language_server_data() {
return Get().collect_language_server_data_;
}
static void SetForceAssertStatements() {
Get().force_assert_statements_ = true;
}
static bool force_assert_statements() {
return Get().force_assert_statements_;
}
static Ast* ast() { return &Get().ast_; }
private:
bool verbose_;
bool collect_language_server_data_;
bool force_assert_statements_;
Namespace* default_namespace_;
Ast ast_;
std::vector<std::unique_ptr<Declarable>> declarables_;
......
......@@ -1002,7 +1002,7 @@ std::string FormatAssertSource(const std::string& str) {
} // namespace
const Type* ImplementationVisitor::Visit(AssertStatement* stmt) {
bool do_check = !stmt->debug_only;
bool do_check = !stmt->debug_only || GlobalContext::force_assert_statements();
#if defined(DEBUG)
do_check = true;
#endif
......
......@@ -180,6 +180,7 @@ void RecompileTorque(MessageWriter writer) {
options.output_directory = "";
options.verbose = false;
options.collect_language_server_data = true;
options.force_assert_statements = true;
TorqueCompilerResult result = CompileTorque(TorqueFileList::Get(), options);
......
......@@ -51,6 +51,9 @@ void CompileCurrentAst(TorqueCompilerOptions options) {
if (options.collect_language_server_data) {
GlobalContext::SetCollectLanguageServerData();
}
if (options.force_assert_statements) {
GlobalContext::SetForceAssertStatements();
}
TypeOracle::Scope type_oracle;
// Two-step process of predeclaration + resolution allows to resolve type
......
......@@ -16,9 +16,14 @@ namespace internal {
namespace torque {
struct TorqueCompilerOptions {
std::string output_directory;
bool verbose;
bool collect_language_server_data;
std::string output_directory = "";
bool verbose = false;
bool collect_language_server_data = false;
// assert(...) are only generated for debug builds. The provide
// language server support for statements inside asserts, this flag
// can force generate them.
bool force_assert_statements = false;
};
struct TorqueCompilerResult {
......
......@@ -33,6 +33,7 @@ int WrappedMain(int argc, const char** argv) {
options.output_directory = output_directory;
options.verbose = verbose;
options.collect_language_server_data = false;
options.force_assert_statements = false;
TorqueCompilerResult result = CompileTorque(files, options);
......
......@@ -21,6 +21,7 @@ struct TestCompiler {
options.output_directory = "";
options.verbose = false;
options.collect_language_server_data = true;
options.force_assert_statements = true;
const TorqueCompilerResult result = CompileTorque(source, options);
SourceFileMap::Get() = result.source_file_map;
......
......@@ -18,6 +18,7 @@ TorqueCompilerResult TestCompileTorque(const std::string& source) {
options.output_directory = "";
options.verbose = false;
options.collect_language_server_data = false;
options.force_assert_statements = false;
return CompileTorque(source, options);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment