From 004a630c69c8958af79d7181f764c6f37f259352 Mon Sep 17 00:00:00 2001 From: Ping Liu Date: Thu, 10 Sep 2026 15:50:50 +0800 Subject: [PATCH 01/14] restore the vendored iceberg::expected backport, updated to zeus-cpp/expected v1.4.0 Co-authored-by: Junwang Zhao --- .github/.licenserc.yaml | 1 + LICENSE | 28 + src/iceberg/expected.h | 2626 +++++++++++++++++++++++++++++ src/iceberg/test/CMakeLists.txt | 1 + src/iceberg/test/expected_test.cc | 636 +++++++ 5 files changed, 3292 insertions(+) create mode 100644 src/iceberg/expected.h create mode 100644 src/iceberg/test/expected_test.cc diff --git a/.github/.licenserc.yaml b/.github/.licenserc.yaml index a667c903e..dcfcd64f6 100644 --- a/.github/.licenserc.yaml +++ b/.github/.licenserc.yaml @@ -29,6 +29,7 @@ header: - 'LICENSE' - 'NOTICE' - 'requirements.txt' + - 'src/iceberg/expected.h' - 'src/iceberg/util/murmurhash3_internal.*' - 'src/iceberg/test/resources/**' - 'src/iceberg/catalog/hive/gen-cpp/**' diff --git a/LICENSE b/LICENSE index d0429e24b..6d0d88e91 100644 --- a/LICENSE +++ b/LICENSE @@ -230,6 +230,34 @@ License: https://www.apache.org/licenses/LICENSE-2.0 -------------------------------------------------------------------------------- +This product includes code from zeus-cpp/expected. + +* src/iceberg/expected.h is adapted from zeus-cpp/expected. + +Copyright: 2024 zeus-cpp. +Home page: https://github.com/zeus-cpp/expected +License: MIT + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +-------------------------------------------------------------------------------- + This product bundles utf8proc, which is available under the MIT License: utf8proc is a software package originally developed by Jan Behrens and the rest diff --git a/src/iceberg/expected.h b/src/iceberg/expected.h new file mode 100644 index 000000000..69c60f3a5 --- /dev/null +++ b/src/iceberg/expected.h @@ -0,0 +1,2626 @@ +/* + * MIT License + * + * Copyright (c) 2024 zeus-cpp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/// \file iceberg/expected.h +/// \brief A C++20 backport of C++23 `std::expected`, used as the storage type +/// behind `iceberg::Result`. +/// +/// Purpose: the library itself may be built as C++23, but its public headers +/// must stay consumable from C++20 translation units. `std::expected` is a +/// C++23 library feature, so `iceberg::Result` (see iceberg/result.h) is +/// defined in terms of `iceberg::expected` instead. The API mirrors +/// `std::expected` (including the monadic `and_then`, `or_else`, `transform` +/// and `transform_error`), so code can be written as if against the standard +/// type. +/// +/// Upstream: https://github.com/zeus-cpp/expected (MIT), +/// include/zeus/expected.hpp at tag v1.4.0 +/// (f9dde3b062f1b3a5d1a9f2888e4b6f6d2303557b). +/// +/// Local changes (search for "iceberg:" for the non-mechanical ones): +/// * Namespace `zeus` and its versioned inline ABI namespace replaced by plain +/// `iceberg`, so symbol names stay stable across upstream updates; macros +/// renamed from `ZEUS_EXPECTED_*` to `ICEBERG_EXPECTED_*`, and the upstream +/// version macros removed. +/// * Public classes annotated with `ICEBERG_EXPORT`, except the primary +/// `expected` template, which uses `ICEBERG_TEMPLATE_CLASS_EXPORT` (empty on +/// MSVC, where exporting a class template breaks the Windows build). +/// * `[[nodiscard]]` added to `unexpected` and `expected`. +/// * The default constructor no longer requires `T` to be default +/// constructible, so `expected` can hold types with no (or a private) +/// default constructor, which MSVC otherwise tried to instantiate. +/// * When `std::expected` is available, `iceberg::expected` can also be +/// constructed from `std::unexpected`, so library code compiled as C++23 +/// that still spells errors with `std::unexpected` keeps working. +/// * Reformatted with clang-format. +/// +/// History: +/// - apache/iceberg-cpp#40 first vendored zeus-cpp/expected (v1.2.0) while the +/// project targeted C++20. +/// - apache/iceberg-cpp#139 raised the project to C++23 and removed the header +/// in favor of `std::expected`, which made C++23 a requirement for users of +/// the public headers too. +/// - apache/iceberg-cpp#936 vendored it again, updated to v1.4.0, so the public +/// headers work in C++20 again. +/// +/// Once C++23 can be required of all consumers, this header can be dropped and +/// `iceberg::Result` aliased back to `std::expected`. + +#pragma once + +#include +#include +#include +#include +#include +#if defined(__cpp_lib_expected) && __cpp_lib_expected >= 202202L +# include +#endif + +#include "iceberg/iceberg_export.h" + +// NOLINTBEGIN + +#if defined(_MSVC_LANG) +# define ICEBERG_EXPECTED_CPLUSPLUS _MSVC_LANG +#else +# define ICEBERG_EXPECTED_CPLUSPLUS __cplusplus +#endif + +#if ICEBERG_EXPECTED_CPLUSPLUS < 201'703L +static_assert(false, "This expected variant requires C++17"); +#endif + +#if ICEBERG_EXPECTED_CPLUSPLUS >= 202'002L +# define ICEBERG_EXPECTED_CONSTEXPR_DTOR constexpr +#else +# define ICEBERG_EXPECTED_CONSTEXPR_DTOR +#endif + +// Detect exception support +#if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND) +# define ICEBERG_EXPECTED_THROW(e) (throw(e)) +#else +# define ICEBERG_EXPECTED_THROW(e) ((void)(e), std::terminate()) +#endif + +namespace iceberg { + +namespace expected_detail { + +template +constexpr T* construct_at(T* p, Args&&... args) noexcept( + noexcept(::new (static_cast(p)) T(std::forward(args)...))) { +#if ICEBERG_EXPECTED_CPLUSPLUS >= 202'002L + return std::construct_at(p, std::forward(args)...); +#else + return ::new (static_cast(p)) T(std::forward(args)...); +#endif +} + +template +struct remove_cvref { + using type = std::remove_cv_t>; +}; +template +using remove_cvref_t = typename remove_cvref::type; + +template class Template> +inline constexpr bool is_specialization_v = + false; // true if and only if T is a specialization of Template +template