From 8dc6f4faef1206ca4442b193463a10e8806f95b6 Mon Sep 17 00:00:00 2001 From: "Matthew \"strager\" Glazar" Date: Tue, 20 Aug 2024 02:32:32 -0400 Subject: [PATCH] refactor(fe): delete unused user_diag_reporter_ code user_diag_reporter_ is always a Null_Diag_Reporter. Stop calling Null_Diag_Reporter::report_impl (which does nothing). --- src/quick-lint-js/fe/lex.cpp | 11 ----------- src/quick-lint-js/fe/lex.h | 16 ---------------- src/quick-lint-js/fe/parse-expression.cpp | 4 +--- src/quick-lint-js/fe/parse-statement.cpp | 6 ------ src/quick-lint-js/fe/parse-type.cpp | 2 -- src/quick-lint-js/fe/parse.cpp | 1 - src/quick-lint-js/fe/parse.h | 10 ---------- 7 files changed, 1 insertion(+), 49 deletions(-) diff --git a/src/quick-lint-js/fe/lex.cpp b/src/quick-lint-js/fe/lex.cpp index 000675de7e..bdb576fe0f 100644 --- a/src/quick-lint-js/fe/lex.cpp +++ b/src/quick-lint-js/fe/lex.cpp @@ -230,7 +230,6 @@ Lexer::Lexer(Padded_String_View input) Lexer::Lexer(Padded_String_View input, Lexer_Options options) : input_(input.data()), - user_diag_reporter_(&Null_Diag_Reporter::instance), original_input_(input), options_(options) { this->last_token_.end = this->input_; @@ -265,8 +264,6 @@ void Lexer::parse_bom_before_shebang() { while (!this->try_parse_current_token()) { // Loop. } - - this->flush_diags_to_user_reporter_if_needed(); } bool Lexer::try_parse_current_token() { @@ -1063,8 +1060,6 @@ void Lexer::skip_in_jsx() { } break; } - - this->flush_diags_to_user_reporter_if_needed(); } void Lexer::skip_in_jsx_children() { @@ -1244,8 +1239,6 @@ void Lexer::reparse_as_regexp() { this->input_ = c; this->last_token_.end = this->input_; - - this->flush_diags_to_user_reporter_if_needed(); } Lexer_Transaction Lexer::begin_transaction() { @@ -1266,8 +1259,6 @@ void Lexer::commit_transaction(Lexer_Transaction&& transaction) { this->diag_reporter_ = transaction.old_diag_reporter; transaction.reporter.reset(); - - this->flush_diags_to_user_reporter_if_needed(); } void Lexer::roll_back_transaction(Lexer_Transaction&& transaction) { @@ -2307,8 +2298,6 @@ void Lexer::skip_jsx_text() { done: // TODO(strager): Should we set has_leading_newline? this->input_ = c; - - this->flush_diags_to_user_reporter_if_needed(); } bool Lexer::is_eof(const Char8* input) const { diff --git a/src/quick-lint-js/fe/lex.h b/src/quick-lint-js/fe/lex.h index 7b12a7bc04..6cf44cd149 100644 --- a/src/quick-lint-js/fe/lex.h +++ b/src/quick-lint-js/fe/lex.h @@ -342,25 +342,9 @@ class Lexer { static Token_Type identifier_token_type(String8_View); - public: - // TODO(#1154): Delete this. - void flush_diags_to_user_reporter_if_needed() { - int i = 0; - this->diags().for_each([&](Diag_Type diag_type, void* diag_data) { - if (i >= this->diags_reporter_to_user_) { - this->user_diag_reporter_->report_impl(diag_type, diag_data); - this->diags_reporter_to_user_ += 1; - } - i += 1; - }); - } - - private: Token last_token_; const Char8* last_last_token_end_; const Char8* input_; - Diag_Reporter* user_diag_reporter_; // TODO(#1154): Delete. - int diags_reporter_to_user_ = 0; // TODO(#1154): Delete. Padded_String_View original_input_; Lexer_Options options_; diff --git a/src/quick-lint-js/fe/parse-expression.cpp b/src/quick-lint-js/fe/parse-expression.cpp index 6462722293..7057b1cef9 100644 --- a/src/quick-lint-js/fe/parse-expression.cpp +++ b/src/quick-lint-js/fe/parse-expression.cpp @@ -347,9 +347,7 @@ Expression* Parser::parse_expression(Parse_Visitor_Base& v, Precedence prec) { if (!prec.binary_operators && prec.math_or_logical_or_assignment) { return ast; } - ast = this->parse_expression_remainder(v, ast, prec); - this->flush_diags_to_user_reporter_if_needed(); - return ast; + return this->parse_expression_remainder(v, ast, prec); } // TODO(strager): Why do we need precedence here? Could we get rid of prec? diff --git a/src/quick-lint-js/fe/parse-statement.cpp b/src/quick-lint-js/fe/parse-statement.cpp index 4728f6e4f2..bc283f0715 100644 --- a/src/quick-lint-js/fe/parse-statement.cpp +++ b/src/quick-lint-js/fe/parse-statement.cpp @@ -70,7 +70,6 @@ void Parser::parse_and_visit_module(Parse_Visitor_Base &v) { } this->check_all_jsx_attributes(); v.visit_end_of_module(); - this->flush_diags_to_user_reporter_if_needed(); } bool Parser::parse_and_visit_statement(Parse_Visitor_Base &v, @@ -785,7 +784,6 @@ bool Parser::parse_and_visit_statement(Parse_Visitor_Base &v, case Token_Type::end_of_file: case Token_Type::right_curly: - this->flush_diags_to_user_reporter_if_needed(); // Do not set is_current_typescript_namespace_non_empty_. return false; @@ -794,7 +792,6 @@ bool Parser::parse_and_visit_statement(Parse_Visitor_Base &v, break; } - this->flush_diags_to_user_reporter_if_needed(); return true; } @@ -1684,7 +1681,6 @@ void Parser::parse_and_visit_typescript_generic_parameters( }); } this->skip(); - this->flush_diags_to_user_reporter_if_needed(); return; } for (const Source_Code_Span &comma : leading_commas) { @@ -1909,8 +1905,6 @@ void Parser::parse_and_visit_typescript_generic_parameters( // See NOTE[generic-type-parameter-visit-order]. extends_visits.visitor().move_into(v); - - this->flush_diags_to_user_reporter_if_needed(); } void Parser::parse_and_visit_statement_block_no_scope(Parse_Visitor_Base &v) { diff --git a/src/quick-lint-js/fe/parse-type.cpp b/src/quick-lint-js/fe/parse-type.cpp index 03055bfa41..cb82ff9e47 100644 --- a/src/quick-lint-js/fe/parse-type.cpp +++ b/src/quick-lint-js/fe/parse-type.cpp @@ -911,8 +911,6 @@ void Parser::parse_and_visit_typescript_type_expression_no_scope( .parse_question_as_invalid = false, }); } - - this->flush_diags_to_user_reporter_if_needed(); } void Parser::parse_and_visit_typescript_arrow_type_expression( diff --git a/src/quick-lint-js/fe/parse.cpp b/src/quick-lint-js/fe/parse.cpp index 8d61c76325..5f158208f0 100644 --- a/src/quick-lint-js/fe/parse.cpp +++ b/src/quick-lint-js/fe/parse.cpp @@ -965,7 +965,6 @@ void Parser::commit_transaction(Parser_Transaction&& transaction) { this->diag_reporter_ = transaction.old_diag_reporter; this->lexer_.commit_transaction(std::move(transaction.lex_transaction)); - this->flush_diags_to_user_reporter_if_needed(); } void Parser::roll_back_transaction(Parser_Transaction&& transaction) { diff --git a/src/quick-lint-js/fe/parse.h b/src/quick-lint-js/fe/parse.h index 882b86901a..95e619e0fd 100644 --- a/src/quick-lint-js/fe/parse.h +++ b/src/quick-lint-js/fe/parse.h @@ -127,13 +127,6 @@ class Parser { return this->lexer_.diag_list_diag_reporter(); } - private: - // TODO(#1154): Delete this. - void flush_diags_to_user_reporter_if_needed() { - this->lexer_.flush_diags_to_user_reporter_if_needed(); - } - - public: // For testing and internal use only. [[nodiscard]] Function_Guard enter_function(Function_Attributes); @@ -179,7 +172,6 @@ class Parser { break; } - this->flush_diags_to_user_reporter_if_needed(); return false; }); @@ -859,8 +851,6 @@ class Parser { auto disable_guard = alloc.disable(); this->visit_expression(ast, v, Variable_Context::rhs); } - - this->flush_diags_to_user_reporter_if_needed(); } Expression *parse_expression(Parse_Visitor_Base &, Precedence);