Skip to content

Commit c000e5e

Browse files
committed
Address review comments.
1 parent edb9daf commit c000e5e

File tree

25 files changed

+313
-178
lines changed

25 files changed

+313
-178
lines changed

libcxx/docs/Status/Cxx20Papers.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180
"`P1973R1 <https://wg21.link/P1973R1>`__","LWG","Rename ""_default_init"" Functions, Rev1","Prague","|Complete|","16.0"
181181
"`P1976R2 <https://wg21.link/P1976R2>`__","LWG","Fixed-size span construction from dynamic range","Prague","|Complete|","11.0","|ranges|"
182182
"`P1981R0 <https://wg21.link/P1981R0>`__","LWG","Rename leap to leap_second","Prague","* *",""
183-
"`P1982R0 <https://wg21.link/P1982R0>`__","LWG","Rename link to time_zone_link","Prague","|Complete|","18.0","|chrono|"
183+
"`P1982R0 <https://wg21.link/P1982R0>`__","LWG","Rename link to time_zone_link","Prague","|Complete|","19.0","|chrono|"
184184
"`P1983R0 <https://wg21.link/P1983R0>`__","LWG","Wording for GB301, US296, US292, US291, and US283","Prague","|Complete|","15.0","|ranges|"
185185
"`P1994R1 <https://wg21.link/P1994R1>`__","LWG","elements_view needs its own sentinel","Prague","|Complete|","16.0","|ranges|"
186186
"`P2002R1 <https://wg21.link/P2002R1>`__","CWG","Defaulted comparison specification cleanups","Prague","* *",""

