Backed out 5 changesets (bug 1743020) for causing linux build bustages in function2.hpp CLOSED TREE

Backed out changeset cf237471cf75 (bug 1743020)
Backed out changeset 78eb51447ce5 (bug 1743020)
Backed out changeset c486f95d55ec (bug 1743020)
Backed out changeset c0abfda55404 (bug 1743020)
Backed out changeset 16be18ca73fb (bug 1743020)
This commit is contained in:
Molnar Sandor 2022-05-14 10:31:12 +03:00
Родитель 6e9d95d04a
Коммит 74e42d0f2f
23 изменённых файлов: 56 добавлений и 2549 удалений

Просмотреть файл

@ -8,9 +8,7 @@
void NoExplicitMoveConstructorChecker::registerMatchers( void NoExplicitMoveConstructorChecker::registerMatchers(
MatchFinder *AstMatcher) { MatchFinder *AstMatcher) {
AstMatcher->addMatcher( AstMatcher->addMatcher(
cxxConstructorDecl(isExplicitMoveConstructor(), isFirstParty()) cxxConstructorDecl(isExplicitMoveConstructor()).bind("node"), this);
.bind("node"),
this);
} }
void NoExplicitMoveConstructorChecker::check( void NoExplicitMoveConstructorChecker::check(

30
dom/cache/CacheWorkerRef.cpp поставляемый
Просмотреть файл

@ -12,6 +12,33 @@
namespace mozilla::dom::cache { namespace mozilla::dom::cache {
namespace {
// XXX Move this to mfbt, or do we already have something like this? Or remove
// the need for that by changing StrongWorkerRef/IPCWorkerRef?
template <class T>
class FakeCopyable {
public:
explicit FakeCopyable(T&& aTarget) : mTarget(std::forward<T>(aTarget)) {}
FakeCopyable(FakeCopyable&&) = default;
FakeCopyable(const FakeCopyable& aOther)
: mTarget(std::move(const_cast<FakeCopyable&>(aOther).mTarget)) {
MOZ_CRASH("Do not copy.");
}
template <typename... Args>
auto operator()(Args&&... aArgs) {
return mTarget(std::forward<Args>(aArgs)...);
}
private:
T mTarget;
};
} // namespace
// static // static
SafeRefPtr<CacheWorkerRef> CacheWorkerRef::Create(WorkerPrivate* aWorkerPrivate, SafeRefPtr<CacheWorkerRef> CacheWorkerRef::Create(WorkerPrivate* aWorkerPrivate,
Behavior aBehavior) { Behavior aBehavior) {
@ -21,7 +48,8 @@ SafeRefPtr<CacheWorkerRef> CacheWorkerRef::Create(WorkerPrivate* aWorkerPrivate,
// of CacheWorkerRef, since we can now use SafeRefPtrFromThis in the ctor // of CacheWorkerRef, since we can now use SafeRefPtrFromThis in the ctor
auto workerRef = auto workerRef =
MakeSafeRefPtr<CacheWorkerRef>(aBehavior, ConstructorGuard{}); MakeSafeRefPtr<CacheWorkerRef>(aBehavior, ConstructorGuard{});
auto notify = [workerRef = workerRef.clonePtr()] { workerRef->Notify(); }; auto notify =
FakeCopyable([workerRef = workerRef.clonePtr()] { workerRef->Notify(); });
if (aBehavior == eStrongWorkerRef) { if (aBehavior == eStrongWorkerRef) {
workerRef->mStrongWorkerRef = StrongWorkerRef::Create( workerRef->mStrongWorkerRef = StrongWorkerRef::Create(
aWorkerPrivate, "CacheWorkerRef-Strong", std::move(notify)); aWorkerPrivate, "CacheWorkerRef-Strong", std::move(notify));

Просмотреть файл

@ -91,7 +91,7 @@ void WorkerRef::Notify() {
return; return;
} }
MoveOnlyFunction<void()> callback = std::move(mCallback); std::function<void()> callback = std::move(mCallback);
MOZ_ASSERT(!mCallback); MOZ_ASSERT(!mCallback);
callback(); callback();
@ -102,7 +102,7 @@ void WorkerRef::Notify() {
/* static */ /* static */
already_AddRefed<WeakWorkerRef> WeakWorkerRef::Create( already_AddRefed<WeakWorkerRef> WeakWorkerRef::Create(
WorkerPrivate* aWorkerPrivate, MoveOnlyFunction<void()>&& aCallback) { WorkerPrivate* aWorkerPrivate, std::function<void()>&& aCallback) {
MOZ_ASSERT(aWorkerPrivate); MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread(); aWorkerPrivate->AssertIsOnWorkerThread();
@ -148,7 +148,7 @@ WorkerPrivate* WeakWorkerRef::GetUnsafePrivate() const {
/* static */ /* static */
already_AddRefed<StrongWorkerRef> StrongWorkerRef::Create( already_AddRefed<StrongWorkerRef> StrongWorkerRef::Create(
WorkerPrivate* const aWorkerPrivate, const char* const aName, WorkerPrivate* const aWorkerPrivate, const char* const aName,
MoveOnlyFunction<void()>&& aCallback) { std::function<void()>&& aCallback) {
if (RefPtr<StrongWorkerRef> ref = if (RefPtr<StrongWorkerRef> ref =
CreateImpl(aWorkerPrivate, aName, Canceling)) { CreateImpl(aWorkerPrivate, aName, Canceling)) {
ref->mCallback = std::move(aCallback); ref->mCallback = std::move(aCallback);
@ -218,7 +218,7 @@ WorkerPrivate* ThreadSafeWorkerRef::Private() const {
/* static */ /* static */
already_AddRefed<IPCWorkerRef> IPCWorkerRef::Create( already_AddRefed<IPCWorkerRef> IPCWorkerRef::Create(
WorkerPrivate* aWorkerPrivate, const char* aName, WorkerPrivate* aWorkerPrivate, const char* aName,
MoveOnlyFunction<void()>&& aCallback) { std::function<void()>&& aCallback) {
MOZ_ASSERT(aWorkerPrivate); MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread(); aWorkerPrivate->AssertIsOnWorkerThread();

Просмотреть файл

@ -7,8 +7,8 @@
#ifndef mozilla_dom_workers_WorkerRef_h #ifndef mozilla_dom_workers_WorkerRef_h
#define mozilla_dom_workers_WorkerRef_h #define mozilla_dom_workers_WorkerRef_h
#include <functional>
#include "mozilla/dom/WorkerStatus.h" #include "mozilla/dom/WorkerStatus.h"
#include "mozilla/MoveOnlyFunction.h"
#include "mozilla/RefPtr.h" #include "mozilla/RefPtr.h"
#include "nsISupports.h" #include "nsISupports.h"
@ -123,7 +123,7 @@ class WorkerRef {
WorkerPrivate* mWorkerPrivate; WorkerPrivate* mWorkerPrivate;
MoveOnlyFunction<void()> mCallback; std::function<void()> mCallback;
const char* const mName; const char* const mName;
const bool mIsPreventingShutdown; const bool mIsPreventingShutdown;
@ -135,7 +135,7 @@ class WeakWorkerRef final : public WorkerRef {
public: public:
static already_AddRefed<WeakWorkerRef> Create( static already_AddRefed<WeakWorkerRef> Create(
WorkerPrivate* aWorkerPrivate, WorkerPrivate* aWorkerPrivate,
MoveOnlyFunction<void()>&& aCallback = nullptr); std::function<void()>&& aCallback = nullptr);
WorkerPrivate* GetPrivate() const; WorkerPrivate* GetPrivate() const;
@ -154,7 +154,7 @@ class StrongWorkerRef final : public WorkerRef {
public: public:
static already_AddRefed<StrongWorkerRef> Create( static already_AddRefed<StrongWorkerRef> Create(
WorkerPrivate* aWorkerPrivate, const char* aName, WorkerPrivate* aWorkerPrivate, const char* aName,
MoveOnlyFunction<void()>&& aCallback = nullptr); std::function<void()>&& aCallback = nullptr);
// This function creates a StrongWorkerRef even when in the Canceling state of // This function creates a StrongWorkerRef even when in the Canceling state of
// the worker's lifecycle. It's intended to be used by system code, e.g. code // the worker's lifecycle. It's intended to be used by system code, e.g. code
@ -205,7 +205,7 @@ class IPCWorkerRef final : public WorkerRef {
public: public:
static already_AddRefed<IPCWorkerRef> Create( static already_AddRefed<IPCWorkerRef> Create(
WorkerPrivate* aWorkerPrivate, const char* aName, WorkerPrivate* aWorkerPrivate, const char* aName,
MoveOnlyFunction<void()>&& aCallback = nullptr); std::function<void()>&& aCallback = nullptr);
WorkerPrivate* Private() const; WorkerPrivate* Private() const;

Просмотреть файл

@ -10,7 +10,6 @@
#include "mozilla/CheckedInt.h" #include "mozilla/CheckedInt.h"
#include "mozilla/ErrorNames.h" #include "mozilla/ErrorNames.h"
#include "mozilla/Logging.h" #include "mozilla/Logging.h"
#include "mozilla/MoveOnlyFunction.h"
#include "mozilla/ipc/InputStreamParams.h" #include "mozilla/ipc/InputStreamParams.h"
#include "nsIAsyncInputStream.h" #include "nsIAsyncInputStream.h"
#include "nsStreamUtils.h" #include "nsStreamUtils.h"
@ -36,19 +35,33 @@ class SCOPED_CAPABILITY DataPipeAutoLock {
template <typename F> template <typename F>
void AddUnlockAction(F aAction) { void AddUnlockAction(F aAction) {
mActions.AppendElement(std::move(aAction)); mActions.AppendElement(MakeUnique<Action<F>>(std::move(aAction)));
} }
~DataPipeAutoLock() CAPABILITY_RELEASE() { ~DataPipeAutoLock() CAPABILITY_RELEASE() {
mMutex.Unlock(); mMutex.Unlock();
for (auto& action : mActions) { for (auto& action : mActions) {
action(); action->Run();
} }
} }
private: private:
// NOTE: This would be better served by something like llvm's
// `UniqueFunction`, but this works as well. We can't use `std::function`, as
// the actions may not be copy constructable.
struct IAction {
virtual void Run() = 0;
virtual ~IAction() = default;
};
template <typename F>
struct Action : IAction {
explicit Action(F&& aAction) : mAction(std::move(aAction)) {}
void Run() override { mAction(); }
F mAction;
};
Mutex& mMutex; Mutex& mMutex;
AutoTArray<MoveOnlyFunction<void()>, 4> mActions; AutoTArray<UniquePtr<IAction>, 4> mActions;
}; };
static void DoNotifyOnUnlock(DataPipeAutoLock& aLock, static void DoNotifyOnUnlock(DataPipeAutoLock& aLock,

Просмотреть файл

@ -176,7 +176,6 @@ rsync_filter_list = """
+ /.cargo/config.in + /.cargo/config.in
+ /third_party/function2/**
- /third_party/python/gyp - /third_party/python/gyp
+ /third_party/python/** + /third_party/python/**
+ /third_party/rust/** + /third_party/rust/**

Просмотреть файл

@ -1,43 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_MoveOnlyFunction_h
#define mozilla_MoveOnlyFunction_h
#include "function2/function2.hpp"
namespace mozilla {
/// A type like `std::function`, but with support for move-only callable
/// objects.
///
/// A similar type is proposed to be added to the standard library as
/// `std::move_only_function` in C++23.
///
/// Unlike `std::function`, the function signature may be given const or
/// reference qualifiers which will be applied to `operator()`. This can be used
/// to declare const qualified or move-only functions.
///
/// The implementation this definition depends on (function2) also has support
/// for callables with overload sets, however support for this was not exposed
/// to align better with the proposed `std::move_only_function`, which does not
/// support overload sets.
///
/// A custom typedef over `fu2::function_base` is used to control the size and
/// alignment of the inline storage to store 2 aligned pointers, and ensure the
/// type is compatible with `nsTArray`.
template <typename Signature>
using MoveOnlyFunction = fu2::function_base<
/* IsOwning */ true,
/* IsCopyable */ false,
/* Capacity */ fu2::capacity_fixed<2 * sizeof(void*), alignof(void*)>,
/* IsThrowing */ false,
/* HasStrongExceptionGuarantee */ false,
/* Signature */ Signature>;
} // namespace mozilla
#endif // mozilla_MoveOnlyFunction_h

Просмотреть файл

@ -71,7 +71,6 @@ EXPORTS.mozilla = [
"MaybeStorageBase.h", "MaybeStorageBase.h",
"MemoryChecking.h", "MemoryChecking.h",
"MemoryReporting.h", "MemoryReporting.h",
"MoveOnlyFunction.h",
"NonDereferenceable.h", "NonDereferenceable.h",
"NotNull.h", "NotNull.h",
"Opaque.h", "Opaque.h",
@ -134,10 +133,6 @@ EXPORTS["double-conversion"] = [
"double-conversion/double-conversion/utils.h", "double-conversion/double-conversion/utils.h",
] ]
EXPORTS.function2 += [
"/third_party/function2/include/function2/function2.hpp",
]
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
"/mfbt/double-conversion", "/mfbt/double-conversion",
] ]

1
python/mozbuild/mozbuild/vendor/moz_yaml.py поставляемый
Просмотреть файл

@ -37,7 +37,6 @@ VALID_LICENSES = [
"BSD-2-Clause", "BSD-2-Clause",
"BSD-3-Clause", "BSD-3-Clause",
"BSD-3-Clause-Clear", "BSD-3-Clause-Clear",
"BSL-1.0",
"CC0-1.0", "CC0-1.0",
"ISC", "ISC",
"ICU", "ICU",

9
third_party/function2/.clang-format поставляемый
Просмотреть файл

@ -1,9 +0,0 @@
BasedOnStyle: LLVM
PointerAlignment: Left
IndentCaseLabels: true
AllowShortFunctionsOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
FixNamespaceComments: true

11
third_party/function2/.editorconfig поставляемый
Просмотреть файл

@ -1,11 +0,0 @@
[*]
charset = utf-8
indent_size = 2
tab_width = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 80
[*.{cpp,hpp}]
charset = latin1

93
third_party/function2/.travis.yml поставляемый
Просмотреть файл

@ -1,93 +0,0 @@
sudo: true
dist: trusty
language: cpp
cache: apt
git:
depth: 1
matrix:
include:
- os: linux
compiler: gcc
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-5
- valgrind
- ninja-build
env:
- COMPILER=g++-5
- NO_EXCEPTIONS=OFF
- os: linux
compiler: gcc
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-6
- valgrind
- ninja-build
env:
- COMPILER=g++-6
- NO_EXCEPTIONS=OFF
- os: linux
compiler: gcc
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-6
- valgrind
- ninja-build
env:
- COMPILER=g++-6
- NO_EXCEPTIONS=ON
- os: linux
compiler: clang
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-5.0
packages:
- g++-6
- clang-5.0
- ninja-build
env:
- COMPILER=clang++-5.0
- NO_EXCEPTIONS=OFF
- os: linux
compiler: clang
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-5.0
packages:
- g++-6
- clang-5.0
- ninja-build
env:
- COMPILER=clang++-5.0
- NO_EXCEPTIONS=ON
install:
- export CXX=$COMPILER
- $CXX --version
- chmod +x tools/travis-ci.sh
script:
- ./tools/travis-ci.sh
notifications:
email: false

130
third_party/function2/CMakeLists.txt поставляемый
Просмотреть файл

@ -1,130 +0,0 @@
cmake_minimum_required(VERSION 3.11)
project(function2 VERSION 4.2.0 LANGUAGES CXX)
if (NOT FU2_IS_FIND_INCLUDED)
string(COMPARE EQUAL ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}
FU2_IS_TOP_LEVEL_PROJECT)
endif()
if (FU2_IS_TOP_LEVEL_PROJECT)
add_library(function2 INTERFACE)
else()
add_library(function2 INTERFACE IMPORTED GLOBAL)
endif()
add_library(function2::function2 ALIAS function2)
target_include_directories(function2
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_features(function2
INTERFACE
cxx_alias_templates
cxx_auto_type
cxx_constexpr
cxx_decltype
cxx_decltype_auto
cxx_final
cxx_lambdas
cxx_lambda_init_captures
cxx_generic_lambdas
cxx_variadic_templates
cxx_defaulted_functions
cxx_nullptr
cxx_trailing_return_types
cxx_return_type_deduction)
if (FU2_IS_TOP_LEVEL_PROJECT)
include(ExternalProject)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
# Create an install target:
# Headers and license files
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/function2"
DESTINATION "include")
install(FILES "LICENSE.txt" DESTINATION .)
install(FILES "Readme.md" DESTINATION .)
# Config.cmake
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
# ConfigVersion.cmake
configure_package_config_file("cmake/config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
# PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
# Targets.cmake
export(TARGETS ${PROJECT_NAME}
NAMESPACE ${PROJECT_NAME}::
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
install(TARGETS ${PROJECT_NAME}
EXPORT "${PROJECT_NAME}Targets"
INCLUDES DESTINATION "include")
install(EXPORT "${PROJECT_NAME}Targets"
NAMESPACE ${PROJECT_NAME}::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
# Setup CPack for bundling
set(CPACK_GENERATOR "ZIP")
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
# Since the header only library is platform independent
# we name the packages after the native line feed
if(WIN32)
set(CPACK_SYSTEM_NAME "crlf")
else()
set(CPACK_SYSTEM_NAME "lf")
endif()
include(CPack)
if (MSVC)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-")
endif()
include(cmake/CMakeLists.txt)
include(CTest)
option(FU2_WITH_NO_EXCEPTIONS
"Test without exceptions"
OFF)
option(FU2_WITH_NO_DEATH_TESTS
"Test without death tests"
OFF)
option(FU2_WITH_CPP_LATEST
"Enable the highest C++ standard available for testing polyfills"
OFF)
if (BUILD_TESTING)
if (FU2_WITH_NO_EXCEPTIONS)
message(STATUS "Testing with exceptions disabled")
add_definitions(-DTESTS_NO_EXCEPTIONS)
endif()
if (FU2_WITH_NO_DEATH_TESTS)
message(STATUS "Testing without death tests")
add_definitions(-DTESTS_NO_DEATH_TESTS)
endif()
add_subdirectory(test)
endif()
endif ()

10
third_party/function2/Findfunction2.cmake поставляемый
Просмотреть файл

@ -1,10 +0,0 @@
# Makes it possible to find function2 through find_package(function2 REQUIRED)
# when this source directory was added to the CMake module path.
# For instance it could be done through adding this to the CMakeLists.txt
# file in the parent directory:
# ```cmake
# list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/function2")
# ```
set(FU2_IS_FIND_INCLUDED ON)
include("${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt")

23
third_party/function2/LICENSE.txt поставляемый
Просмотреть файл

@ -1,23 +0,0 @@
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

260
third_party/function2/Readme.md поставляемый
Просмотреть файл

@ -1,260 +0,0 @@
# fu2::function an improved drop-in replacement to std::function
![](https://img.shields.io/badge/Version-4.0.0-0091EA.svg) ![](https://img.shields.io/badge/License-Boost-blue.svg) [![Build Status](https://travis-ci.org/Naios/function2.svg?branch=master)](https://travis-ci.org/Naios/function2) [![Build status](https://ci.appveyor.com/api/projects/status/1tl0vqpg8ndccats/branch/master?svg=true)](https://ci.appveyor.com/project/Naios/function2/branch/master)
Provides improved implementations of `std::function`:
- **copyable** `fu2::function`
- **move-only** `fu2::unique_function` (capable of holding move only types)
- **non-owning** `fu2::function_view` (capable of referencing callables in a non owning way)
that provide many benefits and improvements over `std::function`:
- [x] **const**, **volatile**, **reference** and **noexcept** correct (qualifiers are part of the `operator()` signature)
- [x] **convertible** to and from `std::function` as well as other callable types
- [x] **adaptable** through `fu2::function_base` (internal capacity, copyable and exception guarantees)
- [x] **overloadable** with an arbitrary count of signatures (`fu2::function<bool(int), bool(float)>`)
- [x] **full allocator support** in contrast to `std::function`, which doesn't provide support anymore
- [x] **covered** by many unit tests and continuous integration services (*GCC*, *Clang* and *MSVC*)
- [x] **header only**, just copy and include `function.hpp` in your project
- [x] **permissively licensed** under the **boost** license
## Table of Contents
* **[Documentation](#documentation)**
* **[How to use](#how-to-use)**
* **[Constructing a function](#constructing-a-function)**
* **[Non copyable unique functions](#non-copyable-unique-functions)**
* **[Convertibility of functions](#convertibility-of-functions)**
* **[Adapt function2](#adapt-function2)**
* **[Performance and optimization](#performance-and-optimization)**
* **[Small functor optimization](#small-functor-optimization)**
* **[Compiler optimization](#compiler-optimization)**
* **[std::function vs fu2::function](#stdfunction-vs-fu2function)**
* **[Coverage and runtime checks](#coverage-and-runtime-checks)**
* **[Compatibility](#compatibility)**
* **[License](#licence)**
* **[Similar implementations](#similar-implementations)**
## Documentation
### How to use
**function2** is implemented in one header (`function.hpp`), no compilation is required.
Just copy the `function.hpp` header in your project and include it to start.
It's recommended to import the library as git submodule using CMake:
```sh
# Shell:
git submodule add https://github.com/Naios/function2.git
```
```cmake
# CMake file:
add_subdirectory(function2)
# function2 provides an interface target which makes it's
# headers available to all projects using function2
target_link_libraries(my_project function2)
```
Use `fu2::function` as a wrapper for copyable function wrappers and `fu2::unique_function` for move only types.
The standard implementation `std::function` and `fu2::function` are convertible to each other, see [the chapter convertibility of functions](#convertibility-of-functions) for details.
A function wrapper is declared as following:
```c++
fu2::function<void(int, float) const>
// Return type ~^ ^ ^ ^
// Parameters ~~~~~|~~~~~| ^
// Qualifier ~~~~~~~~~~~~~~~~~~~|
```
* **Return type**: The return type of the function to wrap.
* **Arguments**: The argument types of the function to wrap.
Any argument types are allowed.
* **Qualifiers**: There are several qualifiers allowed:
- **no qualifier** provides `ReturnType operator() (Args...)`
- Can be assigned from const and no const objects (*mutable lambdas* for example).
- **const** provides `ReturnType operator() (Args...) const`
- Requires that the assigned functor is const callable (won't work with *mutable lambdas*),
- **volatile** provides `ReturnType operator() (Args...) volatile`
- Can only be assigned from volatile qualified functors.
- **const volatile** provides `ReturnType operator() (Args...) const volatile`
- Same as const and volatile together.
- **r-value (one-shot) functions** `ReturnType operator() (Args...) &&`
- one-shot functions which are invalidated after the first call (can be mixed with `const`, `volatile` and `noexcept`). Can only wrap callable objects which call operator is also qualified as `&&` (r-value callable). Normal (*C*) functions are considered to be r-value callable by default.
- **noexcept functions** `ReturnType operator() (Args...) noexcept`
- such functions are guaranteed not to throw an exception (can be mixed with `const`, `volatile` and `&&`). Can only wrap functions or callable objects which call operator is also qualified as `noexcept`. Requires enabled C++17 compilation to work (support is detected automatically). Empty function calls to such a wrapped function will lead to a call to `std::abort` regardless the wrapper is configured to support exceptions or not (see [adapt function2](#adapt-function2)).
* **Multiple overloads**: The library is capable of providing multiple overloads:
```cpp
fu2::function<int(std::vector<int> const&),
int(std::set<int> const&) const> fn = [] (auto const& container) {
return container.size());
};
```
### Constructing a function
`fu2::function` and `fu2::unique_function` (non copyable) are easy to use:
```c++
fu2::function<void() const> fun = [] {
// ...
};
// fun provides void operator()() const now
fun();
```
### Non copyable unique functions
`fu2::unique_function` also works with non copyable functors/ lambdas.
```c++
fu2::unique_function<bool() const> fun = [ptr = std::make_unique<bool>(true)] {
return *ptr;
};
// unique functions are move only
fu2::unique_function<bool() const> otherfun = std::move(fun):
otherfun();
```
### Non owning functions
A `fu2::function_view` can be used to create a non owning view on a persistent object. Note that the view is only valid as long as the object lives.
```c++
auto callable = [ptr = std::make_unique<bool>(true)] {
return *ptr;
};
fu2::function_view<bool() const> view(callable);
```
### Convertibility of functions
`fu2::function`, `fu2::unique_function` and `std::function` are convertible to each other when:
- The return type and parameter type match.
- The functions are both volatile or not.
- The functions are const correct:
- `noconst = const`
- `const = const`
- `noconst = noconst`
- The functions are copyable correct when:
- `unique = unique`
- `unique = copyable`
- `copyable = copyable`
- The functions are reference correct when:
- `lvalue = lvalue`
- `lvalue = rvalue`
- `rvalue = rvalue`
- The functions are `noexcept` correct when:
- `callable = callable`
- `callable = noexcept callable `
- `noexcept callable = noexcept callable`
| Convertibility from \ to | fu2::function | fu2::unique_function | std::function |
| ------------------------ | ------------- | -------------------- | ------------- |
| fu2::function | Yes | Yes | Yes |
| fu2::unique_function | No | Yes | No |
| std::function | Yes | Yes | Yes |
```c++
fu2::function<void()> fun = []{};
// OK
std::function<void()> std_fun = fun;
// OK
fu2::unique_function<void()> un_fun = fun;
// Error (non copyable -> copyable)
fun = un_fun;
// Error (non copyable -> copyable)
fun = un_fun;
```
### Adapt function2
function2 is adaptable through `fu2::function_base` which allows you to set:
- **IsOwning**: defines whether the function owns its contained object
- **Copyable:** defines if the function is copyable or not.
- **Capacity:** defines the internal capacity used for [sfo optimization](#small-functor-optimization):
```cpp
struct my_capacity {
static constexpr std::size_t capacity = sizeof(my_type);
static constexpr std::size_t alignment = alignof(my_type);
};
```
- **IsThrowing** defines if empty function calls throw an `fu2::bad_function_call` exception, otherwise `std::abort` is called.
- **HasStrongExceptGuarantee** defines whether the strong exception guarantees shall be met.
- **Signatures:** defines the signatures of the function.
The following code defines an owning function with a variadic signature which is copyable and sfo optimization is disabled:
```c++
template<typename Signature>
using my_function = fu2::function_base<true, true, fu2::capacity_none, true, false, Signature>;
```
The following code defines a non copyable function which just takes 1 argument, and has a huge capacity for internal sfo optimization. Also it must be called as r-value.
```c++
template<typename Arg>
using my_consumer = fu2::function_base<true, false, fu2::capacity_fixed<100U>,
true, false, void(Arg)&&>;
// Example
my_consumer<int, float> consumer = [](int, float) { }
std::move(consumer)(44, 1.7363f);
```
## Performance and optimization
### Small functor optimization
function2 uses small functor optimization like the most common `std::function` implementations which means it allocates a small internal capacity to evade heap allocation for small functors.
Smart heap allocation moves the inplace allocated functor automatically to the heap to speed up moving between objects.
It's possible to disable small functor optimization through setting the internal capacity to 0.
## Coverage and runtime checks
Function2 is checked with unit tests and valgrind (for memory leaks), where the unit tests provide coverage for all possible template parameter assignments.
## Compatibility
Tested with:
- Visual Studio 2017+ Update 3
- Clang 3.8+
- GCC 5.4+
Every compiler with modern C++14 support should work.
*function2* only depends on the standard library.
## License
*function2* is licensed under the very permissive Boost 1.0 License.
## Similar implementations
There are similar implementations of a function wrapper:
- [pmed/fixed_size_function](https://github.com/pmed/fixed_size_function)
- stdex::function - A multi-signature function implementation.
- multifunction - Example from [Boost.TypeErasure](http://www.boost.org/doc/html/boost_typeerasure/examples.html#boost_typeerasure.examples.multifunction), another multi-signature function.
- std::function - [Standard](http://en.cppreference.com/w/cpp/utility/functional/function).
- boost::function - The one from [Boost](http://www.boost.org/doc/libs/1_55_0/doc/html/function.html).
- func::function - From this [blog](http://probablydance.com/2013/01/13/a-faster-implementation-of-stdfunction/).
- generic::delegate - [Fast delegate in C++11](http://codereview.stackexchange.com/questions/14730/impossibly-fast-delegate-in-c11), also see [here](https://code.google.com/p/cpppractice/source/browse/trunk/).
- ssvu::FastFunc - Another Don Clugston's FastDelegate, as shown [here](https://groups.google.com/a/isocpp.org/forum/#!topic/std-discussion/QgvHF7YMi3o).
- [cxx_function::function](https://github.com/potswa/cxx_function) - By David Krauss
Also check out the amazing [**CxxFunctionBenchmark**](https://github.com/jamboree/CxxFunctionBenchmark) which compares several implementations.

44
third_party/function2/appveyor.yml поставляемый
Просмотреть файл

@ -1,44 +0,0 @@
image:
- Visual Studio 2017
- Visual Studio 2019
environment:
matrix:
- FU2_WITH_NO_EXCEPTIONS: OFF
FU2_WITH_CPP_LATEST: OFF
- FU2_WITH_NO_EXCEPTIONS: ON
FU2_WITH_CPP_LATEST: OFF
- FU2_WITH_NO_EXCEPTIONS: OFF
FU2_WITH_CPP_LATEST: ON
- FU2_WITH_NO_EXCEPTIONS: ON
FU2_WITH_CPP_LATEST: ON
platform:
- x64
clone_script:
- cmd: git clone -q --branch=%APPVEYOR_REPO_BRANCH% https://github.com/%APPVEYOR_REPO_NAME%.git %APPVEYOR_BUILD_FOLDER%
- cmd: cd %APPVEYOR_BUILD_FOLDER%
- cmd: git checkout -qf %APPVEYOR_REPO_COMMIT%
- cmd: git submodule update --init --recursive
before_build:
- cmd: >
cmake -H. -Bbuild -A%PLATFORM%
-DFU2_WITH_NO_EXCEPTIONS=%FU2_WITH_NO_EXCEPTIONS%
-DFU2_WITH_CPP_LATEST=%FU2_WITH_CPP_LATEST%
build_script:
- cmd: >
cmake --build build --config Debug --target ALL_BUILD
-- /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
/verbosity:minimal /maxcpucount:2 /nologo
- cmd: >
cmake --build build --config Release --target ALL_BUILD
-- /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
/verbosity:minimal /maxcpucount:2 /nologo
test_script:
- cmd: cd build
- cmd: ctest -C Debug -V .
- cmd: ctest -C Release -V .

33
third_party/function2/conanfile.py поставляемый
Просмотреть файл

@ -1,33 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from conans import ConanFile, tools
def get_version():
git = tools.Git()
try:
return git.run("describe --tags --abbrev=0")
except:
return None
class Function2Conan(ConanFile):
name = "function2"
version = get_version()
license = "boost"
url = "https://github.com/Naios/function2"
author = "Denis Blank (denis.blank@outlook.com)"
description = "Improved and configurable drop-in replacement to std::function"
homepage = "http://naios.github.io/function2"
no_copy_source = True
scm = {
"type": "git",
"url": "auto",
"revision": "auto"
}
def package(self):
self.copy("LICENSE.txt", "licenses")
self.copy("include/function2/function2.hpp")
def package_id(self):
self.info.header_only()

Разница между файлами не показана из-за своего большого размера Загрузить разницу

38
third_party/function2/moz.yaml поставляемый
Просмотреть файл

@ -1,38 +0,0 @@
schema: 1
bugzilla:
product: Core
component: MFBT
origin:
name: function2
description: Improved and configurable drop-in replacement to std::function
url: https://naios.github.io/function2/
release: 02ca99831de59c7c3a4b834789260253cace0ced (2021-06-16T17:21:46Z).
revision: 02ca99831de59c7c3a4b834789260253cace0ced
license: BSL-1.0
license-file: LICENSE.txt
updatebot:
maintainer-phab: nika
maintainer-bz: nika@thelayzells.com
tasks:
- type: vendoring
branch: master
enabled: True
frequency: every
vendoring:
url: https://github.com/Naios/function2
source-hosting: github
tracking: commit
exclude:
- .github/
- cmake/
- test/
- tools/

3
third_party/moz.build поставляемый
Просмотреть файл

@ -13,9 +13,6 @@ with Files('cups/**'):
with Files('dav1d/**'): with Files('dav1d/**'):
BUG_COMPONENT = ('Core', 'Audio/Video: Playback') BUG_COMPONENT = ('Core', 'Audio/Video: Playback')
with Files('function2/**'):
BUG_COMPONENT = ('Core', 'MFBT')
with Files('googletest/**'): with Files('googletest/**'):
BUG_COMPONENT = ('Testing', 'GTest') BUG_COMPONENT = ('Testing', 'GTest')

Просмотреть файл

@ -72,7 +72,6 @@
<li><a href="about:license#babel">Babel License</a></li> <li><a href="about:license#babel">Babel License</a></li>
<li><a href="about:license#babylon">Babylon License</a></li> <li><a href="about:license#babylon">Babylon License</a></li>
<li><a href="about:license#bincode">bincode License</a></li> <li><a href="about:license#bincode">bincode License</a></li>
<li><a href="about:license#boost">boost License</a></li>
<li><a href="about:license#bsd2clause">BSD 2-Clause License</a></li> <li><a href="about:license#bsd2clause">BSD 2-Clause License</a></li>
<li><a href="about:license#bsd3clause">BSD 3-Clause License</a></li> <li><a href="about:license#bsd3clause">BSD 3-Clause License</a></li>
<li><a href="about:license#bspatch">bspatch License</a></li> <li><a href="about:license#bspatch">bspatch License</a></li>
@ -2149,40 +2148,6 @@ SOFTWARE.
</pre> </pre>
<hr>
<h1><a id="boost"></a>boost License</h1>
<p>This license applies to files in the directory
<code>third_party/function2</code>.</p>
<pre>
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</pre>
<hr> <hr>
<h1><a id="bsd2clause"></a>BSD 2-Clause License</h1> <h1><a id="bsd2clause"></a>BSD 2-Clause License</h1>

Просмотреть файл

@ -54,7 +54,6 @@ dom/webauthn/tests/pkijs/
editor/libeditor/tests/browserscope/lib/richtext/ editor/libeditor/tests/browserscope/lib/richtext/
editor/libeditor/tests/browserscope/lib/richtext2/ editor/libeditor/tests/browserscope/lib/richtext2/
extensions/spellcheck/hunspell/src/ extensions/spellcheck/hunspell/src/
function2/
gfx/angle/checkout/ gfx/angle/checkout/
gfx/cairo/ gfx/cairo/
gfx/graphite2/ gfx/graphite2/