]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Use util::BitSet for core::Sloppiness
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 5 Mar 2023 11:25:57 +0000 (12:25 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 5 Mar 2023 20:42:16 +0000 (21:42 +0100)
src/Config.cpp
src/argprocessing.cpp
src/ccache.cpp
src/core/Manifest.cpp
src/core/Sloppiness.hpp
src/hashutil.cpp

index 840925ca47ffc1f4b9d00d4ad5588de76c3ff9b9..f0525add153ffe2f8d50c9852bae89f531af1229 100644 (file)
@@ -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()) {
index f7f68007574b37221edda2339646a7025b6f2df2..792c57f7c6dbd2d5afc0637e336bdb374df035de 100644 (file)
@@ -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");
index d867dd1ea13633171a55883c1205a56e737655ba..7d3eabdf3bdcc6c1e11e83b9ce598f0252ee185e 100644 (file)
@@ -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 {};
   }
index 5ee94a750ffd4e46b7ad931b644943cd056ed6a7..2137103e9b9b69ef31df58f7955499a55ef0bc46 100644 (file)
@@ -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;
index ef45907dd87258ae28dc6e0a8c5d5c6c7ecbaae1..2466934be509460cff17219a8abda4ef62c929a4 100644 (file)
@@ -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
index 796eb3a2dcffd0c2a2d417f6bc8afd970ec652c7..968384566828ae4283a2dea634c9a09bff2c3a1a 100644 (file)
@@ -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