xref: /aosp_15_r20/external/grpc-grpc/src/core/lib/promise/detail/seq_state.h (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1 // Copyright 2023 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GRPC_SRC_CORE_LIB_PROMISE_DETAIL_SEQ_STATE_H
16 #define GRPC_SRC_CORE_LIB_PROMISE_DETAIL_SEQ_STATE_H
17 
18 // This file is generated by tools/codegen/core/gen_seq.py
19 
20 #include <grpc/support/port_platform.h>
21 
22 #include <stdint.h>
23 
24 #include <utility>
25 
26 #include "absl/base/attributes.h"
27 #include "absl/strings/str_cat.h"
28 
29 #include <grpc/support/log.h>
30 
31 #include "src/core/lib/gprpp/construct_destruct.h"
32 #include "src/core/lib/gprpp/debug_location.h"
33 #include "src/core/lib/promise/detail/promise_factory.h"
34 #include "src/core/lib/promise/detail/promise_like.h"
35 #include "src/core/lib/promise/poll.h"
36 #include "src/core/lib/promise/trace.h"
37 
38 // A sequence under some traits for some set of callables P, Fs.
39 // P should be a promise-like object that yields a value.
40 // Fs... should be promise-factory-like objects that take the value from the
41 // previous step and yield a promise. Note that most of the machinery in
42 // PromiseFactory exists to make it possible for those promise-factory-like
43 // objects to be anything that's convenient.
44 // Traits defines how we move from one step to the next. Traits sets up the
45 // wrapping and escape handling for the sequence.
46 // Promises return wrapped values that the trait can inspect and unwrap before
47 // passing them to the next element of the sequence. The trait can
48 // also interpret a wrapped value as an escape value, which terminates
49 // evaluation of the sequence immediately yielding a result. Traits for type T
50 // have the members:
51 //  * type UnwrappedType - the type after removing wrapping from T (i.e. for
52 //    TrySeq, T=StatusOr<U> yields UnwrappedType=U).
53 //  * type WrappedType - the type after adding wrapping if it doesn't already
54 //    exist (i.e. for TrySeq if T is not Status/StatusOr/void, then
55 //    WrappedType=StatusOr<T>; if T is Status then WrappedType=Status (it's
56 //    already wrapped!))
57 //  * template <typename Next> void CallFactory(Next* next_factory, T&& value) -
58 //    call promise factory next_factory with the result of unwrapping value, and
59 //    return the resulting promise.
60 //  * template <typename Result, typename RunNext> Poll<Result>
61 //    CheckResultAndRunNext(T prior, RunNext run_next) - examine the value of
62 //    prior, and decide to escape or continue. If escaping, return the final
63 //    sequence value of type Poll<Result>. If continuing, return the value of
64 //    run_next(std::move(prior)).
65 //
66 // A state contains the current promise, and the promise factory to turn the
67 // result of the current promise into the next state's promise. We play a shell
68 // game such that the prior state and our current promise are kept in a union,
69 // and the next promise factory is kept alongside in the state struct.
70 // Recursively this guarantees that the next functions get initialized once, and
71 // destroyed once, and don't need to be moved around in between, which avoids a
72 // potential O(n**2) loop of next factory moves had we used a variant of states
73 // here. The very first state does not have a prior state, and so that state has
74 // a partial specialization below. The final state does not have a next state;
75 // that state is inlined in BasicSeq since that was simpler to type.
76 
77 namespace grpc_core {
78 namespace promise_detail {
79 template <template <typename> class Traits, typename P, typename... Fs>
80 struct SeqState;
81 
82 template <template <typename> class Traits, typename P, typename F0>
83 struct SeqState<Traits, P, F0> {
84   using Promise0 = PromiseLike<P>;
85   using PromiseResult0 = typename Promise0::Result;
86   using PromiseResultTraits0 = Traits<PromiseResult0>;
87   using NextFactory0 =
88       OncePromiseFactory<typename PromiseResultTraits0::UnwrappedType, F0>;
89   using Promise1 = typename NextFactory0::Promise;
90   using PromiseResult1 = typename Promise1::Result;
91   using PromiseResultTraits1 = Traits<PromiseResult1>;
92   using Result = typename PromiseResultTraits1::WrappedType;
93   struct Running0 {
94     GPR_NO_UNIQUE_ADDRESS Promise0 current_promise;
95     GPR_NO_UNIQUE_ADDRESS NextFactory0 next_factory;
96   };
97   union {
98     GPR_NO_UNIQUE_ADDRESS Running0 prior;
99     GPR_NO_UNIQUE_ADDRESS Promise1 current_promise;
100   };
101   enum class State : uint8_t { kState0, kState1 };
102   GPR_NO_UNIQUE_ADDRESS State state = State::kState0;
103   GPR_NO_UNIQUE_ADDRESS DebugLocation whence;
104 
105   SeqState(P&& p, F0&& f0, DebugLocation whence) noexcept : whence(whence) {
106     Construct(&prior.current_promise, std::forward<P>(p));
107     Construct(&prior.next_factory, std::forward<F0>(f0));
108   }
109   ~SeqState() {
110     switch (state) {
111       case State::kState0:
112         Destruct(&prior.current_promise);
113         goto tail0;
114       case State::kState1:
115         Destruct(&current_promise);
116         return;
117     }
118   tail0:
119     Destruct(&prior.next_factory);
120   }
121   SeqState(const SeqState& other) noexcept
122       : state(other.state), whence(other.whence) {
123     GPR_ASSERT(state == State::kState0);
124     Construct(&prior.current_promise, other.prior.current_promise);
125     Construct(&prior.next_factory, other.prior.next_factory);
126   }
127   SeqState& operator=(const SeqState& other) = delete;
128   SeqState(SeqState&& other) noexcept
129       : state(other.state), whence(other.whence) {
130     switch (state) {
131       case State::kState0:
132         Construct(&prior.current_promise,
133                   std::move(other.prior.current_promise));
134         goto tail0;
135       case State::kState1:
136         Construct(&current_promise, std::move(other.current_promise));
137         return;
138     }
139   tail0:
140     Construct(&prior.next_factory, std::move(other.prior.next_factory));
141   }
142   SeqState& operator=(SeqState&& other) = delete;
143   Poll<Result> PollOnce() {
144     switch (state) {
145       case State::kState0: {
146         if (grpc_trace_promise_primitives.enabled()) {
147           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
148                   "seq[%p]: begin poll step 1/2", this);
149         }
150         auto result = prior.current_promise();
151         PromiseResult0* p = result.value_if_ready();
152         if (grpc_trace_promise_primitives.enabled()) {
153           gpr_log(
154               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
155               "seq[%p]: poll step 1/2 gets %s", this,
156               p != nullptr
157                   ? (PromiseResultTraits0::IsOk(*p)
158                          ? "ready"
159                          : absl::StrCat("early-error:",
160                                         PromiseResultTraits0::ErrorString(*p))
161                                .c_str())
162                   : "pending");
163         }
164         if (p == nullptr) return Pending{};
165         if (!PromiseResultTraits0::IsOk(*p)) {
166           return PromiseResultTraits0::template ReturnValue<Result>(
167               std::move(*p));
168         }
169         Destruct(&prior.current_promise);
170         auto next_promise = PromiseResultTraits0::CallFactory(
171             &prior.next_factory, std::move(*p));
172         Destruct(&prior.next_factory);
173         Construct(&current_promise, std::move(next_promise));
174         state = State::kState1;
175       }
176         ABSL_FALLTHROUGH_INTENDED;
177       default:
178       case State::kState1: {
179         if (grpc_trace_promise_primitives.enabled()) {
180           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
181                   "seq[%p]: begin poll step 2/2", this);
182         }
183         auto result = current_promise();
184         if (grpc_trace_promise_primitives.enabled()) {
185           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
186                   "seq[%p]: poll step 2/2 gets %s", this,
187                   result.ready() ? "ready" : "pending");
188         }
189         auto* p = result.value_if_ready();
190         if (p == nullptr) return Pending{};
191         return Result(std::move(*p));
192       }
193     }
194   }
195 };
196 
197 template <template <typename> class Traits, typename P, typename F0,
198           typename F1>
199 struct SeqState<Traits, P, F0, F1> {
200   using Promise0 = PromiseLike<P>;
201   using PromiseResult0 = typename Promise0::Result;
202   using PromiseResultTraits0 = Traits<PromiseResult0>;
203   using NextFactory0 =
204       OncePromiseFactory<typename PromiseResultTraits0::UnwrappedType, F0>;
205   using Promise1 = typename NextFactory0::Promise;
206   using PromiseResult1 = typename Promise1::Result;
207   using PromiseResultTraits1 = Traits<PromiseResult1>;
208   using NextFactory1 =
209       OncePromiseFactory<typename PromiseResultTraits1::UnwrappedType, F1>;
210   using Promise2 = typename NextFactory1::Promise;
211   using PromiseResult2 = typename Promise2::Result;
212   using PromiseResultTraits2 = Traits<PromiseResult2>;
213   using Result = typename PromiseResultTraits2::WrappedType;
214   struct Running0 {
215     GPR_NO_UNIQUE_ADDRESS Promise0 current_promise;
216     GPR_NO_UNIQUE_ADDRESS NextFactory0 next_factory;
217   };
218   struct Running1 {
219     union {
220       GPR_NO_UNIQUE_ADDRESS Running0 prior;
221       GPR_NO_UNIQUE_ADDRESS Promise1 current_promise;
222     };
223     GPR_NO_UNIQUE_ADDRESS NextFactory1 next_factory;
224   };
225   union {
226     GPR_NO_UNIQUE_ADDRESS Running1 prior;
227     GPR_NO_UNIQUE_ADDRESS Promise2 current_promise;
228   };
229   enum class State : uint8_t { kState0, kState1, kState2 };
230   GPR_NO_UNIQUE_ADDRESS State state = State::kState0;
231   GPR_NO_UNIQUE_ADDRESS DebugLocation whence;
232 
233   SeqState(P&& p, F0&& f0, F1&& f1, DebugLocation whence) noexcept
234       : whence(whence) {
235     Construct(&prior.prior.current_promise, std::forward<P>(p));
236     Construct(&prior.prior.next_factory, std::forward<F0>(f0));
237     Construct(&prior.next_factory, std::forward<F1>(f1));
238   }
239   ~SeqState() {
240     switch (state) {
241       case State::kState0:
242         Destruct(&prior.prior.current_promise);
243         goto tail0;
244       case State::kState1:
245         Destruct(&prior.current_promise);
246         goto tail1;
247       case State::kState2:
248         Destruct(&current_promise);
249         return;
250     }
251   tail0:
252     Destruct(&prior.prior.next_factory);
253   tail1:
254     Destruct(&prior.next_factory);
255   }
256   SeqState(const SeqState& other) noexcept
257       : state(other.state), whence(other.whence) {
258     GPR_ASSERT(state == State::kState0);
259     Construct(&prior.current_promise, other.prior.current_promise);
260     Construct(&prior.prior.next_factory, other.prior.prior.next_factory);
261     Construct(&prior.next_factory, other.prior.next_factory);
262   }
263   SeqState& operator=(const SeqState& other) = delete;
264   SeqState(SeqState&& other) noexcept
265       : state(other.state), whence(other.whence) {
266     switch (state) {
267       case State::kState0:
268         Construct(&prior.prior.current_promise,
269                   std::move(other.prior.prior.current_promise));
270         goto tail0;
271       case State::kState1:
272         Construct(&prior.current_promise,
273                   std::move(other.prior.current_promise));
274         goto tail1;
275       case State::kState2:
276         Construct(&current_promise, std::move(other.current_promise));
277         return;
278     }
279   tail0:
280     Construct(&prior.prior.next_factory,
281               std::move(other.prior.prior.next_factory));
282   tail1:
283     Construct(&prior.next_factory, std::move(other.prior.next_factory));
284   }
285   SeqState& operator=(SeqState&& other) = delete;
286   Poll<Result> PollOnce() {
287     switch (state) {
288       case State::kState0: {
289         if (grpc_trace_promise_primitives.enabled()) {
290           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
291                   "seq[%p]: begin poll step 1/3", this);
292         }
293         auto result = prior.prior.current_promise();
294         PromiseResult0* p = result.value_if_ready();
295         if (grpc_trace_promise_primitives.enabled()) {
296           gpr_log(
297               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
298               "seq[%p]: poll step 1/3 gets %s", this,
299               p != nullptr
300                   ? (PromiseResultTraits0::IsOk(*p)
301                          ? "ready"
302                          : absl::StrCat("early-error:",
303                                         PromiseResultTraits0::ErrorString(*p))
304                                .c_str())
305                   : "pending");
306         }
307         if (p == nullptr) return Pending{};
308         if (!PromiseResultTraits0::IsOk(*p)) {
309           return PromiseResultTraits0::template ReturnValue<Result>(
310               std::move(*p));
311         }
312         Destruct(&prior.prior.current_promise);
313         auto next_promise = PromiseResultTraits0::CallFactory(
314             &prior.prior.next_factory, std::move(*p));
315         Destruct(&prior.prior.next_factory);
316         Construct(&prior.current_promise, std::move(next_promise));
317         state = State::kState1;
318       }
319         ABSL_FALLTHROUGH_INTENDED;
320       case State::kState1: {
321         if (grpc_trace_promise_primitives.enabled()) {
322           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
323                   "seq[%p]: begin poll step 2/3", this);
324         }
325         auto result = prior.current_promise();
326         PromiseResult1* p = result.value_if_ready();
327         if (grpc_trace_promise_primitives.enabled()) {
328           gpr_log(
329               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
330               "seq[%p]: poll step 2/3 gets %s", this,
331               p != nullptr
332                   ? (PromiseResultTraits1::IsOk(*p)
333                          ? "ready"
334                          : absl::StrCat("early-error:",
335                                         PromiseResultTraits1::ErrorString(*p))
336                                .c_str())
337                   : "pending");
338         }
339         if (p == nullptr) return Pending{};
340         if (!PromiseResultTraits1::IsOk(*p)) {
341           return PromiseResultTraits1::template ReturnValue<Result>(
342               std::move(*p));
343         }
344         Destruct(&prior.current_promise);
345         auto next_promise = PromiseResultTraits1::CallFactory(
346             &prior.next_factory, std::move(*p));
347         Destruct(&prior.next_factory);
348         Construct(&current_promise, std::move(next_promise));
349         state = State::kState2;
350       }
351         ABSL_FALLTHROUGH_INTENDED;
352       default:
353       case State::kState2: {
354         if (grpc_trace_promise_primitives.enabled()) {
355           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
356                   "seq[%p]: begin poll step 3/3", this);
357         }
358         auto result = current_promise();
359         if (grpc_trace_promise_primitives.enabled()) {
360           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
361                   "seq[%p]: poll step 3/3 gets %s", this,
362                   result.ready() ? "ready" : "pending");
363         }
364         auto* p = result.value_if_ready();
365         if (p == nullptr) return Pending{};
366         return Result(std::move(*p));
367       }
368     }
369   }
370 };
371 
372 template <template <typename> class Traits, typename P, typename F0,
373           typename F1, typename F2>
374 struct SeqState<Traits, P, F0, F1, F2> {
375   using Promise0 = PromiseLike<P>;
376   using PromiseResult0 = typename Promise0::Result;
377   using PromiseResultTraits0 = Traits<PromiseResult0>;
378   using NextFactory0 =
379       OncePromiseFactory<typename PromiseResultTraits0::UnwrappedType, F0>;
380   using Promise1 = typename NextFactory0::Promise;
381   using PromiseResult1 = typename Promise1::Result;
382   using PromiseResultTraits1 = Traits<PromiseResult1>;
383   using NextFactory1 =
384       OncePromiseFactory<typename PromiseResultTraits1::UnwrappedType, F1>;
385   using Promise2 = typename NextFactory1::Promise;
386   using PromiseResult2 = typename Promise2::Result;
387   using PromiseResultTraits2 = Traits<PromiseResult2>;
388   using NextFactory2 =
389       OncePromiseFactory<typename PromiseResultTraits2::UnwrappedType, F2>;
390   using Promise3 = typename NextFactory2::Promise;
391   using PromiseResult3 = typename Promise3::Result;
392   using PromiseResultTraits3 = Traits<PromiseResult3>;
393   using Result = typename PromiseResultTraits3::WrappedType;
394   struct Running0 {
395     GPR_NO_UNIQUE_ADDRESS Promise0 current_promise;
396     GPR_NO_UNIQUE_ADDRESS NextFactory0 next_factory;
397   };
398   struct Running1 {
399     union {
400       GPR_NO_UNIQUE_ADDRESS Running0 prior;
401       GPR_NO_UNIQUE_ADDRESS Promise1 current_promise;
402     };
403     GPR_NO_UNIQUE_ADDRESS NextFactory1 next_factory;
404   };
405   struct Running2 {
406     union {
407       GPR_NO_UNIQUE_ADDRESS Running1 prior;
408       GPR_NO_UNIQUE_ADDRESS Promise2 current_promise;
409     };
410     GPR_NO_UNIQUE_ADDRESS NextFactory2 next_factory;
411   };
412   union {
413     GPR_NO_UNIQUE_ADDRESS Running2 prior;
414     GPR_NO_UNIQUE_ADDRESS Promise3 current_promise;
415   };
416   enum class State : uint8_t { kState0, kState1, kState2, kState3 };
417   GPR_NO_UNIQUE_ADDRESS State state = State::kState0;
418   GPR_NO_UNIQUE_ADDRESS DebugLocation whence;
419 
420   SeqState(P&& p, F0&& f0, F1&& f1, F2&& f2, DebugLocation whence) noexcept
421       : whence(whence) {
422     Construct(&prior.prior.prior.current_promise, std::forward<P>(p));
423     Construct(&prior.prior.prior.next_factory, std::forward<F0>(f0));
424     Construct(&prior.prior.next_factory, std::forward<F1>(f1));
425     Construct(&prior.next_factory, std::forward<F2>(f2));
426   }
427   ~SeqState() {
428     switch (state) {
429       case State::kState0:
430         Destruct(&prior.prior.prior.current_promise);
431         goto tail0;
432       case State::kState1:
433         Destruct(&prior.prior.current_promise);
434         goto tail1;
435       case State::kState2:
436         Destruct(&prior.current_promise);
437         goto tail2;
438       case State::kState3:
439         Destruct(&current_promise);
440         return;
441     }
442   tail0:
443     Destruct(&prior.prior.prior.next_factory);
444   tail1:
445     Destruct(&prior.prior.next_factory);
446   tail2:
447     Destruct(&prior.next_factory);
448   }
449   SeqState(const SeqState& other) noexcept
450       : state(other.state), whence(other.whence) {
451     GPR_ASSERT(state == State::kState0);
452     Construct(&prior.current_promise, other.prior.current_promise);
453     Construct(&prior.prior.prior.next_factory,
454               other.prior.prior.prior.next_factory);
455     Construct(&prior.prior.next_factory, other.prior.prior.next_factory);
456     Construct(&prior.next_factory, other.prior.next_factory);
457   }
458   SeqState& operator=(const SeqState& other) = delete;
459   SeqState(SeqState&& other) noexcept
460       : state(other.state), whence(other.whence) {
461     switch (state) {
462       case State::kState0:
463         Construct(&prior.prior.prior.current_promise,
464                   std::move(other.prior.prior.prior.current_promise));
465         goto tail0;
466       case State::kState1:
467         Construct(&prior.prior.current_promise,
468                   std::move(other.prior.prior.current_promise));
469         goto tail1;
470       case State::kState2:
471         Construct(&prior.current_promise,
472                   std::move(other.prior.current_promise));
473         goto tail2;
474       case State::kState3:
475         Construct(&current_promise, std::move(other.current_promise));
476         return;
477     }
478   tail0:
479     Construct(&prior.prior.prior.next_factory,
480               std::move(other.prior.prior.prior.next_factory));
481   tail1:
482     Construct(&prior.prior.next_factory,
483               std::move(other.prior.prior.next_factory));
484   tail2:
485     Construct(&prior.next_factory, std::move(other.prior.next_factory));
486   }
487   SeqState& operator=(SeqState&& other) = delete;
488   Poll<Result> PollOnce() {
489     switch (state) {
490       case State::kState0: {
491         if (grpc_trace_promise_primitives.enabled()) {
492           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
493                   "seq[%p]: begin poll step 1/4", this);
494         }
495         auto result = prior.prior.prior.current_promise();
496         PromiseResult0* p = result.value_if_ready();
497         if (grpc_trace_promise_primitives.enabled()) {
498           gpr_log(
499               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
500               "seq[%p]: poll step 1/4 gets %s", this,
501               p != nullptr
502                   ? (PromiseResultTraits0::IsOk(*p)
503                          ? "ready"
504                          : absl::StrCat("early-error:",
505                                         PromiseResultTraits0::ErrorString(*p))
506                                .c_str())
507                   : "pending");
508         }
509         if (p == nullptr) return Pending{};
510         if (!PromiseResultTraits0::IsOk(*p)) {
511           return PromiseResultTraits0::template ReturnValue<Result>(
512               std::move(*p));
513         }
514         Destruct(&prior.prior.prior.current_promise);
515         auto next_promise = PromiseResultTraits0::CallFactory(
516             &prior.prior.prior.next_factory, std::move(*p));
517         Destruct(&prior.prior.prior.next_factory);
518         Construct(&prior.prior.current_promise, std::move(next_promise));
519         state = State::kState1;
520       }
521         ABSL_FALLTHROUGH_INTENDED;
522       case State::kState1: {
523         if (grpc_trace_promise_primitives.enabled()) {
524           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
525                   "seq[%p]: begin poll step 2/4", this);
526         }
527         auto result = prior.prior.current_promise();
528         PromiseResult1* p = result.value_if_ready();
529         if (grpc_trace_promise_primitives.enabled()) {
530           gpr_log(
531               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
532               "seq[%p]: poll step 2/4 gets %s", this,
533               p != nullptr
534                   ? (PromiseResultTraits1::IsOk(*p)
535                          ? "ready"
536                          : absl::StrCat("early-error:",
537                                         PromiseResultTraits1::ErrorString(*p))
538                                .c_str())
539                   : "pending");
540         }
541         if (p == nullptr) return Pending{};
542         if (!PromiseResultTraits1::IsOk(*p)) {
543           return PromiseResultTraits1::template ReturnValue<Result>(
544               std::move(*p));
545         }
546         Destruct(&prior.prior.current_promise);
547         auto next_promise = PromiseResultTraits1::CallFactory(
548             &prior.prior.next_factory, std::move(*p));
549         Destruct(&prior.prior.next_factory);
550         Construct(&prior.current_promise, std::move(next_promise));
551         state = State::kState2;
552       }
553         ABSL_FALLTHROUGH_INTENDED;
554       case State::kState2: {
555         if (grpc_trace_promise_primitives.enabled()) {
556           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
557                   "seq[%p]: begin poll step 3/4", this);
558         }
559         auto result = prior.current_promise();
560         PromiseResult2* p = result.value_if_ready();
561         if (grpc_trace_promise_primitives.enabled()) {
562           gpr_log(
563               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
564               "seq[%p]: poll step 3/4 gets %s", this,
565               p != nullptr
566                   ? (PromiseResultTraits2::IsOk(*p)
567                          ? "ready"
568                          : absl::StrCat("early-error:",
569                                         PromiseResultTraits2::ErrorString(*p))
570                                .c_str())
571                   : "pending");
572         }
573         if (p == nullptr) return Pending{};
574         if (!PromiseResultTraits2::IsOk(*p)) {
575           return PromiseResultTraits2::template ReturnValue<Result>(
576               std::move(*p));
577         }
578         Destruct(&prior.current_promise);
579         auto next_promise = PromiseResultTraits2::CallFactory(
580             &prior.next_factory, std::move(*p));
581         Destruct(&prior.next_factory);
582         Construct(&current_promise, std::move(next_promise));
583         state = State::kState3;
584       }
585         ABSL_FALLTHROUGH_INTENDED;
586       default:
587       case State::kState3: {
588         if (grpc_trace_promise_primitives.enabled()) {
589           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
590                   "seq[%p]: begin poll step 4/4", this);
591         }
592         auto result = current_promise();
593         if (grpc_trace_promise_primitives.enabled()) {
594           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
595                   "seq[%p]: poll step 4/4 gets %s", this,
596                   result.ready() ? "ready" : "pending");
597         }
598         auto* p = result.value_if_ready();
599         if (p == nullptr) return Pending{};
600         return Result(std::move(*p));
601       }
602     }
603   }
604 };
605 
606 template <template <typename> class Traits, typename P, typename F0,
607           typename F1, typename F2, typename F3>
608 struct SeqState<Traits, P, F0, F1, F2, F3> {
609   using Promise0 = PromiseLike<P>;
610   using PromiseResult0 = typename Promise0::Result;
611   using PromiseResultTraits0 = Traits<PromiseResult0>;
612   using NextFactory0 =
613       OncePromiseFactory<typename PromiseResultTraits0::UnwrappedType, F0>;
614   using Promise1 = typename NextFactory0::Promise;
615   using PromiseResult1 = typename Promise1::Result;
616   using PromiseResultTraits1 = Traits<PromiseResult1>;
617   using NextFactory1 =
618       OncePromiseFactory<typename PromiseResultTraits1::UnwrappedType, F1>;
619   using Promise2 = typename NextFactory1::Promise;
620   using PromiseResult2 = typename Promise2::Result;
621   using PromiseResultTraits2 = Traits<PromiseResult2>;
622   using NextFactory2 =
623       OncePromiseFactory<typename PromiseResultTraits2::UnwrappedType, F2>;
624   using Promise3 = typename NextFactory2::Promise;
625   using PromiseResult3 = typename Promise3::Result;
626   using PromiseResultTraits3 = Traits<PromiseResult3>;
627   using NextFactory3 =
628       OncePromiseFactory<typename PromiseResultTraits3::UnwrappedType, F3>;
629   using Promise4 = typename NextFactory3::Promise;
630   using PromiseResult4 = typename Promise4::Result;
631   using PromiseResultTraits4 = Traits<PromiseResult4>;
632   using Result = typename PromiseResultTraits4::WrappedType;
633   struct Running0 {
634     GPR_NO_UNIQUE_ADDRESS Promise0 current_promise;
635     GPR_NO_UNIQUE_ADDRESS NextFactory0 next_factory;
636   };
637   struct Running1 {
638     union {
639       GPR_NO_UNIQUE_ADDRESS Running0 prior;
640       GPR_NO_UNIQUE_ADDRESS Promise1 current_promise;
641     };
642     GPR_NO_UNIQUE_ADDRESS NextFactory1 next_factory;
643   };
644   struct Running2 {
645     union {
646       GPR_NO_UNIQUE_ADDRESS Running1 prior;
647       GPR_NO_UNIQUE_ADDRESS Promise2 current_promise;
648     };
649     GPR_NO_UNIQUE_ADDRESS NextFactory2 next_factory;
650   };
651   struct Running3 {
652     union {
653       GPR_NO_UNIQUE_ADDRESS Running2 prior;
654       GPR_NO_UNIQUE_ADDRESS Promise3 current_promise;
655     };
656     GPR_NO_UNIQUE_ADDRESS NextFactory3 next_factory;
657   };
658   union {
659     GPR_NO_UNIQUE_ADDRESS Running3 prior;
660     GPR_NO_UNIQUE_ADDRESS Promise4 current_promise;
661   };
662   enum class State : uint8_t { kState0, kState1, kState2, kState3, kState4 };
663   GPR_NO_UNIQUE_ADDRESS State state = State::kState0;
664   GPR_NO_UNIQUE_ADDRESS DebugLocation whence;
665 
666   SeqState(P&& p, F0&& f0, F1&& f1, F2&& f2, F3&& f3,
667            DebugLocation whence) noexcept
668       : whence(whence) {
669     Construct(&prior.prior.prior.prior.current_promise, std::forward<P>(p));
670     Construct(&prior.prior.prior.prior.next_factory, std::forward<F0>(f0));
671     Construct(&prior.prior.prior.next_factory, std::forward<F1>(f1));
672     Construct(&prior.prior.next_factory, std::forward<F2>(f2));
673     Construct(&prior.next_factory, std::forward<F3>(f3));
674   }
675   ~SeqState() {
676     switch (state) {
677       case State::kState0:
678         Destruct(&prior.prior.prior.prior.current_promise);
679         goto tail0;
680       case State::kState1:
681         Destruct(&prior.prior.prior.current_promise);
682         goto tail1;
683       case State::kState2:
684         Destruct(&prior.prior.current_promise);
685         goto tail2;
686       case State::kState3:
687         Destruct(&prior.current_promise);
688         goto tail3;
689       case State::kState4:
690         Destruct(&current_promise);
691         return;
692     }
693   tail0:
694     Destruct(&prior.prior.prior.prior.next_factory);
695   tail1:
696     Destruct(&prior.prior.prior.next_factory);
697   tail2:
698     Destruct(&prior.prior.next_factory);
699   tail3:
700     Destruct(&prior.next_factory);
701   }
702   SeqState(const SeqState& other) noexcept
703       : state(other.state), whence(other.whence) {
704     GPR_ASSERT(state == State::kState0);
705     Construct(&prior.current_promise, other.prior.current_promise);
706     Construct(&prior.prior.prior.prior.next_factory,
707               other.prior.prior.prior.prior.next_factory);
708     Construct(&prior.prior.prior.next_factory,
709               other.prior.prior.prior.next_factory);
710     Construct(&prior.prior.next_factory, other.prior.prior.next_factory);
711     Construct(&prior.next_factory, other.prior.next_factory);
712   }
713   SeqState& operator=(const SeqState& other) = delete;
714   SeqState(SeqState&& other) noexcept
715       : state(other.state), whence(other.whence) {
716     switch (state) {
717       case State::kState0:
718         Construct(&prior.prior.prior.prior.current_promise,
719                   std::move(other.prior.prior.prior.prior.current_promise));
720         goto tail0;
721       case State::kState1:
722         Construct(&prior.prior.prior.current_promise,
723                   std::move(other.prior.prior.prior.current_promise));
724         goto tail1;
725       case State::kState2:
726         Construct(&prior.prior.current_promise,
727                   std::move(other.prior.prior.current_promise));
728         goto tail2;
729       case State::kState3:
730         Construct(&prior.current_promise,
731                   std::move(other.prior.current_promise));
732         goto tail3;
733       case State::kState4:
734         Construct(&current_promise, std::move(other.current_promise));
735         return;
736     }
737   tail0:
738     Construct(&prior.prior.prior.prior.next_factory,
739               std::move(other.prior.prior.prior.prior.next_factory));
740   tail1:
741     Construct(&prior.prior.prior.next_factory,
742               std::move(other.prior.prior.prior.next_factory));
743   tail2:
744     Construct(&prior.prior.next_factory,
745               std::move(other.prior.prior.next_factory));
746   tail3:
747     Construct(&prior.next_factory, std::move(other.prior.next_factory));
748   }
749   SeqState& operator=(SeqState&& other) = delete;
750   Poll<Result> PollOnce() {
751     switch (state) {
752       case State::kState0: {
753         if (grpc_trace_promise_primitives.enabled()) {
754           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
755                   "seq[%p]: begin poll step 1/5", this);
756         }
757         auto result = prior.prior.prior.prior.current_promise();
758         PromiseResult0* p = result.value_if_ready();
759         if (grpc_trace_promise_primitives.enabled()) {
760           gpr_log(
761               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
762               "seq[%p]: poll step 1/5 gets %s", this,
763               p != nullptr
764                   ? (PromiseResultTraits0::IsOk(*p)
765                          ? "ready"
766                          : absl::StrCat("early-error:",
767                                         PromiseResultTraits0::ErrorString(*p))
768                                .c_str())
769                   : "pending");
770         }
771         if (p == nullptr) return Pending{};
772         if (!PromiseResultTraits0::IsOk(*p)) {
773           return PromiseResultTraits0::template ReturnValue<Result>(
774               std::move(*p));
775         }
776         Destruct(&prior.prior.prior.prior.current_promise);
777         auto next_promise = PromiseResultTraits0::CallFactory(
778             &prior.prior.prior.prior.next_factory, std::move(*p));
779         Destruct(&prior.prior.prior.prior.next_factory);
780         Construct(&prior.prior.prior.current_promise, std::move(next_promise));
781         state = State::kState1;
782       }
783         ABSL_FALLTHROUGH_INTENDED;
784       case State::kState1: {
785         if (grpc_trace_promise_primitives.enabled()) {
786           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
787                   "seq[%p]: begin poll step 2/5", this);
788         }
789         auto result = prior.prior.prior.current_promise();
790         PromiseResult1* p = result.value_if_ready();
791         if (grpc_trace_promise_primitives.enabled()) {
792           gpr_log(
793               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
794               "seq[%p]: poll step 2/5 gets %s", this,
795               p != nullptr
796                   ? (PromiseResultTraits1::IsOk(*p)
797                          ? "ready"
798                          : absl::StrCat("early-error:",
799                                         PromiseResultTraits1::ErrorString(*p))
800                                .c_str())
801                   : "pending");
802         }
803         if (p == nullptr) return Pending{};
804         if (!PromiseResultTraits1::IsOk(*p)) {
805           return PromiseResultTraits1::template ReturnValue<Result>(
806               std::move(*p));
807         }
808         Destruct(&prior.prior.prior.current_promise);
809         auto next_promise = PromiseResultTraits1::CallFactory(
810             &prior.prior.prior.next_factory, std::move(*p));
811         Destruct(&prior.prior.prior.next_factory);
812         Construct(&prior.prior.current_promise, std::move(next_promise));
813         state = State::kState2;
814       }
815         ABSL_FALLTHROUGH_INTENDED;
816       case State::kState2: {
817         if (grpc_trace_promise_primitives.enabled()) {
818           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
819                   "seq[%p]: begin poll step 3/5", this);
820         }
821         auto result = prior.prior.current_promise();
822         PromiseResult2* p = result.value_if_ready();
823         if (grpc_trace_promise_primitives.enabled()) {
824           gpr_log(
825               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
826               "seq[%p]: poll step 3/5 gets %s", this,
827               p != nullptr
828                   ? (PromiseResultTraits2::IsOk(*p)
829                          ? "ready"
830                          : absl::StrCat("early-error:",
831                                         PromiseResultTraits2::ErrorString(*p))
832                                .c_str())
833                   : "pending");
834         }
835         if (p == nullptr) return Pending{};
836         if (!PromiseResultTraits2::IsOk(*p)) {
837           return PromiseResultTraits2::template ReturnValue<Result>(
838               std::move(*p));
839         }
840         Destruct(&prior.prior.current_promise);
841         auto next_promise = PromiseResultTraits2::CallFactory(
842             &prior.prior.next_factory, std::move(*p));
843         Destruct(&prior.prior.next_factory);
844         Construct(&prior.current_promise, std::move(next_promise));
845         state = State::kState3;
846       }
847         ABSL_FALLTHROUGH_INTENDED;
848       case State::kState3: {
849         if (grpc_trace_promise_primitives.enabled()) {
850           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
851                   "seq[%p]: begin poll step 4/5", this);
852         }
853         auto result = prior.current_promise();
854         PromiseResult3* p = result.value_if_ready();
855         if (grpc_trace_promise_primitives.enabled()) {
856           gpr_log(
857               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
858               "seq[%p]: poll step 4/5 gets %s", this,
859               p != nullptr
860                   ? (PromiseResultTraits3::IsOk(*p)
861                          ? "ready"
862                          : absl::StrCat("early-error:",
863                                         PromiseResultTraits3::ErrorString(*p))
864                                .c_str())
865                   : "pending");
866         }
867         if (p == nullptr) return Pending{};
868         if (!PromiseResultTraits3::IsOk(*p)) {
869           return PromiseResultTraits3::template ReturnValue<Result>(
870               std::move(*p));
871         }
872         Destruct(&prior.current_promise);
873         auto next_promise = PromiseResultTraits3::CallFactory(
874             &prior.next_factory, std::move(*p));
875         Destruct(&prior.next_factory);
876         Construct(&current_promise, std::move(next_promise));
877         state = State::kState4;
878       }
879         ABSL_FALLTHROUGH_INTENDED;
880       default:
881       case State::kState4: {
882         if (grpc_trace_promise_primitives.enabled()) {
883           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
884                   "seq[%p]: begin poll step 5/5", this);
885         }
886         auto result = current_promise();
887         if (grpc_trace_promise_primitives.enabled()) {
888           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
889                   "seq[%p]: poll step 5/5 gets %s", this,
890                   result.ready() ? "ready" : "pending");
891         }
892         auto* p = result.value_if_ready();
893         if (p == nullptr) return Pending{};
894         return Result(std::move(*p));
895       }
896     }
897   }
898 };
899 
900 template <template <typename> class Traits, typename P, typename F0,
901           typename F1, typename F2, typename F3, typename F4>
902 struct SeqState<Traits, P, F0, F1, F2, F3, F4> {
903   using Promise0 = PromiseLike<P>;
904   using PromiseResult0 = typename Promise0::Result;
905   using PromiseResultTraits0 = Traits<PromiseResult0>;
906   using NextFactory0 =
907       OncePromiseFactory<typename PromiseResultTraits0::UnwrappedType, F0>;
908   using Promise1 = typename NextFactory0::Promise;
909   using PromiseResult1 = typename Promise1::Result;
910   using PromiseResultTraits1 = Traits<PromiseResult1>;
911   using NextFactory1 =
912       OncePromiseFactory<typename PromiseResultTraits1::UnwrappedType, F1>;
913   using Promise2 = typename NextFactory1::Promise;
914   using PromiseResult2 = typename Promise2::Result;
915   using PromiseResultTraits2 = Traits<PromiseResult2>;
916   using NextFactory2 =
917       OncePromiseFactory<typename PromiseResultTraits2::UnwrappedType, F2>;
918   using Promise3 = typename NextFactory2::Promise;
919   using PromiseResult3 = typename Promise3::Result;
920   using PromiseResultTraits3 = Traits<PromiseResult3>;
921   using NextFactory3 =
922       OncePromiseFactory<typename PromiseResultTraits3::UnwrappedType, F3>;
923   using Promise4 = typename NextFactory3::Promise;
924   using PromiseResult4 = typename Promise4::Result;
925   using PromiseResultTraits4 = Traits<PromiseResult4>;
926   using NextFactory4 =
927       OncePromiseFactory<typename PromiseResultTraits4::UnwrappedType, F4>;
928   using Promise5 = typename NextFactory4::Promise;
929   using PromiseResult5 = typename Promise5::Result;
930   using PromiseResultTraits5 = Traits<PromiseResult5>;
931   using Result = typename PromiseResultTraits5::WrappedType;
932   struct Running0 {
933     GPR_NO_UNIQUE_ADDRESS Promise0 current_promise;
934     GPR_NO_UNIQUE_ADDRESS NextFactory0 next_factory;
935   };
936   struct Running1 {
937     union {
938       GPR_NO_UNIQUE_ADDRESS Running0 prior;
939       GPR_NO_UNIQUE_ADDRESS Promise1 current_promise;
940     };
941     GPR_NO_UNIQUE_ADDRESS NextFactory1 next_factory;
942   };
943   struct Running2 {
944     union {
945       GPR_NO_UNIQUE_ADDRESS Running1 prior;
946       GPR_NO_UNIQUE_ADDRESS Promise2 current_promise;
947     };
948     GPR_NO_UNIQUE_ADDRESS NextFactory2 next_factory;
949   };
950   struct Running3 {
951     union {
952       GPR_NO_UNIQUE_ADDRESS Running2 prior;
953       GPR_NO_UNIQUE_ADDRESS Promise3 current_promise;
954     };
955     GPR_NO_UNIQUE_ADDRESS NextFactory3 next_factory;
956   };
957   struct Running4 {
958     union {
959       GPR_NO_UNIQUE_ADDRESS Running3 prior;
960       GPR_NO_UNIQUE_ADDRESS Promise4 current_promise;
961     };
962     GPR_NO_UNIQUE_ADDRESS NextFactory4 next_factory;
963   };
964   union {
965     GPR_NO_UNIQUE_ADDRESS Running4 prior;
966     GPR_NO_UNIQUE_ADDRESS Promise5 current_promise;
967   };
968   enum class State : uint8_t {
969     kState0,
970     kState1,
971     kState2,
972     kState3,
973     kState4,
974     kState5
975   };
976   GPR_NO_UNIQUE_ADDRESS State state = State::kState0;
977   GPR_NO_UNIQUE_ADDRESS DebugLocation whence;
978 
979   SeqState(P&& p, F0&& f0, F1&& f1, F2&& f2, F3&& f3, F4&& f4,
980            DebugLocation whence) noexcept
981       : whence(whence) {
982     Construct(&prior.prior.prior.prior.prior.current_promise,
983               std::forward<P>(p));
984     Construct(&prior.prior.prior.prior.prior.next_factory,
985               std::forward<F0>(f0));
986     Construct(&prior.prior.prior.prior.next_factory, std::forward<F1>(f1));
987     Construct(&prior.prior.prior.next_factory, std::forward<F2>(f2));
988     Construct(&prior.prior.next_factory, std::forward<F3>(f3));
989     Construct(&prior.next_factory, std::forward<F4>(f4));
990   }
991   ~SeqState() {
992     switch (state) {
993       case State::kState0:
994         Destruct(&prior.prior.prior.prior.prior.current_promise);
995         goto tail0;
996       case State::kState1:
997         Destruct(&prior.prior.prior.prior.current_promise);
998         goto tail1;
999       case State::kState2:
1000         Destruct(&prior.prior.prior.current_promise);
1001         goto tail2;
1002       case State::kState3:
1003         Destruct(&prior.prior.current_promise);
1004         goto tail3;
1005       case State::kState4:
1006         Destruct(&prior.current_promise);
1007         goto tail4;
1008       case State::kState5:
1009         Destruct(&current_promise);
1010         return;
1011     }
1012   tail0:
1013     Destruct(&prior.prior.prior.prior.prior.next_factory);
1014   tail1:
1015     Destruct(&prior.prior.prior.prior.next_factory);
1016   tail2:
1017     Destruct(&prior.prior.prior.next_factory);
1018   tail3:
1019     Destruct(&prior.prior.next_factory);
1020   tail4:
1021     Destruct(&prior.next_factory);
1022   }
1023   SeqState(const SeqState& other) noexcept
1024       : state(other.state), whence(other.whence) {
1025     GPR_ASSERT(state == State::kState0);
1026     Construct(&prior.current_promise, other.prior.current_promise);
1027     Construct(&prior.prior.prior.prior.prior.next_factory,
1028               other.prior.prior.prior.prior.prior.next_factory);
1029     Construct(&prior.prior.prior.prior.next_factory,
1030               other.prior.prior.prior.prior.next_factory);
1031     Construct(&prior.prior.prior.next_factory,
1032               other.prior.prior.prior.next_factory);
1033     Construct(&prior.prior.next_factory, other.prior.prior.next_factory);
1034     Construct(&prior.next_factory, other.prior.next_factory);
1035   }
1036   SeqState& operator=(const SeqState& other) = delete;
1037   SeqState(SeqState&& other) noexcept
1038       : state(other.state), whence(other.whence) {
1039     switch (state) {
1040       case State::kState0:
1041         Construct(
1042             &prior.prior.prior.prior.prior.current_promise,
1043             std::move(other.prior.prior.prior.prior.prior.current_promise));
1044         goto tail0;
1045       case State::kState1:
1046         Construct(&prior.prior.prior.prior.current_promise,
1047                   std::move(other.prior.prior.prior.prior.current_promise));
1048         goto tail1;
1049       case State::kState2:
1050         Construct(&prior.prior.prior.current_promise,
1051                   std::move(other.prior.prior.prior.current_promise));
1052         goto tail2;
1053       case State::kState3:
1054         Construct(&prior.prior.current_promise,
1055                   std::move(other.prior.prior.current_promise));
1056         goto tail3;
1057       case State::kState4:
1058         Construct(&prior.current_promise,
1059                   std::move(other.prior.current_promise));
1060         goto tail4;
1061       case State::kState5:
1062         Construct(&current_promise, std::move(other.current_promise));
1063         return;
1064     }
1065   tail0:
1066     Construct(&prior.prior.prior.prior.prior.next_factory,
1067               std::move(other.prior.prior.prior.prior.prior.next_factory));
1068   tail1:
1069     Construct(&prior.prior.prior.prior.next_factory,
1070               std::move(other.prior.prior.prior.prior.next_factory));
1071   tail2:
1072     Construct(&prior.prior.prior.next_factory,
1073               std::move(other.prior.prior.prior.next_factory));
1074   tail3:
1075     Construct(&prior.prior.next_factory,
1076               std::move(other.prior.prior.next_factory));
1077   tail4:
1078     Construct(&prior.next_factory, std::move(other.prior.next_factory));
1079   }
1080   SeqState& operator=(SeqState&& other) = delete;
1081   Poll<Result> PollOnce() {
1082     switch (state) {
1083       case State::kState0: {
1084         if (grpc_trace_promise_primitives.enabled()) {
1085           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1086                   "seq[%p]: begin poll step 1/6", this);
1087         }
1088         auto result = prior.prior.prior.prior.prior.current_promise();
1089         PromiseResult0* p = result.value_if_ready();
1090         if (grpc_trace_promise_primitives.enabled()) {
1091           gpr_log(
1092               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1093               "seq[%p]: poll step 1/6 gets %s", this,
1094               p != nullptr
1095                   ? (PromiseResultTraits0::IsOk(*p)
1096                          ? "ready"
1097                          : absl::StrCat("early-error:",
1098                                         PromiseResultTraits0::ErrorString(*p))
1099                                .c_str())
1100                   : "pending");
1101         }
1102         if (p == nullptr) return Pending{};
1103         if (!PromiseResultTraits0::IsOk(*p)) {
1104           return PromiseResultTraits0::template ReturnValue<Result>(
1105               std::move(*p));
1106         }
1107         Destruct(&prior.prior.prior.prior.prior.current_promise);
1108         auto next_promise = PromiseResultTraits0::CallFactory(
1109             &prior.prior.prior.prior.prior.next_factory, std::move(*p));
1110         Destruct(&prior.prior.prior.prior.prior.next_factory);
1111         Construct(&prior.prior.prior.prior.current_promise,
1112                   std::move(next_promise));
1113         state = State::kState1;
1114       }
1115         ABSL_FALLTHROUGH_INTENDED;
1116       case State::kState1: {
1117         if (grpc_trace_promise_primitives.enabled()) {
1118           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1119                   "seq[%p]: begin poll step 2/6", this);
1120         }
1121         auto result = prior.prior.prior.prior.current_promise();
1122         PromiseResult1* p = result.value_if_ready();
1123         if (grpc_trace_promise_primitives.enabled()) {
1124           gpr_log(
1125               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1126               "seq[%p]: poll step 2/6 gets %s", this,
1127               p != nullptr
1128                   ? (PromiseResultTraits1::IsOk(*p)
1129                          ? "ready"
1130                          : absl::StrCat("early-error:",
1131                                         PromiseResultTraits1::ErrorString(*p))
1132                                .c_str())
1133                   : "pending");
1134         }
1135         if (p == nullptr) return Pending{};
1136         if (!PromiseResultTraits1::IsOk(*p)) {
1137           return PromiseResultTraits1::template ReturnValue<Result>(
1138               std::move(*p));
1139         }
1140         Destruct(&prior.prior.prior.prior.current_promise);
1141         auto next_promise = PromiseResultTraits1::CallFactory(
1142             &prior.prior.prior.prior.next_factory, std::move(*p));
1143         Destruct(&prior.prior.prior.prior.next_factory);
1144         Construct(&prior.prior.prior.current_promise, std::move(next_promise));
1145         state = State::kState2;
1146       }
1147         ABSL_FALLTHROUGH_INTENDED;
1148       case State::kState2: {
1149         if (grpc_trace_promise_primitives.enabled()) {
1150           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1151                   "seq[%p]: begin poll step 3/6", this);
1152         }
1153         auto result = prior.prior.prior.current_promise();
1154         PromiseResult2* p = result.value_if_ready();
1155         if (grpc_trace_promise_primitives.enabled()) {
1156           gpr_log(
1157               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1158               "seq[%p]: poll step 3/6 gets %s", this,
1159               p != nullptr
1160                   ? (PromiseResultTraits2::IsOk(*p)
1161                          ? "ready"
1162                          : absl::StrCat("early-error:",
1163                                         PromiseResultTraits2::ErrorString(*p))
1164                                .c_str())
1165                   : "pending");
1166         }
1167         if (p == nullptr) return Pending{};
1168         if (!PromiseResultTraits2::IsOk(*p)) {
1169           return PromiseResultTraits2::template ReturnValue<Result>(
1170               std::move(*p));
1171         }
1172         Destruct(&prior.prior.prior.current_promise);
1173         auto next_promise = PromiseResultTraits2::CallFactory(
1174             &prior.prior.prior.next_factory, std::move(*p));
1175         Destruct(&prior.prior.prior.next_factory);
1176         Construct(&prior.prior.current_promise, std::move(next_promise));
1177         state = State::kState3;
1178       }
1179         ABSL_FALLTHROUGH_INTENDED;
1180       case State::kState3: {
1181         if (grpc_trace_promise_primitives.enabled()) {
1182           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1183                   "seq[%p]: begin poll step 4/6", this);
1184         }
1185         auto result = prior.prior.current_promise();
1186         PromiseResult3* p = result.value_if_ready();
1187         if (grpc_trace_promise_primitives.enabled()) {
1188           gpr_log(
1189               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1190               "seq[%p]: poll step 4/6 gets %s", this,
1191               p != nullptr
1192                   ? (PromiseResultTraits3::IsOk(*p)
1193                          ? "ready"
1194                          : absl::StrCat("early-error:",
1195                                         PromiseResultTraits3::ErrorString(*p))
1196                                .c_str())
1197                   : "pending");
1198         }
1199         if (p == nullptr) return Pending{};
1200         if (!PromiseResultTraits3::IsOk(*p)) {
1201           return PromiseResultTraits3::template ReturnValue<Result>(
1202               std::move(*p));
1203         }
1204         Destruct(&prior.prior.current_promise);
1205         auto next_promise = PromiseResultTraits3::CallFactory(
1206             &prior.prior.next_factory, std::move(*p));
1207         Destruct(&prior.prior.next_factory);
1208         Construct(&prior.current_promise, std::move(next_promise));
1209         state = State::kState4;
1210       }
1211         ABSL_FALLTHROUGH_INTENDED;
1212       case State::kState4: {
1213         if (grpc_trace_promise_primitives.enabled()) {
1214           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1215                   "seq[%p]: begin poll step 5/6", this);
1216         }
1217         auto result = prior.current_promise();
1218         PromiseResult4* p = result.value_if_ready();
1219         if (grpc_trace_promise_primitives.enabled()) {
1220           gpr_log(
1221               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1222               "seq[%p]: poll step 5/6 gets %s", this,
1223               p != nullptr
1224                   ? (PromiseResultTraits4::IsOk(*p)
1225                          ? "ready"
1226                          : absl::StrCat("early-error:",
1227                                         PromiseResultTraits4::ErrorString(*p))
1228                                .c_str())
1229                   : "pending");
1230         }
1231         if (p == nullptr) return Pending{};
1232         if (!PromiseResultTraits4::IsOk(*p)) {
1233           return PromiseResultTraits4::template ReturnValue<Result>(
1234               std::move(*p));
1235         }
1236         Destruct(&prior.current_promise);
1237         auto next_promise = PromiseResultTraits4::CallFactory(
1238             &prior.next_factory, std::move(*p));
1239         Destruct(&prior.next_factory);
1240         Construct(&current_promise, std::move(next_promise));
1241         state = State::kState5;
1242       }
1243         ABSL_FALLTHROUGH_INTENDED;
1244       default:
1245       case State::kState5: {
1246         if (grpc_trace_promise_primitives.enabled()) {
1247           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1248                   "seq[%p]: begin poll step 6/6", this);
1249         }
1250         auto result = current_promise();
1251         if (grpc_trace_promise_primitives.enabled()) {
1252           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1253                   "seq[%p]: poll step 6/6 gets %s", this,
1254                   result.ready() ? "ready" : "pending");
1255         }
1256         auto* p = result.value_if_ready();
1257         if (p == nullptr) return Pending{};
1258         return Result(std::move(*p));
1259       }
1260     }
1261   }
1262 };
1263 
1264 template <template <typename> class Traits, typename P, typename F0,
1265           typename F1, typename F2, typename F3, typename F4, typename F5>
1266 struct SeqState<Traits, P, F0, F1, F2, F3, F4, F5> {
1267   using Promise0 = PromiseLike<P>;
1268   using PromiseResult0 = typename Promise0::Result;
1269   using PromiseResultTraits0 = Traits<PromiseResult0>;
1270   using NextFactory0 =
1271       OncePromiseFactory<typename PromiseResultTraits0::UnwrappedType, F0>;
1272   using Promise1 = typename NextFactory0::Promise;
1273   using PromiseResult1 = typename Promise1::Result;
1274   using PromiseResultTraits1 = Traits<PromiseResult1>;
1275   using NextFactory1 =
1276       OncePromiseFactory<typename PromiseResultTraits1::UnwrappedType, F1>;
1277   using Promise2 = typename NextFactory1::Promise;
1278   using PromiseResult2 = typename Promise2::Result;
1279   using PromiseResultTraits2 = Traits<PromiseResult2>;
1280   using NextFactory2 =
1281       OncePromiseFactory<typename PromiseResultTraits2::UnwrappedType, F2>;
1282   using Promise3 = typename NextFactory2::Promise;
1283   using PromiseResult3 = typename Promise3::Result;
1284   using PromiseResultTraits3 = Traits<PromiseResult3>;
1285   using NextFactory3 =
1286       OncePromiseFactory<typename PromiseResultTraits3::UnwrappedType, F3>;
1287   using Promise4 = typename NextFactory3::Promise;
1288   using PromiseResult4 = typename Promise4::Result;
1289   using PromiseResultTraits4 = Traits<PromiseResult4>;
1290   using NextFactory4 =
1291       OncePromiseFactory<typename PromiseResultTraits4::UnwrappedType, F4>;
1292   using Promise5 = typename NextFactory4::Promise;
1293   using PromiseResult5 = typename Promise5::Result;
1294   using PromiseResultTraits5 = Traits<PromiseResult5>;
1295   using NextFactory5 =
1296       OncePromiseFactory<typename PromiseResultTraits5::UnwrappedType, F5>;
1297   using Promise6 = typename NextFactory5::Promise;
1298   using PromiseResult6 = typename Promise6::Result;
1299   using PromiseResultTraits6 = Traits<PromiseResult6>;
1300   using Result = typename PromiseResultTraits6::WrappedType;
1301   struct Running0 {
1302     GPR_NO_UNIQUE_ADDRESS Promise0 current_promise;
1303     GPR_NO_UNIQUE_ADDRESS NextFactory0 next_factory;
1304   };
1305   struct Running1 {
1306     union {
1307       GPR_NO_UNIQUE_ADDRESS Running0 prior;
1308       GPR_NO_UNIQUE_ADDRESS Promise1 current_promise;
1309     };
1310     GPR_NO_UNIQUE_ADDRESS NextFactory1 next_factory;
1311   };
1312   struct Running2 {
1313     union {
1314       GPR_NO_UNIQUE_ADDRESS Running1 prior;
1315       GPR_NO_UNIQUE_ADDRESS Promise2 current_promise;
1316     };
1317     GPR_NO_UNIQUE_ADDRESS NextFactory2 next_factory;
1318   };
1319   struct Running3 {
1320     union {
1321       GPR_NO_UNIQUE_ADDRESS Running2 prior;
1322       GPR_NO_UNIQUE_ADDRESS Promise3 current_promise;
1323     };
1324     GPR_NO_UNIQUE_ADDRESS NextFactory3 next_factory;
1325   };
1326   struct Running4 {
1327     union {
1328       GPR_NO_UNIQUE_ADDRESS Running3 prior;
1329       GPR_NO_UNIQUE_ADDRESS Promise4 current_promise;
1330     };
1331     GPR_NO_UNIQUE_ADDRESS NextFactory4 next_factory;
1332   };
1333   struct Running5 {
1334     union {
1335       GPR_NO_UNIQUE_ADDRESS Running4 prior;
1336       GPR_NO_UNIQUE_ADDRESS Promise5 current_promise;
1337     };
1338     GPR_NO_UNIQUE_ADDRESS NextFactory5 next_factory;
1339   };
1340   union {
1341     GPR_NO_UNIQUE_ADDRESS Running5 prior;
1342     GPR_NO_UNIQUE_ADDRESS Promise6 current_promise;
1343   };
1344   enum class State : uint8_t {
1345     kState0,
1346     kState1,
1347     kState2,
1348     kState3,
1349     kState4,
1350     kState5,
1351     kState6
1352   };
1353   GPR_NO_UNIQUE_ADDRESS State state = State::kState0;
1354   GPR_NO_UNIQUE_ADDRESS DebugLocation whence;
1355 
1356   SeqState(P&& p, F0&& f0, F1&& f1, F2&& f2, F3&& f3, F4&& f4, F5&& f5,
1357            DebugLocation whence) noexcept
1358       : whence(whence) {
1359     Construct(&prior.prior.prior.prior.prior.prior.current_promise,
1360               std::forward<P>(p));
1361     Construct(&prior.prior.prior.prior.prior.prior.next_factory,
1362               std::forward<F0>(f0));
1363     Construct(&prior.prior.prior.prior.prior.next_factory,
1364               std::forward<F1>(f1));
1365     Construct(&prior.prior.prior.prior.next_factory, std::forward<F2>(f2));
1366     Construct(&prior.prior.prior.next_factory, std::forward<F3>(f3));
1367     Construct(&prior.prior.next_factory, std::forward<F4>(f4));
1368     Construct(&prior.next_factory, std::forward<F5>(f5));
1369   }
1370   ~SeqState() {
1371     switch (state) {
1372       case State::kState0:
1373         Destruct(&prior.prior.prior.prior.prior.prior.current_promise);
1374         goto tail0;
1375       case State::kState1:
1376         Destruct(&prior.prior.prior.prior.prior.current_promise);
1377         goto tail1;
1378       case State::kState2:
1379         Destruct(&prior.prior.prior.prior.current_promise);
1380         goto tail2;
1381       case State::kState3:
1382         Destruct(&prior.prior.prior.current_promise);
1383         goto tail3;
1384       case State::kState4:
1385         Destruct(&prior.prior.current_promise);
1386         goto tail4;
1387       case State::kState5:
1388         Destruct(&prior.current_promise);
1389         goto tail5;
1390       case State::kState6:
1391         Destruct(&current_promise);
1392         return;
1393     }
1394   tail0:
1395     Destruct(&prior.prior.prior.prior.prior.prior.next_factory);
1396   tail1:
1397     Destruct(&prior.prior.prior.prior.prior.next_factory);
1398   tail2:
1399     Destruct(&prior.prior.prior.prior.next_factory);
1400   tail3:
1401     Destruct(&prior.prior.prior.next_factory);
1402   tail4:
1403     Destruct(&prior.prior.next_factory);
1404   tail5:
1405     Destruct(&prior.next_factory);
1406   }
1407   SeqState(const SeqState& other) noexcept
1408       : state(other.state), whence(other.whence) {
1409     GPR_ASSERT(state == State::kState0);
1410     Construct(&prior.current_promise, other.prior.current_promise);
1411     Construct(&prior.prior.prior.prior.prior.prior.next_factory,
1412               other.prior.prior.prior.prior.prior.prior.next_factory);
1413     Construct(&prior.prior.prior.prior.prior.next_factory,
1414               other.prior.prior.prior.prior.prior.next_factory);
1415     Construct(&prior.prior.prior.prior.next_factory,
1416               other.prior.prior.prior.prior.next_factory);
1417     Construct(&prior.prior.prior.next_factory,
1418               other.prior.prior.prior.next_factory);
1419     Construct(&prior.prior.next_factory, other.prior.prior.next_factory);
1420     Construct(&prior.next_factory, other.prior.next_factory);
1421   }
1422   SeqState& operator=(const SeqState& other) = delete;
1423   SeqState(SeqState&& other) noexcept
1424       : state(other.state), whence(other.whence) {
1425     switch (state) {
1426       case State::kState0:
1427         Construct(
1428             &prior.prior.prior.prior.prior.prior.current_promise,
1429             std::move(
1430                 other.prior.prior.prior.prior.prior.prior.current_promise));
1431         goto tail0;
1432       case State::kState1:
1433         Construct(
1434             &prior.prior.prior.prior.prior.current_promise,
1435             std::move(other.prior.prior.prior.prior.prior.current_promise));
1436         goto tail1;
1437       case State::kState2:
1438         Construct(&prior.prior.prior.prior.current_promise,
1439                   std::move(other.prior.prior.prior.prior.current_promise));
1440         goto tail2;
1441       case State::kState3:
1442         Construct(&prior.prior.prior.current_promise,
1443                   std::move(other.prior.prior.prior.current_promise));
1444         goto tail3;
1445       case State::kState4:
1446         Construct(&prior.prior.current_promise,
1447                   std::move(other.prior.prior.current_promise));
1448         goto tail4;
1449       case State::kState5:
1450         Construct(&prior.current_promise,
1451                   std::move(other.prior.current_promise));
1452         goto tail5;
1453       case State::kState6:
1454         Construct(&current_promise, std::move(other.current_promise));
1455         return;
1456     }
1457   tail0:
1458     Construct(
1459         &prior.prior.prior.prior.prior.prior.next_factory,
1460         std::move(other.prior.prior.prior.prior.prior.prior.next_factory));
1461   tail1:
1462     Construct(&prior.prior.prior.prior.prior.next_factory,
1463               std::move(other.prior.prior.prior.prior.prior.next_factory));
1464   tail2:
1465     Construct(&prior.prior.prior.prior.next_factory,
1466               std::move(other.prior.prior.prior.prior.next_factory));
1467   tail3:
1468     Construct(&prior.prior.prior.next_factory,
1469               std::move(other.prior.prior.prior.next_factory));
1470   tail4:
1471     Construct(&prior.prior.next_factory,
1472               std::move(other.prior.prior.next_factory));
1473   tail5:
1474     Construct(&prior.next_factory, std::move(other.prior.next_factory));
1475   }
1476   SeqState& operator=(SeqState&& other) = delete;
1477   Poll<Result> PollOnce() {
1478     switch (state) {
1479       case State::kState0: {
1480         if (grpc_trace_promise_primitives.enabled()) {
1481           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1482                   "seq[%p]: begin poll step 1/7", this);
1483         }
1484         auto result = prior.prior.prior.prior.prior.prior.current_promise();
1485         PromiseResult0* p = result.value_if_ready();
1486         if (grpc_trace_promise_primitives.enabled()) {
1487           gpr_log(
1488               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1489               "seq[%p]: poll step 1/7 gets %s", this,
1490               p != nullptr
1491                   ? (PromiseResultTraits0::IsOk(*p)
1492                          ? "ready"
1493                          : absl::StrCat("early-error:",
1494                                         PromiseResultTraits0::ErrorString(*p))
1495                                .c_str())
1496                   : "pending");
1497         }
1498         if (p == nullptr) return Pending{};
1499         if (!PromiseResultTraits0::IsOk(*p)) {
1500           return PromiseResultTraits0::template ReturnValue<Result>(
1501               std::move(*p));
1502         }
1503         Destruct(&prior.prior.prior.prior.prior.prior.current_promise);
1504         auto next_promise = PromiseResultTraits0::CallFactory(
1505             &prior.prior.prior.prior.prior.prior.next_factory, std::move(*p));
1506         Destruct(&prior.prior.prior.prior.prior.prior.next_factory);
1507         Construct(&prior.prior.prior.prior.prior.current_promise,
1508                   std::move(next_promise));
1509         state = State::kState1;
1510       }
1511         ABSL_FALLTHROUGH_INTENDED;
1512       case State::kState1: {
1513         if (grpc_trace_promise_primitives.enabled()) {
1514           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1515                   "seq[%p]: begin poll step 2/7", this);
1516         }
1517         auto result = prior.prior.prior.prior.prior.current_promise();
1518         PromiseResult1* p = result.value_if_ready();
1519         if (grpc_trace_promise_primitives.enabled()) {
1520           gpr_log(
1521               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1522               "seq[%p]: poll step 2/7 gets %s", this,
1523               p != nullptr
1524                   ? (PromiseResultTraits1::IsOk(*p)
1525                          ? "ready"
1526                          : absl::StrCat("early-error:",
1527                                         PromiseResultTraits1::ErrorString(*p))
1528                                .c_str())
1529                   : "pending");
1530         }
1531         if (p == nullptr) return Pending{};
1532         if (!PromiseResultTraits1::IsOk(*p)) {
1533           return PromiseResultTraits1::template ReturnValue<Result>(
1534               std::move(*p));
1535         }
1536         Destruct(&prior.prior.prior.prior.prior.current_promise);
1537         auto next_promise = PromiseResultTraits1::CallFactory(
1538             &prior.prior.prior.prior.prior.next_factory, std::move(*p));
1539         Destruct(&prior.prior.prior.prior.prior.next_factory);
1540         Construct(&prior.prior.prior.prior.current_promise,
1541                   std::move(next_promise));
1542         state = State::kState2;
1543       }
1544         ABSL_FALLTHROUGH_INTENDED;
1545       case State::kState2: {
1546         if (grpc_trace_promise_primitives.enabled()) {
1547           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1548                   "seq[%p]: begin poll step 3/7", this);
1549         }
1550         auto result = prior.prior.prior.prior.current_promise();
1551         PromiseResult2* p = result.value_if_ready();
1552         if (grpc_trace_promise_primitives.enabled()) {
1553           gpr_log(
1554               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1555               "seq[%p]: poll step 3/7 gets %s", this,
1556               p != nullptr
1557                   ? (PromiseResultTraits2::IsOk(*p)
1558                          ? "ready"
1559                          : absl::StrCat("early-error:",
1560                                         PromiseResultTraits2::ErrorString(*p))
1561                                .c_str())
1562                   : "pending");
1563         }
1564         if (p == nullptr) return Pending{};
1565         if (!PromiseResultTraits2::IsOk(*p)) {
1566           return PromiseResultTraits2::template ReturnValue<Result>(
1567               std::move(*p));
1568         }
1569         Destruct(&prior.prior.prior.prior.current_promise);
1570         auto next_promise = PromiseResultTraits2::CallFactory(
1571             &prior.prior.prior.prior.next_factory, std::move(*p));
1572         Destruct(&prior.prior.prior.prior.next_factory);
1573         Construct(&prior.prior.prior.current_promise, std::move(next_promise));
1574         state = State::kState3;
1575       }
1576         ABSL_FALLTHROUGH_INTENDED;
1577       case State::kState3: {
1578         if (grpc_trace_promise_primitives.enabled()) {
1579           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1580                   "seq[%p]: begin poll step 4/7", this);
1581         }
1582         auto result = prior.prior.prior.current_promise();
1583         PromiseResult3* p = result.value_if_ready();
1584         if (grpc_trace_promise_primitives.enabled()) {
1585           gpr_log(
1586               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1587               "seq[%p]: poll step 4/7 gets %s", this,
1588               p != nullptr
1589                   ? (PromiseResultTraits3::IsOk(*p)
1590                          ? "ready"
1591                          : absl::StrCat("early-error:",
1592                                         PromiseResultTraits3::ErrorString(*p))
1593                                .c_str())
1594                   : "pending");
1595         }
1596         if (p == nullptr) return Pending{};
1597         if (!PromiseResultTraits3::IsOk(*p)) {
1598           return PromiseResultTraits3::template ReturnValue<Result>(
1599               std::move(*p));
1600         }
1601         Destruct(&prior.prior.prior.current_promise);
1602         auto next_promise = PromiseResultTraits3::CallFactory(
1603             &prior.prior.prior.next_factory, std::move(*p));
1604         Destruct(&prior.prior.prior.next_factory);
1605         Construct(&prior.prior.current_promise, std::move(next_promise));
1606         state = State::kState4;
1607       }
1608         ABSL_FALLTHROUGH_INTENDED;
1609       case State::kState4: {
1610         if (grpc_trace_promise_primitives.enabled()) {
1611           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1612                   "seq[%p]: begin poll step 5/7", this);
1613         }
1614         auto result = prior.prior.current_promise();
1615         PromiseResult4* p = result.value_if_ready();
1616         if (grpc_trace_promise_primitives.enabled()) {
1617           gpr_log(
1618               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1619               "seq[%p]: poll step 5/7 gets %s", this,
1620               p != nullptr
1621                   ? (PromiseResultTraits4::IsOk(*p)
1622                          ? "ready"
1623                          : absl::StrCat("early-error:",
1624                                         PromiseResultTraits4::ErrorString(*p))
1625                                .c_str())
1626                   : "pending");
1627         }
1628         if (p == nullptr) return Pending{};
1629         if (!PromiseResultTraits4::IsOk(*p)) {
1630           return PromiseResultTraits4::template ReturnValue<Result>(
1631               std::move(*p));
1632         }
1633         Destruct(&prior.prior.current_promise);
1634         auto next_promise = PromiseResultTraits4::CallFactory(
1635             &prior.prior.next_factory, std::move(*p));
1636         Destruct(&prior.prior.next_factory);
1637         Construct(&prior.current_promise, std::move(next_promise));
1638         state = State::kState5;
1639       }
1640         ABSL_FALLTHROUGH_INTENDED;
1641       case State::kState5: {
1642         if (grpc_trace_promise_primitives.enabled()) {
1643           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1644                   "seq[%p]: begin poll step 6/7", this);
1645         }
1646         auto result = prior.current_promise();
1647         PromiseResult5* p = result.value_if_ready();
1648         if (grpc_trace_promise_primitives.enabled()) {
1649           gpr_log(
1650               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1651               "seq[%p]: poll step 6/7 gets %s", this,
1652               p != nullptr
1653                   ? (PromiseResultTraits5::IsOk(*p)
1654                          ? "ready"
1655                          : absl::StrCat("early-error:",
1656                                         PromiseResultTraits5::ErrorString(*p))
1657                                .c_str())
1658                   : "pending");
1659         }
1660         if (p == nullptr) return Pending{};
1661         if (!PromiseResultTraits5::IsOk(*p)) {
1662           return PromiseResultTraits5::template ReturnValue<Result>(
1663               std::move(*p));
1664         }
1665         Destruct(&prior.current_promise);
1666         auto next_promise = PromiseResultTraits5::CallFactory(
1667             &prior.next_factory, std::move(*p));
1668         Destruct(&prior.next_factory);
1669         Construct(&current_promise, std::move(next_promise));
1670         state = State::kState6;
1671       }
1672         ABSL_FALLTHROUGH_INTENDED;
1673       default:
1674       case State::kState6: {
1675         if (grpc_trace_promise_primitives.enabled()) {
1676           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1677                   "seq[%p]: begin poll step 7/7", this);
1678         }
1679         auto result = current_promise();
1680         if (grpc_trace_promise_primitives.enabled()) {
1681           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1682                   "seq[%p]: poll step 7/7 gets %s", this,
1683                   result.ready() ? "ready" : "pending");
1684         }
1685         auto* p = result.value_if_ready();
1686         if (p == nullptr) return Pending{};
1687         return Result(std::move(*p));
1688       }
1689     }
1690   }
1691 };
1692 
1693 template <template <typename> class Traits, typename P, typename F0,
1694           typename F1, typename F2, typename F3, typename F4, typename F5,
1695           typename F6>
1696 struct SeqState<Traits, P, F0, F1, F2, F3, F4, F5, F6> {
1697   using Promise0 = PromiseLike<P>;
1698   using PromiseResult0 = typename Promise0::Result;
1699   using PromiseResultTraits0 = Traits<PromiseResult0>;
1700   using NextFactory0 =
1701       OncePromiseFactory<typename PromiseResultTraits0::UnwrappedType, F0>;
1702   using Promise1 = typename NextFactory0::Promise;
1703   using PromiseResult1 = typename Promise1::Result;
1704   using PromiseResultTraits1 = Traits<PromiseResult1>;
1705   using NextFactory1 =
1706       OncePromiseFactory<typename PromiseResultTraits1::UnwrappedType, F1>;
1707   using Promise2 = typename NextFactory1::Promise;
1708   using PromiseResult2 = typename Promise2::Result;
1709   using PromiseResultTraits2 = Traits<PromiseResult2>;
1710   using NextFactory2 =
1711       OncePromiseFactory<typename PromiseResultTraits2::UnwrappedType, F2>;
1712   using Promise3 = typename NextFactory2::Promise;
1713   using PromiseResult3 = typename Promise3::Result;
1714   using PromiseResultTraits3 = Traits<PromiseResult3>;
1715   using NextFactory3 =
1716       OncePromiseFactory<typename PromiseResultTraits3::UnwrappedType, F3>;
1717   using Promise4 = typename NextFactory3::Promise;
1718   using PromiseResult4 = typename Promise4::Result;
1719   using PromiseResultTraits4 = Traits<PromiseResult4>;
1720   using NextFactory4 =
1721       OncePromiseFactory<typename PromiseResultTraits4::UnwrappedType, F4>;
1722   using Promise5 = typename NextFactory4::Promise;
1723   using PromiseResult5 = typename Promise5::Result;
1724   using PromiseResultTraits5 = Traits<PromiseResult5>;
1725   using NextFactory5 =
1726       OncePromiseFactory<typename PromiseResultTraits5::UnwrappedType, F5>;
1727   using Promise6 = typename NextFactory5::Promise;
1728   using PromiseResult6 = typename Promise6::Result;
1729   using PromiseResultTraits6 = Traits<PromiseResult6>;
1730   using NextFactory6 =
1731       OncePromiseFactory<typename PromiseResultTraits6::UnwrappedType, F6>;
1732   using Promise7 = typename NextFactory6::Promise;
1733   using PromiseResult7 = typename Promise7::Result;
1734   using PromiseResultTraits7 = Traits<PromiseResult7>;
1735   using Result = typename PromiseResultTraits7::WrappedType;
1736   struct Running0 {
1737     GPR_NO_UNIQUE_ADDRESS Promise0 current_promise;
1738     GPR_NO_UNIQUE_ADDRESS NextFactory0 next_factory;
1739   };
1740   struct Running1 {
1741     union {
1742       GPR_NO_UNIQUE_ADDRESS Running0 prior;
1743       GPR_NO_UNIQUE_ADDRESS Promise1 current_promise;
1744     };
1745     GPR_NO_UNIQUE_ADDRESS NextFactory1 next_factory;
1746   };
1747   struct Running2 {
1748     union {
1749       GPR_NO_UNIQUE_ADDRESS Running1 prior;
1750       GPR_NO_UNIQUE_ADDRESS Promise2 current_promise;
1751     };
1752     GPR_NO_UNIQUE_ADDRESS NextFactory2 next_factory;
1753   };
1754   struct Running3 {
1755     union {
1756       GPR_NO_UNIQUE_ADDRESS Running2 prior;
1757       GPR_NO_UNIQUE_ADDRESS Promise3 current_promise;
1758     };
1759     GPR_NO_UNIQUE_ADDRESS NextFactory3 next_factory;
1760   };
1761   struct Running4 {
1762     union {
1763       GPR_NO_UNIQUE_ADDRESS Running3 prior;
1764       GPR_NO_UNIQUE_ADDRESS Promise4 current_promise;
1765     };
1766     GPR_NO_UNIQUE_ADDRESS NextFactory4 next_factory;
1767   };
1768   struct Running5 {
1769     union {
1770       GPR_NO_UNIQUE_ADDRESS Running4 prior;
1771       GPR_NO_UNIQUE_ADDRESS Promise5 current_promise;
1772     };
1773     GPR_NO_UNIQUE_ADDRESS NextFactory5 next_factory;
1774   };
1775   struct Running6 {
1776     union {
1777       GPR_NO_UNIQUE_ADDRESS Running5 prior;
1778       GPR_NO_UNIQUE_ADDRESS Promise6 current_promise;
1779     };
1780     GPR_NO_UNIQUE_ADDRESS NextFactory6 next_factory;
1781   };
1782   union {
1783     GPR_NO_UNIQUE_ADDRESS Running6 prior;
1784     GPR_NO_UNIQUE_ADDRESS Promise7 current_promise;
1785   };
1786   enum class State : uint8_t {
1787     kState0,
1788     kState1,
1789     kState2,
1790     kState3,
1791     kState4,
1792     kState5,
1793     kState6,
1794     kState7
1795   };
1796   GPR_NO_UNIQUE_ADDRESS State state = State::kState0;
1797   GPR_NO_UNIQUE_ADDRESS DebugLocation whence;
1798 
1799   SeqState(P&& p, F0&& f0, F1&& f1, F2&& f2, F3&& f3, F4&& f4, F5&& f5, F6&& f6,
1800            DebugLocation whence) noexcept
1801       : whence(whence) {
1802     Construct(&prior.prior.prior.prior.prior.prior.prior.current_promise,
1803               std::forward<P>(p));
1804     Construct(&prior.prior.prior.prior.prior.prior.prior.next_factory,
1805               std::forward<F0>(f0));
1806     Construct(&prior.prior.prior.prior.prior.prior.next_factory,
1807               std::forward<F1>(f1));
1808     Construct(&prior.prior.prior.prior.prior.next_factory,
1809               std::forward<F2>(f2));
1810     Construct(&prior.prior.prior.prior.next_factory, std::forward<F3>(f3));
1811     Construct(&prior.prior.prior.next_factory, std::forward<F4>(f4));
1812     Construct(&prior.prior.next_factory, std::forward<F5>(f5));
1813     Construct(&prior.next_factory, std::forward<F6>(f6));
1814   }
1815   ~SeqState() {
1816     switch (state) {
1817       case State::kState0:
1818         Destruct(&prior.prior.prior.prior.prior.prior.prior.current_promise);
1819         goto tail0;
1820       case State::kState1:
1821         Destruct(&prior.prior.prior.prior.prior.prior.current_promise);
1822         goto tail1;
1823       case State::kState2:
1824         Destruct(&prior.prior.prior.prior.prior.current_promise);
1825         goto tail2;
1826       case State::kState3:
1827         Destruct(&prior.prior.prior.prior.current_promise);
1828         goto tail3;
1829       case State::kState4:
1830         Destruct(&prior.prior.prior.current_promise);
1831         goto tail4;
1832       case State::kState5:
1833         Destruct(&prior.prior.current_promise);
1834         goto tail5;
1835       case State::kState6:
1836         Destruct(&prior.current_promise);
1837         goto tail6;
1838       case State::kState7:
1839         Destruct(&current_promise);
1840         return;
1841     }
1842   tail0:
1843     Destruct(&prior.prior.prior.prior.prior.prior.prior.next_factory);
1844   tail1:
1845     Destruct(&prior.prior.prior.prior.prior.prior.next_factory);
1846   tail2:
1847     Destruct(&prior.prior.prior.prior.prior.next_factory);
1848   tail3:
1849     Destruct(&prior.prior.prior.prior.next_factory);
1850   tail4:
1851     Destruct(&prior.prior.prior.next_factory);
1852   tail5:
1853     Destruct(&prior.prior.next_factory);
1854   tail6:
1855     Destruct(&prior.next_factory);
1856   }
1857   SeqState(const SeqState& other) noexcept
1858       : state(other.state), whence(other.whence) {
1859     GPR_ASSERT(state == State::kState0);
1860     Construct(&prior.current_promise, other.prior.current_promise);
1861     Construct(&prior.prior.prior.prior.prior.prior.prior.next_factory,
1862               other.prior.prior.prior.prior.prior.prior.prior.next_factory);
1863     Construct(&prior.prior.prior.prior.prior.prior.next_factory,
1864               other.prior.prior.prior.prior.prior.prior.next_factory);
1865     Construct(&prior.prior.prior.prior.prior.next_factory,
1866               other.prior.prior.prior.prior.prior.next_factory);
1867     Construct(&prior.prior.prior.prior.next_factory,
1868               other.prior.prior.prior.prior.next_factory);
1869     Construct(&prior.prior.prior.next_factory,
1870               other.prior.prior.prior.next_factory);
1871     Construct(&prior.prior.next_factory, other.prior.prior.next_factory);
1872     Construct(&prior.next_factory, other.prior.next_factory);
1873   }
1874   SeqState& operator=(const SeqState& other) = delete;
1875   SeqState(SeqState&& other) noexcept
1876       : state(other.state), whence(other.whence) {
1877     switch (state) {
1878       case State::kState0:
1879         Construct(&prior.prior.prior.prior.prior.prior.prior.current_promise,
1880                   std::move(other.prior.prior.prior.prior.prior.prior.prior
1881                                 .current_promise));
1882         goto tail0;
1883       case State::kState1:
1884         Construct(
1885             &prior.prior.prior.prior.prior.prior.current_promise,
1886             std::move(
1887                 other.prior.prior.prior.prior.prior.prior.current_promise));
1888         goto tail1;
1889       case State::kState2:
1890         Construct(
1891             &prior.prior.prior.prior.prior.current_promise,
1892             std::move(other.prior.prior.prior.prior.prior.current_promise));
1893         goto tail2;
1894       case State::kState3:
1895         Construct(&prior.prior.prior.prior.current_promise,
1896                   std::move(other.prior.prior.prior.prior.current_promise));
1897         goto tail3;
1898       case State::kState4:
1899         Construct(&prior.prior.prior.current_promise,
1900                   std::move(other.prior.prior.prior.current_promise));
1901         goto tail4;
1902       case State::kState5:
1903         Construct(&prior.prior.current_promise,
1904                   std::move(other.prior.prior.current_promise));
1905         goto tail5;
1906       case State::kState6:
1907         Construct(&prior.current_promise,
1908                   std::move(other.prior.current_promise));
1909         goto tail6;
1910       case State::kState7:
1911         Construct(&current_promise, std::move(other.current_promise));
1912         return;
1913     }
1914   tail0:
1915     Construct(
1916         &prior.prior.prior.prior.prior.prior.prior.next_factory,
1917         std::move(
1918             other.prior.prior.prior.prior.prior.prior.prior.next_factory));
1919   tail1:
1920     Construct(
1921         &prior.prior.prior.prior.prior.prior.next_factory,
1922         std::move(other.prior.prior.prior.prior.prior.prior.next_factory));
1923   tail2:
1924     Construct(&prior.prior.prior.prior.prior.next_factory,
1925               std::move(other.prior.prior.prior.prior.prior.next_factory));
1926   tail3:
1927     Construct(&prior.prior.prior.prior.next_factory,
1928               std::move(other.prior.prior.prior.prior.next_factory));
1929   tail4:
1930     Construct(&prior.prior.prior.next_factory,
1931               std::move(other.prior.prior.prior.next_factory));
1932   tail5:
1933     Construct(&prior.prior.next_factory,
1934               std::move(other.prior.prior.next_factory));
1935   tail6:
1936     Construct(&prior.next_factory, std::move(other.prior.next_factory));
1937   }
1938   SeqState& operator=(SeqState&& other) = delete;
1939   Poll<Result> PollOnce() {
1940     switch (state) {
1941       case State::kState0: {
1942         if (grpc_trace_promise_primitives.enabled()) {
1943           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1944                   "seq[%p]: begin poll step 1/8", this);
1945         }
1946         auto result =
1947             prior.prior.prior.prior.prior.prior.prior.current_promise();
1948         PromiseResult0* p = result.value_if_ready();
1949         if (grpc_trace_promise_primitives.enabled()) {
1950           gpr_log(
1951               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1952               "seq[%p]: poll step 1/8 gets %s", this,
1953               p != nullptr
1954                   ? (PromiseResultTraits0::IsOk(*p)
1955                          ? "ready"
1956                          : absl::StrCat("early-error:",
1957                                         PromiseResultTraits0::ErrorString(*p))
1958                                .c_str())
1959                   : "pending");
1960         }
1961         if (p == nullptr) return Pending{};
1962         if (!PromiseResultTraits0::IsOk(*p)) {
1963           return PromiseResultTraits0::template ReturnValue<Result>(
1964               std::move(*p));
1965         }
1966         Destruct(&prior.prior.prior.prior.prior.prior.prior.current_promise);
1967         auto next_promise = PromiseResultTraits0::CallFactory(
1968             &prior.prior.prior.prior.prior.prior.prior.next_factory,
1969             std::move(*p));
1970         Destruct(&prior.prior.prior.prior.prior.prior.prior.next_factory);
1971         Construct(&prior.prior.prior.prior.prior.prior.current_promise,
1972                   std::move(next_promise));
1973         state = State::kState1;
1974       }
1975         ABSL_FALLTHROUGH_INTENDED;
1976       case State::kState1: {
1977         if (grpc_trace_promise_primitives.enabled()) {
1978           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1979                   "seq[%p]: begin poll step 2/8", this);
1980         }
1981         auto result = prior.prior.prior.prior.prior.prior.current_promise();
1982         PromiseResult1* p = result.value_if_ready();
1983         if (grpc_trace_promise_primitives.enabled()) {
1984           gpr_log(
1985               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
1986               "seq[%p]: poll step 2/8 gets %s", this,
1987               p != nullptr
1988                   ? (PromiseResultTraits1::IsOk(*p)
1989                          ? "ready"
1990                          : absl::StrCat("early-error:",
1991                                         PromiseResultTraits1::ErrorString(*p))
1992                                .c_str())
1993                   : "pending");
1994         }
1995         if (p == nullptr) return Pending{};
1996         if (!PromiseResultTraits1::IsOk(*p)) {
1997           return PromiseResultTraits1::template ReturnValue<Result>(
1998               std::move(*p));
1999         }
2000         Destruct(&prior.prior.prior.prior.prior.prior.current_promise);
2001         auto next_promise = PromiseResultTraits1::CallFactory(
2002             &prior.prior.prior.prior.prior.prior.next_factory, std::move(*p));
2003         Destruct(&prior.prior.prior.prior.prior.prior.next_factory);
2004         Construct(&prior.prior.prior.prior.prior.current_promise,
2005                   std::move(next_promise));
2006         state = State::kState2;
2007       }
2008         ABSL_FALLTHROUGH_INTENDED;
2009       case State::kState2: {
2010         if (grpc_trace_promise_primitives.enabled()) {
2011           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2012                   "seq[%p]: begin poll step 3/8", this);
2013         }
2014         auto result = prior.prior.prior.prior.prior.current_promise();
2015         PromiseResult2* p = result.value_if_ready();
2016         if (grpc_trace_promise_primitives.enabled()) {
2017           gpr_log(
2018               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2019               "seq[%p]: poll step 3/8 gets %s", this,
2020               p != nullptr
2021                   ? (PromiseResultTraits2::IsOk(*p)
2022                          ? "ready"
2023                          : absl::StrCat("early-error:",
2024                                         PromiseResultTraits2::ErrorString(*p))
2025                                .c_str())
2026                   : "pending");
2027         }
2028         if (p == nullptr) return Pending{};
2029         if (!PromiseResultTraits2::IsOk(*p)) {
2030           return PromiseResultTraits2::template ReturnValue<Result>(
2031               std::move(*p));
2032         }
2033         Destruct(&prior.prior.prior.prior.prior.current_promise);
2034         auto next_promise = PromiseResultTraits2::CallFactory(
2035             &prior.prior.prior.prior.prior.next_factory, std::move(*p));
2036         Destruct(&prior.prior.prior.prior.prior.next_factory);
2037         Construct(&prior.prior.prior.prior.current_promise,
2038                   std::move(next_promise));
2039         state = State::kState3;
2040       }
2041         ABSL_FALLTHROUGH_INTENDED;
2042       case State::kState3: {
2043         if (grpc_trace_promise_primitives.enabled()) {
2044           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2045                   "seq[%p]: begin poll step 4/8", this);
2046         }
2047         auto result = prior.prior.prior.prior.current_promise();
2048         PromiseResult3* p = result.value_if_ready();
2049         if (grpc_trace_promise_primitives.enabled()) {
2050           gpr_log(
2051               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2052               "seq[%p]: poll step 4/8 gets %s", this,
2053               p != nullptr
2054                   ? (PromiseResultTraits3::IsOk(*p)
2055                          ? "ready"
2056                          : absl::StrCat("early-error:",
2057                                         PromiseResultTraits3::ErrorString(*p))
2058                                .c_str())
2059                   : "pending");
2060         }
2061         if (p == nullptr) return Pending{};
2062         if (!PromiseResultTraits3::IsOk(*p)) {
2063           return PromiseResultTraits3::template ReturnValue<Result>(
2064               std::move(*p));
2065         }
2066         Destruct(&prior.prior.prior.prior.current_promise);
2067         auto next_promise = PromiseResultTraits3::CallFactory(
2068             &prior.prior.prior.prior.next_factory, std::move(*p));
2069         Destruct(&prior.prior.prior.prior.next_factory);
2070         Construct(&prior.prior.prior.current_promise, std::move(next_promise));
2071         state = State::kState4;
2072       }
2073         ABSL_FALLTHROUGH_INTENDED;
2074       case State::kState4: {
2075         if (grpc_trace_promise_primitives.enabled()) {
2076           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2077                   "seq[%p]: begin poll step 5/8", this);
2078         }
2079         auto result = prior.prior.prior.current_promise();
2080         PromiseResult4* p = result.value_if_ready();
2081         if (grpc_trace_promise_primitives.enabled()) {
2082           gpr_log(
2083               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2084               "seq[%p]: poll step 5/8 gets %s", this,
2085               p != nullptr
2086                   ? (PromiseResultTraits4::IsOk(*p)
2087                          ? "ready"
2088                          : absl::StrCat("early-error:",
2089                                         PromiseResultTraits4::ErrorString(*p))
2090                                .c_str())
2091                   : "pending");
2092         }
2093         if (p == nullptr) return Pending{};
2094         if (!PromiseResultTraits4::IsOk(*p)) {
2095           return PromiseResultTraits4::template ReturnValue<Result>(
2096               std::move(*p));
2097         }
2098         Destruct(&prior.prior.prior.current_promise);
2099         auto next_promise = PromiseResultTraits4::CallFactory(
2100             &prior.prior.prior.next_factory, std::move(*p));
2101         Destruct(&prior.prior.prior.next_factory);
2102         Construct(&prior.prior.current_promise, std::move(next_promise));
2103         state = State::kState5;
2104       }
2105         ABSL_FALLTHROUGH_INTENDED;
2106       case State::kState5: {
2107         if (grpc_trace_promise_primitives.enabled()) {
2108           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2109                   "seq[%p]: begin poll step 6/8", this);
2110         }
2111         auto result = prior.prior.current_promise();
2112         PromiseResult5* p = result.value_if_ready();
2113         if (grpc_trace_promise_primitives.enabled()) {
2114           gpr_log(
2115               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2116               "seq[%p]: poll step 6/8 gets %s", this,
2117               p != nullptr
2118                   ? (PromiseResultTraits5::IsOk(*p)
2119                          ? "ready"
2120                          : absl::StrCat("early-error:",
2121                                         PromiseResultTraits5::ErrorString(*p))
2122                                .c_str())
2123                   : "pending");
2124         }
2125         if (p == nullptr) return Pending{};
2126         if (!PromiseResultTraits5::IsOk(*p)) {
2127           return PromiseResultTraits5::template ReturnValue<Result>(
2128               std::move(*p));
2129         }
2130         Destruct(&prior.prior.current_promise);
2131         auto next_promise = PromiseResultTraits5::CallFactory(
2132             &prior.prior.next_factory, std::move(*p));
2133         Destruct(&prior.prior.next_factory);
2134         Construct(&prior.current_promise, std::move(next_promise));
2135         state = State::kState6;
2136       }
2137         ABSL_FALLTHROUGH_INTENDED;
2138       case State::kState6: {
2139         if (grpc_trace_promise_primitives.enabled()) {
2140           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2141                   "seq[%p]: begin poll step 7/8", this);
2142         }
2143         auto result = prior.current_promise();
2144         PromiseResult6* p = result.value_if_ready();
2145         if (grpc_trace_promise_primitives.enabled()) {
2146           gpr_log(
2147               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2148               "seq[%p]: poll step 7/8 gets %s", this,
2149               p != nullptr
2150                   ? (PromiseResultTraits6::IsOk(*p)
2151                          ? "ready"
2152                          : absl::StrCat("early-error:",
2153                                         PromiseResultTraits6::ErrorString(*p))
2154                                .c_str())
2155                   : "pending");
2156         }
2157         if (p == nullptr) return Pending{};
2158         if (!PromiseResultTraits6::IsOk(*p)) {
2159           return PromiseResultTraits6::template ReturnValue<Result>(
2160               std::move(*p));
2161         }
2162         Destruct(&prior.current_promise);
2163         auto next_promise = PromiseResultTraits6::CallFactory(
2164             &prior.next_factory, std::move(*p));
2165         Destruct(&prior.next_factory);
2166         Construct(&current_promise, std::move(next_promise));
2167         state = State::kState7;
2168       }
2169         ABSL_FALLTHROUGH_INTENDED;
2170       default:
2171       case State::kState7: {
2172         if (grpc_trace_promise_primitives.enabled()) {
2173           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2174                   "seq[%p]: begin poll step 8/8", this);
2175         }
2176         auto result = current_promise();
2177         if (grpc_trace_promise_primitives.enabled()) {
2178           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2179                   "seq[%p]: poll step 8/8 gets %s", this,
2180                   result.ready() ? "ready" : "pending");
2181         }
2182         auto* p = result.value_if_ready();
2183         if (p == nullptr) return Pending{};
2184         return Result(std::move(*p));
2185       }
2186     }
2187   }
2188 };
2189 
2190 template <template <typename> class Traits, typename P, typename F0,
2191           typename F1, typename F2, typename F3, typename F4, typename F5,
2192           typename F6, typename F7>
2193 struct SeqState<Traits, P, F0, F1, F2, F3, F4, F5, F6, F7> {
2194   using Promise0 = PromiseLike<P>;
2195   using PromiseResult0 = typename Promise0::Result;
2196   using PromiseResultTraits0 = Traits<PromiseResult0>;
2197   using NextFactory0 =
2198       OncePromiseFactory<typename PromiseResultTraits0::UnwrappedType, F0>;
2199   using Promise1 = typename NextFactory0::Promise;
2200   using PromiseResult1 = typename Promise1::Result;
2201   using PromiseResultTraits1 = Traits<PromiseResult1>;
2202   using NextFactory1 =
2203       OncePromiseFactory<typename PromiseResultTraits1::UnwrappedType, F1>;
2204   using Promise2 = typename NextFactory1::Promise;
2205   using PromiseResult2 = typename Promise2::Result;
2206   using PromiseResultTraits2 = Traits<PromiseResult2>;
2207   using NextFactory2 =
2208       OncePromiseFactory<typename PromiseResultTraits2::UnwrappedType, F2>;
2209   using Promise3 = typename NextFactory2::Promise;
2210   using PromiseResult3 = typename Promise3::Result;
2211   using PromiseResultTraits3 = Traits<PromiseResult3>;
2212   using NextFactory3 =
2213       OncePromiseFactory<typename PromiseResultTraits3::UnwrappedType, F3>;
2214   using Promise4 = typename NextFactory3::Promise;
2215   using PromiseResult4 = typename Promise4::Result;
2216   using PromiseResultTraits4 = Traits<PromiseResult4>;
2217   using NextFactory4 =
2218       OncePromiseFactory<typename PromiseResultTraits4::UnwrappedType, F4>;
2219   using Promise5 = typename NextFactory4::Promise;
2220   using PromiseResult5 = typename Promise5::Result;
2221   using PromiseResultTraits5 = Traits<PromiseResult5>;
2222   using NextFactory5 =
2223       OncePromiseFactory<typename PromiseResultTraits5::UnwrappedType, F5>;
2224   using Promise6 = typename NextFactory5::Promise;
2225   using PromiseResult6 = typename Promise6::Result;
2226   using PromiseResultTraits6 = Traits<PromiseResult6>;
2227   using NextFactory6 =
2228       OncePromiseFactory<typename PromiseResultTraits6::UnwrappedType, F6>;
2229   using Promise7 = typename NextFactory6::Promise;
2230   using PromiseResult7 = typename Promise7::Result;
2231   using PromiseResultTraits7 = Traits<PromiseResult7>;
2232   using NextFactory7 =
2233       OncePromiseFactory<typename PromiseResultTraits7::UnwrappedType, F7>;
2234   using Promise8 = typename NextFactory7::Promise;
2235   using PromiseResult8 = typename Promise8::Result;
2236   using PromiseResultTraits8 = Traits<PromiseResult8>;
2237   using Result = typename PromiseResultTraits8::WrappedType;
2238   struct Running0 {
2239     GPR_NO_UNIQUE_ADDRESS Promise0 current_promise;
2240     GPR_NO_UNIQUE_ADDRESS NextFactory0 next_factory;
2241   };
2242   struct Running1 {
2243     union {
2244       GPR_NO_UNIQUE_ADDRESS Running0 prior;
2245       GPR_NO_UNIQUE_ADDRESS Promise1 current_promise;
2246     };
2247     GPR_NO_UNIQUE_ADDRESS NextFactory1 next_factory;
2248   };
2249   struct Running2 {
2250     union {
2251       GPR_NO_UNIQUE_ADDRESS Running1 prior;
2252       GPR_NO_UNIQUE_ADDRESS Promise2 current_promise;
2253     };
2254     GPR_NO_UNIQUE_ADDRESS NextFactory2 next_factory;
2255   };
2256   struct Running3 {
2257     union {
2258       GPR_NO_UNIQUE_ADDRESS Running2 prior;
2259       GPR_NO_UNIQUE_ADDRESS Promise3 current_promise;
2260     };
2261     GPR_NO_UNIQUE_ADDRESS NextFactory3 next_factory;
2262   };
2263   struct Running4 {
2264     union {
2265       GPR_NO_UNIQUE_ADDRESS Running3 prior;
2266       GPR_NO_UNIQUE_ADDRESS Promise4 current_promise;
2267     };
2268     GPR_NO_UNIQUE_ADDRESS NextFactory4 next_factory;
2269   };
2270   struct Running5 {
2271     union {
2272       GPR_NO_UNIQUE_ADDRESS Running4 prior;
2273       GPR_NO_UNIQUE_ADDRESS Promise5 current_promise;
2274     };
2275     GPR_NO_UNIQUE_ADDRESS NextFactory5 next_factory;
2276   };
2277   struct Running6 {
2278     union {
2279       GPR_NO_UNIQUE_ADDRESS Running5 prior;
2280       GPR_NO_UNIQUE_ADDRESS Promise6 current_promise;
2281     };
2282     GPR_NO_UNIQUE_ADDRESS NextFactory6 next_factory;
2283   };
2284   struct Running7 {
2285     union {
2286       GPR_NO_UNIQUE_ADDRESS Running6 prior;
2287       GPR_NO_UNIQUE_ADDRESS Promise7 current_promise;
2288     };
2289     GPR_NO_UNIQUE_ADDRESS NextFactory7 next_factory;
2290   };
2291   union {
2292     GPR_NO_UNIQUE_ADDRESS Running7 prior;
2293     GPR_NO_UNIQUE_ADDRESS Promise8 current_promise;
2294   };
2295   enum class State : uint8_t {
2296     kState0,
2297     kState1,
2298     kState2,
2299     kState3,
2300     kState4,
2301     kState5,
2302     kState6,
2303     kState7,
2304     kState8
2305   };
2306   GPR_NO_UNIQUE_ADDRESS State state = State::kState0;
2307   GPR_NO_UNIQUE_ADDRESS DebugLocation whence;
2308 
2309   SeqState(P&& p, F0&& f0, F1&& f1, F2&& f2, F3&& f3, F4&& f4, F5&& f5, F6&& f6,
2310            F7&& f7, DebugLocation whence) noexcept
2311       : whence(whence) {
2312     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.current_promise,
2313               std::forward<P>(p));
2314     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
2315               std::forward<F0>(f0));
2316     Construct(&prior.prior.prior.prior.prior.prior.prior.next_factory,
2317               std::forward<F1>(f1));
2318     Construct(&prior.prior.prior.prior.prior.prior.next_factory,
2319               std::forward<F2>(f2));
2320     Construct(&prior.prior.prior.prior.prior.next_factory,
2321               std::forward<F3>(f3));
2322     Construct(&prior.prior.prior.prior.next_factory, std::forward<F4>(f4));
2323     Construct(&prior.prior.prior.next_factory, std::forward<F5>(f5));
2324     Construct(&prior.prior.next_factory, std::forward<F6>(f6));
2325     Construct(&prior.next_factory, std::forward<F7>(f7));
2326   }
2327   ~SeqState() {
2328     switch (state) {
2329       case State::kState0:
2330         Destruct(
2331             &prior.prior.prior.prior.prior.prior.prior.prior.current_promise);
2332         goto tail0;
2333       case State::kState1:
2334         Destruct(&prior.prior.prior.prior.prior.prior.prior.current_promise);
2335         goto tail1;
2336       case State::kState2:
2337         Destruct(&prior.prior.prior.prior.prior.prior.current_promise);
2338         goto tail2;
2339       case State::kState3:
2340         Destruct(&prior.prior.prior.prior.prior.current_promise);
2341         goto tail3;
2342       case State::kState4:
2343         Destruct(&prior.prior.prior.prior.current_promise);
2344         goto tail4;
2345       case State::kState5:
2346         Destruct(&prior.prior.prior.current_promise);
2347         goto tail5;
2348       case State::kState6:
2349         Destruct(&prior.prior.current_promise);
2350         goto tail6;
2351       case State::kState7:
2352         Destruct(&prior.current_promise);
2353         goto tail7;
2354       case State::kState8:
2355         Destruct(&current_promise);
2356         return;
2357     }
2358   tail0:
2359     Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory);
2360   tail1:
2361     Destruct(&prior.prior.prior.prior.prior.prior.prior.next_factory);
2362   tail2:
2363     Destruct(&prior.prior.prior.prior.prior.prior.next_factory);
2364   tail3:
2365     Destruct(&prior.prior.prior.prior.prior.next_factory);
2366   tail4:
2367     Destruct(&prior.prior.prior.prior.next_factory);
2368   tail5:
2369     Destruct(&prior.prior.prior.next_factory);
2370   tail6:
2371     Destruct(&prior.prior.next_factory);
2372   tail7:
2373     Destruct(&prior.next_factory);
2374   }
2375   SeqState(const SeqState& other) noexcept
2376       : state(other.state), whence(other.whence) {
2377     GPR_ASSERT(state == State::kState0);
2378     Construct(&prior.current_promise, other.prior.current_promise);
2379     Construct(
2380         &prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
2381         other.prior.prior.prior.prior.prior.prior.prior.prior.next_factory);
2382     Construct(&prior.prior.prior.prior.prior.prior.prior.next_factory,
2383               other.prior.prior.prior.prior.prior.prior.prior.next_factory);
2384     Construct(&prior.prior.prior.prior.prior.prior.next_factory,
2385               other.prior.prior.prior.prior.prior.prior.next_factory);
2386     Construct(&prior.prior.prior.prior.prior.next_factory,
2387               other.prior.prior.prior.prior.prior.next_factory);
2388     Construct(&prior.prior.prior.prior.next_factory,
2389               other.prior.prior.prior.prior.next_factory);
2390     Construct(&prior.prior.prior.next_factory,
2391               other.prior.prior.prior.next_factory);
2392     Construct(&prior.prior.next_factory, other.prior.prior.next_factory);
2393     Construct(&prior.next_factory, other.prior.next_factory);
2394   }
2395   SeqState& operator=(const SeqState& other) = delete;
2396   SeqState(SeqState&& other) noexcept
2397       : state(other.state), whence(other.whence) {
2398     switch (state) {
2399       case State::kState0:
2400         Construct(
2401             &prior.prior.prior.prior.prior.prior.prior.prior.current_promise,
2402             std::move(other.prior.prior.prior.prior.prior.prior.prior.prior
2403                           .current_promise));
2404         goto tail0;
2405       case State::kState1:
2406         Construct(&prior.prior.prior.prior.prior.prior.prior.current_promise,
2407                   std::move(other.prior.prior.prior.prior.prior.prior.prior
2408                                 .current_promise));
2409         goto tail1;
2410       case State::kState2:
2411         Construct(
2412             &prior.prior.prior.prior.prior.prior.current_promise,
2413             std::move(
2414                 other.prior.prior.prior.prior.prior.prior.current_promise));
2415         goto tail2;
2416       case State::kState3:
2417         Construct(
2418             &prior.prior.prior.prior.prior.current_promise,
2419             std::move(other.prior.prior.prior.prior.prior.current_promise));
2420         goto tail3;
2421       case State::kState4:
2422         Construct(&prior.prior.prior.prior.current_promise,
2423                   std::move(other.prior.prior.prior.prior.current_promise));
2424         goto tail4;
2425       case State::kState5:
2426         Construct(&prior.prior.prior.current_promise,
2427                   std::move(other.prior.prior.prior.current_promise));
2428         goto tail5;
2429       case State::kState6:
2430         Construct(&prior.prior.current_promise,
2431                   std::move(other.prior.prior.current_promise));
2432         goto tail6;
2433       case State::kState7:
2434         Construct(&prior.current_promise,
2435                   std::move(other.prior.current_promise));
2436         goto tail7;
2437       case State::kState8:
2438         Construct(&current_promise, std::move(other.current_promise));
2439         return;
2440     }
2441   tail0:
2442     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
2443               std::move(other.prior.prior.prior.prior.prior.prior.prior.prior
2444                             .next_factory));
2445   tail1:
2446     Construct(
2447         &prior.prior.prior.prior.prior.prior.prior.next_factory,
2448         std::move(
2449             other.prior.prior.prior.prior.prior.prior.prior.next_factory));
2450   tail2:
2451     Construct(
2452         &prior.prior.prior.prior.prior.prior.next_factory,
2453         std::move(other.prior.prior.prior.prior.prior.prior.next_factory));
2454   tail3:
2455     Construct(&prior.prior.prior.prior.prior.next_factory,
2456               std::move(other.prior.prior.prior.prior.prior.next_factory));
2457   tail4:
2458     Construct(&prior.prior.prior.prior.next_factory,
2459               std::move(other.prior.prior.prior.prior.next_factory));
2460   tail5:
2461     Construct(&prior.prior.prior.next_factory,
2462               std::move(other.prior.prior.prior.next_factory));
2463   tail6:
2464     Construct(&prior.prior.next_factory,
2465               std::move(other.prior.prior.next_factory));
2466   tail7:
2467     Construct(&prior.next_factory, std::move(other.prior.next_factory));
2468   }
2469   SeqState& operator=(SeqState&& other) = delete;
2470   Poll<Result> PollOnce() {
2471     switch (state) {
2472       case State::kState0: {
2473         if (grpc_trace_promise_primitives.enabled()) {
2474           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2475                   "seq[%p]: begin poll step 1/9", this);
2476         }
2477         auto result =
2478             prior.prior.prior.prior.prior.prior.prior.prior.current_promise();
2479         PromiseResult0* p = result.value_if_ready();
2480         if (grpc_trace_promise_primitives.enabled()) {
2481           gpr_log(
2482               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2483               "seq[%p]: poll step 1/9 gets %s", this,
2484               p != nullptr
2485                   ? (PromiseResultTraits0::IsOk(*p)
2486                          ? "ready"
2487                          : absl::StrCat("early-error:",
2488                                         PromiseResultTraits0::ErrorString(*p))
2489                                .c_str())
2490                   : "pending");
2491         }
2492         if (p == nullptr) return Pending{};
2493         if (!PromiseResultTraits0::IsOk(*p)) {
2494           return PromiseResultTraits0::template ReturnValue<Result>(
2495               std::move(*p));
2496         }
2497         Destruct(
2498             &prior.prior.prior.prior.prior.prior.prior.prior.current_promise);
2499         auto next_promise = PromiseResultTraits0::CallFactory(
2500             &prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
2501             std::move(*p));
2502         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory);
2503         Construct(&prior.prior.prior.prior.prior.prior.prior.current_promise,
2504                   std::move(next_promise));
2505         state = State::kState1;
2506       }
2507         ABSL_FALLTHROUGH_INTENDED;
2508       case State::kState1: {
2509         if (grpc_trace_promise_primitives.enabled()) {
2510           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2511                   "seq[%p]: begin poll step 2/9", this);
2512         }
2513         auto result =
2514             prior.prior.prior.prior.prior.prior.prior.current_promise();
2515         PromiseResult1* p = result.value_if_ready();
2516         if (grpc_trace_promise_primitives.enabled()) {
2517           gpr_log(
2518               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2519               "seq[%p]: poll step 2/9 gets %s", this,
2520               p != nullptr
2521                   ? (PromiseResultTraits1::IsOk(*p)
2522                          ? "ready"
2523                          : absl::StrCat("early-error:",
2524                                         PromiseResultTraits1::ErrorString(*p))
2525                                .c_str())
2526                   : "pending");
2527         }
2528         if (p == nullptr) return Pending{};
2529         if (!PromiseResultTraits1::IsOk(*p)) {
2530           return PromiseResultTraits1::template ReturnValue<Result>(
2531               std::move(*p));
2532         }
2533         Destruct(&prior.prior.prior.prior.prior.prior.prior.current_promise);
2534         auto next_promise = PromiseResultTraits1::CallFactory(
2535             &prior.prior.prior.prior.prior.prior.prior.next_factory,
2536             std::move(*p));
2537         Destruct(&prior.prior.prior.prior.prior.prior.prior.next_factory);
2538         Construct(&prior.prior.prior.prior.prior.prior.current_promise,
2539                   std::move(next_promise));
2540         state = State::kState2;
2541       }
2542         ABSL_FALLTHROUGH_INTENDED;
2543       case State::kState2: {
2544         if (grpc_trace_promise_primitives.enabled()) {
2545           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2546                   "seq[%p]: begin poll step 3/9", this);
2547         }
2548         auto result = prior.prior.prior.prior.prior.prior.current_promise();
2549         PromiseResult2* p = result.value_if_ready();
2550         if (grpc_trace_promise_primitives.enabled()) {
2551           gpr_log(
2552               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2553               "seq[%p]: poll step 3/9 gets %s", this,
2554               p != nullptr
2555                   ? (PromiseResultTraits2::IsOk(*p)
2556                          ? "ready"
2557                          : absl::StrCat("early-error:",
2558                                         PromiseResultTraits2::ErrorString(*p))
2559                                .c_str())
2560                   : "pending");
2561         }
2562         if (p == nullptr) return Pending{};
2563         if (!PromiseResultTraits2::IsOk(*p)) {
2564           return PromiseResultTraits2::template ReturnValue<Result>(
2565               std::move(*p));
2566         }
2567         Destruct(&prior.prior.prior.prior.prior.prior.current_promise);
2568         auto next_promise = PromiseResultTraits2::CallFactory(
2569             &prior.prior.prior.prior.prior.prior.next_factory, std::move(*p));
2570         Destruct(&prior.prior.prior.prior.prior.prior.next_factory);
2571         Construct(&prior.prior.prior.prior.prior.current_promise,
2572                   std::move(next_promise));
2573         state = State::kState3;
2574       }
2575         ABSL_FALLTHROUGH_INTENDED;
2576       case State::kState3: {
2577         if (grpc_trace_promise_primitives.enabled()) {
2578           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2579                   "seq[%p]: begin poll step 4/9", this);
2580         }
2581         auto result = prior.prior.prior.prior.prior.current_promise();
2582         PromiseResult3* p = result.value_if_ready();
2583         if (grpc_trace_promise_primitives.enabled()) {
2584           gpr_log(
2585               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2586               "seq[%p]: poll step 4/9 gets %s", this,
2587               p != nullptr
2588                   ? (PromiseResultTraits3::IsOk(*p)
2589                          ? "ready"
2590                          : absl::StrCat("early-error:",
2591                                         PromiseResultTraits3::ErrorString(*p))
2592                                .c_str())
2593                   : "pending");
2594         }
2595         if (p == nullptr) return Pending{};
2596         if (!PromiseResultTraits3::IsOk(*p)) {
2597           return PromiseResultTraits3::template ReturnValue<Result>(
2598               std::move(*p));
2599         }
2600         Destruct(&prior.prior.prior.prior.prior.current_promise);
2601         auto next_promise = PromiseResultTraits3::CallFactory(
2602             &prior.prior.prior.prior.prior.next_factory, std::move(*p));
2603         Destruct(&prior.prior.prior.prior.prior.next_factory);
2604         Construct(&prior.prior.prior.prior.current_promise,
2605                   std::move(next_promise));
2606         state = State::kState4;
2607       }
2608         ABSL_FALLTHROUGH_INTENDED;
2609       case State::kState4: {
2610         if (grpc_trace_promise_primitives.enabled()) {
2611           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2612                   "seq[%p]: begin poll step 5/9", this);
2613         }
2614         auto result = prior.prior.prior.prior.current_promise();
2615         PromiseResult4* p = result.value_if_ready();
2616         if (grpc_trace_promise_primitives.enabled()) {
2617           gpr_log(
2618               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2619               "seq[%p]: poll step 5/9 gets %s", this,
2620               p != nullptr
2621                   ? (PromiseResultTraits4::IsOk(*p)
2622                          ? "ready"
2623                          : absl::StrCat("early-error:",
2624                                         PromiseResultTraits4::ErrorString(*p))
2625                                .c_str())
2626                   : "pending");
2627         }
2628         if (p == nullptr) return Pending{};
2629         if (!PromiseResultTraits4::IsOk(*p)) {
2630           return PromiseResultTraits4::template ReturnValue<Result>(
2631               std::move(*p));
2632         }
2633         Destruct(&prior.prior.prior.prior.current_promise);
2634         auto next_promise = PromiseResultTraits4::CallFactory(
2635             &prior.prior.prior.prior.next_factory, std::move(*p));
2636         Destruct(&prior.prior.prior.prior.next_factory);
2637         Construct(&prior.prior.prior.current_promise, std::move(next_promise));
2638         state = State::kState5;
2639       }
2640         ABSL_FALLTHROUGH_INTENDED;
2641       case State::kState5: {
2642         if (grpc_trace_promise_primitives.enabled()) {
2643           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2644                   "seq[%p]: begin poll step 6/9", this);
2645         }
2646         auto result = prior.prior.prior.current_promise();
2647         PromiseResult5* p = result.value_if_ready();
2648         if (grpc_trace_promise_primitives.enabled()) {
2649           gpr_log(
2650               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2651               "seq[%p]: poll step 6/9 gets %s", this,
2652               p != nullptr
2653                   ? (PromiseResultTraits5::IsOk(*p)
2654                          ? "ready"
2655                          : absl::StrCat("early-error:",
2656                                         PromiseResultTraits5::ErrorString(*p))
2657                                .c_str())
2658                   : "pending");
2659         }
2660         if (p == nullptr) return Pending{};
2661         if (!PromiseResultTraits5::IsOk(*p)) {
2662           return PromiseResultTraits5::template ReturnValue<Result>(
2663               std::move(*p));
2664         }
2665         Destruct(&prior.prior.prior.current_promise);
2666         auto next_promise = PromiseResultTraits5::CallFactory(
2667             &prior.prior.prior.next_factory, std::move(*p));
2668         Destruct(&prior.prior.prior.next_factory);
2669         Construct(&prior.prior.current_promise, std::move(next_promise));
2670         state = State::kState6;
2671       }
2672         ABSL_FALLTHROUGH_INTENDED;
2673       case State::kState6: {
2674         if (grpc_trace_promise_primitives.enabled()) {
2675           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2676                   "seq[%p]: begin poll step 7/9", this);
2677         }
2678         auto result = prior.prior.current_promise();
2679         PromiseResult6* p = result.value_if_ready();
2680         if (grpc_trace_promise_primitives.enabled()) {
2681           gpr_log(
2682               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2683               "seq[%p]: poll step 7/9 gets %s", this,
2684               p != nullptr
2685                   ? (PromiseResultTraits6::IsOk(*p)
2686                          ? "ready"
2687                          : absl::StrCat("early-error:",
2688                                         PromiseResultTraits6::ErrorString(*p))
2689                                .c_str())
2690                   : "pending");
2691         }
2692         if (p == nullptr) return Pending{};
2693         if (!PromiseResultTraits6::IsOk(*p)) {
2694           return PromiseResultTraits6::template ReturnValue<Result>(
2695               std::move(*p));
2696         }
2697         Destruct(&prior.prior.current_promise);
2698         auto next_promise = PromiseResultTraits6::CallFactory(
2699             &prior.prior.next_factory, std::move(*p));
2700         Destruct(&prior.prior.next_factory);
2701         Construct(&prior.current_promise, std::move(next_promise));
2702         state = State::kState7;
2703       }
2704         ABSL_FALLTHROUGH_INTENDED;
2705       case State::kState7: {
2706         if (grpc_trace_promise_primitives.enabled()) {
2707           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2708                   "seq[%p]: begin poll step 8/9", this);
2709         }
2710         auto result = prior.current_promise();
2711         PromiseResult7* p = result.value_if_ready();
2712         if (grpc_trace_promise_primitives.enabled()) {
2713           gpr_log(
2714               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2715               "seq[%p]: poll step 8/9 gets %s", this,
2716               p != nullptr
2717                   ? (PromiseResultTraits7::IsOk(*p)
2718                          ? "ready"
2719                          : absl::StrCat("early-error:",
2720                                         PromiseResultTraits7::ErrorString(*p))
2721                                .c_str())
2722                   : "pending");
2723         }
2724         if (p == nullptr) return Pending{};
2725         if (!PromiseResultTraits7::IsOk(*p)) {
2726           return PromiseResultTraits7::template ReturnValue<Result>(
2727               std::move(*p));
2728         }
2729         Destruct(&prior.current_promise);
2730         auto next_promise = PromiseResultTraits7::CallFactory(
2731             &prior.next_factory, std::move(*p));
2732         Destruct(&prior.next_factory);
2733         Construct(&current_promise, std::move(next_promise));
2734         state = State::kState8;
2735       }
2736         ABSL_FALLTHROUGH_INTENDED;
2737       default:
2738       case State::kState8: {
2739         if (grpc_trace_promise_primitives.enabled()) {
2740           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2741                   "seq[%p]: begin poll step 9/9", this);
2742         }
2743         auto result = current_promise();
2744         if (grpc_trace_promise_primitives.enabled()) {
2745           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
2746                   "seq[%p]: poll step 9/9 gets %s", this,
2747                   result.ready() ? "ready" : "pending");
2748         }
2749         auto* p = result.value_if_ready();
2750         if (p == nullptr) return Pending{};
2751         return Result(std::move(*p));
2752       }
2753     }
2754   }
2755 };
2756 
2757 template <template <typename> class Traits, typename P, typename F0,
2758           typename F1, typename F2, typename F3, typename F4, typename F5,
2759           typename F6, typename F7, typename F8>
2760 struct SeqState<Traits, P, F0, F1, F2, F3, F4, F5, F6, F7, F8> {
2761   using Promise0 = PromiseLike<P>;
2762   using PromiseResult0 = typename Promise0::Result;
2763   using PromiseResultTraits0 = Traits<PromiseResult0>;
2764   using NextFactory0 =
2765       OncePromiseFactory<typename PromiseResultTraits0::UnwrappedType, F0>;
2766   using Promise1 = typename NextFactory0::Promise;
2767   using PromiseResult1 = typename Promise1::Result;
2768   using PromiseResultTraits1 = Traits<PromiseResult1>;
2769   using NextFactory1 =
2770       OncePromiseFactory<typename PromiseResultTraits1::UnwrappedType, F1>;
2771   using Promise2 = typename NextFactory1::Promise;
2772   using PromiseResult2 = typename Promise2::Result;
2773   using PromiseResultTraits2 = Traits<PromiseResult2>;
2774   using NextFactory2 =
2775       OncePromiseFactory<typename PromiseResultTraits2::UnwrappedType, F2>;
2776   using Promise3 = typename NextFactory2::Promise;
2777   using PromiseResult3 = typename Promise3::Result;
2778   using PromiseResultTraits3 = Traits<PromiseResult3>;
2779   using NextFactory3 =
2780       OncePromiseFactory<typename PromiseResultTraits3::UnwrappedType, F3>;
2781   using Promise4 = typename NextFactory3::Promise;
2782   using PromiseResult4 = typename Promise4::Result;
2783   using PromiseResultTraits4 = Traits<PromiseResult4>;
2784   using NextFactory4 =
2785       OncePromiseFactory<typename PromiseResultTraits4::UnwrappedType, F4>;
2786   using Promise5 = typename NextFactory4::Promise;
2787   using PromiseResult5 = typename Promise5::Result;
2788   using PromiseResultTraits5 = Traits<PromiseResult5>;
2789   using NextFactory5 =
2790       OncePromiseFactory<typename PromiseResultTraits5::UnwrappedType, F5>;
2791   using Promise6 = typename NextFactory5::Promise;
2792   using PromiseResult6 = typename Promise6::Result;
2793   using PromiseResultTraits6 = Traits<PromiseResult6>;
2794   using NextFactory6 =
2795       OncePromiseFactory<typename PromiseResultTraits6::UnwrappedType, F6>;
2796   using Promise7 = typename NextFactory6::Promise;
2797   using PromiseResult7 = typename Promise7::Result;
2798   using PromiseResultTraits7 = Traits<PromiseResult7>;
2799   using NextFactory7 =
2800       OncePromiseFactory<typename PromiseResultTraits7::UnwrappedType, F7>;
2801   using Promise8 = typename NextFactory7::Promise;
2802   using PromiseResult8 = typename Promise8::Result;
2803   using PromiseResultTraits8 = Traits<PromiseResult8>;
2804   using NextFactory8 =
2805       OncePromiseFactory<typename PromiseResultTraits8::UnwrappedType, F8>;
2806   using Promise9 = typename NextFactory8::Promise;
2807   using PromiseResult9 = typename Promise9::Result;
2808   using PromiseResultTraits9 = Traits<PromiseResult9>;
2809   using Result = typename PromiseResultTraits9::WrappedType;
2810   struct Running0 {
2811     GPR_NO_UNIQUE_ADDRESS Promise0 current_promise;
2812     GPR_NO_UNIQUE_ADDRESS NextFactory0 next_factory;
2813   };
2814   struct Running1 {
2815     union {
2816       GPR_NO_UNIQUE_ADDRESS Running0 prior;
2817       GPR_NO_UNIQUE_ADDRESS Promise1 current_promise;
2818     };
2819     GPR_NO_UNIQUE_ADDRESS NextFactory1 next_factory;
2820   };
2821   struct Running2 {
2822     union {
2823       GPR_NO_UNIQUE_ADDRESS Running1 prior;
2824       GPR_NO_UNIQUE_ADDRESS Promise2 current_promise;
2825     };
2826     GPR_NO_UNIQUE_ADDRESS NextFactory2 next_factory;
2827   };
2828   struct Running3 {
2829     union {
2830       GPR_NO_UNIQUE_ADDRESS Running2 prior;
2831       GPR_NO_UNIQUE_ADDRESS Promise3 current_promise;
2832     };
2833     GPR_NO_UNIQUE_ADDRESS NextFactory3 next_factory;
2834   };
2835   struct Running4 {
2836     union {
2837       GPR_NO_UNIQUE_ADDRESS Running3 prior;
2838       GPR_NO_UNIQUE_ADDRESS Promise4 current_promise;
2839     };
2840     GPR_NO_UNIQUE_ADDRESS NextFactory4 next_factory;
2841   };
2842   struct Running5 {
2843     union {
2844       GPR_NO_UNIQUE_ADDRESS Running4 prior;
2845       GPR_NO_UNIQUE_ADDRESS Promise5 current_promise;
2846     };
2847     GPR_NO_UNIQUE_ADDRESS NextFactory5 next_factory;
2848   };
2849   struct Running6 {
2850     union {
2851       GPR_NO_UNIQUE_ADDRESS Running5 prior;
2852       GPR_NO_UNIQUE_ADDRESS Promise6 current_promise;
2853     };
2854     GPR_NO_UNIQUE_ADDRESS NextFactory6 next_factory;
2855   };
2856   struct Running7 {
2857     union {
2858       GPR_NO_UNIQUE_ADDRESS Running6 prior;
2859       GPR_NO_UNIQUE_ADDRESS Promise7 current_promise;
2860     };
2861     GPR_NO_UNIQUE_ADDRESS NextFactory7 next_factory;
2862   };
2863   struct Running8 {
2864     union {
2865       GPR_NO_UNIQUE_ADDRESS Running7 prior;
2866       GPR_NO_UNIQUE_ADDRESS Promise8 current_promise;
2867     };
2868     GPR_NO_UNIQUE_ADDRESS NextFactory8 next_factory;
2869   };
2870   union {
2871     GPR_NO_UNIQUE_ADDRESS Running8 prior;
2872     GPR_NO_UNIQUE_ADDRESS Promise9 current_promise;
2873   };
2874   enum class State : uint8_t {
2875     kState0,
2876     kState1,
2877     kState2,
2878     kState3,
2879     kState4,
2880     kState5,
2881     kState6,
2882     kState7,
2883     kState8,
2884     kState9
2885   };
2886   GPR_NO_UNIQUE_ADDRESS State state = State::kState0;
2887   GPR_NO_UNIQUE_ADDRESS DebugLocation whence;
2888 
2889   SeqState(P&& p, F0&& f0, F1&& f1, F2&& f2, F3&& f3, F4&& f4, F5&& f5, F6&& f6,
2890            F7&& f7, F8&& f8, DebugLocation whence) noexcept
2891       : whence(whence) {
2892     Construct(
2893         &prior.prior.prior.prior.prior.prior.prior.prior.prior.current_promise,
2894         std::forward<P>(p));
2895     Construct(
2896         &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
2897         std::forward<F0>(f0));
2898     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
2899               std::forward<F1>(f1));
2900     Construct(&prior.prior.prior.prior.prior.prior.prior.next_factory,
2901               std::forward<F2>(f2));
2902     Construct(&prior.prior.prior.prior.prior.prior.next_factory,
2903               std::forward<F3>(f3));
2904     Construct(&prior.prior.prior.prior.prior.next_factory,
2905               std::forward<F4>(f4));
2906     Construct(&prior.prior.prior.prior.next_factory, std::forward<F5>(f5));
2907     Construct(&prior.prior.prior.next_factory, std::forward<F6>(f6));
2908     Construct(&prior.prior.next_factory, std::forward<F7>(f7));
2909     Construct(&prior.next_factory, std::forward<F8>(f8));
2910   }
2911   ~SeqState() {
2912     switch (state) {
2913       case State::kState0:
2914         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior
2915                       .current_promise);
2916         goto tail0;
2917       case State::kState1:
2918         Destruct(
2919             &prior.prior.prior.prior.prior.prior.prior.prior.current_promise);
2920         goto tail1;
2921       case State::kState2:
2922         Destruct(&prior.prior.prior.prior.prior.prior.prior.current_promise);
2923         goto tail2;
2924       case State::kState3:
2925         Destruct(&prior.prior.prior.prior.prior.prior.current_promise);
2926         goto tail3;
2927       case State::kState4:
2928         Destruct(&prior.prior.prior.prior.prior.current_promise);
2929         goto tail4;
2930       case State::kState5:
2931         Destruct(&prior.prior.prior.prior.current_promise);
2932         goto tail5;
2933       case State::kState6:
2934         Destruct(&prior.prior.prior.current_promise);
2935         goto tail6;
2936       case State::kState7:
2937         Destruct(&prior.prior.current_promise);
2938         goto tail7;
2939       case State::kState8:
2940         Destruct(&prior.current_promise);
2941         goto tail8;
2942       case State::kState9:
2943         Destruct(&current_promise);
2944         return;
2945     }
2946   tail0:
2947     Destruct(
2948         &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory);
2949   tail1:
2950     Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory);
2951   tail2:
2952     Destruct(&prior.prior.prior.prior.prior.prior.prior.next_factory);
2953   tail3:
2954     Destruct(&prior.prior.prior.prior.prior.prior.next_factory);
2955   tail4:
2956     Destruct(&prior.prior.prior.prior.prior.next_factory);
2957   tail5:
2958     Destruct(&prior.prior.prior.prior.next_factory);
2959   tail6:
2960     Destruct(&prior.prior.prior.next_factory);
2961   tail7:
2962     Destruct(&prior.prior.next_factory);
2963   tail8:
2964     Destruct(&prior.next_factory);
2965   }
2966   SeqState(const SeqState& other) noexcept
2967       : state(other.state), whence(other.whence) {
2968     GPR_ASSERT(state == State::kState0);
2969     Construct(&prior.current_promise, other.prior.current_promise);
2970     Construct(
2971         &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
2972         other.prior.prior.prior.prior.prior.prior.prior.prior.prior
2973             .next_factory);
2974     Construct(
2975         &prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
2976         other.prior.prior.prior.prior.prior.prior.prior.prior.next_factory);
2977     Construct(&prior.prior.prior.prior.prior.prior.prior.next_factory,
2978               other.prior.prior.prior.prior.prior.prior.prior.next_factory);
2979     Construct(&prior.prior.prior.prior.prior.prior.next_factory,
2980               other.prior.prior.prior.prior.prior.prior.next_factory);
2981     Construct(&prior.prior.prior.prior.prior.next_factory,
2982               other.prior.prior.prior.prior.prior.next_factory);
2983     Construct(&prior.prior.prior.prior.next_factory,
2984               other.prior.prior.prior.prior.next_factory);
2985     Construct(&prior.prior.prior.next_factory,
2986               other.prior.prior.prior.next_factory);
2987     Construct(&prior.prior.next_factory, other.prior.prior.next_factory);
2988     Construct(&prior.next_factory, other.prior.next_factory);
2989   }
2990   SeqState& operator=(const SeqState& other) = delete;
2991   SeqState(SeqState&& other) noexcept
2992       : state(other.state), whence(other.whence) {
2993     switch (state) {
2994       case State::kState0:
2995         Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior
2996                        .current_promise,
2997                   std::move(other.prior.prior.prior.prior.prior.prior.prior
2998                                 .prior.prior.current_promise));
2999         goto tail0;
3000       case State::kState1:
3001         Construct(
3002             &prior.prior.prior.prior.prior.prior.prior.prior.current_promise,
3003             std::move(other.prior.prior.prior.prior.prior.prior.prior.prior
3004                           .current_promise));
3005         goto tail1;
3006       case State::kState2:
3007         Construct(&prior.prior.prior.prior.prior.prior.prior.current_promise,
3008                   std::move(other.prior.prior.prior.prior.prior.prior.prior
3009                                 .current_promise));
3010         goto tail2;
3011       case State::kState3:
3012         Construct(
3013             &prior.prior.prior.prior.prior.prior.current_promise,
3014             std::move(
3015                 other.prior.prior.prior.prior.prior.prior.current_promise));
3016         goto tail3;
3017       case State::kState4:
3018         Construct(
3019             &prior.prior.prior.prior.prior.current_promise,
3020             std::move(other.prior.prior.prior.prior.prior.current_promise));
3021         goto tail4;
3022       case State::kState5:
3023         Construct(&prior.prior.prior.prior.current_promise,
3024                   std::move(other.prior.prior.prior.prior.current_promise));
3025         goto tail5;
3026       case State::kState6:
3027         Construct(&prior.prior.prior.current_promise,
3028                   std::move(other.prior.prior.prior.current_promise));
3029         goto tail6;
3030       case State::kState7:
3031         Construct(&prior.prior.current_promise,
3032                   std::move(other.prior.prior.current_promise));
3033         goto tail7;
3034       case State::kState8:
3035         Construct(&prior.current_promise,
3036                   std::move(other.prior.current_promise));
3037         goto tail8;
3038       case State::kState9:
3039         Construct(&current_promise, std::move(other.current_promise));
3040         return;
3041     }
3042   tail0:
3043     Construct(
3044         &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
3045         std::move(other.prior.prior.prior.prior.prior.prior.prior.prior.prior
3046                       .next_factory));
3047   tail1:
3048     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
3049               std::move(other.prior.prior.prior.prior.prior.prior.prior.prior
3050                             .next_factory));
3051   tail2:
3052     Construct(
3053         &prior.prior.prior.prior.prior.prior.prior.next_factory,
3054         std::move(
3055             other.prior.prior.prior.prior.prior.prior.prior.next_factory));
3056   tail3:
3057     Construct(
3058         &prior.prior.prior.prior.prior.prior.next_factory,
3059         std::move(other.prior.prior.prior.prior.prior.prior.next_factory));
3060   tail4:
3061     Construct(&prior.prior.prior.prior.prior.next_factory,
3062               std::move(other.prior.prior.prior.prior.prior.next_factory));
3063   tail5:
3064     Construct(&prior.prior.prior.prior.next_factory,
3065               std::move(other.prior.prior.prior.prior.next_factory));
3066   tail6:
3067     Construct(&prior.prior.prior.next_factory,
3068               std::move(other.prior.prior.prior.next_factory));
3069   tail7:
3070     Construct(&prior.prior.next_factory,
3071               std::move(other.prior.prior.next_factory));
3072   tail8:
3073     Construct(&prior.next_factory, std::move(other.prior.next_factory));
3074   }
3075   SeqState& operator=(SeqState&& other) = delete;
3076   Poll<Result> PollOnce() {
3077     switch (state) {
3078       case State::kState0: {
3079         if (grpc_trace_promise_primitives.enabled()) {
3080           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3081                   "seq[%p]: begin poll step 1/10", this);
3082         }
3083         auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior
3084                           .current_promise();
3085         PromiseResult0* p = result.value_if_ready();
3086         if (grpc_trace_promise_primitives.enabled()) {
3087           gpr_log(
3088               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3089               "seq[%p]: poll step 1/10 gets %s", this,
3090               p != nullptr
3091                   ? (PromiseResultTraits0::IsOk(*p)
3092                          ? "ready"
3093                          : absl::StrCat("early-error:",
3094                                         PromiseResultTraits0::ErrorString(*p))
3095                                .c_str())
3096                   : "pending");
3097         }
3098         if (p == nullptr) return Pending{};
3099         if (!PromiseResultTraits0::IsOk(*p)) {
3100           return PromiseResultTraits0::template ReturnValue<Result>(
3101               std::move(*p));
3102         }
3103         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior
3104                       .current_promise);
3105         auto next_promise = PromiseResultTraits0::CallFactory(
3106             &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
3107             std::move(*p));
3108         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior
3109                       .next_factory);
3110         Construct(
3111             &prior.prior.prior.prior.prior.prior.prior.prior.current_promise,
3112             std::move(next_promise));
3113         state = State::kState1;
3114       }
3115         ABSL_FALLTHROUGH_INTENDED;
3116       case State::kState1: {
3117         if (grpc_trace_promise_primitives.enabled()) {
3118           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3119                   "seq[%p]: begin poll step 2/10", this);
3120         }
3121         auto result =
3122             prior.prior.prior.prior.prior.prior.prior.prior.current_promise();
3123         PromiseResult1* p = result.value_if_ready();
3124         if (grpc_trace_promise_primitives.enabled()) {
3125           gpr_log(
3126               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3127               "seq[%p]: poll step 2/10 gets %s", this,
3128               p != nullptr
3129                   ? (PromiseResultTraits1::IsOk(*p)
3130                          ? "ready"
3131                          : absl::StrCat("early-error:",
3132                                         PromiseResultTraits1::ErrorString(*p))
3133                                .c_str())
3134                   : "pending");
3135         }
3136         if (p == nullptr) return Pending{};
3137         if (!PromiseResultTraits1::IsOk(*p)) {
3138           return PromiseResultTraits1::template ReturnValue<Result>(
3139               std::move(*p));
3140         }
3141         Destruct(
3142             &prior.prior.prior.prior.prior.prior.prior.prior.current_promise);
3143         auto next_promise = PromiseResultTraits1::CallFactory(
3144             &prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
3145             std::move(*p));
3146         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory);
3147         Construct(&prior.prior.prior.prior.prior.prior.prior.current_promise,
3148                   std::move(next_promise));
3149         state = State::kState2;
3150       }
3151         ABSL_FALLTHROUGH_INTENDED;
3152       case State::kState2: {
3153         if (grpc_trace_promise_primitives.enabled()) {
3154           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3155                   "seq[%p]: begin poll step 3/10", this);
3156         }
3157         auto result =
3158             prior.prior.prior.prior.prior.prior.prior.current_promise();
3159         PromiseResult2* p = result.value_if_ready();
3160         if (grpc_trace_promise_primitives.enabled()) {
3161           gpr_log(
3162               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3163               "seq[%p]: poll step 3/10 gets %s", this,
3164               p != nullptr
3165                   ? (PromiseResultTraits2::IsOk(*p)
3166                          ? "ready"
3167                          : absl::StrCat("early-error:",
3168                                         PromiseResultTraits2::ErrorString(*p))
3169                                .c_str())
3170                   : "pending");
3171         }
3172         if (p == nullptr) return Pending{};
3173         if (!PromiseResultTraits2::IsOk(*p)) {
3174           return PromiseResultTraits2::template ReturnValue<Result>(
3175               std::move(*p));
3176         }
3177         Destruct(&prior.prior.prior.prior.prior.prior.prior.current_promise);
3178         auto next_promise = PromiseResultTraits2::CallFactory(
3179             &prior.prior.prior.prior.prior.prior.prior.next_factory,
3180             std::move(*p));
3181         Destruct(&prior.prior.prior.prior.prior.prior.prior.next_factory);
3182         Construct(&prior.prior.prior.prior.prior.prior.current_promise,
3183                   std::move(next_promise));
3184         state = State::kState3;
3185       }
3186         ABSL_FALLTHROUGH_INTENDED;
3187       case State::kState3: {
3188         if (grpc_trace_promise_primitives.enabled()) {
3189           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3190                   "seq[%p]: begin poll step 4/10", this);
3191         }
3192         auto result = prior.prior.prior.prior.prior.prior.current_promise();
3193         PromiseResult3* p = result.value_if_ready();
3194         if (grpc_trace_promise_primitives.enabled()) {
3195           gpr_log(
3196               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3197               "seq[%p]: poll step 4/10 gets %s", this,
3198               p != nullptr
3199                   ? (PromiseResultTraits3::IsOk(*p)
3200                          ? "ready"
3201                          : absl::StrCat("early-error:",
3202                                         PromiseResultTraits3::ErrorString(*p))
3203                                .c_str())
3204                   : "pending");
3205         }
3206         if (p == nullptr) return Pending{};
3207         if (!PromiseResultTraits3::IsOk(*p)) {
3208           return PromiseResultTraits3::template ReturnValue<Result>(
3209               std::move(*p));
3210         }
3211         Destruct(&prior.prior.prior.prior.prior.prior.current_promise);
3212         auto next_promise = PromiseResultTraits3::CallFactory(
3213             &prior.prior.prior.prior.prior.prior.next_factory, std::move(*p));
3214         Destruct(&prior.prior.prior.prior.prior.prior.next_factory);
3215         Construct(&prior.prior.prior.prior.prior.current_promise,
3216                   std::move(next_promise));
3217         state = State::kState4;
3218       }
3219         ABSL_FALLTHROUGH_INTENDED;
3220       case State::kState4: {
3221         if (grpc_trace_promise_primitives.enabled()) {
3222           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3223                   "seq[%p]: begin poll step 5/10", this);
3224         }
3225         auto result = prior.prior.prior.prior.prior.current_promise();
3226         PromiseResult4* p = result.value_if_ready();
3227         if (grpc_trace_promise_primitives.enabled()) {
3228           gpr_log(
3229               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3230               "seq[%p]: poll step 5/10 gets %s", this,
3231               p != nullptr
3232                   ? (PromiseResultTraits4::IsOk(*p)
3233                          ? "ready"
3234                          : absl::StrCat("early-error:",
3235                                         PromiseResultTraits4::ErrorString(*p))
3236                                .c_str())
3237                   : "pending");
3238         }
3239         if (p == nullptr) return Pending{};
3240         if (!PromiseResultTraits4::IsOk(*p)) {
3241           return PromiseResultTraits4::template ReturnValue<Result>(
3242               std::move(*p));
3243         }
3244         Destruct(&prior.prior.prior.prior.prior.current_promise);
3245         auto next_promise = PromiseResultTraits4::CallFactory(
3246             &prior.prior.prior.prior.prior.next_factory, std::move(*p));
3247         Destruct(&prior.prior.prior.prior.prior.next_factory);
3248         Construct(&prior.prior.prior.prior.current_promise,
3249                   std::move(next_promise));
3250         state = State::kState5;
3251       }
3252         ABSL_FALLTHROUGH_INTENDED;
3253       case State::kState5: {
3254         if (grpc_trace_promise_primitives.enabled()) {
3255           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3256                   "seq[%p]: begin poll step 6/10", this);
3257         }
3258         auto result = prior.prior.prior.prior.current_promise();
3259         PromiseResult5* p = result.value_if_ready();
3260         if (grpc_trace_promise_primitives.enabled()) {
3261           gpr_log(
3262               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3263               "seq[%p]: poll step 6/10 gets %s", this,
3264               p != nullptr
3265                   ? (PromiseResultTraits5::IsOk(*p)
3266                          ? "ready"
3267                          : absl::StrCat("early-error:",
3268                                         PromiseResultTraits5::ErrorString(*p))
3269                                .c_str())
3270                   : "pending");
3271         }
3272         if (p == nullptr) return Pending{};
3273         if (!PromiseResultTraits5::IsOk(*p)) {
3274           return PromiseResultTraits5::template ReturnValue<Result>(
3275               std::move(*p));
3276         }
3277         Destruct(&prior.prior.prior.prior.current_promise);
3278         auto next_promise = PromiseResultTraits5::CallFactory(
3279             &prior.prior.prior.prior.next_factory, std::move(*p));
3280         Destruct(&prior.prior.prior.prior.next_factory);
3281         Construct(&prior.prior.prior.current_promise, std::move(next_promise));
3282         state = State::kState6;
3283       }
3284         ABSL_FALLTHROUGH_INTENDED;
3285       case State::kState6: {
3286         if (grpc_trace_promise_primitives.enabled()) {
3287           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3288                   "seq[%p]: begin poll step 7/10", this);
3289         }
3290         auto result = prior.prior.prior.current_promise();
3291         PromiseResult6* p = result.value_if_ready();
3292         if (grpc_trace_promise_primitives.enabled()) {
3293           gpr_log(
3294               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3295               "seq[%p]: poll step 7/10 gets %s", this,
3296               p != nullptr
3297                   ? (PromiseResultTraits6::IsOk(*p)
3298                          ? "ready"
3299                          : absl::StrCat("early-error:",
3300                                         PromiseResultTraits6::ErrorString(*p))
3301                                .c_str())
3302                   : "pending");
3303         }
3304         if (p == nullptr) return Pending{};
3305         if (!PromiseResultTraits6::IsOk(*p)) {
3306           return PromiseResultTraits6::template ReturnValue<Result>(
3307               std::move(*p));
3308         }
3309         Destruct(&prior.prior.prior.current_promise);
3310         auto next_promise = PromiseResultTraits6::CallFactory(
3311             &prior.prior.prior.next_factory, std::move(*p));
3312         Destruct(&prior.prior.prior.next_factory);
3313         Construct(&prior.prior.current_promise, std::move(next_promise));
3314         state = State::kState7;
3315       }
3316         ABSL_FALLTHROUGH_INTENDED;
3317       case State::kState7: {
3318         if (grpc_trace_promise_primitives.enabled()) {
3319           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3320                   "seq[%p]: begin poll step 8/10", this);
3321         }
3322         auto result = prior.prior.current_promise();
3323         PromiseResult7* p = result.value_if_ready();
3324         if (grpc_trace_promise_primitives.enabled()) {
3325           gpr_log(
3326               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3327               "seq[%p]: poll step 8/10 gets %s", this,
3328               p != nullptr
3329                   ? (PromiseResultTraits7::IsOk(*p)
3330                          ? "ready"
3331                          : absl::StrCat("early-error:",
3332                                         PromiseResultTraits7::ErrorString(*p))
3333                                .c_str())
3334                   : "pending");
3335         }
3336         if (p == nullptr) return Pending{};
3337         if (!PromiseResultTraits7::IsOk(*p)) {
3338           return PromiseResultTraits7::template ReturnValue<Result>(
3339               std::move(*p));
3340         }
3341         Destruct(&prior.prior.current_promise);
3342         auto next_promise = PromiseResultTraits7::CallFactory(
3343             &prior.prior.next_factory, std::move(*p));
3344         Destruct(&prior.prior.next_factory);
3345         Construct(&prior.current_promise, std::move(next_promise));
3346         state = State::kState8;
3347       }
3348         ABSL_FALLTHROUGH_INTENDED;
3349       case State::kState8: {
3350         if (grpc_trace_promise_primitives.enabled()) {
3351           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3352                   "seq[%p]: begin poll step 9/10", this);
3353         }
3354         auto result = prior.current_promise();
3355         PromiseResult8* p = result.value_if_ready();
3356         if (grpc_trace_promise_primitives.enabled()) {
3357           gpr_log(
3358               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3359               "seq[%p]: poll step 9/10 gets %s", this,
3360               p != nullptr
3361                   ? (PromiseResultTraits8::IsOk(*p)
3362                          ? "ready"
3363                          : absl::StrCat("early-error:",
3364                                         PromiseResultTraits8::ErrorString(*p))
3365                                .c_str())
3366                   : "pending");
3367         }
3368         if (p == nullptr) return Pending{};
3369         if (!PromiseResultTraits8::IsOk(*p)) {
3370           return PromiseResultTraits8::template ReturnValue<Result>(
3371               std::move(*p));
3372         }
3373         Destruct(&prior.current_promise);
3374         auto next_promise = PromiseResultTraits8::CallFactory(
3375             &prior.next_factory, std::move(*p));
3376         Destruct(&prior.next_factory);
3377         Construct(&current_promise, std::move(next_promise));
3378         state = State::kState9;
3379       }
3380         ABSL_FALLTHROUGH_INTENDED;
3381       default:
3382       case State::kState9: {
3383         if (grpc_trace_promise_primitives.enabled()) {
3384           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3385                   "seq[%p]: begin poll step 10/10", this);
3386         }
3387         auto result = current_promise();
3388         if (grpc_trace_promise_primitives.enabled()) {
3389           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3390                   "seq[%p]: poll step 10/10 gets %s", this,
3391                   result.ready() ? "ready" : "pending");
3392         }
3393         auto* p = result.value_if_ready();
3394         if (p == nullptr) return Pending{};
3395         return Result(std::move(*p));
3396       }
3397     }
3398   }
3399 };
3400 
3401 template <template <typename> class Traits, typename P, typename F0,
3402           typename F1, typename F2, typename F3, typename F4, typename F5,
3403           typename F6, typename F7, typename F8, typename F9>
3404 struct SeqState<Traits, P, F0, F1, F2, F3, F4, F5, F6, F7, F8, F9> {
3405   using Promise0 = PromiseLike<P>;
3406   using PromiseResult0 = typename Promise0::Result;
3407   using PromiseResultTraits0 = Traits<PromiseResult0>;
3408   using NextFactory0 =
3409       OncePromiseFactory<typename PromiseResultTraits0::UnwrappedType, F0>;
3410   using Promise1 = typename NextFactory0::Promise;
3411   using PromiseResult1 = typename Promise1::Result;
3412   using PromiseResultTraits1 = Traits<PromiseResult1>;
3413   using NextFactory1 =
3414       OncePromiseFactory<typename PromiseResultTraits1::UnwrappedType, F1>;
3415   using Promise2 = typename NextFactory1::Promise;
3416   using PromiseResult2 = typename Promise2::Result;
3417   using PromiseResultTraits2 = Traits<PromiseResult2>;
3418   using NextFactory2 =
3419       OncePromiseFactory<typename PromiseResultTraits2::UnwrappedType, F2>;
3420   using Promise3 = typename NextFactory2::Promise;
3421   using PromiseResult3 = typename Promise3::Result;
3422   using PromiseResultTraits3 = Traits<PromiseResult3>;
3423   using NextFactory3 =
3424       OncePromiseFactory<typename PromiseResultTraits3::UnwrappedType, F3>;
3425   using Promise4 = typename NextFactory3::Promise;
3426   using PromiseResult4 = typename Promise4::Result;
3427   using PromiseResultTraits4 = Traits<PromiseResult4>;
3428   using NextFactory4 =
3429       OncePromiseFactory<typename PromiseResultTraits4::UnwrappedType, F4>;
3430   using Promise5 = typename NextFactory4::Promise;
3431   using PromiseResult5 = typename Promise5::Result;
3432   using PromiseResultTraits5 = Traits<PromiseResult5>;
3433   using NextFactory5 =
3434       OncePromiseFactory<typename PromiseResultTraits5::UnwrappedType, F5>;
3435   using Promise6 = typename NextFactory5::Promise;
3436   using PromiseResult6 = typename Promise6::Result;
3437   using PromiseResultTraits6 = Traits<PromiseResult6>;
3438   using NextFactory6 =
3439       OncePromiseFactory<typename PromiseResultTraits6::UnwrappedType, F6>;
3440   using Promise7 = typename NextFactory6::Promise;
3441   using PromiseResult7 = typename Promise7::Result;
3442   using PromiseResultTraits7 = Traits<PromiseResult7>;
3443   using NextFactory7 =
3444       OncePromiseFactory<typename PromiseResultTraits7::UnwrappedType, F7>;
3445   using Promise8 = typename NextFactory7::Promise;
3446   using PromiseResult8 = typename Promise8::Result;
3447   using PromiseResultTraits8 = Traits<PromiseResult8>;
3448   using NextFactory8 =
3449       OncePromiseFactory<typename PromiseResultTraits8::UnwrappedType, F8>;
3450   using Promise9 = typename NextFactory8::Promise;
3451   using PromiseResult9 = typename Promise9::Result;
3452   using PromiseResultTraits9 = Traits<PromiseResult9>;
3453   using NextFactory9 =
3454       OncePromiseFactory<typename PromiseResultTraits9::UnwrappedType, F9>;
3455   using Promise10 = typename NextFactory9::Promise;
3456   using PromiseResult10 = typename Promise10::Result;
3457   using PromiseResultTraits10 = Traits<PromiseResult10>;
3458   using Result = typename PromiseResultTraits10::WrappedType;
3459   struct Running0 {
3460     GPR_NO_UNIQUE_ADDRESS Promise0 current_promise;
3461     GPR_NO_UNIQUE_ADDRESS NextFactory0 next_factory;
3462   };
3463   struct Running1 {
3464     union {
3465       GPR_NO_UNIQUE_ADDRESS Running0 prior;
3466       GPR_NO_UNIQUE_ADDRESS Promise1 current_promise;
3467     };
3468     GPR_NO_UNIQUE_ADDRESS NextFactory1 next_factory;
3469   };
3470   struct Running2 {
3471     union {
3472       GPR_NO_UNIQUE_ADDRESS Running1 prior;
3473       GPR_NO_UNIQUE_ADDRESS Promise2 current_promise;
3474     };
3475     GPR_NO_UNIQUE_ADDRESS NextFactory2 next_factory;
3476   };
3477   struct Running3 {
3478     union {
3479       GPR_NO_UNIQUE_ADDRESS Running2 prior;
3480       GPR_NO_UNIQUE_ADDRESS Promise3 current_promise;
3481     };
3482     GPR_NO_UNIQUE_ADDRESS NextFactory3 next_factory;
3483   };
3484   struct Running4 {
3485     union {
3486       GPR_NO_UNIQUE_ADDRESS Running3 prior;
3487       GPR_NO_UNIQUE_ADDRESS Promise4 current_promise;
3488     };
3489     GPR_NO_UNIQUE_ADDRESS NextFactory4 next_factory;
3490   };
3491   struct Running5 {
3492     union {
3493       GPR_NO_UNIQUE_ADDRESS Running4 prior;
3494       GPR_NO_UNIQUE_ADDRESS Promise5 current_promise;
3495     };
3496     GPR_NO_UNIQUE_ADDRESS NextFactory5 next_factory;
3497   };
3498   struct Running6 {
3499     union {
3500       GPR_NO_UNIQUE_ADDRESS Running5 prior;
3501       GPR_NO_UNIQUE_ADDRESS Promise6 current_promise;
3502     };
3503     GPR_NO_UNIQUE_ADDRESS NextFactory6 next_factory;
3504   };
3505   struct Running7 {
3506     union {
3507       GPR_NO_UNIQUE_ADDRESS Running6 prior;
3508       GPR_NO_UNIQUE_ADDRESS Promise7 current_promise;
3509     };
3510     GPR_NO_UNIQUE_ADDRESS NextFactory7 next_factory;
3511   };
3512   struct Running8 {
3513     union {
3514       GPR_NO_UNIQUE_ADDRESS Running7 prior;
3515       GPR_NO_UNIQUE_ADDRESS Promise8 current_promise;
3516     };
3517     GPR_NO_UNIQUE_ADDRESS NextFactory8 next_factory;
3518   };
3519   struct Running9 {
3520     union {
3521       GPR_NO_UNIQUE_ADDRESS Running8 prior;
3522       GPR_NO_UNIQUE_ADDRESS Promise9 current_promise;
3523     };
3524     GPR_NO_UNIQUE_ADDRESS NextFactory9 next_factory;
3525   };
3526   union {
3527     GPR_NO_UNIQUE_ADDRESS Running9 prior;
3528     GPR_NO_UNIQUE_ADDRESS Promise10 current_promise;
3529   };
3530   enum class State : uint8_t {
3531     kState0,
3532     kState1,
3533     kState2,
3534     kState3,
3535     kState4,
3536     kState5,
3537     kState6,
3538     kState7,
3539     kState8,
3540     kState9,
3541     kState10
3542   };
3543   GPR_NO_UNIQUE_ADDRESS State state = State::kState0;
3544   GPR_NO_UNIQUE_ADDRESS DebugLocation whence;
3545 
3546   SeqState(P&& p, F0&& f0, F1&& f1, F2&& f2, F3&& f3, F4&& f4, F5&& f5, F6&& f6,
3547            F7&& f7, F8&& f8, F9&& f9, DebugLocation whence) noexcept
3548       : whence(whence) {
3549     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
3550                    .current_promise,
3551               std::forward<P>(p));
3552     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
3553                    .next_factory,
3554               std::forward<F0>(f0));
3555     Construct(
3556         &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
3557         std::forward<F1>(f1));
3558     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
3559               std::forward<F2>(f2));
3560     Construct(&prior.prior.prior.prior.prior.prior.prior.next_factory,
3561               std::forward<F3>(f3));
3562     Construct(&prior.prior.prior.prior.prior.prior.next_factory,
3563               std::forward<F4>(f4));
3564     Construct(&prior.prior.prior.prior.prior.next_factory,
3565               std::forward<F5>(f5));
3566     Construct(&prior.prior.prior.prior.next_factory, std::forward<F6>(f6));
3567     Construct(&prior.prior.prior.next_factory, std::forward<F7>(f7));
3568     Construct(&prior.prior.next_factory, std::forward<F8>(f8));
3569     Construct(&prior.next_factory, std::forward<F9>(f9));
3570   }
3571   ~SeqState() {
3572     switch (state) {
3573       case State::kState0:
3574         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
3575                       .current_promise);
3576         goto tail0;
3577       case State::kState1:
3578         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior
3579                       .current_promise);
3580         goto tail1;
3581       case State::kState2:
3582         Destruct(
3583             &prior.prior.prior.prior.prior.prior.prior.prior.current_promise);
3584         goto tail2;
3585       case State::kState3:
3586         Destruct(&prior.prior.prior.prior.prior.prior.prior.current_promise);
3587         goto tail3;
3588       case State::kState4:
3589         Destruct(&prior.prior.prior.prior.prior.prior.current_promise);
3590         goto tail4;
3591       case State::kState5:
3592         Destruct(&prior.prior.prior.prior.prior.current_promise);
3593         goto tail5;
3594       case State::kState6:
3595         Destruct(&prior.prior.prior.prior.current_promise);
3596         goto tail6;
3597       case State::kState7:
3598         Destruct(&prior.prior.prior.current_promise);
3599         goto tail7;
3600       case State::kState8:
3601         Destruct(&prior.prior.current_promise);
3602         goto tail8;
3603       case State::kState9:
3604         Destruct(&prior.current_promise);
3605         goto tail9;
3606       case State::kState10:
3607         Destruct(&current_promise);
3608         return;
3609     }
3610   tail0:
3611     Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
3612                   .next_factory);
3613   tail1:
3614     Destruct(
3615         &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory);
3616   tail2:
3617     Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory);
3618   tail3:
3619     Destruct(&prior.prior.prior.prior.prior.prior.prior.next_factory);
3620   tail4:
3621     Destruct(&prior.prior.prior.prior.prior.prior.next_factory);
3622   tail5:
3623     Destruct(&prior.prior.prior.prior.prior.next_factory);
3624   tail6:
3625     Destruct(&prior.prior.prior.prior.next_factory);
3626   tail7:
3627     Destruct(&prior.prior.prior.next_factory);
3628   tail8:
3629     Destruct(&prior.prior.next_factory);
3630   tail9:
3631     Destruct(&prior.next_factory);
3632   }
3633   SeqState(const SeqState& other) noexcept
3634       : state(other.state), whence(other.whence) {
3635     GPR_ASSERT(state == State::kState0);
3636     Construct(&prior.current_promise, other.prior.current_promise);
3637     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
3638                    .next_factory,
3639               other.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
3640                   .next_factory);
3641     Construct(
3642         &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
3643         other.prior.prior.prior.prior.prior.prior.prior.prior.prior
3644             .next_factory);
3645     Construct(
3646         &prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
3647         other.prior.prior.prior.prior.prior.prior.prior.prior.next_factory);
3648     Construct(&prior.prior.prior.prior.prior.prior.prior.next_factory,
3649               other.prior.prior.prior.prior.prior.prior.prior.next_factory);
3650     Construct(&prior.prior.prior.prior.prior.prior.next_factory,
3651               other.prior.prior.prior.prior.prior.prior.next_factory);
3652     Construct(&prior.prior.prior.prior.prior.next_factory,
3653               other.prior.prior.prior.prior.prior.next_factory);
3654     Construct(&prior.prior.prior.prior.next_factory,
3655               other.prior.prior.prior.prior.next_factory);
3656     Construct(&prior.prior.prior.next_factory,
3657               other.prior.prior.prior.next_factory);
3658     Construct(&prior.prior.next_factory, other.prior.prior.next_factory);
3659     Construct(&prior.next_factory, other.prior.next_factory);
3660   }
3661   SeqState& operator=(const SeqState& other) = delete;
3662   SeqState(SeqState&& other) noexcept
3663       : state(other.state), whence(other.whence) {
3664     switch (state) {
3665       case State::kState0:
3666         Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
3667                        .current_promise,
3668                   std::move(other.prior.prior.prior.prior.prior.prior.prior
3669                                 .prior.prior.prior.current_promise));
3670         goto tail0;
3671       case State::kState1:
3672         Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior
3673                        .current_promise,
3674                   std::move(other.prior.prior.prior.prior.prior.prior.prior
3675                                 .prior.prior.current_promise));
3676         goto tail1;
3677       case State::kState2:
3678         Construct(
3679             &prior.prior.prior.prior.prior.prior.prior.prior.current_promise,
3680             std::move(other.prior.prior.prior.prior.prior.prior.prior.prior
3681                           .current_promise));
3682         goto tail2;
3683       case State::kState3:
3684         Construct(&prior.prior.prior.prior.prior.prior.prior.current_promise,
3685                   std::move(other.prior.prior.prior.prior.prior.prior.prior
3686                                 .current_promise));
3687         goto tail3;
3688       case State::kState4:
3689         Construct(
3690             &prior.prior.prior.prior.prior.prior.current_promise,
3691             std::move(
3692                 other.prior.prior.prior.prior.prior.prior.current_promise));
3693         goto tail4;
3694       case State::kState5:
3695         Construct(
3696             &prior.prior.prior.prior.prior.current_promise,
3697             std::move(other.prior.prior.prior.prior.prior.current_promise));
3698         goto tail5;
3699       case State::kState6:
3700         Construct(&prior.prior.prior.prior.current_promise,
3701                   std::move(other.prior.prior.prior.prior.current_promise));
3702         goto tail6;
3703       case State::kState7:
3704         Construct(&prior.prior.prior.current_promise,
3705                   std::move(other.prior.prior.prior.current_promise));
3706         goto tail7;
3707       case State::kState8:
3708         Construct(&prior.prior.current_promise,
3709                   std::move(other.prior.prior.current_promise));
3710         goto tail8;
3711       case State::kState9:
3712         Construct(&prior.current_promise,
3713                   std::move(other.prior.current_promise));
3714         goto tail9;
3715       case State::kState10:
3716         Construct(&current_promise, std::move(other.current_promise));
3717         return;
3718     }
3719   tail0:
3720     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
3721                    .next_factory,
3722               std::move(other.prior.prior.prior.prior.prior.prior.prior.prior
3723                             .prior.prior.next_factory));
3724   tail1:
3725     Construct(
3726         &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
3727         std::move(other.prior.prior.prior.prior.prior.prior.prior.prior.prior
3728                       .next_factory));
3729   tail2:
3730     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
3731               std::move(other.prior.prior.prior.prior.prior.prior.prior.prior
3732                             .next_factory));
3733   tail3:
3734     Construct(
3735         &prior.prior.prior.prior.prior.prior.prior.next_factory,
3736         std::move(
3737             other.prior.prior.prior.prior.prior.prior.prior.next_factory));
3738   tail4:
3739     Construct(
3740         &prior.prior.prior.prior.prior.prior.next_factory,
3741         std::move(other.prior.prior.prior.prior.prior.prior.next_factory));
3742   tail5:
3743     Construct(&prior.prior.prior.prior.prior.next_factory,
3744               std::move(other.prior.prior.prior.prior.prior.next_factory));
3745   tail6:
3746     Construct(&prior.prior.prior.prior.next_factory,
3747               std::move(other.prior.prior.prior.prior.next_factory));
3748   tail7:
3749     Construct(&prior.prior.prior.next_factory,
3750               std::move(other.prior.prior.prior.next_factory));
3751   tail8:
3752     Construct(&prior.prior.next_factory,
3753               std::move(other.prior.prior.next_factory));
3754   tail9:
3755     Construct(&prior.next_factory, std::move(other.prior.next_factory));
3756   }
3757   SeqState& operator=(SeqState&& other) = delete;
3758   Poll<Result> PollOnce() {
3759     switch (state) {
3760       case State::kState0: {
3761         if (grpc_trace_promise_primitives.enabled()) {
3762           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3763                   "seq[%p]: begin poll step 1/11", this);
3764         }
3765         auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior
3766                           .prior.current_promise();
3767         PromiseResult0* p = result.value_if_ready();
3768         if (grpc_trace_promise_primitives.enabled()) {
3769           gpr_log(
3770               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3771               "seq[%p]: poll step 1/11 gets %s", this,
3772               p != nullptr
3773                   ? (PromiseResultTraits0::IsOk(*p)
3774                          ? "ready"
3775                          : absl::StrCat("early-error:",
3776                                         PromiseResultTraits0::ErrorString(*p))
3777                                .c_str())
3778                   : "pending");
3779         }
3780         if (p == nullptr) return Pending{};
3781         if (!PromiseResultTraits0::IsOk(*p)) {
3782           return PromiseResultTraits0::template ReturnValue<Result>(
3783               std::move(*p));
3784         }
3785         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
3786                       .current_promise);
3787         auto next_promise = PromiseResultTraits0::CallFactory(
3788             &prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
3789                  .next_factory,
3790             std::move(*p));
3791         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
3792                       .next_factory);
3793         Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior
3794                        .current_promise,
3795                   std::move(next_promise));
3796         state = State::kState1;
3797       }
3798         ABSL_FALLTHROUGH_INTENDED;
3799       case State::kState1: {
3800         if (grpc_trace_promise_primitives.enabled()) {
3801           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3802                   "seq[%p]: begin poll step 2/11", this);
3803         }
3804         auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior
3805                           .current_promise();
3806         PromiseResult1* p = result.value_if_ready();
3807         if (grpc_trace_promise_primitives.enabled()) {
3808           gpr_log(
3809               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3810               "seq[%p]: poll step 2/11 gets %s", this,
3811               p != nullptr
3812                   ? (PromiseResultTraits1::IsOk(*p)
3813                          ? "ready"
3814                          : absl::StrCat("early-error:",
3815                                         PromiseResultTraits1::ErrorString(*p))
3816                                .c_str())
3817                   : "pending");
3818         }
3819         if (p == nullptr) return Pending{};
3820         if (!PromiseResultTraits1::IsOk(*p)) {
3821           return PromiseResultTraits1::template ReturnValue<Result>(
3822               std::move(*p));
3823         }
3824         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior
3825                       .current_promise);
3826         auto next_promise = PromiseResultTraits1::CallFactory(
3827             &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
3828             std::move(*p));
3829         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior
3830                       .next_factory);
3831         Construct(
3832             &prior.prior.prior.prior.prior.prior.prior.prior.current_promise,
3833             std::move(next_promise));
3834         state = State::kState2;
3835       }
3836         ABSL_FALLTHROUGH_INTENDED;
3837       case State::kState2: {
3838         if (grpc_trace_promise_primitives.enabled()) {
3839           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3840                   "seq[%p]: begin poll step 3/11", this);
3841         }
3842         auto result =
3843             prior.prior.prior.prior.prior.prior.prior.prior.current_promise();
3844         PromiseResult2* p = result.value_if_ready();
3845         if (grpc_trace_promise_primitives.enabled()) {
3846           gpr_log(
3847               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3848               "seq[%p]: poll step 3/11 gets %s", this,
3849               p != nullptr
3850                   ? (PromiseResultTraits2::IsOk(*p)
3851                          ? "ready"
3852                          : absl::StrCat("early-error:",
3853                                         PromiseResultTraits2::ErrorString(*p))
3854                                .c_str())
3855                   : "pending");
3856         }
3857         if (p == nullptr) return Pending{};
3858         if (!PromiseResultTraits2::IsOk(*p)) {
3859           return PromiseResultTraits2::template ReturnValue<Result>(
3860               std::move(*p));
3861         }
3862         Destruct(
3863             &prior.prior.prior.prior.prior.prior.prior.prior.current_promise);
3864         auto next_promise = PromiseResultTraits2::CallFactory(
3865             &prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
3866             std::move(*p));
3867         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory);
3868         Construct(&prior.prior.prior.prior.prior.prior.prior.current_promise,
3869                   std::move(next_promise));
3870         state = State::kState3;
3871       }
3872         ABSL_FALLTHROUGH_INTENDED;
3873       case State::kState3: {
3874         if (grpc_trace_promise_primitives.enabled()) {
3875           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3876                   "seq[%p]: begin poll step 4/11", this);
3877         }
3878         auto result =
3879             prior.prior.prior.prior.prior.prior.prior.current_promise();
3880         PromiseResult3* p = result.value_if_ready();
3881         if (grpc_trace_promise_primitives.enabled()) {
3882           gpr_log(
3883               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3884               "seq[%p]: poll step 4/11 gets %s", this,
3885               p != nullptr
3886                   ? (PromiseResultTraits3::IsOk(*p)
3887                          ? "ready"
3888                          : absl::StrCat("early-error:",
3889                                         PromiseResultTraits3::ErrorString(*p))
3890                                .c_str())
3891                   : "pending");
3892         }
3893         if (p == nullptr) return Pending{};
3894         if (!PromiseResultTraits3::IsOk(*p)) {
3895           return PromiseResultTraits3::template ReturnValue<Result>(
3896               std::move(*p));
3897         }
3898         Destruct(&prior.prior.prior.prior.prior.prior.prior.current_promise);
3899         auto next_promise = PromiseResultTraits3::CallFactory(
3900             &prior.prior.prior.prior.prior.prior.prior.next_factory,
3901             std::move(*p));
3902         Destruct(&prior.prior.prior.prior.prior.prior.prior.next_factory);
3903         Construct(&prior.prior.prior.prior.prior.prior.current_promise,
3904                   std::move(next_promise));
3905         state = State::kState4;
3906       }
3907         ABSL_FALLTHROUGH_INTENDED;
3908       case State::kState4: {
3909         if (grpc_trace_promise_primitives.enabled()) {
3910           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3911                   "seq[%p]: begin poll step 5/11", this);
3912         }
3913         auto result = prior.prior.prior.prior.prior.prior.current_promise();
3914         PromiseResult4* p = result.value_if_ready();
3915         if (grpc_trace_promise_primitives.enabled()) {
3916           gpr_log(
3917               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3918               "seq[%p]: poll step 5/11 gets %s", this,
3919               p != nullptr
3920                   ? (PromiseResultTraits4::IsOk(*p)
3921                          ? "ready"
3922                          : absl::StrCat("early-error:",
3923                                         PromiseResultTraits4::ErrorString(*p))
3924                                .c_str())
3925                   : "pending");
3926         }
3927         if (p == nullptr) return Pending{};
3928         if (!PromiseResultTraits4::IsOk(*p)) {
3929           return PromiseResultTraits4::template ReturnValue<Result>(
3930               std::move(*p));
3931         }
3932         Destruct(&prior.prior.prior.prior.prior.prior.current_promise);
3933         auto next_promise = PromiseResultTraits4::CallFactory(
3934             &prior.prior.prior.prior.prior.prior.next_factory, std::move(*p));
3935         Destruct(&prior.prior.prior.prior.prior.prior.next_factory);
3936         Construct(&prior.prior.prior.prior.prior.current_promise,
3937                   std::move(next_promise));
3938         state = State::kState5;
3939       }
3940         ABSL_FALLTHROUGH_INTENDED;
3941       case State::kState5: {
3942         if (grpc_trace_promise_primitives.enabled()) {
3943           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3944                   "seq[%p]: begin poll step 6/11", this);
3945         }
3946         auto result = prior.prior.prior.prior.prior.current_promise();
3947         PromiseResult5* p = result.value_if_ready();
3948         if (grpc_trace_promise_primitives.enabled()) {
3949           gpr_log(
3950               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3951               "seq[%p]: poll step 6/11 gets %s", this,
3952               p != nullptr
3953                   ? (PromiseResultTraits5::IsOk(*p)
3954                          ? "ready"
3955                          : absl::StrCat("early-error:",
3956                                         PromiseResultTraits5::ErrorString(*p))
3957                                .c_str())
3958                   : "pending");
3959         }
3960         if (p == nullptr) return Pending{};
3961         if (!PromiseResultTraits5::IsOk(*p)) {
3962           return PromiseResultTraits5::template ReturnValue<Result>(
3963               std::move(*p));
3964         }
3965         Destruct(&prior.prior.prior.prior.prior.current_promise);
3966         auto next_promise = PromiseResultTraits5::CallFactory(
3967             &prior.prior.prior.prior.prior.next_factory, std::move(*p));
3968         Destruct(&prior.prior.prior.prior.prior.next_factory);
3969         Construct(&prior.prior.prior.prior.current_promise,
3970                   std::move(next_promise));
3971         state = State::kState6;
3972       }
3973         ABSL_FALLTHROUGH_INTENDED;
3974       case State::kState6: {
3975         if (grpc_trace_promise_primitives.enabled()) {
3976           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3977                   "seq[%p]: begin poll step 7/11", this);
3978         }
3979         auto result = prior.prior.prior.prior.current_promise();
3980         PromiseResult6* p = result.value_if_ready();
3981         if (grpc_trace_promise_primitives.enabled()) {
3982           gpr_log(
3983               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
3984               "seq[%p]: poll step 7/11 gets %s", this,
3985               p != nullptr
3986                   ? (PromiseResultTraits6::IsOk(*p)
3987                          ? "ready"
3988                          : absl::StrCat("early-error:",
3989                                         PromiseResultTraits6::ErrorString(*p))
3990                                .c_str())
3991                   : "pending");
3992         }
3993         if (p == nullptr) return Pending{};
3994         if (!PromiseResultTraits6::IsOk(*p)) {
3995           return PromiseResultTraits6::template ReturnValue<Result>(
3996               std::move(*p));
3997         }
3998         Destruct(&prior.prior.prior.prior.current_promise);
3999         auto next_promise = PromiseResultTraits6::CallFactory(
4000             &prior.prior.prior.prior.next_factory, std::move(*p));
4001         Destruct(&prior.prior.prior.prior.next_factory);
4002         Construct(&prior.prior.prior.current_promise, std::move(next_promise));
4003         state = State::kState7;
4004       }
4005         ABSL_FALLTHROUGH_INTENDED;
4006       case State::kState7: {
4007         if (grpc_trace_promise_primitives.enabled()) {
4008           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4009                   "seq[%p]: begin poll step 8/11", this);
4010         }
4011         auto result = prior.prior.prior.current_promise();
4012         PromiseResult7* p = result.value_if_ready();
4013         if (grpc_trace_promise_primitives.enabled()) {
4014           gpr_log(
4015               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4016               "seq[%p]: poll step 8/11 gets %s", this,
4017               p != nullptr
4018                   ? (PromiseResultTraits7::IsOk(*p)
4019                          ? "ready"
4020                          : absl::StrCat("early-error:",
4021                                         PromiseResultTraits7::ErrorString(*p))
4022                                .c_str())
4023                   : "pending");
4024         }
4025         if (p == nullptr) return Pending{};
4026         if (!PromiseResultTraits7::IsOk(*p)) {
4027           return PromiseResultTraits7::template ReturnValue<Result>(
4028               std::move(*p));
4029         }
4030         Destruct(&prior.prior.prior.current_promise);
4031         auto next_promise = PromiseResultTraits7::CallFactory(
4032             &prior.prior.prior.next_factory, std::move(*p));
4033         Destruct(&prior.prior.prior.next_factory);
4034         Construct(&prior.prior.current_promise, std::move(next_promise));
4035         state = State::kState8;
4036       }
4037         ABSL_FALLTHROUGH_INTENDED;
4038       case State::kState8: {
4039         if (grpc_trace_promise_primitives.enabled()) {
4040           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4041                   "seq[%p]: begin poll step 9/11", this);
4042         }
4043         auto result = prior.prior.current_promise();
4044         PromiseResult8* p = result.value_if_ready();
4045         if (grpc_trace_promise_primitives.enabled()) {
4046           gpr_log(
4047               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4048               "seq[%p]: poll step 9/11 gets %s", this,
4049               p != nullptr
4050                   ? (PromiseResultTraits8::IsOk(*p)
4051                          ? "ready"
4052                          : absl::StrCat("early-error:",
4053                                         PromiseResultTraits8::ErrorString(*p))
4054                                .c_str())
4055                   : "pending");
4056         }
4057         if (p == nullptr) return Pending{};
4058         if (!PromiseResultTraits8::IsOk(*p)) {
4059           return PromiseResultTraits8::template ReturnValue<Result>(
4060               std::move(*p));
4061         }
4062         Destruct(&prior.prior.current_promise);
4063         auto next_promise = PromiseResultTraits8::CallFactory(
4064             &prior.prior.next_factory, std::move(*p));
4065         Destruct(&prior.prior.next_factory);
4066         Construct(&prior.current_promise, std::move(next_promise));
4067         state = State::kState9;
4068       }
4069         ABSL_FALLTHROUGH_INTENDED;
4070       case State::kState9: {
4071         if (grpc_trace_promise_primitives.enabled()) {
4072           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4073                   "seq[%p]: begin poll step 10/11", this);
4074         }
4075         auto result = prior.current_promise();
4076         PromiseResult9* p = result.value_if_ready();
4077         if (grpc_trace_promise_primitives.enabled()) {
4078           gpr_log(
4079               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4080               "seq[%p]: poll step 10/11 gets %s", this,
4081               p != nullptr
4082                   ? (PromiseResultTraits9::IsOk(*p)
4083                          ? "ready"
4084                          : absl::StrCat("early-error:",
4085                                         PromiseResultTraits9::ErrorString(*p))
4086                                .c_str())
4087                   : "pending");
4088         }
4089         if (p == nullptr) return Pending{};
4090         if (!PromiseResultTraits9::IsOk(*p)) {
4091           return PromiseResultTraits9::template ReturnValue<Result>(
4092               std::move(*p));
4093         }
4094         Destruct(&prior.current_promise);
4095         auto next_promise = PromiseResultTraits9::CallFactory(
4096             &prior.next_factory, std::move(*p));
4097         Destruct(&prior.next_factory);
4098         Construct(&current_promise, std::move(next_promise));
4099         state = State::kState10;
4100       }
4101         ABSL_FALLTHROUGH_INTENDED;
4102       default:
4103       case State::kState10: {
4104         if (grpc_trace_promise_primitives.enabled()) {
4105           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4106                   "seq[%p]: begin poll step 11/11", this);
4107         }
4108         auto result = current_promise();
4109         if (grpc_trace_promise_primitives.enabled()) {
4110           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4111                   "seq[%p]: poll step 11/11 gets %s", this,
4112                   result.ready() ? "ready" : "pending");
4113         }
4114         auto* p = result.value_if_ready();
4115         if (p == nullptr) return Pending{};
4116         return Result(std::move(*p));
4117       }
4118     }
4119   }
4120 };
4121 
4122 template <template <typename> class Traits, typename P, typename F0,
4123           typename F1, typename F2, typename F3, typename F4, typename F5,
4124           typename F6, typename F7, typename F8, typename F9, typename F10>
4125 struct SeqState<Traits, P, F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10> {
4126   using Promise0 = PromiseLike<P>;
4127   using PromiseResult0 = typename Promise0::Result;
4128   using PromiseResultTraits0 = Traits<PromiseResult0>;
4129   using NextFactory0 =
4130       OncePromiseFactory<typename PromiseResultTraits0::UnwrappedType, F0>;
4131   using Promise1 = typename NextFactory0::Promise;
4132   using PromiseResult1 = typename Promise1::Result;
4133   using PromiseResultTraits1 = Traits<PromiseResult1>;
4134   using NextFactory1 =
4135       OncePromiseFactory<typename PromiseResultTraits1::UnwrappedType, F1>;
4136   using Promise2 = typename NextFactory1::Promise;
4137   using PromiseResult2 = typename Promise2::Result;
4138   using PromiseResultTraits2 = Traits<PromiseResult2>;
4139   using NextFactory2 =
4140       OncePromiseFactory<typename PromiseResultTraits2::UnwrappedType, F2>;
4141   using Promise3 = typename NextFactory2::Promise;
4142   using PromiseResult3 = typename Promise3::Result;
4143   using PromiseResultTraits3 = Traits<PromiseResult3>;
4144   using NextFactory3 =
4145       OncePromiseFactory<typename PromiseResultTraits3::UnwrappedType, F3>;
4146   using Promise4 = typename NextFactory3::Promise;
4147   using PromiseResult4 = typename Promise4::Result;
4148   using PromiseResultTraits4 = Traits<PromiseResult4>;
4149   using NextFactory4 =
4150       OncePromiseFactory<typename PromiseResultTraits4::UnwrappedType, F4>;
4151   using Promise5 = typename NextFactory4::Promise;
4152   using PromiseResult5 = typename Promise5::Result;
4153   using PromiseResultTraits5 = Traits<PromiseResult5>;
4154   using NextFactory5 =
4155       OncePromiseFactory<typename PromiseResultTraits5::UnwrappedType, F5>;
4156   using Promise6 = typename NextFactory5::Promise;
4157   using PromiseResult6 = typename Promise6::Result;
4158   using PromiseResultTraits6 = Traits<PromiseResult6>;
4159   using NextFactory6 =
4160       OncePromiseFactory<typename PromiseResultTraits6::UnwrappedType, F6>;
4161   using Promise7 = typename NextFactory6::Promise;
4162   using PromiseResult7 = typename Promise7::Result;
4163   using PromiseResultTraits7 = Traits<PromiseResult7>;
4164   using NextFactory7 =
4165       OncePromiseFactory<typename PromiseResultTraits7::UnwrappedType, F7>;
4166   using Promise8 = typename NextFactory7::Promise;
4167   using PromiseResult8 = typename Promise8::Result;
4168   using PromiseResultTraits8 = Traits<PromiseResult8>;
4169   using NextFactory8 =
4170       OncePromiseFactory<typename PromiseResultTraits8::UnwrappedType, F8>;
4171   using Promise9 = typename NextFactory8::Promise;
4172   using PromiseResult9 = typename Promise9::Result;
4173   using PromiseResultTraits9 = Traits<PromiseResult9>;
4174   using NextFactory9 =
4175       OncePromiseFactory<typename PromiseResultTraits9::UnwrappedType, F9>;
4176   using Promise10 = typename NextFactory9::Promise;
4177   using PromiseResult10 = typename Promise10::Result;
4178   using PromiseResultTraits10 = Traits<PromiseResult10>;
4179   using NextFactory10 =
4180       OncePromiseFactory<typename PromiseResultTraits10::UnwrappedType, F10>;
4181   using Promise11 = typename NextFactory10::Promise;
4182   using PromiseResult11 = typename Promise11::Result;
4183   using PromiseResultTraits11 = Traits<PromiseResult11>;
4184   using Result = typename PromiseResultTraits11::WrappedType;
4185   struct Running0 {
4186     GPR_NO_UNIQUE_ADDRESS Promise0 current_promise;
4187     GPR_NO_UNIQUE_ADDRESS NextFactory0 next_factory;
4188   };
4189   struct Running1 {
4190     union {
4191       GPR_NO_UNIQUE_ADDRESS Running0 prior;
4192       GPR_NO_UNIQUE_ADDRESS Promise1 current_promise;
4193     };
4194     GPR_NO_UNIQUE_ADDRESS NextFactory1 next_factory;
4195   };
4196   struct Running2 {
4197     union {
4198       GPR_NO_UNIQUE_ADDRESS Running1 prior;
4199       GPR_NO_UNIQUE_ADDRESS Promise2 current_promise;
4200     };
4201     GPR_NO_UNIQUE_ADDRESS NextFactory2 next_factory;
4202   };
4203   struct Running3 {
4204     union {
4205       GPR_NO_UNIQUE_ADDRESS Running2 prior;
4206       GPR_NO_UNIQUE_ADDRESS Promise3 current_promise;
4207     };
4208     GPR_NO_UNIQUE_ADDRESS NextFactory3 next_factory;
4209   };
4210   struct Running4 {
4211     union {
4212       GPR_NO_UNIQUE_ADDRESS Running3 prior;
4213       GPR_NO_UNIQUE_ADDRESS Promise4 current_promise;
4214     };
4215     GPR_NO_UNIQUE_ADDRESS NextFactory4 next_factory;
4216   };
4217   struct Running5 {
4218     union {
4219       GPR_NO_UNIQUE_ADDRESS Running4 prior;
4220       GPR_NO_UNIQUE_ADDRESS Promise5 current_promise;
4221     };
4222     GPR_NO_UNIQUE_ADDRESS NextFactory5 next_factory;
4223   };
4224   struct Running6 {
4225     union {
4226       GPR_NO_UNIQUE_ADDRESS Running5 prior;
4227       GPR_NO_UNIQUE_ADDRESS Promise6 current_promise;
4228     };
4229     GPR_NO_UNIQUE_ADDRESS NextFactory6 next_factory;
4230   };
4231   struct Running7 {
4232     union {
4233       GPR_NO_UNIQUE_ADDRESS Running6 prior;
4234       GPR_NO_UNIQUE_ADDRESS Promise7 current_promise;
4235     };
4236     GPR_NO_UNIQUE_ADDRESS NextFactory7 next_factory;
4237   };
4238   struct Running8 {
4239     union {
4240       GPR_NO_UNIQUE_ADDRESS Running7 prior;
4241       GPR_NO_UNIQUE_ADDRESS Promise8 current_promise;
4242     };
4243     GPR_NO_UNIQUE_ADDRESS NextFactory8 next_factory;
4244   };
4245   struct Running9 {
4246     union {
4247       GPR_NO_UNIQUE_ADDRESS Running8 prior;
4248       GPR_NO_UNIQUE_ADDRESS Promise9 current_promise;
4249     };
4250     GPR_NO_UNIQUE_ADDRESS NextFactory9 next_factory;
4251   };
4252   struct Running10 {
4253     union {
4254       GPR_NO_UNIQUE_ADDRESS Running9 prior;
4255       GPR_NO_UNIQUE_ADDRESS Promise10 current_promise;
4256     };
4257     GPR_NO_UNIQUE_ADDRESS NextFactory10 next_factory;
4258   };
4259   union {
4260     GPR_NO_UNIQUE_ADDRESS Running10 prior;
4261     GPR_NO_UNIQUE_ADDRESS Promise11 current_promise;
4262   };
4263   enum class State : uint8_t {
4264     kState0,
4265     kState1,
4266     kState2,
4267     kState3,
4268     kState4,
4269     kState5,
4270     kState6,
4271     kState7,
4272     kState8,
4273     kState9,
4274     kState10,
4275     kState11
4276   };
4277   GPR_NO_UNIQUE_ADDRESS State state = State::kState0;
4278   GPR_NO_UNIQUE_ADDRESS DebugLocation whence;
4279 
4280   SeqState(P&& p, F0&& f0, F1&& f1, F2&& f2, F3&& f3, F4&& f4, F5&& f5, F6&& f6,
4281            F7&& f7, F8&& f8, F9&& f9, F10&& f10, DebugLocation whence) noexcept
4282       : whence(whence) {
4283     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4284                    .current_promise,
4285               std::forward<P>(p));
4286     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4287                    .next_factory,
4288               std::forward<F0>(f0));
4289     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4290                    .next_factory,
4291               std::forward<F1>(f1));
4292     Construct(
4293         &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
4294         std::forward<F2>(f2));
4295     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
4296               std::forward<F3>(f3));
4297     Construct(&prior.prior.prior.prior.prior.prior.prior.next_factory,
4298               std::forward<F4>(f4));
4299     Construct(&prior.prior.prior.prior.prior.prior.next_factory,
4300               std::forward<F5>(f5));
4301     Construct(&prior.prior.prior.prior.prior.next_factory,
4302               std::forward<F6>(f6));
4303     Construct(&prior.prior.prior.prior.next_factory, std::forward<F7>(f7));
4304     Construct(&prior.prior.prior.next_factory, std::forward<F8>(f8));
4305     Construct(&prior.prior.next_factory, std::forward<F9>(f9));
4306     Construct(&prior.next_factory, std::forward<F10>(f10));
4307   }
4308   ~SeqState() {
4309     switch (state) {
4310       case State::kState0:
4311         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4312                       .prior.current_promise);
4313         goto tail0;
4314       case State::kState1:
4315         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4316                       .current_promise);
4317         goto tail1;
4318       case State::kState2:
4319         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior
4320                       .current_promise);
4321         goto tail2;
4322       case State::kState3:
4323         Destruct(
4324             &prior.prior.prior.prior.prior.prior.prior.prior.current_promise);
4325         goto tail3;
4326       case State::kState4:
4327         Destruct(&prior.prior.prior.prior.prior.prior.prior.current_promise);
4328         goto tail4;
4329       case State::kState5:
4330         Destruct(&prior.prior.prior.prior.prior.prior.current_promise);
4331         goto tail5;
4332       case State::kState6:
4333         Destruct(&prior.prior.prior.prior.prior.current_promise);
4334         goto tail6;
4335       case State::kState7:
4336         Destruct(&prior.prior.prior.prior.current_promise);
4337         goto tail7;
4338       case State::kState8:
4339         Destruct(&prior.prior.prior.current_promise);
4340         goto tail8;
4341       case State::kState9:
4342         Destruct(&prior.prior.current_promise);
4343         goto tail9;
4344       case State::kState10:
4345         Destruct(&prior.current_promise);
4346         goto tail10;
4347       case State::kState11:
4348         Destruct(&current_promise);
4349         return;
4350     }
4351   tail0:
4352     Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4353                   .next_factory);
4354   tail1:
4355     Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4356                   .next_factory);
4357   tail2:
4358     Destruct(
4359         &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory);
4360   tail3:
4361     Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory);
4362   tail4:
4363     Destruct(&prior.prior.prior.prior.prior.prior.prior.next_factory);
4364   tail5:
4365     Destruct(&prior.prior.prior.prior.prior.prior.next_factory);
4366   tail6:
4367     Destruct(&prior.prior.prior.prior.prior.next_factory);
4368   tail7:
4369     Destruct(&prior.prior.prior.prior.next_factory);
4370   tail8:
4371     Destruct(&prior.prior.prior.next_factory);
4372   tail9:
4373     Destruct(&prior.prior.next_factory);
4374   tail10:
4375     Destruct(&prior.next_factory);
4376   }
4377   SeqState(const SeqState& other) noexcept
4378       : state(other.state), whence(other.whence) {
4379     GPR_ASSERT(state == State::kState0);
4380     Construct(&prior.current_promise, other.prior.current_promise);
4381     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4382                    .next_factory,
4383               other.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4384                   .prior.next_factory);
4385     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4386                    .next_factory,
4387               other.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4388                   .next_factory);
4389     Construct(
4390         &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
4391         other.prior.prior.prior.prior.prior.prior.prior.prior.prior
4392             .next_factory);
4393     Construct(
4394         &prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
4395         other.prior.prior.prior.prior.prior.prior.prior.prior.next_factory);
4396     Construct(&prior.prior.prior.prior.prior.prior.prior.next_factory,
4397               other.prior.prior.prior.prior.prior.prior.prior.next_factory);
4398     Construct(&prior.prior.prior.prior.prior.prior.next_factory,
4399               other.prior.prior.prior.prior.prior.prior.next_factory);
4400     Construct(&prior.prior.prior.prior.prior.next_factory,
4401               other.prior.prior.prior.prior.prior.next_factory);
4402     Construct(&prior.prior.prior.prior.next_factory,
4403               other.prior.prior.prior.prior.next_factory);
4404     Construct(&prior.prior.prior.next_factory,
4405               other.prior.prior.prior.next_factory);
4406     Construct(&prior.prior.next_factory, other.prior.prior.next_factory);
4407     Construct(&prior.next_factory, other.prior.next_factory);
4408   }
4409   SeqState& operator=(const SeqState& other) = delete;
4410   SeqState(SeqState&& other) noexcept
4411       : state(other.state), whence(other.whence) {
4412     switch (state) {
4413       case State::kState0:
4414         Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4415                        .prior.current_promise,
4416                   std::move(other.prior.prior.prior.prior.prior.prior.prior
4417                                 .prior.prior.prior.prior.current_promise));
4418         goto tail0;
4419       case State::kState1:
4420         Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4421                        .current_promise,
4422                   std::move(other.prior.prior.prior.prior.prior.prior.prior
4423                                 .prior.prior.prior.current_promise));
4424         goto tail1;
4425       case State::kState2:
4426         Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior
4427                        .current_promise,
4428                   std::move(other.prior.prior.prior.prior.prior.prior.prior
4429                                 .prior.prior.current_promise));
4430         goto tail2;
4431       case State::kState3:
4432         Construct(
4433             &prior.prior.prior.prior.prior.prior.prior.prior.current_promise,
4434             std::move(other.prior.prior.prior.prior.prior.prior.prior.prior
4435                           .current_promise));
4436         goto tail3;
4437       case State::kState4:
4438         Construct(&prior.prior.prior.prior.prior.prior.prior.current_promise,
4439                   std::move(other.prior.prior.prior.prior.prior.prior.prior
4440                                 .current_promise));
4441         goto tail4;
4442       case State::kState5:
4443         Construct(
4444             &prior.prior.prior.prior.prior.prior.current_promise,
4445             std::move(
4446                 other.prior.prior.prior.prior.prior.prior.current_promise));
4447         goto tail5;
4448       case State::kState6:
4449         Construct(
4450             &prior.prior.prior.prior.prior.current_promise,
4451             std::move(other.prior.prior.prior.prior.prior.current_promise));
4452         goto tail6;
4453       case State::kState7:
4454         Construct(&prior.prior.prior.prior.current_promise,
4455                   std::move(other.prior.prior.prior.prior.current_promise));
4456         goto tail7;
4457       case State::kState8:
4458         Construct(&prior.prior.prior.current_promise,
4459                   std::move(other.prior.prior.prior.current_promise));
4460         goto tail8;
4461       case State::kState9:
4462         Construct(&prior.prior.current_promise,
4463                   std::move(other.prior.prior.current_promise));
4464         goto tail9;
4465       case State::kState10:
4466         Construct(&prior.current_promise,
4467                   std::move(other.prior.current_promise));
4468         goto tail10;
4469       case State::kState11:
4470         Construct(&current_promise, std::move(other.current_promise));
4471         return;
4472     }
4473   tail0:
4474     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4475                    .next_factory,
4476               std::move(other.prior.prior.prior.prior.prior.prior.prior.prior
4477                             .prior.prior.prior.next_factory));
4478   tail1:
4479     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4480                    .next_factory,
4481               std::move(other.prior.prior.prior.prior.prior.prior.prior.prior
4482                             .prior.prior.next_factory));
4483   tail2:
4484     Construct(
4485         &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
4486         std::move(other.prior.prior.prior.prior.prior.prior.prior.prior.prior
4487                       .next_factory));
4488   tail3:
4489     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
4490               std::move(other.prior.prior.prior.prior.prior.prior.prior.prior
4491                             .next_factory));
4492   tail4:
4493     Construct(
4494         &prior.prior.prior.prior.prior.prior.prior.next_factory,
4495         std::move(
4496             other.prior.prior.prior.prior.prior.prior.prior.next_factory));
4497   tail5:
4498     Construct(
4499         &prior.prior.prior.prior.prior.prior.next_factory,
4500         std::move(other.prior.prior.prior.prior.prior.prior.next_factory));
4501   tail6:
4502     Construct(&prior.prior.prior.prior.prior.next_factory,
4503               std::move(other.prior.prior.prior.prior.prior.next_factory));
4504   tail7:
4505     Construct(&prior.prior.prior.prior.next_factory,
4506               std::move(other.prior.prior.prior.prior.next_factory));
4507   tail8:
4508     Construct(&prior.prior.prior.next_factory,
4509               std::move(other.prior.prior.prior.next_factory));
4510   tail9:
4511     Construct(&prior.prior.next_factory,
4512               std::move(other.prior.prior.next_factory));
4513   tail10:
4514     Construct(&prior.next_factory, std::move(other.prior.next_factory));
4515   }
4516   SeqState& operator=(SeqState&& other) = delete;
4517   Poll<Result> PollOnce() {
4518     switch (state) {
4519       case State::kState0: {
4520         if (grpc_trace_promise_primitives.enabled()) {
4521           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4522                   "seq[%p]: begin poll step 1/12", this);
4523         }
4524         auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior
4525                           .prior.prior.current_promise();
4526         PromiseResult0* p = result.value_if_ready();
4527         if (grpc_trace_promise_primitives.enabled()) {
4528           gpr_log(
4529               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4530               "seq[%p]: poll step 1/12 gets %s", this,
4531               p != nullptr
4532                   ? (PromiseResultTraits0::IsOk(*p)
4533                          ? "ready"
4534                          : absl::StrCat("early-error:",
4535                                         PromiseResultTraits0::ErrorString(*p))
4536                                .c_str())
4537                   : "pending");
4538         }
4539         if (p == nullptr) return Pending{};
4540         if (!PromiseResultTraits0::IsOk(*p)) {
4541           return PromiseResultTraits0::template ReturnValue<Result>(
4542               std::move(*p));
4543         }
4544         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4545                       .prior.current_promise);
4546         auto next_promise = PromiseResultTraits0::CallFactory(
4547             &prior.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4548                  .next_factory,
4549             std::move(*p));
4550         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4551                       .prior.next_factory);
4552         Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4553                        .current_promise,
4554                   std::move(next_promise));
4555         state = State::kState1;
4556       }
4557         ABSL_FALLTHROUGH_INTENDED;
4558       case State::kState1: {
4559         if (grpc_trace_promise_primitives.enabled()) {
4560           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4561                   "seq[%p]: begin poll step 2/12", this);
4562         }
4563         auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior
4564                           .prior.current_promise();
4565         PromiseResult1* p = result.value_if_ready();
4566         if (grpc_trace_promise_primitives.enabled()) {
4567           gpr_log(
4568               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4569               "seq[%p]: poll step 2/12 gets %s", this,
4570               p != nullptr
4571                   ? (PromiseResultTraits1::IsOk(*p)
4572                          ? "ready"
4573                          : absl::StrCat("early-error:",
4574                                         PromiseResultTraits1::ErrorString(*p))
4575                                .c_str())
4576                   : "pending");
4577         }
4578         if (p == nullptr) return Pending{};
4579         if (!PromiseResultTraits1::IsOk(*p)) {
4580           return PromiseResultTraits1::template ReturnValue<Result>(
4581               std::move(*p));
4582         }
4583         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4584                       .current_promise);
4585         auto next_promise = PromiseResultTraits1::CallFactory(
4586             &prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4587                  .next_factory,
4588             std::move(*p));
4589         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
4590                       .next_factory);
4591         Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior
4592                        .current_promise,
4593                   std::move(next_promise));
4594         state = State::kState2;
4595       }
4596         ABSL_FALLTHROUGH_INTENDED;
4597       case State::kState2: {
4598         if (grpc_trace_promise_primitives.enabled()) {
4599           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4600                   "seq[%p]: begin poll step 3/12", this);
4601         }
4602         auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior
4603                           .current_promise();
4604         PromiseResult2* p = result.value_if_ready();
4605         if (grpc_trace_promise_primitives.enabled()) {
4606           gpr_log(
4607               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4608               "seq[%p]: poll step 3/12 gets %s", this,
4609               p != nullptr
4610                   ? (PromiseResultTraits2::IsOk(*p)
4611                          ? "ready"
4612                          : absl::StrCat("early-error:",
4613                                         PromiseResultTraits2::ErrorString(*p))
4614                                .c_str())
4615                   : "pending");
4616         }
4617         if (p == nullptr) return Pending{};
4618         if (!PromiseResultTraits2::IsOk(*p)) {
4619           return PromiseResultTraits2::template ReturnValue<Result>(
4620               std::move(*p));
4621         }
4622         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior
4623                       .current_promise);
4624         auto next_promise = PromiseResultTraits2::CallFactory(
4625             &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
4626             std::move(*p));
4627         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior
4628                       .next_factory);
4629         Construct(
4630             &prior.prior.prior.prior.prior.prior.prior.prior.current_promise,
4631             std::move(next_promise));
4632         state = State::kState3;
4633       }
4634         ABSL_FALLTHROUGH_INTENDED;
4635       case State::kState3: {
4636         if (grpc_trace_promise_primitives.enabled()) {
4637           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4638                   "seq[%p]: begin poll step 4/12", this);
4639         }
4640         auto result =
4641             prior.prior.prior.prior.prior.prior.prior.prior.current_promise();
4642         PromiseResult3* p = result.value_if_ready();
4643         if (grpc_trace_promise_primitives.enabled()) {
4644           gpr_log(
4645               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4646               "seq[%p]: poll step 4/12 gets %s", this,
4647               p != nullptr
4648                   ? (PromiseResultTraits3::IsOk(*p)
4649                          ? "ready"
4650                          : absl::StrCat("early-error:",
4651                                         PromiseResultTraits3::ErrorString(*p))
4652                                .c_str())
4653                   : "pending");
4654         }
4655         if (p == nullptr) return Pending{};
4656         if (!PromiseResultTraits3::IsOk(*p)) {
4657           return PromiseResultTraits3::template ReturnValue<Result>(
4658               std::move(*p));
4659         }
4660         Destruct(
4661             &prior.prior.prior.prior.prior.prior.prior.prior.current_promise);
4662         auto next_promise = PromiseResultTraits3::CallFactory(
4663             &prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
4664             std::move(*p));
4665         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory);
4666         Construct(&prior.prior.prior.prior.prior.prior.prior.current_promise,
4667                   std::move(next_promise));
4668         state = State::kState4;
4669       }
4670         ABSL_FALLTHROUGH_INTENDED;
4671       case State::kState4: {
4672         if (grpc_trace_promise_primitives.enabled()) {
4673           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4674                   "seq[%p]: begin poll step 5/12", this);
4675         }
4676         auto result =
4677             prior.prior.prior.prior.prior.prior.prior.current_promise();
4678         PromiseResult4* p = result.value_if_ready();
4679         if (grpc_trace_promise_primitives.enabled()) {
4680           gpr_log(
4681               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4682               "seq[%p]: poll step 5/12 gets %s", this,
4683               p != nullptr
4684                   ? (PromiseResultTraits4::IsOk(*p)
4685                          ? "ready"
4686                          : absl::StrCat("early-error:",
4687                                         PromiseResultTraits4::ErrorString(*p))
4688                                .c_str())
4689                   : "pending");
4690         }
4691         if (p == nullptr) return Pending{};
4692         if (!PromiseResultTraits4::IsOk(*p)) {
4693           return PromiseResultTraits4::template ReturnValue<Result>(
4694               std::move(*p));
4695         }
4696         Destruct(&prior.prior.prior.prior.prior.prior.prior.current_promise);
4697         auto next_promise = PromiseResultTraits4::CallFactory(
4698             &prior.prior.prior.prior.prior.prior.prior.next_factory,
4699             std::move(*p));
4700         Destruct(&prior.prior.prior.prior.prior.prior.prior.next_factory);
4701         Construct(&prior.prior.prior.prior.prior.prior.current_promise,
4702                   std::move(next_promise));
4703         state = State::kState5;
4704       }
4705         ABSL_FALLTHROUGH_INTENDED;
4706       case State::kState5: {
4707         if (grpc_trace_promise_primitives.enabled()) {
4708           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4709                   "seq[%p]: begin poll step 6/12", this);
4710         }
4711         auto result = prior.prior.prior.prior.prior.prior.current_promise();
4712         PromiseResult5* p = result.value_if_ready();
4713         if (grpc_trace_promise_primitives.enabled()) {
4714           gpr_log(
4715               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4716               "seq[%p]: poll step 6/12 gets %s", this,
4717               p != nullptr
4718                   ? (PromiseResultTraits5::IsOk(*p)
4719                          ? "ready"
4720                          : absl::StrCat("early-error:",
4721                                         PromiseResultTraits5::ErrorString(*p))
4722                                .c_str())
4723                   : "pending");
4724         }
4725         if (p == nullptr) return Pending{};
4726         if (!PromiseResultTraits5::IsOk(*p)) {
4727           return PromiseResultTraits5::template ReturnValue<Result>(
4728               std::move(*p));
4729         }
4730         Destruct(&prior.prior.prior.prior.prior.prior.current_promise);
4731         auto next_promise = PromiseResultTraits5::CallFactory(
4732             &prior.prior.prior.prior.prior.prior.next_factory, std::move(*p));
4733         Destruct(&prior.prior.prior.prior.prior.prior.next_factory);
4734         Construct(&prior.prior.prior.prior.prior.current_promise,
4735                   std::move(next_promise));
4736         state = State::kState6;
4737       }
4738         ABSL_FALLTHROUGH_INTENDED;
4739       case State::kState6: {
4740         if (grpc_trace_promise_primitives.enabled()) {
4741           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4742                   "seq[%p]: begin poll step 7/12", this);
4743         }
4744         auto result = prior.prior.prior.prior.prior.current_promise();
4745         PromiseResult6* p = result.value_if_ready();
4746         if (grpc_trace_promise_primitives.enabled()) {
4747           gpr_log(
4748               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4749               "seq[%p]: poll step 7/12 gets %s", this,
4750               p != nullptr
4751                   ? (PromiseResultTraits6::IsOk(*p)
4752                          ? "ready"
4753                          : absl::StrCat("early-error:",
4754                                         PromiseResultTraits6::ErrorString(*p))
4755                                .c_str())
4756                   : "pending");
4757         }
4758         if (p == nullptr) return Pending{};
4759         if (!PromiseResultTraits6::IsOk(*p)) {
4760           return PromiseResultTraits6::template ReturnValue<Result>(
4761               std::move(*p));
4762         }
4763         Destruct(&prior.prior.prior.prior.prior.current_promise);
4764         auto next_promise = PromiseResultTraits6::CallFactory(
4765             &prior.prior.prior.prior.prior.next_factory, std::move(*p));
4766         Destruct(&prior.prior.prior.prior.prior.next_factory);
4767         Construct(&prior.prior.prior.prior.current_promise,
4768                   std::move(next_promise));
4769         state = State::kState7;
4770       }
4771         ABSL_FALLTHROUGH_INTENDED;
4772       case State::kState7: {
4773         if (grpc_trace_promise_primitives.enabled()) {
4774           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4775                   "seq[%p]: begin poll step 8/12", this);
4776         }
4777         auto result = prior.prior.prior.prior.current_promise();
4778         PromiseResult7* p = result.value_if_ready();
4779         if (grpc_trace_promise_primitives.enabled()) {
4780           gpr_log(
4781               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4782               "seq[%p]: poll step 8/12 gets %s", this,
4783               p != nullptr
4784                   ? (PromiseResultTraits7::IsOk(*p)
4785                          ? "ready"
4786                          : absl::StrCat("early-error:",
4787                                         PromiseResultTraits7::ErrorString(*p))
4788                                .c_str())
4789                   : "pending");
4790         }
4791         if (p == nullptr) return Pending{};
4792         if (!PromiseResultTraits7::IsOk(*p)) {
4793           return PromiseResultTraits7::template ReturnValue<Result>(
4794               std::move(*p));
4795         }
4796         Destruct(&prior.prior.prior.prior.current_promise);
4797         auto next_promise = PromiseResultTraits7::CallFactory(
4798             &prior.prior.prior.prior.next_factory, std::move(*p));
4799         Destruct(&prior.prior.prior.prior.next_factory);
4800         Construct(&prior.prior.prior.current_promise, std::move(next_promise));
4801         state = State::kState8;
4802       }
4803         ABSL_FALLTHROUGH_INTENDED;
4804       case State::kState8: {
4805         if (grpc_trace_promise_primitives.enabled()) {
4806           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4807                   "seq[%p]: begin poll step 9/12", this);
4808         }
4809         auto result = prior.prior.prior.current_promise();
4810         PromiseResult8* p = result.value_if_ready();
4811         if (grpc_trace_promise_primitives.enabled()) {
4812           gpr_log(
4813               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4814               "seq[%p]: poll step 9/12 gets %s", this,
4815               p != nullptr
4816                   ? (PromiseResultTraits8::IsOk(*p)
4817                          ? "ready"
4818                          : absl::StrCat("early-error:",
4819                                         PromiseResultTraits8::ErrorString(*p))
4820                                .c_str())
4821                   : "pending");
4822         }
4823         if (p == nullptr) return Pending{};
4824         if (!PromiseResultTraits8::IsOk(*p)) {
4825           return PromiseResultTraits8::template ReturnValue<Result>(
4826               std::move(*p));
4827         }
4828         Destruct(&prior.prior.prior.current_promise);
4829         auto next_promise = PromiseResultTraits8::CallFactory(
4830             &prior.prior.prior.next_factory, std::move(*p));
4831         Destruct(&prior.prior.prior.next_factory);
4832         Construct(&prior.prior.current_promise, std::move(next_promise));
4833         state = State::kState9;
4834       }
4835         ABSL_FALLTHROUGH_INTENDED;
4836       case State::kState9: {
4837         if (grpc_trace_promise_primitives.enabled()) {
4838           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4839                   "seq[%p]: begin poll step 10/12", this);
4840         }
4841         auto result = prior.prior.current_promise();
4842         PromiseResult9* p = result.value_if_ready();
4843         if (grpc_trace_promise_primitives.enabled()) {
4844           gpr_log(
4845               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4846               "seq[%p]: poll step 10/12 gets %s", this,
4847               p != nullptr
4848                   ? (PromiseResultTraits9::IsOk(*p)
4849                          ? "ready"
4850                          : absl::StrCat("early-error:",
4851                                         PromiseResultTraits9::ErrorString(*p))
4852                                .c_str())
4853                   : "pending");
4854         }
4855         if (p == nullptr) return Pending{};
4856         if (!PromiseResultTraits9::IsOk(*p)) {
4857           return PromiseResultTraits9::template ReturnValue<Result>(
4858               std::move(*p));
4859         }
4860         Destruct(&prior.prior.current_promise);
4861         auto next_promise = PromiseResultTraits9::CallFactory(
4862             &prior.prior.next_factory, std::move(*p));
4863         Destruct(&prior.prior.next_factory);
4864         Construct(&prior.current_promise, std::move(next_promise));
4865         state = State::kState10;
4866       }
4867         ABSL_FALLTHROUGH_INTENDED;
4868       case State::kState10: {
4869         if (grpc_trace_promise_primitives.enabled()) {
4870           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4871                   "seq[%p]: begin poll step 11/12", this);
4872         }
4873         auto result = prior.current_promise();
4874         PromiseResult10* p = result.value_if_ready();
4875         if (grpc_trace_promise_primitives.enabled()) {
4876           gpr_log(
4877               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4878               "seq[%p]: poll step 11/12 gets %s", this,
4879               p != nullptr
4880                   ? (PromiseResultTraits10::IsOk(*p)
4881                          ? "ready"
4882                          : absl::StrCat("early-error:",
4883                                         PromiseResultTraits10::ErrorString(*p))
4884                                .c_str())
4885                   : "pending");
4886         }
4887         if (p == nullptr) return Pending{};
4888         if (!PromiseResultTraits10::IsOk(*p)) {
4889           return PromiseResultTraits10::template ReturnValue<Result>(
4890               std::move(*p));
4891         }
4892         Destruct(&prior.current_promise);
4893         auto next_promise = PromiseResultTraits10::CallFactory(
4894             &prior.next_factory, std::move(*p));
4895         Destruct(&prior.next_factory);
4896         Construct(&current_promise, std::move(next_promise));
4897         state = State::kState11;
4898       }
4899         ABSL_FALLTHROUGH_INTENDED;
4900       default:
4901       case State::kState11: {
4902         if (grpc_trace_promise_primitives.enabled()) {
4903           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4904                   "seq[%p]: begin poll step 12/12", this);
4905         }
4906         auto result = current_promise();
4907         if (grpc_trace_promise_primitives.enabled()) {
4908           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
4909                   "seq[%p]: poll step 12/12 gets %s", this,
4910                   result.ready() ? "ready" : "pending");
4911         }
4912         auto* p = result.value_if_ready();
4913         if (p == nullptr) return Pending{};
4914         return Result(std::move(*p));
4915       }
4916     }
4917   }
4918 };
4919 
4920 template <template <typename> class Traits, typename P, typename F0,
4921           typename F1, typename F2, typename F3, typename F4, typename F5,
4922           typename F6, typename F7, typename F8, typename F9, typename F10,
4923           typename F11>
4924 struct SeqState<Traits, P, F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11> {
4925   using Promise0 = PromiseLike<P>;
4926   using PromiseResult0 = typename Promise0::Result;
4927   using PromiseResultTraits0 = Traits<PromiseResult0>;
4928   using NextFactory0 =
4929       OncePromiseFactory<typename PromiseResultTraits0::UnwrappedType, F0>;
4930   using Promise1 = typename NextFactory0::Promise;
4931   using PromiseResult1 = typename Promise1::Result;
4932   using PromiseResultTraits1 = Traits<PromiseResult1>;
4933   using NextFactory1 =
4934       OncePromiseFactory<typename PromiseResultTraits1::UnwrappedType, F1>;
4935   using Promise2 = typename NextFactory1::Promise;
4936   using PromiseResult2 = typename Promise2::Result;
4937   using PromiseResultTraits2 = Traits<PromiseResult2>;
4938   using NextFactory2 =
4939       OncePromiseFactory<typename PromiseResultTraits2::UnwrappedType, F2>;
4940   using Promise3 = typename NextFactory2::Promise;
4941   using PromiseResult3 = typename Promise3::Result;
4942   using PromiseResultTraits3 = Traits<PromiseResult3>;
4943   using NextFactory3 =
4944       OncePromiseFactory<typename PromiseResultTraits3::UnwrappedType, F3>;
4945   using Promise4 = typename NextFactory3::Promise;
4946   using PromiseResult4 = typename Promise4::Result;
4947   using PromiseResultTraits4 = Traits<PromiseResult4>;
4948   using NextFactory4 =
4949       OncePromiseFactory<typename PromiseResultTraits4::UnwrappedType, F4>;
4950   using Promise5 = typename NextFactory4::Promise;
4951   using PromiseResult5 = typename Promise5::Result;
4952   using PromiseResultTraits5 = Traits<PromiseResult5>;
4953   using NextFactory5 =
4954       OncePromiseFactory<typename PromiseResultTraits5::UnwrappedType, F5>;
4955   using Promise6 = typename NextFactory5::Promise;
4956   using PromiseResult6 = typename Promise6::Result;
4957   using PromiseResultTraits6 = Traits<PromiseResult6>;
4958   using NextFactory6 =
4959       OncePromiseFactory<typename PromiseResultTraits6::UnwrappedType, F6>;
4960   using Promise7 = typename NextFactory6::Promise;
4961   using PromiseResult7 = typename Promise7::Result;
4962   using PromiseResultTraits7 = Traits<PromiseResult7>;
4963   using NextFactory7 =
4964       OncePromiseFactory<typename PromiseResultTraits7::UnwrappedType, F7>;
4965   using Promise8 = typename NextFactory7::Promise;
4966   using PromiseResult8 = typename Promise8::Result;
4967   using PromiseResultTraits8 = Traits<PromiseResult8>;
4968   using NextFactory8 =
4969       OncePromiseFactory<typename PromiseResultTraits8::UnwrappedType, F8>;
4970   using Promise9 = typename NextFactory8::Promise;
4971   using PromiseResult9 = typename Promise9::Result;
4972   using PromiseResultTraits9 = Traits<PromiseResult9>;
4973   using NextFactory9 =
4974       OncePromiseFactory<typename PromiseResultTraits9::UnwrappedType, F9>;
4975   using Promise10 = typename NextFactory9::Promise;
4976   using PromiseResult10 = typename Promise10::Result;
4977   using PromiseResultTraits10 = Traits<PromiseResult10>;
4978   using NextFactory10 =
4979       OncePromiseFactory<typename PromiseResultTraits10::UnwrappedType, F10>;
4980   using Promise11 = typename NextFactory10::Promise;
4981   using PromiseResult11 = typename Promise11::Result;
4982   using PromiseResultTraits11 = Traits<PromiseResult11>;
4983   using NextFactory11 =
4984       OncePromiseFactory<typename PromiseResultTraits11::UnwrappedType, F11>;
4985   using Promise12 = typename NextFactory11::Promise;
4986   using PromiseResult12 = typename Promise12::Result;
4987   using PromiseResultTraits12 = Traits<PromiseResult12>;
4988   using Result = typename PromiseResultTraits12::WrappedType;
4989   struct Running0 {
4990     GPR_NO_UNIQUE_ADDRESS Promise0 current_promise;
4991     GPR_NO_UNIQUE_ADDRESS NextFactory0 next_factory;
4992   };
4993   struct Running1 {
4994     union {
4995       GPR_NO_UNIQUE_ADDRESS Running0 prior;
4996       GPR_NO_UNIQUE_ADDRESS Promise1 current_promise;
4997     };
4998     GPR_NO_UNIQUE_ADDRESS NextFactory1 next_factory;
4999   };
5000   struct Running2 {
5001     union {
5002       GPR_NO_UNIQUE_ADDRESS Running1 prior;
5003       GPR_NO_UNIQUE_ADDRESS Promise2 current_promise;
5004     };
5005     GPR_NO_UNIQUE_ADDRESS NextFactory2 next_factory;
5006   };
5007   struct Running3 {
5008     union {
5009       GPR_NO_UNIQUE_ADDRESS Running2 prior;
5010       GPR_NO_UNIQUE_ADDRESS Promise3 current_promise;
5011     };
5012     GPR_NO_UNIQUE_ADDRESS NextFactory3 next_factory;
5013   };
5014   struct Running4 {
5015     union {
5016       GPR_NO_UNIQUE_ADDRESS Running3 prior;
5017       GPR_NO_UNIQUE_ADDRESS Promise4 current_promise;
5018     };
5019     GPR_NO_UNIQUE_ADDRESS NextFactory4 next_factory;
5020   };
5021   struct Running5 {
5022     union {
5023       GPR_NO_UNIQUE_ADDRESS Running4 prior;
5024       GPR_NO_UNIQUE_ADDRESS Promise5 current_promise;
5025     };
5026     GPR_NO_UNIQUE_ADDRESS NextFactory5 next_factory;
5027   };
5028   struct Running6 {
5029     union {
5030       GPR_NO_UNIQUE_ADDRESS Running5 prior;
5031       GPR_NO_UNIQUE_ADDRESS Promise6 current_promise;
5032     };
5033     GPR_NO_UNIQUE_ADDRESS NextFactory6 next_factory;
5034   };
5035   struct Running7 {
5036     union {
5037       GPR_NO_UNIQUE_ADDRESS Running6 prior;
5038       GPR_NO_UNIQUE_ADDRESS Promise7 current_promise;
5039     };
5040     GPR_NO_UNIQUE_ADDRESS NextFactory7 next_factory;
5041   };
5042   struct Running8 {
5043     union {
5044       GPR_NO_UNIQUE_ADDRESS Running7 prior;
5045       GPR_NO_UNIQUE_ADDRESS Promise8 current_promise;
5046     };
5047     GPR_NO_UNIQUE_ADDRESS NextFactory8 next_factory;
5048   };
5049   struct Running9 {
5050     union {
5051       GPR_NO_UNIQUE_ADDRESS Running8 prior;
5052       GPR_NO_UNIQUE_ADDRESS Promise9 current_promise;
5053     };
5054     GPR_NO_UNIQUE_ADDRESS NextFactory9 next_factory;
5055   };
5056   struct Running10 {
5057     union {
5058       GPR_NO_UNIQUE_ADDRESS Running9 prior;
5059       GPR_NO_UNIQUE_ADDRESS Promise10 current_promise;
5060     };
5061     GPR_NO_UNIQUE_ADDRESS NextFactory10 next_factory;
5062   };
5063   struct Running11 {
5064     union {
5065       GPR_NO_UNIQUE_ADDRESS Running10 prior;
5066       GPR_NO_UNIQUE_ADDRESS Promise11 current_promise;
5067     };
5068     GPR_NO_UNIQUE_ADDRESS NextFactory11 next_factory;
5069   };
5070   union {
5071     GPR_NO_UNIQUE_ADDRESS Running11 prior;
5072     GPR_NO_UNIQUE_ADDRESS Promise12 current_promise;
5073   };
5074   enum class State : uint8_t {
5075     kState0,
5076     kState1,
5077     kState2,
5078     kState3,
5079     kState4,
5080     kState5,
5081     kState6,
5082     kState7,
5083     kState8,
5084     kState9,
5085     kState10,
5086     kState11,
5087     kState12
5088   };
5089   GPR_NO_UNIQUE_ADDRESS State state = State::kState0;
5090   GPR_NO_UNIQUE_ADDRESS DebugLocation whence;
5091 
5092   SeqState(P&& p, F0&& f0, F1&& f1, F2&& f2, F3&& f3, F4&& f4, F5&& f5, F6&& f6,
5093            F7&& f7, F8&& f8, F9&& f9, F10&& f10, F11&& f11,
5094            DebugLocation whence) noexcept
5095       : whence(whence) {
5096     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5097                    .prior.current_promise,
5098               std::forward<P>(p));
5099     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5100                    .prior.next_factory,
5101               std::forward<F0>(f0));
5102     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5103                    .next_factory,
5104               std::forward<F1>(f1));
5105     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5106                    .next_factory,
5107               std::forward<F2>(f2));
5108     Construct(
5109         &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
5110         std::forward<F3>(f3));
5111     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
5112               std::forward<F4>(f4));
5113     Construct(&prior.prior.prior.prior.prior.prior.prior.next_factory,
5114               std::forward<F5>(f5));
5115     Construct(&prior.prior.prior.prior.prior.prior.next_factory,
5116               std::forward<F6>(f6));
5117     Construct(&prior.prior.prior.prior.prior.next_factory,
5118               std::forward<F7>(f7));
5119     Construct(&prior.prior.prior.prior.next_factory, std::forward<F8>(f8));
5120     Construct(&prior.prior.prior.next_factory, std::forward<F9>(f9));
5121     Construct(&prior.prior.next_factory, std::forward<F10>(f10));
5122     Construct(&prior.next_factory, std::forward<F11>(f11));
5123   }
5124   ~SeqState() {
5125     switch (state) {
5126       case State::kState0:
5127         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5128                       .prior.prior.current_promise);
5129         goto tail0;
5130       case State::kState1:
5131         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5132                       .prior.current_promise);
5133         goto tail1;
5134       case State::kState2:
5135         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5136                       .current_promise);
5137         goto tail2;
5138       case State::kState3:
5139         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior
5140                       .current_promise);
5141         goto tail3;
5142       case State::kState4:
5143         Destruct(
5144             &prior.prior.prior.prior.prior.prior.prior.prior.current_promise);
5145         goto tail4;
5146       case State::kState5:
5147         Destruct(&prior.prior.prior.prior.prior.prior.prior.current_promise);
5148         goto tail5;
5149       case State::kState6:
5150         Destruct(&prior.prior.prior.prior.prior.prior.current_promise);
5151         goto tail6;
5152       case State::kState7:
5153         Destruct(&prior.prior.prior.prior.prior.current_promise);
5154         goto tail7;
5155       case State::kState8:
5156         Destruct(&prior.prior.prior.prior.current_promise);
5157         goto tail8;
5158       case State::kState9:
5159         Destruct(&prior.prior.prior.current_promise);
5160         goto tail9;
5161       case State::kState10:
5162         Destruct(&prior.prior.current_promise);
5163         goto tail10;
5164       case State::kState11:
5165         Destruct(&prior.current_promise);
5166         goto tail11;
5167       case State::kState12:
5168         Destruct(&current_promise);
5169         return;
5170     }
5171   tail0:
5172     Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5173                   .prior.next_factory);
5174   tail1:
5175     Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5176                   .next_factory);
5177   tail2:
5178     Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5179                   .next_factory);
5180   tail3:
5181     Destruct(
5182         &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory);
5183   tail4:
5184     Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory);
5185   tail5:
5186     Destruct(&prior.prior.prior.prior.prior.prior.prior.next_factory);
5187   tail6:
5188     Destruct(&prior.prior.prior.prior.prior.prior.next_factory);
5189   tail7:
5190     Destruct(&prior.prior.prior.prior.prior.next_factory);
5191   tail8:
5192     Destruct(&prior.prior.prior.prior.next_factory);
5193   tail9:
5194     Destruct(&prior.prior.prior.next_factory);
5195   tail10:
5196     Destruct(&prior.prior.next_factory);
5197   tail11:
5198     Destruct(&prior.next_factory);
5199   }
5200   SeqState(const SeqState& other) noexcept
5201       : state(other.state), whence(other.whence) {
5202     GPR_ASSERT(state == State::kState0);
5203     Construct(&prior.current_promise, other.prior.current_promise);
5204     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5205                    .prior.next_factory,
5206               other.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5207                   .prior.prior.next_factory);
5208     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5209                    .next_factory,
5210               other.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5211                   .prior.next_factory);
5212     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5213                    .next_factory,
5214               other.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5215                   .next_factory);
5216     Construct(
5217         &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
5218         other.prior.prior.prior.prior.prior.prior.prior.prior.prior
5219             .next_factory);
5220     Construct(
5221         &prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
5222         other.prior.prior.prior.prior.prior.prior.prior.prior.next_factory);
5223     Construct(&prior.prior.prior.prior.prior.prior.prior.next_factory,
5224               other.prior.prior.prior.prior.prior.prior.prior.next_factory);
5225     Construct(&prior.prior.prior.prior.prior.prior.next_factory,
5226               other.prior.prior.prior.prior.prior.prior.next_factory);
5227     Construct(&prior.prior.prior.prior.prior.next_factory,
5228               other.prior.prior.prior.prior.prior.next_factory);
5229     Construct(&prior.prior.prior.prior.next_factory,
5230               other.prior.prior.prior.prior.next_factory);
5231     Construct(&prior.prior.prior.next_factory,
5232               other.prior.prior.prior.next_factory);
5233     Construct(&prior.prior.next_factory, other.prior.prior.next_factory);
5234     Construct(&prior.next_factory, other.prior.next_factory);
5235   }
5236   SeqState& operator=(const SeqState& other) = delete;
5237   SeqState(SeqState&& other) noexcept
5238       : state(other.state), whence(other.whence) {
5239     switch (state) {
5240       case State::kState0:
5241         Construct(
5242             &prior.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5243                  .prior.current_promise,
5244             std::move(other.prior.prior.prior.prior.prior.prior.prior.prior
5245                           .prior.prior.prior.prior.current_promise));
5246         goto tail0;
5247       case State::kState1:
5248         Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5249                        .prior.current_promise,
5250                   std::move(other.prior.prior.prior.prior.prior.prior.prior
5251                                 .prior.prior.prior.prior.current_promise));
5252         goto tail1;
5253       case State::kState2:
5254         Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5255                        .current_promise,
5256                   std::move(other.prior.prior.prior.prior.prior.prior.prior
5257                                 .prior.prior.prior.current_promise));
5258         goto tail2;
5259       case State::kState3:
5260         Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior
5261                        .current_promise,
5262                   std::move(other.prior.prior.prior.prior.prior.prior.prior
5263                                 .prior.prior.current_promise));
5264         goto tail3;
5265       case State::kState4:
5266         Construct(
5267             &prior.prior.prior.prior.prior.prior.prior.prior.current_promise,
5268             std::move(other.prior.prior.prior.prior.prior.prior.prior.prior
5269                           .current_promise));
5270         goto tail4;
5271       case State::kState5:
5272         Construct(&prior.prior.prior.prior.prior.prior.prior.current_promise,
5273                   std::move(other.prior.prior.prior.prior.prior.prior.prior
5274                                 .current_promise));
5275         goto tail5;
5276       case State::kState6:
5277         Construct(
5278             &prior.prior.prior.prior.prior.prior.current_promise,
5279             std::move(
5280                 other.prior.prior.prior.prior.prior.prior.current_promise));
5281         goto tail6;
5282       case State::kState7:
5283         Construct(
5284             &prior.prior.prior.prior.prior.current_promise,
5285             std::move(other.prior.prior.prior.prior.prior.current_promise));
5286         goto tail7;
5287       case State::kState8:
5288         Construct(&prior.prior.prior.prior.current_promise,
5289                   std::move(other.prior.prior.prior.prior.current_promise));
5290         goto tail8;
5291       case State::kState9:
5292         Construct(&prior.prior.prior.current_promise,
5293                   std::move(other.prior.prior.prior.current_promise));
5294         goto tail9;
5295       case State::kState10:
5296         Construct(&prior.prior.current_promise,
5297                   std::move(other.prior.prior.current_promise));
5298         goto tail10;
5299       case State::kState11:
5300         Construct(&prior.current_promise,
5301                   std::move(other.prior.current_promise));
5302         goto tail11;
5303       case State::kState12:
5304         Construct(&current_promise, std::move(other.current_promise));
5305         return;
5306     }
5307   tail0:
5308     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5309                    .prior.next_factory,
5310               std::move(other.prior.prior.prior.prior.prior.prior.prior.prior
5311                             .prior.prior.prior.prior.next_factory));
5312   tail1:
5313     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5314                    .next_factory,
5315               std::move(other.prior.prior.prior.prior.prior.prior.prior.prior
5316                             .prior.prior.prior.next_factory));
5317   tail2:
5318     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5319                    .next_factory,
5320               std::move(other.prior.prior.prior.prior.prior.prior.prior.prior
5321                             .prior.prior.next_factory));
5322   tail3:
5323     Construct(
5324         &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
5325         std::move(other.prior.prior.prior.prior.prior.prior.prior.prior.prior
5326                       .next_factory));
5327   tail4:
5328     Construct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
5329               std::move(other.prior.prior.prior.prior.prior.prior.prior.prior
5330                             .next_factory));
5331   tail5:
5332     Construct(
5333         &prior.prior.prior.prior.prior.prior.prior.next_factory,
5334         std::move(
5335             other.prior.prior.prior.prior.prior.prior.prior.next_factory));
5336   tail6:
5337     Construct(
5338         &prior.prior.prior.prior.prior.prior.next_factory,
5339         std::move(other.prior.prior.prior.prior.prior.prior.next_factory));
5340   tail7:
5341     Construct(&prior.prior.prior.prior.prior.next_factory,
5342               std::move(other.prior.prior.prior.prior.prior.next_factory));
5343   tail8:
5344     Construct(&prior.prior.prior.prior.next_factory,
5345               std::move(other.prior.prior.prior.prior.next_factory));
5346   tail9:
5347     Construct(&prior.prior.prior.next_factory,
5348               std::move(other.prior.prior.prior.next_factory));
5349   tail10:
5350     Construct(&prior.prior.next_factory,
5351               std::move(other.prior.prior.next_factory));
5352   tail11:
5353     Construct(&prior.next_factory, std::move(other.prior.next_factory));
5354   }
5355   SeqState& operator=(SeqState&& other) = delete;
5356   Poll<Result> PollOnce() {
5357     switch (state) {
5358       case State::kState0: {
5359         if (grpc_trace_promise_primitives.enabled()) {
5360           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5361                   "seq[%p]: begin poll step 1/13", this);
5362         }
5363         auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior
5364                           .prior.prior.prior.current_promise();
5365         PromiseResult0* p = result.value_if_ready();
5366         if (grpc_trace_promise_primitives.enabled()) {
5367           gpr_log(
5368               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5369               "seq[%p]: poll step 1/13 gets %s", this,
5370               p != nullptr
5371                   ? (PromiseResultTraits0::IsOk(*p)
5372                          ? "ready"
5373                          : absl::StrCat("early-error:",
5374                                         PromiseResultTraits0::ErrorString(*p))
5375                                .c_str())
5376                   : "pending");
5377         }
5378         if (p == nullptr) return Pending{};
5379         if (!PromiseResultTraits0::IsOk(*p)) {
5380           return PromiseResultTraits0::template ReturnValue<Result>(
5381               std::move(*p));
5382         }
5383         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5384                       .prior.prior.current_promise);
5385         auto next_promise = PromiseResultTraits0::CallFactory(
5386             &prior.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5387                  .prior.next_factory,
5388             std::move(*p));
5389         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5390                       .prior.prior.next_factory);
5391         Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5392                        .prior.current_promise,
5393                   std::move(next_promise));
5394         state = State::kState1;
5395       }
5396         ABSL_FALLTHROUGH_INTENDED;
5397       case State::kState1: {
5398         if (grpc_trace_promise_primitives.enabled()) {
5399           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5400                   "seq[%p]: begin poll step 2/13", this);
5401         }
5402         auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior
5403                           .prior.prior.current_promise();
5404         PromiseResult1* p = result.value_if_ready();
5405         if (grpc_trace_promise_primitives.enabled()) {
5406           gpr_log(
5407               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5408               "seq[%p]: poll step 2/13 gets %s", this,
5409               p != nullptr
5410                   ? (PromiseResultTraits1::IsOk(*p)
5411                          ? "ready"
5412                          : absl::StrCat("early-error:",
5413                                         PromiseResultTraits1::ErrorString(*p))
5414                                .c_str())
5415                   : "pending");
5416         }
5417         if (p == nullptr) return Pending{};
5418         if (!PromiseResultTraits1::IsOk(*p)) {
5419           return PromiseResultTraits1::template ReturnValue<Result>(
5420               std::move(*p));
5421         }
5422         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5423                       .prior.current_promise);
5424         auto next_promise = PromiseResultTraits1::CallFactory(
5425             &prior.prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5426                  .next_factory,
5427             std::move(*p));
5428         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5429                       .prior.next_factory);
5430         Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5431                        .current_promise,
5432                   std::move(next_promise));
5433         state = State::kState2;
5434       }
5435         ABSL_FALLTHROUGH_INTENDED;
5436       case State::kState2: {
5437         if (grpc_trace_promise_primitives.enabled()) {
5438           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5439                   "seq[%p]: begin poll step 3/13", this);
5440         }
5441         auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior
5442                           .prior.current_promise();
5443         PromiseResult2* p = result.value_if_ready();
5444         if (grpc_trace_promise_primitives.enabled()) {
5445           gpr_log(
5446               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5447               "seq[%p]: poll step 3/13 gets %s", this,
5448               p != nullptr
5449                   ? (PromiseResultTraits2::IsOk(*p)
5450                          ? "ready"
5451                          : absl::StrCat("early-error:",
5452                                         PromiseResultTraits2::ErrorString(*p))
5453                                .c_str())
5454                   : "pending");
5455         }
5456         if (p == nullptr) return Pending{};
5457         if (!PromiseResultTraits2::IsOk(*p)) {
5458           return PromiseResultTraits2::template ReturnValue<Result>(
5459               std::move(*p));
5460         }
5461         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5462                       .current_promise);
5463         auto next_promise = PromiseResultTraits2::CallFactory(
5464             &prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5465                  .next_factory,
5466             std::move(*p));
5467         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior.prior
5468                       .next_factory);
5469         Construct(&prior.prior.prior.prior.prior.prior.prior.prior.prior
5470                        .current_promise,
5471                   std::move(next_promise));
5472         state = State::kState3;
5473       }
5474         ABSL_FALLTHROUGH_INTENDED;
5475       case State::kState3: {
5476         if (grpc_trace_promise_primitives.enabled()) {
5477           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5478                   "seq[%p]: begin poll step 4/13", this);
5479         }
5480         auto result = prior.prior.prior.prior.prior.prior.prior.prior.prior
5481                           .current_promise();
5482         PromiseResult3* p = result.value_if_ready();
5483         if (grpc_trace_promise_primitives.enabled()) {
5484           gpr_log(
5485               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5486               "seq[%p]: poll step 4/13 gets %s", this,
5487               p != nullptr
5488                   ? (PromiseResultTraits3::IsOk(*p)
5489                          ? "ready"
5490                          : absl::StrCat("early-error:",
5491                                         PromiseResultTraits3::ErrorString(*p))
5492                                .c_str())
5493                   : "pending");
5494         }
5495         if (p == nullptr) return Pending{};
5496         if (!PromiseResultTraits3::IsOk(*p)) {
5497           return PromiseResultTraits3::template ReturnValue<Result>(
5498               std::move(*p));
5499         }
5500         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior
5501                       .current_promise);
5502         auto next_promise = PromiseResultTraits3::CallFactory(
5503             &prior.prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
5504             std::move(*p));
5505         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.prior
5506                       .next_factory);
5507         Construct(
5508             &prior.prior.prior.prior.prior.prior.prior.prior.current_promise,
5509             std::move(next_promise));
5510         state = State::kState4;
5511       }
5512         ABSL_FALLTHROUGH_INTENDED;
5513       case State::kState4: {
5514         if (grpc_trace_promise_primitives.enabled()) {
5515           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5516                   "seq[%p]: begin poll step 5/13", this);
5517         }
5518         auto result =
5519             prior.prior.prior.prior.prior.prior.prior.prior.current_promise();
5520         PromiseResult4* p = result.value_if_ready();
5521         if (grpc_trace_promise_primitives.enabled()) {
5522           gpr_log(
5523               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5524               "seq[%p]: poll step 5/13 gets %s", this,
5525               p != nullptr
5526                   ? (PromiseResultTraits4::IsOk(*p)
5527                          ? "ready"
5528                          : absl::StrCat("early-error:",
5529                                         PromiseResultTraits4::ErrorString(*p))
5530                                .c_str())
5531                   : "pending");
5532         }
5533         if (p == nullptr) return Pending{};
5534         if (!PromiseResultTraits4::IsOk(*p)) {
5535           return PromiseResultTraits4::template ReturnValue<Result>(
5536               std::move(*p));
5537         }
5538         Destruct(
5539             &prior.prior.prior.prior.prior.prior.prior.prior.current_promise);
5540         auto next_promise = PromiseResultTraits4::CallFactory(
5541             &prior.prior.prior.prior.prior.prior.prior.prior.next_factory,
5542             std::move(*p));
5543         Destruct(&prior.prior.prior.prior.prior.prior.prior.prior.next_factory);
5544         Construct(&prior.prior.prior.prior.prior.prior.prior.current_promise,
5545                   std::move(next_promise));
5546         state = State::kState5;
5547       }
5548         ABSL_FALLTHROUGH_INTENDED;
5549       case State::kState5: {
5550         if (grpc_trace_promise_primitives.enabled()) {
5551           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5552                   "seq[%p]: begin poll step 6/13", this);
5553         }
5554         auto result =
5555             prior.prior.prior.prior.prior.prior.prior.current_promise();
5556         PromiseResult5* p = result.value_if_ready();
5557         if (grpc_trace_promise_primitives.enabled()) {
5558           gpr_log(
5559               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5560               "seq[%p]: poll step 6/13 gets %s", this,
5561               p != nullptr
5562                   ? (PromiseResultTraits5::IsOk(*p)
5563                          ? "ready"
5564                          : absl::StrCat("early-error:",
5565                                         PromiseResultTraits5::ErrorString(*p))
5566                                .c_str())
5567                   : "pending");
5568         }
5569         if (p == nullptr) return Pending{};
5570         if (!PromiseResultTraits5::IsOk(*p)) {
5571           return PromiseResultTraits5::template ReturnValue<Result>(
5572               std::move(*p));
5573         }
5574         Destruct(&prior.prior.prior.prior.prior.prior.prior.current_promise);
5575         auto next_promise = PromiseResultTraits5::CallFactory(
5576             &prior.prior.prior.prior.prior.prior.prior.next_factory,
5577             std::move(*p));
5578         Destruct(&prior.prior.prior.prior.prior.prior.prior.next_factory);
5579         Construct(&prior.prior.prior.prior.prior.prior.current_promise,
5580                   std::move(next_promise));
5581         state = State::kState6;
5582       }
5583         ABSL_FALLTHROUGH_INTENDED;
5584       case State::kState6: {
5585         if (grpc_trace_promise_primitives.enabled()) {
5586           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5587                   "seq[%p]: begin poll step 7/13", this);
5588         }
5589         auto result = prior.prior.prior.prior.prior.prior.current_promise();
5590         PromiseResult6* p = result.value_if_ready();
5591         if (grpc_trace_promise_primitives.enabled()) {
5592           gpr_log(
5593               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5594               "seq[%p]: poll step 7/13 gets %s", this,
5595               p != nullptr
5596                   ? (PromiseResultTraits6::IsOk(*p)
5597                          ? "ready"
5598                          : absl::StrCat("early-error:",
5599                                         PromiseResultTraits6::ErrorString(*p))
5600                                .c_str())
5601                   : "pending");
5602         }
5603         if (p == nullptr) return Pending{};
5604         if (!PromiseResultTraits6::IsOk(*p)) {
5605           return PromiseResultTraits6::template ReturnValue<Result>(
5606               std::move(*p));
5607         }
5608         Destruct(&prior.prior.prior.prior.prior.prior.current_promise);
5609         auto next_promise = PromiseResultTraits6::CallFactory(
5610             &prior.prior.prior.prior.prior.prior.next_factory, std::move(*p));
5611         Destruct(&prior.prior.prior.prior.prior.prior.next_factory);
5612         Construct(&prior.prior.prior.prior.prior.current_promise,
5613                   std::move(next_promise));
5614         state = State::kState7;
5615       }
5616         ABSL_FALLTHROUGH_INTENDED;
5617       case State::kState7: {
5618         if (grpc_trace_promise_primitives.enabled()) {
5619           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5620                   "seq[%p]: begin poll step 8/13", this);
5621         }
5622         auto result = prior.prior.prior.prior.prior.current_promise();
5623         PromiseResult7* p = result.value_if_ready();
5624         if (grpc_trace_promise_primitives.enabled()) {
5625           gpr_log(
5626               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5627               "seq[%p]: poll step 8/13 gets %s", this,
5628               p != nullptr
5629                   ? (PromiseResultTraits7::IsOk(*p)
5630                          ? "ready"
5631                          : absl::StrCat("early-error:",
5632                                         PromiseResultTraits7::ErrorString(*p))
5633                                .c_str())
5634                   : "pending");
5635         }
5636         if (p == nullptr) return Pending{};
5637         if (!PromiseResultTraits7::IsOk(*p)) {
5638           return PromiseResultTraits7::template ReturnValue<Result>(
5639               std::move(*p));
5640         }
5641         Destruct(&prior.prior.prior.prior.prior.current_promise);
5642         auto next_promise = PromiseResultTraits7::CallFactory(
5643             &prior.prior.prior.prior.prior.next_factory, std::move(*p));
5644         Destruct(&prior.prior.prior.prior.prior.next_factory);
5645         Construct(&prior.prior.prior.prior.current_promise,
5646                   std::move(next_promise));
5647         state = State::kState8;
5648       }
5649         ABSL_FALLTHROUGH_INTENDED;
5650       case State::kState8: {
5651         if (grpc_trace_promise_primitives.enabled()) {
5652           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5653                   "seq[%p]: begin poll step 9/13", this);
5654         }
5655         auto result = prior.prior.prior.prior.current_promise();
5656         PromiseResult8* p = result.value_if_ready();
5657         if (grpc_trace_promise_primitives.enabled()) {
5658           gpr_log(
5659               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5660               "seq[%p]: poll step 9/13 gets %s", this,
5661               p != nullptr
5662                   ? (PromiseResultTraits8::IsOk(*p)
5663                          ? "ready"
5664                          : absl::StrCat("early-error:",
5665                                         PromiseResultTraits8::ErrorString(*p))
5666                                .c_str())
5667                   : "pending");
5668         }
5669         if (p == nullptr) return Pending{};
5670         if (!PromiseResultTraits8::IsOk(*p)) {
5671           return PromiseResultTraits8::template ReturnValue<Result>(
5672               std::move(*p));
5673         }
5674         Destruct(&prior.prior.prior.prior.current_promise);
5675         auto next_promise = PromiseResultTraits8::CallFactory(
5676             &prior.prior.prior.prior.next_factory, std::move(*p));
5677         Destruct(&prior.prior.prior.prior.next_factory);
5678         Construct(&prior.prior.prior.current_promise, std::move(next_promise));
5679         state = State::kState9;
5680       }
5681         ABSL_FALLTHROUGH_INTENDED;
5682       case State::kState9: {
5683         if (grpc_trace_promise_primitives.enabled()) {
5684           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5685                   "seq[%p]: begin poll step 10/13", this);
5686         }
5687         auto result = prior.prior.prior.current_promise();
5688         PromiseResult9* p = result.value_if_ready();
5689         if (grpc_trace_promise_primitives.enabled()) {
5690           gpr_log(
5691               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5692               "seq[%p]: poll step 10/13 gets %s", this,
5693               p != nullptr
5694                   ? (PromiseResultTraits9::IsOk(*p)
5695                          ? "ready"
5696                          : absl::StrCat("early-error:",
5697                                         PromiseResultTraits9::ErrorString(*p))
5698                                .c_str())
5699                   : "pending");
5700         }
5701         if (p == nullptr) return Pending{};
5702         if (!PromiseResultTraits9::IsOk(*p)) {
5703           return PromiseResultTraits9::template ReturnValue<Result>(
5704               std::move(*p));
5705         }
5706         Destruct(&prior.prior.prior.current_promise);
5707         auto next_promise = PromiseResultTraits9::CallFactory(
5708             &prior.prior.prior.next_factory, std::move(*p));
5709         Destruct(&prior.prior.prior.next_factory);
5710         Construct(&prior.prior.current_promise, std::move(next_promise));
5711         state = State::kState10;
5712       }
5713         ABSL_FALLTHROUGH_INTENDED;
5714       case State::kState10: {
5715         if (grpc_trace_promise_primitives.enabled()) {
5716           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5717                   "seq[%p]: begin poll step 11/13", this);
5718         }
5719         auto result = prior.prior.current_promise();
5720         PromiseResult10* p = result.value_if_ready();
5721         if (grpc_trace_promise_primitives.enabled()) {
5722           gpr_log(
5723               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5724               "seq[%p]: poll step 11/13 gets %s", this,
5725               p != nullptr
5726                   ? (PromiseResultTraits10::IsOk(*p)
5727                          ? "ready"
5728                          : absl::StrCat("early-error:",
5729                                         PromiseResultTraits10::ErrorString(*p))
5730                                .c_str())
5731                   : "pending");
5732         }
5733         if (p == nullptr) return Pending{};
5734         if (!PromiseResultTraits10::IsOk(*p)) {
5735           return PromiseResultTraits10::template ReturnValue<Result>(
5736               std::move(*p));
5737         }
5738         Destruct(&prior.prior.current_promise);
5739         auto next_promise = PromiseResultTraits10::CallFactory(
5740             &prior.prior.next_factory, std::move(*p));
5741         Destruct(&prior.prior.next_factory);
5742         Construct(&prior.current_promise, std::move(next_promise));
5743         state = State::kState11;
5744       }
5745         ABSL_FALLTHROUGH_INTENDED;
5746       case State::kState11: {
5747         if (grpc_trace_promise_primitives.enabled()) {
5748           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5749                   "seq[%p]: begin poll step 12/13", this);
5750         }
5751         auto result = prior.current_promise();
5752         PromiseResult11* p = result.value_if_ready();
5753         if (grpc_trace_promise_primitives.enabled()) {
5754           gpr_log(
5755               whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5756               "seq[%p]: poll step 12/13 gets %s", this,
5757               p != nullptr
5758                   ? (PromiseResultTraits11::IsOk(*p)
5759                          ? "ready"
5760                          : absl::StrCat("early-error:",
5761                                         PromiseResultTraits11::ErrorString(*p))
5762                                .c_str())
5763                   : "pending");
5764         }
5765         if (p == nullptr) return Pending{};
5766         if (!PromiseResultTraits11::IsOk(*p)) {
5767           return PromiseResultTraits11::template ReturnValue<Result>(
5768               std::move(*p));
5769         }
5770         Destruct(&prior.current_promise);
5771         auto next_promise = PromiseResultTraits11::CallFactory(
5772             &prior.next_factory, std::move(*p));
5773         Destruct(&prior.next_factory);
5774         Construct(&current_promise, std::move(next_promise));
5775         state = State::kState12;
5776       }
5777         ABSL_FALLTHROUGH_INTENDED;
5778       default:
5779       case State::kState12: {
5780         if (grpc_trace_promise_primitives.enabled()) {
5781           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5782                   "seq[%p]: begin poll step 13/13", this);
5783         }
5784         auto result = current_promise();
5785         if (grpc_trace_promise_primitives.enabled()) {
5786           gpr_log(whence.file(), whence.line(), GPR_LOG_SEVERITY_DEBUG,
5787                   "seq[%p]: poll step 13/13 gets %s", this,
5788                   result.ready() ? "ready" : "pending");
5789         }
5790         auto* p = result.value_if_ready();
5791         if (p == nullptr) return Pending{};
5792         return Result(std::move(*p));
5793       }
5794     }
5795   }
5796 };
5797 
5798 }  // namespace promise_detail
5799 }  // namespace grpc_core
5800 
5801 #endif  // GRPC_SRC_CORE_LIB_PROMISE_DETAIL_SEQ_STATE_H
5802