From 095583f1fbab20937720f9311ddb9945ff2b9224 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 18 Apr 2022 10:03:13 +0200 Subject: Switch recipe from std::function to butl::move_only_function_ex --- libbuild2/adhoc-rule-buildscript.cxx | 34 ++++------------------------------ libbuild2/install/rule.cxx | 2 +- libbuild2/recipe.cxx | 8 ++++---- libbuild2/recipe.hxx | 19 ++++++++++--------- libbuild2/types.hxx | 6 +++++- 5 files changed, 24 insertions(+), 45 deletions(-) diff --git a/libbuild2/adhoc-rule-buildscript.cxx b/libbuild2/adhoc-rule-buildscript.cxx index 78891b9..aa30552 100644 --- a/libbuild2/adhoc-rule-buildscript.cxx +++ b/libbuild2/adhoc-rule-buildscript.cxx @@ -770,23 +770,10 @@ namespace build2 mdb->bs = &bs; mdb->mt = update ? timestamp_nonexistent : mt; - // @@ TMP: re-enable once recipe becomes move_only_function. - // -#if 0 - return [this, md = move (mdb)] (action a, const target& t) mutable - { - auto r (perform_update_file_dyndep_byproduct (a, t, *md)); - md.reset (); // @@ TMP: is this really necessary (+mutable)? - return r; - }; -#else - t.data (move (mdb)); - return recipe ([this] (action a, const target& t) mutable + return [this, md = move (mdb)] (action a, const target& t) { - auto md (move (t.data> ())); return perform_update_file_dyndep_byproduct (a, t, *md); - }); -#endif + }; } else { @@ -819,23 +806,10 @@ namespace build2 md->mt = update ? timestamp_nonexistent : mt; md->deferred_failure = deferred_failure; - // @@ TMP: re-enable once recipe becomes move_only_function. - // -#if 0 - return [this, md = move (md)] (action a, const target& t) mutable - { - auto r (perform_update_file_dyndep (a, t, *md)); - md.reset (); // @@ TMP: is this really necessary (+mutable)? - return r; - }; -#else - t.data (move (md)); - return recipe ([this] (action a, const target& t) mutable + return [this, md = move (md)] (action a, const target& t) { - auto md (move (t.data> ())); return perform_update_file_dyndep (a, t, *md); - }); -#endif + }; } } diff --git a/libbuild2/install/rule.cxx b/libbuild2/install/rule.cxx index 30f1755..1411143 100644 --- a/libbuild2/install/rule.cxx +++ b/libbuild2/install/rule.cxx @@ -342,7 +342,7 @@ namespace build2 apply (action a, target& t) const { recipe r (apply_impl (a, t)); - return r != nullptr ? r : noop_recipe; + return r != nullptr ? move (r) : noop_recipe; } recipe file_rule:: diff --git a/libbuild2/recipe.cxx b/libbuild2/recipe.cxx index 3720059..eeafe87 100644 --- a/libbuild2/recipe.cxx +++ b/libbuild2/recipe.cxx @@ -7,8 +7,8 @@ namespace build2 { - const recipe empty_recipe; - const recipe noop_recipe (&noop_action); - const recipe default_recipe (&default_action); - const recipe group_recipe (&group_action); + recipe_function* const empty_recipe = nullptr; + recipe_function* const noop_recipe = &noop_action; + recipe_function* const default_recipe = &default_action; + recipe_function* const group_recipe = &group_action; } diff --git a/libbuild2/recipe.hxx b/libbuild2/recipe.hxx index 508c059..dfe36ec 100644 --- a/libbuild2/recipe.hxx +++ b/libbuild2/recipe.hxx @@ -27,13 +27,14 @@ namespace build2 // and while the prerequisite will be re-examined via another dependency, // this target is done). // - // Note that max size for the "small capture optimization" in std::function - // ranges (in pointer sizes) from 0 (GCC prior to 5) to 2 (GCC 5) to 6 (VC - // 14.2). With the size ranging (in bytes for 64-bit target) from 32 (GCC) - // to 64 (VC). + // Note that max size for the "small size optimization" in std::function + // (which is what move_only_function_ex is based on) ranges (in pointer + // sizes) from 0 (GCC libstdc++ prior to 5) to 2 (GCC 5 and later) to 3 + // (Clang libc++) to 6 (VC 14.2). With the size ranging (in bytes for 64-bit + // target) from 32 (GCC) to 64 (VC). // using recipe_function = target_state (action, const target&); - using recipe = function; + using recipe = move_only_function_ex; // Commonly-used recipes. // @@ -44,10 +45,10 @@ namespace build2 // for details). The group recipe calls the // group's recipe. // - LIBBUILD2_SYMEXPORT extern const recipe empty_recipe; - LIBBUILD2_SYMEXPORT extern const recipe noop_recipe; - LIBBUILD2_SYMEXPORT extern const recipe default_recipe; - LIBBUILD2_SYMEXPORT extern const recipe group_recipe; + LIBBUILD2_SYMEXPORT extern recipe_function* const empty_recipe; + LIBBUILD2_SYMEXPORT extern recipe_function* const noop_recipe; + LIBBUILD2_SYMEXPORT extern recipe_function* const default_recipe; + LIBBUILD2_SYMEXPORT extern recipe_function* const group_recipe; } #endif // LIBBUILD2_RECIPE_HXX diff --git a/libbuild2/types.hxx b/libbuild2/types.hxx index 7bc6b32..cd6fdd8 100644 --- a/libbuild2/types.hxx +++ b/libbuild2/types.hxx @@ -59,6 +59,7 @@ #include #include #include +#include #include @@ -82,9 +83,12 @@ namespace build2 using std::pair; using std::tuple; using std::string; - using std::function; using std::reference_wrapper; + using std::function; + using butl::move_only_function; + using butl::move_only_function_ex; + using strings = std::vector; using cstrings = std::vector; -- cgit v1.1