Skip to content

Commit e23f858

Browse files
Anton Likhtarovmeta-codesync[bot]
authored andcommitted
Make carbon-generated Messages headers self-contained
Summary: X-link: facebookresearch/DCPerf#631 `Messages-inl.h` is not "self-contained", meaning a .cpp file that only includes it will fail to compile. This blocks some build time optimizations like C++20 header units. -inl.h are discouraged for that reason (https://www.internalfb.com/wiki/Cpp/CppCodingConventions#avoid-using-inl-h-files), and the proper way is to just list all templates directly in the including file. But we can make a narrow change instead to avoid large scale code movements. Introduce `Messages-decl.h` (declarations only) so that both `Messages.h` and `Messages-inl.h` are self-contained: - `Messages-decl.h`: declarations, type traits, free function forward declarations. Identical to the current `Messages.h` without the last `#include "Messages-inl.h"` line. - `Messages-inl.h`: adds `#pragma once` and `#include "Messages-decl.h"` at top, otherwise unchanged - `Messages.h`: thin wrapper that includes `-decl.h` and `-inl.h` Reviewed By: IvanTopolcic Differential Revision: D106002540 fbshipit-source-id: 3153f0adb2325293e5b50159aca8609c7fa0dd17
1 parent 76c5472 commit e23f858

24 files changed