libcxx/include/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ set(files
292292
__chrono/time_point.h
293293
__chrono/time_zone.h
294294
__chrono/time_zone_link.h
295-
__chrono/time_zone_types.h
296295
__chrono/tzdb.h
297296
__chrono/tzdb_list.h
298297
__chrono/weekday.h

libcxx/include/__chrono/time_zone.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616
// Enable the contents of the header only when libc++ was built with experimental features enabled.
1717
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
1818

19-
# include <__chrono/time_zone_types.h>
2019
# include <__compare/strong_order.h>
2120
# include <__config>
22-
# include <string>
21+
# include <__memory/unique_ptr.h>
2322
# include <string_view>
24-
# include <vector>
2523

2624
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2725
# pragma GCC system_header
2826
# endif
2927

28+
_LIBCPP_PUSH_MACROS
29+
# include <__undef_macros>
30+
3031
_LIBCPP_BEGIN_NAMESPACE_STD
3132

3233
# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
@@ -36,21 +37,17 @@ namespace chrono {
3637

3738
class _LIBCPP_AVAILABILITY_TZDB time_zone {
3839
public:
39-
explicit _LIBCPP_HIDE_FROM_ABI time_zone(string&& __name) : __name_(std::move(__name)) {}
40+
class __impl; // public so it can be used by make_unique.
41+
_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI explicit time_zone(unique_ptr<__impl>&& __p);
42+
_LIBCPP_EXPORTED_FROM_ABI ~time_zone();
4043

41-
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI string_view name() const noexcept { return __name_; }
44+
time_zone(time_zone&&) = default;
45+
time_zone& operator=(time_zone&&) = default;
4246

43-
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI vector<__tz::__continuation>& __continuations() { return __continuations_; }
44-
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI const vector<__tz::__continuation>& __continuations() const {
45-
return __continuations_;
46-
}
47+
_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI string_view name() const noexcept;
4748

4849
private:
49-
string __name_;
50-
// Note the first line has a name + __continuation, the other lines
51-
// are just __continuations. So there is always at least one item in
52-
// the vector.
53-
vector<__tz::__continuation> __continuations_;
50+
unique_ptr<__impl> __impl_;
5451
};
5552

5653
_LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline bool
@@ -70,6 +67,8 @@ operator<=>(const time_zone& __x, const time_zone& __y) noexcept {
7067

7168
_LIBCPP_END_NAMESPACE_STD
7269

70+
_LIBCPP_POP_MACROS
71+
7372
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
7473

7574
#endif // _LIBCPP___CHRONO_TIME_ZONE_H

libcxx/include/__chrono/time_zone_link.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@
2525
# pragma GCC system_header
2626
# endif
2727

28+
_LIBCPP_PUSH_MACROS
29+
# include <__undef_macros>
30+
2831
_LIBCPP_BEGIN_NAMESPACE_STD
2932

3033
# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
3134
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
3235

3336
namespace chrono {
3437

35-
class _LIBCPP_AVAILABILITY_TZDB time_zone_link {
38+
class time_zone_link {
3639
public:
3740
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI explicit time_zone_link(string_view __name, string_view __target)
3841
: __name_{__name}, __target_{__target} {}
@@ -67,6 +70,8 @@ operator<=>(const time_zone_link& __x, const time_zone_link& __y) noexcept {
6770

6871
_LIBCPP_END_NAMESPACE_STD
6972

73+
_LIBCPP_POP_MACROS
74+
7075
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
7176

7277
#endif // _LIBCPP___CHRONO_TIME_ZONE_LINK_H

libcxx/include/__chrono/tzdb.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
// Enable the contents of the header only when libc++ was built with experimental features enabled.
1717
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
1818

19-
# include <__availability>
2019
# include <__chrono/time_zone.h>
2120
# include <__chrono/time_zone_link.h>
22-
# include <__chrono/time_zone_types.h>
2321
# include <__config>
2422
# include <string>
2523
# include <vector>
@@ -28,16 +26,18 @@
2826
# pragma GCC system_header
2927
# endif
3028

29+
_LIBCPP_PUSH_MACROS
30+
# include <__undef_macros>
31+
3132
_LIBCPP_BEGIN_NAMESPACE_STD
3233

3334
# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
3435
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
3536

3637
namespace chrono {
3738

38-
struct _LIBCPP_AVAILABILITY_TZDB tzdb {
39+
struct tzdb {
3940
string version;
40-
vector<pair<string, vector<__tz::__rule>>> __rules;
4141
vector<time_zone> zones;
4242
vector<time_zone_link> links;
4343
};
@@ -49,6 +49,8 @@ struct _LIBCPP_AVAILABILITY_TZDB tzdb {
4949

5050
_LIBCPP_END_NAMESPACE_STD
5151

52+
_LIBCPP_POP_MACROS
53+
5254
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
5355

5456
#endif // _LIBCPP___CHRONO_TZDB_H

libcxx/include/__chrono/tzdb_list.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# include <__availability>
2020
# include <__chrono/tzdb.h>
2121
# include <forward_list>
22-
# include <string_view>
22+
# include <string>
2323

2424
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2525
# pragma GCC system_header
@@ -34,7 +34,8 @@ namespace chrono {
3434

3535
class _LIBCPP_AVAILABILITY_TZDB tzdb_list {
3636
public:
37-
_LIBCPP_EXPORTED_FROM_ABI explicit tzdb_list(tzdb&& __tzdb);
37+
class __impl; // public to allow construction in dylib
38+
_LIBCPP_EXPORTED_FROM_ABI explicit tzdb_list(__impl* __p);
3839
_LIBCPP_EXPORTED_FROM_ABI ~tzdb_list();
3940

4041
tzdb_list(const tzdb_list&) = delete;
@@ -46,16 +47,15 @@ class _LIBCPP_AVAILABILITY_TZDB tzdb_list {
4647

4748
_LIBCPP_EXPORTED_FROM_ABI const_iterator erase_after(const_iterator __p);
4849

49-
_LIBCPP_EXPORTED_FROM_ABI tzdb& __emplace_front(tzdb&& __tzdb);
50-
5150
_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI const_iterator begin() const noexcept;
5251
_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI const_iterator end() const noexcept;
5352

5453
_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI const_iterator cbegin() const noexcept;
5554
_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI const_iterator cend() const noexcept;
5655

56+
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI __impl& __implementation();
57+
5758
private:
58-
class __impl;
5959
__impl* __impl_;
6060
};
6161

libcxx/include/chrono

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,6 @@ constexpr chrono::year operator ""y(unsigned lo
865865
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
866866
# include <__chrono/time_zone.h>
867867
# include <__chrono/time_zone_link.h>
868-
# include <__chrono/time_zone_types.h>
869868
# include <__chrono/tzdb.h>
870869
# include <__chrono/tzdb_list.h>
871870
#endif

libcxx/include/module.modulemap.in

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,10 +1163,6 @@ module std_private_chrono_time_zone_link [system] {
11631163
header "__chrono/time_zone_link.h"
11641164
export *
11651165
}
1166-
module std_private_chrono_time_zone_types [system] {
1167-
header "__chrono/time_zone_types.h"
1168-
export *
1169-
}
11701166
module std_private_chrono_system_clock [system] {
11711167
header "__chrono/system_clock.h"
11721168
export std_private_chrono_time_point

libcxx/src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ endif()
336336

337337
if (LIBCXX_ENABLE_LOCALIZATION AND LIBCXX_ENABLE_FILESYSTEM AND LIBCXX_ENABLE_TIME_ZONE_DATABASE)
338338
list(APPEND LIBCXX_EXPERIMENTAL_SOURCES
339+
include/tzdb/time_zone.h
340+
include/tzdb/types.h
341+
include/tzdb/tz.h
342+
include/tzdb/tzdb_list.h
343+
time_zone.cpp
339344
tz.cpp
340345
tzdb_list.cpp
341346
)

libcxx/src/include/tzdb/time_zone.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html
11+
12+
#ifndef _LIBCPP_SRC_INCLUDE_TZDB_TIME_ZONE_H
13+
#define _LIBCPP_SRC_INCLUDE_TZDB_TIME_ZONE_H
14+
15+
#include <chrono>
16+
#include <string>
17+
#include <vector>
18+
19+
#include "types.h"
20+
21+
_LIBCPP_BEGIN_NAMESPACE_STD
22+
23+
namespace chrono {
24+
25+
class time_zone::__impl {
26+
public:
27+
explicit _LIBCPP_HIDE_FROM_ABI __impl(string&& __name) : __name_(std::move(__name)) {}
28+
29+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_view name() const noexcept { return __name_; }
30+
31+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI vector<__tz::__continuation>& __continuations() { return __continuations_; }
32+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI const vector<__tz::__continuation>& __continuations() const {
33+
return __continuations_;
34+
}
35+
36+
private:
37+
string __name_;
38+
// Note the first line has a name + __continuation, the other lines
39+
// are just __continuations. So there is always at least one item in
40+
// the vector.
41+
vector<__tz::__continuation> __continuations_;
42+
};
43+
44+
} // namespace chrono
45+
46+
_LIBCPP_END_NAMESPACE_STD
47+
48+
#endif // _LIBCPP_SRC_INCLUDE_TZDB_TIME_ZONE_H

libcxx/include/__chrono/time_zone_types.h renamed to libcxx/src/include/tzdb/types.h

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,30 @@
99

1010
// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html
1111

12-
#ifndef _LIBCPP___CHRONO_TIME_ZONE_TYPES_H
13-
#define _LIBCPP___CHRONO_TIME_ZONE_TYPES_H
14-
15-
#include <version>
16-
// Enable the contents of the header only when libc++ was built with experimental features enabled.
17-
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
18-
19-
# include <__chrono/day.h>
20-
# include <__chrono/duration.h>
21-
# include <__chrono/month.h>
22-
# include <__chrono/weekday.h>
23-
# include <__chrono/year.h>
24-
# include <__config>
25-
# include <string>
26-
# include <variant>
27-
28-
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29-
# pragma GCC system_header
30-
# endif
12+
#ifndef __LIBCPP_SRC_INCLUDE_TZDB_TYPES_H
13+
#define __LIBCPP_SRC_INCLUDE_TZDB_TYPES_H
14+
15+
#include <chrono>
16+
#include <string>
17+
#include <utility>
18+
#include <variant>
19+
#include <vector>
3120

3221
_LIBCPP_BEGIN_NAMESPACE_STD
3322

34-
# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
35-
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
23+
// TODO TZDB
24+
// The helper classes in this header have no constructor but are loaded with
25+
// dedicated parse functions. In the original design this header was public and
26+
// the parsing is done in the dylib. In that design having constructors would
27+
// expand the ABI interface. Since this header is now in the dylib that design
28+
// should be reconsidered. (For now the design is kept as is, in case this
29+
// header needs to be public for unforseen reasons.)
3630

3731
namespace chrono::__tz {
3832

3933
// Sun>=8 first Sunday on or after the eighth
4034
// Sun<=25 last Sunday on or before the 25th
41-
struct _LIBCPP_AVAILABILITY_TZDB __constrained_weekday {
35+
struct __constrained_weekday {
4236
/* year_month_day operator()(year __year, month __month);*/ // needed but not implemented
4337

4438
weekday __weekday;
@@ -54,30 +48,35 @@ struct _LIBCPP_AVAILABILITY_TZDB __constrained_weekday {
5448
// Sun<=25 last Sunday on or before the 25th
5549
using __on = variant<day, weekday_last, __constrained_weekday>;
5650

57-
enum class _LIBCPP_AVAILABILITY_TZDB __clock { __local, __standard, __universal };
51+
enum class __clock { __local, __standard, __universal };
5852

59-
struct _LIBCPP_AVAILABILITY_TZDB __at {
53+
struct __at {
6054
seconds __time{0};
6155
__tz::__clock __clock{__tz::__clock::__local};
6256
};
6357

64-
struct _LIBCPP_AVAILABILITY_TZDB __save {
58+
struct __save {
6559
seconds __time;
6660
bool __is_dst;
6761
};
6862

6963
// The names of the fields match the fields of a Rule.
70-
struct _LIBCPP_AVAILABILITY_TZDB __rule {
64+
struct __rule {
7165
year __from;
7266
year __to;
73-
month __in_month; // __in is a reserved name
67+
month __in;
7468
__tz::__on __on;
7569
__tz::__at __at;
7670
__tz::__save __save;
7771
string __letters;
7872
};
7973

80-
struct _LIBCPP_AVAILABILITY_TZDB __continuation {
74+
using __rules_storage_type = std::vector<std::pair<string, vector<__tz::__rule>>>; // TODO TZDB use flat_map;
75+
76+
struct __continuation {
77+
// Non-owning link to the RULE entries.
78+
__tz::__rules_storage_type* __rule_database_;
79+
8180
seconds __stdoff;
8281

8382
// The RULES is either a SAVE or a NAME.
@@ -95,18 +94,13 @@ struct _LIBCPP_AVAILABILITY_TZDB __continuation {
9594
// Parts of the UNTIL, the optional parts are default initialized
9695
// optional<year> __until_;
9796
year __year = chrono::year::min();
98-
month __in_month{January}; // __in is a reserved name
97+
month __in{January};
9998
__tz::__on __on{chrono::day{1}};
10099
__tz::__at __at{chrono::seconds{0}, __tz::__clock::__local};
101100
};
102101

103102
} // namespace chrono::__tz
104103

105-
# endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
106-
// && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
107-
108104
_LIBCPP_END_NAMESPACE_STD
109105

110-
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
111-
112-
#endif // _LIBCPP___CHRONO_TIME_ZONE_TYPES_H
106+
#endif // __LIBCPP_SRC_INCLUDE_TZDB_TYPES_H

0 commit comments

Comments
 (0)