Skip to content

Commit ceb74cd

Browse files
authored
style: use type aliases (envoyproxy#11601)
Risk Level: Low Testing: Docs Changes: Release Notes: Fixes envoyproxy#11535 Signed-off-by: tomocy <[email protected]>
1 parent 83433ae commit ceb74cd

32 files changed

+74
-59
lines changed

api/bazel/repository_locations.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ REPOSITORY_LOCATIONS = dict(
3333
urls = ["https://github.com/envoyproxy/protoc-gen-validate/archive/" + PGV_GIT_SHA + ".tar.gz"],
3434
),
3535
com_google_googleapis = dict(
36-
# TODO(dio): Consider writing a Skylark macro for importing Google API proto.
36+
# TODO(dio): Consider writing a Starlark macro for importing Google API proto.
3737
sha256 = GOOGLEAPIS_SHA,
3838
strip_prefix = "googleapis-" + GOOGLEAPIS_GIT_SHA,
3939
urls = ["https://github.com/googleapis/googleapis/archive/" + GOOGLEAPIS_GIT_SHA + ".tar.gz"],

bazel/envoy_library.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def tcmalloc_external_deps(repository):
2121

2222
# Envoy C++ library targets that need no transformations or additional dependencies before being
2323
# passed to cc_library should be specified with this function. Note: this exists to ensure that
24-
# all envoy targets pass through an envoy-declared skylark function where they can be modified
24+
# all envoy targets pass through an envoy-declared starlark function where they can be modified
2525
# before being passed to a native bazel function.
2626
def envoy_basic_cc_library(name, deps = [], external_deps = [], **kargs):
2727
cc_library(

bazel/genrule_repository.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _genrule_cc_deps(ctx):
6868
genrule_cc_deps = rule(
6969
attrs = {
7070
"deps": attr.label_list(
71-
providers = [], # CcSkylarkApiProvider
71+
providers = [], # CcStarlarkApiProvider
7272
mandatory = True,
7373
allow_empty = False,
7474
),

generated_api_shadow/bazel/repository_locations.bzl

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

include/envoy/network/filter.h

+2
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ class DrainableFilterChain : public FilterChain {
356356
virtual void startDraining() PURE;
357357
};
358358

359+
using DrainableFilterChainSharedPtr = std::shared_ptr<DrainableFilterChain>;
360+
359361
/**
360362
* Interface for searching through configured filter chains.
361363
*/

include/envoy/runtime/runtime.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ class Snapshot {
257257
virtual const std::vector<OverrideLayerConstPtr>& getLayers() const PURE;
258258
};
259259

260+
using SnapshotConstSharedPtr = std::shared_ptr<const Snapshot>;
261+
260262
/**
261263
* Loads runtime snapshots from storage (local disk, etc.).
262264
*/
@@ -285,7 +287,7 @@ class Loader {
285287
* @return shared_ptr<const Snapshot> the current snapshot. This function may safely be called
286288
* from non-worker threads.
287289
*/
288-
virtual std::shared_ptr<const Snapshot> threadsafeSnapshot() PURE;
290+
virtual SnapshotConstSharedPtr threadsafeSnapshot() PURE;
289291

290292
/**
291293
* Merge the given map of key-value pairs into the runtime's state. To remove a previous merge for

include/envoy/server/factory_context.h

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <functional>
4+
#include <memory>
45

56
#include "envoy/access_log/access_log.h"
67
#include "envoy/config/core/v3/base.pb.h"

include/envoy/stream_info/filter_state.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
namespace Envoy {
1616
namespace StreamInfo {
1717

18+
class FilterState;
19+
20+
using FilterStateSharedPtr = std::shared_ptr<FilterState>;
21+
1822
/**
1923
* FilterState represents dynamically generated information regarding a stream (TCP or HTTP level)
2024
* or a connection by various filters in Envoy. FilterState can be write-once or write-many.
@@ -146,14 +150,12 @@ class FilterState {
146150
* @return the pointer of the parent FilterState that has longer life span. nullptr means this is
147151
* either the top LifeSpan or the parent is not yet created.
148152
*/
149-
virtual std::shared_ptr<FilterState> parent() const PURE;
153+
virtual FilterStateSharedPtr parent() const PURE;
150154

151155
protected:
152156
virtual const Object* getDataReadOnlyGeneric(absl::string_view data_name) const PURE;
153157
virtual Object* getDataMutableGeneric(absl::string_view data_name) PURE;
154158
};
155159

156-
using FilterStateSharedPtr = std::shared_ptr<FilterState>;
157-
158160
} // namespace StreamInfo
159161
} // namespace Envoy

source/common/grpc/google_async_client_impl.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <memory>
34
#include <queue>
45

56
#include "envoy/api/api.h"
@@ -128,6 +129,8 @@ class GoogleStub {
128129
grpc::CompletionQueue* cq) PURE;
129130
};
130131

132+
using GoogleStubSharedPtr = std::shared_ptr<GoogleStub>;
133+
131134
class GoogleGenericStub : public GoogleStub {
132135
public:
133136
GoogleGenericStub(std::shared_ptr<grpc::Channel> channel) : stub_(channel) {}
@@ -148,12 +151,12 @@ class GoogleStubFactory {
148151
virtual ~GoogleStubFactory() = default;
149152

150153
// Create a stub from a given channel.
151-
virtual std::shared_ptr<GoogleStub> createStub(std::shared_ptr<grpc::Channel> channel) PURE;
154+
virtual GoogleStubSharedPtr createStub(std::shared_ptr<grpc::Channel> channel) PURE;
152155
};
153156

154157
class GoogleGenericStubFactory : public GoogleStubFactory {
155158
public:
156-
std::shared_ptr<GoogleStub> createStub(std::shared_ptr<grpc::Channel> channel) override {
159+
GoogleStubSharedPtr createStub(std::shared_ptr<grpc::Channel> channel) override {
157160
return std::make_shared<GoogleGenericStub>(channel);
158161
}
159162
};
@@ -185,7 +188,7 @@ class GoogleAsyncClientImpl final : public RawAsyncClient, Logger::Loggable<Logg
185188
// This is shared with child streams, so that they can cleanup independent of
186189
// the client if it gets destructed. The streams need to wait for their tags
187190
// to drain from the CQ.
188-
std::shared_ptr<GoogleStub> stub_;
191+
GoogleStubSharedPtr stub_;
189192
std::list<std::unique_ptr<GoogleAsyncStreamImpl>> active_streams_;
190193
const std::string stat_prefix_;
191194
const Protobuf::RepeatedPtrField<envoy::config::core::v3::HeaderValue> initial_metadata_;
@@ -272,7 +275,7 @@ class GoogleAsyncStreamImpl : public RawAsyncStream,
272275
Event::Dispatcher& dispatcher_;
273276
// We hold a ref count on the stub_ to allow the stream to wait for its tags
274277
// to drain from the CQ on cleanup.
275-
std::shared_ptr<GoogleStub> stub_;
278+
GoogleStubSharedPtr stub_;
276279
std::string service_full_name_;
277280
std::string method_name_;
278281
RawAsyncStreamCallbacks& callbacks_;

source/common/router/scoped_config_impl.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ ScopeKeyBuilderImpl::ScopeKeyBuilderImpl(ScopedRoutes::ScopeKeyBuilder&& config)
103103
}
104104
}
105105

106-
std::unique_ptr<ScopeKey>
107-
ScopeKeyBuilderImpl::computeScopeKey(const Http::HeaderMap& headers) const {
106+
ScopeKeyPtr ScopeKeyBuilderImpl::computeScopeKey(const Http::HeaderMap& headers) const {
108107
ScopeKey key;
109108
for (const auto& builder : fragment_builders_) {
110109
// returns nullopt if a null fragment is found.
@@ -139,7 +138,7 @@ void ScopedConfigImpl::removeRoutingScope(const std::string& scope_name) {
139138

140139
Router::ConfigConstSharedPtr
141140
ScopedConfigImpl::getRouteConfig(const Http::HeaderMap& headers) const {
142-
std::unique_ptr<ScopeKey> scope_key = scope_key_builder_.computeScopeKey(headers);
141+
ScopeKeyPtr scope_key = scope_key_builder_.computeScopeKey(headers);
143142
if (scope_key == nullptr) {
144143
return nullptr;
145144
}

source/common/router/scoped_config_impl.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <memory>
34
#include <typeinfo>
45

56
#include "envoy/config/route/v3/scoped_route.pb.h"
@@ -77,6 +78,8 @@ class ScopeKey {
7778
std::vector<std::unique_ptr<ScopeKeyFragmentBase>> fragments_;
7879
};
7980

81+
using ScopeKeyPtr = std::unique_ptr<ScopeKey>;
82+
8083
// String fragment.
8184
class StringKeyFragment : public ScopeKeyFragmentBase {
8285
public:
@@ -130,7 +133,7 @@ class ScopeKeyBuilderBase {
130133
virtual ~ScopeKeyBuilderBase() = default;
131134

132135
// Computes scope key for given headers, returns nullptr if a key can't be computed.
133-
virtual std::unique_ptr<ScopeKey> computeScopeKey(const Http::HeaderMap& headers) const PURE;
136+
virtual ScopeKeyPtr computeScopeKey(const Http::HeaderMap& headers) const PURE;
134137

135138
protected:
136139
const ScopedRoutes::ScopeKeyBuilder config_;
@@ -140,7 +143,7 @@ class ScopeKeyBuilderImpl : public ScopeKeyBuilderBase {
140143
public:
141144
explicit ScopeKeyBuilderImpl(ScopedRoutes::ScopeKeyBuilder&& config);
142145

143-
std::unique_ptr<ScopeKey> computeScopeKey(const Http::HeaderMap& headers) const override;
146+
ScopeKeyPtr computeScopeKey(const Http::HeaderMap& headers) const override;
144147

145148
private:
146149
std::vector<std::unique_ptr<FragmentBuilderBase>> fragment_builders_;

source/common/runtime/runtime_impl.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ const Snapshot& LoaderImpl::snapshot() {
604604
return tls_->getTyped<Snapshot>();
605605
}
606606

607-
std::shared_ptr<const Snapshot> LoaderImpl::threadsafeSnapshot() {
607+
SnapshotConstSharedPtr LoaderImpl::threadsafeSnapshot() {
608608
if (tls_->currentThreadRegistered()) {
609609
return std::dynamic_pointer_cast<const Snapshot>(tls_->get());
610610
}
@@ -630,7 +630,7 @@ RuntimeStats LoaderImpl::generateStats(Stats::Store& store) {
630630
return stats;
631631
}
632632

633-
std::unique_ptr<SnapshotImpl> LoaderImpl::createNewSnapshot() {
633+
SnapshotImplPtr LoaderImpl::createNewSnapshot() {
634634
std::vector<Snapshot::OverrideLayerConstPtr> layers;
635635
uint32_t disk_layers = 0;
636636
uint32_t error_layers = 0;

source/common/runtime/runtime_impl.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ class SnapshotImpl : public Snapshot,
130130
RuntimeStats& stats_;
131131
};
132132

133+
using SnapshotImplPtr = std::unique_ptr<SnapshotImpl>;
134+
133135
/**
134136
* Base implementation of OverrideLayer that by itself provides an empty values map.
135137
*/
@@ -252,15 +254,15 @@ class LoaderImpl : public Loader, Logger::Loggable<Logger::Id::runtime> {
252254
// Runtime::Loader
253255
void initialize(Upstream::ClusterManager& cm) override;
254256
const Snapshot& snapshot() override;
255-
std::shared_ptr<const Snapshot> threadsafeSnapshot() override;
257+
SnapshotConstSharedPtr threadsafeSnapshot() override;
256258
void mergeValues(const std::unordered_map<std::string, std::string>& values) override;
257259
void startRtdsSubscriptions(ReadyCallback on_done) override;
258260

259261
private:
260262
friend RtdsSubscription;
261263

262264
// Create a new Snapshot
263-
virtual std::unique_ptr<SnapshotImpl> createNewSnapshot();
265+
virtual SnapshotImplPtr createNewSnapshot();
264266
// Load a new Snapshot into TLS
265267
void loadNewSnapshot();
266268
RuntimeStats generateStats(Stats::Store& store);
@@ -281,7 +283,7 @@ class LoaderImpl : public Loader, Logger::Loggable<Logger::Id::runtime> {
281283
Upstream::ClusterManager* cm_{};
282284

283285
absl::Mutex snapshot_mutex_;
284-
std::shared_ptr<const Snapshot> thread_safe_snapshot_ ABSL_GUARDED_BY(snapshot_mutex_);
286+
SnapshotConstSharedPtr thread_safe_snapshot_ ABSL_GUARDED_BY(snapshot_mutex_);
285287
};
286288

287289
} // namespace Runtime

source/common/stream_info/filter_state_impl.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ void FilterStateImpl::maybeCreateParent(ParentAccessMode parent_access_mode) {
9797
if (life_span_ >= FilterState::LifeSpan::TopSpan) {
9898
return;
9999
}
100-
if (absl::holds_alternative<std::shared_ptr<FilterState>>(ancestor_)) {
101-
std::shared_ptr<FilterState> ancestor = absl::get<std::shared_ptr<FilterState>>(ancestor_);
100+
if (absl::holds_alternative<FilterStateSharedPtr>(ancestor_)) {
101+
FilterStateSharedPtr ancestor = absl::get<FilterStateSharedPtr>(ancestor_);
102102
if (ancestor == nullptr || ancestor->lifeSpan() != life_span_ + 1) {
103103
parent_ = std::make_shared<FilterStateImpl>(ancestor, FilterState::LifeSpan(life_span_ + 1));
104104
} else {

source/common/stream_info/filter_state_impl.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ class FilterStateImpl : public FilterState {
2222
* @param ancestor a std::shared_ptr storing an already created ancestor.
2323
* @param life_span the life span this is handling.
2424
*/
25-
FilterStateImpl(std::shared_ptr<FilterState> ancestor, FilterState::LifeSpan life_span)
25+
FilterStateImpl(FilterStateSharedPtr ancestor, FilterState::LifeSpan life_span)
2626
: ancestor_(ancestor), life_span_(life_span) {
2727
maybeCreateParent(ParentAccessMode::ReadOnly);
2828
}
2929

30-
using LazyCreateAncestor = std::pair<std::shared_ptr<FilterState>&, FilterState::LifeSpan>;
30+
using LazyCreateAncestor = std::pair<FilterStateSharedPtr&, FilterState::LifeSpan>;
3131
/**
3232
* @param ancestor a std::pair storing an ancestor, that can be passed in as a way to lazy
3333
* initialize a FilterState that's owned by an object with bigger scope than this. This is to
@@ -49,7 +49,7 @@ class FilterStateImpl : public FilterState {
4949
bool hasDataAtOrAboveLifeSpan(FilterState::LifeSpan life_span) const override;
5050

5151
FilterState::LifeSpan lifeSpan() const override { return life_span_; }
52-
std::shared_ptr<FilterState> parent() const override { return parent_; }
52+
FilterStateSharedPtr parent() const override { return parent_; }
5353

5454
private:
5555
// This only checks the local data_storage_ for data_name existence.
@@ -62,8 +62,8 @@ class FilterStateImpl : public FilterState {
6262
FilterState::StateType state_type_;
6363
};
6464

65-
absl::variant<std::shared_ptr<FilterState>, LazyCreateAncestor> ancestor_;
66-
std::shared_ptr<FilterState> parent_;
65+
absl::variant<FilterStateSharedPtr, LazyCreateAncestor> ancestor_;
66+
FilterStateSharedPtr parent_;
6767
const FilterState::LifeSpan life_span_;
6868
absl::flat_hash_map<std::string, std::unique_ptr<FilterObject>> data_storage_;
6969
};

source/common/stream_info/stream_info_impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct StreamInfoImpl : public StreamInfo {
2727
std::make_shared<FilterStateImpl>(FilterState::LifeSpan::FilterChain)) {}
2828

2929
StreamInfoImpl(Http::Protocol protocol, TimeSource& time_source,
30-
std::shared_ptr<FilterState>& parent_filter_state)
30+
FilterStateSharedPtr& parent_filter_state)
3131
: StreamInfoImpl(protocol, time_source,
3232
std::make_shared<FilterStateImpl>(
3333
FilterStateImpl::LazyCreateAncestor(parent_filter_state,

source/extensions/common/wasm/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ envoy_cc_library(
2121
hdrs = ["wasm_vm.h"],
2222
deps = [
2323
":well_known_names",
24+
"//include/envoy/stats:stats_interface",
2425
"//source/common/common:minimal_logger_lib",
2526
],
2627
)

source/extensions/common/wasm/null/null_vm.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct NullVm : public WasmVmBase {
5555
#undef _REGISTER_CALLBACK
5656

5757
std::string plugin_name_;
58-
std::unique_ptr<NullVmPlugin> plugin_;
58+
NullVmPluginPtr plugin_;
5959
};
6060

6161
} // namespace Null

source/extensions/common/wasm/null/null_vm_plugin.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <memory>
4+
35
#include "envoy/config/typed_config.h"
46

57
#include "extensions/common/wasm/wasm_vm.h"
@@ -24,6 +26,8 @@ class NullVmPlugin {
2426
#undef _DEFIN_GET_FUNCTIONE
2527
};
2628

29+
using NullVmPluginPtr = std::unique_ptr<NullVmPlugin>;
30+
2731
/**
2832
* Pseudo-WASM plugins using the NullVM should implement this factory and register via
2933
* Registry::registerFactory or the convenience class RegisterFactory.
@@ -37,7 +41,7 @@ class NullVmPluginFactory : public Config::UntypedFactory {
3741
/**
3842
* Create an instance of the plugin.
3943
*/
40-
virtual std::unique_ptr<NullVmPlugin> create() const PURE;
44+
virtual NullVmPluginPtr create() const PURE;
4145
};
4246

4347
} // namespace Null

source/server/filter_chain_factory_context_callback.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class FilterChainFactoryContextCreator {
2121
* Generate the filter chain factory context from proto. Note the caller does not own the filter
2222
* chain context.
2323
*/
24-
virtual std::unique_ptr<Configuration::FilterChainFactoryContext> createFilterChainFactoryContext(
24+
virtual Configuration::FilterChainFactoryContextPtr createFilterChainFactoryContext(
2525
const ::envoy::config::listener::v3::FilterChain* const filter_chain) PURE;
2626
};
2727

source/server/filter_chain_manager_impl.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ void FilterChainManagerImpl::convertIPsToTries() {
593593
}
594594
}
595595

596-
std::shared_ptr<Network::DrainableFilterChain> FilterChainManagerImpl::findExistingFilterChain(
596+
Network::DrainableFilterChainSharedPtr FilterChainManagerImpl::findExistingFilterChain(
597597
const envoy::config::listener::v3::FilterChain& filter_chain_message) {
598598
// Origin filter chain manager could be empty if the current is the ancestor.
599599
const auto* origin = getOriginFilterChainManager();
@@ -609,8 +609,7 @@ std::shared_ptr<Network::DrainableFilterChain> FilterChainManagerImpl::findExist
609609
return nullptr;
610610
}
611611

612-
std::unique_ptr<Configuration::FilterChainFactoryContext>
613-
FilterChainManagerImpl::createFilterChainFactoryContext(
612+
Configuration::FilterChainFactoryContextPtr FilterChainManagerImpl::createFilterChainFactoryContext(
614613
const ::envoy::config::listener::v3::FilterChain* const filter_chain) {
615614
// TODO(lambdai): add stats
616615
UNREFERENCED_PARAMETER(filter_chain);

0 commit comments

Comments
 (0)