Lines changed: 3313 additions & 3153 deletions
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the LICENSE
5+
* file in the root directory of this source tree.
6+
*
7+
*/
8+
9+
/*
10+
* THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN
11+
* VAIN.
12+
*
13+
* @generated
14+
*/
15+
#pragma once
16+
17+
#include <memory>
18+
#include <string>
19+
#include <utility>
20+
21+
#include <folly/Optional.h>
22+
#include <folly/io/IOBuf.h>
23+
#include <mcrouter/lib/carbon/CarbonProtocolReader.h>
24+
#include <mcrouter/lib/carbon/CommonSerializationTraits.h>
25+
#include <mcrouter/lib/carbon/Keys.h>
26+
#include <mcrouter/lib/carbon/ReplyCommon.h>
27+
#include <mcrouter/lib/carbon/RequestCommon.h>
28+
#include <mcrouter/lib/carbon/RequestReplyUtil.h>
29+
#include <mcrouter/lib/carbon/Result.h>
30+
#include <mcrouter/lib/carbon/TypeList.h>
31+
#include <mcrouter/lib/carbon/Variant.h>
32+
33+
#include "mcrouter/lib/carbon/example/gen/gen-cpp2/HelloGoodbye_types.h"
34+
35+
#include "mcrouter/lib/network/gen/CommonMessages.h"
36+
37+
namespace hellogoodbye {
38+
39+
using EnumUInt32 = hellogoodbye::thrift::EnumUInt32;
40+
41+
std::string enumEnumUInt32ToString(EnumUInt32 val);
42+
43+
class HelloReply;
44+
45+
class HelloRequest : public carbon::RequestCommon, public hellogoodbye::thrift::HelloRequest {
46+
public:
47+
using reply_type = HelloReply;
48+
49+
static constexpr size_t typeId = 65;
50+
static constexpr const char* name = "hello";
51+
static constexpr const char* idlName = "HelloGoodbye";
52+
53+
HelloRequest() = default;
54+
HelloRequest(const HelloRequest&) = default;
55+
HelloRequest& operator=(const HelloRequest&) = default;
56+
HelloRequest(HelloRequest&&) = default;
57+
HelloRequest& operator=(HelloRequest&&) = default;
58+
explicit HelloRequest(folly::StringPiece sp) {
59+
key_ref() = sp;
60+
}
61+
explicit HelloRequest(folly::IOBuf&& carbonKey) {
62+
key_ref() = std::move(carbonKey);
63+
}
64+
65+
friend class apache::thrift::Cpp2Ops<HelloRequest>;
66+
67+
};
68+
69+
class HelloReply : public carbon::ReplyCommon, public hellogoodbye::thrift::HelloReply {
70+
public:
71+
72+
static constexpr size_t typeId = 66;
73+
74+
HelloReply() = default;
75+
HelloReply(const HelloReply&) = default;
76+
HelloReply& operator=(const HelloReply&) = default;
77+
HelloReply(HelloReply&&) = default;
78+
HelloReply& operator=(HelloReply&&) = default;
79+
explicit HelloReply(carbon::Result carbonResult) {
80+
result_ref() = carbonResult;
81+
}
82+
83+
friend class apache::thrift::Cpp2Ops<HelloReply>;
84+
85+
};
86+
87+
class GoodbyeReply;
88+
89+
class GoodbyeRequest : public carbon::RequestCommon, public hellogoodbye::thrift::GoodbyeRequest {
90+
public:
91+
using reply_type = GoodbyeReply;
92+
93+
static constexpr size_t typeId = 67;
94+
static constexpr const char* name = "goodbye";
95+
static constexpr const char* idlName = "HelloGoodbye";
96+
97+
GoodbyeRequest() = default;
98+
GoodbyeRequest(const GoodbyeRequest&) = default;
99+
GoodbyeRequest& operator=(const GoodbyeRequest&) = default;
100+
GoodbyeRequest(GoodbyeRequest&&) = default;
101+
GoodbyeRequest& operator=(GoodbyeRequest&&) = default;
102+
explicit GoodbyeRequest(folly::StringPiece sp) {
103+
key_ref() = sp;
104+
}
105+
explicit GoodbyeRequest(folly::IOBuf&& carbonKey) {
106+
key_ref() = std::move(carbonKey);
107+
}
108+
109+
friend class apache::thrift::Cpp2Ops<GoodbyeRequest>;
110+
111+
};
112+
113+
class GoodbyeReply : public carbon::ReplyCommon, public hellogoodbye::thrift::GoodbyeReply {
114+
public:
115+
116+
static constexpr size_t typeId = 68;
117+
118+
GoodbyeReply() = default;
119+
GoodbyeReply(const GoodbyeReply&) = default;
120+
GoodbyeReply& operator=(const GoodbyeReply&) = default;
121+
GoodbyeReply(GoodbyeReply&&) = default;
122+
GoodbyeReply& operator=(GoodbyeReply&&) = default;
123+
explicit GoodbyeReply(carbon::Result carbonResult) {
124+
result_ref() = carbonResult;
125+
}
126+
127+
friend class apache::thrift::Cpp2Ops<GoodbyeReply>;
128+
129+
};
130+
131+
} // namespace hellogoodbye
132+
133+
namespace carbon {
134+
template <>
135+
struct IsCarbonStruct<::hellogoodbye::HelloRequest> : std::true_type {};
136+
137+
template <>
138+
struct IsCarbonStruct<::hellogoodbye::HelloReply> : std::true_type {};
139+
140+
template <>
141+
struct IsCarbonStruct<::hellogoodbye::GoodbyeRequest> : std::true_type {};
142+
143+
template <>
144+
struct IsCarbonStruct<::hellogoodbye::GoodbyeReply> : std::true_type {};
145+
} // namespace carbon
146+
147+
namespace hellogoodbye {
148+
namespace thrift {
149+
150+
template <class Writer>
151+
void serialize(const HelloRequest& self, Writer&& writer);
152+
153+
void deserialize(HelloRequest& self, carbon::CarbonProtocolReader& reader);
154+
155+
template <class V>
156+
void visitFields(HelloRequest& self, V&& v);
157+
158+
template <class V>
159+
void visitFields(const HelloRequest& self, V&& v);
160+
161+
template <class Writer>
162+
void serialize(const HelloReply& self, Writer&& writer);
163+
164+
void deserialize(HelloReply& self, carbon::CarbonProtocolReader& reader);
165+
166+
template <class V>
167+
void visitFields(HelloReply& self, V&& v);
168+
169+
template <class V>
170+
void visitFields(const HelloReply& self, V&& v);
171+
172+
template <class Writer>
173+
void serialize(const GoodbyeRequest& self, Writer&& writer);
174+
175+
void deserialize(GoodbyeRequest& self, carbon::CarbonProtocolReader& reader);
176+
177+
template <class V>
178+
void visitFields(GoodbyeRequest& self, V&& v);
179+
180+
template <class V>
181+
void visitFields(const GoodbyeRequest& self, V&& v);
182+
183+
template <class Writer>
184+
void serialize(const GoodbyeReply& self, Writer&& writer);
185+
186+
void deserialize(GoodbyeReply& self, carbon::CarbonProtocolReader& reader);
187+
188+
template <class V>
189+
void visitFields(GoodbyeReply& self, V&& v);
190+
191+
template <class V>
192+
void visitFields(const GoodbyeReply& self, V&& v);
193+
} // namespace thrift
194+
} // namespace hellogoodbye

