Skip to content

Commit

Permalink
Revert "[promises] Add an optimizer for Seq, TrySeq (grpc#38445)" (
Browse files Browse the repository at this point in the history
…grpc#38748)

This reverts commit a7a650a.

Original PR breaks grpc#38286 and I think the breakage is in the PR -- in a construct like:

```
TrySeq(
  /*a*/ []() -> Promise<absl::Status>,
  /*b*/ []() -> Promise<StatusFlag>,
  /*c*/ []() -> Promise<absl::Status>)
```

the original seq_state code would try to promote the intermediate `StatusFlag` to an `absl::Status` which is great - however with the optimization, if `b` is instantaneous we try to demote the result of `a` to `StatusFlag`, losing information.

I'll need to consider how to change this optimization to preserve the final output type before rolling forward.

Closes grpc#38748

COPYBARA_INTEGRATE_REVIEW=grpc#38748 from ctiller:rb1 743eb33
PiperOrigin-RevId: 727109120
  • Loading branch information
ctiller authored and copybara-github committed Feb 15, 2025
1 parent 55cf79c commit 57a18b6
Show file tree
Hide file tree
Showing 20 changed files with 2,942 additions and 21,180 deletions.
96 changes: 0 additions & 96 deletions CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 0 additions & 76 deletions build_autogenerated.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1012,14 +1012,12 @@ grpc_cc_library(
],
deps = [
"construct_destruct",
"map",
"poll",
"promise_factory",
"promise_like",
"//:debug_location",
"//:gpr",
"//:grpc_trace",
"//:promise",
],
)

Expand Down
18 changes: 0 additions & 18 deletions src/core/lib/promise/detail/promise_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ class OncePromiseFactory {
using Arg = A;
using Promise =
decltype(PromiseFactoryImpl(std::move(f_), std::declval<A>()));
static constexpr bool kInstantaneousPromise = Promise::kInstantaneous;

GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION explicit OncePromiseFactory(F f)
: f_(std::move(f)) {}
Expand All @@ -194,14 +193,6 @@ class OncePromiseFactory {
}
};

template <typename A, typename F>
GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION
std::enable_if_t<OncePromiseFactory<A, F>::kInstantaneousPromise,
typename OncePromiseFactory<A, F>::Promise::Result>
MakeAndCall(A&& a, OncePromiseFactory<A, F>& f) {
return f.Make(std::forward<A>(a)).CallUnderlyingFn();
}

template <typename F>
class OncePromiseFactory<void, F> {
private:
Expand All @@ -210,7 +201,6 @@ class OncePromiseFactory<void, F> {
public:
using Arg = void;
using Promise = decltype(PromiseFactoryImpl(std::move(f_)));
static constexpr bool kInstantaneousPromise = Promise::kInstantaneous;

GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION explicit OncePromiseFactory(F f)
: f_(std::move(f)) {}
Expand All @@ -220,14 +210,6 @@ class OncePromiseFactory<void, F> {
}
};

template <typename F>
GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION
std::enable_if_t<OncePromiseFactory<void, F>::kInstantaneousPromise,
typename OncePromiseFactory<void, F>::Promise::Result>
MakeAndCall(OncePromiseFactory<void, F>& f) {
return f.Make().CallUnderlyingFn();
}

template <typename A, typename F>
class RepeatedPromiseFactory {
private:
Expand Down
10 changes: 0 additions & 10 deletions src/core/lib/promise/detail/promise_like.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@ struct PollWrapper {
GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION static Poll<T> Wrap(T&& x) {
return Poll<T>(std::forward<T>(x));
}
static constexpr bool kInstantaneous = true;
};

template <typename T>
struct PollWrapper<Poll<T>> {
GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION static Poll<T> Wrap(Poll<T>&& x) {
return std::forward<Poll<T>>(x);
}
static constexpr bool kInstantaneous = false;
};

template <typename T>
Expand Down Expand Up @@ -89,15 +87,12 @@ class PromiseLike<
using WrappedResult = decltype(WrapInPoll(std::declval<OriginalResult>()));

public:
static constexpr bool kInstantaneous =
PollWrapper<std::invoke_result_t<F>>::kInstantaneous;
// NOLINTNEXTLINE - internal detail that drastically simplifies calling code.
GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION PromiseLike(F&& f)
: f_(std::forward<F>(f)) {}
GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION WrappedResult operator()() {
return WrapInPoll(f_());
}
GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION auto CallUnderlyingFn() { return f_(); }
PromiseLike(const PromiseLike&) = default;
PromiseLike& operator=(const PromiseLike&) = default;
PromiseLike(PromiseLike&&) = default;
Expand All @@ -112,18 +107,13 @@ class PromiseLike<
GPR_NO_UNIQUE_ADDRESS RemoveCVRef<F> f_;

public:
static constexpr bool kInstantaneous = true;
// NOLINTNEXTLINE - internal detail that drastically simplifies calling code.
GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION PromiseLike(F&& f)
: f_(std::forward<F>(f)) {}
GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION Poll<Empty> operator()() {
f_();
return Empty{};
}
GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION auto CallUnderlyingFn() {
f_();
return Empty{};
}
PromiseLike(const PromiseLike&) = default;
PromiseLike& operator=(const PromiseLike&) = default;
PromiseLike(PromiseLike&&) = default;
Expand Down
Loading

0 comments on commit 57a18b6

Please sign in to comment.