Unable to compile with fmt 10.0.0
FtZPetruska opened this issue · comments
Describe the bug
Using fmt 10.0.0, building fails with the error:
FAILED: navy/CMakeFiles/cachelib_navy.dir/admission_policy/DynamicRandomAP.cpp.o
/usr/bin/c++ -DGFLAGS_IS_A_DLL=0 -DSODIUM_STATIC -I/mnt/vcpkg-ci/buildtrees/cachelib/src/3.02.27.00-fc5b057a08.clean/cachelib/.. -I/mnt/vcpkg-ci/buildtrees/cachelib/x64-linux-dbg/.. -I/mnt/vcpkg-ci/buildtrees/cachelib/x64-linux-dbg -isystem /mnt/vcpkg-ci/installed/x64-linux/include -fPIC -g -fPIC -pthread -std=gnu++17 -MD -MT navy/CMakeFiles/cachelib_navy.dir/admission_policy/DynamicRandomAP.cpp.o -MF navy/CMakeFiles/cachelib_navy.dir/admission_policy/DynamicRandomAP.cpp.o.d -o navy/CMakeFiles/cachelib_navy.dir/admission_policy/DynamicRandomAP.cpp.o -c /mnt/vcpkg-ci/buildtrees/cachelib/src/3.02.27.00-fc5b057a08.clean/cachelib/navy/admission_policy/DynamicRandomAP.cpp
In file included from /mnt/vcpkg-ci/installed/x64-linux/include/fmt/format.h:49,
from /mnt/vcpkg-ci/installed/x64-linux/include/folly/FBString.h:34,
from /mnt/vcpkg-ci/installed/x64-linux/include/folly/Demangle.h:19,
from /mnt/vcpkg-ci/installed/x64-linux/include/folly/Conv.h:123,
from /mnt/vcpkg-ci/installed/x64-linux/include/folly/Exception.h:25,
from /mnt/vcpkg-ci/installed/x64-linux/include/folly/detail/ThreadLocalDetail.h:30,
from /mnt/vcpkg-ci/installed/x64-linux/include/folly/ThreadLocal.h:52,
from /mnt/vcpkg-ci/buildtrees/cachelib/src/3.02.27.00-fc5b057a08.clean/cachelib/../cachelib/common/FastStats.h:21,
from /mnt/vcpkg-ci/buildtrees/cachelib/src/3.02.27.00-fc5b057a08.clean/cachelib/../cachelib/common/AtomicCounter.h:22,
from /mnt/vcpkg-ci/buildtrees/cachelib/src/3.02.27.00-fc5b057a08.clean/cachelib/../cachelib/navy/admission_policy/DynamicRandomAP.h:25,
from /mnt/vcpkg-ci/buildtrees/cachelib/src/3.02.27.00-fc5b057a08.clean/cachelib/navy/admission_policy/DynamicRandomAP.cpp:17:
/mnt/vcpkg-ci/installed/x64-linux/include/fmt/core.h: In instantiation of ‘constexpr fmt::v10::detail::value<Context> fmt::v10::detail::make_value(T&&) [with Context = fmt::v10::basic_format_context<fmt::v10::appender, char>; T = const std::atomic<long unsigned int>&]’:
/mnt/vcpkg-ci/installed/x64-linux/include/fmt/core.h:1711:29: required from ‘constexpr fmt::v10::detail::value<Context> fmt::v10::detail::make_arg(T&&) [with bool IS_PACKED = true; Context = fmt::v10::basic_format_context<fmt::v10::appender, char>; fmt::v10::detail::type <anonymous> = fmt::v10::detail::type::custom_type; T = const std::atomic<long unsigned int>&; typename std::enable_if<IS_PACKED, int>::type <anonymous> = 0]’
/mnt/vcpkg-ci/installed/x64-linux/include/fmt/core.h:1827:77: required from ‘constexpr fmt::v10::format_arg_store<Context, Args>::format_arg_store(T&& ...) [with T = {const std::atomic<long unsigned int>&, const long unsigned int&}; Context = fmt::v10::basic_format_context<fmt::v10::appender, char>; Args = {std::atomic<long unsigned int>, long unsigned int}]’
/mnt/vcpkg-ci/installed/x64-linux/include/fmt/core.h:1844:31: required from ‘constexpr fmt::v10::format_arg_store<Context, fmt::v10::remove_cvref_t<T>...> fmt::v10::make_format_args(T&& ...) [with Context = fmt::v10::basic_format_context<fmt::v10::appender, char>; T = {const std::atomic<long unsigned int>&, const long unsigned int&}]’
/mnt/vcpkg-ci/installed/x64-linux/include/folly/logging/LogStreamProcessor.h:371:52: required from ‘std::string folly::LogStreamProcessor::formatLogString(folly::StringPiece, const Args& ...) [with Args = {std::atomic<long unsigned int>, long unsigned int}; std::string = std::__cxx11::basic_string<char>; folly::StringPiece = folly::Range<const char*>]’
/mnt/vcpkg-ci/installed/x64-linux/include/folly/logging/LogStreamProcessor.h:255:62: required from ‘folly::LogStreamProcessor::LogStreamProcessor(folly::XlogFileScopeInfo*, folly::LogLevel, folly::StringPiece, bool, folly::StringPiece, unsigned int, folly::StringPiece, folly::LogStreamProcessor::FormatType, folly::StringPiece, Args&& ...) [with Args = {std::atomic<long unsigned int>&, long unsigned int&}; folly::StringPiece = folly::Range<const char*>]’
/mnt/vcpkg-ci/buildtrees/cachelib/src/3.02.27.00-fc5b057a08.clean/cachelib/navy/admission_policy/DynamicRandomAP.cpp:189:5: required from here
/mnt/vcpkg-ci/installed/x64-linux/include/fmt/core.h:1691:7: error: static assertion failed: Cannot format an argument. To make type T formattable provide a formatter<T> specialization: https://fmt.dev/latest/api.html#udt
1691 | formattable,
| ^~~~~~~~~~~
This is most likely due with the following breaking change in fmt:
Removed deprecated implicit conversions for enums and conversions to primitive types for compatibility with std::format and to prevent potential ODR violations. Use format_as instead.
From what I'm gathering, the following call is what breaks due to maxRate_ (std::atomic<uint64_t>
) no longer implicitly being converted to its underlying type:
XLOGF(INFO,
"max write rate {} will be used because target current write rate {} "
"exceeds it.",
maxRate_, curTargetRate);
To Reproduce
Steps to reproduce the behavior:
- Install fmt 10.0.0
- Build CacheLib (main or tagged release)
Expected behavior
Build succeeds.
Screenshots
N/A
Desktop (please complete the following information):
- OS: Linux
- Browser: N/A
- Version: N/A
Smartphone (please complete the following information):
N/A
Additional context
See:
I found two possible fixes:
- Using an explicit load:
XLOGF(INFO, "max write rate {} will be used because target current write rate {} " "exceeds it.", maxRate_.load(std::memory_order_relaxed), curTargetRate);
- Casting to the underlying type:
XLOGF(INFO, "max write rate {} will be used because target current write rate {} " "exceeds it.", static_cast<uint64_t>(maxRate_), curTargetRate);
The following patch was able to fix compilation for the vcpkg port of cachelib:
diff --git a/cachelib/cachebench/cache/ItemRecords.h b/cachelib/cachebench/cache/ItemRecords.h
index 80fe7489..e581d78e 100644
--- a/cachelib/cachebench/cache/ItemRecords.h
+++ b/cachelib/cachebench/cache/ItemRecords.h
@@ -102,11 +102,11 @@ class ItemRecords {
}
if (record.destructCount != 0) {
XLOGF(ERR, "unexpected destructCount {} for item {}, context {}|{}",
- record.destructCount, item.getKey(), data.context, record.context);
+ record.destructCount, item.getKey().data(), data.context, record.context);
}
if (record.version != ptr->getVersion()) {
XLOGF(ERR, "unexpected version {}|{} for item {}", record.version,
- ptr->getVersion(), item.getKey());
+ ptr->getVersion(), item.getKey().data());
}
++record.destructCount;
diff --git a/cachelib/cachebench/runner/FastShutdown.cpp b/cachelib/cachebench/runner/FastShutdown.cpp
index 82c878eb..5ceb342d 100644
--- a/cachelib/cachebench/runner/FastShutdown.cpp
+++ b/cachelib/cachebench/runner/FastShutdown.cpp
@@ -27,7 +27,7 @@ namespace cachebench {
FastShutdownStressor::FastShutdownStressor(const CacheConfig& cacheConfig,
uint64_t numOps)
: numOps_(numOps),
- cacheDir_{folly::sformat("/tmp/cache_bench_fss_{}", getpid())},
+ cacheDir_{folly::sformat("/tmp/cache_bench_fss_{}", std::to_string(getpid()))},
cache_(std::make_unique<Cache<LruAllocator>>(
cacheConfig, nullptr, cacheDir_)) {}
diff --git a/cachelib/navy/admission_policy/DynamicRandomAP.cpp b/cachelib/navy/admission_policy/DynamicRandomAP.cpp
index 3a8a1aa0..2ab0fa45 100644
--- a/cachelib/navy/admission_policy/DynamicRandomAP.cpp
+++ b/cachelib/navy/admission_policy/DynamicRandomAP.cpp
@@ -189,7 +189,7 @@ void DynamicRandomAP::updateThrottleParamsLocked(std::chrono::seconds curTime) {
XLOGF(INFO,
"max write rate {} will be used because target current write rate {} "
"exceeds it.",
- maxRate_, curTargetRate);
+ maxRate_.load(std::memory_order_relaxed), curTargetRate);
curTargetRate = maxRate_;
}
writeStats_.curTargetRate = curTargetRate;