Skip to content

Commit

Permalink
Unless -> if not
Browse files Browse the repository at this point in the history
Summary:
Unify on the more flexible syntax to allow removing unless blocks from
the language

Reviewed By: yfeldblum, praihan

Differential Revision: D67060740

fbshipit-source-id: 3b7e411cd6d601d149e68c2d893869652691aaf8
  • Loading branch information
iahs authored and facebook-github-bot committed Dec 13, 2024
1 parent 04eaba8 commit 35aebf8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}}{{#struct:fields}}{{#field:type}}{{#field:has_deprecated_accessors?}}
{{#type:resolves_to_base_or_enum?}}

{{#unless type:string_or_binary?}}
{{#if (not type:string_or_binary?)}}
{{#if field:optional?}}
{{> common/field_docblock}}
[[deprecated("Use `FOO.{{field:cpp_name}}().value();` instead of `FOO.get_{{field:cpp_name}}();`")]]
Expand Down Expand Up @@ -85,7 +85,7 @@
{{field:cpp_name}}_ref() = std::forward<T_{{struct:cpp_underlying_name}}_{{field:cpp_name}}_struct_setter>({{field:cpp_name}}_);
return {{field:cpp_storage_name}};
}
{{/unless type:string_or_binary?}}
{{/if (not type:string_or_binary?)}}
{{/type:resolves_to_base_or_enum?}}
{{#type:resolves_to_container_or_struct?}}
{{#if field:optional?}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ folly::SemiFuture<{{> types/return_type_client_lift_unit}}> {{> service_common/c
}
apache::thrift::SerializedRequest request = fbthrift_serialize_{{function:cpp_name}}(rpcOptions, *header, contextStack{{function:comma}}{{> service_common/param_list}});
fbthrift_send_{{function:cpp_name}}(std::move(request), rpcOptions, std::move(header), std::move(wrappedCallback){{#function:creates_interaction?}}, interactionHandle{{/function:creates_interaction?}});
{{#unless function:creates_interaction?}}
{{#if (not function:creates_interaction?)}}
return std::move(semifuture).deferValue(CallbackHelper::processClientInterceptorsAndExtractResult);
{{#else}}
return std::move(semifuture)
Expand All @@ -68,7 +68,7 @@ folly::SemiFuture<{{> types/return_type_client_lift_unit}}> {{> service_common/c
return std::pair{std::move(interactionHandle), std::move(*returnValue)};
{{/if type:void?}}
});
{{/unless function:creates_interaction?}}
{{/if (not function:creates_interaction?)}}
}

{{^service:reduced_client?}}{{^function:creates_interaction?}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
}}{{#unless function:sync_returns_by_outparam?}}
}}{{#if (not function:sync_returns_by_outparam?)}}
{{> types/return_type_client}} {{> service_common/client_class_name}}::sync_{{function:cpp_name}}({{> service_common/function_param_list_client}}) {
::apache::thrift::RpcOptions rpcOptions;
{{#if function:void?}}
Expand All @@ -28,27 +28,27 @@ void {{> service_common/client_class_name}}::sync_{{function:cpp_name}}({{functi
::apache::thrift::RpcOptions rpcOptions;
sync_{{function:cpp_name}}(rpcOptions, _return{{function:comma}}{{> service_common/param_list}});
}
{{/unless function:sync_returns_by_outparam?}}
{{/if (not function:sync_returns_by_outparam?)}}

{{#unless function:sync_returns_by_outparam?}}
{{#if (not function:sync_returns_by_outparam?)}}
{{> types/return_type_client}} {{> service_common/client_class_name}}::sync_{{function:cpp_name}}(apache::thrift::RpcOptions& rpcOptions{{function:comma}}{{> service_common/function_param_list_client}}) {
{{#else}}
void {{> service_common/client_class_name}}::sync_{{function:cpp_name}}(apache::thrift::RpcOptions& rpcOptions, {{function:cpp_return_type}}& _return{{function:comma}}{{> service_common/function_param_list_client}}) {
{{/unless function:sync_returns_by_outparam?}}
{{/if (not function:sync_returns_by_outparam?)}}
apache::thrift::ClientReceiveState returnState;
apache::thrift::ClientSyncCallback<{{#if function:oneway?}}true{{#else}}false{{/if function:oneway?}}> callback(&returnState);
{{#unless function:oneway?}}
{{#if (not function:oneway?)}}
auto protocolId = apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
{{/unless function:oneway?}}
{{/if (not function:oneway?)}}
auto evb = apache::thrift::GeneratedAsyncClient::getChannel()->getEventBase();
auto ctxAndHeader = {{function:cpp_name}}Ctx(&rpcOptions);
{{#unless function:stream?}}
{{#if (not function:stream?)}}
auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(&callback);
{{#else}}
auto wrappedCallback = apache::thrift::createStreamClientCallback(
apache::thrift::RequestClientCallback::Ptr(&callback),
rpcOptions.getBufferOptions());
{{/unless function:stream?}}
{{/if (not function:stream?)}}
{{#if function:creates_interaction?}}
{{function:created_interaction}} interactionHandle(channel_, "{{function:created_interaction}}", interceptors_);
{{/if function:creates_interaction?}}
Expand All @@ -62,15 +62,15 @@ void {{> service_common/client_class_name}}::sync_{{function:cpp_name}}(apache::
[&] {
fbthrift_serialize_and_send_{{function:cpp_name}}(rpcOptions, ctxAndHeader.second, ctxAndHeader.first.get(), std::move(wrappedCallback){{#function:creates_interaction?}}, interactionHandle{{/function:creates_interaction?}}{{function:comma}}{{> service_common/param_list}});
});
{{#unless function:oneway?}}
{{#if (not function:oneway?)}}
if (contextStack != nullptr) {
contextStack->processClientInterceptorsOnResponse(returnState.header()).throwUnlessValue();
}
{{/unless function:oneway?}}
{{/if (not function:oneway?)}}
if (returnState.isException()) {
returnState.exception().throw_exception();
}
{{#unless function:oneway?}}
{{#if (not function:oneway?)}}
returnState.resetProtocolId(protocolId);
returnState.resetCtx(std::move(ctxAndHeader.first));
SCOPE_EXIT {
Expand All @@ -79,11 +79,11 @@ void {{> service_common/client_class_name}}::sync_{{function:cpp_name}}(apache::
}
};
return folly::fibers::runInMainContext([&] {
{{#unless function:sync_returns_by_outparam?}}
{{#if (not function:sync_returns_by_outparam?)}}
{{#if function:void?}}
recv_{{function:cpp_name}}(returnState);
{{#else}}
{{#unless function:creates_interaction?}}
{{#if (not function:creates_interaction?)}}
return recv_{{function:cpp_name}}(returnState);
{{#else}}
{{#if function:stream?}}
Expand All @@ -92,28 +92,28 @@ void {{> service_common/client_class_name}}::sync_{{function:cpp_name}}(apache::
recv_{{function:cpp_name}}(returnState)
);
{{#else}}
{{#unless type:void?}}
{{#if (not type:void?)}}
return std::make_pair(
std::move(interactionHandle),
recv_{{function:cpp_name}}(returnState)
);
{{#else}}
recv_{{function:cpp_name}}(returnState);
return std::move(interactionHandle);
{{/unless type:void?}}
{{/if (not type:void?)}}
{{/if function:stream?}}
{{/unless function:creates_interaction?}}
{{/if (not function:creates_interaction?)}}
{{/if function:void?}}
{{#else}}
recv_{{function:cpp_name}}(_return, returnState);
{{/unless function:sync_returns_by_outparam?}}
{{/if (not function:sync_returns_by_outparam?)}}
});
{{/unless function:oneway?}}
{{/if (not function:oneway?)}}
}

{{#if type:sync_methods_return_try?}}
{{#unless function:oneway?}}
{{#unless function:sink?}}
{{#if (not function:oneway?)}}
{{#if (not function:sink?)}}
folly::Try<apache::thrift::RpcResponseComplete<{{> types/return_type_client}}>>
{{> service_common/client_class_name}}::sync_complete_{{function:cpp_name}}(
apache::thrift::RpcOptions&& rpcOptions{{function:comma}} {{> service_common/function_param_list_client}}) {
Expand All @@ -122,13 +122,13 @@ folly::Try<apache::thrift::RpcResponseComplete<{{> types/return_type_client}}>>
apache::thrift::ClientSyncCallback<false> callback(&returnState);
const auto protocolId = apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
auto* const evb = apache::thrift::GeneratedAsyncClient::getChannel()->getEventBase();
{{#unless function:stream?}}
{{#if (not function:stream?)}}
auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(&callback);
{{#else}}
auto wrappedCallback = apache::thrift::createStreamClientCallback(
apache::thrift::RequestClientCallback::Ptr(&callback),
rpcOptions.getBufferOptions());
{{/unless function:stream?}}
{{/if (not function:stream?)}}
callback.waitUntilDone(
evb,
[&] {
Expand Down Expand Up @@ -173,6 +173,6 @@ folly::Try<apache::thrift::RpcResponseComplete<{{> types/return_type_client}}>>
}
return tryResponse;
}
{{/unless function:sink?}}
{{/unless function:oneway?}}
{{/if (not function:sink?)}}
{{/if (not function:oneway?)}}
{{/if type:sync_methods_return_try?}}
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@
}}
{{> common/fun_docblock}}
folly::coro::Task<{{> types/return_type_client}}> co_{{function:cpp_name}}({{> service_common/function_param_list_client}}) {
{{#if function:stream?}}co_return {{#else}}{{#unless type:void?}}co_return {{/unless type:void?}}{{/if function:stream?}}co_await folly::coro::detachOnCancel(semifuture_{{function:cpp_name}}({{> service_common/param_list}}));
{{#if function:stream?}}co_return {{#else}}{{#if (not type:void?)}}co_return {{/if (not type:void?)}}{{/if function:stream?}}co_await folly::coro::detachOnCancel(semifuture_{{function:cpp_name}}({{> service_common/param_list}}));
}
{{> common/fun_docblock}}
folly::coro::Task<{{> types/return_type_client}}> co_{{function:cpp_name}}(apache::thrift::RpcOptions& rpcOptions{{function:comma}}{{> service_common/function_param_list_client}}) {
{{#if function:stream?}}co_return {{#else}}{{#unless type:void?}}co_return {{/unless type:void?}}{{/if function:stream?}}co_await folly::coro::detachOnCancel(semifuture_{{function:cpp_name}}(rpcOptions{{function:comma}}{{> service_common/param_list}}));
{{#if function:stream?}}co_return {{#else}}{{#if (not type:void?)}}co_return {{/if (not type:void?)}}{{/if function:stream?}}co_await folly::coro::detachOnCancel(semifuture_{{function:cpp_name}}(rpcOptions{{function:comma}}{{> service_common/param_list}}));
}
#endif
private:
Expand Down Expand Up @@ -190,25 +190,25 @@
}
{{/if type:void?}}
{{/if function:stream?}}
{{#unless function:creates_interaction?}}
{{#if (not function:creates_interaction?)}}
{{#if function:stream?}}
co_return _return;
{{#else}}
{{#unless type:void?}}
{{#if (not type:void?)}}
co_return _return;
{{/unless type:void?}}
{{/if (not type:void?)}}
{{/if function:stream?}}
{{#else}}
{{#if function:stream?}}
co_return std::make_pair(std::move(interactionHandle), std::move(_return));
{{#else}}
{{#unless type:void?}}
{{#if (not type:void?)}}
co_return std::make_pair(std::move(interactionHandle), std::move(_return));
{{#else}}
co_return interactionHandle;
{{/unless type:void?}}
{{/if (not type:void?)}}
{{/if function:stream?}}
{{/unless function:creates_interaction?}}
{{/if (not function:creates_interaction?)}}
{{/function:oneway?}}
}
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ import thrift.python.types as _fbthrift_python_types
import folly.iobuf as _fbthrift_iobuf

import {{program:module_path}}.thrift_types as {{program:module_mangle}}__thrift_types
{{#unless program:safe_patch?}}
{{#if (not program:safe_patch?)}}
import {{program:safe_patch_module_path}}.thrift_types as _fbthrift_safe_patch_types
{{/unless program:safe_patch?}}
{{/if (not program:safe_patch?)}}

{{#program:include_namespaces}}
{{#has_types?}}
Expand Down Expand Up @@ -85,7 +85,7 @@ class {{struct:py_name}}Patch(
self._patch,
{{field:key}},
{{#field:type}}{{> ../python/types/typeinfo }}{{/field:type}})
{{#unless program:safe_patch?}}{{! If the program is already a safe patch, we should not generate to_safe_patch/from_safe_patch, otherwise it becomes a safe patch of safe patch}}
{{#if (not program:safe_patch?)}}{{! If the program is already a safe patch, we should not generate to_safe_patch/from_safe_patch, otherwise it becomes a safe patch of safe patch}}

def to_safe_patch(self) -> _fbthrift_safe_patch_types.{{struct:name}}SafePatch:
return _fbthrift_safe_patch_types.{{struct:name}}SafePatch(
Expand All @@ -98,7 +98,7 @@ class {{struct:py_name}}Patch(
DynamicPatch = Dynamic{{#if struct:union?}}Union{{#else}}Struct{{/if struct:union?}}Patch
patch._patch = DynamicPatch.deserialize_from_compact_protocol(safe_patch.data)
return patch
{{/unless program:safe_patch?}}
{{/if (not program:safe_patch?)}}


{{/struct:fields_ordered_by_id}}
Expand Down

0 comments on commit 35aebf8

Please sign in to comment.