‎mcrouter/lib/carbon/example/gen/HelloGoodbyeMessages-inl.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
*
1313
* @generated
1414
*/
15+
#pragma once
16+
17+
#include "mcrouter/lib/carbon/example/gen/HelloGoodbyeMessages-decl.h"
1518

1619
namespace hellogoodbye {
1720
namespace thrift {

‎mcrouter/lib/carbon/example/gen/HelloGoodbyeMessages.h‎

Lines changed: 2 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -14,182 +14,5 @@
1414
*/
1515
#pragma once
1616

17-
#include <memory>
18-
#include <string>
19-
#include <utility>
20-
21-
#include <folly/Optional.h>
22-
#include <folly/io/IOBuf.h>
23-
#include <mcrouter/lib/carbon/CarbonProtocolReader.h>
24-
#include <mcrouter/lib/carbon/CommonSerializationTraits.h>
25-
#include <mcrouter/lib/carbon/Keys.h>
26-
#include <mcrouter/lib/carbon/ReplyCommon.h>
27-
#include <mcrouter/lib/carbon/RequestCommon.h>
28-
#include <mcrouter/lib/carbon/RequestReplyUtil.h>
29-
#include <mcrouter/lib/carbon/Result.h>
30-
#include <mcrouter/lib/carbon/TypeList.h>
31-
#include <mcrouter/lib/carbon/Variant.h>
32-
33-
#include "mcrouter/lib/carbon/example/gen/gen-cpp2/HelloGoodbye_types.h"
34-
35-
#include "mcrouter/lib/network/gen/CommonMessages.h"
36-
37-
namespace hellogoodbye {
38-
39-
using EnumUInt32 = hellogoodbye::thrift::EnumUInt32;
40-
41-
std::string enumEnumUInt32ToString(EnumUInt32 val);
42-
43-
class HelloReply;
44-
45-
class HelloRequest : public carbon::RequestCommon, public hellogoodbye::thrift::HelloRequest {
46-
public:
47-
using reply_type = HelloReply;
48-
49-
static constexpr size_t typeId = 65;
50-
static constexpr const char* name = "hello";
51-
static constexpr const char* idlName = "HelloGoodbye";
52-
53-
HelloRequest() = default;
54-
HelloRequest(const HelloRequest&) = default;
55-
HelloRequest& operator=(const HelloRequest&) = default;
56-
HelloRequest(HelloRequest&&) = default;
57-
HelloRequest& operator=(HelloRequest&&) = default;
58-
explicit HelloRequest(folly::StringPiece sp) {
59-
key_ref() = sp;
60-
}
61-
explicit HelloRequest(folly::IOBuf&& carbonKey) {
62-
key_ref() = std::move(carbonKey);
63-
}
64-
65-
friend class apache::thrift::Cpp2Ops<HelloRequest>;
66-
67-
};
68-
69-
class HelloReply : public carbon::ReplyCommon, public hellogoodbye::thrift::HelloReply {
70-
public:
71-
72-
static constexpr size_t typeId = 66;
73-
74-
HelloReply() = default;
75-
HelloReply(const HelloReply&) = default;
76-
HelloReply& operator=(const HelloReply&) = default;
77-
HelloReply(HelloReply&&) = default;
78-
HelloReply& operator=(HelloReply&&) = default;
79-
explicit HelloReply(carbon::Result carbonResult) {
80-
result_ref() = carbonResult;
81-
}
82-
83-
friend class apache::thrift::Cpp2Ops<HelloReply>;
84-
85-
};
86-
87-
class GoodbyeReply;
88-
89-
class GoodbyeRequest : public carbon::RequestCommon, public hellogoodbye::thrift::GoodbyeRequest {
90-
public:
91-
using reply_type = GoodbyeReply;
92-
93-
static constexpr size_t typeId = 67;
94-
static constexpr const char* name = "goodbye";
95-
static constexpr const char* idlName = "HelloGoodbye";
96-
97-
GoodbyeRequest() = default;
98-
GoodbyeRequest(const GoodbyeRequest&) = default;
99-
GoodbyeRequest& operator=(const GoodbyeRequest&) = default;
100-
GoodbyeRequest(GoodbyeRequest&&) = default;
101-
GoodbyeRequest& operator=(GoodbyeRequest&&) = default;
102-
explicit GoodbyeRequest(folly::StringPiece sp) {
103-
key_ref() = sp;
104-
}
105-
explicit GoodbyeRequest(folly::IOBuf&& carbonKey) {
106-
key_ref() = std::move(carbonKey);
107-
}
108-
109-
friend class apache::thrift::Cpp2Ops<GoodbyeRequest>;
110-
111-
};
112-
113-
class GoodbyeReply : public carbon::ReplyCommon, public hellogoodbye::thrift::GoodbyeReply {
114-
public:
115-
116-
static constexpr size_t typeId = 68;
117-
118-
GoodbyeReply() = default;
119-
GoodbyeReply(const GoodbyeReply&) = default;
120-
GoodbyeReply& operator=(const GoodbyeReply&) = default;
121-
GoodbyeReply(GoodbyeReply&&) = default;
122-
GoodbyeReply& operator=(GoodbyeReply&&) = default;
123-
explicit GoodbyeReply(carbon::Result carbonResult) {
124-
result_ref() = carbonResult;
125-
}
126-
127-
friend class apache::thrift::Cpp2Ops<GoodbyeReply>;
128-
129-
};
130-
131-
} // namespace hellogoodbye
132-
133-
namespace carbon {
134-
template <>
135-
struct IsCarbonStruct<::hellogoodbye::HelloRequest> : std::true_type {};
136-
137-
template <>
138-
struct IsCarbonStruct<::hellogoodbye::HelloReply> : std::true_type {};
139-
140-
template <>
141-
struct IsCarbonStruct<::hellogoodbye::GoodbyeRequest> : std::true_type {};
142-
143-
template <>
144-
struct IsCarbonStruct<::hellogoodbye::GoodbyeReply> : std::true_type {};
145-
} // namespace carbon
146-
147-
namespace hellogoodbye {
148-
namespace thrift {
149-
150-
template <class Writer>
151-
void serialize(const HelloRequest& self, Writer&& writer);
152-
153-
void deserialize(HelloRequest& self, carbon::CarbonProtocolReader& reader);
154-
155-
template <class V>
156-
void visitFields(HelloRequest& self, V&& v);
157-
158-
template <class V>
159-
void visitFields(const HelloRequest& self, V&& v);
160-
161-
template <class Writer>
162-
void serialize(const HelloReply& self, Writer&& writer);
163-
164-
void deserialize(HelloReply& self, carbon::CarbonProtocolReader& reader);
165-
166-
template <class V>
167-
void visitFields(HelloReply& self, V&& v);
168-
169-
template <class V>
170-
void visitFields(const HelloReply& self, V&& v);
171-
172-
template <class Writer>
173-
void serialize(const GoodbyeRequest& self, Writer&& writer);
174-
175-
void deserialize(GoodbyeRequest& self, carbon::CarbonProtocolReader& reader);
176-
177-
template <class V>
178-
void visitFields(GoodbyeRequest& self, V&& v);
179-
180-
template <class V>
181-
void visitFields(const GoodbyeRequest& self, V&& v);
182-
183-
template <class Writer>
184-
void serialize(const GoodbyeReply& self, Writer&& writer);
185-
186-
void deserialize(GoodbyeReply& self, carbon::CarbonProtocolReader& reader);
187-
188-
template <class V>
189-
void visitFields(GoodbyeReply& self, V&& v);
190-
191-
template <class V>
192-
void visitFields(const GoodbyeReply& self, V&& v);
193-
} // namespace thrift
194-
} // namespace hellogoodbye
195-
#include "HelloGoodbyeMessages-inl.h"
17+
#include "mcrouter/lib/carbon/example/gen/HelloGoodbyeMessages-decl.h"
18+
#include "mcrouter/lib/carbon/example/gen/HelloGoodbyeMessages-inl.h"

0 commit comments

Comments
 (0)