Enable FastTable for non-opt builds. PiperOrigin-RevId: 945728522
diff --git a/cmake/installed_include_golden.txt b/cmake/installed_include_golden.txt index b5a35ec..5b8e525 100644 --- a/cmake/installed_include_golden.txt +++ b/cmake/installed_include_golden.txt
@@ -240,6 +240,9 @@ upb/wire/decode.h upb/wire/decode_fast/combinations.h upb/wire/decode_fast/data.h +upb/wire/decode_fast/dispatch.h +upb/wire/decode_fast/field_parsers.h +upb/wire/decode_fast/function_array.h upb/wire/decode_fast/select.h upb/wire/encode.h upb/wire/eps_copy_input_stream.h
diff --git a/upb/BUILD b/upb/BUILD index b33477e..3741d23 100644 --- a/upb/BUILD +++ b/upb/BUILD
@@ -6,7 +6,7 @@ # https://developers.google.com/open-source/licenses/bsd load("@bazel_skylib//lib:selects.bzl", "selects") -load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") +load("@bazel_skylib//rules:common_settings.bzl", "string_flag") load("@rules_cc//cc:defs.bzl", "cc_library") load("@rules_python//python:defs.bzl", "py_binary") load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_FEATURES") @@ -44,28 +44,95 @@ visibility = UPB_CONFIG_VISIBILITY, ) -bool_flag( +# FastTable flag definition + enablement rules. +# FastTable will only enable for builds targeting 64bit. +# If not explicitly specified, FastTable will enable by default for non-opt builds. +string_flag( name = "fasttable_enabled", - build_setting_default = False, + build_setting_default = "auto", scope = "universal", + values = [ + "true", + "false", + "auto", + "True", + "False", + "Auto", + ], visibility = UPB_CONFIG_VISIBILITY, ) config_setting( - name = "fasttable_enabled_setting_flag", + name = "fasttable_enabled_true", flag_values = {"//upb:fasttable_enabled": "true"}, - visibility = UPB_CONFIG_VISIBILITY, +) + +config_setting( + name = "fasttable_enabled_True_cap", + flag_values = {"//upb:fasttable_enabled": "True"}, ) selects.config_setting_group( - name = "fasttable_enabled_setting", - match_all = [ - ":fasttable_enabled_setting_flag", - ":any_64bit", + name = "fasttable_enabled_explicit_true", + match_any = [ + ":fasttable_enabled_true", + ":fasttable_enabled_True_cap", ], visibility = UPB_CONFIG_VISIBILITY, ) +config_setting( + name = "fasttable_enabled_auto", + flag_values = {"//upb:fasttable_enabled": "auto"}, +) + +config_setting( + name = "fasttable_enabled_Auto_cap", + flag_values = {"//upb:fasttable_enabled": "Auto"}, +) + +selects.config_setting_group( + name = "fasttable_enabled_is_auto", + match_any = [ + ":fasttable_enabled_auto", + ":fasttable_enabled_Auto_cap", + ], +) + +config_setting( + name = "dbg_mode", + values = {"compilation_mode": "dbg"}, +) + +config_setting( + name = "fastbuild_mode", + values = {"compilation_mode": "fastbuild"}, +) + +selects.config_setting_group( + name = "non_opt_build", + match_any = [ + ":dbg_mode", + ":fastbuild_mode", + ], +) + +selects.config_setting_group( + name = "fasttable_enabled_default_active", + match_all = [ + ":fasttable_enabled_is_auto", + ":non_opt_build", + ], +) + +selects.config_setting_group( + name = "fasttable_enabled_active", + match_any = [ + ":fasttable_enabled_explicit_true", + ":fasttable_enabled_default_active", + ], +) + selects.config_setting_group( name = "any_64bit", match_any = [ @@ -82,6 +149,15 @@ visibility = UPB_CONFIG_VISIBILITY, ) +selects.config_setting_group( + name = "fasttable_enabled_setting", + match_all = [ + ":fasttable_enabled_active", + ":any_64bit", + ], + visibility = UPB_CONFIG_VISIBILITY, +) + upb_proto_library_copts( name = "upb_proto_library_copts", copts = UPB_DEFAULT_COPTS,
diff --git a/upb/bazel/copts.bzl b/upb/bazel/copts.bzl index dfbf84c..4a2593d 100644 --- a/upb/bazel/copts.bzl +++ b/upb/bazel/copts.bzl
@@ -44,7 +44,8 @@ "//upb:windows": [], "//conditions:default": _DEFAULT_CPPOPTS, }) + select({ - "//upb:fasttable_enabled_setting": ["-DUPB_ENABLE_FASTTABLE"], + "//upb:fasttable_enabled_explicit_true": ["-DUPB_ENABLE_FASTTABLE"], + "//upb:fasttable_enabled_setting": ["-DUPB_TRY_ENABLE_FASTTABLE"], "//conditions:default": [], }) @@ -52,7 +53,8 @@ "//upb:windows": [], "//conditions:default": _DEFAULT_COPTS, }) + select({ - "//upb:fasttable_enabled_setting": ["-DUPB_ENABLE_FASTTABLE"], + "//upb:fasttable_enabled_explicit_true": ["-DUPB_ENABLE_FASTTABLE"], + "//upb:fasttable_enabled_setting": ["-DUPB_TRY_ENABLE_FASTTABLE"], "//conditions:default": [], })
diff --git a/upb/mini_table/BUILD b/upb/mini_table/BUILD index abde510..e5c27b8 100644 --- a/upb/mini_table/BUILD +++ b/upb/mini_table/BUILD
@@ -230,18 +230,17 @@ # separate tests and use configuration-aware genrules to ensure each test # only performs real validation when its configuration is active. # -# We move the generator binary to "srcs" so that it is built in the target -# configuration (not the exec configuration), ensuring it correctly receives -# the fasttable enablement flag. +# Generator binary is in tools so it is built for the host (exec configuration) +# to support cross-compilation (e.g. darwin_x86_64). genrule( name = "debug_string_test_txt_gen", srcs = select({ - "//upb:fasttable_enabled_setting": ["debug_string_test.txt"], + "//upb:fasttable_enabled_explicit_true": ["debug_string_test.txt"], "//conditions:default": [], }), outs = ["generated/debug_string_test.txt"], cmd = select({ - "//upb:fasttable_enabled_setting": "cp $(location debug_string_test.txt) $@", + "//upb:fasttable_enabled_explicit_true": "cp $(location debug_string_test.txt) $@", "//conditions:default": "$(location :debug_string_test_generate) > $@", }), tools = [":debug_string_test_generate"], @@ -250,12 +249,12 @@ genrule( name = "debug_string_test_fasttable_txt_gen", srcs = select({ - "//upb:fasttable_enabled_setting": [], + "//upb:fasttable_enabled_explicit_true": [], "//conditions:default": ["debug_string_test.fasttable.txt"], }), outs = ["generated/debug_string_test.fasttable.txt"], cmd = select({ - "//upb:fasttable_enabled_setting": "$(location :debug_string_test_generate) > $@", + "//upb:fasttable_enabled_explicit_true": "$(location :debug_string_test_generate) > $@", "//conditions:default": "cp $(location debug_string_test.fasttable.txt) $@", }), tools = [":debug_string_test_generate"],
diff --git a/upb/port/BUILD b/upb/port/BUILD index 2a74325..cffe7b3 100644 --- a/upb/port/BUILD +++ b/upb/port/BUILD
@@ -21,7 +21,8 @@ ], copts = UPB_DEFAULT_COPTS, defines = select({ - "//upb:fasttable_enabled_setting": ["UPB_ENABLE_FASTTABLE"], + "//upb:fasttable_enabled_explicit_true": ["UPB_ENABLE_FASTTABLE"], + "//upb:fasttable_enabled_setting": ["UPB_TRY_ENABLE_FASTTABLE"], "//conditions:default": [], }), features = UPB_DEFAULT_FEATURES,
diff --git a/upb/port/def.inc b/upb/port/def.inc index 0044696..9d83c8a 100644 --- a/upb/port/def.inc +++ b/upb/port/def.inc
@@ -499,7 +499,7 @@ /* aarch64 supports big and little endian modes; fasttable performs multibyte * tag loads assumes the tag of a varint is in the low bits. */ -#if (defined(__x86_64__) || defined(__AARCH64EL__)) && \ +#if !defined(_WIN32) && (defined(__x86_64__) || defined(__AARCH64EL__)) && \ UPB_HAS_ATTRIBUTE(preserve_none) && UPB_HAS_ATTRIBUTE(musttail) #define UPB_FASTTABLE_SUPPORTED 1 #else @@ -518,7 +518,11 @@ * This is useful for releasing code that might be used on multiple platforms, * for example the PHP or Ruby C extensions. */ #elif defined(UPB_TRY_ENABLE_FASTTABLE) -#define UPB_FASTTABLE UPB_FASTTABLE_SUPPORTED +#if UPB_FASTTABLE_SUPPORTED +#define UPB_FASTTABLE 1 +#else +#define UPB_FASTTABLE 0 +#endif #else #define UPB_FASTTABLE 0 #endif @@ -572,6 +576,12 @@ #define UPB_RETAIN #endif +#if defined(__GNUC__) || defined(__clang__) +#define UPB_HIDDEN __attribute__((visibility("hidden"))) +#else +#define UPB_HIDDEN +#endif + // Linker arrays combine elements from multiple translation units into a single // array that can be iterated over at runtime. // @@ -625,7 +635,7 @@ #elif defined(__MACH__) -/* As described in: https://stackoverflow.com/a/22366882 */ + /* As described in: https://stackoverflow.com/a/22366882 */ #define UPB_LINKARR_APPEND(name) \ __attribute__(( \ section("__DATA,__la_" #name))) UPB_LINKARR_ATTR UPB_NO_SANITIZE_ADDRESS @@ -644,10 +654,10 @@ #elif defined(_MSC_VER) -/* See: - * https://devblogs.microsoft.com/oldnewthing/20181107-00/?p=100155 - * https://devblogs.microsoft.com/oldnewthing/20181108-00/?p=100165 - * https://devblogs.microsoft.com/oldnewthing/20181109-00/?p=100175 */ + /* See: + * https://devblogs.microsoft.com/oldnewthing/20181107-00/?p=100155 + * https://devblogs.microsoft.com/oldnewthing/20181108-00/?p=100165 + * https://devblogs.microsoft.com/oldnewthing/20181109-00/?p=100175 */ #define UPB_STRINGIFY_INTERNAL(x) #x #define UPB_STRINGIFY(x) UPB_STRINGIFY_INTERNAL(x) #define UPB_CONCAT(a, b, c) a##b##c @@ -656,7 +666,7 @@ #define UPB_LINKARR_APPEND(name) \ __pragma(section(UPB_LINKARR_NAME(name, $j), read)) \ __declspec(allocate(UPB_LINKARR_NAME(name, $j))) -// clang-format off + // clang-format off #define UPB_LINKARR_DECLARE(name, type) \ __pragma(message(UPB_LINKARR_NAME(name, $j))) \ __pragma(section(UPB_LINKARR_NAME(name, $a), read)) \ @@ -667,13 +677,13 @@ type __stop_linkarr_##name; \ UPB_LINKARR_APPEND(name) \ __declspec(selectany) type UPB_linkarr_internal_empty_##name[1] = {0} -// clang-format on + // clang-format on #define UPB_LINKARR_START(name) (&__start_linkarr_##name) #define UPB_LINKARR_STOP(name) (&__stop_linkarr_##name) #else -// Linker arrays are not supported on this platform. Make macros no-ops. + // Linker arrays are not supported on this platform. Make macros no-ops. #define UPB_LINKARR_APPEND(name) #define UPB_LINKARR_DECLARE(name, type) \ UPB_STATIC_ASSERT(sizeof("__la_" #name) <= 17, \
diff --git a/upb/port/undef.inc b/upb/port/undef.inc index a2bf8a6..5030ee0 100644 --- a/upb/port/undef.inc +++ b/upb/port/undef.inc
@@ -94,3 +94,5 @@ #undef _UPB_STRINGIFY #undef _UPB_STRINGIFY2 #undef UPB_CONSTRUCTOR +#undef UPB_RETAIN +#undef UPB_HIDDEN
diff --git a/upb/wire/decode_fast/cardinality.h b/upb/wire/decode_fast/cardinality.h index e457e67..b453e7f 100644 --- a/upb/wire/decode_fast/cardinality.h +++ b/upb/wire/decode_fast/cardinality.h
@@ -543,8 +543,8 @@ // Workaround for b/177688959. We need to ensure that this function never goes // through PLT lookup. It follows that this function may not be called by // any other cc_library(). -__attribute__((visibility("hidden"))) UPB_PRESERVE_MOST const char* -upb_DecodeFast_IsDoneFallback(upb_Decoder* d, const char* ptr); +UPB_HIDDEN UPB_PRESERVE_MOST const char* upb_DecodeFast_IsDoneFallback( + upb_Decoder* d, const char* ptr); UPB_FORCEINLINE bool upb_DecodeFast_IsDone(upb_Decoder* d, const char** ptr) {