From 27f46798d98ae6f06445743e0023fa6e8739f8d2 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Wed, 28 Aug 2024 00:16:29 +0800 Subject: [PATCH 1/5] Remove pre-P0960R3 workaround for `emplace_front` --- stl/inc/chrono | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stl/inc/chrono b/stl/inc/chrono index 67593076fb..fec2485e0a 100644 --- a/stl/inc/chrono +++ b/stl/inc/chrono @@ -2209,8 +2209,8 @@ namespace chrono { auto [_Icu_version, _Zones, _Links] = _Tzdb_generate_time_zones(); auto [_Leap_sec, _All_ls_positive] = _Tzdb_generate_leap_seconds(0); auto _Version = _Icu_version + "." + _STD to_string(_Leap_sec.size()); - _Tzdb_list.emplace_front(tzdb{ - _STD move(_Version), _STD move(_Zones), _STD move(_Links), _STD move(_Leap_sec), _All_ls_positive}); + _Tzdb_list.emplace_front( + _STD move(_Version), _STD move(_Zones), _STD move(_Links), _STD move(_Leap_sec), _All_ls_positive); } _NODISCARD const tzdb& front() const noexcept { @@ -2266,8 +2266,8 @@ namespace chrono { } auto _Version = _Tzdb_update_version(_Tzdb.version, _Leap_sec.size()); - _Tzdb_list.emplace_front(tzdb{ - _STD move(_Version), _STD move(_Zones), _STD move(_Links), _STD move(_Leap_sec), _All_ls_positive}); + _Tzdb_list.emplace_front( + _STD move(_Version), _STD move(_Zones), _STD move(_Links), _STD move(_Leap_sec), _All_ls_positive); } return _Tzdb_list.front(); } From be90910f63c2794174c3fac19e592be1fb55cfd3 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Wed, 28 Aug 2024 00:17:26 +0800 Subject: [PATCH 2/5] Remove `tzdb_list::_Emplace_front` and completely hack in test codes --- stl/inc/chrono | 6 --- tests/std/include/timezone_data.hpp | 51 +++++++++++++++++++ .../test.cpp | 4 +- .../test.cpp | 2 +- 4 files changed, 54 insertions(+), 9 deletions(-) diff --git a/stl/inc/chrono b/stl/inc/chrono index fec2485e0a..593ec27bb8 100644 --- a/stl/inc/chrono +++ b/stl/inc/chrono @@ -2241,12 +2241,6 @@ namespace chrono { return _Tzdb_list.cend(); // no lock necessary for forward_list::cend() } - template - void _Emplace_front(_ArgsTy&&... _Args) { - _Unique_lock _Lk(_Tzdb_mutex); - _Tzdb_list.emplace_front(_STD forward<_ArgsTy>(_Args)...); - } - const tzdb& _Reload() { _Unique_lock _Lk(_Tzdb_mutex); auto [_Leap_sec, _All_ls_positive] = _Tzdb_generate_leap_seconds(_Tzdb_list.front().leap_seconds.size()); diff --git a/tests/std/include/timezone_data.hpp b/tests/std/include/timezone_data.hpp index be71968f2f..73f0f6890a 100644 --- a/tests/std/include/timezone_data.hpp +++ b/tests/std/include/timezone_data.hpp @@ -170,3 +170,54 @@ void run_tz_test(TestFunction test_function) { assert(false); } } + +namespace tzdb_list_hack { // non-portable hack into tzdb_list + template + struct member_hacker; + + template + consteval auto get_hacked_memptr(member_hacker) noexcept { + return Val; + } + + template <> + struct member_hacker<&tzdb_list::_Tzdb_list> { + friend consteval auto get_tzdb_list_inner_forward_list() noexcept { + return get_hacked_memptr(member_hacker{}); + } + }; + + template <> + struct member_hacker<&tzdb_list::_Tzdb_mutex> { + friend consteval auto get_tzdb_list_inner_smtx() noexcept { + return get_hacked_memptr(member_hacker{}); + } + }; + + consteval auto get_tzdb_list_inner_forward_list() noexcept; + consteval auto get_tzdb_list_inner_smtx() noexcept; + + template + void emplace_front(tzdb_list& tl, ArgsTypes&&... args) { + struct [[nodiscard]] unique_smtx_lock { + explicit unique_smtx_lock(_Smtx_t& mtx) : mtx_{&mtx} { + _Smtx_lock_exclusive(mtx_); + } + + unique_smtx_lock(const unique_smtx_lock&) = delete; + unique_smtx_lock& operator=(const unique_smtx_lock&) = delete; + + ~unique_smtx_lock() { + _Smtx_unlock_exclusive(mtx_); + } + + _Smtx_t* mtx_; + }; + + constexpr auto memptr_fwdlist = get_tzdb_list_inner_forward_list(); + constexpr auto memptr_smtx = get_tzdb_list_inner_smtx(); + + unique_smtx_lock guard_{tl.*memptr_smtx}; + (tl.*memptr_fwdlist).emplace_front(forward(args)...); + } +} // namespace tzdb_list_hack diff --git a/tests/std/tests/P0355R7_calendars_and_time_zones_clocks/test.cpp b/tests/std/tests/P0355R7_calendars_and_time_zones_clocks/test.cpp index eb4812739b..4043cdb003 100644 --- a/tests/std/tests/P0355R7_calendars_and_time_zones_clocks/test.cpp +++ b/tests/std/tests/P0355R7_calendars_and_time_zones_clocks/test.cpp @@ -431,7 +431,7 @@ void test() { leap_vec.emplace_back(sys_days{1d / January / 2020y}, false, leap_vec.back()._Elapsed()); leap_vec.emplace_back(sys_days{1d / January / 2021y}, true, leap_vec.back()._Elapsed()); my_tzdb._All_ls_positive = false; - get_tzdb_list()._Emplace_front(move(my_tzdb)); + tzdb_list_hack::emplace_front(get_tzdb_list(), move(my_tzdb)); } offset = 0s; @@ -458,7 +458,7 @@ void test() { leap_vec.emplace_back(sys_days{1d / January / year{i + 2020}}, false, leap_vec.back()._Elapsed()); } leap_vec.emplace_back(sys_days{1d / January / 2060y}, true, leap_vec.back()._Elapsed()); - get_tzdb_list()._Emplace_front(move(my_tzdb)); + tzdb_list_hack::emplace_front(get_tzdb_list(), move(my_tzdb)); } offset = 0s; diff --git a/tests/std/tests/P0355R7_calendars_and_time_zones_io/test.cpp b/tests/std/tests/P0355R7_calendars_and_time_zones_io/test.cpp index 64fbc3c229..82250d215b 100644 --- a/tests/std/tests/P0355R7_calendars_and_time_zones_io/test.cpp +++ b/tests/std/tests/P0355R7_calendars_and_time_zones_io/test.cpp @@ -1070,7 +1070,7 @@ void parse_timepoints() { leap_vec.emplace_back(sys_days{1d / January / 2020y}, false, leap_vec.back()._Elapsed()); leap_vec.emplace_back(sys_days{1d / January / 2022y}, true, leap_vec.back()._Elapsed()); my_tzdb._All_ls_positive = false; - get_tzdb_list()._Emplace_front(move(my_tzdb)); + tzdb_list_hack::emplace_front(get_tzdb_list(), move(my_tzdb)); } utc_seconds ut_ref = utc_clock::from_sys(sys_days{1d / July / 1972y}) - 1s; // leap second insertion From 558d45c05d05ca4f137f3c68188ef5abc3be394b Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Wed, 28 Aug 2024 01:34:20 +0800 Subject: [PATCH 3/5] Revert "Remove pre-P0960R3 workaround for `emplace_front`" This reverts commit 27f46798d98ae6f06445743e0023fa6e8739f8d2. --- stl/inc/chrono | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/stl/inc/chrono b/stl/inc/chrono index 593ec27bb8..a311c55ecf 100644 --- a/stl/inc/chrono +++ b/stl/inc/chrono @@ -2209,8 +2209,9 @@ namespace chrono { auto [_Icu_version, _Zones, _Links] = _Tzdb_generate_time_zones(); auto [_Leap_sec, _All_ls_positive] = _Tzdb_generate_leap_seconds(0); auto _Version = _Icu_version + "." + _STD to_string(_Leap_sec.size()); - _Tzdb_list.emplace_front( - _STD move(_Version), _STD move(_Zones), _STD move(_Links), _STD move(_Leap_sec), _All_ls_positive); + // TRANSITION, DevCom-10732572, should call emplace_front with construction arguments + _Tzdb_list.emplace_front(tzdb{ + _STD move(_Version), _STD move(_Zones), _STD move(_Links), _STD move(_Leap_sec), _All_ls_positive}); } _NODISCARD const tzdb& front() const noexcept { @@ -2260,8 +2261,9 @@ namespace chrono { } auto _Version = _Tzdb_update_version(_Tzdb.version, _Leap_sec.size()); - _Tzdb_list.emplace_front( - _STD move(_Version), _STD move(_Zones), _STD move(_Links), _STD move(_Leap_sec), _All_ls_positive); + // TRANSITION, DevCom-10732572, should call emplace_front with construction arguments + _Tzdb_list.emplace_front(tzdb{ + _STD move(_Version), _STD move(_Zones), _STD move(_Links), _STD move(_Leap_sec), _All_ls_positive}); } return _Tzdb_list.front(); } From b7baa109702747bf35d42778880dacd50b2e350a Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Wed, 28 Aug 2024 01:36:40 +0800 Subject: [PATCH 4/5] VSO-2228186 --- stl/inc/chrono | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/chrono b/stl/inc/chrono index a311c55ecf..ed1b09a2a5 100644 --- a/stl/inc/chrono +++ b/stl/inc/chrono @@ -2209,7 +2209,7 @@ namespace chrono { auto [_Icu_version, _Zones, _Links] = _Tzdb_generate_time_zones(); auto [_Leap_sec, _All_ls_positive] = _Tzdb_generate_leap_seconds(0); auto _Version = _Icu_version + "." + _STD to_string(_Leap_sec.size()); - // TRANSITION, DevCom-10732572, should call emplace_front with construction arguments + // TRANSITION, VSO-2228186, should call emplace_front with construction arguments _Tzdb_list.emplace_front(tzdb{ _STD move(_Version), _STD move(_Zones), _STD move(_Links), _STD move(_Leap_sec), _All_ls_positive}); } @@ -2261,7 +2261,7 @@ namespace chrono { } auto _Version = _Tzdb_update_version(_Tzdb.version, _Leap_sec.size()); - // TRANSITION, DevCom-10732572, should call emplace_front with construction arguments + // TRANSITION, VSO-2228186, should call emplace_front with construction arguments _Tzdb_list.emplace_front(tzdb{ _STD move(_Version), _STD move(_Zones), _STD move(_Links), _STD move(_Leap_sec), _All_ls_positive}); } From d9851b17f668365086e626b356f43fdd0c7b18d6 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 27 Aug 2024 15:50:28 -0700 Subject: [PATCH 5/5] Revert all but the TRANSITION, VSO-2228186 comments. --- stl/inc/chrono | 6 +++ tests/std/include/timezone_data.hpp | 51 ------------------- .../test.cpp | 4 +- .../test.cpp | 2 +- 4 files changed, 9 insertions(+), 54 deletions(-) diff --git a/stl/inc/chrono b/stl/inc/chrono index ed1b09a2a5..0a2db79cb6 100644 --- a/stl/inc/chrono +++ b/stl/inc/chrono @@ -2242,6 +2242,12 @@ namespace chrono { return _Tzdb_list.cend(); // no lock necessary for forward_list::cend() } + template + void _Emplace_front(_ArgsTy&&... _Args) { + _Unique_lock _Lk(_Tzdb_mutex); + _Tzdb_list.emplace_front(_STD forward<_ArgsTy>(_Args)...); + } + const tzdb& _Reload() { _Unique_lock _Lk(_Tzdb_mutex); auto [_Leap_sec, _All_ls_positive] = _Tzdb_generate_leap_seconds(_Tzdb_list.front().leap_seconds.size()); diff --git a/tests/std/include/timezone_data.hpp b/tests/std/include/timezone_data.hpp index 73f0f6890a..be71968f2f 100644 --- a/tests/std/include/timezone_data.hpp +++ b/tests/std/include/timezone_data.hpp @@ -170,54 +170,3 @@ void run_tz_test(TestFunction test_function) { assert(false); } } - -namespace tzdb_list_hack { // non-portable hack into tzdb_list - template - struct member_hacker; - - template - consteval auto get_hacked_memptr(member_hacker) noexcept { - return Val; - } - - template <> - struct member_hacker<&tzdb_list::_Tzdb_list> { - friend consteval auto get_tzdb_list_inner_forward_list() noexcept { - return get_hacked_memptr(member_hacker{}); - } - }; - - template <> - struct member_hacker<&tzdb_list::_Tzdb_mutex> { - friend consteval auto get_tzdb_list_inner_smtx() noexcept { - return get_hacked_memptr(member_hacker{}); - } - }; - - consteval auto get_tzdb_list_inner_forward_list() noexcept; - consteval auto get_tzdb_list_inner_smtx() noexcept; - - template - void emplace_front(tzdb_list& tl, ArgsTypes&&... args) { - struct [[nodiscard]] unique_smtx_lock { - explicit unique_smtx_lock(_Smtx_t& mtx) : mtx_{&mtx} { - _Smtx_lock_exclusive(mtx_); - } - - unique_smtx_lock(const unique_smtx_lock&) = delete; - unique_smtx_lock& operator=(const unique_smtx_lock&) = delete; - - ~unique_smtx_lock() { - _Smtx_unlock_exclusive(mtx_); - } - - _Smtx_t* mtx_; - }; - - constexpr auto memptr_fwdlist = get_tzdb_list_inner_forward_list(); - constexpr auto memptr_smtx = get_tzdb_list_inner_smtx(); - - unique_smtx_lock guard_{tl.*memptr_smtx}; - (tl.*memptr_fwdlist).emplace_front(forward(args)...); - } -} // namespace tzdb_list_hack diff --git a/tests/std/tests/P0355R7_calendars_and_time_zones_clocks/test.cpp b/tests/std/tests/P0355R7_calendars_and_time_zones_clocks/test.cpp index 4043cdb003..eb4812739b 100644 --- a/tests/std/tests/P0355R7_calendars_and_time_zones_clocks/test.cpp +++ b/tests/std/tests/P0355R7_calendars_and_time_zones_clocks/test.cpp @@ -431,7 +431,7 @@ void test() { leap_vec.emplace_back(sys_days{1d / January / 2020y}, false, leap_vec.back()._Elapsed()); leap_vec.emplace_back(sys_days{1d / January / 2021y}, true, leap_vec.back()._Elapsed()); my_tzdb._All_ls_positive = false; - tzdb_list_hack::emplace_front(get_tzdb_list(), move(my_tzdb)); + get_tzdb_list()._Emplace_front(move(my_tzdb)); } offset = 0s; @@ -458,7 +458,7 @@ void test() { leap_vec.emplace_back(sys_days{1d / January / year{i + 2020}}, false, leap_vec.back()._Elapsed()); } leap_vec.emplace_back(sys_days{1d / January / 2060y}, true, leap_vec.back()._Elapsed()); - tzdb_list_hack::emplace_front(get_tzdb_list(), move(my_tzdb)); + get_tzdb_list()._Emplace_front(move(my_tzdb)); } offset = 0s; diff --git a/tests/std/tests/P0355R7_calendars_and_time_zones_io/test.cpp b/tests/std/tests/P0355R7_calendars_and_time_zones_io/test.cpp index 82250d215b..64fbc3c229 100644 --- a/tests/std/tests/P0355R7_calendars_and_time_zones_io/test.cpp +++ b/tests/std/tests/P0355R7_calendars_and_time_zones_io/test.cpp @@ -1070,7 +1070,7 @@ void parse_timepoints() { leap_vec.emplace_back(sys_days{1d / January / 2020y}, false, leap_vec.back()._Elapsed()); leap_vec.emplace_back(sys_days{1d / January / 2022y}, true, leap_vec.back()._Elapsed()); my_tzdb._All_ls_positive = false; - tzdb_list_hack::emplace_front(get_tzdb_list(), move(my_tzdb)); + get_tzdb_list()._Emplace_front(move(my_tzdb)); } utc_seconds ut_ref = utc_clock::from_sys(sys_days{1d / July / 1972y}) - 1s; // leap second insertion