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

[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: 's avatarSigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61295}
parent 034defad
......@@ -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
......
......@@ -19,6 +19,11 @@ struct TorqueCompilerOptions {
std::string output_directory;
bool verbose;
bool collect_language_server_data;
// 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;
};
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);
......
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