summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2023-03-05 12:25:57 +0100
committerJoel Rosdahl <joel@rosdahl.net>2023-03-05 21:42:16 +0100
commit03023ee78c0a34aab305ff61b2851248eb77c673 (patch)
treeac4e5637d639bc8d9abd484e038c816540c3680f
parentaff0f0f4ce70394d8aa3e3ce0b6521e41a4befcc (diff)
downloadccache-03023ee78c0a34aab305ff61b2851248eb77c673.tar.gz
refactor: Use util::BitSet for core::Sloppiness
-rw-r--r--src/Config.cpp52
-rw-r--r--src/argprocessing.cpp12
-rw-r--r--src/ccache.cpp14
-rw-r--r--src/core/Manifest.cpp6
-rw-r--r--src/core/Sloppiness.hpp48
-rw-r--r--src/hashutil.cpp6
6 files changed, 49 insertions, 89 deletions
diff --git a/src/Config.cpp b/src/Config.cpp
index 840925ca..f0525add 100644
--- a/src/Config.cpp
+++ b/src/Config.cpp
@@ -282,31 +282,31 @@ parse_sloppiness(const std::string& value)
for (const auto token : util::Tokenizer(value, ", ")) {
if (token == "clang_index_store") {
- result.enable(core::Sloppy::clang_index_store);
+ result.insert(core::Sloppy::clang_index_store);
} else if (token == "file_stat_matches") {
- result.enable(core::Sloppy::file_stat_matches);
+ result.insert(core::Sloppy::file_stat_matches);
} else if (token == "file_stat_matches_ctime") {
- result.enable(core::Sloppy::file_stat_matches_ctime);
+ result.insert(core::Sloppy::file_stat_matches_ctime);
} else if (token == "gcno_cwd") {
- result.enable(core::Sloppy::gcno_cwd);
+ result.insert(core::Sloppy::gcno_cwd);
} else if (token == "include_file_ctime") {
- result.enable(core::Sloppy::include_file_ctime);
+ result.insert(core::Sloppy::include_file_ctime);
} else if (token == "include_file_mtime") {
- result.enable(core::Sloppy::include_file_mtime);
+ result.insert(core::Sloppy::include_file_mtime);
} else if (token == "ivfsoverlay") {
- result.enable(core::Sloppy::ivfsoverlay);
+ result.insert(core::Sloppy::ivfsoverlay);
} else if (token == "locale") {
- result.enable(core::Sloppy::locale);
+ result.insert(core::Sloppy::locale);
} else if (token == "modules") {
- result.enable(core::Sloppy::modules);
+ result.insert(core::Sloppy::modules);
} else if (token == "pch_defines") {
- result.enable(core::Sloppy::pch_defines);
+ result.insert(core::Sloppy::pch_defines);
} else if (token == "random_seed") {
- result.enable(core::Sloppy::random_seed);
+ result.insert(core::Sloppy::random_seed);
} else if (token == "system_headers" || token == "no_system_headers") {
- result.enable(core::Sloppy::system_headers);
+ result.insert(core::Sloppy::system_headers);
} else if (token == "time_macros") {
- result.enable(core::Sloppy::time_macros);
+ result.insert(core::Sloppy::time_macros);
} // else: ignore unknown value for forward compatibility
}
@@ -317,43 +317,43 @@ std::string
format_sloppiness(core::Sloppiness sloppiness)
{
std::string result;
- if (sloppiness.is_enabled(core::Sloppy::clang_index_store)) {
+ if (sloppiness.contains(core::Sloppy::clang_index_store)) {
result += "clang_index_store, ";
}
- if (sloppiness.is_enabled(core::Sloppy::file_stat_matches)) {
+ if (sloppiness.contains(core::Sloppy::file_stat_matches)) {
result += "file_stat_matches, ";
}
- if (sloppiness.is_enabled(core::Sloppy::file_stat_matches_ctime)) {
+ if (sloppiness.contains(core::Sloppy::file_stat_matches_ctime)) {
result += "file_stat_matches_ctime, ";
}
- if (sloppiness.is_enabled(core::Sloppy::gcno_cwd)) {
+ if (sloppiness.contains(core::Sloppy::gcno_cwd)) {
result += "gcno_cwd, ";
}
- if (sloppiness.is_enabled(core::Sloppy::include_file_ctime)) {
+ if (sloppiness.contains(core::Sloppy::include_file_ctime)) {
result += "include_file_ctime, ";
}
- if (sloppiness.is_enabled(core::Sloppy::include_file_mtime)) {
+ if (sloppiness.contains(core::Sloppy::include_file_mtime)) {
result += "include_file_mtime, ";
}
- if (sloppiness.is_enabled(core::Sloppy::ivfsoverlay)) {
+ if (sloppiness.contains(core::Sloppy::ivfsoverlay)) {
result += "ivfsoverlay, ";
}
- if (sloppiness.is_enabled(core::Sloppy::locale)) {
+ if (sloppiness.contains(core::Sloppy::locale)) {
result += "locale, ";
}
- if (sloppiness.is_enabled(core::Sloppy::modules)) {
+ if (sloppiness.contains(core::Sloppy::modules)) {
result += "modules, ";
}
- if (sloppiness.is_enabled(core::Sloppy::pch_defines)) {
+ if (sloppiness.contains(core::Sloppy::pch_defines)) {
result += "pch_defines, ";
}
- if (sloppiness.is_enabled(core::Sloppy::random_seed)) {
+ if (sloppiness.contains(core::Sloppy::random_seed)) {
result += "random_seed, ";
}
- if (sloppiness.is_enabled(core::Sloppy::system_headers)) {
+ if (sloppiness.contains(core::Sloppy::system_headers)) {
result += "system_headers, ";
}
- if (sloppiness.is_enabled(core::Sloppy::time_macros)) {
+ if (sloppiness.contains(core::Sloppy::time_macros)) {
result += "time_macros, ";
}
if (!result.empty()) {
diff --git a/src/argprocessing.cpp b/src/argprocessing.cpp
index f7f68007..792c57f7 100644
--- a/src/argprocessing.cpp
+++ b/src/argprocessing.cpp
@@ -309,7 +309,7 @@ process_option_arg(const Context& ctx,
// Ignore clang -ivfsoverlay <arg> to not detect multiple input files.
if (arg == "-ivfsoverlay"
- && !(config.sloppiness().is_enabled(core::Sloppy::ivfsoverlay))) {
+ && !(config.sloppiness().contains(core::Sloppy::ivfsoverlay))) {
LOG_RAW(
"You have to specify \"ivfsoverlay\" sloppiness when using"
" -ivfsoverlay to get hits");
@@ -478,7 +478,7 @@ process_option_arg(const Context& ctx,
LOG("Compiler option {} is unsupported without direct depend mode",
args[i]);
return Statistic::could_not_use_modules;
- } else if (!(config.sloppiness().is_enabled(core::Sloppy::modules))) {
+ } else if (!(config.sloppiness().contains(core::Sloppy::modules))) {
LOG_RAW(
"You have to specify \"modules\" sloppiness when using"
" -fmodules to get hits");
@@ -734,7 +734,7 @@ process_option_arg(const Context& ctx,
}
if (arg == "-fprofile-abs-path") {
- if (!config.sloppiness().is_enabled(core::Sloppy::gcno_cwd)) {
+ if (!config.sloppiness().contains(core::Sloppy::gcno_cwd)) {
// -fprofile-abs-path makes the compiler include absolute paths based on
// the actual CWD in the .gcno file.
state.hash_actual_cwd = true;
@@ -930,7 +930,7 @@ process_option_arg(const Context& ctx,
return Statistic::none;
}
- if (config.sloppiness().is_enabled(core::Sloppy::clang_index_store)
+ if (config.sloppiness().contains(core::Sloppy::clang_index_store)
&& arg == "-index-store-path") {
// Xcode 9 or later calls Clang with this option. The given path includes a
// UUID that might lead to cache misses, especially when cache is shared
@@ -1222,7 +1222,7 @@ process_args(Context& ctx)
if (state.found_pch || state.found_fpch_preprocess) {
args_info.using_precompiled_header = true;
- if (!(config.sloppiness().is_enabled(core::Sloppy::time_macros))) {
+ if (!(config.sloppiness().contains(core::Sloppy::time_macros))) {
LOG_RAW(
"You have to specify \"time_macros\" sloppiness when using"
" precompiled headers to get direct hits");
@@ -1260,7 +1260,7 @@ process_args(Context& ctx)
}
if (args_info.output_is_precompiled_header
- && !(config.sloppiness().is_enabled(core::Sloppy::pch_defines))) {
+ && !(config.sloppiness().contains(core::Sloppy::pch_defines))) {
LOG_RAW(
"You have to specify \"pch_defines,time_macros\" sloppiness when"
" creating precompiled headers");
diff --git a/src/ccache.cpp b/src/ccache.cpp
index d867dd1e..7d3eabdf 100644
--- a/src/ccache.cpp
+++ b/src/ccache.cpp
@@ -265,14 +265,14 @@ include_file_too_new(const Context& ctx,
// The comparison using >= is intentional, due to a possible race between
// starting compilation and writing the include file. See also the notes under
// "Performance" in doc/MANUAL.adoc.
- if (!(ctx.config.sloppiness().is_enabled(core::Sloppy::include_file_mtime))
+ if (!(ctx.config.sloppiness().contains(core::Sloppy::include_file_mtime))
&& path_stat.mtime() >= ctx.time_of_compilation) {
LOG("Include file {} too new", path);
return true;
}
// The same >= logic as above applies to the change time of the file.
- if (!(ctx.config.sloppiness().is_enabled(core::Sloppy::include_file_ctime))
+ if (!(ctx.config.sloppiness().contains(core::Sloppy::include_file_ctime))
&& path_stat.ctime() >= ctx.time_of_compilation) {
LOG("Include file {} ctime too new", path);
return true;
@@ -302,7 +302,7 @@ do_remember_include_file(Context& ctx,
}
if (system
- && (ctx.config.sloppiness().is_enabled(core::Sloppy::system_headers))) {
+ && (ctx.config.sloppiness().contains(core::Sloppy::system_headers))) {
// Don't remember this system header.
return true;
}
@@ -833,7 +833,7 @@ update_manifest(Context& ctx,
// so mtimes/ctimes are stored as a dummy value (-1) if not enabled. This
// reduces the number of file_info entries for the common case.
const bool save_timestamp =
- (ctx.config.sloppiness().is_enabled(core::Sloppy::file_stat_matches))
+ (ctx.config.sloppiness().contains(core::Sloppy::file_stat_matches))
|| ctx.args_info.output_is_precompiled_header;
const bool added = ctx.manifest.add_result(
@@ -1421,7 +1421,7 @@ hash_common_info(const Context& ctx,
}
}
- if (!(ctx.config.sloppiness().is_enabled(core::Sloppy::locale))) {
+ if (!(ctx.config.sloppiness().contains(core::Sloppy::locale))) {
// Hash environment variables that may affect localization of compiler
// warning messages.
const char* envvars[] = {
@@ -1483,7 +1483,7 @@ hash_common_info(const Context& ctx,
}
if (ctx.args_info.generating_coverage
- && !(ctx.config.sloppiness().is_enabled(core::Sloppy::gcno_cwd))) {
+ && !(ctx.config.sloppiness().contains(core::Sloppy::gcno_cwd))) {
// GCC 9+ includes $PWD in the .gcno file. Since we don't have knowledge
// about compiler version we always (unless sloppiness is wanted) include
// the directory in the hash for now.
@@ -1661,7 +1661,7 @@ hash_argument(const Context& ctx,
}
if (util::starts_with(args[i], "-frandom-seed=")
- && ctx.config.sloppiness().is_enabled(core::Sloppy::random_seed)) {
+ && ctx.config.sloppiness().contains(core::Sloppy::random_seed)) {
LOG("Ignoring {} since random_seed sloppiness is requested", args[i]);
return {};
}
diff --git a/src/core/Manifest.cpp b/src/core/Manifest.cpp
index 5ee94a75..2137103e 100644
--- a/src/core/Manifest.cpp
+++ b/src/core/Manifest.cpp
@@ -378,9 +378,9 @@ Manifest::result_matches(
return false;
}
- if (ctx.config.sloppiness().is_enabled(core::Sloppy::file_stat_matches)) {
- if (!(ctx.config.sloppiness().is_enabled(
- core::Sloppy::file_stat_matches_ctime))) {
+ if (ctx.config.sloppiness().contains(core::Sloppy::file_stat_matches)) {
+ if (!ctx.config.sloppiness().contains(
+ core::Sloppy::file_stat_matches_ctime)) {
if (fi.mtime == fs.mtime && fi.ctime == fs.ctime) {
LOG("mtime/ctime hit for {}", path);
continue;
diff --git a/src/core/Sloppiness.hpp b/src/core/Sloppiness.hpp
index ef45907d..2466934b 100644
--- a/src/core/Sloppiness.hpp
+++ b/src/core/Sloppiness.hpp
@@ -1,4 +1,4 @@
-// Copyright (C) 2021-2022 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2023 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
@@ -18,6 +18,8 @@
#pragma once
+#include <util/BitSet.hpp>
+
#include <cstdint>
#include <string>
@@ -53,48 +55,6 @@ enum class Sloppy : uint32_t {
random_seed = 1U << 12,
};
-class Sloppiness
-{
-public:
- Sloppiness(Sloppy value = Sloppy::none);
- explicit Sloppiness(uint32_t value);
-
- void enable(Sloppy value);
- bool is_enabled(Sloppy value) const;
- uint32_t to_bitmask() const;
-
-private:
- Sloppy m_sloppiness = Sloppy::none;
-};
-
-// --- Inline implementations ---
-
-inline Sloppiness::Sloppiness(Sloppy value) : m_sloppiness(value)
-{
-}
-
-inline Sloppiness::Sloppiness(uint32_t value)
- : m_sloppiness(static_cast<Sloppy>(value))
-{
-}
-
-inline void
-Sloppiness::enable(Sloppy value)
-{
- m_sloppiness = static_cast<Sloppy>(static_cast<uint32_t>(m_sloppiness)
- | static_cast<uint32_t>(value));
-}
-
-inline bool
-Sloppiness::is_enabled(Sloppy value) const
-{
- return static_cast<uint32_t>(m_sloppiness) & static_cast<uint32_t>(value);
-}
-
-inline uint32_t
-Sloppiness::to_bitmask() const
-{
- return static_cast<uint32_t>(m_sloppiness);
-}
+using Sloppiness = util::BitSet<Sloppy>;
} // namespace core
diff --git a/src/hashutil.cpp b/src/hashutil.cpp
index 796eb3a2..96838456 100644
--- a/src/hashutil.cpp
+++ b/src/hashutil.cpp
@@ -1,4 +1,4 @@
-// Copyright (C) 2009-2022 Joel Rosdahl and other contributors
+// Copyright (C) 2009-2023 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
@@ -242,8 +242,8 @@ hash_source_code_file(const Context& ctx,
size_t size_hint)
{
const bool check_temporal_macros =
- !ctx.config.sloppiness().is_enabled(core::Sloppy::time_macros);
- int result =
+ !ctx.config.sloppiness().contains(core::Sloppy::time_macros);
+ auto result =
do_hash_file(ctx, digest, path, size_hint, check_temporal_macros);
if (!check_temporal_macros || result == HASH_SOURCE_CODE_OK