Skip to content

Commit

Permalink
refactor(container): remove allocator template param from Bump_Vector
Browse files Browse the repository at this point in the history
Bump_Vector is only instantiated with Linked_Bump_Allocator for
Bump_Allocator. Inline Bump_Allocator, making some code less verbose.
  • Loading branch information
strager committed Nov 5, 2023
1 parent 9bf7e0a commit 6036c62
Show file tree
Hide file tree
Showing 27 changed files with 104 additions and 121 deletions.
9 changes: 4 additions & 5 deletions src/quick-lint-js/c-api-diag-reporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class C_API_Diag_Reporter final : public Diag_Reporter {

Translator translator_;
Monotonic_Allocator allocator_{"C_API_Diag_Reporter::allocator_"};
Bump_Vector<Diagnostic, Monotonic_Allocator> diagnostics_{
"C_API_Diag_Reporter::diagnostics_", &this->allocator_};
Bump_Vector<Diagnostic> diagnostics_{"C_API_Diag_Reporter::diagnostics_",
&this->allocator_};
const Char8 *input_;
std::optional<Locator> locator_;
Monotonic_Allocator string_allocator_{
Expand All @@ -68,9 +68,8 @@ class C_API_Diag_Formatter

private:
C_API_Diag_Reporter<Diagnostic, Locator> *reporter_;
Bump_Vector<Char8, Monotonic_Allocator> current_message_{
"C_API_Diag_Reporter::current_message_",
&this->reporter_->string_allocator_};
Bump_Vector<Char8> current_message_{"C_API_Diag_Reporter::current_message_",
&this->reporter_->string_allocator_};
};

QLJS_WARNING_PUSH
Expand Down
9 changes: 4 additions & 5 deletions src/quick-lint-js/cli/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ Options parse_options(int argc, char** argv, Monotonic_Allocator* allocator) {
const char* arg_var;
} next_vim_file_bufnr;

Bump_Vector<File_To_Lint, Monotonic_Allocator> files_to_lint("files_to_lint",
allocator);
Bump_Vector<const char*, Monotonic_Allocator> error_unrecognized_options(
Bump_Vector<File_To_Lint> files_to_lint("files_to_lint", allocator);
Bump_Vector<const char*> error_unrecognized_options(
"error_unrecognized_options", allocator);
Bump_Vector<const char*, Monotonic_Allocator> warning_vim_bufnr_without_file(
Bump_Vector<const char*> warning_vim_bufnr_without_file(
"warning_vim_bufnr_without_file", allocator);
Bump_Vector<const char*, Monotonic_Allocator> warning_language_without_file(
Bump_Vector<const char*> warning_language_without_file(
"warning_language_without_file", allocator);

const char* next_path_for_config_search = nullptr;
Expand Down
6 changes: 2 additions & 4 deletions src/quick-lint-js/container/vector-profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,12 @@ Vector_Max_Size_Histogram_By_Owner::histogram(

// NOTE(strager): We use Raw_Bump_Vector to prevent vector profiling code from
// emitting events itself.
Raw_Bump_Vector<Trace_Vector_Max_Size_Histogram_By_Owner_Entry,
Monotonic_Allocator>
Raw_Bump_Vector<Trace_Vector_Max_Size_Histogram_By_Owner_Entry>
out_entries_by_owner(memory);
out_entries_by_owner.reserve(
narrow_cast<Bump_Vector_Size>(stable_histogram.size()));
for (auto &[owner, counts] : stable_histogram) {
Raw_Bump_Vector<Trace_Vector_Max_Size_Histogram_Entry, Monotonic_Allocator>
out_entries(memory);
Raw_Bump_Vector<Trace_Vector_Max_Size_Histogram_Entry> out_entries(memory);
out_entries.reserve(narrow_cast<Bump_Vector_Size>(counts.size()));
for (auto &[size, count] : counts) {
out_entries.push_back(Trace_Vector_Max_Size_Histogram_Entry{
Expand Down
20 changes: 11 additions & 9 deletions src/quick-lint-js/container/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <cstdint>
#include <memory>
#include <quick-lint-js/assert.h>
#include <quick-lint-js/container/linked-bump-allocator.h>
#include <quick-lint-js/container/winkable.h>
#include <quick-lint-js/feature.h>
#include <quick-lint-js/port/attribute.h>
Expand Down Expand Up @@ -91,11 +92,11 @@ class Uninstrumented_Vector : private Vector {

using Bump_Vector_Size = std::ptrdiff_t;

template <class T, class Bump_Allocator>
template <class T>
class Raw_Bump_Vector {
public:
using value_type = T;
using allocator_type = Bump_Allocator *;
using allocator_type = Linked_Bump_Allocator *;
using size_type = Bump_Vector_Size;
using difference_type = Bump_Vector_Size;
using reference = T &;
Expand All @@ -107,7 +108,8 @@ class Raw_Bump_Vector {

static_assert(is_winkable_v<T>);

explicit Raw_Bump_Vector(Bump_Allocator *allocator) : allocator_(allocator) {}
explicit Raw_Bump_Vector(Linked_Bump_Allocator *allocator)
: allocator_(allocator) {}

Raw_Bump_Vector(const Raw_Bump_Vector &) = delete;
Raw_Bump_Vector &operator=(const Raw_Bump_Vector &) = delete;
Expand All @@ -124,7 +126,7 @@ class Raw_Bump_Vector {

~Raw_Bump_Vector() { this->clear(); }

Bump_Allocator *get_allocator() const { return this->allocator_; }
Linked_Bump_Allocator *get_allocator() const { return this->allocator_; }

bool empty() const { return this->data_ == this->data_end_; }
size_type size() const {
Expand Down Expand Up @@ -338,15 +340,15 @@ class Raw_Bump_Vector {
T *data_end_ = nullptr;
T *capacity_end_ = nullptr;

Bump_Allocator *allocator_;
Linked_Bump_Allocator *allocator_;
};

#if QLJS_FEATURE_VECTOR_PROFILING
template <class T, class Bump_Allocator>
using Bump_Vector = Instrumented_Vector<Raw_Bump_Vector<T, Bump_Allocator>>;
template <class T>
using Bump_Vector = Instrumented_Vector<Raw_Bump_Vector<T>>;
#else
template <class T, class Bump_Allocator>
using Bump_Vector = Uninstrumented_Vector<Raw_Bump_Vector<T, Bump_Allocator>>;
template <class T>
using Bump_Vector = Uninstrumented_Vector<Raw_Bump_Vector<T>>;
#endif
}

Expand Down
3 changes: 1 addition & 2 deletions src/quick-lint-js/debug/find-debug-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@ void enumerate_all_process_thread_names(Callback&& callback) {

#if defined(__linux__)
Span<Found_Debug_Server> find_debug_servers(Monotonic_Allocator* allocator) {
Bump_Vector<Found_Debug_Server, Monotonic_Allocator> debug_servers(
"debug_servers", allocator);
Bump_Vector<Found_Debug_Server> debug_servers("debug_servers", allocator);

enumerate_all_process_thread_names([&](std::string_view process_id_string,
std::string_view thread_name) {
Expand Down
29 changes: 12 additions & 17 deletions src/quick-lint-js/diag/diag-code-list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@ Parsed_Diag_Code_List parse_diag_code_list(const char* const raw_diag_code_list,
return '0' <= c && c <= '9';
};

Bump_Vector<std::string_view, Monotonic_Allocator> included_codes(
"included_codes", allocator);
Bump_Vector<std::string_view, Monotonic_Allocator> excluded_codes(
"excluded_codes", allocator);
Bump_Vector<std::string_view, Monotonic_Allocator> included_categories(
"included_categories", allocator);
Bump_Vector<std::string_view, Monotonic_Allocator> excluded_categories(
"excluded_categories", allocator);
Bump_Vector<std::string_view, Monotonic_Allocator> unexpected("unexpected",
allocator);
Bump_Vector<std::string_view> included_codes("included_codes", allocator);
Bump_Vector<std::string_view> excluded_codes("excluded_codes", allocator);
Bump_Vector<std::string_view> included_categories("included_categories",
allocator);
Bump_Vector<std::string_view> excluded_categories("excluded_categories",
allocator);
Bump_Vector<std::string_view> unexpected("unexpected", allocator);
bool override_defaults = false;

std::size_t i = 0;
Expand Down Expand Up @@ -143,11 +140,10 @@ void Compiled_Diag_Code_List::add(const Parsed_Diag_Code_List& diag_code_list) {

Span<std::string_view> Compiled_Diag_Code_List::parse_errors(
std::string_view cli_option_name, Monotonic_Allocator* allocator) const {
Bump_Vector<std::string_view, Monotonic_Allocator> errors("errors",
allocator);
Bump_Vector<std::string_view> errors("errors", allocator);
if (this->has_missing_predicate_error_) {
// TODO(#1102): Make this code pretty.
Bump_Vector<char, Monotonic_Allocator> error("error", allocator);
Bump_Vector<char> error("error", allocator);
error += cli_option_name;
error += " must be given at least one category or code"sv;
errors.emplace_back(error.release_to_string_view());
Expand All @@ -157,12 +153,11 @@ Span<std::string_view> Compiled_Diag_Code_List::parse_errors(

Span<std::string_view> Compiled_Diag_Code_List::parse_warnings(
Monotonic_Allocator* allocator) const {
Bump_Vector<std::string_view, Monotonic_Allocator> warnings("warnings",
allocator);
Bump_Vector<std::string_view> warnings("warnings", allocator);
auto check_category = [&](std::string_view category) {
if (category != "all") {
// TODO(#1102): Make this code pretty.
Bump_Vector<char, Monotonic_Allocator> warning("warning", allocator);
Bump_Vector<char> warning("warning", allocator);
warning += "unknown error category: "sv;
warning += category;
warnings.emplace_back(warning.release_to_string_view());
Expand All @@ -180,7 +175,7 @@ Span<std::string_view> Compiled_Diag_Code_List::parse_warnings(

for (std::string_view code : this->unknown_codes_) {
// TODO(#1102): Make this code pretty.
Bump_Vector<char, Monotonic_Allocator> warning("warning", allocator);
Bump_Vector<char> warning("warning", allocator);
warning += "unknown error code: "sv;
warning += code;
warnings.emplace_back(warning.release_to_string_view());
Expand Down
8 changes: 4 additions & 4 deletions src/quick-lint-js/diag/diag-code-list.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ class Compiled_Diag_Code_List {
// movable.
std::unique_ptr<Monotonic_Allocator> allocator_;

Bump_Vector<Codes, Monotonic_Allocator> parsed_diag_code_lists_{
"parsed_diag_code_lists_", this->allocator_.get()};
Bump_Vector<Codes> parsed_diag_code_lists_{"parsed_diag_code_lists_",
this->allocator_.get()};

// Collected errors and warnings:
Bump_Vector<std::string_view, Monotonic_Allocator> unknown_codes_{
"unknown_codes_", this->allocator_.get()};
Bump_Vector<std::string_view> unknown_codes_{"unknown_codes_",
this->allocator_.get()};
bool has_missing_predicate_error_ = false;
};
}
Expand Down
6 changes: 3 additions & 3 deletions src/quick-lint-js/fe/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class Expression_Arena {
using Buffering_Visitor_Ptr = Buffering_Visitor *;

template <class T>
using Vector = Bump_Vector<T, Monotonic_Allocator>;
using Vector = Bump_Vector<T>;

template <class T>
static inline constexpr bool is_allocatable =
Expand All @@ -172,7 +172,7 @@ class Expression_Arena {
Expression *make_expression(Args &&... args);

template <class T>
Array_Ptr<T> make_array(Bump_Vector<T, Monotonic_Allocator> &&);
Array_Ptr<T> make_array(Bump_Vector<T> &&);

template <class T>
Array_Ptr<T> make_array(T *begin, T *end);
Expand Down Expand Up @@ -337,7 +337,7 @@ Expression *Expression_Arena::make_expression(Args &&... args) {

template <class T>
inline Expression_Arena::Array_Ptr<T> Expression_Arena::make_array(
Bump_Vector<T, Monotonic_Allocator> &&elements) {
Bump_Vector<T> &&elements) {
QLJS_ASSERT(elements.get_allocator() == &this->allocator_);
// NOTE(strager): Adopt the pointer instead of copying.
Array_Ptr<T> result(elements.data(), elements.size());
Expand Down
4 changes: 2 additions & 2 deletions src/quick-lint-js/fe/lex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1698,8 +1698,8 @@ Lexer::Parsed_Identifier Lexer::parse_identifier_slow(
const Char8* private_identifier_begin =
is_private_identifier ? &identifier_begin[-1] : identifier_begin;

Bump_Vector<Char8, Monotonic_Allocator> normalized(
"parse_identifier_slow normalized", &this->allocator_);
Bump_Vector<Char8> normalized("parse_identifier_slow normalized",
&this->allocator_);
normalized.append(private_identifier_begin, input);

Escape_Sequence_List* escape_sequences =
Expand Down
13 changes: 6 additions & 7 deletions src/quick-lint-js/fe/parse-class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,8 @@ void Parser::parse_and_visit_class_or_interface_member(
this->type == Token_Type::kw_public;
}
};
Bump_Vector<Modifier, Monotonic_Allocator> modifiers =
Bump_Vector<Modifier, Monotonic_Allocator>("class member modifiers",
&p->temporary_memory_);
Bump_Vector<Modifier> modifiers =
Bump_Vector<Modifier>("class member modifiers", &p->temporary_memory_);

// Example:
//
Expand All @@ -323,8 +322,8 @@ void Parser::parse_and_visit_class_or_interface_member(

Source_Code_Span name_span;
};
Bump_Vector<TypeScript_Overload_Signature, Monotonic_Allocator>
overload_signatures{"class overload signatures", &p->temporary_memory_};
Bump_Vector<TypeScript_Overload_Signature> overload_signatures{
"class overload signatures", &p->temporary_memory_};

void reset_state_except_overload_signatures() {
this->current_member_begin = p->peek().begin;
Expand Down Expand Up @@ -897,8 +896,8 @@ void Parser::parse_and_visit_class_or_interface_member(
// this->overload_signatures then parse the next member.
is_possibly_typescript_overload = true;
const Char8 *expected_body = p->lexer_.end_of_previous_token();
Bump_Vector<Source_Code_Span, Monotonic_Allocator> semicolons(
"semicolons", &p->temporary_memory_);
Bump_Vector<Source_Code_Span> semicolons("semicolons",
&p->temporary_memory_);
while (p->peek().type == Token_Type::semicolon) {
semicolons.push_back(p->peek().span());
p->skip();
Expand Down
4 changes: 2 additions & 2 deletions src/quick-lint-js/fe/parse-expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3763,8 +3763,8 @@ Expression* Parser::parse_jsx_element_or_fragment(Parse_Visitor_Base& v,
mismatch = true;
}
if (mismatch) {
Bump_Vector<Char8, Monotonic_Allocator> opening_tag_name_pretty(
"opening_tag_name_pretty", &this->diagnostic_memory_);
Bump_Vector<Char8> opening_tag_name_pretty("opening_tag_name_pretty",
&this->diagnostic_memory_);
if (tag_namespace) {
opening_tag_name_pretty += tag_namespace->span().string_view();
opening_tag_name_pretty += u8':';
Expand Down
8 changes: 4 additions & 4 deletions src/quick-lint-js/fe/parse-statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ void Parser::parse_and_visit_export(Parse_Visitor_Base &v,
// NOTE[ambiguous-ambient-statement-in-namespace].
Stacked_Buffering_Visitor exports_visitor =
this->buffering_visitor_stack_.push();
Bump_Vector<Token, Monotonic_Allocator> exported_bad_tokens(
Bump_Vector<Token> exported_bad_tokens(
"parse_and_visit_export exported_bad_tokens", &this->temporary_memory_);
this->parse_and_visit_named_exports(
exports_visitor.visitor(),
Expand Down Expand Up @@ -1595,7 +1595,7 @@ void Parser::parse_and_visit_typescript_generic_parameters(
const Char8 *less_end = this->peek().end;
this->skip();

Bump_Vector<Source_Code_Span, Monotonic_Allocator> leading_commas(
Bump_Vector<Source_Code_Span> leading_commas(
"parse_and_visit_typescript_generic_parameters leading_commas",
&this->temporary_memory_);
while (this->peek().type == Token_Type::comma) {
Expand Down Expand Up @@ -1942,7 +1942,7 @@ void Parser::parse_and_visit_function_declaration(
Identifier function_name = this->peek().identifier_name();
this->skip();

Bump_Vector<Identifier, Monotonic_Allocator> overload_names(
Bump_Vector<Identifier> overload_names(
"parse_and_visit_function_declaration overload_names",
&this->temporary_memory_);

Expand Down Expand Up @@ -4626,7 +4626,7 @@ void Parser::parse_and_visit_named_exports_for_typescript_type_only_import(
void Parser::parse_and_visit_named_exports(
Parse_Visitor_Base &v,
std::optional<Source_Code_Span> typescript_type_only_keyword,
Bump_Vector<Token, Monotonic_Allocator> *out_exported_bad_tokens) {
Bump_Vector<Token> *out_exported_bad_tokens) {
QLJS_ASSERT(this->peek().type == Token_Type::left_curly);
this->skip();

Expand Down
4 changes: 2 additions & 2 deletions src/quick-lint-js/fe/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ void Parser::check_jsx_attribute(const Identifier& attribute_name) {
bool name_has_upper = any_of(name, isupper);

if (!name_has_upper && is_event_attribute) {
Bump_Vector<Char8, Monotonic_Allocator> fixed_name(
"check_jsx_attribute fixed_name", &this->diagnostic_memory_);
Bump_Vector<Char8> fixed_name("check_jsx_attribute fixed_name",
&this->diagnostic_memory_);
fixed_name += name;
fixed_name[2] = toupper(fixed_name[2]);
this->diag_reporter_->report(Diag_JSX_Event_Attribute_Should_Be_Camel_Case{
Expand Down
2 changes: 1 addition & 1 deletion src/quick-lint-js/fe/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ class Parser {
void parse_and_visit_named_exports(
Parse_Visitor_Base &v,
std::optional<Source_Code_Span> typescript_type_only_keyword,
Bump_Vector<Token, Monotonic_Allocator> *out_exported_bad_tokens);
Bump_Vector<Token> *out_exported_bad_tokens);

void parse_and_visit_variable_declaration_statement(
Parse_Visitor_Base &v,
Expand Down
2 changes: 1 addition & 1 deletion src/quick-lint-js/fe/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ enum class Token_Type {
const char* to_string(Token_Type);
std::ostream& operator<<(std::ostream&, Token_Type);

using Escape_Sequence_List = Bump_Vector<Source_Code_Span, Monotonic_Allocator>;
using Escape_Sequence_List = Bump_Vector<Source_Code_Span>;

struct Token {
Identifier identifier_name() const;
Expand Down
6 changes: 2 additions & 4 deletions src/quick-lint-js/i18n/po-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ class PO_Parser {
this->fatal();
}
this->input_ += 1;
Bump_Vector<Char8, Monotonic_Allocator> decoded("parse_string",
this->allocator_);
Bump_Vector<Char8> decoded("parse_string", this->allocator_);
for (;;) {
switch (*this->input_) {
case u8'"': {
Expand Down Expand Up @@ -219,8 +218,7 @@ class PO_Parser {
const CLI_Locator* locator_;
Monotonic_Allocator* allocator_;

Bump_Vector<PO_Entry, Monotonic_Allocator> entries_{"PO_Parser::entries",
this->allocator_};
Bump_Vector<PO_Entry> entries_{"PO_Parser::entries", this->allocator_};

bool is_next_entry_fuzzy_ = false;
};
Expand Down
Loading

0 comments on commit 6036c62

Please sign in to comment.