diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 88e561c365..eb426ffa83 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -289,7 +289,6 @@ quick_lint_js_add_library( quick-lint-js/container/hash-map.h quick-lint-js/container/hash-set.h quick-lint-js/container/hash.h - quick-lint-js/container/heap-function.h quick-lint-js/container/linked-bump-allocator.h quick-lint-js/container/linked-vector.h quick-lint-js/container/optional.h diff --git a/src/quick-lint-js/container/heap-function.h b/src/quick-lint-js/container/heap-function.h deleted file mode 100644 index 9607451b50..0000000000 --- a/src/quick-lint-js/container/heap-function.h +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (C) 2020 Matthew "strager" Glazar -// See end of file for extended copyright information. - -#pragma once - -#include -#include - -namespace quick_lint_js { -template -class Heap_Function; - -// Heap_Function is like std::function but with a few differences: -// -// * Heap_Function compiles significantly faster than libc++'s std::function. -// * Heap_Function supports move-only targets. -// * Heap_Function does not have inline storage. It always heap-allocates. -// * Heap_Function does not support allocators. -// * Heap_Function does not support member function pointers and other -// craziness. -template -class Heap_Function { - public: - /*implicit*/ Heap_Function() = default; - - template >::type> - /*implicit*/ Heap_Function(Func&& func) - : callable_(new Dynamic_Callable(std::move(func))) {} - - Heap_Function(Heap_Function&& other) - : callable_(std::exchange(other.callable_, nullptr)) {} - - Heap_Function& operator=(Heap_Function&& other) { - if (this != &other) { - delete this->callable_; - this->callable_ = std::exchange(other.callable_, nullptr); - } - return *this; - } - - ~Heap_Function() { delete this->callable_; } - - explicit operator bool() const { return this->callable_ != nullptr; } - - Result operator()(Args... args) { - return this->callable_->call(std::forward(args)...); - } - - private: - struct Dynamic_Callable_Base { - virtual ~Dynamic_Callable_Base() = default; - - virtual Result call(Args... args) = 0; - }; - - template - struct Dynamic_Callable : Dynamic_Callable_Base { - explicit Dynamic_Callable(Func&& func) : func(std::move(func)) {} - - virtual ~Dynamic_Callable() override = default; - - Result call(Args... args) override { - return this->func(std::forward(args)...); - } - - Func func; - }; - - Dynamic_Callable_Base* callable_ = nullptr; -}; -} - -// quick-lint-js finds bugs in JavaScript programs. -// Copyright (C) 2020 Matthew "strager" Glazar -// -// This file is part of quick-lint-js. -// -// quick-lint-js is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// quick-lint-js is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with quick-lint-js. If not, see . diff --git a/src/quick-lint-js/lsp/lsp-workspace-configuration.cpp b/src/quick-lint-js/lsp/lsp-workspace-configuration.cpp index ec4aebbc81..9b606f71ae 100644 --- a/src/quick-lint-js/lsp/lsp-workspace-configuration.cpp +++ b/src/quick-lint-js/lsp/lsp-workspace-configuration.cpp @@ -6,7 +6,6 @@ #else #include -#include #include #include #include diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4f61ea838d..a07387674c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -107,7 +107,6 @@ quick_lint_js_add_executable( test-file.cpp test-fixed-vector.cpp test-function-ref.cpp - test-heap-function.cpp test-instance-tracker.cpp test-integer-decimal.cpp test-integer-hexadecimal.cpp diff --git a/test/quick-lint-js/fake-configuration-filesystem.cpp b/test/quick-lint-js/fake-configuration-filesystem.cpp index ff00323905..0a9afb7c79 100644 --- a/test/quick-lint-js/fake-configuration-filesystem.cpp +++ b/test/quick-lint-js/fake-configuration-filesystem.cpp @@ -7,7 +7,6 @@ #include #include -#include #include #include #include diff --git a/test/quick-lint-js/fake-configuration-filesystem.h b/test/quick-lint-js/fake-configuration-filesystem.h index 4781bf5487..77b124a6e7 100644 --- a/test/quick-lint-js/fake-configuration-filesystem.h +++ b/test/quick-lint-js/fake-configuration-filesystem.h @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/test/test-heap-function.cpp b/test/test-heap-function.cpp deleted file mode 100644 index 8da1831e35..0000000000 --- a/test/test-heap-function.cpp +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright (C) 2020 Matthew "strager" Glazar -// See end of file for extended copyright information. - -#include -#include -#include -#include - -QLJS_WARNING_IGNORE_CLANG("-Wunused-member-function") - -namespace quick_lint_js { -namespace { -// Copy_Spy keeps track of the number of instances. -struct Copy_Spy { - inline static int instance_count; - - Copy_Spy() { instance_count += 1; } - - Copy_Spy(const Copy_Spy&) { instance_count += 1; } - Copy_Spy& operator=(const Copy_Spy&) { return *this; } - - Copy_Spy(Copy_Spy&&) { instance_count += 1; } - Copy_Spy& operator=(Copy_Spy&&) { return *this; } - - ~Copy_Spy() { instance_count -= 1; } - - void operator()() {} -}; - -TEST(Test_Heap_Function, default_constructed_has_no_target) { - Heap_Function f; - EXPECT_FALSE(f); -} - -TEST(Test_Heap_Function, constructed_with_lambda_has_target) { - Heap_Function f = []() -> void {}; - EXPECT_TRUE(f); -} - -TEST(Test_Heap_Function, destructing_heap_function_calls_target_destructor) { - Copy_Spy::instance_count = 0; - { - Heap_Function f = Copy_Spy(); - EXPECT_EQ(Copy_Spy::instance_count, 1); - } - EXPECT_EQ(Copy_Spy::instance_count, 0); -} - -TEST(Test_Heap_Function, call_closureless_lambda) { - static bool called; - Heap_Function f = []() -> void { called = true; }; - called = false; - f(); - EXPECT_TRUE(called); -} - -TEST(Test_Heap_Function, call_lambda_with_closure) { - bool called = false; - Heap_Function f = [&called]() -> void { called = true; }; - ASSERT_FALSE(called); - f(); - EXPECT_TRUE(called); -} - -TEST(Test_Heap_Function, call_manual_functor_with_closure) { - struct Functor { - bool& called; - - void operator()() { called = true; } - }; - bool called = false; - Heap_Function f = Functor{called}; - ASSERT_FALSE(called); - f(); - EXPECT_TRUE(called); -} - -TEST(Test_Heap_Function, lambda_return_value) { - Heap_Function f = []() -> int { return 42; }; - int result = f(); - EXPECT_EQ(result, 42); -} - -TEST(Test_Heap_Function, single_parameter) { - static int got_x; - Heap_Function f = [](int x) -> void { got_x = x; }; - got_x = 0; - f(42); - EXPECT_EQ(got_x, 42); -} - -TEST(Test_Heap_Function, move_only_parameter) { - static int* got_o; - Heap_Function)> f = - [](std::unique_ptr o) -> void { got_o = o.get(); }; - got_o = nullptr; - - std::unique_ptr o = std::make_unique(42); - int* o_raw = o.get(); - f(std::move(o)); - - EXPECT_EQ(got_o, o_raw); -} - -TEST(Test_Heap_Function, assign_lambda_over_empty) { - static bool called; - called = false; - - Heap_Function f; - f = []() -> void { called = true; }; - - EXPECT_TRUE(f); - f(); - EXPECT_TRUE(called); -} - -TEST(Test_Heap_Function, assign_heap_function_over_empty) { - static bool called; - called = false; - - Heap_Function f; - f = Heap_Function([]() -> void { called = true; }); - - EXPECT_TRUE(f); - f(); - EXPECT_TRUE(called); -} - -TEST(Test_Heap_Function, assign_empty_over_empty) { - Heap_Function f; - f = Heap_Function(); - EXPECT_FALSE(f); -} - -TEST(Test_Heap_Function, assign_over_existing_destructs_existing) { - Copy_Spy::instance_count = 0; - Heap_Function f = Copy_Spy(); - EXPECT_EQ(Copy_Spy::instance_count, 1); - f = []() -> void {}; - EXPECT_EQ(Copy_Spy::instance_count, 0); -} - -TEST(Test_Heap_Function, assign_empty_over_lambda) { - Heap_Function f = []() -> void {}; - f = Heap_Function(); - EXPECT_FALSE(f); -} -} -} - -// quick-lint-js finds bugs in JavaScript programs. -// Copyright (C) 2020 Matthew "strager" Glazar -// -// This file is part of quick-lint-js. -// -// quick-lint-js is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// quick-lint-js is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with quick-lint-js. If not, see . diff --git a/test/test-lsp-server.cpp b/test/test-lsp-server.cpp index 36c373f580..07faee6e3c 100644 --- a/test/test-lsp-server.cpp +++ b/test/test-lsp-server.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include